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.

114 lines
3.6 KiB

  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 FP_TEXT_GRID_TABLE_H
  24. #define FP_TEXT_GRID_TABLE_H
  25. #include <wx/grid.h>
  26. #include <grid_tricks.h>
  27. #include <pcb_field.h>
  28. #include <validators.h>
  29. #include <dialog_shim.h>
  30. class PCB_BASE_FRAME;
  31. enum PCB_FIELDS_COL_ORDER
  32. {
  33. PFC_NAME,
  34. PFC_VALUE,
  35. PFC_SHOWN,
  36. PFC_WIDTH,
  37. PFC_HEIGHT,
  38. PFC_THICKNESS,
  39. PFC_ITALIC,
  40. PFC_LAYER,
  41. PFC_ORIENTATION,
  42. PFC_UPRIGHT, // keep text upright when viewed from bottom or right of board
  43. PFC_XOFFSET,
  44. PFC_YOFFSET,
  45. PFC_KNOCKOUT,
  46. PFC_MIRRORED,
  47. PFC_COUNT // keep as last
  48. };
  49. class PCB_FIELDS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<PCB_FIELD>
  50. {
  51. public:
  52. PCB_FIELDS_GRID_TABLE( PCB_BASE_FRAME* aFrame, DIALOG_SHIM* aDialog,
  53. std::vector<EMBEDDED_FILES*> aFilesStack );
  54. ~PCB_FIELDS_GRID_TABLE();
  55. int GetNumberRows() override { return (int) size(); }
  56. int GetNumberCols() override { return PFC_COUNT; }
  57. int GetMandatoryRowCount() const;
  58. wxString GetColLabelValue( int aCol ) override;
  59. bool IsEmptyCell( int row, int col ) override
  60. {
  61. return false; // don't allow adjacent cell overflow, even if we are actually empty
  62. }
  63. bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  64. bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
  65. wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
  66. wxString GetValue( int aRow, int aCol ) override;
  67. bool GetValueAsBool( int aRow, int aCol ) override;
  68. long GetValueAsLong( int aRow, int aCol ) override;
  69. void SetValue( int aRow, int aCol, const wxString& aValue ) override;
  70. void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
  71. void SetValueAsLong( int aRow, int aCol, long aValue ) override;
  72. protected:
  73. void onUnitsChanged( wxCommandEvent& aEvent );
  74. private:
  75. PCB_BASE_FRAME* m_frame;
  76. DIALOG_SHIM* m_dialog;
  77. FIELD_VALIDATOR m_fieldNameValidator;
  78. FIELD_VALIDATOR m_referenceValidator;
  79. FIELD_VALIDATOR m_valueValidator;
  80. FIELD_VALIDATOR m_urlValidator;
  81. FIELD_VALIDATOR m_nonUrlValidator;
  82. wxGridCellAttr* m_readOnlyAttr;
  83. wxGridCellAttr* m_boolColAttr;
  84. wxGridCellAttr* m_orientationColAttr;
  85. wxGridCellAttr* m_layerColAttr;
  86. wxGridCellAttr* m_referenceAttr;
  87. wxGridCellAttr* m_valueAttr;
  88. wxGridCellAttr* m_urlAttr;
  89. std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
  90. std::map< std::pair<int, int>, wxString > m_evalOriginal;
  91. };
  92. #endif // FP_TEXT_GRID_TABLE_H