KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_multichannel_generate_rule_areas.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 (C) 2014 John Beard, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <widgets/wx_grid.h>
27#include <grid_tricks.h>
28#include <pcb_edit_frame.h>
29
31
33 PCB_BASE_FRAME* aFrame,
34 MULTICHANNEL_TOOL* aParentTool ) :
36 m_parentTool( aParentTool )
37{
38 m_bSizer1 = new wxBoxSizer( wxVERTICAL );
39 m_bSizer2 = new wxBoxSizer( wxVERTICAL );
40
41 // Generate the sheet source grid
42 m_sheetGrid = new WX_GRID( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
43 m_sheetGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_sheetGrid ) ) );
44 m_sheetGrid->CreateGrid( 0, 3 );
45 m_sheetGrid->EnableEditing( false );
46 m_sheetGrid->EnableGridLines( true );
47 m_sheetGrid->EnableDragGridSize( false );
48 m_sheetGrid->SetMargins( 0, 0 );
49 m_sheetGrid->SetColSize( 0, 100 );
50 m_sheetGrid->SetColSize( 1, 300 );
51 m_sheetGrid->SetColSize( 2, 100 );
52 m_sheetGrid->AutoSizeColumns();
53 m_sheetGrid->EnableDragColMove( true );
54 m_sheetGrid->EnableDragColSize( true );
55 m_sheetGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
56 m_sheetGrid->AutoSizeRows();
57 m_sheetGrid->EnableDragRowSize( true );
58 m_sheetGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
59 m_sheetGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
60 m_sheetGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
61 m_sheetGrid->EnableEditing( true );
62 m_sheetGrid->HideRowLabels();
63 m_sheetGrid->SetColLabelValue( 0, _( "Generate" ) );
64 m_sheetGrid->SetColLabelValue( 1, _( "Sheet Path" ) );
65 m_sheetGrid->SetColLabelValue( 2, _( "Sheet Name" ) );
66 m_sheetGrid->AutoSizeColumn( 1 );
67 m_bSizer1->Add( m_sheetGrid, 1, wxEXPAND | wxALL, 5 );
68 m_panel1->SetSizer( m_bSizer1 );
69 m_panel1->Layout();
70 m_bSizer1->Fit( m_panel1 );
71
72 // Generate the component class source grid
73 m_componentClassGrid = new WX_GRID( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
74 m_componentClassGrid->CreateGrid( 0, 2 );
75 m_componentClassGrid->EnableEditing( false );
76 m_componentClassGrid->EnableGridLines( true );
77 m_componentClassGrid->EnableDragGridSize( false );
78 m_componentClassGrid->SetMargins( 0, 0 );
79 m_componentClassGrid->SetColSize( 0, 100 );
80 m_componentClassGrid->SetColSize( 1, 300 );
81 m_componentClassGrid->AutoSizeColumns();
82 m_componentClassGrid->EnableDragColMove( true );
83 m_componentClassGrid->EnableDragColSize( true );
84 m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
85 m_componentClassGrid->AutoSizeRows();
86 m_componentClassGrid->EnableDragRowSize( true );
87 m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
88 m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
89 m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
90 m_componentClassGrid->EnableEditing( true );
91 m_componentClassGrid->HideRowLabels();
92 m_componentClassGrid->SetColLabelValue( 0, _( "Generate" ) );
93 m_componentClassGrid->SetColLabelValue( 1, _( "Component Class" ) );
94 m_componentClassGrid->AutoSizeColumn( 1 );
95 m_bSizer2->Add( m_componentClassGrid, 1, wxEXPAND | wxALL, 5 );
96 m_panel2->SetSizer( m_bSizer2 );
97 m_panel2->Layout();
98 m_bSizer2->Fit( m_panel2 );
99
100 // Generate the group source grid
101 m_groupGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
102 m_groupGrid->CreateGrid( 0, 2 );
103 m_groupGrid->EnableEditing( false );
104 m_groupGrid->EnableGridLines( true );
105 m_groupGrid->EnableDragGridSize( false );
106 m_groupGrid->SetMargins( 0, 0 );
107 m_groupGrid->SetColSize( 0, 100 );
108 m_groupGrid->SetColSize( 1, 300 );
109 m_groupGrid->AutoSizeColumns();
110 m_groupGrid->EnableDragColMove( true );
111 m_groupGrid->EnableDragColSize( true );
112 m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
113 m_groupGrid->AutoSizeRows();
114 m_groupGrid->EnableDragRowSize( true );
115 m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
116 m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
117 m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
118 m_groupGrid->EnableEditing( true );
119 m_groupGrid->HideRowLabels();
120 m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
121 m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
122 m_groupGrid->AutoSizeColumn( 1 );
123 m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
124
126
127 int sheetRowIdx = 0;
128 int componentClassRowIdx = 0;
129 int groupIdx = 0;
130
131 for( RULE_AREA& ruleArea : raData->m_areas )
132 {
133 if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
134 sheetRowIdx++;
135 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
136 componentClassRowIdx++;
137 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::GROUP_PLACEMENT )
138 groupIdx++;
139 }
140
141 if( sheetRowIdx > 0 )
142 m_sheetGrid->AppendRows( sheetRowIdx );
143
144 if( componentClassRowIdx > 0 )
145 m_componentClassGrid->AppendRows( componentClassRowIdx );
146
147 if( groupIdx > 0 )
148 m_groupGrid->AppendRows( groupIdx );
149
150 sheetRowIdx = 0;
151 componentClassRowIdx = 0;
152 groupIdx = 0;
153
154 for( RULE_AREA& ruleArea : raData->m_areas )
155 {
156 if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
157 {
158 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
159 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
160 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
161 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
162 m_sheetGrid->SetCellValue( sheetRowIdx, 0,
163 ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
164 sheetRowIdx++;
165 }
166 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
167 {
168 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1,
169 ruleArea.m_componentClass );
170 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0,
171 new wxGridCellBoolRenderer );
172 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0,
173 new wxGridCellBoolEditor );
174 m_componentClassGrid->SetCellValue(
175 componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
176 componentClassRowIdx++;
177 }
178 else
179 {
180 m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
181 m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
182 m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
183 m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
184 groupIdx++;
185 }
186 }
187
188 m_sheetGrid->Fit();
190 m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
191 m_groupGrid->Fit();
192 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
193 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
194 Layout();
195
196 if( m_sheetGrid->GetNumberRows() == 1 )
197 {
198 if( m_componentClassGrid->GetNumberRows() > 0 )
199 m_sourceNotebook->SetSelection( 1 );
200 else if( m_groupGrid->GetNumberRows() > 0 )
201 m_sourceNotebook->SetSelection( 2 );
202 }
203
206}
207
208
210{
211 m_sheetGrid->PopEventHandler( true );
212}
213
214
216{
218
219 int sheetRowIdx = 0;
220 int componentClassRowIdx = 0;
221 int groupIdx = 0;
222
223 for( size_t i = 0; i < raData->m_areas.size(); i++ )
224 {
225 wxString enabled;
226
227 if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
228 {
229 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
230 sheetRowIdx++;
231 }
232 else if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
233 {
234 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
235 componentClassRowIdx++;
236 }
237 else
238 {
239 enabled = m_groupGrid->GetCellValue( groupIdx, 0 );
240 groupIdx++;
241 }
242
243 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
244 }
245
246 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
247
248 // Don't allow grouping for groups
249 if( m_sourceNotebook->GetSelection() == 2 )
250 raData->m_options.m_groupItems = false;
251 else
252 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
253
254 return true;
255}
256
257
259{
260 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
261 // grid cells from within this method.
262 return true;
263}
264
265
267{
268 if( event.GetSelection() == 2 )
269 m_cbGroupItems->Disable();
270 else
271 m_cbGroupItems->Enable();
272}
Class DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS_BASE.
DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS(PCB_BASE_FRAME *aFrame, MULTICHANNEL_TOOL *aParentTool)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
RULE_AREAS_DATA * GetData()
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define _(s)
REPEAT_LAYOUT_OPTIONS m_options
std::vector< RULE_AREA > m_areas
wxString m_sheetName
PLACEMENT_SOURCE_T m_sourceType
wxString m_componentClass
wxString m_groupName
wxString m_sheetPath
bool m_generateEnabled