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 <confirm.h>
21 #include <sch_edit_frame.h>
22 #include <schematic.h>
23 #include <kiface_i.h>
26 #include <panel_setup_severities.h>
27 #include <panel_setup_formatting.h>
28 #include <panel_setup_pinmap.h>
29 #include <erc_item.h>
30 #include <panel_text_variables.h>
31 #include <project/project_file.h>
32 #include <project/net_settings.h>
34 #include "dialog_schematic_setup.h"
36 
37 
39  PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true,
40  _( "Import Settings from Another Project..." ) ),
41  m_frame( aFrame ),
42  m_severities( nullptr )
43 {
44  PROJECT_FILE& project = aFrame->Prj().GetProjectFile();
45  SCHEMATIC& schematic = aFrame->Schematic();
46 
49  m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
50 
53  schematic.ErcSettings().m_Severities,
55 
57 
59  schematic.GetNetClassAssignmentCandidates(), true );
60 
61  /*
62  * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
63  */
64 
65  m_treebook->AddGroupEntry( _( "General" ) );
66  m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
67  m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
68 
69  m_treebook->AddGroupEntry( _( "Electrical Rules" ) );
70  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
71  m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
72 
73  m_treebook->AddGroupEntry( _( "Project" ) );
74  m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
75  m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
76 
77  for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
78  m_macHack.push_back( true );
79 
80  // Connect Events
81  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
82  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
83 
85 }
86 
87 
89 {
90  delete m_pinToPinError;
91 
92  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
93  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
94 }
95 
96 
97 void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
98 {
99  int page = event.GetSelection();
100 
101  // Enable the reset button only if the page is resettable
102  if( m_resetButton )
103  {
104  if( auto panel = dynamic_cast<RESETTABLE_PANEL*>( m_treebook->GetPage( page ) ) )
105  {
106  m_resetButton->SetToolTip( panel->GetResetTooltip() );
107  m_resetButton->Enable( true );
108  }
109  else
110  {
111  m_resetButton->SetToolTip( wxString() );
112  m_resetButton->Enable( false );
113  }
114  }
115 
116  // Work around an OSX bug where the wxGrid children don't get placed correctly until
117  // the first resize event
118 #ifdef __WXMAC__
119  if( m_macHack[ page ] )
120  {
121  wxSize pageSize = m_treebook->GetPage( page )->GetSize();
122  pageSize.x -= 1;
123  pageSize.y += 2;
124 
125  m_treebook->GetPage( page )->SetSize( pageSize );
126  m_macHack[ page ] = false;
127  }
128 #endif
129 
130  Layout();
131 }
132 
133 
134 // Run Import Settings... action
135 void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
136 {
137  DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
138 
139  if( importDlg.ShowModal() == wxID_CANCEL )
140  return;
141 
142  wxFileName projectFn( importDlg.GetFilePath() );
143 
144  if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
145  {
146  wxString msg = wxString::Format( _( "Error importing settings from project:\n"
147  "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 
156  SCHEMATIC otherSch( otherPrj );
157 
158  TEMPLATES templateMgr;
159  PROJECT_FILE& file = otherPrj->GetProjectFile();
160 
161  wxASSERT( file.m_SchematicSettings );
162 
163  file.m_SchematicSettings->m_TemplateFieldNames = &templateMgr;
165 
166  if( importDlg.m_FormattingOpt->GetValue() )
168 
169  if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
171 
172  if( importDlg.m_PinMapOpt->GetValue() )
174 
175  if( importDlg.m_SeveritiesOpt->GetValue() )
177 
178  if( importDlg.m_NetClassesOpt->GetValue() )
179  m_netclasses->ImportSettingsFrom( &file.m_NetSettings->m_NetClasses );
180 
181  m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
182 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
PAGED_TREEBOOK * m_treebook
Definition: paged_dialog.h:83
PROJECT holds project specific data.
Definition: project.h:61
PANEL_SETUP_PINMAP * m_pinMap
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
DIALOG_SCHEMATIC_SETUP(SCH_EDIT_FRAME *aFrame)
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
This file is part of the common library.
PANEL_TEXT_VARIABLES * m_textVars
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:39
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
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
Schematic editor (Eeschema) main window.
TEMPLATES * m_TemplateFieldNames
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
void ImportSettingsFrom(PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL])
std::vector< bool > m_macHack
PANEL_SETUP_FORMATTING * m_formatting
PANEL_SETUP_SEVERITIES * m_severities
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here) NOTE: If we go multi-board in the future,...
Definition: project_file.h:186
NETCLASSES m_NetClasses
Definition: net_settings.h:39
#define NULL
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:137
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void OnPageChange(wxBookCtrlEvent &event)
SCHEMATIC & Schematic() const
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:159
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:135
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:138
std::map< int, int > m_Severities
Definition: erc_settings.h:157
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
PANEL_EESCHEMA_TEMPLATE_FIELDNAMES * m_fieldNameTemplates
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
#define _(s)
Definition: 3d_actions.cpp:33
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
wxButton * m_resetButton
Definition: paged_dialog.h:85
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:145
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
void ImportSettingsFrom(NETCLASSES *aBoard)
std::vector< wxString > GetNetClassAssignmentCandidates()
Returns a list of name candidates for netclass assignment.
Definition: schematic.cpp:167
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
PANEL_SETUP_NETCLASSES * m_netclasses