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