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 <kiface_i.h>
28 #include <drc/drc.h>
29 #include <drc/drc_item.h>
30 #include <dialog_import_settings.h>
31 #include <panel_setup_severities.h>
32 #include <panel_text_variables.h>
33 
34 #include "dialog_board_setup.h"
35 #include "panel_setup_rules.h"
36 
38  PAGED_DIALOG( aFrame, _( "Board Setup" ), _( "Import Settings from Another Project..." ) ),
39  m_frame( aFrame )
40 {
41  m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
43  m_constraints = new PANEL_SETUP_FEATURE_CONSTRAINTS( this, aFrame );
44  m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, m_constraints );
45  m_rules = new PANEL_SETUP_RULES( this, aFrame );
47  m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame );
49 
50  DRC_ITEM dummyItem( 0 );
52  m_severities = new PANEL_SETUP_SEVERITIES( this, dummyItem, bds.m_DRCSeverities,
54 
56 
57  /*
58  * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog().
59  */
60 
61  m_treebook->AddPage( new wxPanel( this ), _( "Board Stackup" ) );
62  m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
63  m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
64  // Change this value if m_physicalStackup is not the page 2 of m_treebook
65  m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
66 
67  m_treebook->AddPage( new wxPanel( this ), _( "Defaults" ) );
68  m_treebook->AddSubPage( m_textAndGraphics, _( "Text & Graphics" ) );
69  m_treebook->AddSubPage( m_tracksAndVias, _( "Tracks & Vias" ) );
70  m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
71 
72  m_treebook->AddPage( new wxPanel( this ), _( "Design Rules" ) );
73  m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
74  m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
75  m_treebook->AddSubPage( m_rules, _( "Rules" ) );
76  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
77 
78  m_treebook->AddPage( new wxPanel( this ), _( "Project" ) );
79  m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
80 
81  for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
82  m_macHack.push_back( true );
83 
84  // Connect Events
85  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
86  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
87 
89 }
90 
91 
93 {
94  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
95  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
96 }
97 
98 
99 void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
100 {
101  if( event.GetSelection() == m_physicalStackupPage )
103 
104 #ifdef __WXMAC__
105  // Work around an OSX bug where the wxGrid children don't get placed correctly until
106  // the first resize event
107  int page = event.GetSelection();
108 
109  if( m_macHack[ page ] )
110  {
111  wxSize pageSize = m_treebook->GetPage( page )->GetSize();
112  pageSize.x -= 1;
113  pageSize.y += 2;
114 
115  m_treebook->GetPage( page )->SetSize( pageSize );
116  m_macHack[ page ] = false;
117  }
118 #endif
119 }
120 
121 
122 // Run Import Settings... action
123 void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
124 {
125  DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
126 
127  if( importDlg.ShowModal() == wxID_CANCEL )
128  return;
129 
130  wxConfigBase* cfg = new wxFileConfig( wxEmptyString, wxEmptyString, importDlg.GetFilePath() );
131 
132  // We do not want expansion of env var values when reading our project config file
133  cfg->SetExpandEnvVars( false );
134  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
135 
136  BOARD* dummyBoard = new BOARD();
137  std::vector<PARAM_CFG*> designSettingsConfig;
138 
139  dummyBoard->GetDesignSettings().AppendConfigs( dummyBoard, &designSettingsConfig );
140  wxConfigLoadParams( cfg, designSettingsConfig, GROUP_PCB );
141 
142  if( importDlg.m_LayersOpt->GetValue() )
143  m_layers->ImportSettingsFrom( dummyBoard );
144  if( importDlg.m_TextAndGraphicsOpt->GetValue() )
145  m_textAndGraphics->ImportSettingsFrom( dummyBoard );
146  if( importDlg.m_ConstraintsOpt->GetValue() )
147  m_constraints->ImportSettingsFrom( dummyBoard );
148  if( importDlg.m_NetclassesOpt->GetValue() )
149  m_netclasses->ImportSettingsFrom( dummyBoard );
150  if( importDlg.m_TracksAndViasOpt->GetValue() )
151  m_tracksAndVias->ImportSettingsFrom( dummyBoard );
152  if( importDlg.m_MaskAndPasteOpt->GetValue() )
153  m_maskAndPaste->ImportSettingsFrom( dummyBoard );
154 
155  // If layers options are imported, import also the stackup
156  // layers options and stackup are linked, so they cannot be imported
157  // separately, and stackup can be imported only after layers options
158  //
159  // Note also currently only the list of enabled layers can be imported, because
160  // we import settings from a .pro project file, not the settings inside
161  // a board, and info only living in the board is not imported.
162  if( importDlg.m_LayersOpt->GetValue() )
163  m_physicalStackup->ImportSettingsFrom( dummyBoard );
164 
165  if( importDlg.m_SeveritiesOpt->GetValue() )
167 
168  delete dummyBoard;
169  delete cfg;
170 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
PANEL_SETUP_RULES * m_rules
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame.
void wxConfigLoadParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Function wxConfigLoadParams uses aList of PARAM_CFG to load configuration values from aCfg.
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:542
PCB_EDIT_FRAME * m_frame
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...
#define NULL
void ImportSettingsFrom(BOARD *aBoard)
Definition: drc.h:109
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void ImportSettingsFrom(BOARD *aBoard)
wxTreebook * m_treebook
Definition: paged_dialog.h:65
void ImportSettingsFrom(BOARD *aBoard)
DIALOG_BOARD_SETUP(PCB_EDIT_FRAME *aFrame)
PANEL_SETUP_TRACKS_AND_VIAS * m_tracksAndVias
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
#define _(s)
Definition: 3d_actions.cpp:33
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
Definition: drc.h:41
PANEL_SETUP_LAYERS * m_layers
std::vector< bool > m_macHack
void OnPageChange(wxBookCtrlEvent &event)
#define GROUP_PCB
Names of sub sections where to store project info in *.pro project config files.
Definition: config_params.h:40
void AppendConfigs(BOARD *aBoard, std::vector< PARAM_CFG * > *aResult)
Function AppendConfigs appends to aResult the configuration setting accessors which will later allow ...
PANEL_SETUP_FEATURE_CONSTRAINTS * m_constraints
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.