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;
33class SCH_SHEET;
34
35
36wxString BuildFootprintChooserSymbolNetlist( const LIB_SYMBOL* aSymbol );
37wxString BuildFootprintChooserSymbolNetlist( const std::vector<LIB_SYMBOL*>& aSymbols );
38
39
40std::vector<SCH_FIELD> GetSheetFieldsForEditing( const SCH_SHEET& aSheet );
41
42
44{
45public:
46 FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog, std::vector<EMBEDDED_FILES*> aFilesStack,
47 std::function<void( wxCommandEvent& )> aAddHandler ) :
48 GRID_TRICKS( aGrid, std::move( aAddHandler ) ),
49 m_dlg( aDialog ),
50 m_filesStack( aFilesStack )
51 {}
52
53protected:
54 int getFieldRow( FIELD_T aFieldId );
55
56 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
57 void doPopupSelection( wxCommandEvent& event ) override;
58
59protected:
61 std::vector<EMBEDDED_FILES*> m_filesStack;
62};
63
64
89
90
91class FIELDS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<SCH_FIELD>
92{
93public:
94 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
95 LIB_SYMBOL* aSymbol, std::vector<EMBEDDED_FILES*>& aFilesStack );
96 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
97 SCH_SYMBOL* aSymbol, LIB_SYMBOL* aPart, std::vector<EMBEDDED_FILES*>& aFilesStack );
98 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
99 SCH_SHEET* aSheet, std::vector<EMBEDDED_FILES*>& aFilesStack );
100 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
101 SCH_LABEL_BASE* aLabel, std::vector<EMBEDDED_FILES*>& aFilesStack );
102 ~FIELDS_GRID_TABLE() override;
103
104 int GetNumberRows() override { return getVisibleRowCount(); }
105 int GetNumberCols() override { return getColumnCount(); }
106
107 int GetMandatoryRowCount() const;
108
109 wxString GetColLabelValue( int aCol ) override;
110
111 bool IsEmptyCell( int row, int col ) override
112 {
113 return false; // don't allow adjacent cell overflow, even if we are actually empty
114 }
115
116 bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
117 bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
118 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
119
120 wxString GetValue( int aRow, int aCol ) override;
121 bool GetValueAsBool( int aRow, int aCol ) override;
122
123 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
124 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
125
126 wxString StringFromBool( bool aValue ) const;
127 bool BoolFromString( const wxString& aValue ) const;
128
129 SCH_FIELD* GetField( FIELD_T aFieldId );
130 int GetFieldRow( FIELD_T aFieldId );
131
135 void AddInheritedField( const SCH_FIELD& aParent, const wxString& aSource );
136
142 void SetFieldInherited( size_t aFieldIndex, const SCH_FIELD& aParent, const wxString& aSource );
143
147 bool IsInherited( size_t aRow ) const;
148
149 const SCH_FIELD& ParentField( size_t aRow ) const;
150
154 const wxString& InheritedFrom( size_t aRow ) const;
155
156 void push_back( const SCH_FIELD& field );
157 // For std::vector compatibility, but we don't use it directly.
158 void emplace_back( const SCH_FIELD& field ) { push_back( field ); }
159
160 bool EraseRow( size_t row );
161 void SwapRows( size_t a, size_t b );
162
163 void DetachFields();
164
165protected:
166 void initGrid( WX_GRID* aGrid );
167
168 void onUnitsChanged( wxCommandEvent& aEvent );
169
170 bool privateFieldsAreHidden() const;
171 int getFieldIndex( int aRow ) const;
172 int getColumnCount() const;
173 int getVisibleRowCount() const;
174
175 SCH_FIELD& getField( int aRow );
176
177private:
182 std::vector<EMBEDDED_FILES*>& m_filesStack;
184 wxString m_curdir;
185
192
193 wxGridCellAttr* m_readOnlyAttr;
194 wxGridCellAttr* m_fieldNameAttr;
195 wxGridCellAttr* m_referenceAttr;
196 wxGridCellAttr* m_valueAttr;
197 wxGridCellAttr* m_footprintAttr;
198 wxGridCellAttr* m_urlAttr;
199 wxGridCellAttr* m_nonUrlAttr;
200 wxGridCellAttr* m_filepathAttr;
201 wxGridCellAttr* m_boolAttr;
202 wxGridCellAttr* m_vAlignAttr;
203 wxGridCellAttr* m_hAlignAttr;
204 wxGridCellAttr* m_orientationAttr;
205 wxGridCellAttr* m_netclassAttr;
206 wxGridCellAttr* m_fontAttr;
207 wxGridCellAttr* m_colorAttr;
208
210 {
212 wxString m_source;
213 bool m_hasParent = false;
214 bool m_derived = false;
215 };
216
217 std::vector<INHERITANCE> m_inheritance;
218
219 std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
220 std::map< std::pair<int, int>, wxString > m_evalOriginal;
221};
222
223
224#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:81
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
bool IsInherited(size_t aRow) const
const wxString & InheritedFrom(size_t aRow) const
SCH_FIELD * GetField(FIELD_T aFieldId)
wxString StringFromBool(bool aValue) const
bool GetValueAsBool(int aRow, int aCol) override
void SetFieldInherited(size_t aFieldIndex, const SCH_FIELD &aParent, const wxString &aSource)
Record the ancestor field that aFieldIndex resolves against.
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
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
std::vector< INHERITANCE > m_inheritance
bool IsEmptyCell(int row, int col) override
const SCH_FIELD & ParentField(size_t aRow) const
wxGridCellAttr * m_footprintAttr
wxGridCellAttr * m_boolAttr
int GetFieldRow(FIELD_T aFieldId)
bool BoolFromString(const wxString &aValue) const
wxGridCellAttr * m_fontAttr
wxGridCellAttr * m_urlAttr
wxGridCellAttr * m_valueAttr
wxGridCellAttr * m_hAlignAttr
wxGridCellAttr * m_orientationAttr
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * m_vAlignAttr
bool privateFieldsAreHidden() const
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
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, WX_GRID *aGrid, LIB_SYMBOL *aSymbol, std::vector< EMBEDDED_FILES * > &aFilesStack)
int getFieldIndex(int aRow) const
std::vector< EMBEDDED_FILES * > & m_filesStack
void SwapRows(size_t a, size_t b)
void AddInheritedField(const SCH_FIELD &aParent, const wxString &aSource)
Append a row for an ancestor field the symbol does not define.
void onUnitsChanged(wxCommandEvent &aEvent)
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
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:137
GRID_TRICKS(WX_GRID *aGrid)
Define a library symbol object.
Definition lib_symbol.h:114
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:50
Schematic symbol object.
Definition sch_symbol.h:76
std::vector< SCH_FIELD > GetSheetFieldsForEditing(const SCH_SHEET &aSheet)
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
wxString BuildFootprintChooserSymbolNetlist(const LIB_SYMBOL *aSymbol)
STL namespace.
bool m_derived
Row shows the ancestor's value instead of owning one.
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:70
Custom text control validator definitions.