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 
33 #include "dialog_board_setup.h"
34 
35 
36 bool g_macHack;
37 
38 
40  PAGED_DIALOG( aFrame, _( "Board Setup" ), _( "Import Settings from Another Project..." ) ),
41  m_frame( aFrame )
42 {
43  m_layers = new PANEL_SETUP_LAYERS( this, aFrame );
45  m_constraints = new PANEL_SETUP_FEATURE_CONSTRAINTS( this, aFrame );
46  m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, m_constraints );
48  m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame );
50 
51  DRC_ITEM dummyItem;
53  m_severities = new PANEL_SETUP_SEVERITIES( this, dummyItem, bds.m_DRCSeverities,
55 
56  /*
57  * WARNING: If you change page names you MUST update calls to DoShowBoardSetupDialog().
58  */
59 
60  m_treebook->AddPage( new wxPanel( this ), _( "Board Stackup" ) );
61  m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) );
62  m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
63  // Change this value if m_physicalStackup is not the page 2 of m_treebook
64  m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
65 
66  m_treebook->AddPage( new wxPanel( this ), _( "Defaults" ) );
67  m_treebook->AddSubPage( m_textAndGraphics, _( "Text & Graphics" ) );
68  m_treebook->AddSubPage( m_tracksAndVias, _( "Tracks & Vias" ) );
69  m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) );
70 
71  m_treebook->AddPage( new wxPanel( this ), _( "Design Rules" ) );
72  m_treebook->AddSubPage( m_constraints, _( "Constraints" ) );
73  m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
74  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
75 
76  // Connect Events
77  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
78  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
79 
81  g_macHack = true;
82 }
83 
84 
86 {
87  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
88  wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), NULL, this );
89 }
90 
91 
92 void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
93 {
94  if( event.GetSelection() == m_physicalStackupPage )
96 
97 #ifdef __WXMAC__
98  // Work around an OSX bug where the wxGrid children don't get placed correctly
99  if( g_macHack && m_treebook->GetPage( event.GetSelection() ) == m_tracksAndVias )
100  {
101  m_tracksAndVias->SetSize( wxSize( m_tracksAndVias->GetSize().x - 1,
102  m_tracksAndVias->GetSize().y + 2 ) );
103 
104  g_macHack = false;
105  }
106 #endif
107 }
108 
109 
110 // Run Import Settings... action
111 void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
112 {
113  DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
114 
115  if( importDlg.ShowModal() == wxID_CANCEL )
116  return;
117 
118  wxConfigBase* cfg = new wxFileConfig( wxEmptyString, wxEmptyString, importDlg.GetFilePath() );
119 
120  // We do not want expansion of env var values when reading our project config file
121  cfg->SetExpandEnvVars( false );
122  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
123 
124  BOARD* dummyBoard = new BOARD();
125  std::vector<PARAM_CFG*> designSettingsConfig;
126 
127  dummyBoard->GetDesignSettings().AppendConfigs( dummyBoard, &designSettingsConfig );
128  wxConfigLoadParams( cfg, designSettingsConfig, GROUP_PCB );
129 
130  if( importDlg.m_LayersOpt->GetValue() )
131  m_layers->ImportSettingsFrom( dummyBoard );
132  if( importDlg.m_TextAndGraphicsOpt->GetValue() )
133  m_textAndGraphics->ImportSettingsFrom( dummyBoard );
134  if( importDlg.m_ConstraintsOpt->GetValue() )
135  m_constraints->ImportSettingsFrom( dummyBoard );
136  if( importDlg.m_NetclassesOpt->GetValue() )
137  m_netclasses->ImportSettingsFrom( dummyBoard );
138  if( importDlg.m_TracksAndViasOpt->GetValue() )
139  m_tracksAndVias->ImportSettingsFrom( dummyBoard );
140  if( importDlg.m_MaskAndPasteOpt->GetValue() )
141  m_maskAndPaste->ImportSettingsFrom( dummyBoard );
142 
143  // If layers options are imported, import also the stackup
144  // layers options and stackup are linked, so they cannot be imported
145  // separately, and stackup can be imported only after layers options
146  //
147  // Note also currently only the list of enabled layers can be imported, because
148  // we import settings from a .pro project file, not the settings inside
149  // a board, and info only living in the board is not imported.
150  if( importDlg.m_LayersOpt->GetValue() )
151  m_physicalStackup->ImportSettingsFrom( dummyBoard );
152 
153  if( importDlg.m_SeveritiesOpt->GetValue() )
155 
156  delete dummyBoard;
157  delete cfg;
158 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
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.
bool g_macHack
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:512
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:103
void ImportSettingsFrom(BOARD *aBoard)
wxTreebook * m_treebook
Definition: paged_dialog.h:59
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:163
#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
Definition: drc.h:44
PANEL_SETUP_LAYERS * m_layers
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.