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 along
17 * with this program. If not, see <http://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>
34#include <sch_painter.h>
35#include <schematic.h>
45#include <sim/spice_settings.h>
46#include <tool/tool_manager.h>
48
49
52{
53 return ::GetColorSettings( DEFAULT_THEME )->GetColor( aLayer );
54}
55
56
81
82
84{
85 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
86 // If empty, or not existing, the default drawing sheet is loaded.
87
90 resolver.SetProject( &Prj() );
91 resolver.SetProgramBase( &Pgm() );
92
93 wxString filename = resolver.ResolvePath( settings.m_SchDrawingSheetFileName,
94 Prj().GetProjectPath(),
96 wxString msg;
97
98 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
99 ShowInfoBarError( msg, true );
100}
101
102
103void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
104{
105 static std::mutex dialogMutex; // Local static mutex
106
107 std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
108
109 // One dialog at a time.
110 if( !dialogLock.owns_lock() )
111 {
113 m_schematicSetupDialog->Raise(); // Brings the existing dialog to the front
114
115 return;
116 }
117
118 std::map<wxString, std::vector<wxString>> oldAliases = Prj().GetProjectFile().m_BusAliases;
119
120 DIALOG_SCHEMATIC_SETUP dlg( this );
121
122 if( !aInitialPage.IsEmpty() )
123 dlg.SetInitialPage( aInitialPage, wxEmptyString );
124
125 // Assign dlg to the m_schematicSetupDialog pointer to track its status.
126 // No, this does not escape the function context.
127 NULLER raii_nuller( (void*&) m_schematicSetupDialog ); m_schematicSetupDialog = &dlg;
128
129 // TODO: is QuasiModal required here?
130 if( dlg.ShowQuasiModal() == wxID_OK )
131 {
132 // Mark document as modified so that project settings can be saved as part of doc save
133 OnModify();
134
136
140
141 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
146
147 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
148 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
149
152
153 std::map<wxString, std::vector<wxString>> newAliases = Prj().GetProjectFile().m_BusAliases;
154
155 if( oldAliases != newAliases )
157
159 GetCanvas()->Refresh();
160 }
161}
162
163
165{
166 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
167
168 PROJECT_FILE& projectFile = Prj().GetProjectFile();
169 double multiplier = sizeMultipliers[projectFile.m_SchematicSettings->m_JunctionSizeChoice];
170 int dotSize = KiROUND( projectFile.NetSettings()->GetDefaultNetclass()->GetWireWidth() * multiplier );
171
172 return std::max( dotSize, 1 );
173}
174
175
177{
178 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
179
180 return sizeMultipliers[Prj().GetProjectFile().m_SchematicSettings->m_HopOverSizeChoice];
181}
182
183
185{
186 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
187
189
190 if( !fn.HasName() || !IsWritable( fn, false ) )
191 return;
192
194
195 if( Kiway().Player( FRAME_SIMULATOR, false ) )
197
198 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
199
200 // TODO: We need to remove dependence on BASE_SCREEN
202
204 {
205 FILENAME_RESOLVER resolve;
206 resolve.SetProject( &Prj() );
207 resolve.SetProgramBase( &Pgm() );
208
209 wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
210 Prj().GetProjectPath(),
211 { Schematic().GetEmbeddedFiles() } ) );
212
213 bool success = true;
214
215 if( !layoutfn.IsAbsolute() )
216 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
217
218 if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
219 {
220 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
221 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
222 }
223 }
224
225 // Update top-level sheets information in the project file
226 const std::vector<SCH_SHEET*>& topLevelSheets = Schematic().GetTopLevelSheets();
227
228 if( !topLevelSheets.empty() )
229 {
230 std::vector<TOP_LEVEL_SHEET_INFO>& projectSheets = Prj().GetProjectFile().GetTopLevelSheets();
231 projectSheets.clear();
232
233 wxString projectPath = Prj().GetProjectPath();
234
235 for( SCH_SHEET* sheet : topLevelSheets )
236 {
238 info.uuid = sheet->m_Uuid;
239 info.name = sheet->GetName();
240
241 // For top-level sheets, get the filename from the screen, not from the sheet's
242 // SHEET_FILENAME field (which is only used for sheet instances on parent sheets)
243 wxString filename;
244
245 if( sheet->GetScreen() )
246 filename = sheet->GetScreen()->GetFileName();
247
248 // Make the filename relative to the project path
249 wxFileName sheetFn( filename );
250
251 if( sheetFn.IsAbsolute() )
252 sheetFn.MakeRelativeTo( projectPath );
253
254 info.filename = sheetFn.GetFullPath();
255
256 projectSheets.push_back( std::move( info ) );
257 }
258 }
259
260 GetSettingsManager()->SaveProject( fn.GetFullPath() );
261}
262
263
265{
266 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
268
269 localSettings.m_SchSelectionFilter = selTool->GetFilter();
270 localSettings.m_SchHierarchyCollapsed = m_hierarchy->GetCollapsedPaths();
271}
272
273
275{
276 // For now, axes are forced off in Eeschema even if turned on in config
278 cfg->m_Window.grid.axes_enabled = false;
279
281
282 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
283
284 if( searchData )
285 {
292 }
293
295
300}
301
302
304{
307 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
308
309 if( cfg )
310 {
311 cfg->m_System.units = static_cast<int>( GetUserUnits() );
312 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
313 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
314
315 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
316 // and hierarchy_panel_docked_width should have been updated when resizing the
317 // hierarchy panel
318
319 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
320
321 if( searchData )
322 {
329 }
330
331 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
332 m_show_search = searchPaneInfo.IsShown();
334 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
335 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
336 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
337
338 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
339 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
340 cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
342
343 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
344 cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
345 cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
346
347 if( netNavigatorPane.IsDocked() )
348 {
350 }
351 else
352 {
353 cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
354 cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
355 }
356
357 wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
358 cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
359
360 if( designBlocksPane.IsDocked() )
361 {
363 }
364 else
365 {
366 cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
367 cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
368 }
369
370 m_designBlocksPane->SaveSettings();
371 }
372}
373
374
376{
377 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
378
380
381 // Move legacy user grids to grid list
382 if( !aCfg->m_Window.grid.user_grid_x.empty() )
383 {
384 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid",
386 aCfg->m_Window.grid.user_grid_y } );
387 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
388 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
389 }
390
391 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
392 aCfg->m_Window.grid.last_size_idx = 1;
393
394 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
395 aCfg->m_Window.grid.fast_grid_1 = 1;
396
397 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
398 aCfg->m_Window.grid.fast_grid_2 = 2;
399}
400
401
403{
404 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
405
407}
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
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:85
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
wxAuiManager m_auimgr
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Check if aFileName can be written.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_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...
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()
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.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
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:1561
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:659
virtual void CommonSettingsChanged(int aFlags=0)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition kiway.cpp:600
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS.
int GetWireWidth() const
Definition netclass.h:204
std::shared_ptr< NETCLASS > GetDefaultNetclass()
Gets the default netclass for the project.
Definition raii.h:38
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:128
The backing store for a PROJECT, in JSON format.
SCHEMATIC_SETTINGS * m_SchematicSettings
std::shared_ptr< NET_SETTINGS > & NetSettings()
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:165
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:211
void IncrementNetclassesTicker()
Definition project.h:123
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:205
void IncrementTextVarsTicker()
Definition project.h:120
These are loaded from Eeschema settings but then overwritten by the project settings.
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
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.
wxTreeCtrl * m_netNavigator
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
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
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.
double GetSchematicHopOverScale()
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:152
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
This file is part of the common library.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
static FILENAME_RESOLVER * resolver
@ FRAME_SIMULATOR
Definition frame_type.h:38
static const std::string ProjectFileExtension
PROJECT & Prj()
Definition kicad.cpp:623
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
int GetUserUnits()
Return the currently selected user unit value for the interface.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE
@ GLOBAL_CLEANUP
Definition schematic.h:77
#define DEFAULT_THEME
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< double > junction_size_mult_list
wxString user_grid_x
std::vector< GRID > grids
wxString user_grid_y
Common grid settings, available to every frame.
Information about a top-level schematic sheet.
GRID_SETTINGS grid
#define TEXTVARS_CHANGED
Definition of file extensions used in Kicad.