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