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/erc_item.h>
32#include <panel_bom_presets.h>
39
40
42 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, false,
43 _( "Import Settings from Another Project..." ), wxSize( 920, 460 ) ),
44 m_frame( aFrame )
45{
46 SetEvtHandlerEnabled( false );
47
49
50 /*
51 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
52 */
53
54 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
55
56 m_formattingPage = m_treebook->GetPageCount();
58 [this]( wxWindow* aParent ) -> wxWindow*
59 {
60 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
61 }, _( "Formatting" ) );
62
63 m_fieldNameTemplatesPage = m_treebook->GetPageCount();
65 [this]( wxWindow* aParent ) -> wxWindow*
66 {
68 return new PANEL_TEMPLATE_FIELDNAMES( aParent, &settings.m_TemplateFieldNames );
69 }, _( "Field Name Templates" ) );
70
71 m_bomPresetsPage = m_treebook->GetPageCount();
73 [this]( wxWindow* aParent ) -> wxWindow*
74 {
76 return new PANEL_BOM_PRESETS( aParent, settings );
77 }, _( "BOM Presets" ) );
78
79
80 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
81
82 m_severitiesPage = m_treebook->GetPageCount();
84 [this]( wxWindow* aParent ) -> wxWindow*
85 {
86 ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
88 ercSettings.m_ERCSeverities,
89 m_pinToPinError.get() );
90 }, _( "Violation Severity" ) );
91
92 m_pinMapPage = m_treebook->GetPageCount();
94 [this]( wxWindow* aParent ) -> wxWindow*
95 {
96 return new PANEL_SETUP_PINMAP( aParent, m_frame );
97 }, _( "Pin Conflicts Map" ) );
98
99 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
100
101 m_netclassesPage = m_treebook->GetPageCount();
103 [this]( wxWindow* aParent ) -> wxWindow*
104 {
105 SCHEMATIC& schematic = m_frame->Schematic();
106 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
109 true );
110 }, _( "Net Classes" ) );
111
112 m_busesPage = m_treebook->GetPageCount();
114 [this]( wxWindow* aParent ) -> wxWindow*
115 {
116 return new PANEL_SETUP_BUSES( aParent, m_frame );
117 }, _( "Bus Alias Definitions" ) );
118
120 [this]( wxWindow* aParent ) -> wxWindow*
121 {
122 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
123 }, _( "Text Variables" ) );
124
125
126 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Schematic Data" ) );
127
128 m_embeddedFilesPage = m_treebook->GetPageCount();
130 [this]( wxWindow* aParent ) -> wxWindow*
131 {
132 return new PANEL_EMBEDDED_FILES( aParent, &m_frame->Schematic() );
133 }, _( "Embedded Files" ) );
134
135 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
136 m_treebook->ExpandNode( i );
137
138 SetEvtHandlerEnabled( true );
139
141
142 if( Prj().IsReadOnly() )
143 {
144 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
145 "editable." ), wxICON_WARNING );
146 }
147
148 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
149
150 wxQueueEvent( m_treebook, evt.Clone() );
151}
152
153
155{
156}
157
158
159void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
160{
162
163 int page = aEvent.GetSelection();
164
165 if( Prj().IsReadOnly() )
166 KIUI::Disable( m_treebook->GetPage( page ) );
167}
168
169
170void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
171{
172 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
173
174 if( importDlg.ShowModal() == wxID_CANCEL )
175 return;
176
177 wxFileName projectFn( importDlg.GetFilePath() );
178 bool alreadyLoaded = false;
179
180 if( m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ) )
181 {
182 alreadyLoaded = true;
183 }
184 else if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
185 {
186 wxString msg = wxString::Format( _( "Error importing settings from project:\n"
187 "Project file %s could not be loaded." ),
188 projectFn.GetFullPath() );
189 DisplayErrorMessage( this, msg );
190
191 return;
192 }
193
194 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
195 SCHEMATIC otherSch( otherPrj );
196 PROJECT_FILE& file = otherPrj->GetProjectFile();
197
198 wxASSERT( file.m_SchematicSettings );
199
201
202 if( importDlg.m_FormattingOpt->GetValue() )
203 {
205 ->ImportSettingsFrom( *file.m_SchematicSettings );
206 }
207
208 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
209 {
211 ->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames );
212 }
213
214 if( importDlg.m_PinMapOpt->GetValue() )
215 {
217 ->ImportSettingsFrom( file.m_ErcSettings->m_PinMap );
218 }
219
220 if( importDlg.m_SeveritiesOpt->GetValue() )
221 {
223 ->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities );
224 }
225
226 if( importDlg.m_NetClassesOpt->GetValue() )
227 {
229 ->ImportSettingsFrom( file.m_NetSettings );
230 }
231
232 if( importDlg.m_BomPresetsOpt->GetValue() )
233 {
235 ->ImportBomPresetsFrom( *file.m_SchematicSettings );
236 }
237
238 if( importDlg.m_BomFmtPresetsOpt->GetValue() )
239 {
241 ->ImportBomFmtPresetsFrom( *file.m_SchematicSettings );
242 }
243
244 if( !alreadyLoaded )
245 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
246}
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:294
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:76
Container for ERC settings.
Definition: erc_settings.h:127
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:186
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:190
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:39
WX_INFOBAR * m_infoBar
Definition: paged_dialog.h:72
WX_TREEBOOK * m_treebook
Definition: paged_dialog.h:68
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:70
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:132
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:135
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:101
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:173
Container for project specific data.
Definition: project.h:62
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:76
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:297
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:408
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:304
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)
bool AddLazySubPage(std::function< wxWindow *(wxWindow *aParent)> aLazyCtor, const wxString &text, bool bSelect=false, int imageId=NO_IMAGE)
Definition: wx_treebook.cpp:96
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
#define _(s)
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:96
KICOMMON_API void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:323