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, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <widgets/wx_grid.h>
23#include <grid_tricks.h>
24#include <pcb_edit_frame.h>
25
27
29 MULTICHANNEL_TOOL* aParentTool ) :
31 m_parentTool( aParentTool )
32{
33 m_bSizer1 = new wxBoxSizer( wxVERTICAL );
34 m_bSizer2 = new wxBoxSizer( wxVERTICAL );
35
36 // Generate the sheet source grid
37 m_sheetGrid = new WX_GRID( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
38 m_sheetGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_sheetGrid ) ) );
39 m_sheetGrid->CreateGrid( 0, 3 );
40 m_sheetGrid->EnableEditing( false );
41 m_sheetGrid->EnableGridLines( true );
42 m_sheetGrid->EnableDragGridSize( false );
43 m_sheetGrid->SetMargins( 0, 0 );
44 m_sheetGrid->SetColSize( 0, 100 );
45 m_sheetGrid->SetColSize( 1, 300 );
46 m_sheetGrid->SetColSize( 2, 100 );
47 m_sheetGrid->AutoSizeColumns();
48 m_sheetGrid->EnableDragColMove( true );
49 m_sheetGrid->EnableDragColSize( true );
50 m_sheetGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
51 m_sheetGrid->AutoSizeRows();
52 m_sheetGrid->EnableDragRowSize( true );
53 m_sheetGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
54 m_sheetGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
55 m_sheetGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
56 m_sheetGrid->HideRowLabels();
57 m_sheetGrid->SetColLabelValue( 0, _( "Generate" ) );
58 m_sheetGrid->SetColLabelValue( 1, _( "Sheet Path" ) );
59 m_sheetGrid->SetColLabelValue( 2, _( "Sheet Name" ) );
60 m_sheetGrid->AutoSizeColumn( 1 );
61 m_bSizer1->Add( m_sheetGrid, 1, wxEXPAND | wxALL, 5 );
62 m_panel1->SetSizer( m_bSizer1 );
63 m_panel1->Layout();
64 m_bSizer1->Fit( m_panel1 );
65
66 // Generate the component class source grid
67 m_componentClassGrid = new WX_GRID( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
68 m_componentClassGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_componentClassGrid ) ) );
69 m_componentClassGrid->CreateGrid( 0, 2 );
70 m_componentClassGrid->EnableEditing( false );
71 m_componentClassGrid->EnableGridLines( true );
72 m_componentClassGrid->EnableDragGridSize( false );
73 m_componentClassGrid->SetMargins( 0, 0 );
74 m_componentClassGrid->SetColSize( 0, 100 );
75 m_componentClassGrid->SetColSize( 1, 300 );
76 m_componentClassGrid->AutoSizeColumns();
77 m_componentClassGrid->EnableDragColMove( true );
78 m_componentClassGrid->EnableDragColSize( true );
79 m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
80 m_componentClassGrid->AutoSizeRows();
81 m_componentClassGrid->EnableDragRowSize( true );
82 m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
83 m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
84 m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
85 m_componentClassGrid->HideRowLabels();
86 m_componentClassGrid->SetColLabelValue( 0, _( "Generate" ) );
87 m_componentClassGrid->SetColLabelValue( 1, _( "Component Class" ) );
88 m_componentClassGrid->AutoSizeColumn( 1 );
89 m_bSizer2->Add( m_componentClassGrid, 1, wxEXPAND | wxALL, 5 );
90 m_panel2->SetSizer( m_bSizer2 );
91 m_panel2->Layout();
92 m_bSizer2->Fit( m_panel2 );
93
94 // Generate the group source grid
95 m_groupGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
96 m_groupGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_groupGrid ) ) );
97 m_groupGrid->CreateGrid( 0, 2 );
98 m_groupGrid->EnableEditing( false );
99 m_groupGrid->EnableGridLines( true );
100 m_groupGrid->EnableDragGridSize( false );
101 m_groupGrid->SetMargins( 0, 0 );
102 m_groupGrid->SetColSize( 0, 100 );
103 m_groupGrid->SetColSize( 1, 300 );
104 m_groupGrid->AutoSizeColumns();
105 m_groupGrid->EnableDragColMove( true );
106 m_groupGrid->EnableDragColSize( true );
107 m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
108 m_groupGrid->AutoSizeRows();
109 m_groupGrid->EnableDragRowSize( true );
110 m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
111 m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
112 m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
113 m_groupGrid->HideRowLabels();
114 m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
115 m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
116 m_groupGrid->AutoSizeColumn( 1 );
117 m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
118
119 RULE_AREAS_DATA* raData = m_parentTool->GetData();
120
121 int sheetRowIdx = 0;
122 int componentClassRowIdx = 0;
123 int groupIdx = 0;
124
125 for( RULE_AREA& ruleArea : raData->m_areas )
126 {
128 sheetRowIdx++;
130 componentClassRowIdx++;
132 groupIdx++;
133 }
134
135 if( sheetRowIdx > 0 )
136 m_sheetGrid->AppendRows( sheetRowIdx );
137
138 if( componentClassRowIdx > 0 )
139 m_componentClassGrid->AppendRows( componentClassRowIdx );
140
141 if( groupIdx > 0 )
142 m_groupGrid->AppendRows( groupIdx );
143
144 sheetRowIdx = 0;
145 componentClassRowIdx = 0;
146 groupIdx = 0;
147
148 for( RULE_AREA& ruleArea : raData->m_areas )
149 {
151 {
152 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
153 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
154 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
155 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
156 m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
157 sheetRowIdx++;
158 }
160 {
161 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass );
162 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer );
163 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor );
164 m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" )
165 : wxT( "" ) );
166 componentClassRowIdx++;
167 }
168 else
169 {
170 m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
171 m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
172 m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
173 m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
174 groupIdx++;
175 }
176 }
177
178 m_sheetGrid->Fit();
180 m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
181 m_groupGrid->Fit();
182 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
183 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
184 Layout();
185
186 if( m_sheetGrid->GetNumberRows() == 1 )
187 {
188 if( m_componentClassGrid->GetNumberRows() > 0 )
189 m_sourceNotebook->SetSelection( 1 );
190 else if( m_groupGrid->GetNumberRows() > 0 )
191 m_sourceNotebook->SetSelection( 2 );
192 }
193
196}
197
198
200{
201 m_sheetGrid->PopEventHandler( true );
202 m_componentClassGrid->PopEventHandler( true );
203 m_groupGrid->PopEventHandler( true );
204}
205
206
208{
209 RULE_AREAS_DATA* raData = m_parentTool->GetData();
210
211 int sheetRowIdx = 0;
212 int componentClassRowIdx = 0;
213 int groupIdx = 0;
214
215 for( size_t i = 0; i < raData->m_areas.size(); i++ )
216 {
217 wxString enabled;
218
219 if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
220 {
221 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
222 sheetRowIdx++;
223 }
224 else if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
225 {
226 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
227 componentClassRowIdx++;
228 }
229 else
230 {
231 enabled = m_groupGrid->GetCellValue( groupIdx, 0 );
232 groupIdx++;
233 }
234
235 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
236 }
237
238 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
239
240 // Don't allow grouping for groups
241 if( m_sourceNotebook->GetSelection() == 2 )
242 raData->m_options.m_groupItems = false;
243 else
244 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
245
246 return true;
247}
248
249
251{
252 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
253 // grid cells from within this method.
254 return true;
255}
256
257
259{
260 if( event.GetSelection() == 2 )
261 m_cbGroupItems->Disable();
262 else
263 m_cbGroupItems->Enable();
264}
DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Generate Multichannel Rule Areas"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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:57
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