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, 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 <wx/grid.h>
28#include <sch_symbol.h>
29#include <grid_tricks.h>
30#include <validators.h>
31#include <vector>
32
33class SCH_BASE_FRAME;
34class DIALOG_SHIM;
35class EMBEDDED_FILES;
36class SCH_LABEL_BASE;
37
38
40{
41public:
43 std::vector<EMBEDDED_FILES*> aFilesStack,
44 std::function<void( wxCommandEvent& )> aAddHandler ) :
45 GRID_TRICKS( aGrid, std::move( aAddHandler ) ),
46 m_dlg( aDialog ),
47 m_filesStack( aFilesStack )
48 {}
49
50protected:
51 int getFieldRow( FIELD_T aFieldId );
52
53 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
54 void doPopupSelection( wxCommandEvent& event ) override;
55
56protected:
58 std::vector<EMBEDDED_FILES*> m_filesStack;
59};
60
61
63{
79
81
83
85};
86
87
88class FIELDS_GRID_TABLE : public WX_GRID_TABLE_BASE, public std::vector<SCH_FIELD>
89{
90public:
91 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
92 LIB_SYMBOL* aSymbol, std::vector<EMBEDDED_FILES*> aFilesStack = {} );
93 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
94 SCH_SYMBOL* aSymbol );
95 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
96 SCH_SHEET* aSheet );
97 FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
98 SCH_LABEL_BASE* aLabel );
99 ~FIELDS_GRID_TABLE() override;
100
101 int GetNumberRows() override { return getVisibleRowCount(); }
102 int GetNumberCols() override { return getColumnCount(); }
103
104 int GetMandatoryRowCount() const;
105
106 wxString GetColLabelValue( int aCol ) override;
107
108 bool IsEmptyCell( int row, int col ) override
109 {
110 return false; // don't allow adjacent cell overflow, even if we are actually empty
111 }
112
113 bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
114 bool CanSetValueAs( int aRow, int aCol, const wxString& aTypeName ) override;
115 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
116
117 wxString GetValue( int aRow, int aCol ) override;
118 bool GetValueAsBool( int aRow, int aCol ) override;
119
120 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
121 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
122
123 wxString StringFromBool( bool aValue ) const;
124 bool BoolFromString( const wxString& aValue ) const;
125
126 SCH_FIELD* GetField( FIELD_T aFieldId );
127 int GetFieldRow( FIELD_T aFieldId );
128
129 void AddInheritedField( const SCH_FIELD& aParent );
130
131 void SetFieldInherited( size_t aRow, const SCH_FIELD& aParent )
132 {
133 m_isInherited.resize( aRow + 1, false );
134 m_parentFields.resize( aRow + 1 );
135 m_parentFields[aRow] = aParent;
136 m_isInherited[aRow] = true;
137 }
138
139
140 bool IsInherited( size_t aRow ) const
141 {
142 if( aRow >= m_isInherited.size() || aRow >= m_parentFields.size() )
143 return false;
144
145 return m_isInherited[aRow] && m_parentFields[aRow].GetText() == at( aRow ).GetText();
146 }
147
148 const SCH_FIELD& ParentField( size_t row ) const { return m_parentFields[row]; }
149
150 void push_back( const SCH_FIELD& field );
151 // For std::vector compatibility, but we don't use it directly.
152 void emplace_back( const SCH_FIELD& field ) { push_back( field ); }
153
154 bool EraseRow( size_t row );
155 void SwapRows( size_t a, size_t b );
156
157 void DetachFields();
158
159protected:
160 void initGrid( WX_GRID* aGrid );
161
162 void onUnitsChanged( wxCommandEvent& aEvent );
163
164 int getColumnCount() const;
165 int getVisibleRowCount() const;
166
167 SCH_FIELD& getField( int aRow );
168
169private:
174 std::vector<EMBEDDED_FILES*> m_filesStack;
176 wxString m_curdir;
177
184
185 wxGridCellAttr* m_readOnlyAttr;
186 wxGridCellAttr* m_fieldNameAttr;
187 wxGridCellAttr* m_referenceAttr;
188 wxGridCellAttr* m_valueAttr;
189 wxGridCellAttr* m_footprintAttr;
190 wxGridCellAttr* m_urlAttr;
191 wxGridCellAttr* m_nonUrlAttr;
192 wxGridCellAttr* m_filepathAttr;
193 wxGridCellAttr* m_boolAttr;
194 wxGridCellAttr* m_vAlignAttr;
195 wxGridCellAttr* m_hAlignAttr;
196 wxGridCellAttr* m_orientationAttr;
197 wxGridCellAttr* m_netclassAttr;
198 wxGridCellAttr* m_fontAttr;
199 wxGridCellAttr* m_colorAttr;
200
201 std::vector<bool> m_isInherited;
202 std::vector<SCH_FIELD> m_parentFields;
203
204 std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
205 std::map< std::pair<int, int>, wxString > m_evalOriginal;
206};
207
208
209#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:61
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
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
int getVisibleRowCount() const
DIALOG_SHIM * m_dialog
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:142
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
Define a library symbol object.
Definition: lib_symbol.h:85
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:47
Schematic symbol object.
Definition: sch_symbol.h:75
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:78
Custom text control validator definitions.