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 <jobs/scratch_doc.h>
22#include <sch_edit_frame.h>
23#include <schematic.h>
24#include <kiface_base.h>
32#include <panel_setup_pinmap.h>
33#include <erc/erc_item.h>
35#include <panel_bom_presets.h>
39#include <sch_io/sch_io.h>
41#include <widgets/wx_infobar.h>
44
47
48
50 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, false,
51 _( "Import Settings from Another Project..." ), wxSize( 920, 460 ) ),
52 m_frame( aFrame )
53{
54 SetEvtHandlerEnabled( false );
55
57
58 /*
59 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
60 */
61
62 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
63
64 m_formattingPage = m_treebook->GetPageCount();
65 m_treebook->AddLazySubPage(
66 [this]( wxWindow* aParent ) -> wxWindow*
67 {
68 return new PANEL_SETUP_FORMATTING( aParent, m_frame );
69 }, _( "Formatting" ) );
70
71 m_annotationPage = m_treebook->GetPageCount();
72 m_treebook->AddLazySubPage(
73 [this]( wxWindow* aParent ) -> wxWindow*
74 {
75 return new PANEL_EESCHEMA_ANNOTATION_OPTIONS( aParent, m_frame );
76 }, _( "Annotation" ) );
77
78 m_fieldNameTemplatesPage = m_treebook->GetPageCount();
79 m_treebook->AddLazySubPage(
80 [this]( wxWindow* aParent ) -> wxWindow*
81 {
82 PROJECT_FILE& project = m_frame->Prj().GetProjectFile();
83 return new PANEL_TEMPLATE_FIELDNAMES( aParent, &project.m_TemplateFieldNames );
84 }, _( "Field Name Templates" ) );
85
86 m_bomPresetsPage = m_treebook->GetPageCount();
87 m_treebook->AddLazySubPage(
88 [this]( wxWindow* aParent ) -> wxWindow*
89 {
90 SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings();
91 return new PANEL_BOM_PRESETS( aParent, settings );
92 }, _( "BOM Presets" ) );
93
94
95 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
96
97 m_severitiesPage = m_treebook->GetPageCount();
98 m_treebook->AddLazySubPage(
99 [this]( wxWindow* aParent ) -> wxWindow*
100 {
101 ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings();
103 ercSettings.m_ERCSeverities, m_pinToPinError.get() );
104 }, _( "Violation Severity" ) );
105
106 m_symbolParityPage = m_treebook->GetPageCount();
107 m_treebook->AddLazySubPage(
108 [this]( wxWindow* aParent ) -> wxWindow*
109 {
110 return new PANEL_SETUP_SYMBOL_PARITY( aParent, m_frame );
111 }, _( "Compare Symbol with Library" ) );
112
113 m_pinMapPage = m_treebook->GetPageCount();
114 m_treebook->AddLazySubPage(
115 [this]( wxWindow* aParent ) -> wxWindow*
116 {
117 return new PANEL_SETUP_PINMAP( aParent, m_frame );
118 }, _( "Pin Conflicts Map" ) );
119
120 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
121
122 m_netclassesPage = m_treebook->GetPageCount();
123 m_treebook->AddLazySubPage(
124 [this]( wxWindow* aParent ) -> wxWindow*
125 {
126 SCHEMATIC& schematic = m_frame->Schematic();
127 return new PANEL_SETUP_NETCLASSES( aParent, m_frame, m_frame->Prj().GetProjectFile().NetSettings(),
128 schematic.GetNetClassAssignmentCandidates(), true );
129 }, _( "Net Classes" ) );
130
131 m_busesPage = m_treebook->GetPageCount();
132 m_treebook->AddLazySubPage(
133 [this]( wxWindow* aParent ) -> wxWindow*
134 {
135 return new PANEL_SETUP_BUSES( aParent, m_frame );
136 }, _( "Bus Alias Definitions" ) );
137
138 m_netChainsPage = m_treebook->GetPageCount();
139 m_treebook->AddLazySubPage(
140 [this]( wxWindow* aParent ) -> wxWindow*
141 {
142 return new PANEL_SETUP_NET_CHAINS( aParent, m_frame );
143 }, _( "Net Chains" ) );
144
145 m_textVarsPage = m_treebook->GetPageCount();
146 m_treebook->AddLazySubPage(
147 [this]( wxWindow* aParent ) -> wxWindow*
148 {
149 return new PANEL_TEXT_VARIABLES( aParent, &Prj() );
150 }, _( "Text Variables" ) );
151
152
153 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Schematic Data" ) );
154
155 m_embeddedFilesPage = m_treebook->GetPageCount();
156 m_treebook->AddLazySubPage(
157 [this]( wxWindow* aParent ) -> wxWindow*
158 {
159 return new PANEL_EMBEDDED_FILES( aParent, &m_frame->Schematic(), NO_MARGINS );
160 }, _( "Embedded Files" ) );
161
162 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
163 m_treebook->ExpandNode( i );
164
165 SetEvtHandlerEnabled( true );
166
168
169 if( Prj().IsReadOnly() )
170 {
171 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be editable." ),
172 wxICON_WARNING );
173 }
174
175 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
176
177 wxQueueEvent( m_treebook, evt.Clone() );
178}
179
180
181void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
182{
184
185 int page = aEvent.GetSelection();
186
187 if( Prj().IsReadOnly() )
188 KIUI::Disable( m_treebook->GetPage( page ) );
189}
190
191
192void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
193{
194 SETTINGS_MANAGER* mgr = m_frame->GetSettingsManager();
195 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
196
197 if( importDlg.ShowModal() == wxID_CANCEL )
198 return;
199
200 wxFileName projectFn( importDlg.GetFilePath() );
201
202 SCRATCH_PROJECT scratch( *mgr, projectFn.GetFullPath(), /*aRequireProjectFile=*/true );
203
204 if( !scratch.IsValid() )
205 {
206 DisplayErrorMessage( this, wxString::Format( _( "Error importing settings from project:\n"
207 "Project file %s could not be loaded." ),
208 projectFn.GetFullPath() ) );
209 return;
210 }
211
212 PROJECT* otherPrj = scratch.GetProject();
213 SCHEMATIC otherSch( otherPrj );
214 PROJECT_FILE& file = otherPrj->GetProjectFile();
215
216 wxASSERT( file.m_SchematicSettings );
217
219
220 if( importDlg.m_FormattingOpt->GetValue() )
221 {
222 static_cast<PANEL_SETUP_FORMATTING*>( m_treebook->ResolvePage( m_formattingPage ) )
224 }
225
226 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
227 {
228 static_cast<PANEL_TEMPLATE_FIELDNAMES*>( m_treebook->ResolvePage( m_fieldNameTemplatesPage ) )
230 }
231
232 if( importDlg.m_SymbolParityOpt->GetValue() )
233 {
234 static_cast<PANEL_SETUP_SYMBOL_PARITY*>( m_treebook->ResolvePage( m_symbolParityPage ) )
236 }
237
238 if( importDlg.m_PinMapOpt->GetValue() )
239 {
240 static_cast<PANEL_SETUP_PINMAP*>( m_treebook->ResolvePage( m_pinMapPage ) )
242 }
243
244 if( importDlg.m_SeveritiesOpt->GetValue() )
245 {
246 static_cast<PANEL_SETUP_SEVERITIES*>( m_treebook->ResolvePage( m_severitiesPage ) )
248 }
249
250 if( importDlg.m_NetClassesOpt->GetValue() )
251 {
252 static_cast<PANEL_SETUP_NETCLASSES*>( m_treebook->ResolvePage( m_netclassesPage ) )
254 }
255
256 if( importDlg.m_BomPresetsOpt->GetValue() )
257 {
258 static_cast<PANEL_BOM_PRESETS*>( m_treebook->ResolvePage( m_bomPresetsPage ) )
260 }
261
262 if( importDlg.m_BomFmtPresetsOpt->GetValue() )
263 {
264 static_cast<PANEL_BOM_PRESETS*>( m_treebook->ResolvePage( m_bomPresetsPage ) )
266 }
267
268 if( importDlg.m_annotationOpt->GetValue() )
269 {
270 static_cast<PANEL_EESCHEMA_ANNOTATION_OPTIONS*>( m_treebook->ResolvePage( m_annotationPage ) )
272 }
273
274 if( importDlg.m_BusAliasesOpt->GetValue() )
275 {
276 static_cast<PANEL_SETUP_BUSES*>( m_treebook->ResolvePage( m_busesPage ) )
278 }
279
280 if( importDlg.m_TextVarsOpt->GetValue() )
281 {
282 static_cast<PANEL_TEXT_VARIABLES*>( m_treebook->ResolvePage( m_textVarsPage ) )
283 ->ImportSettingsFrom( otherPrj );
284 }
285}
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:305
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.
ERC_SETTINGS * m_ErcSettings
Eeschema params.
SCHEMATIC_SETTINGS * m_SchematicSettings
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:148
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