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
50 SetEvtHandlerEnabled( false );
51
53
55 &settings.m_TemplateFieldNames );
56
57 m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame );
58
61 schematic.ErcSettings().m_ERCSeverities,
62 m_pinToPinError.get() );
63
65
66 m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(),
67 schematic.GetNetClassAssignmentCandidates(), true );
68
69 m_buses = new PANEL_SETUP_BUSES( m_treebook, aFrame );
70
71 /*
72 * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog().
73 */
74
75 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) );
76 m_treebook->AddSubPage( m_formatting, _( "Formatting" ) );
77 m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) );
78
79 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) );
80 m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) );
81 m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) );
82
83 m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) );
84 m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) );
85 m_treebook->AddSubPage( m_buses, _( "Bus Alias Definitions" ) );
86 m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) );
87
88 for( size_t i = 0; i < m_treebook->GetPageCount(); ++i )
89 m_treebook->ExpandNode( i );
90
91 SetEvtHandlerEnabled( true );
92
94
95 if( Prj().IsReadOnly() )
96 {
97 m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
98 "editable." ), wxICON_WARNING );
99 }
100
101 wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
102
103 wxQueueEvent( m_treebook, evt.Clone() );
104}
105
106
108{
109}
110
111
112void DIALOG_SCHEMATIC_SETUP::onPageChanged( wxBookCtrlEvent& aEvent )
113{
115
116 int page = aEvent.GetSelection();
117
118 if( Prj().IsReadOnly() )
119 KIUI::Disable( m_treebook->GetPage( page ) );
120}
121
122
123void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event )
124{
125 DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
126
127 if( importDlg.ShowModal() == wxID_CANCEL )
128 return;
129
130 wxFileName projectFn( importDlg.GetFilePath() );
131
132 if( !m_frame->GetSettingsManager()->LoadProject( projectFn.GetFullPath(), false ) )
133 {
134 wxString msg = wxString::Format( _( "Error importing settings from project:\n"
135 "Project file %s could not be loaded." ),
136 projectFn.GetFullPath() );
137 DisplayErrorMessage( this, msg );
138
139 return;
140 }
141
142 PROJECT* otherPrj = m_frame->GetSettingsManager()->GetProject( projectFn.GetFullPath() );
143 SCHEMATIC otherSch( otherPrj );
144 PROJECT_FILE& file = otherPrj->GetProjectFile();
145
146 wxASSERT( file.m_SchematicSettings );
147
149
150 if( importDlg.m_FormattingOpt->GetValue() )
152
153 if( importDlg.m_FieldNameTemplatesOpt->GetValue() )
155
156 if( importDlg.m_PinMapOpt->GetValue() )
158
159 if( importDlg.m_SeveritiesOpt->GetValue() )
161
162 if( importDlg.m_NetClassesOpt->GetValue() )
164
165 m_frame->GetSettingsManager()->UnloadProject( otherPrj, false );
166}
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:232
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
Definition: erc_item.h:76
std::map< int, SEVERITY > m_ERCSeverities
Definition: erc_settings.h:173
PIN_ERROR m_PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Definition: erc_settings.h:176
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:64
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
These settings were stored in SCH_BASE_FRAME previously.
TEMPLATES m_TemplateFieldNames
Holds all the data relating to one schematic.
Definition: schematic.h:61
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:178
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:279
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:185
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: wx_infobar.cpp:142
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
This file is part of the common library.
#define _(s)
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:85
void Disable(wxWindow *aWindow)
Makes a window read-only.
Definition: ui_common.cpp:321
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