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 <kiway.h>
26#include <symbol_edit_frame.h>
28#include <filename_resolver.h>
29#include <pgm_base.h>
33#include <sch_edit_frame.h>
35#include <sch_painter.h>
36#include <connection_graph.h>
37#include <schematic.h>
39#include <text_var_dependency.h>
50#include <sim/spice_settings.h>
51#include <tool/tool_manager.h>
53
54
57{
58 return ::GetColorSettings( DEFAULT_THEME )->GetColor( aLayer );
59}
60
61
85
86
88{
89 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
90 // If empty, or not existing, the default drawing sheet is loaded.
91
93
94 if( settings.m_SchDrawingSheetFileName == wxS( "empty.kicad_wks" ) )
95 {
97 return;
98 }
99
100 wxString msg;
101
102 if( !DS_DATA_MODEL::GetTheInstance().LoadFromName( settings.m_SchDrawingSheetFileName,
103 Prj().GetProjectPath(), &Prj(),
104 { Schematic().GetEmbeddedFiles() }, &msg ) )
105 {
106 ShowInfoBarError( msg, true );
107 }
108}
109
110
111void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
112{
113 static std::mutex dialogMutex; // Local static mutex
114
115 std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
116
117 // One dialog at a time.
118 if( !dialogLock.owns_lock() )
119 {
121 m_schematicSetupDialog->Raise(); // Brings the existing dialog to the front
122
123 return;
124 }
125
126 std::map<wxString, std::vector<wxString>> oldAliases = Prj().GetProjectFile().m_BusAliases;
127
128 DIALOG_SCHEMATIC_SETUP dlg( this );
129
130 if( !aInitialPage.IsEmpty() )
131 dlg.SetInitialPage( aInitialPage, wxEmptyString );
132
133 // Assign dlg to the m_schematicSetupDialog pointer to track its status.
134 // No, this does not escape the function context.
135 NULLER raii_nuller( (void*&) m_schematicSetupDialog ); m_schematicSetupDialog = &dlg;
136
137 if( dlg.ShowModal() == wxID_OK )
138 {
139 // Mark document as modified so that project settings can be saved as part of doc save
140 OnModify();
141
143
146
147 // CROSS_REF keys deliberately excluded — those are driven by per-item
148 // SCH_COMMIT changes.
149 if( SCHEMATIC_TEXT_VAR_ADAPTER* adapter = Schematic().GetTextVarAdapter() )
150 adapter->Tracker().InvalidateProjectScoped();
151
153
154 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
160
161 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
162 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
163
166
167 std::map<wxString, std::vector<wxString>> newAliases = Prj().GetProjectFile().m_BusAliases;
168
169 if( oldAliases != newAliases )
170 {
172 }
173 else if( CONNECTION_GRAPH* graph = Schematic().ConnectionGraph() )
174 {
175 // No connectivity rebuild ran, so a net-chain netclass override or a deleted/renamed
176 // netclass would otherwise leave the chain-derived assignments stale. Re-derive them
177 // directly; chain membership is unaffected by the setup dialog.
178 graph->ApplyNetChainNetclasses();
179 }
180
182 GetCanvas()->Refresh();
183 }
184}
185
186
188{
189 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
190
192
193 if( !fn.HasName() || !IsWritable( fn, false ) )
194 return;
195
197
198 if( Kiway().Player( FRAME_SIMULATOR, false ) )
200
201 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
202
203 // TODO: We need to remove dependence on BASE_SCREEN
205
207 {
208 FILENAME_RESOLVER resolve;
209 resolve.SetProject( &Prj() );
210 resolve.SetProgramBase( &Pgm() );
211
212 wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
213 Prj().GetProjectPath(),
214 { Schematic().GetEmbeddedFiles() } ) );
215
216 bool success = true;
217
218 if( !layoutfn.IsAbsolute() )
219 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
220
221 if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
222 {
223 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
224 {
225 try
226 {
227 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
228 }
229 catch( const IO_ERROR& ioe )
230 {
231 wxLogError( _( "Failed to save drawing sheet '%s': %s" ),
232 layoutfn.GetFullPath(), ioe.What() );
233 }
234 }
235 }
236 }
237
238 // Propagate the root schematic revision to the project file for IPC-2581 BOM export
239 if( Schematic().RootScreen() )
240 {
243 }
244
245 // Update top-level sheets information in the project file
246 const std::vector<SCH_SHEET*>& topLevelSheets = Schematic().GetTopLevelSheets();
247
248 if( !topLevelSheets.empty() )
249 {
250 std::vector<TOP_LEVEL_SHEET_INFO>& projectSheets = Prj().GetProjectFile().GetTopLevelSheets();
251 projectSheets.clear();
252
253 wxString projectPath = Prj().GetProjectPath();
254
255 for( SCH_SHEET* sheet : topLevelSheets )
256 {
258 info.uuid = sheet->m_Uuid;
259 info.name = sheet->GetName();
260
261 // For top-level sheets, get the filename from the screen, not from the sheet's
262 // SHEET_FILENAME field (which is only used for sheet instances on parent sheets)
263 wxString filename;
264
265 if( sheet->GetScreen() )
266 filename = sheet->GetScreen()->GetFileName();
267
268 // Make the filename relative to the project path
269 wxFileName sheetFn( filename );
270
271 if( sheetFn.IsAbsolute() )
272 sheetFn.MakeRelativeTo( projectPath );
273
274 info.filename = sheetFn.GetFullPath();
275
276 projectSheets.push_back( std::move( info ) );
277 }
278 }
279
280 GetSettingsManager()->SaveProject( fn.GetFullPath() );
281}
282
283
285{
286 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
287
288 if( TOOL_MANAGER* toolMgr = GetToolManager() )
289 {
290 if( SCH_SELECTION_TOOL* selTool = toolMgr->GetTool<SCH_SELECTION_TOOL>() )
291 localSettings.m_SchSelectionFilter = selTool->GetFilter();
292 }
293
294 localSettings.m_SchHierarchyCollapsed = m_hierarchy->GetCollapsedPaths();
295}
296
297
326
327
329{
332 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
333
334 if( cfg )
335 {
336 cfg->m_System.units = static_cast<int>( GetUserUnits() );
337 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
338 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
339
340 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
341 // and hierarchy_panel_docked_width should have been updated when resizing the
342 // hierarchy panel
343
344 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
345
346 if( searchData )
347 {
354 }
355
356 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
357 m_show_search = searchPaneInfo.IsShown();
359 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
360 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
361 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
362
363 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
364 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
365 cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
367
368 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
369 cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
370 cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
371
372 if( netNavigatorPane.IsDocked() )
373 {
375 }
376 else
377 {
378 cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
379 cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
380 }
381
382 wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
383 cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
384
385 if( designBlocksPane.IsDocked() )
386 {
388 }
389 else
390 {
391 cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
392 cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
393 }
394
395 m_designBlocksPane->SaveSettings();
396
397 wxAuiPaneInfo& remoteSymbolPane = m_auimgr.GetPane( RemoteSymbolPaneName() );
398 cfg->m_AuiPanels.remote_symbol_show = remoteSymbolPane.IsShown();
399
400 if( remoteSymbolPane.IsDocked() )
401 {
403 }
404 else
405 {
406 cfg->m_AuiPanels.remote_symbol_panel_float_height = remoteSymbolPane.floating_size.y;
407 cfg->m_AuiPanels.remote_symbol_panel_float_width = remoteSymbolPane.floating_size.x;
408 }
409 }
410}
411
412
414{
415 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
416
418
419 // Move legacy user grids to grid list
420 if( !aCfg->m_Window.grid.user_grid_x.empty() )
421 {
422 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid",
424 aCfg->m_Window.grid.user_grid_y } );
425 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
426 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
427 }
428
429 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
430 aCfg->m_Window.grid.last_size_idx = 1;
431
432 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
433 aCfg->m_Window.grid.fast_grid_1 = 1;
434
435 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
436 aCfg->m_Window.grid.fast_grid_2 = 2;
437}
438
439
441{
442 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
443
445}
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.
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:1703
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:679
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:580
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:183
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 #VIEW instance used in the panel.
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
void RefreshOperatingPointDisplay()
Refresh the display of any operating points.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
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.
DIALOG_SCHEMATIC_SETUP * m_schematicSetupDialog
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()
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.
wxGenericTreeCtrl * m_netNavigator
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:153
TITLE_BLOCK & GetTitleBlock()
Definition sch_screen.h:164
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:
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:727
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:471
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ GLOBAL_CLEANUP
Definition schematic.h:94
#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.