KiCad PCB EDA Suite
dialog_schematic_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) 2020 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 
20 #include <sch_edit_frame.h>
21 #include <schematic.h>
22 #include <kiface_i.h>
24 #include <panel_setup_severities.h>
25 #include <panel_setup_formatting.h>
26 #include <panel_setup_pinmap.h>
27 #include <eeschema_config.h>
28 #include <erc_item.h>
29 #include <panel_text_variables.h>
30 #include "dialog_schematic_setup.h"
32 
33 
35  PAGED_DIALOG( aFrame, _( "Schematic Setup" ),
36  _( "Import Settings from Another Project..." ) ),
37  m_frame( aFrame ),
38  m_severities( nullptr )
39 {
42  m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
43 
44  ERC_ITEM dummyItem( 0 );
45  m_severities = new PANEL_SETUP_SEVERITIES( this, dummyItem,
48 
50 
51  /*
52  * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
53  */
54 
55  m_treebook->AddPage( new wxPanel( this ), _( "General" ) );
56  m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
57  m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
58 
59  m_treebook->AddPage( new wxPanel( this ), _( "Electrical Rules" ) );
60  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
61  m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
62 
63  m_treebook->AddPage( new wxPanel( this ), _( "Project" ) );
64  m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
65 
66  for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
67  m_macHack.push_back( true );
68 
69  // Connect Events
70  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
71  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
72 
74 }
75 
76 
78 {
79  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
80  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
81 }
82 
83 
84 void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
85 {
86 #ifdef __WXMAC__
87  // Work around an OSX bug where the wxGrid children don't get placed correctly until
88  // the first resize event
89  int page = event.GetSelection();
90 
91  if( m_macHack[ page ] )
92  {
93  wxSize pageSize = m_treebook->GetPage( page )->GetSize();
94  pageSize.x -= 1;
95 
96  m_treebook->GetPage( page )->SetSize( pageSize );
97  m_macHack[ page ] = false;
98  }
99 #endif
100 }
101 
102 
103 // Run Import Settings... action
104 void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
105 {
106  DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
107 
108  if( importDlg.ShowModal() == wxID_CANCEL )
109  return;
110 
111  wxConfigBase* cfg = new wxFileConfig( wxEmptyString, wxEmptyString, importDlg.GetFilePath() );
112 
113  // We do not want expansion of env var values when reading our project config file
114  cfg->SetExpandEnvVars( false );
115  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
116 
117  if( importDlg.m_formattingOpt->GetValue() )
118  {
119  std::vector<PARAM_CFG*> params;
120  m_frame->AddFormattingParameters( params );
121 
122  wxConfigLoadParams( cfg, params, GROUP_SCH_EDIT );
124  }
125 
126  if( importDlg.m_fieldNameTemplatesOpt->GetValue() )
127  {
128  TEMPLATES templateMgr;
129  PARAM_CFG_FIELDNAMES param( &templateMgr );
130  param.ReadParam( cfg );
131 
132  m_fieldNameTemplates->ImportSettingsFrom( &templateMgr );
133  }
134 
135  if( importDlg.m_pinMapOpt->GetValue() )
136  {
137  // JEY TODO
138  }
139 
140  if( importDlg.m_SeveritiesOpt->GetValue() )
141  {
142  ERC_SETTINGS settings;
143  settings.LoadDefaults();
145 
147  }
148 
149  delete cfg;
150 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
PANEL_SETUP_PINMAP * m_pinMap
DIALOG_SCHEMATIC_SETUP(SCH_EDIT_FRAME *aFrame)
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.
PANEL_TEXT_VARIABLES * m_textVars
Definition: erc.h:61
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void OnAuxiliaryAction(wxCommandEvent &event) override
void AddFormattingParameters(std::vector< PARAM_CFG * > &params)
Definition: erc.h:80
Schematic editor (Eeschema) main window.
std::vector< bool > m_macHack
PANEL_SETUP_FORMATTING * m_formatting
PANEL_SETUP_SEVERITIES * m_severities
#define NULL
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void OnPageChange(wxBookCtrlEvent &event)
wxTreebook * m_treebook
Definition: paged_dialog.h:65
SCHEMATIC & Schematic() const
#define GROUP_SCH_EDIT
Definition: config_params.h:42
std::map< int, int > m_Severities
Definition: erc_settings.h:75
Container for ERC settings.
Definition: erc_settings.h:37
std::vector< PARAM_CFG * > GetProjectFileParameters()
void LoadDefaults()
Definition: erc_settings.h:48
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES * m_fieldNameTemplates
#define _(s)
Definition: 3d_actions.cpp:33
void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
ERC_SETTINGS * ErcSettings() const
Definition: schematic.h:155