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 <kiface_base.h>
30#include <drc/drc_item.h>
32#include <pcb_io/pcb_io.h>
33#include <pcb_io/pcb_io_mgr.h>
43#include <project.h>
49
50#include "dialog_board_setup.h"
51
52#include <advanced_config.h>
53#include <dialog_board_setup.h>
54#include <footprint.h>
55
56
57#define RESOLVE_PAGE( T, pageIndex ) static_cast<T*>( m_treebook->ResolvePage( pageIndex ) )
58
59DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame, wxWindow* aParentWindow ) :
60 PAGED_DIALOG( aParentWindow ? aParentWindow : aFrame, _( "Board Setup" ), false, false,
61 _( "Import Settings from Another Board..." ), wxSize( 980, 600 ) ),
62 m_frame( aFrame ),
63 m_layers( nullptr ),
64 m_boardFinish( nullptr ),
65 m_physicalStackup( nullptr ),
66 m_tuningProfiles( nullptr ),
67 m_netClasses( nullptr ),
68 m_currentPage( 0 ),
69 m_layersPage( 0 ),
77 m_teardropsPage( 0 ),
83{
84 SetEvtHandlerEnabled( false );
85
86 /*
87 * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
88 */
89
90 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) );
91
92 /*
93 * WARNING: Code currently relies on the layers setup coming before the physical stackup panel,
94 * and thus transferring data to the board first. See comment in
95 * PANEL_SETUP_BOARD_STACKUP::TransferDataFromWindow and rework this logic if it is determined
96 * that the order of these pages should be changed.
97 */
98 m_layersPage = m_treebook->GetPageCount();
99 m_treebook->AddLazySubPage(
100 [this]( wxWindow* aParent ) -> wxWindow*
101 {
102 return new PANEL_SETUP_LAYERS( aParent, m_frame );
103 }, _( "Board Editor Layers" ) );
104
105 m_physicalStackupPage = m_treebook->GetPageCount();
106 m_treebook->AddLazySubPage(
107 [this]( wxWindow* aParent ) -> wxWindow*
108 {
112 }, _( "Physical Stackup" ) );
113
114 m_boardFinishPage = m_treebook->GetPageCount();
115 m_treebook->AddLazySubPage(
116 [this]( wxWindow* aParent ) -> wxWindow*
117 {
118 return new PANEL_SETUP_BOARD_FINISH( aParent, m_frame );
119 }, _( "Board Finish" ) );
120
121 m_maskAndPagePage = m_treebook->GetPageCount();
122 m_treebook->AddLazySubPage(
123 [this]( wxWindow* aParent ) -> wxWindow*
124 {
125 return new PANEL_SETUP_MASK_AND_PASTE( aParent, m_frame );
126 }, _( "Solder Mask/Paste" ) );
127
128 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
129
130 m_textAndGraphicsPage = m_treebook->GetPageCount();
131 m_treebook->AddLazySubPage(
132 [this]( wxWindow* aParent ) -> wxWindow*
133 {
134 return new PANEL_SETUP_TEXT_AND_GRAPHICS( aParent, m_frame );
135 }, _( "Defaults" ) );
136
137 m_formattingPage = m_treebook->GetPageCount();
138 m_treebook->AddLazySubPage(
139 [this]( wxWindow* aParent ) -> wxWindow*
140 {
141 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
142 }, _( "Formatting" ) );
143
144 m_treebook->AddLazySubPage(
145 [this]( wxWindow* aParent ) -> wxWindow*
146 {
147 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
148 }, _( "Text Variables" ) );
149
150 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
151
152 m_constraintsPage = m_treebook->GetPageCount();
153 m_treebook->AddLazySubPage(
154 [this]( wxWindow* aParent ) -> wxWindow*
155 {
156 return new PANEL_SETUP_CONSTRAINTS( aParent, m_frame );
157 }, _( "Constraints" ) );
158
159 m_tracksAndViasPage = m_treebook->GetPageCount();
160 m_treebook->AddLazySubPage(
161 [this]( wxWindow* aParent ) -> wxWindow*
162 {
163 return new PANEL_SETUP_TRACKS_AND_VIAS( aParent, m_frame );
164 }, _( "Pre-defined Sizes" ) );
165
166 m_teardropsPage = m_treebook->GetPageCount();
167 m_treebook->AddLazySubPage(
168 [this]( wxWindow* aParent ) -> wxWindow*
169 {
170 return new PANEL_SETUP_TEARDROPS( aParent, m_frame );
171 }, _( "Teardrops" ) );
172
173 m_tuningPatternsPage = m_treebook->GetPageCount();
174 m_treebook->AddLazySubPage(
175 [this]( wxWindow* aParent ) -> wxWindow*
176 {
177 BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
178
179 return new PANEL_SETUP_TUNING_PATTERNS( aParent, m_frame,
183 }, _( "Length-tuning Patterns" ) );
184
185 m_tuningProfilesPage = m_treebook->GetPageCount();
186 m_treebook->AddLazySubPage(
187 [this]( wxWindow* aParent ) -> wxWindow*
188 {
189 BOARD* board = m_frame->GetBoard();
190 return new PANEL_SETUP_TUNING_PROFILES( aParent, m_frame, board,
191 m_frame->Prj().GetProjectFile().TuningProfileParameters() );
192 },
193 _( "Tuning Profiles" ) );
194
195 m_netclassesPage = m_treebook->GetPageCount();
196 m_treebook->AddLazySubPage(
197 [this]( wxWindow* aParent ) -> wxWindow*
198 {
199 BOARD* board = m_frame->GetBoard();
200 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
201 m_frame->Prj().GetProjectFile().NetSettings(),
203 false );
204 }, _( "Net Classes" ) );
205
206 m_componentClassesPage = m_treebook->GetPageCount();
207 m_treebook->AddLazySubPage(
208 [this]( wxWindow* aParent ) -> wxWindow*
209 {
210 // Construct the panel
212 aParent, m_frame, m_frame->Prj().GetProjectFile().ComponentClassSettings(),
213 this );
214 },
215 _( "Component Classes" ) );
216
217 m_customRulesPage = m_treebook->GetPageCount();
218 m_treebook->AddLazySubPage(
219 [this]( wxWindow* aParent ) -> wxWindow*
220 {
221 return new PANEL_SETUP_RULES( aParent, m_frame );
222 },
223 _( "Custom Rules" ) );
224
225 m_severitiesPage = m_treebook->GetPageCount();
226 m_treebook->AddLazySubPage(
227 [this]( wxWindow* aParent ) -> wxWindow*
228 {
229 BOARD* board = m_frame->GetBoard();
232 },
233 _( "Violation Severity" ) );
234
235 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Data" ) );
236 m_embeddedFilesPage = m_treebook->GetPageCount();
237 m_treebook->AddLazySubPage(
238 [this]( wxWindow* aParent ) -> wxWindow*
239 {
240 return new PANEL_EMBEDDED_FILES( aParent, m_frame->GetBoard(), NO_MARGINS );
241 },
242 _( "Embedded Files" ) );
243
244 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
245 m_treebook->ExpandNode( i );
246
247 SetEvtHandlerEnabled( true );
248
250
251 if( Prj().IsReadOnly() )
252 {
253 m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not "
254 "be editable." ),
255 wxICON_WARNING );
256 }
257
258 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
259
260 wxQueueEvent( m_treebook, evt.Clone() );
261}
262
263
267
268
269void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
270{
272
273 size_t page = aEvent.GetSelection();
274
275 if( m_physicalStackupPage > 0 ) // Don't run this during initialization
276 {
278 || page == m_tuningProfilesPage )
279 {
284 }
285
286 // Ensure layer page always gets updated even if we aren't moving towards it
288 {
289 m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
290
291 // Avoid calling SyncCopperLayers twice if moving from stackup to tuning profiles directly
292 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
293 }
294
295 if( page == m_physicalStackupPage )
296 {
297 m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
298 }
300 {
301 m_netClasses->UpdateDelayProfileNames( m_tuningProfiles->GetDelayProfileNames() );
302 }
303 else if( page == m_tuningProfilesPage )
304 {
305 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
306 }
307
308 if( Prj().IsReadOnly() )
309 {
310 KIUI::Disable( m_treebook->GetPage( page ) );
311 }
312 }
313
314 m_currentPage = page;
315}
316
317
318void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
319{
320 DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
321
322 if( importDlg.ShowModal() == wxID_CANCEL )
323 return;
324
325 wxFileName boardFn( importDlg.GetFilePath() );
326 wxFileName projectFn( boardFn );
327
328 projectFn.SetExt( FILEEXT::ProjectFileExtension );
329
330 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
331 {
332 wxString msg = wxString::Format( _( "Error importing settings from board:\n"
333 "Associated project file %s could not be loaded" ),
334 projectFn.GetFullPath() );
335 DisplayErrorMessage( this, msg );
336
337 return;
338 }
339
343
344 // Flag so user can stop work if it will result in deleted inner copper layers
345 // and still clean up this function properly.
346 bool okToProceed = true;
347
348 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
349
351 BOARD* otherBoard = nullptr;
352
353 try
354 {
355 WX_PROGRESS_REPORTER progressReporter( this, _( "Load PCB" ), 1, PR_CAN_ABORT );
356
357 pi->SetProgressReporter( &progressReporter );
358
359 otherBoard = pi->LoadBoard( boardFn.GetFullPath(), nullptr );
360
361 if( importDlg.m_LayersOpt->GetValue() )
362 {
363 BOARD* loadedBoard = m_frame->GetBoard();
364
365 // Check if "Import Settings" board has more layers than the current board.
366 okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard );
367 }
368 }
369 catch( const IO_ERROR& ioe )
370 {
371 // You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
372 // underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
373 // cost us much.
374 try
375 {
376 if( ioe.Problem() != wxT( "CANCEL" ) )
377 {
378 wxString msg = wxString::Format( _( "Error loading board file:\n%s" ),
379 boardFn.GetFullPath() );
380 DisplayErrorMessage( this, msg, ioe.What() );
381 }
382
383 if( otherPrj != &m_frame->Prj() )
384 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
385 }
386 catch(...)
387 {
388 // That was already our best-efforts
389 }
390
391 return;
392 }
393
394 if( okToProceed )
395 {
396 otherBoard->SetProject( otherPrj );
397
398 // If layers options are imported, import also the stackup
399 // layers options and stackup are linked, so they cannot be imported
400 // separately, and stackup can be imported only after layers options
401 if( importDlg.m_LayersOpt->GetValue() )
402 {
403 m_physicalStackup->ImportSettingsFrom( otherBoard );
404 m_layers->ImportSettingsFrom( otherBoard );
405 m_boardFinish->ImportSettingsFrom( otherBoard );
406 }
407
408 if( importDlg.m_TextAndGraphicsOpt->GetValue() )
409 {
411 m_textAndGraphicsPage )->ImportSettingsFrom( otherBoard );
412 }
413
414 if( importDlg.m_FormattingOpt->GetValue() )
415 {
417 m_formattingPage )->ImportSettingsFrom( otherBoard );
418 }
419
420 if( importDlg.m_ConstraintsOpt->GetValue() )
421 {
423 m_constraintsPage )->ImportSettingsFrom( otherBoard );
424 }
425
426 if( importDlg.m_NetclassesOpt->GetValue() )
427 {
428 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
429
431 m_netclassesPage )->ImportSettingsFrom( otherProjectFile.m_NetSettings );
432 }
433
434 if( importDlg.m_ComponentClassesOpt->GetValue() )
435 {
436 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
437
439 ->ImportSettingsFrom( otherProjectFile.m_ComponentClassSettings );
440 }
441
442 if( importDlg.m_TracksAndViasOpt->GetValue() )
443 {
445 m_tracksAndViasPage )->ImportSettingsFrom( otherBoard );
446 }
447
448 if( importDlg.m_TeardropsOpt->GetValue() )
449 {
451 m_teardropsPage )->ImportSettingsFrom( otherBoard );
452 }
453
454 if( importDlg.m_TuningPatternsOpt->GetValue() )
455 {
457 m_tuningPatternsPage )->ImportSettingsFrom( otherBoard );
458 }
459
460 if( importDlg.m_MaskAndPasteOpt->GetValue() )
461 {
463 m_maskAndPagePage )->ImportSettingsFrom( otherBoard );
464 }
465
466 if( importDlg.m_CustomRulesOpt->GetValue() )
467 {
469 m_customRulesPage )->ImportSettingsFrom( otherBoard );
470 }
471
472 if( importDlg.m_SeveritiesOpt->GetValue() )
473 {
474 BOARD_DESIGN_SETTINGS& otherSettings = otherBoard->GetDesignSettings();
475
477 m_severitiesPage )->ImportSettingsFrom( otherSettings.m_DRCSeverities );
478 }
479 if( importDlg.m_TuningProfilesOpt->GetValue() )
480 {
481 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
482
484 ->ImportSettingsFrom( otherProjectFile.TuningProfileParameters() );
485 }
486
487 if( otherPrj != &m_frame->Prj() )
488 otherBoard->ClearProject();
489 }
490
491 // Clean up and free memory before leaving
492 if( otherPrj != &m_frame->Prj() )
493 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
494
495 delete otherBoard;
496}
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:322
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition board.cpp:2393
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:202
void ClearProject()
Definition board.cpp:240
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1044
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_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:136
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.
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:58
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:205
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:202
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