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.

177 lines
5.5 KiB

10 months ago
10 months ago
10 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 <wx/grid.h>
  26. #include <sch_symbol.h>
  27. #include <grid_tricks.h>
  28. #include <validators.h>
  29. class SCH_BASE_FRAME;
  30. class DIALOG_SHIM;
  31. class EMBEDDED_FILES;
  32. class SCH_LABEL_BASE;
  33. class FIELDS_GRID_TRICKS : public GRID_TRICKS
  34. {
  35. public:
  36. FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog,
  37. std::vector<EMBEDDED_FILES*> aFilesStack,
  38. std::function<void( wxCommandEvent& )> aAddHandler ) :
  39. GRID_TRICKS( aGrid, std::move( aAddHandler ) ),
  40. m_dlg( aDialog ),
  41. m_filesStack( aFilesStack )
  42. {}
  43. protected:
  44. int getFieldRow( FIELD_T aFieldId );
  45. void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
  46. void doPopupSelection( wxCommandEvent& event ) override;
  47. protected:
  48. DIALOG_SHIM* m_dlg;
  49. std::vector<EMBEDDED_FILES*> m_filesStack;
  50. };
  51. enum FIELDS_DATA_COL_ORDER
  52. {
  53. FDC_NAME = 0,
  54. FDC_VALUE,
  55. FDC_SHOWN,
  56. FDC_SHOW_NAME,
  57. FDC_H_ALIGN,
  58. FDC_V_ALIGN,
  59. FDC_ITALIC,
  60. FDC_BOLD,
  61. FDC_TEXT_SIZE,
  62. FDC_ORIENTATION,
  63. FDC_POSX,
  64. FDC_POSY,
  65. FDC_FONT,
  66. FDC_COLOR,
  67. FDC_ALLOW_AUTOPLACE,
  68. FDC_SCH_EDIT_COUNT,
  69. FDC_PRIVATE = FDC_SCH_EDIT_COUNT,
  70. FDC_SYMBOL_EDITOR_COUNT
  71. };
  72. class FIELDS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<SCH_FIELD>
  73. {
  74. public:
  75. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
  76. LIB_SYMBOL* aSymbol, std::vector<EMBEDDED_FILES*> aFilesStack = {} );
  77. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  78. SCH_SYMBOL* aSymbol );
  79. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  80. SCH_SHEET* aSheet );
  81. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  82. SCH_LABEL_BASE* aLabel );
  83. ~FIELDS_GRID_TABLE() override;
  84. int GetNumberRows() override { return getVisibleRowCount(); }
  85. int GetNumberCols() override { return getColumnCount(); }
  86. int GetMandatoryRowCount() const;
  87. wxString GetColLabelValue( int aCol ) override;
  88. bool IsEmptyCell( int row, int col ) override
  89. {
  90. return false; // don't allow adjacent cell overflow, even if we are actually empty
  91. }
  92. bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  93. bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  94. wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
  95. wxString GetValue( int aRow, int aCol ) override;
  96. bool GetValueAsBool( int aRow, int aCol ) override;
  97. void SetValue( int aRow, int aCol, const wxString& aValue ) override;
  98. void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
  99. wxString StringFromBool( bool aValue ) const;
  100. bool BoolFromString( const wxString& aValue ) const;
  101. SCH_FIELD* GetField( FIELD_T aFieldId );
  102. int GetFieldRow( FIELD_T aFieldId );
  103. void DetachFields();
  104. protected:
  105. void initGrid( WX_GRID* aGrid );
  106. void onUnitsChanged( wxCommandEvent& aEvent );
  107. int getColumnCount() const;
  108. int getVisibleRowCount() const;
  109. SCH_FIELD& getField( int aRow );
  110. private:
  111. SCH_BASE_FRAME* m_frame;
  112. DIALOG_SHIM* m_dialog;
  113. KICAD_T m_parentType;
  114. LIB_SYMBOL* m_part;
  115. std::vector<EMBEDDED_FILES*> m_filesStack;
  116. wxString m_symbolNetlist;
  117. wxString m_curdir;
  118. FIELD_VALIDATOR m_fieldNameValidator;
  119. FIELD_VALIDATOR m_referenceValidator;
  120. FIELD_VALIDATOR m_valueValidator;
  121. FIELD_VALIDATOR m_urlValidator;
  122. FIELD_VALIDATOR m_nonUrlValidator;
  123. FIELD_VALIDATOR m_filepathValidator;
  124. wxGridCellAttr* m_readOnlyAttr;
  125. wxGridCellAttr* m_fieldNameAttr;
  126. wxGridCellAttr* m_referenceAttr;
  127. wxGridCellAttr* m_valueAttr;
  128. wxGridCellAttr* m_footprintAttr;
  129. wxGridCellAttr* m_urlAttr;
  130. wxGridCellAttr* m_nonUrlAttr;
  131. wxGridCellAttr* m_filepathAttr;
  132. wxGridCellAttr* m_boolAttr;
  133. wxGridCellAttr* m_vAlignAttr;
  134. wxGridCellAttr* m_hAlignAttr;
  135. wxGridCellAttr* m_orientationAttr;
  136. wxGridCellAttr* m_netclassAttr;
  137. wxGridCellAttr* m_fontAttr;
  138. wxGridCellAttr* m_colorAttr;
  139. std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
  140. std::map< std::pair<int, int>, wxString > m_evalOriginal;
  141. };
  142. #endif // FIELDS_GRID_TABLE_H