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 <widgets/infobar.h>
35 #include "dialog_schematic_setup.h"
37 
38 
40  PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true,
41  _( "Import Settings from Another Project..." ) ),
42  m_frame( aFrame ),
43  m_severities( nullptr )
44 {
45  PROJECT_FILE& project = aFrame->Prj().GetProjectFile();
46  SCHEMATIC& schematic = aFrame->Schematic();
47 
50  m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
51 
54  schematic.ErcSettings().m_Severities,
55  m_pinToPinError.get() );
56 
58 
60  schematic.GetNetClassAssignmentCandidates(), true );
61 
62  /*
63  * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
64  */
65 
66  m_treebook->AddPage( new wxPanel( this ), _( "General" ) );
67  m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
68  m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
69 
70  m_treebook->AddPage( new wxPanel( this ), _( "Electrical Rules" ) );
71  m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
72  m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
73 
74  m_treebook->AddPage( new wxPanel( this ), _( "Project" ) );
75  m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
76  m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
77 
78  for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
79  m_macHack.push_back( true );
80 
81  // Connect Events
82  m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
83  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
84 
85  if( Prj().IsReadOnly() )
86  m_infoBar->ShowMessage( _( "Project is missing or read-only. Changes will not be saved." ) );
87 
89 }
90 
91 
93 {
94  m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
95  wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this );
96 }
97 
98 
99 void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
100 {
101  int page = event.GetSelection();
102 
103  // Enable the reset button only if the page is resettable
104  if( m_resetButton )
105  {
106  if( auto panel = dynamic_cast<RESETTABLE_PANEL*>( m_treebook->GetPage( page ) ) )
107  {
108  m_resetButton->SetToolTip( panel->GetResetTooltip() );
109  m_resetButton->Enable( true );
110  }
111  else
112  {
113  m_resetButton->SetToolTip( wxString() );
114  m_resetButton->Enable( false );
115  }
116  }
117 
118  // Work around an OSX bug where the wxGrid children don't get placed correctly until
119  // the first resize event
120 #ifdef __WXMAC__
121  if( m_macHack[ page ] )
122  {
123  wxSize pageSize = m_treebook->GetPage( page )->GetSize();
124  pageSize.x -= 1;
125  pageSize.y += 2;
126 
127  m_treebook->GetPage( page )->SetSize( pageSize );
128  m_macHack[ page ] = false;
129  }
130 #endif
131 
132  Layout();
133 }
134 
135 
136 // Run Import Settings... action
137 void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
138 {
139  DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
140 
141  if( importDlg.ShowModal() == wxID_CANCEL )
142  return;
143 
144  wxFileName projectFn( importDlg.GetFilePath() );
145 
146  if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
147  {
148  wxString msg = wxString::Format( _( "Error importing settings from project:\n"
149  "Project file %s could not be loaded" ),
150  projectFn.GetFullPath() );
151  DisplayErrorMessage( this, msg );
152 
153  return;
154  }
155 
156  PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
157  SCHEMATIC otherSch( otherPrj );
158  TEMPLATES templateMgr;
159  PROJECT_FILE& file = otherPrj->GetProjectFile();
160 
161  wxASSERT( file.m_SchematicSettings );
162 
164 
165  if( importDlg.m_FormattingOpt->GetValue() )
167 
168  if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
170 
171  if( importDlg.m_PinMapOpt->GetValue() )
173 
174  if( importDlg.m_SeveritiesOpt->GetValue() )
176 
177  if( importDlg.m_NetClassesOpt->GetValue() )
178  m_netclasses->ImportSettingsFrom( &file.m_NetSettings->m_NetClasses );
179 
180  m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
181 }
void ImportSettingsFrom(std::map< int, int > &aSettings)
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:120
PROJECT holds project specific data.
Definition: project.h:61
PANEL_SETUP_PINMAP * m_pinMap
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:253
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:44
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
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:155
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:124
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
TEMPLATES m_TemplateFieldNames
void OnAuxiliaryAction(wxCommandEvent &event) override
NET_SETTINGS & NetSettings()
Definition: project_file.h:92
Schematic editor (Eeschema) main window.
std::shared_ptr< ERC_ITEM > m_pinToPinError
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:175
NETCLASSES m_NetClasses
Definition: net_settings.h:39
#define NULL
WX_INFOBAR * m_infoBar
Definition: paged_dialog.h:79
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:141
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:75
SCHEMATIC & Schematic() const
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:156
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:154
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
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:201
#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:77
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:131
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:153
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
PANEL_SETUP_NETCLASSES * m_netclasses