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 (C) 2014-2023 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>
45#include <zoom_defines.h>
46#include <sim/spice_settings.h>
47#include <tool/tool_manager.h>
49
50
53{
54 return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
55}
56
57
59{
62
67
70
72
73 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
74
76 selTool->GetFilter() = localSettings.m_SchSelectionFilter;
78
79 return true;
80}
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
92
93 wxString filename = resolver.ResolvePath( settings.m_SchDrawingSheetFileName,
94 Prj().GetProjectPath(),
95 Schematic().GetEmbeddedFiles() );
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 SCH_SCREENS screens( Schematic().Root() );
106 std::vector<std::shared_ptr<BUS_ALIAS>> oldAliases;
107
108 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
109 {
110 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
111 oldAliases.push_back( alias );
112 }
113
114 DIALOG_SCHEMATIC_SETUP dlg( this );
115
116 if( !aInitialPage.IsEmpty() )
117 dlg.SetInitialPage( aInitialPage, wxEmptyString );
118
119 // TODO: is QuasiModal required here?
120 if( dlg.ShowQuasiModal() == wxID_OK )
121 {
122 // Mark document as modified so that project settings can be saved as part of doc save
123 OnModify();
124
125 Kiway().CommonSettingsChanged( false, true );
126
130
131 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
135
136 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
137 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
138
141
142 std::vector<std::shared_ptr<BUS_ALIAS>> newAliases;
143
144 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
145 {
146 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
147 newAliases.push_back( alias );
148 }
149
150 if( oldAliases != newAliases )
152
154 GetCanvas()->Refresh();
155 }
156}
157
158
160{
161 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
162
163 const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
164 int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
165 int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
166
167 return std::max( dotSize, 1 );
168}
169
170
172{
173 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
174
176
177 if( !fn.HasName() || !IsWritable( fn, false ) )
178 return;
179
181
182 if( Kiway().Player( FRAME_SIMULATOR, false ) )
184
185 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
186
187 // TODO: We need to remove dependence on BASE_SCREEN
190
192 {
193 FILENAME_RESOLVER resolve;
194 resolve.SetProject( &Prj() );
195 resolve.SetProgramBase( &Pgm() );
196
197 wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
198 Prj().GetProjectPath(),
199 Schematic().GetEmbeddedFiles() ) );
200
201 bool success = true;
202
203 if( !layoutfn.IsAbsolute() )
204 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
205
206 if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
207 {
208 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
209 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
210 }
211 }
212
213 GetSettingsManager()->SaveProject( fn.GetFullPath() );
214}
215
216
218{
219 if( m_schematic )
221
222 PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
224
225 localSettings.m_SchSelectionFilter = selTool->GetFilter();
226}
227
228
230{
231 // For now, axes are forced off in Eeschema even if turned on in config
233 cfg->m_Window.grid.axes_enabled = false;
234
236
237 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
238
239 if( searchData )
240 {
246 }
247
249
253}
254
255
257{
260 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
261
262 if( cfg )
263 {
264 cfg->m_System.units = static_cast<int>( GetUserUnits() );
265 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
266 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
267
268 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
269 // and hierarchy_panel_docked_width should have been updated when resizing the
270 // hierarchy panel
271
272 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
273
274 if( searchData )
275 {
280 searchData->searchCurrentSheetOnly;
282 }
283
284 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
285 m_show_search = searchPaneInfo.IsShown();
287 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
288 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
289 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
290
291 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
292 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
295
296 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
297 cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
298 cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
299
300 if( netNavigatorPane.IsDocked() )
302 else
303 {
304 cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
305 cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
306 }
307 }
308}
309
310
312{
313 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
314
316
317 if( aCfg->m_Window.grid.grids.empty() )
318 aCfg->m_Window.grid.grids = aCfg->DefaultGridSizeList();
319
320 // Move legacy user grids to grid list
321 if( !aCfg->m_Window.grid.user_grid_x.empty() )
322 {
323 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
324 aCfg->m_Window.grid.user_grid_y } );
325 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
326 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
327 }
328
329 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
330 aCfg->m_Window.grid.last_size_idx = 1;
331
332 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
333 aCfg->m_Window.grid.fast_grid_1 = 1;
334
335 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
336 aCfg->m_Window.grid.fast_grid_2 = 2;
337
338 if( aCfg->m_Window.zoom_factors.empty() )
339 {
341 }
342}
343
344
346{
347 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
348
350}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:172
const std::vector< GRID > DefaultGridSizeList() const
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
COLOR4D GetColor(int aLayer) const
int ShowQuasiModal()
static DS_DATA_MODEL & GetTheInstance()
static function: returns 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)
Checks 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
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
SCH_SELECTION_FILTER_OPTIONS & GetFilter()
Provide an extensible class to resolve 3D model paths.
bool SetProject(PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles)
Determines the full path of the given file name.
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:1563
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:649
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:617
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:142
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:135
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:101
The project local settings are things that are attached to a particular project, but also might be pa...
SCH_SELECTION_FILTER_OPTIONS m_SchSelectionFilter
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:172
void IncrementNetclassesTicker()
Definition: project.h:98
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
void IncrementTextVarsTicker()
Definition: project.h:95
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:297
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:811
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:207
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 operaintg 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.
SCHEMATIC * m_schematic
The currently loaded schematic.
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()
void LoadDrawingSheet()
Load the drawing sheet file.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
static const wxString SchematicHierarchyPaneName()
int GetSchematicJunctionSize()
static const wxString NetNavigatorPaneName()
void saveProjectSettings() override
Saves any design-related project settings associated with this frame.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:710
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
const wxString & GetFileName() const
Definition: sch_screen.h:143
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves 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:595
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:354
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
int GetUserUnits()
Return the currently selected user unit value for the interface.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
@ GLOBAL_CLEANUP
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:81
std::vector< double > zoom_factors
Definition: app_settings.h:78
Definition for symbol library class.
Definition of file extensions used in Kicad.
#define ZOOM_LIST_EESCHEMA
Definition: zoom_defines.h:41