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>
28#include <confirm.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>
44#include <project.h>
50
51#include "dialog_board_setup.h"
52
53#include <advanced_config.h>
54#include <dialog_board_setup.h>
55#include <footprint.h>
56
57
58#define RESOLVE_PAGE( T, pageIndex ) static_cast<T*>( m_treebook->ResolvePage( pageIndex ) )
59
60DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame, wxWindow* aParentWindow ) :
61 PAGED_DIALOG( aParentWindow ? aParentWindow : aFrame, _( "Board Setup" ), false, false,
62 _( "Import Settings from Another Board..." ), wxSize( 980, 600 ) ),
63 m_frame( aFrame ),
64 m_layers( nullptr ),
65 m_boardFinish( nullptr ),
66 m_physicalStackup( nullptr ),
67 m_zoneHatchOffsets( nullptr ),
68 m_tuningProfiles( nullptr ),
69 m_netClasses( nullptr ),
70 m_currentPage( 0 ),
71 m_layersPage( 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_zoneHatchOffsetsPage = m_treebook->GetPageCount();
132 m_treebook->AddLazySubPage(
133 [this]( wxWindow* aParent ) -> wxWindow*
134 {
135 BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
136
137 return new PANEL_SETUP_ZONE_HATCH_OFFSETS( aParent, m_frame, bds );
138 }, _( "Zone Hatch Offsets" ) );
139
140 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
141
142 m_textAndGraphicsPage = m_treebook->GetPageCount();
143 m_treebook->AddLazySubPage(
144 [this]( wxWindow* aParent ) -> wxWindow*
145 {
146 return new PANEL_SETUP_TEXT_AND_GRAPHICS( aParent, m_frame );
147 }, _( "Defaults" ) );
148
149 m_formattingPage = m_treebook->GetPageCount();
150 m_treebook->AddLazySubPage(
151 [this]( wxWindow* aParent ) -> wxWindow*
152 {
153 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
154 }, _( "Formatting" ) );
155
156 m_treebook->AddLazySubPage(
157 [this]( wxWindow* aParent ) -> wxWindow*
158 {
159 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
160 }, _( "Text Variables" ) );
161
162 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
163
164 m_constraintsPage = m_treebook->GetPageCount();
165 m_treebook->AddLazySubPage(
166 [this]( wxWindow* aParent ) -> wxWindow*
167 {
168 return new PANEL_SETUP_CONSTRAINTS( aParent, m_frame );
169 }, _( "Constraints" ) );
170
171 m_tracksAndViasPage = m_treebook->GetPageCount();
172 m_treebook->AddLazySubPage(
173 [this]( wxWindow* aParent ) -> wxWindow*
174 {
175 return new PANEL_SETUP_TRACKS_AND_VIAS( aParent, m_frame );
176 }, _( "Pre-defined Sizes" ) );
177
178 m_teardropsPage = m_treebook->GetPageCount();
179 m_treebook->AddLazySubPage(
180 [this]( wxWindow* aParent ) -> wxWindow*
181 {
182 return new PANEL_SETUP_TEARDROPS( aParent, m_frame );
183 }, _( "Teardrops" ) );
184
185 m_tuningPatternsPage = m_treebook->GetPageCount();
186 m_treebook->AddLazySubPage(
187 [this]( wxWindow* aParent ) -> wxWindow*
188 {
189 BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings();
190
191 return new PANEL_SETUP_TUNING_PATTERNS( aParent, m_frame,
195 }, _( "Length-tuning Patterns" ) );
196
197 m_tuningProfilesPage = m_treebook->GetPageCount();
198 m_treebook->AddLazySubPage(
199 [this]( wxWindow* aParent ) -> wxWindow*
200 {
201 BOARD* board = m_frame->GetBoard();
202 return new PANEL_SETUP_TUNING_PROFILES( aParent, m_frame, board,
203 m_frame->Prj().GetProjectFile().TuningProfileParameters() );
204 },
205 _( "Tuning Profiles" ) );
206
207 m_netclassesPage = m_treebook->GetPageCount();
208 m_treebook->AddLazySubPage(
209 [this]( wxWindow* aParent ) -> wxWindow*
210 {
211 BOARD* board = m_frame->GetBoard();
212 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
213 m_frame->Prj().GetProjectFile().NetSettings(),
215 false );
216 }, _( "Net Classes" ) );
217
218 m_componentClassesPage = m_treebook->GetPageCount();
219 m_treebook->AddLazySubPage(
220 [this]( wxWindow* aParent ) -> wxWindow*
221 {
222 // Construct the panel
224 aParent, m_frame, m_frame->Prj().GetProjectFile().ComponentClassSettings(),
225 this );
226 },
227 _( "Component Classes" ) );
228
229 m_customRulesPage = m_treebook->GetPageCount();
230 m_treebook->AddLazySubPage(
231 [this]( wxWindow* aParent ) -> wxWindow*
232 {
233 return new PANEL_SETUP_RULES( aParent, m_frame );
234 },
235 _( "Custom Rules" ) );
236
237 m_severitiesPage = m_treebook->GetPageCount();
238 m_treebook->AddLazySubPage(
239 [this]( wxWindow* aParent ) -> wxWindow*
240 {
241 BOARD* board = m_frame->GetBoard();
244 },
245 _( "Violation Severity" ) );
246
247 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Data" ) );
248 m_embeddedFilesPage = m_treebook->GetPageCount();
249 m_treebook->AddLazySubPage(
250 [this]( wxWindow* aParent ) -> wxWindow*
251 {
252 return new PANEL_EMBEDDED_FILES( aParent, m_frame->GetBoard(), NO_MARGINS );
253 },
254 _( "Embedded Files" ) );
255
256 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
257 m_treebook->ExpandNode( i );
258
259 SetEvtHandlerEnabled( true );
260
262
263 if( Prj().IsReadOnly() )
264 {
265 m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not be editable." ),
266 wxICON_WARNING );
267 }
268
269 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
270
271 wxQueueEvent( m_treebook, evt.Clone() );
272}
273
274
278
279
280void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
281{
283
284 size_t page = aEvent.GetSelection();
285
286 if( m_physicalStackupPage > 0 ) // Don't run this during initialization
287 {
289 || page == m_tuningProfilesPage || page == m_zoneHatchOffsetsPage )
290 {
296 }
297
298 // Ensure layer page always gets updated even if we aren't moving towards it
300 {
301 m_layers->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
302
303 // Avoid calling SyncCopperLayers twice if moving from stackup to tuning profiles directly
304 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
305 }
306
307 if( page == m_physicalStackupPage )
308 {
309 m_physicalStackup->OnLayersOptionsChanged( m_layers->GetUILayerMask() );
310 }
312 {
313 m_netClasses->UpdateDelayProfileNames( m_tuningProfiles->GetDelayProfileNames() );
314 }
315 else if( page == m_tuningProfilesPage )
316 {
317 m_tuningProfiles->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
318 }
319 else if( page == m_zoneHatchOffsetsPage )
320 {
321 m_zoneHatchOffsets->SyncCopperLayers( m_physicalStackup->GetCopperLayerCount() );
322 }
323
324 if( Prj().IsReadOnly() )
325 {
326 KIUI::Disable( m_treebook->GetPage( page ) );
327 }
328 }
329
330 m_currentPage = page;
331}
332
333
334void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
335{
336 DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
337
338 if( importDlg.ShowModal() == wxID_CANCEL )
339 return;
340
341 wxFileName boardFn( importDlg.GetFilePath() );
342 wxFileName projectFn( boardFn );
343
344 projectFn.SetExt( FILEEXT::ProjectFileExtension );
345
346 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
347 {
348 wxString msg = wxString::Format( _( "Error importing settings from board:\n"
349 "Associated project file %s could not be loaded" ),
350 projectFn.GetFullPath() );
351 DisplayErrorMessage( this, msg );
352
353 return;
354 }
355
359
360 // Flag so user can stop work if it will result in deleted inner copper layers
361 // and still clean up this function properly.
362 bool okToProceed = true;
363
364 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
365
367 BOARD* otherBoard = nullptr;
368
369 try
370 {
371 WX_PROGRESS_REPORTER progressReporter( this, _( "Load PCB" ), 1, PR_CAN_ABORT );
372
373 pi->SetProgressReporter( &progressReporter );
374
375 otherBoard = pi->LoadBoard( boardFn.GetFullPath(), nullptr );
376
377 if( importDlg.m_LayersOpt->GetValue() )
378 {
379 BOARD* loadedBoard = m_frame->GetBoard();
380
381 // Check if "Import Settings" board has more layers than the current board.
382 okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard );
383 }
384 }
385 catch( const IO_ERROR& ioe )
386 {
387 // You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
388 // underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
389 // cost us much.
390 try
391 {
392 if( ioe.Problem() != wxT( "CANCEL" ) )
393 {
394 wxString msg = wxString::Format( _( "Error loading board file:\n%s" ), boardFn.GetFullPath() );
395 DisplayErrorMessage( this, msg, ioe.What() );
396 }
397
398 if( otherPrj != &m_frame->Prj() )
399 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
400 }
401 catch(...)
402 {
403 // That was already our best-efforts
404 }
405
406 return;
407 }
408
409 if( okToProceed )
410 {
411 otherBoard->SetProject( otherPrj );
412
413 // If layers options are imported, import also the stackup
414 // layers options and stackup are linked, so they cannot be imported
415 // separately, and stackup can be imported only after layers options
416 if( importDlg.m_LayersOpt->GetValue() )
417 {
418 m_physicalStackup->ImportSettingsFrom( otherBoard );
419 m_layers->ImportSettingsFrom( otherBoard );
420 m_boardFinish->ImportSettingsFrom( otherBoard );
421 }
422
423 if( importDlg.m_TextAndGraphicsOpt->GetValue() )
424 RESOLVE_PAGE( PANEL_SETUP_TEXT_AND_GRAPHICS, m_textAndGraphicsPage )->ImportSettingsFrom( otherBoard );
425
426 if( importDlg.m_FormattingOpt->GetValue() )
427 RESOLVE_PAGE( PANEL_SETUP_FORMATTING, m_formattingPage )->ImportSettingsFrom( otherBoard );
428
429 if( importDlg.m_ConstraintsOpt->GetValue() )
430 RESOLVE_PAGE( PANEL_SETUP_CONSTRAINTS, m_constraintsPage )->ImportSettingsFrom( otherBoard );
431
432 if( importDlg.m_NetclassesOpt->GetValue() )
433 {
434 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
435
437 m_netclassesPage )->ImportSettingsFrom( otherProjectFile.m_NetSettings );
438 }
439
440 if( importDlg.m_ComponentClassesOpt->GetValue() )
441 {
442 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
443
445 m_componentClassesPage )->ImportSettingsFrom( otherProjectFile.m_ComponentClassSettings );
446 }
447
448 if( importDlg.m_TracksAndViasOpt->GetValue() )
449 RESOLVE_PAGE( PANEL_SETUP_TRACKS_AND_VIAS, m_tracksAndViasPage )->ImportSettingsFrom( otherBoard );
450
451 if( importDlg.m_TeardropsOpt->GetValue() )
452 RESOLVE_PAGE( PANEL_SETUP_TEARDROPS, m_teardropsPage )->ImportSettingsFrom( otherBoard );
453
454 if( importDlg.m_TuningPatternsOpt->GetValue() )
455 RESOLVE_PAGE( PANEL_SETUP_TUNING_PATTERNS, m_tuningPatternsPage )->ImportSettingsFrom( otherBoard );
456
457 if( importDlg.m_MaskAndPasteOpt->GetValue() )
458 RESOLVE_PAGE( PANEL_SETUP_MASK_AND_PASTE, m_maskAndPastePage )->ImportSettingsFrom( otherBoard );
459
460 if( importDlg.m_ZoneHatchingOffsetsOpt->GetValue() )
461 RESOLVE_PAGE( PANEL_SETUP_ZONE_HATCH_OFFSETS, m_zoneHatchOffsetsPage )->ImportSettingsFrom( otherBoard );
462
463 if( importDlg.m_CustomRulesOpt->GetValue() )
464 RESOLVE_PAGE( PANEL_SETUP_RULES, m_customRulesPage )->ImportSettingsFrom( otherBoard );
465
466 if( importDlg.m_SeveritiesOpt->GetValue() )
467 {
468 BOARD_DESIGN_SETTINGS& otherSettings = otherBoard->GetDesignSettings();
469
471 m_severitiesPage )->ImportSettingsFrom( otherSettings.m_DRCSeverities );
472 }
473
474 if( importDlg.m_TuningProfilesOpt->GetValue() )
475 {
476 PROJECT_FILE& otherProjectFile = otherPrj->GetProjectFile();
477
479 m_tuningProfilesPage )->ImportSettingsFrom( otherProjectFile.TuningProfileParameters() );
480 }
481
482 if( otherPrj != &m_frame->Prj() )
483 otherBoard->ClearProject();
484 }
485
486 // Clean up and free memory before leaving
487 if( otherPrj != &m_frame->Prj() )
488 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
489
490 delete otherBoard;
491}
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
PANEL_SETUP_ZONE_HATCH_OFFSETS * m_zoneHatchOffsets
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.
@ 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:65
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: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