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 <pcb_edit_frame.h>
28
30
32 PCB_BASE_FRAME* aFrame,
33 MULTICHANNEL_TOOL* aParentTool ) :
35 m_parentTool( aParentTool )
36{
37 // Generate the sheet source grid
38 m_sheetGrid = new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
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, wxT( "Generate" ) );
59 m_sheetGrid->SetColLabelValue( 1, wxT( "Sheet Path" ) );
60 m_sheetGrid->SetColLabelValue( 2, wxT( "Sheet Name" ) );
61 m_sheetGrid->AutoSizeColumn( 1 );
62 m_sourceNotebook->AddPage( m_sheetGrid, _( "Sheets" ) );
63
64 // Generate the component class source grid
66 new WX_GRID( m_sourceNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
67 m_componentClassGrid->CreateGrid( 0, 2 );
68 m_componentClassGrid->EnableEditing( false );
69 m_componentClassGrid->EnableGridLines( true );
70 m_componentClassGrid->EnableDragGridSize( false );
71 m_componentClassGrid->SetMargins( 0, 0 );
72 m_componentClassGrid->SetColSize( 0, 100 );
73 m_componentClassGrid->SetColSize( 1, 300 );
74 m_componentClassGrid->AutoSizeColumns();
75 m_componentClassGrid->EnableDragColMove( true );
76 m_componentClassGrid->EnableDragColSize( true );
77 m_componentClassGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
78 m_componentClassGrid->AutoSizeRows();
79 m_componentClassGrid->EnableDragRowSize( true );
80 m_componentClassGrid->SetRowLabelSize( wxGRID_AUTOSIZE );
81 m_componentClassGrid->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
82 m_componentClassGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
83 m_componentClassGrid->EnableEditing( true );
84 m_componentClassGrid->HideRowLabels();
85 m_componentClassGrid->SetColLabelValue( 0, wxT( "Generate" ) );
86 m_componentClassGrid->SetColLabelValue( 1, wxT( "Component Class" ) );
87 m_componentClassGrid->AutoSizeColumn( 1 );
88 m_sourceNotebook->AddPage( m_componentClassGrid, _( "Component Classes" ) );
89
91
92 int sheetRowIdx = 0;
93 int componentClassRowIdx = 0;
94
95 for( RULE_AREA& ruleArea : raData->m_areas )
96 {
97 if( ruleArea.m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
98 sheetRowIdx++;
99 else
100 componentClassRowIdx++;
101 }
102
103 if( sheetRowIdx > 0 )
104 m_sheetGrid->AppendRows( sheetRowIdx );
105
106 if( componentClassRowIdx > 0 )
107 m_componentClassGrid->AppendRows( componentClassRowIdx );
108
109 sheetRowIdx = 0;
110 componentClassRowIdx = 0;
111
112 for( RULE_AREA& ruleArea : raData->m_areas )
113 {
114 if( ruleArea.m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
115 {
116 m_sheetGrid->SetCellValue( sheetRowIdx, 1, ruleArea.m_sheetPath );
117 m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName );
118 m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer );
119 m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor );
120 m_sheetGrid->SetCellValue( sheetRowIdx, 0,
121 ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
122 sheetRowIdx++;
123 }
124 else
125 {
126 m_componentClassGrid->SetCellValue( componentClassRowIdx, 1,
127 ruleArea.m_componentClass );
128 m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0,
129 new wxGridCellBoolRenderer );
130 m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0,
131 new wxGridCellBoolEditor );
132 m_componentClassGrid->SetCellValue(
133 componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) );
134 componentClassRowIdx++;
135 }
136 }
137
138 m_sheetGrid->SetMaxSize( wxSize( -1, 800 ) );
139 m_sheetGrid->Fit();
140 m_componentClassGrid->SetMaxSize( wxSize( -1, 800 ) );
142 m_cbGroupItems->SetValue( raData->m_options.m_groupItems );
143 m_cbReplaceExisting->SetValue( raData->m_replaceExisting );
144
145 Layout();
146
147 if( m_sheetGrid->GetNumberRows() == 1 && m_componentClassGrid->GetNumberRows() > 0 )
148 m_sourceNotebook->SetSelection( 1 );
149
152}
153
154
156{
158
159 int sheetRowIdx = 0;
160 int componentClassRowIdx = 0;
161
162 for( size_t i = 0; i < raData->m_areas.size(); i++ )
163 {
164 wxString enabled;
165
166 if( raData->m_areas[i].m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
167 {
168 enabled = m_sheetGrid->GetCellValue( sheetRowIdx, 0 );
169 sheetRowIdx++;
170 }
171 else
172 {
173 enabled = m_componentClassGrid->GetCellValue( componentClassRowIdx, 0 );
174 componentClassRowIdx++;
175 }
176
177 raData->m_areas[i].m_generateEnabled = ( !enabled.CompareTo( wxT( "1" ) ) ) ? true : false;
178 }
179
180 raData->m_replaceExisting = m_cbReplaceExisting->GetValue();
181 raData->m_options.m_groupItems = m_cbGroupItems->GetValue();
182
183 return true;
184}
185
186
188{
189 // fixme: no idea how to make the wxGrid autoresize to the actual window width when setting
190 // grid cells from within this method.
191 return true;
192}
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...
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