KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fields_view_controls_grid_data_model.cpp
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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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#include <template_fieldnames.h>
21
23
25{
26 switch( aCol )
27 {
28 case DISPLAY_NAME_COLUMN: return _( "Field" );
29 case LABEL_COLUMN: return m_forBOM ? _( "BOM Name" ) : _( "Label" );
30 case SHOW_FIELD_COLUMN: return _( "Include" );
31 case GROUP_BY_COLUMN: return _( "Group By" );
32 default: return wxT( "unknown column" );
33 };
34}
35
36
37wxString VIEW_CONTROLS_GRID_DATA_MODEL::GetValue( int aRow, int aCol )
38{
39 wxCHECK( aRow < GetNumberRows(), wxT( "bad row!" ) );
40
41 BOM_FIELD& rowData = m_fields[aRow];
42
43 switch( aCol )
44 {
46 for( FIELD_T fieldId : MANDATORY_FIELDS )
47 {
48 if( GetDefaultFieldName( fieldId, !DO_TRANSLATE ) == rowData.name )
49 return GetDefaultFieldName( fieldId, DO_TRANSLATE );
50 }
51
52 return rowData.name;
53
54 case LABEL_COLUMN:
55 return rowData.label;
56
57 default:
58 // we can't assert here because wxWidgets sometimes calls this without checking
59 // the column type when trying to see if there's an overflow
60 return wxT( "bad wxWidgets!" );
61 }
62}
63
64
66{
67 wxCHECK( aRow < GetNumberRows(), false );
68
69 BOM_FIELD& rowData = m_fields[aRow];
70
71 switch( aCol )
72 {
73 case SHOW_FIELD_COLUMN: return rowData.show;
74 case GROUP_BY_COLUMN: return rowData.groupBy;
75
76 default:
77 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
78 return false;
79 }
80}
81
82
83void VIEW_CONTROLS_GRID_DATA_MODEL::SetValue( int aRow, int aCol, const wxString& aValue )
84{
85 wxCHECK( aRow < GetNumberRows(), /*void*/ );
86
87 BOM_FIELD& rowData = m_fields[aRow];
88
89 switch( aCol )
90 {
92 // Not editable
93 break;
94
95 case LABEL_COLUMN:
96 rowData.label = aValue;
97 break;
98
99 default:
100 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a string value" ), aCol ) );
101 }
102
103 GetView()->Refresh();
104}
105
106
107void VIEW_CONTROLS_GRID_DATA_MODEL::SetValueAsBool( int aRow, int aCol, bool aValue )
108{
109 wxCHECK( aRow < GetNumberRows(), /*void*/ );
110
111 BOM_FIELD& rowData = m_fields[aRow];
112
113 switch( aCol )
114 {
115 case SHOW_FIELD_COLUMN: rowData.show = aValue; break;
116 case GROUP_BY_COLUMN: rowData.groupBy = aValue; break;
117
118 default:
119 wxFAIL_MSG( wxString::Format( wxT( "column %d doesn't hold a bool value" ), aCol ) );
120 }
121}
122
123
124void VIEW_CONTROLS_GRID_DATA_MODEL::AppendRow( const wxString& aFieldName, const wxString& aBOMName,
125 bool aShow, bool aGroupBy )
126{
127 m_fields.emplace_back( BOM_FIELD{ aFieldName, aBOMName, aShow, aGroupBy } );
128
129 if( wxGrid* grid = GetView() )
130 {
131 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
132 grid->ProcessTableMessage( msg );
133 }
134}
135
136
138{
139 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), /* void */ );
140
141 m_fields.erase( m_fields.begin() + aRow );
142
143 if( wxGrid* grid = GetView() )
144 {
145 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
146 grid->ProcessTableMessage( msg );
147 }
148}
149
150
152{
153 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), wxEmptyString );
154
155 BOM_FIELD& rowData = m_fields[aRow];
156
157 return rowData.name;
158}
159
160
161void VIEW_CONTROLS_GRID_DATA_MODEL::SetCanonicalFieldName( int aRow, const wxString& aName )
162{
163 wxCHECK( aRow >= 0 && aRow < GetNumberRows(), /* void */ );
164
165 BOM_FIELD& rowData = m_fields[aRow];
166
167 rowData.name = aName;
168}
void SetValueAsBool(int aRow, int aCol, bool aValue) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
void AppendRow(const wxString &aFieldName, const wxString &aBOMName, bool aShow, bool aGroupBy)
bool GetValueAsBool(int aRow, int aCol) override
void SetCanonicalFieldName(int aRow, const wxString &aName)
wxString GetValue(int aRow, int aCol) override
#define _(s)
wxString label
wxString name
wxString GetDefaultFieldName(FIELD_T aFieldId, bool aTranslateForHI)
Return a default symbol field name for a mandatory field type.
#define DO_TRANSLATE
#define MANDATORY_FIELDS
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...