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 <symbol_library.h>
24#include <confirm.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>
35#include <sch_painter.h>
36#include <schematic.h>
46#include <sim/spice_settings.h>
47#include <tool/tool_manager.h>
49
50
53{
54 return ::GetColorSettings( DEFAULT_THEME )->GetColor( aLayer );
55}
56
57
59{
63
71
73
74 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
75
77 selTool->GetFilter() = localSettings.m_SchSelectionFilter;
79
80 return true;
81}
82
83
85{
86 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
87 // If empty, or not existing, the default drawing sheet is loaded.
88
93
94 wxString filename = resolver.ResolvePath( settings.m_SchDrawingSheetFileName,
95 Prj().GetProjectPath(),
97 wxString msg;
98
99 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
100 ShowInfoBarError( msg, true );
101}
102
103
104void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
105{
106 static std::mutex dialogMutex; // Local static mutex
107
108 std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
109
110 // One dialog at a time.
111 if( !dialogLock.owns_lock() )
112 {
114 m_schematicSetupDialog->Raise(); // Brings the existing dialog to the front
115
116 return;
117 }
118
119 SCH_SCREENS screens( Schematic().Root() );
120 std::vector<std::shared_ptr<BUS_ALIAS>> oldAliases;
121
122 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
123 {
124 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
125 oldAliases.push_back( alias );
126 }
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 // TODO: is QuasiModal required here?
138 if( dlg.ShowQuasiModal() == wxID_OK )
139 {
140 // Mark document as modified so that project settings can be saved as part of doc save
141 OnModify();
142
144
148
149 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
154
155 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
156 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
157
160
161 std::vector<std::shared_ptr<BUS_ALIAS>> newAliases;
162
163 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
164 {
165 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
166 newAliases.push_back( alias );
167 }
168
169 if( oldAliases != newAliases )
171
173 GetCanvas()->Refresh();
174 }
175}
176
177
179{
180 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
181
182 PROJECT_FILE& projectFile = Prj().GetProjectFile();
183 double multiplier = sizeMultipliers[projectFile.m_SchematicSettings->m_JunctionSizeChoice];
184 int dotSize = KiROUND( projectFile.NetSettings()->GetDefaultNetclass()->GetWireWidth() * multiplier );
185
186 return std::max( dotSize, 1 );
187}
188
189
191{
192 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
193
194 return sizeMultipliers[Prj().GetProjectFile().m_SchematicSettings->m_HopOverSizeChoice];
195}
196
197
199{
200 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
201
203
204 if( !fn.HasName() || !IsWritable( fn, false ) )
205 return;
206
208
209 if( Kiway().Player( FRAME_SIMULATOR, false ) )
211
212 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
213
214 // TODO: We need to remove dependence on BASE_SCREEN
216
218 {
219 FILENAME_RESOLVER resolve;
220 resolve.SetProject( &Prj() );
221 resolve.SetProgramBase( &Pgm() );
222
223 wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
224 Prj().GetProjectPath(),
225 { Schematic().GetEmbeddedFiles() } ) );
226
227 bool success = true;
228
229 if( !layoutfn.IsAbsolute() )
230 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
231
232 if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
233 {
234 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
235 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
236 }
237 }
238
239 GetSettingsManager()->SaveProject( fn.GetFullPath() );
240}
241
242
244{
245 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
247
248 localSettings.m_SchSelectionFilter = selTool->GetFilter();
250}
251
252
254{
255 // For now, axes are forced off in Eeschema even if turned on in config
257 cfg->m_Window.grid.axes_enabled = false;
258
260
261 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
262
263 if( searchData )
264 {
271 }
272
274
279}
280
281
283{
286 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
287
288 if( cfg )
289 {
290 cfg->m_System.units = static_cast<int>( GetUserUnits() );
291 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
292 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
293
294 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
295 // and hierarchy_panel_docked_width should have been updated when resizing the
296 // hierarchy panel
297
298 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
299
300 if( searchData )
301 {
308 }
309
310 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
311 m_show_search = searchPaneInfo.IsShown();
313 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
314 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
315 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
316
317 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
318 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
321
322 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
323 cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
324 cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
325
326 if( netNavigatorPane.IsDocked() )
327 {
329 }
330 else
331 {
332 cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
333 cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
334 }
335
336 wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
337 cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
338
339 if( designBlocksPane.IsDocked() )
340 {
342 }
343 else
344 {
345 cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
346 cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
347 }
348
350 }
351}
352
353
355{
356 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
357
359
360 // Move legacy user grids to grid list
361 if( !aCfg->m_Window.grid.user_grid_x.empty() )
362 {
363 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid",
365 aCfg->m_Window.grid.user_grid_y } );
366 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
367 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
368 }
369
370 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
371 aCfg->m_Window.grid.last_size_idx = 1;
372
373 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
374 aCfg->m_Window.grid.fast_grid_1 = 1;
375
376 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
377 aCfg->m_Window.grid.fast_grid_2 = 2;
378}
379
380
382{
383 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
384
386}
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.
Definition: app_settings.h:108
WINDOW_SETTINGS m_Window
Definition: app_settings.h:233
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
int ShowQuasiModal()
bool LoadDrawingSheet(const wxString &aFullFileName, wxString *aMsg, bool aAppend=false)
Populate the list with a custom layout or the default layout if no custom layout is available.
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.
std::vector< wxString > GetCollapsedPaths() const
Returns a list of sheet paths for nodes that are currently collapsed.
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:589
Definition: raii.h:38
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
void SetCheckboxesFromFilter(SCH_SELECTION_FILTER_OPTIONS &aOptions)
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:68
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:151
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:99
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 PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:210
void IncrementNetclassesTicker()
Definition: project.h:122
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:204
void IncrementTextVarsTicker()
Definition: project.h:119
float SplitterProportion() const
These are loaded from Eeschema settings but then overwritten by the project settings.
wxString m_SchDrawingSheetFileName
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:356
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:884
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:927
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:252
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()
int GetSchematicJunctionSize()
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.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:758
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
const wxString & GetFileName() const
Definition: sch_screen.h:152
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
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
Definition: export_idf.cpp:53
@ FRAME_SIMULATOR
Definition: frame_type.h:38
static const std::string ProjectFileExtension
PROJECT & Prj()
Definition: kicad.cpp:608
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:439
@ 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:902
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
Definition: grid_settings.h:67
std::vector< GRID > grids
Definition: grid_settings.h:66
wxString user_grid_y
Definition: grid_settings.h:68
Common grid settings, available to every frame.
Definition: grid_settings.h:34
GRID_SETTINGS grid
Definition: app_settings.h:97
Definition for symbol library class.
#define TEXTVARS_CHANGED
Definition: tools_holder.h:153
Definition of file extensions used in Kicad.