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 (C) 2018-2020 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 // Generate the sheet source grid
39 m_sheetGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
40 m_sheetGrid->PushEventHandler( new GRID_TRICKS( static_cast<WX_GRID*>( m_sheetGrid ) ) );
41 m_sheetGrid->CreateGrid( 0, 3 );
42 m_sheetGrid->EnableEditing( false );
43 m_sheetGrid->EnableGridLines( true );
44 m_sheetGrid->EnableDragGridSize( false );
45 m_sheetGrid->SetMargins( 0, 0 );
46 m_sheetGrid->SetColSize( 0, 100 );
47 m_sheetGrid->SetColSize( 1, 300 );
48 m_sheetGrid->SetColSize( 2, 100 );
49 m_sheetGrid->AutoSizeColumns();
50 m_sheetGrid->EnableDragColMove( true );
51 m_sheetGrid->EnableDragColSize( true );
52 m_sheetGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
53 m_sheetGrid->AutoSizeRows();
54 m_sheetGrid->EnableDragRowSize( true );
55 m_sheetGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
56 m_sheetGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
57 m_sheetGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
58 m_sheetGrid->EnableEditing( true );
59 m_sheetGrid->HideRowLabels();
60 m_sheetGrid->SetColLabelValue( 0, wxT( "Generate" ) );
61 m_sheetGrid->SetColLabelValue( 1, wxT( "Sheet Path" ) );
62 m_sheetGrid->SetColLabelValue( 2, wxT( "Sheet Name" ) );
63 m_sheetGrid->AutoSizeColumn( 1 );
64 m_sourceNotebook->AddPage( m_sheetGrid, _( "Sheets" ) );
65
66 // Generate the component class source grid
68 new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
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->EnableEditing( true );
86 m_componentClassGrid->HideRowLabels();
87 m_componentClassGrid->SetColLabelValue( 0, wxT( "Generate" ) );
88 m_componentClassGrid->SetColLabelValue( 1, wxT( "Component Class" ) );
89 m_componentClassGrid->AutoSizeColumn( 1 );
90 m_sourceNotebook->AddPage( m_componentClassGrid, _( "Component Classes" ) );
91
93
94 int sheetRowIdx = 0;
95 int componentClassRowIdx = 0;
96
97 for( RULE_AREA& ruleArea : raData->m_areas )
98 {
99 if( ruleArea.m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
100 sheetRowIdx++;
101 else
102 componentClassRowIdx++;
103 }
104
105 if( sheetRowIdx > 0 )
106 m_sheetGrid->AppendRows( sheetRowIdx );
107
108 if( componentClassRowIdx > 0 )
109 m_componentClassGrid->AppendRows( componentClassRowIdx );
110
111 sheetRowIdx = 0;
112 componentClassRowIdx = 0;
113
114 for( RULE_AREA& ruleArea : raData->m_areas )
115 {
116 if( ruleArea.m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
117 {
118 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
119 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
120 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
121 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
122 m_sheetGrid->SetCellValue( sheetRowIdx, 0,
123 ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
124 sheetRowIdx++;
125 }
126 else
127 {
128 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1,
129 ruleArea.m_componentClass );
130 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0,
131 new wxGridCellBoolRenderer );
132 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0,
133 new wxGridCellBoolEditor );
134 m_componentClassGrid->SetCellValue(
135 componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
136 componentClassRowIdx++;
137 }
138 }
139
140 m_sheetGrid->SetMaxSize( wxSize( -1, 800 ) );
141 m_sheetGrid->Fit();
142 m_componentClassGrid->SetMaxSize( wxSize( -1, 800 ) );
144 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
145 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
146
147 Layout();
148
149 if( m_sheetGrid->GetNumberRows() == 1 && m_componentClassGrid->GetNumberRows() > 0 )
150 m_sourceNotebook->SetSelection( 1 );
151
154}
155
156
158{
159 m_sheetGrid->PopEventHandler( true );
160}
161
162
164{
166
167 int sheetRowIdx = 0;
168 int componentClassRowIdx = 0;
169
170 for( size_t i = 0; i < raData->m_areas.size(); i++ )
171 {
172 wxString enabled;
173
174 if( raData->m_areas[i].m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
175 {
176 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
177 sheetRowIdx++;
178 }
179 else
180 {
181 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
182 componentClassRowIdx++;
183 }
184
185 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
186 }
187
188 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
189 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
190
191 return true;
192}
193
194
196{
197 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
198 // grid cells from within this method.
199 return true;
200}
201
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
RULE_AREA_PLACEMENT_SOURCE_TYPE m_sourceType
wxString m_sheetName
wxString m_componentClass
wxString m_sheetPath
bool m_generateEnabled