KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_board_setup.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <pcb_edit_frame.h>
20#include <panel_setup_layers.h>
27#include <confirm.h>
29#include <widgets/wx_infobar.h>
30#include <kiface_base.h>
31#include <drc/drc_item.h>
33#include <pcb_io/pcb_io.h>
34#include <pcb_io/pcb_io_mgr.h>
45#include <project.h>
51
52#include "dialog_board_setup.h"
53
54#include <advanced_config.h>
55#include <dialog_board_setup.h>
56#include <footprint.h>
57
58
59#define RESOLVE_PAGE( T, pageIndex ) static_cast<T*>( m_treebook->ResolvePage( pageIndex ) )
60
61DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame, wxWindow* aParentWindow ) :
62 PAGED_DIALOG( aParentWindow ? aParentWindow : aFrame, _( "Board Setup" ), false, false,
63 _( "Import Settings from Another Board..." ), wxSize( 980, 600 ) ),
64 m_frame( aFrame ),
65 m_layers( nullptr ),
66 m_boardFinish( nullptr ),
67 m_physicalStackup( nullptr ),
68 m_zones( nullptr ),
69 m_tuningProfiles( nullptr ),
70 m_netClasses( nullptr ),
71 m_currentPage( 0 ),
72 m_layersPage( 0 ),
75 m_defaultsPage( 0 ),
80 m_teardropsPage( 0 ),
86{
87 SetEvtHandlerEnabled( false );
88
89 /*
90 * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
91 */
92
93 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) );
94
95 /*
96 * WARNING: Code currently relies on the layers setup coming before the physical stackup panel,
97 * and thus transferring data to the board first. See comment in
98 * PANEL_SETUP_BOARD_STACKUP::TransferDataFromWindow and rework this logic if it is determined
99 * that the order of these pages should be changed.
100 */
101 m_layersPage = m_treebook->GetPageCount();
102 m_treebook->AddLazySubPage(
103 [this]( wxWindow* aParent ) -> wxWindow*
104 {
105 return new PANEL_SETUP_LAYERS( aParent, m_frame );
106 }, _( "Board Editor Layers" ) );
107
108 m_physicalStackupPage = m_treebook->GetPageCount();
109 m_treebook->AddLazySubPage(
110 [this]( wxWindow* aParent ) -> wxWindow*
111 {
115 }, _( "Physical Stackup" ) );
116
117 m_boardFinishPage = m_treebook->GetPageCount();
118 m_treebook->AddLazySubPage(
119 [this]( wxWindow* aParent ) -> wxWindow*
120 {
121 return new PANEL_SETUP_BOARD_FINISH( aParent, m_frame );
122 }, _( "Board Finish" ) );
123
124 m_maskAndPastePage = m_treebook->GetPageCount();
125 m_treebook->AddLazySubPage(
126 [this]( wxWindow* aParent ) -> wxWindow*
127 {
128 return new PANEL_SETUP_MASK_AND_PASTE( aParent, m_frame );
129 }, _( "Solder Mask/Paste" ) );
130
131 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
132
133 m_defaultsPage = m_treebook->GetPageCount();
134 m_treebook->AddLazySubPage(
135 [this]( wxWindow* aParent ) -> wxWindow*
136 {
137 return new PANEL_SETUP_DEFAULTS( aParent, m_frame );
138 }, _( "Defaults" ) );
139
140 m_formattingPage = m_treebook->GetPageCount();
141 m_treebook->AddLazySubPage(
142 [this]( wxWindow* aParent ) -> wxWindow*
143 {
144 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
145 }, _( "Formatting" ) );
146
147 m_treebook->AddLazySubPage(
148 [this]( wxWindow* aParent ) -> wxWindow*
149 {
150 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
151 }, _( "Text Variables" ) );
152
153 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
154
155 m_constraintsPage = m_treebook->GetPageCount();
156 m_treebook->AddLazySubPage(
157 [this]( wxWindow* aParent ) -> wxWindow*
158 {
159 return new PANEL_SETUP_CONSTRAINTS( aParent, m_frame );
160 }, _( "Constraints" ) );
161
162 m_tracksAndViasPage = m_treebook->GetPageCount();
163 m_treebook->AddLazySubPage(
164 [this]( wxWindow* aParent ) -> wxWindow*
165 {
166 return new PANEL_SETUP_TRACKS_AND_VIAS( aParent, m_frame );
167 }, _( "Pre-defined Sizes" ) );
168
169 m_zonesPage = m_treebook->GetPageCount();
170 m_treebook->AddLazySubPage(
171 [this]( wxWindow* aParent ) -> wxWindow*
172 {
173 return new PANEL_SETUP_ZONES( aParent, m_frame, m_frame->GetBoard()->GetDesignSettings() );
174 },
175 _( "Zones" ) );
176
177 m_teardropsPage = m_treebook->GetPageCount();
178 m_treebook->AddLazySubPage(
179 [this]( wxWindow* aParent ) -> wxWindow*
180 {
181 return new PANEL_SETUP_TEARDROPS( aParent, m_frame );
182 }, _( "Teardrops" ) );
183
184 m_tuningPatternsPage = m_treebook->GetPageCount();
185 m_treebook->AddLazySubPage(
186 [this]( wxWindow* aParent ) -> wxWindow*
187 {
188 BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
189
190 return new PANEL_SETUP_TUNING_PATTERNS( aParent, m_frame,
194 }, _( "Length-tuning Patterns" ) );
195
196 m_tuningProfilesPage = m_treebook->GetPageCount();
197 m_treebook->AddLazySubPage(
198 [this]( wxWindow* aParent ) -> wxWindow*
199 {
200 BOARD* board = m_frame->GetBoard();
201 return new PANEL_SETUP_TUNING_PROFILES( aParent, m_frame, board,
202 m_frame->Prj().GetProjectFile().TuningProfileParameters() );
203 },
204 _( "Tuning Profiles" ) );
205
206 m_netclassesPage = m_treebook->GetPageCount();
207 m_treebook->AddLazySubPage(
208 [this]( wxWindow* aParent ) -> wxWindow*
209 {
210 BOARD* board = m_frame->GetBoard();
211 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
212 m_frame->Prj().GetProjectFile().NetSettings(),
214 false );
215 }, _( "Net Classes" ) );
216
217 m_componentClassesPage = m_treebook->GetPageCount();
218 m_treebook->AddLazySubPage(
219 [this]( wxWindow* aParent ) -> wxWindow*
220 {
221 // Construct the panel
223 aParent, m_frame, m_frame->Prj().GetProjectFile().ComponentClassSettings(),
224 this );
225 },
226 _( "Component Classes" ) );
227
228 m_customRulesPage = m_treebook->GetPageCount();
229 m_treebook->AddLazySubPage(
230 [this]( wxWindow* aParent ) -> wxWindow*
231 {
232 return new PANEL_SETUP_RULES( aParent, m_frame );
233 },
234 _( "Custom Rules" ) );
235
236 m_severitiesPage = m_treebook->GetPageCount();
237 m_treebook->AddLazySubPage(
238 [this]( wxWindow* aParent ) -> wxWindow*
239 {
240 BOARD* board = m_frame->GetBoard();
243 },
244 _( "Violation Severity" ) );
245
246 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Data" ) );
247 m_embeddedFilesPage = m_treebook->GetPageCount();
248 m_treebook->AddLazySubPage(
249 [this]( wxWindow* aParent ) -> wxWindow*
250 {
251 BOARD* board = m_frame->GetBoard();
252
253 std::vector<const EMBEDDED_FILES*> inheritedFiles;
254
255 for( FOOTPRINT* fp : board->Footprints() )
256 inheritedFiles.push_back( fp->GetEmbeddedFiles() );
257
258 return new PANEL_EMBEDDED_FILES( aParent, board, NO_MARGINS, inheritedFiles );
259 },
260 _( "Embedded Files" ) );
261
262 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
263 m_treebook->ExpandNode( i );
264
265 SetEvtHandlerEnabled( true );
266
268
269 if( Prj().IsReadOnly() )
270 {
271 m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not be editable." ),
272 wxICON_WARNING );
273 }
274
275 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
276
277 wxQueueEvent( m_treebook, evt.Clone() );
278}
279
280
284
285
286void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
287{
289
290 size_t page = aEvent.GetSelection();
291
292 if( m_physicalStackupPage > 0 ) // Don't run this during initialization
293 {
295 || page == m_tuningProfilesPage || page == m_zonesPage )
296 {
302 }
303
304 // Ensure layer page always gets updated even if we aren't moving towards it
306 {
307 m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
308
309 // Avoid calling SyncCopperLayers twice if moving from stackup to tuning profiles directly
310 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
311 }
312
313 if( page == m_physicalStackupPage )
314 {
315 m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
316 }
318 {
319 m_netClasses->UpdateDelayProfileNames( m_tuningProfiles->GetDelayProfileNames() );
320 }
321 else if( page == m_tuningProfilesPage )
322 {
323 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
324 }
325 else if( page == m_zonesPage )
326 {
327 m_zones->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
328 }
329
330 if( Prj().IsReadOnly() )
331 {
332 KIUI::Disable( m_treebook->GetPage( page ) );
333 }
334 }
335
336 m_currentPage = page;
337}
338
339
340void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
341{
342 DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
343
344 if( importDlg.ShowModal() == wxID_CANCEL )
345 return;
346
347 wxFileName boardFn( importDlg.GetFilePath() );
348 wxFileName projectFn( boardFn );
349
350 projectFn.SetExt( FILEEXT::ProjectFileExtension );
351
352 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
353 {
354 wxString msg = wxString::Format( _( "Error importing settings from board:\n"
355 "Associated project file %s could not be loaded" ),
356 projectFn.GetFullPath() );
357 DisplayErrorMessage( this, msg );
358
359 return;
360 }
361
365
366 // Flag so user can stop work if it will result in deleted inner copper layers
367 // and still clean up this function properly.
368 bool okToProceed = true;
369
370 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
371
373 BOARD* otherBoard = nullptr;
374
375 try
376 {
377 WX_PROGRESS_REPORTER progressReporter( this, _( "Load PCB" ), 1, PR_CAN_ABORT );
378
379 pi->SetProgressReporter( &progressReporter );
380
381 otherBoard = pi->LoadBoard( boardFn.GetFullPath(), nullptr );
382
383 if( importDlg.m_LayersOpt->GetValue() )
384 {
385 BOARD* loadedBoard = m_frame->GetBoard();
386
387 // Check if "Import Settings" board has more layers than the current board.
388 okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard );
389 }
390 }
391 catch( const IO_ERROR& ioe )
392 {
393 // You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
394 // underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
395 // cost us much.
396 try
397 {
398 if( ioe.Problem() != wxT( "CANCEL" ) )
399 {
400 wxString msg = wxString::Format( _( "Error loading board file:\n%s" ), boardFn.GetFullPath() );
401 DisplayErrorMessage( this, msg, ioe.What() );
402 }
403
404 if( otherPrj != &m_frame->Prj() )
405 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
406 }
407 catch(...)
408 {
409 // That was already our best-efforts
410 }
411
412 return;
413 }
414
415 if( okToProceed )
416 {
417 otherBoard->SetProject( otherPrj );
418
419 // If layers options are imported, import also the stackup
420 // layers options and stackup are linked, so they cannot be imported
421 // separately, and stackup can be imported only after layers options
422 if( importDlg.m_LayersOpt->GetValue() )
423 {
424 m_physicalStackup->ImportSettingsFrom( otherBoard );
425 m_layers->ImportSettingsFrom( otherBoard );
426 m_boardFinish->ImportSettingsFrom( otherBoard );
427 }
428
429 if( importDlg.m_TextAndGraphicsOpt->GetValue() )
430 RESOLVE_PAGE( PANEL_SETUP_DEFAULTS, m_defaultsPage )->ImportSettingsFrom( otherBoard );
431
432 if( importDlg.m_FormattingOpt->GetValue() )
433 RESOLVE_PAGE( PANEL_SETUP_FORMATTING, m_formattingPage )->ImportSettingsFrom( otherBoard );
434
435 if( importDlg.m_ConstraintsOpt->GetValue() )
436 RESOLVE_PAGE( PANEL_SETUP_CONSTRAINTS, m_constraintsPage )->ImportSettingsFrom( otherBoard );
437
438 if( importDlg.m_NetclassesOpt->GetValue() )
439 {
440 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
441
443 m_netclassesPage )->ImportSettingsFrom( otherProjectFile.m_NetSettings );
444 }
445
446 if( importDlg.m_ComponentClassesOpt->GetValue() )
447 {
448 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
449
451 m_componentClassesPage )->ImportSettingsFrom( otherProjectFile.m_ComponentClassSettings );
452 }
453
454 if( importDlg.m_TracksAndViasOpt->GetValue() )
455 RESOLVE_PAGE( PANEL_SETUP_TRACKS_AND_VIAS, m_tracksAndViasPage )->ImportSettingsFrom( otherBoard );
456
457 if( importDlg.m_ZonesOpt->GetValue() )
458 RESOLVE_PAGE( PANEL_SETUP_ZONES, m_zonesPage )->ImportSettingsFrom( otherBoard );
459
460 if( importDlg.m_TeardropsOpt->GetValue() )
461 RESOLVE_PAGE( PANEL_SETUP_TEARDROPS, m_teardropsPage )->ImportSettingsFrom( otherBoard );
462
463 if( importDlg.m_TuningPatternsOpt->GetValue() )
464 RESOLVE_PAGE( PANEL_SETUP_TUNING_PATTERNS, m_tuningPatternsPage )->ImportSettingsFrom( otherBoard );
465
466 if( importDlg.m_MaskAndPasteOpt->GetValue() )
467 RESOLVE_PAGE( PANEL_SETUP_MASK_AND_PASTE, m_maskAndPastePage )->ImportSettingsFrom( otherBoard );
468
469 if( importDlg.m_ZoneHatchingOffsetsOpt->GetValue() )
470 RESOLVE_PAGE( PANEL_SETUP_ZONES, m_zonesPage )->ImportHatchOffsetsFrom( otherBoard );
471
472 if( importDlg.m_CustomRulesOpt->GetValue() )
473 RESOLVE_PAGE( PANEL_SETUP_RULES, m_customRulesPage )->ImportSettingsFrom( otherBoard );
474
475 if( importDlg.m_SeveritiesOpt->GetValue() )
476 {
477 BOARD_DESIGN_SETTINGS& otherSettings = otherBoard->GetDesignSettings();
478
480 m_severitiesPage )->ImportSettingsFrom( otherSettings.m_DRCSeverities );
481 }
482
483 if( importDlg.m_TuningProfilesOpt->GetValue() )
484 {
485 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
486
488 m_tuningProfilesPage )->ImportSettingsFrom( otherProjectFile.TuningProfileParameters() );
489 }
490
491 if( otherPrj != &m_frame->Prj() )
492 otherBoard->ClearProject();
493 }
494
495 // Clean up and free memory before leaving
496 if( otherPrj != &m_frame->Prj() )
497 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
498
499 delete otherBoard;
500}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
PNS::MEANDER_SETTINGS m_DiffPairMeanderSettings
PNS::MEANDER_SETTINGS m_SingleTrackMeanderSettings
PNS::MEANDER_SETTINGS m_SkewMeanderSettings
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:324
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition board.cpp:2759
const FOOTPRINTS & Footprints() const
Definition board.h:372
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:214
void ClearProject()
Definition board.cpp:255
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1113
DIALOG_BOARD_SETUP(PCB_EDIT_FRAME *aFrame, wxWindow *aWindow=nullptr)
PCB_EDIT_FRAME * m_frame
PANEL_SETUP_TUNING_PROFILES * m_tuningProfiles
void onAuxiliaryAction(wxCommandEvent &aEvent) override
PANEL_SETUP_BOARD_STACKUP * m_physicalStackup
PANEL_SETUP_ZONES * m_zones
PANEL_SETUP_BOARD_FINISH * m_boardFinish
PANEL_SETUP_LAYERS * m_layers
void onPageChanged(wxBookCtrlEvent &aEvent) override
PANEL_SETUP_NETCLASSES * m_netClasses
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition drc_item.h:145
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const wxString Problem() const
what was the problem?
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
WX_TREEBOOK * GetTreebook()
WX_INFOBAR * m_infoBar
PAGED_DIALOG(wxWindow *aParent, const wxString &aTitle, bool aShowReset, bool aShowOpenFolder, const wxString &aAuxiliaryAction=wxEmptyString, const wxSize &aInitialSize=wxDefaultSize)
WX_TREEBOOK * m_treebook
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
The main frame for Pcbnew.
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:58
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
std::shared_ptr< TUNING_PROFILES > & TuningProfileParameters()
std::shared_ptr< COMPONENT_CLASS_SETTINGS > m_ComponentClassSettings
Component class settings for the project (owned here)
Container for project specific data.
Definition project.h:66
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:204
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:221
This file is part of the common library.
#define RESOLVE_PAGE(T, pageIndex)
#define _(s)
static const std::string ProjectFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
KICOMMON_API void Disable(wxWindow *aWindow)
Makes a window read-only.
#define NO_MARGINS
Definition of file extensions used in Kicad.
#define PR_CAN_ABORT