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-2019 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>
23 #include <panel_setup_netclasses.h>
26 #include <../board_stackup_manager/panel_board_stackup.h>
27 #include <confirm.h>
28 #include <kiface_i.h>
29 #include <drc/drc.h>
30 #include <drc/drc_item.h>
31 #include <dialog_import_settings.h>
32 #include <io_mgr.h>
33 #include <panel_setup_severities.h>
34 #include <panel_text_variables.h>
35 #include <project.h>
36 #include <project/project_file.h>
39 
40 #include "dialog_board_setup.h"
41 #include "panel_setup_rules.h"
42 
44  PAGED_DIALOG( aFrame, _( "Board Setup" ), false, _( "Import Settings from Another Board..." ) ),
45  m_frame( aFrame )
46 {
47  BOARD* board = aFrame->GetBoard();
49 
50  m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
52  m_constraints = new PANEL_SETUP_FEATURE_CONSTRAINTS( this, aFrame );
53  m_rules = new PANEL_SETUP_RULES( this, aFrame );
55  m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame );
57 
59  bds.m_DRCSeverities );
60 
62  board->GetNetClassAssignmentCandidates(), false );
63 
65 
66  /*
67  * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
68  */
69 
70  m_treebook->AddGroupEntry( _( "Board Stackup" ) );
71  m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
72  m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
73  // Change this value if m_physicalStackup is not the page 2 of m_treebook
74  m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
75 
76  m_treebook->AddGroupEntry( _( "Defaults" ) );
77  m_treebook->AddSubPage( m_textAndGraphics, _( "Text & Graphics" ) );
78  m_treebook->AddSubPage( m_tracksAndVias, _( "Tracks & Vias" ) );
79  m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
80 
81  m_treebook->AddGroupEntry( _( "Design Rules" ) );
82  m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
83  m_treebook->AddSubPage( m_rules, _( "Rules" ) );
84  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
85 
86  m_treebook->AddGroupEntry( _( "Project" ) );
87  m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
88  m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
89 
90  for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
91  m_macHack.push_back( true );
92 
93  // Connect Events
94  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
95  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
96 
98 }
99 
100 
102 {
103  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
104  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
105 }
106 
107 
108 void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
109 {
110  if( event.GetSelection() == m_physicalStackupPage )
112 
113 #ifdef __WXMAC__
114  // Work around an OSX bug where the wxGrid children don't get placed correctly until
115  // the first resize event
116  int page = event.GetSelection();
117 
118  if( m_macHack[ page ] )
119  {
120  wxSize pageSize = m_treebook->GetPage( page )->GetSize();
121  pageSize.x -= 1;
122  pageSize.y += 2;
123 
124  m_treebook->GetPage( page )->SetSize( pageSize );
125  m_macHack[ page ] = false;
126  }
127 #endif
128 }
129 
130 
131 // Run Import Settings... action
132 void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
133 {
134  DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
135 
136  if( importDlg.ShowModal() == wxID_CANCEL )
137  return;
138 
139  wxFileName boardFn( importDlg.GetFilePath() );
140  wxFileName projectFn( boardFn );
141 
142  projectFn.SetExt( ProjectFileExtension );
143 
144  if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
145  {
146  wxString msg = wxString::Format( _( "Error importing settings from board:\n"
147  "Associated project file %s could not be loaded" ),
148  projectFn.GetFullPath() );
149  DisplayErrorMessage( this, msg );
150 
151  return;
152  }
153 
154  PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
155 
157 
158  BOARD* otherBoard = new BOARD();
159 
160  try
161  {
162  otherBoard = pi->Load( boardFn.GetFullPath(), nullptr, nullptr );
163  }
164  catch( const IO_ERROR& ioe )
165  {
166  if( ioe.Problem() != wxT( "CANCEL" ) )
167  {
168  wxString msg =
169  wxString::Format( _( "Error loading board file:\n%s" ), boardFn.GetFullPath() );
170  DisplayErrorMessage( this, msg, ioe.What() );
171  }
172 
173  m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
174 
175  return;
176  }
177 
178  otherBoard->SetProject( otherPrj );
179 
180  if( importDlg.m_LayersOpt->GetValue() )
181  m_layers->ImportSettingsFrom( otherBoard );
182  if( importDlg.m_TextAndGraphicsOpt->GetValue() )
183  m_textAndGraphics->ImportSettingsFrom( otherBoard );
184  if( importDlg.m_ConstraintsOpt->GetValue() )
185  m_constraints->ImportSettingsFrom( otherBoard );
186  if( importDlg.m_NetclassesOpt->GetValue() )
188  if( importDlg.m_TracksAndViasOpt->GetValue() )
189  m_tracksAndVias->ImportSettingsFrom( otherBoard );
190  if( importDlg.m_MaskAndPasteOpt->GetValue() )
191  m_maskAndPaste->ImportSettingsFrom( otherBoard );
192 
193  // If layers options are imported, import also the stackup
194  // layers options and stackup are linked, so they cannot be imported
195  // separately, and stackup can be imported only after layers options
196  //
197  // Note also currently only the list of enabled layers can be imported, because
198  // we import settings from a .pro project file, not the settings inside
199  // a board, and info only living in the board is not imported.
200  // TODO: Add import of physical settings now that we are actually loading the board here
201  if( importDlg.m_LayersOpt->GetValue() )
202  m_physicalStackup->ImportSettingsFrom( otherBoard );
203 
204  if( importDlg.m_SeveritiesOpt->GetValue() )
206 
207  otherBoard->ClearProject();
208 
209  m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
210 
211  delete otherBoard;
212 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
PAGED_TREEBOOK * m_treebook
Definition: paged_dialog.h:83
PANEL_SETUP_RULES * m_rules
PROJECT holds project specific data.
Definition: project.h:61
bool AddGroupEntry(const wxString &text, int imageId=NO_IMAGE)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
SETTINGS_MANAGER * GetSettingsManager() const
This file is part of the common library.
const std::string ProjectFileExtension
std::map< int, int > m_DRCSeverities
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...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
PCB_EDIT_FRAME * m_frame
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:45
PANEL_SETUP_BOARD_STACKUP * m_physicalStackup
void OnAuxiliaryAction(wxCommandEvent &event) override
PANEL_SETUP_SEVERITIES * m_severities
void OnLayersOptionsChanged(LSET aNewLayerSet)
Must be called if the copper layers count has changed or solder mask, solder paste or silkscreen laye...
RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destructor.
Definition: io_mgr.h:579
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void ImportSettingsFrom(BOARD *aBoard)
Definition of file extensions used in Kicad.
NETCLASSES & GetNetClasses() const
void ClearProject()
void ImportSettingsFrom(BOARD *aBoard)
DIALOG_BOARD_SETUP(PCB_EDIT_FRAME *aFrame)
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void SetProject(PROJECT *aProject)
Links a board to a given project.
PANEL_SETUP_TRACKS_AND_VIAS * m_tracksAndVias
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save,...
Definition: io_mgr.cpp:61
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
PCB_EDIT_FRAME is the main frame for Pcbnew.
PANEL_SETUP_TEXT_AND_GRAPHICS * m_textAndGraphics
PANEL_SETUP_MASK_AND_PASTE * m_maskAndPaste
PANEL_TEXT_VARIABLES * m_textVars
BOARD * GetBoard() const
void ImportSettingsFrom(NETCLASSES *aBoard)
PANEL_SETUP_LAYERS * m_layers
std::vector< bool > m_macHack
void OnPageChange(wxBookCtrlEvent &event)
std::vector< wxString > GetNetClassAssignmentCandidates()
Function GetNetClassAssignmentCandidates Returns a list of name candidates for netclass assignment.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
PANEL_SETUP_FEATURE_CONSTRAINTS * m_constraints
S-expression Pcbnew file format.
Definition: io_mgr.h:57
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.