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 MULTICHANNEL_TOOL* aParentTool ) :
35 m_parentTool( aParentTool )
36{
37 m_bSizer1 = new wxBoxSizer( wxVERTICAL );
38 m_bSizer2 = new wxBoxSizer( wxVERTICAL );
39
40 // Generate the sheet source grid
41 m_sheetGrid = new WX_GRID( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
42 m_sheetGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_sheetGrid ) ) );
43 m_sheetGrid->CreateGrid( 0, 3 );
44 m_sheetGrid->EnableEditing( false );
45 m_sheetGrid->EnableGridLines( true );
46 m_sheetGrid->EnableDragGridSize( false );
47 m_sheetGrid->SetMargins( 0, 0 );
48 m_sheetGrid->SetColSize( 0, 100 );
49 m_sheetGrid->SetColSize( 1, 300 );
50 m_sheetGrid->SetColSize( 2, 100 );
51 m_sheetGrid->AutoSizeColumns();
52 m_sheetGrid->EnableDragColMove( true );
53 m_sheetGrid->EnableDragColSize( true );
54 m_sheetGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
55 m_sheetGrid->AutoSizeRows();
56 m_sheetGrid->EnableDragRowSize( true );
57 m_sheetGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
58 m_sheetGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
59 m_sheetGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
60 m_sheetGrid->EnableEditing( true );
61 m_sheetGrid->HideRowLabels();
62 m_sheetGrid->SetColLabelValue( 0, _( "Generate" ) );
63 m_sheetGrid->SetColLabelValue( 1, _( "Sheet Path" ) );
64 m_sheetGrid->SetColLabelValue( 2, _( "Sheet Name" ) );
65 m_sheetGrid->AutoSizeColumn( 1 );
66 m_bSizer1->Add( m_sheetGrid, 1, wxEXPAND | wxALL, 5 );
67 m_panel1->SetSizer( m_bSizer1 );
68 m_panel1->Layout();
69 m_bSizer1->Fit( m_panel1 );
70
71 // Generate the component class source grid
72 m_componentClassGrid = new WX_GRID( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
73 m_componentClassGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_componentClassGrid ) ) );
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->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_groupGrid ) ) );
103 m_groupGrid->CreateGrid( 0, 2 );
104 m_groupGrid->EnableEditing( false );
105 m_groupGrid->EnableGridLines( true );
106 m_groupGrid->EnableDragGridSize( false );
107 m_groupGrid->SetMargins( 0, 0 );
108 m_groupGrid->SetColSize( 0, 100 );
109 m_groupGrid->SetColSize( 1, 300 );
110 m_groupGrid->AutoSizeColumns();
111 m_groupGrid->EnableDragColMove( true );
112 m_groupGrid->EnableDragColSize( true );
113 m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
114 m_groupGrid->AutoSizeRows();
115 m_groupGrid->EnableDragRowSize( true );
116 m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
117 m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
118 m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
119 m_groupGrid->EnableEditing( true );
120 m_groupGrid->HideRowLabels();
121 m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
122 m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
123 m_groupGrid->AutoSizeColumn( 1 );
124 m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
125
126 RULE_AREAS_DATA* raData = m_parentTool->GetData();
127
128 int sheetRowIdx = 0;
129 int componentClassRowIdx = 0;
130 int groupIdx = 0;
131
132 for( RULE_AREA& ruleArea : raData->m_areas )
133 {
135 sheetRowIdx++;
137 componentClassRowIdx++;
139 groupIdx++;
140 }
141
142 if( sheetRowIdx > 0 )
143 m_sheetGrid->AppendRows( sheetRowIdx );
144
145 if( componentClassRowIdx > 0 )
146 m_componentClassGrid->AppendRows( componentClassRowIdx );
147
148 if( groupIdx > 0 )
149 m_groupGrid->AppendRows( groupIdx );
150
151 sheetRowIdx = 0;
152 componentClassRowIdx = 0;
153 groupIdx = 0;
154
155 for( RULE_AREA& ruleArea : raData->m_areas )
156 {
158 {
159 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
160 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
161 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
162 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
163 m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
164 sheetRowIdx++;
165 }
167 {
168 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass );
169 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer );
170 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor );
171 m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" )
172 : wxT( "" ) );
173 componentClassRowIdx++;
174 }
175 else
176 {
177 m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
178 m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
179 m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
180 m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
181 groupIdx++;
182 }
183 }
184
185 m_sheetGrid->Fit();
187 m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
188 m_groupGrid->Fit();
189 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
190 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
191 Layout();
192
193 if( m_sheetGrid->GetNumberRows() == 1 )
194 {
195 if( m_componentClassGrid->GetNumberRows() > 0 )
196 m_sourceNotebook->SetSelection( 1 );
197 else if( m_groupGrid->GetNumberRows() > 0 )
198 m_sourceNotebook->SetSelection( 2 );
199 }
200
203}
204
205
207{
208 m_sheetGrid->PopEventHandler( true );
209 m_componentClassGrid->PopEventHandler( true );
210 m_groupGrid->PopEventHandler( true );
211}
212
213
215{
216 RULE_AREAS_DATA* raData = m_parentTool->GetData();
217
218 int sheetRowIdx = 0;
219 int componentClassRowIdx = 0;
220 int groupIdx = 0;
221
222 for( size_t i = 0; i < raData->m_areas.size(); i++ )
223 {
224 wxString enabled;
225
226 if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
227 {
228 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
229 sheetRowIdx++;
230 }
231 else if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
232 {
233 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
234 componentClassRowIdx++;
235 }
236 else
237 {
238 enabled = m_groupGrid->GetCellValue( groupIdx, 0 );
239 groupIdx++;
240 }
241
242 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
243 }
244
245 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
246
247 // Don't allow grouping for groups
248 if( m_sourceNotebook->GetSelection() == 2 )
249 raData->m_options.m_groupItems = false;
250 else
251 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
252
253 return true;
254}
255
256
258{
259 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
260 // grid cells from within this method.
261 return true;
262}
263
264
266{
267 if( event.GetSelection() == 2 )
268 m_cbGroupItems->Disable();
269 else
270 m_cbGroupItems->Enable();
271}
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:61
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