KiCad PCB EDA Suite
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-2022 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_item.h>
37#include <wx/treebook.h>
38
39
41 PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true,
42 _( "Import Settings from Another Project..." ) ),
43 m_frame( aFrame ),
44 m_severities( nullptr )
45{
47 SCHEMATIC& schematic = aFrame->Schematic();
48 SCHEMATIC_SETTINGS& settings = schematic.Settings();
49
51
53 &settings.m_TemplateFieldNames );
54
55 m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
56
59 schematic.ErcSettings().m_ERCSeverities,
60 m_pinToPinError.get() );
61
63
64 m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(),
65 schematic.GetNetClassAssignmentCandidates(), true );
66
67 m_buses = new PANEL_SETUP_BUSES( m_treebook, aFrame );
68
69 /*
70 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
71 */
72
73 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
74 m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
75 m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
76
77 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
78 m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
79 m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
80
81 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
82 m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
83 m_treebook->AddSubPage( m_buses, _( "Bus Alias Definitions" ) );
84 m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
85
86 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
87 m_treebook->ExpandNode( i );
88
90
91 if( Prj().IsReadOnly() )
92 {
93 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
94 "editable." ), wxICON_WARNING );
95 }
96
97 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
98
99 wxQueueEvent( m_treebook, evt.Clone() );
100}
101
102
104{
105}
106
107
108void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
109{
111
112 int page = aEvent.GetSelection();
113
114 if( Prj().IsReadOnly() )
115 KIUI::Disable( m_treebook->GetPage( page ) );
116}
117
118
119void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
120{
121 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
122
123 if( importDlg.ShowModal() == wxID_CANCEL )
124 return;
125
126 wxFileName projectFn( importDlg.GetFilePath() );
127
128 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
129 {
130 wxString msg = wxString::Format( _( "Error importing settings from project:\n"
131 "Project file %s could not be loaded." ),
132 projectFn.GetFullPath() );
133 DisplayErrorMessage( this, msg );
134
135 return;
136 }
137
138 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
139 SCHEMATIC otherSch( otherPrj );
140 PROJECT_FILE& file = otherPrj->GetProjectFile();
141
142 wxASSERT( file.m_SchematicSettings );
143
145
146 if( importDlg.m_FormattingOpt->GetValue() )
148
149 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
151
152 if( importDlg.m_PinMapOpt->GetValue() )
154
155 if( importDlg.m_SeveritiesOpt->GetValue() )
157
158 if( importDlg.m_NetClassesOpt->GetValue() )
160
161 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
162}
PANEL_SETUP_SEVERITIES * m_severities
PANEL_SETUP_NETCLASSES * m_netclasses
PANEL_TEXT_VARIABLES * m_textVars
void onPageChanged(wxBookCtrlEvent &aEvent) override
PANEL_TEMPLATE_FIELDNAMES * m_fieldNameTemplates
PANEL_SETUP_PINMAP * m_pinMap
PANEL_SETUP_FORMATTING * m_formatting
DIALOG_SCHEMATIC_SETUP(SCH_EDIT_FRAME *aFrame)
std::shared_ptr< ERC_ITEM > m_pinToPinError
void onAuxiliaryAction(wxCommandEvent &aEvent) override
PANEL_SETUP_BUSES * m_buses
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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:202
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:50
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:168
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:171
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_INFOBAR * m_infoBar
Definition: paged_dialog.h:67
wxTreebook * m_treebook
Definition: paged_dialog.h:63
virtual void onPageChanged(wxBookCtrlEvent &aEvent)
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
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)
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:127
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
std::shared_ptr< NET_SETTINGS > m_NetSettings
Net settings for this project (owned here)
Definition: project_file.h:168
Container for project specific data.
Definition: project.h:63
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
These settings were stored in SCH_BASE_FRAME previously.
TEMPLATES m_TemplateFieldNames
Holds all the data relating to one schematic.
Definition: schematic.h:60
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:240
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:179
Schematic editor (Eeschema) main window.
SCHEMATIC & Schematic() const
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: infobar.cpp:142
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:299
This file is part of the common library.
#define _(s)
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:80
void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:309
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200