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>
36#include <sch_io/sch_io.h>
41
42
44 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, false,
45 _( "Import Settings from Another Project..." ), wxSize( 920, 460 ) ),
46 m_frame( aFrame )
47{
48 SetEvtHandlerEnabled( false );
49
51
52 /*
53 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
54 */
55
56 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
57
58 m_formattingPage = m_treebook->GetPageCount();
60 [this]( wxWindow* aParent ) -> wxWindow*
61 {
62 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
63 }, _( "Formatting" ) );
64
65 m_fieldNameTemplatesPage = m_treebook->GetPageCount();
67 [this]( wxWindow* aParent ) -> wxWindow*
68 {
70 return new PANEL_TEMPLATE_FIELDNAMES( aParent, &settings.m_TemplateFieldNames );
71 }, _( "Field Name Templates" ) );
72
73 m_bomPresetsPage = m_treebook->GetPageCount();
75 [this]( wxWindow* aParent ) -> wxWindow*
76 {
78 return new PANEL_BOM_PRESETS( aParent, settings );
79 }, _( "BOM Presets" ) );
80
81
82 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
83
84 m_severitiesPage = m_treebook->GetPageCount();
86 [this]( wxWindow* aParent ) -> wxWindow*
87 {
88 ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
90 ercSettings.m_ERCSeverities,
91 m_pinToPinError.get() );
92 }, _( "Violation Severity" ) );
93
94 m_pinMapPage = m_treebook->GetPageCount();
96 [this]( wxWindow* aParent ) -> wxWindow*
97 {
98 return new PANEL_SETUP_PINMAP( aParent, m_frame );
99 }, _( "Pin Conflicts Map" ) );
100
101 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
102
103 m_netclassesPage = m_treebook->GetPageCount();
105 [this]( wxWindow* aParent ) -> wxWindow*
106 {
107 SCHEMATIC& schematic = m_frame->Schematic();
108 return new PANEL_SETUP_NETCLASSES( aParent, m_frame,
111 true );
112 }, _( "Net Classes" ) );
113
114 m_busesPage = m_treebook->GetPageCount();
116 [this]( wxWindow* aParent ) -> wxWindow*
117 {
118 return new PANEL_SETUP_BUSES( aParent, m_frame );
119 }, _( "Bus Alias Definitions" ) );
120
121 m_textVarsPage = m_treebook->GetPageCount();
123 [this]( wxWindow* aParent ) -> wxWindow*
124 {
125 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
126 }, _( "Text Variables" ) );
127
128
129 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Schematic Data" ) );
130
131 m_embeddedFilesPage = m_treebook->GetPageCount();
133 [this]( wxWindow* aParent ) -> wxWindow*
134 {
135 return new PANEL_EMBEDDED_FILES( aParent, &m_frame->Schematic() );
136 }, _( "Embedded Files" ) );
137
138 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
139 m_treebook->ExpandNode( i );
140
141 SetEvtHandlerEnabled( true );
142
144
145 if( Prj().IsReadOnly() )
146 {
147 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
148 "editable." ), wxICON_WARNING );
149 }
150
151 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
152
153 wxQueueEvent( m_treebook, evt.Clone() );
154}
155
156
158{
159}
160
161
162void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
163{
165
166 int page = aEvent.GetSelection();
167
168 if( Prj().IsReadOnly() )
169 KIUI::Disable( m_treebook->GetPage( page ) );
170}
171
172
173void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
174{
175 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
176
177 if( importDlg.ShowModal() == wxID_CANCEL )
178 return;
179
180 wxFileName projectFn( importDlg.GetFilePath() );
181 bool alreadyLoaded = false;
182
183 if( m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() ) )
184 {
185 alreadyLoaded = true;
186 }
187 else if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
188 {
189 wxString msg = wxString::Format( _( "Error importing settings from project:\n"
190 "Project file %s could not be loaded." ),
191 projectFn.GetFullPath() );
192 DisplayErrorMessage( this, msg );
193
194 return;
195 }
196
197 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
198 SCHEMATIC otherSch( otherPrj );
199 PROJECT_FILE& file = otherPrj->GetProjectFile();
200
201 wxASSERT( file.m_SchematicSettings );
202
204
205 if( importDlg.m_FormattingOpt->GetValue() )
206 {
208 ->ImportSettingsFrom( *file.m_SchematicSettings );
209 }
210
211 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
212 {
214 ->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames );
215 }
216
217 if( importDlg.m_PinMapOpt->GetValue() )
218 {
220 ->ImportSettingsFrom( file.m_ErcSettings->m_PinMap );
221 }
222
223 if( importDlg.m_SeveritiesOpt->GetValue() )
224 {
226 ->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities );
227 }
228
229 if( importDlg.m_NetClassesOpt->GetValue() )
230 {
232 ->ImportSettingsFrom( file.m_NetSettings );
233 }
234
235 if( importDlg.m_BomPresetsOpt->GetValue() )
236 {
238 ->ImportBomPresetsFrom( *file.m_SchematicSettings );
239 }
240
241 if( importDlg.m_BomFmtPresetsOpt->GetValue() )
242 {
244 ->ImportBomFmtPresetsFrom( *file.m_SchematicSettings );
245 }
246
247 if( importDlg.m_BusAliasesOpt->GetValue() )
248 {
249 // The bus aliases are stored on individual sheets, so we have to load the whole
250 // schematic for this one.
251
252 wxFileName schematicFn( projectFn );
253 schematicFn.SetExt( FILEEXT::KiCadSchematicFileExtension );
254
255 wxString fullFileName = schematicFn.GetFullPath();
256 wxString msg;
257 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
258 WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Bus Aliases" ), 1 );
259
260 pi->SetProgressReporter( &progressReporter );
261
262 try
263 {
264 wxBusyCursor busy;
265 otherSch.SetRoot( pi->LoadSchematicFile( fullFileName, &otherSch ) );
266
267 // Make ${SHEETNAME} work on the root sheet until we properly support
268 // naming the root sheet
269 otherSch.Root().SetName( _( "Root" ) );
270 }
271 catch( const FUTURE_FORMAT_ERROR& ffe )
272 {
273 msg.Printf( _( "Error fetching bus aliases. Could not load schematic '%s'." ),
274 fullFileName );
275 progressReporter.Hide();
276 DisplayErrorMessage( this, msg, ffe.Problem() );
277 }
278 catch( const IO_ERROR& ioe )
279 {
280 msg.Printf( _( "Error fetching bus aliases. Could not load schematic '%s'." ),
281 fullFileName );
282 progressReporter.Hide();
283 DisplayErrorMessage( this, msg, ioe.What() );
284 }
285
286 // This fixes a focus issue after the progress reporter is done on GTK. It shouldn't
287 // cause any issues on macOS and Windows. If it does, it will have to be conditionally
288 // compiled.
289 Raise();
290
292 ->ImportSettingsFrom( otherSch );
293 }
294
295 if( importDlg.m_TextVarsOpt->GetValue() )
296 {
298 ->ImportSettingsFrom( otherPrj );
299 }
300
301 if( !alreadyLoaded )
302 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
303}
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...
int ShowModal() override
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:299
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:76
Container for ERC settings.
Definition: erc_settings.h:135
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:212
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:216
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
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:72
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:137
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:140
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:103
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:178
Container for project specific data.
Definition: project.h:64
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:77
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:312
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:194
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:423
SCH_SHEET & Root() const
Definition: schematic.h:125
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:319
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
void SetName(const wxString &aName)
Definition: sch_sheet.h:108
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
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
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:97
static const std::string KiCadSchematicFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
KICOMMON_API void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:323
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:176