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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19#include <jobs/scratch_doc.h>
20#include <pcb_edit_frame.h>
21#include <panel_setup_layers.h>
30#include <confirm.h>
32#include <widgets/wx_infobar.h>
33#include <kiface_base.h>
34#include <drc/drc_item.h>
36#include <pcb_io/pcb_io.h>
37#include <pcb_io/pcb_io_mgr.h>
42#include <drc/drc_engine.h>
44#include <ki_exception.h>
52#include <project.h>
59
60#include "dialog_board_setup.h"
61
62#include <advanced_config.h>
63#include <dialog_board_setup.h>
64#include <footprint.h>
65
66
67#define RESOLVE_PAGE( T, pageIndex ) static_cast<T*>( m_treebook->ResolvePage( pageIndex ) )
68
69DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame, wxWindow* aParentWindow ) :
70 PAGED_DIALOG( aParentWindow ? aParentWindow : aFrame, _( "Board Setup" ), false, false,
71 _( "Import Settings from Another Board..." ), wxSize( 980, 600 ) ),
72 m_frame( aFrame ),
73 m_layers( nullptr ),
74 m_boardFinish( nullptr ),
75 m_physicalStackup( nullptr ),
76 m_zones( nullptr ),
77 m_tuningProfiles( nullptr ),
78 m_netClasses( nullptr ),
79 m_currentPage( 0 ),
80 m_layersPage( 0 ),
83 m_defaultsPage( 0 ),
87 m_viaStacksPage( 0 ),
88 m_teardropsPage( 0 ),
93 m_initComplete( false )
94{
95 m_ruleDocument = std::make_unique<DRC_RULE_DOCUMENT>( m_frame->GetBoard() );
96 m_ruleDocument->Load();
97
98 m_stagedSettings = std::make_unique<BOARD_DESIGN_SETTINGS>( m_frame->GetBoard()->GetDesignSettings() );
99
100 SetEvtHandlerEnabled( false );
101
102 /*
103 * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
104 */
105
106 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) );
107
108 /*
109 * WARNING: Code currently relies on the layers setup coming before the physical stackup panel,
110 * and thus transferring data to the board first. See comment in
111 * PANEL_SETUP_BOARD_STACKUP::TransferDataFromWindow and rework this logic if it is determined
112 * that the order of these pages should be changed.
113 */
114 m_layersPage = m_treebook->GetPageCount();
115 m_treebook->AddLazySubPage(
116 [this]( wxWindow* aParent ) -> wxWindow*
117 {
118 return new PANEL_SETUP_LAYERS( aParent, m_frame );
119 }, _( "Board Editor Layers" ) );
120
121 m_physicalStackupPage = m_treebook->GetPageCount();
122 m_treebook->AddLazySubPage(
123 [this]( wxWindow* aParent ) -> wxWindow*
124 {
128 }, _( "Physical Stackup" ) );
129
130 m_boardFinishPage = m_treebook->GetPageCount();
131 m_treebook->AddLazySubPage(
132 [this]( wxWindow* aParent ) -> wxWindow*
133 {
134 return new PANEL_SETUP_BOARD_FINISH( aParent, m_frame );
135 }, _( "Board Finish" ) );
136
137 m_drillChartPage = m_treebook->GetPageCount();
138 m_treebook->AddLazySubPage(
139 [this]( wxWindow* aParent ) -> wxWindow*
140 {
141 return new PANEL_SETUP_DRILL_CHART( aParent, m_frame );
142 }, _( "Drill Chart" ) );
143
144 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
145
146 m_defaultsPage = m_treebook->GetPageCount();
147 m_treebook->AddLazySubPage(
148 [this]( wxWindow* aParent ) -> wxWindow*
149 {
150 return new PANEL_SETUP_DEFAULTS( aParent, m_frame );
151 }, _( "Defaults" ) );
152
153 m_formattingPage = m_treebook->GetPageCount();
154 m_treebook->AddLazySubPage(
155 [this]( wxWindow* aParent ) -> wxWindow*
156 {
157 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
158 }, _( "Formatting" ) );
159
160 m_treebook->AddLazySubPage(
161 [this]( wxWindow* aParent ) -> wxWindow*
162 {
163 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
164 }, _( "Text Variables" ) );
165
166 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
167
168 m_treebook->AddLazySubPage(
169 [this]( wxWindow* aParent ) -> wxWindow*
170 {
171 return new PANEL_SETUP_CONSTRAINTS( aParent, m_frame, m_ruleDocument.get(), *m_stagedSettings );
172 },
173 _( "Constraints" ) );
174
175 const std::vector<std::pair<PANEL_SETUP_CONSTRAINT_RULES::FAMILY, wxString>> ruleFamilies = {
183 };
184
185 for( const auto& [family, familyTitle] : ruleFamilies )
186 {
187 size_t familyPage = m_treebook->GetPageCount();
188
189 // An empty page, so selecting the family drops through to the first page under it, as
190 // the other tree level nodes do.
191 m_treebook->AddSubPage( new wxPanel( GetTreebook() ), familyTitle );
192
194 {
195 // The rules in this family are read against these defaults, so they sit together.
196 m_treebook->InsertLazySubPage(
197 familyPage,
198 [this]( wxWindow* aParent ) -> wxWindow*
199 {
200 return new PANEL_SETUP_MASK_AND_PASTE( aParent, m_frame, *m_stagedSettings );
201 },
202 _( "Solder Mask/Paste" ) );
203 }
204
205 for( const CONSTRAINT_SECTION& section : PANEL_SETUP_CONSTRAINT_RULES::SectionsFor( family ) )
206 {
207 m_treebook->InsertLazySubPage(
208 familyPage,
209 [this, section]( wxWindow* aParent ) -> wxWindow*
210 {
211 return new PANEL_SETUP_CONSTRAINT_RULES( aParent, m_frame, m_ruleDocument.get(),
212 *m_stagedSettings, section );
213 },
214 section.title );
215 }
216 }
217
218 m_tracksAndViasPage = m_treebook->GetPageCount();
219 m_treebook->AddLazySubPage(
220 [this]( wxWindow* aParent ) -> wxWindow*
221 {
222 return new PANEL_SETUP_TRACKS_AND_VIAS( aParent, m_frame );
223 }, _( "Pre-defined Sizes" ) );
224
225 m_viaStacksPage = m_treebook->GetPageCount();
226 m_treebook->AddLazySubPage(
227 [this]( wxWindow* aParent ) -> wxWindow*
228 {
229 return new PANEL_SETUP_VIA_STACKS( aParent, m_frame );
230 },
231 _( "Microvia Stacks" ) );
232
233 m_zonesPage = m_treebook->GetPageCount();
234 m_treebook->AddLazySubPage(
235 [this]( wxWindow* aParent ) -> wxWindow*
236 {
237 return new PANEL_SETUP_ZONES( aParent, m_frame, m_frame->GetBoard()->GetDesignSettings() );
238 },
239 _( "Zones" ) );
240
241 m_teardropsPage = m_treebook->GetPageCount();
242 m_treebook->AddLazySubPage(
243 [this]( wxWindow* aParent ) -> wxWindow*
244 {
245 return new PANEL_SETUP_TEARDROPS( aParent, m_frame );
246 }, _( "Teardrops" ) );
247
248 m_tuningPatternsPage = m_treebook->GetPageCount();
249 m_treebook->AddLazySubPage(
250 [this]( wxWindow* aParent ) -> wxWindow*
251 {
252 BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
253
254 return new PANEL_SETUP_TUNING_PATTERNS( aParent, m_frame,
258 }, _( "Length-tuning Patterns" ) );
259
260 m_tuningProfilesPage = m_treebook->GetPageCount();
261 m_treebook->AddLazySubPage(
262 [this]( wxWindow* aParent ) -> wxWindow*
263 {
264 BOARD* board = m_frame->GetBoard();
265 return new PANEL_SETUP_TUNING_PROFILES( aParent, m_frame, board,
266 m_frame->Prj().GetProjectFile().TuningProfileParameters() );
267 },
268 _( "Tuning Profiles" ) );
269
270 m_netclassesPage = m_treebook->GetPageCount();
271 m_treebook->AddLazySubPage(
272 [this]( wxWindow* aParent ) -> wxWindow*
273 {
274 BOARD* board = m_frame->GetBoard();
275 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
276 m_frame->Prj().GetProjectFile().NetSettings(),
278 false );
279 }, _( "Net Classes" ) );
280
281 m_componentClassesPage = m_treebook->GetPageCount();
282 m_treebook->AddLazySubPage(
283 [this]( wxWindow* aParent ) -> wxWindow*
284 {
285 // Construct the panel
287 aParent, m_frame, m_frame->Prj().GetProjectFile().ComponentClassSettings(),
288 this );
289 },
290 _( "Component Classes" ) );
291
292 m_customRulesPage = m_treebook->GetPageCount();
293 m_treebook->AddLazySubPage(
294 [this]( wxWindow* aParent ) -> wxWindow*
295 {
296 return new PANEL_SETUP_RULES( aParent, m_frame, m_ruleDocument.get() );
297 },
298 _( "Custom Rules" ) );
299
300 m_severitiesPage = m_treebook->GetPageCount();
301 m_treebook->AddLazySubPage(
302 [this]( wxWindow* aParent ) -> wxWindow*
303 {
304 BOARD* board = m_frame->GetBoard();
307 },
308 _( "Violation Severity" ) );
309
310 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Data" ) );
311 m_embeddedFilesPage = m_treebook->GetPageCount();
312 m_treebook->AddLazySubPage(
313 [this]( wxWindow* aParent ) -> wxWindow*
314 {
315 BOARD* board = m_frame->GetBoard();
316
317 std::vector<EMBEDDED_FILES*> inheritedFiles;
318
319 for( FOOTPRINT* fp : board->Footprints() )
320 inheritedFiles.push_back( fp->GetEmbeddedFiles() );
321
322 return new PANEL_EMBEDDED_FILES( aParent, board->GetEmbeddedFiles(), NO_MARGINS, inheritedFiles );
323 },
324 _( "Embedded Files" ) );
325
326 m_initComplete = true;
327
328 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
329 m_treebook->ExpandNode( i );
330
331 SetEvtHandlerEnabled( true );
332
333 // Bound after DIALOG_SHIM's handlers so these run first
334 Bind( wxEVT_BUTTON, &DIALOG_BOARD_SETUP::onCancelButton, this, wxID_CANCEL );
335 Bind( wxEVT_CLOSE_WINDOW, &DIALOG_BOARD_SETUP::onCloseWindow, this );
336
338
339 if( Prj().IsReadOnly() )
340 {
341 m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not be editable." ),
342 wxICON_WARNING );
343 }
344
345 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
346
347 wxQueueEvent( m_treebook, evt.Clone() );
348}
349
350
352{
353 Unbind( wxEVT_BUTTON, &DIALOG_BOARD_SETUP::onCancelButton, this, wxID_CANCEL );
354 Unbind( wxEVT_CLOSE_WINDOW, &DIALOG_BOARD_SETUP::onCloseWindow, this );
355
356 // Pages reading m_ruleDocument or m_stagedSettings would outlive them in ~wxWindow, so empty
357 // their lazy holders now and leave the tree intact for ~PAGED_DIALOG
358 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
359 {
360 wxWindow* page = m_treebook->GetResolvedPage( i );
361
362 if( page && page != m_treebook->GetPage( i )
363 && ( dynamic_cast<PANEL_SETUP_CONSTRAINT_RULES*>( page ) || dynamic_cast<PANEL_SETUP_RULES*>( page )
364 || dynamic_cast<PANEL_SETUP_CONSTRAINTS*>( page )
365 || dynamic_cast<PANEL_SETUP_MASK_AND_PASTE*>( page ) ) )
366 {
367 m_treebook->GetPage( i )->DestroyChildren();
368 }
369 }
370}
371
372
374{
375 auto* rules = static_cast<PANEL_SETUP_RULES*>( m_treebook->GetResolvedPage( m_customRulesPage ) );
376
377 if( !m_ruleDocument->IsModified() && ( !rules || !rules->IsModified() ) )
378 return true;
379
380 return OKOrCancelDialog( this, _( "Confirmation" ), _( "Discard changes to custom rules?" ), wxEmptyString,
381 _( "Discard Changes" ) ) == wxID_OK;
382}
383
384
385void DIALOG_BOARD_SETUP::onCancelButton( wxCommandEvent& aEvent )
386{
387 if( canDiscardChanges() )
388 aEvent.Skip();
389}
390
391
392void DIALOG_BOARD_SETUP::onCloseWindow( wxCloseEvent& aEvent )
393{
394 if( aEvent.CanVeto() && !canDiscardChanges() )
395 {
396 aEvent.Veto();
397 return;
398 }
399
400 aEvent.Skip();
401}
402
403
405{
407 return false;
408
409 bool saveRules = m_ruleDocument->IsModified() && !m_frame->GetBoard()->GetDesignRulesPath().IsEmpty();
410
411 if( saveRules )
412 {
413 wxString error;
414
415 if( !m_ruleDocument->Save( &error ) )
416 {
417 SetError( wxString::Format( _( "Cannot save design rules: %s" ), error ), nullptr, nullptr );
418 return false;
419 }
420 }
421
422 BOARD_DESIGN_SETTINGS& boardSettings = m_frame->GetBoard()->GetDesignSettings();
423
426
427 // The engine builds its implicit rules from the board defaults, so it starts after they land
428 if( saveRules )
429 {
430 try
431 {
432 boardSettings.m_DRCEngine->InitEngine( m_frame->GetBoard()->GetDesignRulesPath() );
433 }
434 catch( PARSE_ERROR& )
435 {
436 // The rules are saved. DRC reports any compile problem when it runs.
437 }
438 }
439
440 // References to renamed profiles can only be fixed up after all pages have saved
441 auto* tuningProfiles =
442 static_cast<PANEL_SETUP_TUNING_PROFILES*>( m_treebook->GetResolvedPage( m_tuningProfilesPage ) );
443
444 if( tuningProfiles )
445 {
446 const std::map<wxString, wxString> renames = tuningProfiles->TakeProfileRenames();
447
448 if( !renames.empty() )
449 {
450 std::shared_ptr<NET_SETTINGS>& netSettings = m_frame->Prj().GetProjectFile().NetSettings();
451
452 auto remapProfile = [&renames]( const std::shared_ptr<NETCLASS>& aNetclass )
453 {
454 auto it = renames.find( aNetclass->GetTuningProfile() );
455
456 if( it != renames.end() )
457 aNetclass->SetTuningProfile( it->second );
458 };
459
460 remapProfile( netSettings->GetDefaultNetclass() );
461
462 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
463 remapProfile( netclass );
464
465 netSettings->ClearAllCaches();
466 }
467 }
468
469 return true;
470}
471
472
473void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
474{
476
477 size_t page = m_treebook->GetSelection();
478
479 if( int selected = m_treebook->GetSelection(); selected != wxNOT_FOUND )
480 refreshRulePage( selected );
481
482 // A constraint can be set on its rule page or on the page it has always been set on, and
483 // leaving either one writes it, so every open page showing that value reads it again
484 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
485 {
486 wxWindow* resolved = m_treebook->GetResolvedPage( i );
487
488 if( auto* rulesPage = dynamic_cast<PANEL_SETUP_CONSTRAINT_RULES*>( resolved ) )
489 rulesPage->RefreshDefaults();
490 else if( auto* constraintsPage = dynamic_cast<PANEL_SETUP_CONSTRAINTS*>( resolved ) )
491 constraintsPage->RefreshDefaults();
492 else if( auto* maskPage = dynamic_cast<PANEL_SETUP_MASK_AND_PASTE*>( resolved ) )
493 maskPage->RefreshDefaults();
494 }
495
496 if( m_initComplete )
497 {
499 || page == m_tuningProfilesPage || page == m_zonesPage || page == m_boardFinishPage )
500 {
506 }
507
508 // Ensure layer page always gets updated even if we aren't moving towards it
510 {
511 m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
512
513 // Avoid calling SyncCopperLayers twice if moving from stackup to tuning profiles directly
514 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
515 }
516
517 if( page == m_physicalStackupPage )
518 {
519 m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
520 }
522 {
523 m_netClasses->RemapDelayProfileNames( m_tuningProfiles->TakeProfileRenames() );
524 m_netClasses->UpdateDelayProfileNames( m_tuningProfiles->GetDelayProfileNames() );
525 }
526 else if( page == m_tuningProfilesPage )
527 {
528 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
529 }
530 else if( page == m_zonesPage )
531 {
532 m_zones->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
533 }
534
535 if( page == m_boardFinishPage )
536 {
537 m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
538 m_boardFinish->SetStackup( m_physicalStackup->GetStackup(), m_physicalStackup->GetCopperLayerCount() );
539 }
540
541 if( Prj().IsReadOnly() )
542 {
543 KIUI::Disable( m_treebook->GetPage( page ) );
544 }
545 }
546
547 m_currentPage = page;
548}
549
550
551void DIALOG_BOARD_SETUP::forEachOpenRulePage( const std::function<void( PANEL_SETUP_CONSTRAINT_RULES* )>& aAction )
552{
553 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
554 {
555 if( auto* page = dynamic_cast<PANEL_SETUP_CONSTRAINT_RULES*>( m_treebook->GetResolvedPage( i ) ) )
556 aAction( page );
557 }
558}
559
560
561void DIALOG_BOARD_SETUP::refreshStagedPages( const wxString& aGroup )
562{
563 // Pages of the other group may hold edits not yet written to the staged settings
564 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
565 {
566 wxWindow* resolved = m_treebook->GetResolvedPage( i );
567
568 if( auto* rulesPage = dynamic_cast<PANEL_SETUP_CONSTRAINT_RULES*>( resolved ) )
569 {
570 if( rulesPage->ImportGroup() == aGroup )
571 rulesPage->RefreshDefaults();
572 }
573 else if( dynamic_cast<PANEL_SETUP_CONSTRAINTS*>( resolved ) )
574 {
575 if( aGroup == _( "Constraints" ) )
576 resolved->TransferDataToWindow();
577 }
578 else if( dynamic_cast<PANEL_SETUP_MASK_AND_PASTE*>( resolved ) )
579 {
580 if( aGroup == _( "Solder Mask/Paste" ) )
581 resolved->TransferDataToWindow();
582 }
583 }
584}
585
586
588{
589 wxWindow* resolved = m_treebook->GetResolvedPage( aPage );
590
591 if( auto* rulesPage = dynamic_cast<PANEL_SETUP_CONSTRAINT_RULES*>( resolved ) )
592 rulesPage->RefreshFromDocument();
593 else if( auto* textPage = dynamic_cast<PANEL_SETUP_RULES*>( resolved ) )
594 textPage->RefreshFromDocument();
595 else if( auto* constraintsPage = dynamic_cast<PANEL_SETUP_CONSTRAINTS*>( resolved ) )
596 constraintsPage->RefreshDefaults();
597 else if( auto* maskPage = dynamic_cast<PANEL_SETUP_MASK_AND_PASTE*>( resolved ) )
598 maskPage->RefreshDefaults();
599}
600
601
602void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
603{
604 DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
605
606 if( importDlg.ShowModal() == wxID_CANCEL )
607 return;
608
609 wxFileName boardFn( importDlg.GetFilePath() );
610
611 SCRATCH_PROJECT scratch( *m_frame->GetSettingsManager(), boardFn.GetFullPath(),
612 /*aRequireProjectFile=*/true );
613
614 if( !scratch.IsValid() )
615 {
616 wxFileName projectFn( boardFn );
617 projectFn.SetExt( FILEEXT::ProjectFileExtension );
618
619 wxString msg = wxString::Format( _( "Error importing settings from board:\n"
620 "Associated project file %s could not be loaded" ),
621 projectFn.GetFullPath() );
622 DisplayErrorMessage( this, msg );
623
624 return;
625 }
626
627 PROJECT* otherPrj = scratch.GetProject();
628
632
633 // Flag so user can stop work if it will result in deleted inner copper layers
634 // and still clean up this function properly.
635 bool okToProceed = true;
636
638 std::unique_ptr<BOARD> otherBoard;
639
640 try
641 {
642 WX_PROGRESS_REPORTER progressReporter( this, _( "Load PCB" ), 1, PR_CAN_ABORT );
643
644 pi->SetProgressReporter( &progressReporter );
645
646 otherBoard = pi->LoadBoard( boardFn.GetFullPath() );
647
648 if( importDlg.m_LayersOpt->GetValue() )
649 {
650 BOARD* loadedBoard = m_frame->GetBoard();
651
652 // Check if "Import Settings" board has more layers than the current board.
653 okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard.get() );
654 }
655 }
656 catch( const IO_CANCELLED& )
657 {
658 // A user-cancelled load is not an error.
659 return;
660 }
661 catch( const IO_ERROR& ioe )
662 {
663 // You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
664 // underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
665 // cost us much.
666 try
667 {
668 wxString msg = wxString::Format( _( "Error loading board file:\n%s" ), boardFn.GetFullPath() );
669 DisplayErrorMessage( this, msg, ioe.What() );
670 }
671 catch(...)
672 {
673 // That was already our best-efforts
674 }
675
676 return;
677 }
678
679 if( okToProceed )
680 {
681 BOARD* other = otherBoard.get();
682
683 other->SetProject( otherPrj );
684
685 // Always ClearProject before destruction, even if a later
686 // ImportSettingsFrom throws. Skipping clear when otherPrj is the
687 // active project preserves the live editor's BoardSettings.
688 const bool activeProject = ( otherPrj == &m_frame->Prj() );
689
690 struct BOARD_DETACH_GUARD
691 {
692 BOARD* board;
693 bool skip;
694 ~BOARD_DETACH_GUARD() { if( board && !skip ) board->ClearProject(); }
695 } detachGuard{ other, activeProject };
696
697 // If layers options are imported, import also the stackup
698 // layers options and stackup are linked, so they cannot be imported
699 // separately, and stackup can be imported only after layers options
700 if( importDlg.m_LayersOpt->GetValue() )
701 {
702 m_physicalStackup->ImportSettingsFrom( other );
703 m_layers->ImportSettingsFrom( other );
704 m_boardFinish->ImportSettingsFrom( other );
705 }
706
707 if( importDlg.m_TextAndGraphicsOpt->GetValue() )
708 RESOLVE_PAGE( PANEL_SETUP_DEFAULTS, m_defaultsPage )->ImportSettingsFrom( other );
709
710 if( importDlg.m_FormattingOpt->GetValue() )
711 RESOLVE_PAGE( PANEL_SETUP_FORMATTING, m_formattingPage )->ImportSettingsFrom( other );
712
713 if( importDlg.m_ConstraintsOpt->GetValue() )
714 {
716 refreshStagedPages( _( "Constraints" ) );
717 }
718
719 if( importDlg.m_NetclassesOpt->GetValue() )
720 {
721 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
722
724 m_netclassesPage )->ImportSettingsFrom( otherProjectFile.m_NetSettings );
725 }
726
727 if( importDlg.m_ComponentClassesOpt->GetValue() )
728 {
729 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
730
732 m_componentClassesPage )->ImportSettingsFrom( otherProjectFile.m_ComponentClassSettings );
733 }
734
735 if( importDlg.m_TracksAndViasOpt->GetValue() )
736 {
737 RESOLVE_PAGE( PANEL_SETUP_TRACKS_AND_VIAS, m_tracksAndViasPage )->ImportSettingsFrom( other );
738 RESOLVE_PAGE( PANEL_SETUP_VIA_STACKS, m_viaStacksPage )->ImportSettingsFrom( other );
739 }
740
741 if( importDlg.m_ZonesOpt->GetValue() )
742 RESOLVE_PAGE( PANEL_SETUP_ZONES, m_zonesPage )->ImportSettingsFrom( other );
743
744 if( importDlg.m_TeardropsOpt->GetValue() )
745 RESOLVE_PAGE( PANEL_SETUP_TEARDROPS, m_teardropsPage )->ImportSettingsFrom( other );
746
747 if( importDlg.m_TuningPatternsOpt->GetValue() )
748 RESOLVE_PAGE( PANEL_SETUP_TUNING_PATTERNS, m_tuningPatternsPage )->ImportSettingsFrom( other );
749
750 if( importDlg.m_MaskAndPasteOpt->GetValue() )
751 {
753 refreshStagedPages( _( "Solder Mask/Paste" ) );
754 }
755
756 if( importDlg.m_ZoneHatchingOffsetsOpt->GetValue() )
757 RESOLVE_PAGE( PANEL_SETUP_ZONES, m_zonesPage )->ImportHatchOffsetsFrom( other );
758
759 if( importDlg.m_CustomRulesOpt->GetValue() )
760 {
761 m_ruleDocument->LoadFrom( other->GetDesignRulesPath() );
762
764
767 {
768 aPage->RefreshFromDocument();
769 } );
770 }
771
772 if( importDlg.m_SeveritiesOpt->GetValue() )
773 {
774 BOARD_DESIGN_SETTINGS& otherSettings = other->GetDesignSettings();
775
777 m_severitiesPage )->ImportSettingsFrom( otherSettings.m_DRCSeverities );
778 }
779
780 if( importDlg.m_TuningProfilesOpt->GetValue() )
781 {
782 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
783
785 m_tuningProfilesPage )->ImportSettingsFrom( otherProjectFile.TuningProfileParameters() );
786 }
787
788 }
789}
const char * name
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
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:411
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition board.cpp:3709
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition board.cpp:2982
const FOOTPRINTS & Footprints() const
Definition board.h:465
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition board.cpp:379
void ClearProject()
Definition board.cpp:420
wxString GetDesignRulesPath() const
Return the absolute path to the design rules file for this board.
Definition board.cpp:437
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
DIALOG_BOARD_SETUP(PCB_EDIT_FRAME *aFrame, wxWindow *aWindow=nullptr)
void forEachOpenRulePage(const std::function< void(PANEL_SETUP_CONSTRAINT_RULES *)> &aAction)
std::unique_ptr< DRC_RULE_DOCUMENT > m_ruleDocument
PCB_EDIT_FRAME * m_frame
void onCancelButton(wxCommandEvent &aEvent)
PANEL_SETUP_TUNING_PROFILES * m_tuningProfiles
std::unique_ptr< BOARD_DESIGN_SETTINGS > m_stagedSettings
The constraint, mask and rule pages edit one value from several pages, so they share this copy,...
void onAuxiliaryAction(wxCommandEvent &aEvent) override
PANEL_SETUP_BOARD_STACKUP * m_physicalStackup
PANEL_SETUP_ZONES * m_zones
void refreshStagedPages(const wxString &aGroup)
Reads the staged settings back into the open pages of one Import Settings group.
PANEL_SETUP_BOARD_FINISH * m_boardFinish
PANEL_SETUP_LAYERS * m_layers
bool TransferDataFromWindow() override
void onPageChanged(wxBookCtrlEvent &aEvent) override
PANEL_SETUP_NETCLASSES * m_netClasses
void onCloseWindow(wxCloseEvent &aEvent)
void refreshRulePage(size_t aPage)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition drc_item.h:173
An exception saying that the user cancelled an interactive part of a load, import,...
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()
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)
bool TransferDataFromWindow() override
WX_TREEBOOK * m_treebook
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
static void CopySettings(const BOARD_DESIGN_SETTINGS &aFrom, BOARD_DESIGN_SETTINGS &aTo)
Copies every value this page edits, which is what the Constraints import group carries.
static std::vector< CONSTRAINT_SECTION > SectionsFor(FAMILY aFamily)
The sections of one family, in the order they are shown in the tree.
Board-wide drill chart and map setup.
static void CopySettings(const BOARD_DESIGN_SETTINGS &aFrom, BOARD_DESIGN_SETTINGS &aTo)
Copies every value this page edits, which is what the Solder Mask/Paste import group carries.
The main frame for Pcbnew.
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a PCB_IO 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:63
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
Move-only RAII wrapper for "load a foreign PROJECT non-active and unload it on scope exit.
Definition scratch_doc.h:56
bool IsValid() const
True iff the project loaded (or was already loaded).
PROJECT * GetProject() const
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
Definition confirm.cpp:165
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
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
One constraint on a Design Rules page: its board default, the net class values that apply to it,...
A filename or source description, a problem input line, a line number, a byte offset,...
Definition of file extensions used in Kicad.
#define PR_CAN_ABORT