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 <pgm_base.h>
32#include <sch_edit_frame.h>
33#include <sch_painter.h>
34#include <schematic.h>
42#include <zoom_defines.h>
43#include <sim/spice_settings.h>
44
45
48{
49 return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
50}
51
52
54{
57
62
65
67
68 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
69 // If empty, or not existing, the default drawing sheet is loaded.
71 Prj().GetProjectPath() );
72
73 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
74 ShowInfoBarError( _( "Error loading drawing sheet." ), true );
75
76 return true;
77}
78
79
80void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
81{
82 DIALOG_SCHEMATIC_SETUP dlg( this );
83
84 if( !aInitialPage.IsEmpty() )
85 dlg.SetInitialPage( aInitialPage, wxEmptyString );
86
87 if( dlg.ShowQuasiModal() == wxID_OK )
88 {
89 // Mark document as modified so that project settings can be saved as part of doc save
90 OnModify();
91
92 Kiway().CommonSettingsChanged( false, true );
93
96
97 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
101
102 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
103 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
104
108 GetCanvas()->Refresh();
109 }
110}
111
112
114{
115 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
116
117 const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
118 int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
119 int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
120
121 return std::max( dotSize, 1 );
122}
123
124
126{
127 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
128
129 fn.SetExt( ProjectFileExtension );
130
131 if( !fn.HasName() || !IsWritable( fn, false ) )
132 return;
133
135
136 if( Kiway().Player( FRAME_SIMULATOR, false ) )
138
139 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
140
141 // TODO: We need to remove dependence on BASE_SCREEN
144
146 {
148 Prj().GetProjectPath() ) );
149
150 bool success = true;
151
152 if( !layoutfn.IsAbsolute() )
153 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
154
155 if( success && layoutfn.IsOk() && !layoutfn.FileExists() )
156 {
157 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
158 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
159 }
160 }
161
162 GetSettingsManager()->SaveProject( fn.GetFullPath() );
163}
164
165
167{
168 if( m_schematic )
170}
171
172
174{
175 // For now, axes are forced off in Eeschema even if turned on in config
177 cfg->m_Window.grid.axes_enabled = false;
178
180
181 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
182
183 if( searchData )
184 {
190 }
191
193
197}
198
199
201{
204 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
205
206 if( cfg )
207 {
208 cfg->m_System.units = static_cast<int>( GetUserUnits() );
209 cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
210 cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
211
212 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
213 // and hierarchy_panel_docked_width should have been updated when resizing the
214 // hierarchy panel
215
216 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
217
218 if( searchData )
219 {
224 searchData->searchCurrentSheetOnly;
226 }
227
228 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
229 m_show_search = searchPaneInfo.IsShown();
231 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
232 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
233 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
234
235 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
236 cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
239 }
240}
241
242
244{
245 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
246
248
249 if( aCfg->m_Window.grid.grids.empty() )
250 aCfg->m_Window.grid.grids = aCfg->DefaultGridSizeList();
251
252 // Move legacy user grids to grid list
253 if( !aCfg->m_Window.grid.user_grid_x.empty() )
254 {
255 aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
256 aCfg->m_Window.grid.user_grid_y } );
257 aCfg->m_Window.grid.user_grid_x = wxEmptyString;
258 aCfg->m_Window.grid.user_grid_y = wxEmptyString;
259 }
260
261 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
262 aCfg->m_Window.grid.last_size_idx = 1;
263
264 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
265 aCfg->m_Window.grid.fast_grid_1 = 1;
266
267 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
268 aCfg->m_Window.grid.fast_grid_2 = 2;
269
270 if( aCfg->m_Window.zoom_factors.empty() )
271 {
273 }
274}
275
276
278{
279 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
280
282}
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:169
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
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.
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
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
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:1500
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:643
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:637
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:135
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:101
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 settings were stored in SCH_BASE_FRAME previously.
wxString m_SchDrawingSheetFileName
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:287
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:197
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
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
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.
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 SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
static const wxString SchematicHierarchyPaneName()
int GetSchematicJunctionSize()
void saveProjectSettings() override
Saves any design-related project settings associated with this frame.
const wxString & GetFileName() const
Definition: sch_screen.h:144
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
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:38
const std::string ProjectFileExtension
PROJECT & Prj()
Definition: kicad.cpp:576
KIWAY Kiway
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:346
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
int GetUserUnits()
Return the currently selected user unit value for the interface.
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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