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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <confirm.h>
21#include <erc/erc_settings.h>
22#include <jobs/scratch_doc.h>
23#include <sch_edit_frame.h>
24#include <schematic.h>
25#include <schematic_settings.h>
26#include <kiface_base.h>
34#include <panel_setup_pinmap.h>
35#include <erc/erc_item.h>
37#include <panel_bom_presets.h>
41#include <sch_io/sch_io.h>
43#include <widgets/wx_infobar.h>
46
49
50
52 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, false,
53 _( "Import Settings from Another Project..." ), wxSize( 920, 460 ) ),
54 m_frame( aFrame )
55{
56 SetEvtHandlerEnabled( false );
57
59
60 /*
61 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
62 */
63
64 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
65
66 m_formattingPage = m_treebook->GetPageCount();
67 m_treebook->AddLazySubPage(
68 [this]( wxWindow* aParent ) -> wxWindow*
69 {
70 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
71 }, _( "Formatting" ) );
72
73 m_annotationPage = m_treebook->GetPageCount();
74 m_treebook->AddLazySubPage(
75 [this]( wxWindow* aParent ) -> wxWindow*
76 {
77 return new PANEL_EESCHEMA_ANNOTATION_OPTIONS( aParent, m_frame );
78 }, _( "Annotation" ) );
79
80 m_fieldNameTemplatesPage = m_treebook->GetPageCount();
81 m_treebook->AddLazySubPage(
82 [this]( wxWindow* aParent ) -> wxWindow*
83 {
84 PROJECT_FILE& project = m_frame->Prj().GetProjectFile();
85 return new PANEL_TEMPLATE_FIELDNAMES( aParent, &project.m_TemplateFieldNames );
86 }, _( "Field Name Templates" ) );
87
88 m_bomPresetsPage = m_treebook->GetPageCount();
89 m_treebook->AddLazySubPage(
90 [this]( wxWindow* aParent ) -> wxWindow*
91 {
92 SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
93 return new PANEL_BOM_PRESETS( aParent, settings );
94 }, _( "BOM Presets" ) );
95
96
97 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
98
99 m_severitiesPage = m_treebook->GetPageCount();
100 m_treebook->AddLazySubPage(
101 [this]( wxWindow* aParent ) -> wxWindow*
102 {
103 ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
105 ercSettings.m_ERCSeverities, m_pinToPinError.get() );
106 }, _( "Violation Severity" ) );
107
108 m_symbolParityPage = m_treebook->GetPageCount();
109 m_treebook->AddLazySubPage(
110 [this]( wxWindow* aParent ) -> wxWindow*
111 {
112 return new PANEL_SETUP_SYMBOL_PARITY( aParent, m_frame );
113 }, _( "Compare Symbol with Library" ) );
114
115 m_pinMapPage = m_treebook->GetPageCount();
116 m_treebook->AddLazySubPage(
117 [this]( wxWindow* aParent ) -> wxWindow*
118 {
119 return new PANEL_SETUP_PINMAP( aParent, m_frame );
120 }, _( "Pin Conflicts Map" ) );
121
122 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
123
124 m_netclassesPage = m_treebook->GetPageCount();
125 m_treebook->AddLazySubPage(
126 [this]( wxWindow* aParent ) -> wxWindow*
127 {
128 SCHEMATIC& schematic = m_frame->Schematic();
129 return new PANEL_SETUP_NETCLASSES( aParent, m_frame, m_frame->Prj().GetProjectFile().NetSettings(),
130 schematic.GetNetClassAssignmentCandidates(), true );
131 }, _( "Net Classes" ) );
132
133 m_busesPage = m_treebook->GetPageCount();
134 m_treebook->AddLazySubPage(
135 [this]( wxWindow* aParent ) -> wxWindow*
136 {
137 return new PANEL_SETUP_BUSES( aParent, m_frame );
138 }, _( "Bus Alias Definitions" ) );
139
140 m_netChainsPage = m_treebook->GetPageCount();
141 m_treebook->AddLazySubPage(
142 [this]( wxWindow* aParent ) -> wxWindow*
143 {
144 return new PANEL_SETUP_NET_CHAINS( aParent, m_frame );
145 }, _( "Net Chains" ) );
146
147 m_textVarsPage = m_treebook->GetPageCount();
148 m_treebook->AddLazySubPage(
149 [this]( wxWindow* aParent ) -> wxWindow*
150 {
151 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
152 }, _( "Text Variables" ) );
153
154
155 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Schematic Data" ) );
156
157 m_embeddedFilesPage = m_treebook->GetPageCount();
158 m_treebook->AddLazySubPage(
159 [this]( wxWindow* aParent ) -> wxWindow*
160 {
161 return new PANEL_EMBEDDED_FILES( aParent, &m_frame->Schematic(), NO_MARGINS );
162 }, _( "Embedded Files" ) );
163
164 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
165 m_treebook->ExpandNode( i );
166
167 SetEvtHandlerEnabled( true );
168
170
171 if( Prj().IsReadOnly() )
172 {
173 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be editable." ),
174 wxICON_WARNING );
175 }
176
177 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
178
179 wxQueueEvent( m_treebook, evt.Clone() );
180}
181
182
183void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
184{
186
187 int page = aEvent.GetSelection();
188
189 if( Prj().IsReadOnly() )
190 KIUI::Disable( m_treebook->GetPage( page ) );
191}
192
193
194void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
195{
196 SETTINGS_MANAGER* mgr = m_frame->GetSettingsManager();
197 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
198
199 if( importDlg.ShowModal() == wxID_CANCEL )
200 return;
201
202 wxFileName projectFn( importDlg.GetFilePath() );
203
204 SCRATCH_PROJECT scratch( *mgr, projectFn.GetFullPath(), /*aRequireProjectFile=*/true );
205
206 if( !scratch.IsValid() )
207 {
208 DisplayErrorMessage( this, wxString::Format( _( "Error importing settings from project:\n"
209 "Project file %s could not be loaded." ),
210 projectFn.GetFullPath() ) );
211 return;
212 }
213
214 PROJECT* otherPrj = scratch.GetProject();
215 PROJECT_FILE& file = otherPrj->GetProjectFile();
216
217 SCHEMATIC_SETTINGS schematicSettings( &file, "schematic" );
218 ERC_SETTINGS ercSettings( &file, "erc" );
219
220 schematicSettings.LoadFromFile();
221 ercSettings.LoadFromFile();
222
223 if( importDlg.m_FormattingOpt->GetValue() )
224 {
225 static_cast<PANEL_SETUP_FORMATTING*>( m_treebook->ResolvePage( m_formattingPage ) )
226 ->ImportSettingsFrom( schematicSettings );
227 }
228
229 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
230 {
231 static_cast<PANEL_TEMPLATE_FIELDNAMES*>( m_treebook->ResolvePage( m_fieldNameTemplatesPage ) )
233 }
234
235 if( importDlg.m_SymbolParityOpt->GetValue() )
236 {
237 static_cast<PANEL_SETUP_SYMBOL_PARITY*>( m_treebook->ResolvePage( m_symbolParityPage ) )
238 ->ImportSettingsFrom( schematicSettings.m_SymbolParity );
239 }
240
241 if( importDlg.m_PinMapOpt->GetValue() )
242 {
243 static_cast<PANEL_SETUP_PINMAP*>( m_treebook->ResolvePage( m_pinMapPage ) )
244 ->ImportSettingsFrom( ercSettings.m_PinMap );
245 }
246
247 if( importDlg.m_SeveritiesOpt->GetValue() )
248 {
249 static_cast<PANEL_SETUP_SEVERITIES*>( m_treebook->ResolvePage( m_severitiesPage ) )
250 ->ImportSettingsFrom( ercSettings.m_ERCSeverities );
251 }
252
253 if( importDlg.m_NetClassesOpt->GetValue() )
254 {
255 static_cast<PANEL_SETUP_NETCLASSES*>( m_treebook->ResolvePage( m_netclassesPage ) )
257 }
258
259 if( importDlg.m_BomPresetsOpt->GetValue() )
260 {
261 static_cast<PANEL_BOM_PRESETS*>( m_treebook->ResolvePage( m_bomPresetsPage ) )
262 ->ImportBomPresetsFrom( schematicSettings );
263 }
264
265 if( importDlg.m_BomFmtPresetsOpt->GetValue() )
266 {
267 static_cast<PANEL_BOM_PRESETS*>( m_treebook->ResolvePage( m_bomPresetsPage ) )
268 ->ImportBomFmtPresetsFrom( schematicSettings );
269 }
270
271 if( importDlg.m_annotationOpt->GetValue() )
272 {
273 static_cast<PANEL_EESCHEMA_ANNOTATION_OPTIONS*>( m_treebook->ResolvePage( m_annotationPage ) )
274 ->ImportSettingsFrom( schematicSettings );
275 }
276
277 if( importDlg.m_BusAliasesOpt->GetValue() )
278 {
279 static_cast<PANEL_SETUP_BUSES*>( m_treebook->ResolvePage( m_busesPage ) )
281 }
282
283 if( importDlg.m_TextVarsOpt->GetValue() )
284 {
285 static_cast<PANEL_TEXT_VARIABLES*>( m_treebook->ResolvePage( m_textVarsPage ) )
286 ->ImportSettingsFrom( otherPrj );
287 }
288}
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:309
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition erc_item.h:72
Container for ERC settings.
std::map< int, SEVERITY > m_ERCSeverities
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
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 std::map< wxString, std::vector< wxString > > &aAliases)
void ImportSettingsFrom(SCHEMATIC_SETTINGS &aSettings)
void ImportSettingsFrom(const std::shared_ptr< NET_SETTINGS > &aNetSettings)
Schematic-Setup tab for managing committed net chains.
void ImportSettingsFrom(PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL])
void ImportSettingsFrom(std::map< int, SEVERITY > &aSettings)
void ImportSettingsFrom(SYMBOL_PARITY_SETTINGS &aSettings)
void ImportSettingsFrom(TEMPLATES *templateMgr)
void ImportSettingsFrom(const PROJECT *aOtherProject)
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
TEMPLATES m_TemplateFieldNames
Project and global field name templates shared by project editors.
std::map< wxString, std::vector< wxString > > m_BusAliases
Bus alias definitions for the schematic project.
Container for project specific data.
Definition project.h:63
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
These are loaded from Eeschema settings but then overwritten by the project settings.
SYMBOL_PARITY_SETTINGS m_SymbolParity
Holds all the data relating to one schematic.
Definition schematic.h:149
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Schematic editor (Eeschema) main window.
Move-only RAII wrapper for "load a foreign PROJECT non-active and unload it on scope exit.
Definition scratch_doc.h:55
bool IsValid() const
True iff the project loaded (or was already loaded).
PROJECT * GetProject() const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
@ ERCE_PIN_TO_PIN_WARNING
KICOMMON_API void Disable(wxWindow *aWindow)
Makes a window read-only.
#define NO_MARGINS