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->EnableEditing( true );
57 m_sheetGrid->HideRowLabels();
58 m_sheetGrid->SetColLabelValue( 0, _( "Generate" ) );
59 m_sheetGrid->SetColLabelValue( 1, _( "Sheet Path" ) );
60 m_sheetGrid->SetColLabelValue( 2, _( "Sheet Name" ) );
61 m_sheetGrid->AutoSizeColumn( 1 );
62 m_bSizer1->Add( m_sheetGrid, 1, wxEXPAND | wxALL, 5 );
63 m_panel1->SetSizer( m_bSizer1 );
64 m_panel1->Layout();
65 m_bSizer1->Fit( m_panel1 );
66
67 // Generate the component class source grid
68 m_componentClassGrid = new WX_GRID( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
69 m_componentClassGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_componentClassGrid ) ) );
70 m_componentClassGrid->CreateGrid( 0, 2 );
71 m_componentClassGrid->EnableEditing( false );
72 m_componentClassGrid->EnableGridLines( true );
73 m_componentClassGrid->EnableDragGridSize( false );
74 m_componentClassGrid->SetMargins( 0, 0 );
75 m_componentClassGrid->SetColSize( 0, 100 );
76 m_componentClassGrid->SetColSize( 1, 300 );
77 m_componentClassGrid->AutoSizeColumns();
78 m_componentClassGrid->EnableDragColMove( true );
79 m_componentClassGrid->EnableDragColSize( true );
80 m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
81 m_componentClassGrid->AutoSizeRows();
82 m_componentClassGrid->EnableDragRowSize( true );
83 m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
84 m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
85 m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
86 m_componentClassGrid->EnableEditing( true );
87 m_componentClassGrid->HideRowLabels();
88 m_componentClassGrid->SetColLabelValue( 0, _( "Generate" ) );
89 m_componentClassGrid->SetColLabelValue( 1, _( "Component Class" ) );
90 m_componentClassGrid->AutoSizeColumn( 1 );
91 m_bSizer2->Add( m_componentClassGrid, 1, wxEXPAND | wxALL, 5 );
92 m_panel2->SetSizer( m_bSizer2 );
93 m_panel2->Layout();
94 m_bSizer2->Fit( m_panel2 );
95
96 // Generate the group source grid
97 m_groupGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
98 m_groupGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_groupGrid ) ) );
99 m_groupGrid->CreateGrid( 0, 2 );
100 m_groupGrid->EnableEditing( false );
101 m_groupGrid->EnableGridLines( true );
102 m_groupGrid->EnableDragGridSize( false );
103 m_groupGrid->SetMargins( 0, 0 );
104 m_groupGrid->SetColSize( 0, 100 );
105 m_groupGrid->SetColSize( 1, 300 );
106 m_groupGrid->AutoSizeColumns();
107 m_groupGrid->EnableDragColMove( true );
108 m_groupGrid->EnableDragColSize( true );
109 m_groupGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
110 m_groupGrid->AutoSizeRows();
111 m_groupGrid->EnableDragRowSize( true );
112 m_groupGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
113 m_groupGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
114 m_groupGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
115 m_groupGrid->EnableEditing( true );
116 m_groupGrid->HideRowLabels();
117 m_groupGrid->SetColLabelValue( 0, _( "Generate" ) );
118 m_groupGrid->SetColLabelValue( 1, _( "Name" ) );
119 m_groupGrid->AutoSizeColumn( 1 );
120 m_sourceNotebook->AddPage( m_groupGrid, _( "Groups" ) );
121
122 RULE_AREAS_DATA* raData = m_parentTool->GetData();
123
124 int sheetRowIdx = 0;
125 int componentClassRowIdx = 0;
126 int groupIdx = 0;
127
128 for( RULE_AREA& ruleArea : raData->m_areas )
129 {
131 sheetRowIdx++;
133 componentClassRowIdx++;
135 groupIdx++;
136 }
137
138 if( sheetRowIdx > 0 )
139 m_sheetGrid->AppendRows( sheetRowIdx );
140
141 if( componentClassRowIdx > 0 )
142 m_componentClassGrid->AppendRows( componentClassRowIdx );
143
144 if( groupIdx > 0 )
145 m_groupGrid->AppendRows( groupIdx );
146
147 sheetRowIdx = 0;
148 componentClassRowIdx = 0;
149 groupIdx = 0;
150
151 for( RULE_AREA& ruleArea : raData->m_areas )
152 {
154 {
155 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
156 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
157 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
158 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
159 m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
160 sheetRowIdx++;
161 }
163 {
164 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass );
165 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer );
166 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor );
167 m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" )
168 : wxT( "" ) );
169 componentClassRowIdx++;
170 }
171 else
172 {
173 m_groupGrid->SetCellValue( groupIdx, 1, ruleArea.m_groupName );
174 m_groupGrid->SetCellRenderer( groupIdx, 0, new wxGridCellBoolRenderer );
175 m_groupGrid->SetCellEditor( groupIdx, 0, new wxGridCellBoolEditor );
176 m_groupGrid->SetCellValue( groupIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
177 groupIdx++;
178 }
179 }
180
181 m_sheetGrid->Fit();
183 m_groupGrid->SetMaxSize( wxSize( -1, 800 ) );
184 m_groupGrid->Fit();
185 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
186 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
187 Layout();
188
189 if( m_sheetGrid->GetNumberRows() == 1 )
190 {
191 if( m_componentClassGrid->GetNumberRows() > 0 )
192 m_sourceNotebook->SetSelection( 1 );
193 else if( m_groupGrid->GetNumberRows() > 0 )
194 m_sourceNotebook->SetSelection( 2 );
195 }
196
199}
200
201
203{
204 m_sheetGrid->PopEventHandler( true );
205 m_componentClassGrid->PopEventHandler( true );
206 m_groupGrid->PopEventHandler( true );
207}
208
209
211{
212 RULE_AREAS_DATA* raData = m_parentTool->GetData();
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}
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