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->CreateGrid( 0, 2 );
74 m_componentClassGrid->EnableEditing( false );
75 m_componentClassGrid->EnableGridLines( true );
76 m_componentClassGrid->EnableDragGridSize( false );
77 m_componentClassGrid->SetMargins( 0, 0 );
78 m_componentClassGrid->SetColSize( 0, 100 );
79 m_componentClassGrid->SetColSize( 1, 300 );
80 m_componentClassGrid->AutoSizeColumns();
81 m_componentClassGrid->EnableDragColMove( true );
82 m_componentClassGrid->EnableDragColSize( true );
83 m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
84 m_componentClassGrid->AutoSizeRows();
85 m_componentClassGrid->EnableDragRowSize( true );
86 m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
87 m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
88 m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
89 m_componentClassGrid->EnableEditing( true );
90 m_componentClassGrid->HideRowLabels();
91 m_componentClassGrid->SetColLabelValue( 0, _( "Generate" ) );
92 m_componentClassGrid->SetColLabelValue( 1, _( "Component Class" ) );
93 m_componentClassGrid->AutoSizeColumn( 1 );
94 m_bSizer2->Add( m_componentClassGrid, 1, wxEXPAND | wxALL, 5 );
95 m_panel2->SetSizer( m_bSizer2 );
96 m_panel2->Layout();
97 m_bSizer2->Fit( m_panel2 );
98
99 // Generate the group source grid
100 m_groupGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
101 m_groupGrid->CreateGrid( 0, 2 );
102 m_groupGrid->EnableEditing( false );
103 m_groupGrid->EnableGridLines( true );
104 m_groupGrid->EnableDragGridSize( false );
105 m_groupGrid->SetMargins( 0, 0 );
106 m_groupGrid->SetColSize( 0, 100 );
107 m_groupGrid->SetColSize( 1, 300 );
108 m_groupGrid->AutoSizeColumns();
109 m_groupGrid->EnableDragColMove( true );
110 m_groupGrid->EnableDragColSize( true );
111 m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
112 m_groupGrid->AutoSizeRows();
113 m_groupGrid->EnableDragRowSize( true );
114 m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
115 m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
116 m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
117 m_groupGrid->EnableEditing( true );
118 m_groupGrid->HideRowLabels();
119 m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
120 m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
121 m_groupGrid->AutoSizeColumn( 1 );
122 m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
123
125
126 int sheetRowIdx = 0;
127 int componentClassRowIdx = 0;
128 int groupIdx = 0;
129
130 for( RULE_AREA& ruleArea : raData->m_areas )
131 {
132 if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
133 sheetRowIdx++;
134 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
135 componentClassRowIdx++;
136 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::GROUP_PLACEMENT )
137 groupIdx++;
138 }
139
140 if( sheetRowIdx > 0 )
141 m_sheetGrid->AppendRows( sheetRowIdx );
142
143 if( componentClassRowIdx > 0 )
144 m_componentClassGrid->AppendRows( componentClassRowIdx );
145
146 if( groupIdx > 0 )
147 m_groupGrid->AppendRows( groupIdx );
148
149 sheetRowIdx = 0;
150 componentClassRowIdx = 0;
151 groupIdx = 0;
152
153 for( RULE_AREA& ruleArea : raData->m_areas )
154 {
155 if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
156 {
157 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
158 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
159 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
160 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
161 m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
162 sheetRowIdx++;
163 }
164 else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
165 {
166 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass );
167 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer );
168 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor );
169 m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" )
170 : wxT( "" ) );
171 componentClassRowIdx++;
172 }
173 else
174 {
175 m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
176 m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
177 m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
178 m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
179 groupIdx++;
180 }
181 }
182
183 m_sheetGrid->Fit();
185 m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
186 m_groupGrid->Fit();
187 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
188 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
189 Layout();
190
191 if( m_sheetGrid->GetNumberRows() == 1 )
192 {
193 if( m_componentClassGrid->GetNumberRows() > 0 )
194 m_sourceNotebook->SetSelection( 1 );
195 else if( m_groupGrid->GetNumberRows() > 0 )
196 m_sourceNotebook->SetSelection( 2 );
197 }
198
201}
202
203
205{
206 m_sheetGrid->PopEventHandler( true );
207}
208
209
211{
213
214 int sheetRowIdx = 0;
215 int componentClassRowIdx = 0;
216 int groupIdx = 0;
217
218 for( size_t i = 0; i < raData->m_areas.size(); i++ )
219 {
220 wxString enabled;
221
222 if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::SHEETNAME )
223 {
224 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
225 sheetRowIdx++;
226 }
227 else if( raData->m_areas[i].m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
228 {
229 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
230 componentClassRowIdx++;
231 }
232 else
233 {
234 enabled = m_groupGrid->GetCellValue( groupIdx, 0 );
235 groupIdx++;
236 }
237
238 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
239 }
240
241 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
242
243 // Don't allow grouping for groups
244 if( m_sourceNotebook->GetSelection() == 2 )
245 raData->m_options.m_groupItems = false;
246 else
247 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
248
249 return true;
250}
251
252
254{
255 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
256 // grid cells from within this method.
257 return true;
258}
259
260
262{
263 if( event.GetSelection() == 2 )
264 m_cbGroupItems->Disable();
265 else
266 m_cbGroupItems->Enable();
267}
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