KiCad PCB EDA Suite
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>
38#include <symbol_lib_table.h>
41#include <zoom_defines.h>
42
43
46{
47 return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
48}
49
50
52{
55
60
63
64 // Verify some values, because the config file can be edited by hand, and have bad values:
67
69
70 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
71 // If empty, or not existing, the default drawing sheet is loaded.
73 Prj().GetProjectPath() );
74
75 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
76 ShowInfoBarError( _( "Error loading drawing sheet." ), true );
77
78 return true;
79}
80
81
82void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
83{
84 DIALOG_SCHEMATIC_SETUP dlg( this );
85
86 if( !aInitialPage.IsEmpty() )
87 dlg.SetInitialPage( aInitialPage, wxEmptyString );
88
89 if( dlg.ShowQuasiModal() == wxID_OK )
90 {
92
93 Kiway().CommonSettingsChanged( false, true );
94
95 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
99
100 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
101 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
102
105 GetCanvas()->Refresh();
106 }
107}
108
109
111{
112 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
113
114 const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
115 int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
116 int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
117
118 return std::max( dotSize, 1 );
119}
120
121
123{
124 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
125
126 fn.SetExt( ProjectFileExtension );
127
128 if( !fn.HasName() || !IsWritable( fn, false ) )
129 return;
130
132
133
134 // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
135
136 // TODO: We need to remove dependence on BASE_SCREEN
139
141 {
142 wxFileName layoutfn( BASE_SCREEN::m_DrawingSheetFileName );
143
144 bool success = true;
145
146 if( !layoutfn.IsAbsolute() )
147 success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
148
149 if( success && layoutfn.IsOk() && !layoutfn.FileExists() )
150 {
151 if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
152 DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
153 }
154 }
155
156 GetSettingsManager()->SaveProject( fn.GetFullPath() );
157}
158
159
161{
162 // For now, axes are forced off in Eeschema even if turned on in config
164
166
167 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
168
169 if( searchData )
170 {
175 }
176
179 GetRenderSettings()->SetDefaultFont( eeconfig()->m_Appearance.default_font );
180}
181
182
184{
186 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
187
188 if( eeconfig() )
189 {
190 eeconfig()->m_System.units = static_cast<int>( GetUserUnits() );
191 eeconfig()->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
192 eeconfig()->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
193 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
194 // and hierarchy_panel_docked_width should have been updated when resizing the
195 // hierarchy panel
196
197 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
198
199 if( searchData )
200 {
205 searchData->searchCurrentSheetOnly;
206 }
207 }
208}
209
210
212{
213 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
214
216
217 /*
218 * Do NOT add other values (particularly grid values in mm), because they can break the
219 * schematic: Because wires and pins are considered as connected when the are to the same
220 * coordinate we cannot mix coordinates in mils (internal units) and mm (that cannot exactly
221 * converted in mils in many cases). In fact schematic must only use 50 and 25 mils to
222 * place labels, wires and symbols others values are useful only for graphic items (mainly
223 * in library editor) so use integer values in mils only.
224 * The 100 mil grid is added to help conform to the KiCad Library Convention which states:
225 * "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
226 */
227 aCfg->m_Window.grid.sizes = { wxS( "100 mil" ),
228 wxS( "50 mil" ),
229 wxS( "25 mil" ),
230 wxS( "10 mil" ),
231 wxS( "5 mil" ),
232 wxS( "2 mil" ),
233 wxS( "1 mil" ) };
234
235 if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.sizes.size() )
236 aCfg->m_Window.grid.last_size_idx = 1;
237
238 if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.sizes.size() )
239 aCfg->m_Window.grid.fast_grid_1 = 1;
240
241 if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.sizes.size() )
242 aCfg->m_Window.grid.fast_grid_2 = 2;
243
244 if( aCfg->m_Window.zoom_factors.empty() )
245 {
247 }
248}
249
250
252{
253 wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
254
256}
257
258
259static std::mutex s_symbolTableMutex;
260
261
262SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
263{
264 std::lock_guard<std::mutex> lock( s_symbolTableMutex );
265
266 // This is a lazy loading function, it loads the project specific table when
267 // that table is asked for, not before.
269
270 // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
271 wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
272
273 if( !tbl )
274 {
275 // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
276 // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
277 // stack this way, all using the same global fallback table.
279
281
282 wxString prjPath;
283
284 wxGetEnv( PROJECT_VAR_NAME, &prjPath );
285
286 if( !prjPath.IsEmpty() )
287 {
288 wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
289
290 try
291 {
292 tbl->Load( fn.GetFullPath() );
293 }
294 catch( const IO_ERROR& ioe )
295 {
296 wxString msg;
297 msg.Printf( _( "Error loading the symbol library table '%s'." ),
298 fn.GetFullPath() );
299 DisplayErrorMessage( nullptr, msg, ioe.What() );
300 }
301 }
302 }
303
304 return tbl;
305}
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.
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
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: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:1484
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:641
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:575
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:570
static int GetSubpartFirstId()
Definition: lib_symbol.h:576
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
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:203
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:120
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 SaveProjectSettings() 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.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
static const wxString SchematicHierarchyPaneName()
int GetSchematicJunctionSize()
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
EDA_UNITS GetUserUnits() const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
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.
const std::string ProjectFileExtension
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
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:111
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:234
Definition of file extensions used in Kicad.
#define ZOOM_LIST_EESCHEMA
Definition: zoom_defines.h:38