KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema_config.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 <mutex>
21#include <wx/ffile.h>
22
23#include <confirm.h>
25#include <dialogs/dialog_erc.h>
26#include <kiway.h>
27#include <symbol_edit_frame.h>
29#include <filename_resolver.h>
30#include <pgm_base.h>
34#include <sch_edit_frame.h>
36#include <sch_painter.h>
37#include <connection_graph.h>
38#include <schematic.h>
40#include <text_var_dependency.h>
51#include <sim/spice_settings.h>
52#include <tool/tool_manager.h>
54
55
58{
59 return ::GetColorSettings( DEFAULT_THEME )->GetColor( aLayer );
60}
61
62
86
87
89{
90 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
91 // If empty, or not existing, the default drawing sheet is loaded.
92
94
95 if( settings.m_SchDrawingSheetFileName == wxS( "empty.kicad_wks" ) )
96 {
98 return;
99 }
100
101 wxString msg;
102
103 if( !DS_DATA_MODEL::GetTheInstance().LoadFromName( settings.m_SchDrawingSheetFileName,
104 Prj().GetProjectPath(), &Prj(),
105 { Schematic().GetEmbeddedFiles() }, &msg ) )
106 {
107 ShowInfoBarError( msg, true );
108 }
109}
110
111
112void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
113{
114 static std::mutex dialogMutex; // Local static mutex
115
116 std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
117
118 // One dialog at a time.
119 if( !dialogLock.owns_lock() )
120 {
122 m_schematicSetupDialog->Raise(); // Brings the existing dialog to the front
123
124 return;
125 }
126
127 std::map<wxString, std::vector<wxString>> oldAliases = Prj().GetProjectFile().m_BusAliases;
128
129 DIALOG_SCHEMATIC_SETUP dlg( this );
130
131 if( !aInitialPage.IsEmpty() )
132 dlg.SetInitialPage( aInitialPage, wxEmptyString );
133
134 // Assign dlg to the m_schematicSetupDialog pointer to track its status.
135 // No, this does not escape the function context.
136 NULLER raii_nuller( (void*&) m_schematicSetupDialog ); m_schematicSetupDialog = &dlg;
137
138 if( dlg.ShowModal() == wxID_OK )
139 {
140 // Mark document as modified so that project settings can be saved as part of doc save
141 OnModify();
142
144
147
148 // CROSS_REF keys deliberately excluded — those are driven by per-item
149 // SCH_COMMIT changes.
150 if( SCHEMATIC_TEXT_VAR_ADAPTER* adapter = Schematic().GetTextVarAdapter() )
151 adapter->Tracker().InvalidateProjectScoped();
152
154
155 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
161
162 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
163 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
164
167
168 std::map<wxString, std::vector<wxString>> newAliases = Prj().GetProjectFile().m_BusAliases;
169
170 if( oldAliases != newAliases )
171 {
173 }
174 else if( CONNECTION_GRAPH* graph = Schematic().ConnectionGraph() )
175 {
176 // No connectivity rebuild ran, so a net-chain netclass override or a deleted/renamed
177 // netclass would otherwise leave the chain-derived assignments stale. Re-derive them
178 // directly; chain membership is unaffected by the setup dialog.
179 graph->ApplyNetChainNetclasses();
180 }
181
183 GetCanvas()->Refresh();
184
185 if( DIALOG_ERC* ercDialog = GetErcDialog() )
186 ercDialog->UpdateData();
187 }
188}
189
190
192{
193 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
194
196
197 if( !fn.HasName() || !IsWritable( fn, false ) )
198 return;
199
201
202 if( Kiway().Player( FRAME_SIMULATOR, false ) )
204
205 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
206
207 // TODO: We need to remove dependence on BASE_SCREEN
209
211 {
212 FILENAME_RESOLVER resolve;
213 resolve.SetProject( &Prj() );
214 resolve.SetProgramBase( &Pgm() );
215
216 wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
217 Prj().GetProjectPath(),
218 { Schematic().GetEmbeddedFiles() } ) );
219
220 bool success = true;
221
222 if( !layoutfn.IsAbsolute() )
223 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
224
225 if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
226 {
227 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
228 {
229 try
230 {
231 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
232 }
233 catch( const IO_ERROR& ioe )
234 {
235 wxLogError( _( "Failed to save drawing sheet '%s': %s" ),
236 layoutfn.GetFullPath(), ioe.What() );
237 }
238 }
239 }
240 }
241
242 // Propagate the root schematic revision to the project file for IPC-2581 BOM export
243 if( Schematic().RootScreen() )
244 {
247 }
248
249 // Update top-level sheets information in the project file
250 const std::vector<SCH_SHEET*>& topLevelSheets = Schematic().GetTopLevelSheets();
251
252 if( !topLevelSheets.empty() )
253 {
254 std::vector<TOP_LEVEL_SHEET_INFO>& projectSheets = Prj().GetProjectFile().GetTopLevelSheets();
255 projectSheets.clear();
256
257 wxString projectPath = Prj().GetProjectPath();
258
259 for( SCH_SHEET* sheet : topLevelSheets )
260 {
262 info.uuid = sheet->m_Uuid;
263 info.name = sheet->GetName();
264
265 // For top-level sheets, get the filename from the screen, not from the sheet's
266 // SHEET_FILENAME field (which is only used for sheet instances on parent sheets)
267 wxString filename;
268
269 if( sheet->GetScreen() )
270 filename = sheet->GetScreen()->GetFileName();
271
272 // Make the filename relative to the project path
273 wxFileName sheetFn( filename );
274
275 if( sheetFn.IsAbsolute() )
276 sheetFn.MakeRelativeTo( projectPath );
277
278 info.filename = sheetFn.GetFullPath();
279
280 projectSheets.push_back( std::move( info ) );
281 }
282 }
283
284 GetSettingsManager()->SaveProject( fn.GetFullPath() );
285}
286
287
289{
290 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
291
292 if( TOOL_MANAGER* toolMgr = GetToolManager() )
293 {
294 if( SCH_SELECTION_TOOL* selTool = toolMgr->GetTool<SCH_SELECTION_TOOL>() )
295 localSettings.m_SchSelectionFilter = selTool->GetFilter();
296 }
297
298 localSettings.m_SchHierarchyCollapsed = m_hierarchy->GetCollapsedPaths();
299}
300
301
330
331
333{
336 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
337
338 if( cfg )
339 {
340 cfg->m_System.units = static_cast<int>( GetUserUnits() );
341 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
342 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
343
344 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
345 // and hierarchy_panel_docked_width should have been updated when resizing the
346 // hierarchy panel
347
348 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
349
350 if( searchData )
351 {
358 }
359
360 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
361 m_show_search = searchPaneInfo.IsShown();
363 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
364 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
365 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
366
367 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
368 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
369 cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
371
372 cfg->m_AuiPanels.show_git_commit_pane = m_auimgr.GetPane( GitCommitPaneName() ).IsShown();
373
374 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
375 cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
376 cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
377
378 if( netNavigatorPane.IsDocked() )
379 {
381 }
382 else
383 {
384 cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
385 cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
386 }
387
388 wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
389 cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
390
391 if( designBlocksPane.IsDocked() )
392 {
394 }
395 else
396 {
397 cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
398 cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
399 }
400
401 m_designBlocksPane->SaveSettings();
402
403 wxAuiPaneInfo& remoteSymbolPane = m_auimgr.GetPane( RemoteSymbolPaneName() );
404 cfg->m_AuiPanels.remote_symbol_show = remoteSymbolPane.IsShown();
405
406 if( remoteSymbolPane.IsDocked() )
407 {
409 }
410 else
411 {
412 cfg->m_AuiPanels.remote_symbol_panel_float_height = remoteSymbolPane.floating_size.y;
413 cfg->m_AuiPanels.remote_symbol_panel_float_width = remoteSymbolPane.floating_size.x;
414 }
415 }
416}
417
418
420{
421 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
422
424
425 // Move legacy user grids to grid list
426 if( !aCfg->m_Window.grid.user_grid_x.empty() )
427 {
428 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid",
430 aCfg->m_Window.grid.user_grid_y } );
431 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
432 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
433 }
434
435 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
436 aCfg->m_Window.grid.last_size_idx = 1;
437
438 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
439 aCfg->m_Window.grid.fast_grid_1 = 1;
440
441 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
442 aCfg->m_Window.grid.fast_grid_2 = 2;
443}
444
445
447{
448 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
449
451}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
WINDOW_SETTINGS m_Window
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition base_screen.h:81
Calculate the connectivity of a schematic and generate netlists.
int ShowModal() override
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void Save(const wxString &aFullFileName)
Save the description in a file.
static const wxString GitCommitPaneName()
Named here rather than beside the editors' other panes, because the project manager docks this one to...
SETTINGS_MANAGER * GetSettingsManager() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
wxAuiManager m_auimgr
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Check if aFileName can be written.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
static const wxString PropertiesPaneName()
static const wxString RemoteSymbolPaneName()
SEARCH_PANE * m_searchPane
static const wxString DesignBlocksPaneName()
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
PROPERTIES_PANEL * m_propertiesPanel
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
FIND_REPLACE_EXTRA m_FindReplaceExtra
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
bool SetProject(const PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
void SetDefaultPenWidth(int aWidth)
void SetDefaultFont(const wxString &aFont)
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition view.cpp:2475
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:779
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:593
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS.
Definition raii.h:34
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
SCHEMATIC_SETTINGS * m_SchematicSettings
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
std::map< wxString, std::vector< wxString > > m_BusAliases
Bus alias definitions for the schematic project.
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
The project local settings are things that are attached to a particular project, but also might be pa...
SCH_SELECTION_FILTER_OPTIONS m_SchSelectionFilter
std::vector< wxString > m_SchHierarchyCollapsed
Collapsed nodes in the schematic hierarchy navigator.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:276
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:207
void IncrementNetclassesTicker()
Definition project.h:115
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:201
void IncrementTextVarsTicker()
Definition project.h:112
These are loaded from Eeschema settings but then overwritten by the project settings.
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
Bridges SCHEMATIC's listener stream into the generic TEXT_VAR_TRACKER.
SCHEMATIC_SETTINGS & Settings() const
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
SCH_RENDER_SETTINGS * GetRenderSettings()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
PANEL_SCH_SELECTION_FILTER * m_selectionFilterPanel
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
void RefreshOperatingPointDisplay()
Refresh the display of any operating points.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void SaveProjectLocalSettings() override
Save changes to the project settings to the project (.pro) file.
NET_NAVIGATOR_TREE * m_netNavigator
DIALOG_SCHEMATIC_SETUP * m_schematicSetupDialog
bool RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
PANEL_REMOTE_SYMBOL * m_remoteSymbolPane
SCHEMATIC & Schematic() const
bool LoadProjectSettings()
Load the KiCad project file (*.pro) settings specific to Eeschema.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
static const wxString SearchPaneName()
DIALOG_ERC * GetErcDialog()
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
void LoadDrawingSheet()
Load the drawing sheet file.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
static const wxString SchematicHierarchyPaneName()
static const wxString NetNavigatorPaneName()
void saveProjectSettings() override
Save any design-related project settings associated with this frame.
HIERARCHY_PANE * m_hierarchy
int m_SymbolLineWidth
Override line widths for symbol drawing objects set to default line width.
const wxString & GetFileName() const
Definition sch_screen.h:157
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:168
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
const wxString & GetRevision() const
Definition title_block.h:83
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
EDA_UNITS GetUserUnits() const
This file is part of the common library.
#define _(s)
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
@ FRAME_SIMULATOR
Definition frame_type.h:34
static const std::string ProjectFileExtension
PROJECT & Prj()
Definition kicad.cpp:737
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:477
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
@ LAYERS
Layers have changed.
Definition view_item.h:52
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ GLOBAL_CLEANUP
Definition schematic.h:95
#define DEFAULT_THEME
KIWAY Kiway(KFCTL_STANDALONE)
wxString user_grid_x
std::vector< GRID > grids
wxString user_grid_y
Common grid settings, available to every frame.
wxString schRevision
Auto-propagated schematic title block revision.
Information about a top-level schematic sheet.
GRID_SETTINGS grid
#define TEXTVARS_CHANGED
Definition of file extensions used in Kicad.