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.

156 lines
5.0 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 <sch_validators.h>
  26. #include <wx/grid.h>
  27. #include <sch_symbol.h>
  28. #include <grid_tricks.h>
  29. #include <validators.h>
  30. class SCH_BASE_FRAME;
  31. class DIALOG_SHIM;
  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::function<void( wxCommandEvent& )> aAddHandler ) :
  38. GRID_TRICKS( aGrid, std::move( aAddHandler ) ),
  39. m_dlg( aDialog )
  40. {}
  41. protected:
  42. virtual void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) 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_SHOW_NAME,
  52. FDC_H_ALIGN,
  53. FDC_V_ALIGN,
  54. FDC_ITALIC,
  55. FDC_BOLD,
  56. FDC_TEXT_SIZE,
  57. FDC_ORIENTATION,
  58. FDC_POSX,
  59. FDC_POSY,
  60. FDC_FONT,
  61. FDC_COLOR,
  62. FDC_ALLOW_AUTOPLACE,
  63. FDC_COUNT // keep as last
  64. };
  65. template <class T>
  66. class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<T>
  67. {
  68. public:
  69. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
  70. LIB_SYMBOL* aSymbol );
  71. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  72. SCH_SYMBOL* aSymbol );
  73. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  74. SCH_SHEET* aSheet );
  75. FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
  76. SCH_LABEL_BASE* aLabel );
  77. ~FIELDS_GRID_TABLE();
  78. int GetNumberRows() override { return (int) this->size(); }
  79. int GetNumberCols() override { return FDC_COUNT; }
  80. wxString GetColLabelValue( int aCol ) override;
  81. bool IsEmptyCell( int row, int col ) override
  82. {
  83. return false; // don't allow adjacent cell overflow, even if we are actually empty
  84. }
  85. bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  86. bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  87. wxGridCellAttr* GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind ) override;
  88. wxString GetValue( int aRow, int aCol ) override;
  89. bool GetValueAsBool( int aRow, int aCol ) override;
  90. void SetValue( int aRow, int aCol, const wxString& aValue ) override;
  91. void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
  92. wxString StringFromBool( bool aValue ) const;
  93. bool BoolFromString( wxString aValue ) const;
  94. protected:
  95. void initGrid( WX_GRID* aGrid );
  96. void onUnitsChanged( wxCommandEvent& aEvent );
  97. private:
  98. SCH_BASE_FRAME* m_frame;
  99. DIALOG_SHIM* m_dialog;
  100. WX_GRID* m_grid;
  101. KICAD_T m_parentType;
  102. int m_mandatoryFieldCount;
  103. LIB_SYMBOL* m_part;
  104. wxString m_symbolNetlist;
  105. wxString m_curdir;
  106. FIELD_VALIDATOR m_fieldNameValidator;
  107. FIELD_VALIDATOR m_referenceValidator;
  108. FIELD_VALIDATOR m_valueValidator;
  109. FIELD_VALIDATOR m_urlValidator;
  110. FIELD_VALIDATOR m_nonUrlValidator;
  111. FIELD_VALIDATOR m_filepathValidator;
  112. wxGridCellAttr* m_readOnlyAttr;
  113. wxGridCellAttr* m_fieldNameAttr;
  114. wxGridCellAttr* m_referenceAttr;
  115. wxGridCellAttr* m_valueAttr;
  116. wxGridCellAttr* m_footprintAttr;
  117. wxGridCellAttr* m_urlAttr;
  118. wxGridCellAttr* m_nonUrlAttr;
  119. wxGridCellAttr* m_filepathAttr;
  120. wxGridCellAttr* m_boolAttr;
  121. wxGridCellAttr* m_vAlignAttr;
  122. wxGridCellAttr* m_hAlignAttr;
  123. wxGridCellAttr* m_orientationAttr;
  124. wxGridCellAttr* m_netclassAttr;
  125. wxGridCellAttr* m_fontAttr;
  126. wxGridCellAttr* m_colorAttr;
  127. std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
  128. std::map< std::pair<int, int>, wxString > m_evalOriginal;
  129. };
  130. #endif // FIELDS_GRID_TABLE_H