KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef FIELDS_GRID_TABLE_H
21#define FIELDS_GRID_TABLE_H
22
23#include <wx/grid.h>
24#include <sch_symbol.h>
25#include <grid_tricks.h>
26#include <validators.h>
27#include <vector>
28
29class SCH_BASE_FRAME;
30class DIALOG_SHIM;
31class EMBEDDED_FILES;
32class SCH_LABEL_BASE;
33
34
36{
37public:
39 std::vector<EMBEDDED_FILES*> aFilesStack,
40 std::function<void( wxCommandEvent& )> aAddHandler ) :
41 GRID_TRICKS( aGrid, std::move( aAddHandler ) ),
42 m_dlg( aDialog ),
43 m_filesStack( aFilesStack )
44 {}
45
46protected:
47 int getFieldRow( FIELD_T aFieldId );
48
49 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
50 void doPopupSelection( wxCommandEvent& event ) override;
51
52protected:
54 std::vector<EMBEDDED_FILES*> m_filesStack;
55};
56
57
82
83
84class FIELDS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<SCH_FIELD>
85{
86public:
87 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
88 LIB_SYMBOL* aSymbol, std::vector<EMBEDDED_FILES*> aFilesStack = {} );
89 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
90 SCH_SYMBOL* aSymbol );
91 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
92 SCH_SHEET* aSheet );
93 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
94 SCH_LABEL_BASE* aLabel );
95 ~FIELDS_GRID_TABLE() override;
96
97 int GetNumberRows() override { return getVisibleRowCount(); }
98 int GetNumberCols() override { return getColumnCount(); }
99
100 int GetMandatoryRowCount() const;
101
102 wxString GetColLabelValue( int aCol ) override;
103
104 bool IsEmptyCell( int row, int col ) override
105 {
106 return false; // don't allow adjacent cell overflow, even if we are actually empty
107 }
108
109 bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
110 bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
111 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
112
113 wxString GetValue( int aRow, int aCol ) override;
114 bool GetValueAsBool( int aRow, int aCol ) override;
115
116 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
117 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
118
119 wxString StringFromBool( bool aValue ) const;
120 bool BoolFromString( const wxString& aValue ) const;
121
122 SCH_FIELD* GetField( FIELD_T aFieldId );
123 int GetFieldRow( FIELD_T aFieldId );
124
125 void AddInheritedField( const SCH_FIELD& aParent );
126
127 void SetFieldInherited( size_t aRow, const SCH_FIELD& aParent )
128 {
129 m_isInherited.resize( aRow + 1, false );
130 m_parentFields.resize( aRow + 1 );
131 m_parentFields[aRow] = aParent;
132 m_isInherited[aRow] = true;
133 }
134
135 bool IsInherited( size_t aRow ) const
136 {
137 if( aRow >= m_isInherited.size() || aRow >= m_parentFields.size() )
138 return false;
139
140 return m_isInherited[aRow] && m_parentFields[aRow].GetText() == at( aRow ).GetText();
141 }
142
143 const SCH_FIELD& ParentField( size_t row ) const { return m_parentFields[row]; }
144
145 void push_back( const SCH_FIELD& field );
146 // For std::vector compatibility, but we don't use it directly.
147 void emplace_back( const SCH_FIELD& field ) { push_back( field ); }
148
149 bool EraseRow( size_t row );
150 void SwapRows( size_t a, size_t b );
151
152 void DetachFields();
153
154protected:
155 void initGrid( WX_GRID* aGrid );
156
157 void onUnitsChanged( wxCommandEvent& aEvent );
158
159 int getColumnCount() const;
160 int getVisibleRowCount() const;
161
162 SCH_FIELD& getField( int aRow );
163
164private:
169 std::vector<EMBEDDED_FILES*> m_filesStack;
171 wxString m_curdir;
172
179
180 wxGridCellAttr* m_readOnlyAttr;
181 wxGridCellAttr* m_fieldNameAttr;
182 wxGridCellAttr* m_referenceAttr;
183 wxGridCellAttr* m_valueAttr;
184 wxGridCellAttr* m_footprintAttr;
185 wxGridCellAttr* m_urlAttr;
186 wxGridCellAttr* m_nonUrlAttr;
187 wxGridCellAttr* m_filepathAttr;
188 wxGridCellAttr* m_boolAttr;
189 wxGridCellAttr* m_vAlignAttr;
190 wxGridCellAttr* m_hAlignAttr;
191 wxGridCellAttr* m_orientationAttr;
192 wxGridCellAttr* m_netclassAttr;
193 wxGridCellAttr* m_fontAttr;
194 wxGridCellAttr* m_colorAttr;
195
196 std::vector<bool> m_isInherited;
197 std::vector<SCH_FIELD> m_parentFields;
198
199 std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
200 std::map< std::pair<int, int>, wxString > m_evalOriginal;
201};
202
203
204#endif // FIELDS_GRID_TABLE_H
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:65
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
std::vector< bool > m_isInherited
bool IsInherited(size_t aRow) const
SCH_FIELD * GetField(FIELD_T aFieldId)
wxString StringFromBool(bool aValue) const
bool GetValueAsBool(int aRow, int aCol) override
FIELD_VALIDATOR m_fieldNameValidator
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
void initGrid(WX_GRID *aGrid)
wxGridCellAttr * m_fieldNameAttr
int GetNumberRows() override
void push_back(const SCH_FIELD &field)
wxGridCellAttr * m_readOnlyAttr
int GetMandatoryRowCount() const
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, WX_GRID *aGrid, LIB_SYMBOL *aSymbol, std::vector< EMBEDDED_FILES * > aFilesStack={})
FIELD_VALIDATOR m_urlValidator
SCH_BASE_FRAME * m_frame
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
wxGridCellAttr * m_colorAttr
wxGridCellAttr * m_nonUrlAttr
bool EraseRow(size_t row)
wxGridCellAttr * m_referenceAttr
FIELD_VALIDATOR m_referenceValidator
FIELD_VALIDATOR m_valueValidator
std::map< std::pair< int, int >, wxString > m_evalOriginal
bool IsEmptyCell(int row, int col) override
wxGridCellAttr * m_footprintAttr
wxGridCellAttr * m_boolAttr
void SetFieldInherited(size_t aRow, const SCH_FIELD &aParent)
std::vector< EMBEDDED_FILES * > m_filesStack
int GetFieldRow(FIELD_T aFieldId)
bool BoolFromString(const wxString &aValue) const
wxGridCellAttr * m_fontAttr
const SCH_FIELD & ParentField(size_t row) const
wxGridCellAttr * m_urlAttr
wxGridCellAttr * m_valueAttr
wxGridCellAttr * m_hAlignAttr
void AddInheritedField(const SCH_FIELD &aParent)
wxGridCellAttr * m_orientationAttr
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * m_vAlignAttr
wxGridCellAttr * m_filepathAttr
SCH_FIELD & getField(int aRow)
wxGridCellAttr * m_netclassAttr
void emplace_back(const SCH_FIELD &field)
void SetValueAsBool(int aRow, int aCol, bool aValue) override
int GetNumberCols() override
wxString GetValue(int aRow, int aCol) override
void SwapRows(size_t a, size_t b)
void onUnitsChanged(wxCommandEvent &aEvent)
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
std::vector< SCH_FIELD > m_parentFields
FIELD_VALIDATOR m_nonUrlValidator
FIELD_VALIDATOR m_filepathValidator
wxString GetColLabelValue(int aCol) override
FIELDS_GRID_TRICKS(WX_GRID *aGrid, DIALOG_SHIM *aDialog, std::vector< EMBEDDED_FILES * > aFilesStack, std::function< void(wxCommandEvent &)> aAddHandler)
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
int getFieldRow(FIELD_T aFieldId)
std::vector< EMBEDDED_FILES * > m_filesStack
void doPopupSelection(wxCommandEvent &event) override
A text control validator used for validating the text allowed in fields.
Definition validators.h:138
GRID_TRICKS(WX_GRID *aGrid)
Define a library symbol object.
Definition lib_symbol.h:79
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Schematic editor (Eeschema) main window.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
Schematic symbol object.
Definition sch_symbol.h:69
FIELDS_DATA_COL_ORDER
@ FDC_TEXT_SIZE
@ FDC_BOLD
@ FDC_SCH_EDIT_COUNT
@ FDC_POSY
@ FDC_ITALIC
@ FDC_SHOW_NAME
@ FDC_NAME
@ FDC_H_ALIGN
@ FDC_COLOR
@ FDC_SHOWN
@ FDC_ALLOW_AUTOPLACE
@ FDC_VALUE
@ FDC_SYMBOL_EDITOR_COUNT
@ FDC_POSX
@ FDC_ORIENTATION
@ FDC_V_ALIGN
@ FDC_FONT
@ FDC_PRIVATE
STL namespace.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
Custom text control validator definitions.