KiCad PCB EDA Suite
fields_grid_table.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018-2019 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 
24 #ifndef FIELDS_GRID_TABLE_H
25 #define FIELDS_GRID_TABLE_H
26 
27 #include <base_units.h>
28 #include <sch_validators.h>
29 #include <wx/grid.h>
30 #include <sch_component.h>
31 #include <grid_tricks.h>
32 #include <validators.h>
33 
34 class SCH_BASE_FRAME;
35 class DIALOG_SHIM;
36 
37 
39 {
40 public:
41  FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog ) :
42  GRID_TRICKS( aGrid ),
43  m_dlg( aDialog )
44  {}
45 
46 protected:
47  virtual void showPopupMenu( wxMenu& menu ) override;
48  virtual void doPopupSelection( wxCommandEvent& event ) override;
50 };
51 
52 
54 {
66 
67  FDC_COUNT // keep as last
68 };
69 
70 
71 template <class T>
72 class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<T>
73 {
74 public:
75  FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, LIB_PART* aPart );
77 
78  int GetNumberRows() override { return (int) this->size(); }
79  int GetNumberCols() override { return FDC_COUNT; }
80 
81  wxString GetColLabelValue( int aCol ) override;
82 
83  bool IsEmptyCell( int row, int col ) override
84  {
85  return false; // don't allow adjacent cell overflow, even if we are actually empty
86  }
87 
88  bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
89  bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
90  wxGridCellAttr* GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind ) override;
91 
92  wxString GetValue( int aRow, int aCol ) override;
93  bool GetValueAsBool( int aRow, int aCol ) override;
94 
95  void SetValue( int aRow, int aCol, const wxString &aValue ) override;
96  void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
97 
98  wxString StringFromBool( bool aValue );
99  bool BoolFromString( wxString aValue );
100 
101 private:
105 
112 
113  wxGridCellAttr* m_readOnlyAttr;
114  wxGridCellAttr* m_fieldNameAttr;
115  wxGridCellAttr* m_referenceAttr;
116  wxGridCellAttr* m_valueAttr;
117  wxGridCellAttr* m_footprintAttr;
118  wxGridCellAttr* m_urlAttr;
119  wxGridCellAttr* m_nonUrlAttr;
120  wxGridCellAttr* m_boolAttr;
121  wxGridCellAttr* m_vAlignAttr;
122  wxGridCellAttr* m_hAlignAttr;
123  wxGridCellAttr* m_orientationAttr;
124 };
125 
126 
127 #endif // FIELDS_GRID_TABLE_H
virtual void showPopupMenu(wxMenu &menu) override
int GetNumberRows() override
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
Implementation of conversion functions that require both schematic and board internal units.
Class GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GR...
Definition: grid_tricks.h:51
wxGridCellAttr * m_referenceAttr
SCH_BASE_FRAME * m_frame
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:83
wxString GetColLabelValue(int aCol) override
wxGridCellAttr * m_readOnlyAttr
FIELDS_GRID_TRICKS(WX_GRID *aGrid, DIALOG_SHIM *aDialog)
wxGridCellAttr * m_hAlignAttr
SCH_FIELD_VALIDATOR m_referenceValidator
bool IsEmptyCell(int row, int col) override
Definitions of control validators for schematic dialogs.
wxString GetValue(int aRow, int aCol) override
SCH_FIELD_VALIDATOR m_fieldNameValidator
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
wxGridCellAttr * m_boolAttr
Define a library symbol object.
Custom validator that verifies that a string defines a valid LIB_ID.
Definition: validators.h:173
bool BoolFromString(wxString aValue)
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) override
wxGridCellAttr * m_fieldNameAttr
FIELDS_DATA_COL_ORDER
wxGridCellAttr * m_urlAttr
SCH_FIELD_VALIDATOR m_valueValidator
bool GetValueAsBool(int aRow, int aCol) override
wxGridCellAttr * m_vAlignAttr
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * m_orientationAttr
wxGridCellAttr * m_valueAttr
LIB_ID_VALIDATOR m_libIdValidator
SCH_FIELD_VALIDATOR m_urlValidator
wxGridCellAttr * m_nonUrlAttr
A text control validator used for validating the text allowed in library and schematic component fiel...
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, LIB_PART *aPart)
void SetValueAsBool(int aRow, int aCol, bool aValue) override
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
wxGridCellAttr * m_footprintAttr
int GetNumberCols() override
virtual void doPopupSelection(wxCommandEvent &event) override
Custom text control validator definitions.
EDA_UNITS_T
Definition: common.h:133
wxString StringFromBool(bool aValue)
SCH_FIELD_VALIDATOR m_nonUrlValidator