KiCad PCB EDA Suite
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 (C) 2017-2023 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>
26#include <../board_stackup_manager/panel_board_stackup.h>
27#include <../board_stackup_manager/panel_board_finish.h>
28#include <confirm.h>
30#include <kiface_base.h>
31#include <drc/drc_item.h>
33#include <io_mgr.h>
36#include <project.h>
42
43#include "dialog_board_setup.h"
44#include "panel_setup_rules.h"
45
46#include <wx/treebook.h>
47
48
50 PAGED_DIALOG( aFrame, _( "Board Setup" ), false,
51 _( "Import Settings from Another Board..." ) ),
52 m_frame( aFrame )
53{
54 SetEvtHandlerEnabled( false );
56 BOARD* board = aFrame->GetBoard();
58
59 m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
61 m_formatting = new PANEL_SETUP_FORMATTING( this, aFrame );
62 m_constraints = new PANEL_SETUP_CONSTRAINTS( this, aFrame );
63 m_rules = new PANEL_SETUP_RULES( this, aFrame );
64 m_tracksAndVias = new PANEL_SETUP_TRACKS_AND_VIAS( this, aFrame );
65 m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame );
67 m_boardFinish = new PANEL_SETUP_BOARD_FINISH( this, aFrame );
68
70 bds.m_DRCSeverities );
71
72 m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(),
73 board->GetNetClassAssignmentCandidates(), false );
74
76
77 /*
78 * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
79 */
80
81 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) );
82
83 m_currentPage = -1;
84
85 /*
86 * WARNING: Code currently relies on the layers setup coming before the physical stackup panel,
87 * and thus transferring data to the board first. See comment in
88 * PANEL_SETUP_BOARD_STACKUP::TransferDataFromWindow and rework this logic if it is determined
89 * that the order of these pages should be changed.
90 */
91 m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
93
94 m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
95
96 // Change this value if m_physicalStackup is not the page 2 of m_treebook
97 m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
98
99 m_treebook->AddSubPage( m_boardFinish, _( "Board Finish" ) );
100 m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
101
102 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) );
103 m_treebook->AddSubPage( m_textAndGraphics, _( "Defaults" ) );
104 m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
105 m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
106
107 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) );
108 m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
109 m_treebook->AddSubPage( m_tracksAndVias, _( "Pre-defined Sizes" ) );
110 m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
111 m_treebook->AddSubPage( m_rules, _( "Custom Rules" ) );
112 m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
113
114 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
115 m_treebook->ExpandNode( i );
116
117 m_treebook->SetMinSize( wxSize( -1, 580 ) );
118 m_treebook->SetInitialSize( wxSize( -1, 700 ) );
119 SetEvtHandlerEnabled( true );
120
122
123 if( Prj().IsReadOnly() )
124 {
125 m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not "
126 "be editable." ), wxICON_WARNING );
127 }
128
129 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
130
131 wxQueueEvent( m_treebook, evt.Clone() );
132}
133
134
136{
137}
138
139
140void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
141{
143
144 int page = aEvent.GetSelection();
145
146 // Ensure layer page always gets updated even if we aren't moving towards it
149
150 if( page == m_physicalStackupPage )
152 else if( Prj().IsReadOnly() )
153 KIUI::Disable( m_treebook->GetPage( page ) );
154
155 m_currentPage = page;
156}
157
158
159void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent )
160{
161 DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
162
163 if( importDlg.ShowModal() == wxID_CANCEL )
164 return;
165
166 wxFileName boardFn( importDlg.GetFilePath() );
167 wxFileName projectFn( boardFn );
168
169 projectFn.SetExt( ProjectFileExtension );
170
171 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
172 {
173 wxString msg = wxString::Format( _( "Error importing settings from board:\n"
174 "Associated project file %s could not be loaded" ),
175 projectFn.GetFullPath() );
176 DisplayErrorMessage( this, msg );
177
178 return;
179 }
180
181 // Flag so user can stop work if it will result in deleted inner copper layers
182 // and still clean up this function properly.
183 bool okToProceed = true;
184
185 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
186
188
189 BOARD* otherBoard = nullptr;
190
191 try
192 {
193 WX_PROGRESS_REPORTER progressReporter( this, _( "Loading PCB" ), 1 );
194
195 otherBoard = pi->Load( boardFn.GetFullPath(), nullptr, nullptr, nullptr,
196 &progressReporter );
197
198 if( importDlg.m_LayersOpt->GetValue() )
199 {
200 BOARD* loadedBoard = m_frame->GetBoard();
201
202 // Check if "Import Settings" board has more layers than the current board.
203 okToProceed = m_layers->CheckCopperLayerCount( loadedBoard, otherBoard );
204 }
205 }
206 catch( const IO_ERROR& ioe )
207 {
208 // You wouldn't think boardFn.GetFullPath() would throw, but we get a stack buffer
209 // underflow from ASAN. While it's probably an ASAN error, a second try/catch doesn't
210 // cost us much.
211 try
212 {
213 if( ioe.Problem() != wxT( "CANCEL" ) )
214 {
215 wxString msg = wxString::Format( _( "Error loading board file:\n%s" ),
216 boardFn.GetFullPath() );
217 DisplayErrorMessage( this, msg, ioe.What() );
218 }
219
220 if( otherPrj != &m_frame->Prj() )
221 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
222 }
223 catch(...)
224 {
225 // That was already our best-efforts
226 }
227
228 return;
229 }
230
231 if( okToProceed )
232 {
233 otherBoard->SetProject( otherPrj );
234
235 // If layers options are imported, import also the stackup
236 // layers options and stackup are linked, so they cannot be imported
237 // separately, and stackup can be imported only after layers options
238 if( importDlg.m_LayersOpt->GetValue() )
239 {
241 m_layers->ImportSettingsFrom( otherBoard );
242 m_boardFinish->ImportSettingsFrom( otherBoard );
243 }
244
245 if( importDlg.m_TextAndGraphicsOpt->GetValue() )
247
248 if( importDlg.m_FormattingOpt->GetValue() )
249 m_formatting->ImportSettingsFrom( otherBoard );
250
251 if( importDlg.m_ConstraintsOpt->GetValue() )
252 m_constraints->ImportSettingsFrom( otherBoard );
253
254 if( importDlg.m_NetclassesOpt->GetValue() )
256
257 if( importDlg.m_TracksAndViasOpt->GetValue() )
258 m_tracksAndVias->ImportSettingsFrom( otherBoard );
259
260 if( importDlg.m_MaskAndPasteOpt->GetValue() )
261 m_maskAndPaste->ImportSettingsFrom( otherBoard );
262
263 if( importDlg.m_SeveritiesOpt->GetValue() )
265
266 if( otherPrj != &m_frame->Prj() )
267 otherBoard->ClearProject();
268 }
269
270 // Clean up and free memory before leaving
271 if( otherPrj != &m_frame->Prj() )
272 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
273
274 delete otherBoard;
275}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
std::set< wxString > GetNetClassAssignmentCandidates() const
Return the set of netname candidates for netclass assignment.
Definition: board.cpp:1501
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
Definition: board.cpp:172
void ClearProject()
Definition: board.cpp:206
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:682
DIALOG_BOARD_SETUP(PCB_EDIT_FRAME *aFrame)
PANEL_SETUP_TEXT_AND_GRAPHICS * m_textAndGraphics
PANEL_SETUP_FORMATTING * m_formatting
PCB_EDIT_FRAME * m_frame
PANEL_SETUP_TRACKS_AND_VIAS * m_tracksAndVias
PANEL_SETUP_MASK_AND_PASTE * m_maskAndPaste
PANEL_SETUP_NETCLASSES * m_netclasses
void onAuxiliaryAction(wxCommandEvent &aEvent) override
PANEL_SETUP_CONSTRAINTS * m_constraints
PANEL_SETUP_RULES * m_rules
PANEL_SETUP_BOARD_STACKUP * m_physicalStackup
PANEL_TEXT_VARIABLES * m_textVars
PANEL_SETUP_BOARD_FINISH * m_boardFinish
PANEL_SETUP_LAYERS * m_layers
void onPageChanged(wxBookCtrlEvent &aEvent) override
PANEL_SETUP_SEVERITIES * m_severities
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: drc_item.h:122
SETTINGS_MANAGER * GetSettingsManager() const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
WX_INFOBAR * m_infoBar
Definition: paged_dialog.h:67
wxTreebook * m_treebook
Definition: paged_dialog.h:63
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
void ImportSettingsFrom(BOARD *aBoard)
void ImportSettingsFrom(BOARD *aBoard)
void OnLayersOptionsChanged(LSET aNewLayerSet)
Must be called if the copper layers count has changed or solder mask, solder paste or silkscreen laye...
void ImportSettingsFrom(BOARD *aBoard)
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
bool CheckCopperLayerCount(BOARD *aWorkingBoard, BOARD *aImportedBoard)
Check and warn if inner copper layers will be deleted.
void SyncCopperLayers(int aNumCopperLayers)
Called when switching to this tab to make sure that any changes to the copper layer count made on the...
void ImportSettingsFrom(BOARD *aBoard)
void ImportSettingsFrom(const std::shared_ptr< NET_SETTINGS > &aNetSettings)
void ImportSettingsFrom(std::map< int, SEVERITY > &aSettings)
BOARD * GetBoard() const
The main frame for Pcbnew.
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:564
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:46
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:168
Container for project specific data.
Definition: project.h:64
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:142
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:325
This file is part of the common library.
#define _(s)
const std::string ProjectFileExtension
void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:321
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Definition of file extensions used in Kicad.