KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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_base.h>
29#include <panel_setup_pinmap.h>
30#include <erc_item.h>
37
38
40 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true,
41 _( "Import Settings from Another Project..." ) ),
42 m_frame( aFrame )
43{
44 SetEvtHandlerEnabled( false );
45
47
48 /*
49 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
50 */
51
52 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
53
54 m_formattingPage = m_treebook->GetPageCount();
56 [this]( wxWindow* aParent ) -> wxWindow*
57 {
58 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
59 }, _( "Formatting" ) );
60
61 m_fieldNameTemplatesPage = m_treebook->GetPageCount();
63 [this]( wxWindow* aParent ) -> wxWindow*
64 {
66 return new PANEL_TEMPLATE_FIELDNAMES( aParent, &settings.m_TemplateFieldNames );
67 }, _( "Field Name Templates" ) );
68
69 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
70
71 m_severitiesPage = m_treebook->GetPageCount();
73 [this]( wxWindow* aParent ) -> wxWindow*
74 {
75 ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
77 ercSettings.m_ERCSeverities,
78 m_pinToPinError.get() );
79 }, _( "Violation Severity" ) );
80
81 m_pinMapPage = m_treebook->GetPageCount();
83 [this]( wxWindow* aParent ) -> wxWindow*
84 {
85 return new PANEL_SETUP_PINMAP( aParent, m_frame );
86 }, _( "Pin Conflicts Map" ) );
87
88 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
89
90 m_netclassesPage = m_treebook->GetPageCount();
92 [this]( wxWindow* aParent ) -> wxWindow*
93 {
94 SCHEMATIC& schematic = m_frame->Schematic();
95 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
98 true );
99 }, _( "Net Classes" ) );
100
101 m_busesPage = m_treebook->GetPageCount();
103 [this]( wxWindow* aParent ) -> wxWindow*
104 {
105 return new PANEL_SETUP_BUSES( aParent, m_frame );
106 }, _( "Bus Alias Definitions" ) );
107
109 [this]( wxWindow* aParent ) -> wxWindow*
110 {
111 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
112 }, _( "Text Variables" ) );
113
114 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
115 m_treebook->ExpandNode( i );
116
117 // This is unfortunate, but it's the cost of lazy-loading the panels
118 m_treebook->SetMinSize( wxSize( 920, 460 ) );
119 m_treebook->SetInitialSize( wxSize( 920, 460 ) );
120
121 SetEvtHandlerEnabled( true );
122
124
125 if( Prj().IsReadOnly() )
126 {
127 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
128 "editable." ), wxICON_WARNING );
129 }
130
131 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
132
133 wxQueueEvent( m_treebook, evt.Clone() );
134}
135
136
138{
139}
140
141
142void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
143{
145
146 int page = aEvent.GetSelection();
147
148 if( Prj().IsReadOnly() )
149 KIUI::Disable( m_treebook->GetPage( page ) );
150}
151
152
153void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
154{
155 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
156
157 if( importDlg.ShowModal() == wxID_CANCEL )
158 return;
159
160 wxFileName projectFn( importDlg.GetFilePath() );
161
162 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
163 {
164 wxString msg = wxString::Format( _( "Error importing settings from project:\n"
165 "Project file %s could not be loaded." ),
166 projectFn.GetFullPath() );
167 DisplayErrorMessage( this, msg );
168
169 return;
170 }
171
172 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
173 SCHEMATIC otherSch( otherPrj );
174 PROJECT_FILE& file = otherPrj->GetProjectFile();
175
176 wxASSERT( file.m_SchematicSettings );
177
179
180 if( importDlg.m_FormattingOpt->GetValue() )
181 {
183 ->ImportSettingsFrom( *file.m_SchematicSettings );
184 }
185
186 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
187 {
189 ->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames );
190 }
191
192 if( importDlg.m_PinMapOpt->GetValue() )
193 {
195 ->ImportSettingsFrom( file.m_ErcSettings->m_PinMap );
196 }
197
198 if( importDlg.m_SeveritiesOpt->GetValue() )
199 {
201 ->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities );
202 }
203
204 if( importDlg.m_NetClassesOpt->GetValue() )
205 {
207 ->ImportSettingsFrom( file.m_NetSettings );
208 }
209
210 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
211}
void onPageChanged(wxBookCtrlEvent &aEvent) override
DIALOG_SCHEMATIC_SETUP(SCH_EDIT_FRAME *aFrame)
std::shared_ptr< ERC_ITEM > m_pinToPinError
void onAuxiliaryAction(wxCommandEvent &aEvent) override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SETTINGS_MANAGER * GetSettingsManager() const
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:232
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:76
Container for ERC settings.
Definition: erc_settings.h:114
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:173
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:176
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
WX_TREEBOOK * GetTreebook()
Definition: paged_dialog.h:38
WX_INFOBAR * m_infoBar
Definition: paged_dialog.h:70
WX_TREEBOOK * m_treebook
Definition: paged_dialog.h:66
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:127
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:96
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:168
Container for project specific data.
Definition: project.h:64
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
These settings were stored in SCH_BASE_FRAME previously.
TEMPLATES m_TemplateFieldNames
Holds all the data relating to one schematic.
Definition: schematic.h:72
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:205
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:306
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:212
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
wxWindow * ResolvePage(size_t aPage)
Definition: wx_treebook.cpp:99
bool AddLazySubPage(std::function< wxWindow *(wxWindow *aParent)> aLazyCtor, const wxString &text, bool bSelect=false, int imageId=NO_IMAGE)
Definition: wx_treebook.cpp:92
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:308
This file is part of the common library.
#define _(s)
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:85
void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:321