You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef FIELDS_GRID_TABLE_H
  24. #define FIELDS_GRID_TABLE_H
  25. #include <base_units.h>
  26. #include <sch_validators.h>
  27. #include <wx/grid.h>
  28. #include <sch_symbol.h>
  29. #include <grid_tricks.h>
  30. #include <validators.h>
  31. class SCH_BASE_FRAME;
  32. class DIALOG_SHIM;
  33. class SCH_LABEL_BASE;
  34. class FIELDS_GRID_TRICKS : public GRID_TRICKS
  35. {
  36. public:
  37. FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog ) :
  38. GRID_TRICKS( aGrid ),
  39. m_dlg( aDialog )
  40. {}
  41. protected:
  42. virtual void showPopupMenu( wxMenu& menu ) override;
  43. virtual void doPopupSelection( wxCommandEvent& event ) override;
  44. DIALOG_SHIM* m_dlg;
  45. };
  46. enum FIELDS_DATA_COL_ORDER
  47. {
  48. FDC_NAME,
  49. FDC_VALUE,
  50. FDC_SHOWN,
  51. FDC_H_ALIGN,
  52. FDC_V_ALIGN,
  53. FDC_ITALIC,
  54. FDC_BOLD,
  55. FDC_TEXT_SIZE,
  56. FDC_ORIENTATION,
  57. FDC_POSX,
  58. FDC_POSY,
  59. FDC_FONT,
  60. FDC_COLOR,
  61. FDC_COUNT // keep as last
  62. };
  63. template <class T>
  64. class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<T>
  65. {
  66. public:
  67. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
  68. LIB_SYMBOL* aSymbol );
  69. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  70. SCH_SYMBOL* aSymbol );
  71. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  72. SCH_SHEET* aSheet );
  73. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  74. SCH_LABEL_BASE* aLabel );
  75. ~FIELDS_GRID_TABLE();
  76. int GetNumberRows() override { return (int) this->size(); }
  77. int GetNumberCols() override { return FDC_COUNT; }
  78. wxString GetColLabelValue( int aCol ) override;
  79. bool IsEmptyCell( int row, int col ) override
  80. {
  81. return false; // don't allow adjacent cell overflow, even if we are actually empty
  82. }
  83. bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  84. bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  85. wxGridCellAttr* GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind ) override;
  86. wxString GetValue( int aRow, int aCol ) override;
  87. bool GetValueAsBool( int aRow, int aCol ) override;
  88. void SetValue( int aRow, int aCol, const wxString& aValue ) override;
  89. void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
  90. wxString StringFromBool( bool aValue ) const;
  91. bool BoolFromString( wxString aValue ) const;
  92. protected:
  93. void initGrid( WX_GRID* aGrid );
  94. void onUnitsChanged( wxCommandEvent& aEvent );
  95. private:
  96. SCH_BASE_FRAME* m_frame;
  97. DIALOG_SHIM* m_dialog;
  98. WX_GRID* m_grid;
  99. KICAD_T m_parentType;
  100. int m_mandatoryFieldCount;
  101. LIB_SYMBOL* m_part;
  102. wxString m_symbolNetlist;
  103. wxString m_curdir;
  104. SCH_FIELD_VALIDATOR m_fieldNameValidator;
  105. SCH_FIELD_VALIDATOR m_referenceValidator;
  106. SCH_FIELD_VALIDATOR m_valueValidator;
  107. LIB_ID_VALIDATOR m_libIdValidator;
  108. SCH_FIELD_VALIDATOR m_urlValidator;
  109. SCH_FIELD_VALIDATOR m_nonUrlValidator;
  110. SCH_FIELD_VALIDATOR m_filepathValidator;
  111. wxGridCellAttr* m_readOnlyAttr;
  112. wxGridCellAttr* m_fieldNameAttr;
  113. wxGridCellAttr* m_referenceAttr;
  114. wxGridCellAttr* m_valueAttr;
  115. wxGridCellAttr* m_footprintAttr;
  116. wxGridCellAttr* m_urlAttr;
  117. wxGridCellAttr* m_nonUrlAttr;
  118. wxGridCellAttr* m_filepathAttr;
  119. wxGridCellAttr* m_boolAttr;
  120. wxGridCellAttr* m_vAlignAttr;
  121. wxGridCellAttr* m_hAlignAttr;
  122. wxGridCellAttr* m_orientationAttr;
  123. wxGridCellAttr* m_netclassAttr;
  124. wxGridCellAttr* m_fontAttr;
  125. wxGridCellAttr* m_colorAttr;
  126. };
  127. #endif // FIELDS_GRID_TABLE_H