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>
39#include <symbol_lib_table.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
66 // Verify some values, because the config file can be edited by hand, and have bad values:
69
71
72 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
73 // If empty, or not existing, the default drawing sheet is loaded.
75 Prj().GetProjectPath() );
76
77 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
78 ShowInfoBarError( _( "Error loading drawing sheet." ), true );
79
80 return true;
81}
82
83
84void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
85{
86 DIALOG_SCHEMATIC_SETUP dlg( this );
87
88 if( !aInitialPage.IsEmpty() )
89 dlg.SetInitialPage( aInitialPage, wxEmptyString );
90
91 if( dlg.ShowQuasiModal() == wxID_OK )
92 {
93 // Mark document as modified so that project settings can be saved as part of doc save
94 OnModify();
95
96 Kiway().CommonSettingsChanged( false, true );
97
98 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
102
103 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
104 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
105
109 GetCanvas()->Refresh();
110 }
111}
112
113
115{
116 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
117
118 const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
119 int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
120 int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
121
122 return std::max( dotSize, 1 );
123}
124
125
127{
128 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
129
130 fn.SetExt( ProjectFileExtension );
131
132 if( !fn.HasName() || !IsWritable( fn, false ) )
133 return;
134
136
137 if( Kiway().Player( FRAME_SIMULATOR, false ) )
139
140 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
141
142 // TODO: We need to remove dependence on BASE_SCREEN
145
147 {
149 Prj().GetProjectPath() ) );
150
151 bool success = true;
152
153 if( !layoutfn.IsAbsolute() )
154 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
155
156 if( success && layoutfn.IsOk() && !layoutfn.FileExists() )
157 {
158 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
159 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
160 }
161 }
162
163 GetSettingsManager()->SaveProject( fn.GetFullPath() );
164}
165
166
168{
169 // No schematic local settings yet
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 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
212 // and hierarchy_panel_docked_width should have been updated when resizing the
213 // hierarchy panel
214
215 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
216
217 if( searchData )
218 {
223 searchData->searchCurrentSheetOnly;
225 }
226
227 m_show_search = m_auimgr.GetPane( SearchPaneName() ).IsShown();
229 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
230 }
231}
232
233
235{
236 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
237
239
240 /*
241 * Do NOT add other values (particularly grid values in mm), because they can break the
242 * schematic: Because wires and pins are considered as connected when the are to the same
243 * coordinate we cannot mix coordinates in mils (internal units) and mm (that cannot exactly
244 * converted in mils in many cases). In fact schematic must only use 50 and 25 mils to
245 * place labels, wires and symbols others values are useful only for graphic items (mainly
246 * in library editor) so use integer values in mils only.
247 * The 100 mil grid is added to help conform to the KiCad Library Convention which states:
248 * "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
249 */
250 aCfg->m_Window.grid.sizes = { wxS( "100 mil" ),
251 wxS( "50 mil" ),
252 wxS( "25 mil" ),
253 wxS( "10 mil" ) };
254
255 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.sizes.size() )
256 aCfg->m_Window.grid.last_size_idx = 1;
257
258 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.sizes.size() )
259 aCfg->m_Window.grid.fast_grid_1 = 1;
260
261 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.sizes.size() )
262 aCfg->m_Window.grid.fast_grid_2 = 2;
263
264 if( aCfg->m_Window.zoom_factors.empty() )
265 {
267 }
268}
269
270
272{
273 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
274
276}
277
278
279static std::mutex s_symbolTableMutex;
280
281
282SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
283{
284 std::lock_guard<std::mutex> lock( s_symbolTableMutex );
285
286 // This is a lazy loading function, it loads the project specific table when
287 // that table is asked for, not before.
289
290 // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
291 wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
292
293 if( !tbl )
294 {
295 // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
296 // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
297 // stack this way, all using the same global fallback table.
299
301
302 wxString prjPath;
303
304 wxGetEnv( PROJECT_VAR_NAME, &prjPath );
305
306 if( !prjPath.IsEmpty() )
307 {
308 wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
309
310 try
311 {
312 tbl->Load( fn.GetFullPath() );
313 }
314 catch( const IO_ERROR& ioe )
315 {
316 wxString msg;
317 msg.Printf( _( "Error loading the symbol library table '%s'." ),
318 fn.GetFullPath() );
319 DisplayErrorMessage( nullptr, msg, ioe.What() );
320 }
321 }
322 }
323
324 return tbl;
325}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
WINDOW_SETTINGS m_Window
Definition: app_settings.h:187
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.
SEARCH_PANE * m_searchPane
The current canvas type.
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
FIND_REPLACE_EXTRA m_FindReplaceExtra
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
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:1501
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:641
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:633
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:577
static int GetSubpartFirstId()
Definition: lib_symbol.h:583
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:96
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:284
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:294
@ ELEM_SYMBOL_LIB_TABLE
Definition: project.h:211
These settings were stored in SCH_BASE_FRAME previously.
wxString m_SchDrawingSheetFileName
std::shared_ptr< NGSPICE_SIMULATOR_SETTINGS > m_NgspiceSimulatorSettings
Ngspice simulator settings.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:205
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:122
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.
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
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.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString & GetSymbolLibTableFileName()
KICAD_T Type() override
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:308
This file is part of the common library.
#define _(s)
static std::mutex s_symbolTableMutex
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:554
KIWAY Kiway
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:345
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
int GetUserUnits()
Return the currently selected user unit value for the interface.
see class PGM_BASE
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:39
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
std::vector< double > junction_size_mult_list
std::vector< wxString > sizes
Definition: app_settings.h:53
GRID_SETTINGS grid
Definition: app_settings.h:99
std::vector< double > zoom_factors
Definition: app_settings.h:96
Definition for symbol library class.
@ SYMBOL_LIB_TABLE_T
Definition: typeinfo.h:224
Definition of file extensions used in Kicad.
#define ZOOM_LIST_EESCHEMA
Definition: zoom_defines.h:38