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-2022 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
22#include <symbol_library.h>
23#include <confirm.h>
25#include <kiway.h>
26#include <symbol_edit_frame.h>
28#include <pgm_base.h>
31#include <sch_edit_frame.h>
32#include <sch_painter.h>
33#include <schematic.h>
34#include <hierarch.h>
37#include <symbol_lib_table.h>
40#include <zoom_defines.h>
41
42
45{
46 return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
47}
48
49
51{
54
59
62
63 // Verify some values, because the config file can be edited by hand, and have bad values:
66
67 // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
68 // If empty, or not existing, the default drawing sheet is loaded.
70 Prj().GetProjectPath() );
71
72 if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
73 ShowInfoBarError( _( "Error loading drawing sheet." ), true );
74
75 return true;
76}
77
78
79void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
80{
81 DIALOG_SCHEMATIC_SETUP dlg( this );
82
83 if( !aInitialPage.IsEmpty() )
84 dlg.SetInitialPage( aInitialPage, wxEmptyString );
85
86 if( dlg.ShowQuasiModal() == wxID_OK )
87 {
89
90 Kiway().CommonSettingsChanged( false, true );
91
92 GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
96
97 GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
98 GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
99
102 GetCanvas()->Refresh();
103 }
104}
105
106
108{
109 std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
110
111 const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
112 int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
113 int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
114
115 return std::max( dotSize, 1 );
116}
117
118
120{
121 wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
122
123 fn.SetExt( ProjectFileExtension );
124
125 if( !fn.HasName() || !IsWritable( fn, false ) )
126 return;
127
129
130 GetSettingsManager()->SaveProject( fn.GetFullPath() );
131}
132
133
135{
136 // For now, axes are forced off in Eeschema even if turned on in config
138
140
141 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
142
143 if( searchData )
144 {
149 }
150
153}
154
155
157{
159 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
160
161 if( eeconfig() )
162 {
163 eeconfig()->m_System.units = static_cast<int>( GetUserUnits() );
164 eeconfig()->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
165 eeconfig()->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
166 // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
167 // and hierarchy_panel_docked_width should have been updated when resizing the
168 // hierarchy panel
169
170 SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
171
172 if( searchData )
173 {
178 searchData->searchCurrentSheetOnly;
179 }
180 }
181}
182
183
185{
186 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
187
189
190 // Currently values read from config file are not used because the user cannot
191 // change this config
192 // if( aCfg->m_Window.grid.sizes.empty() ) // Will be probably never enabled
193 {
194 /*
195 * Do NOT add others values (mainly grid values in mm), because they can break the
196 * schematic: Because wires and pins are considered as connected when the are to the
197 * same coordinate we cannot mix coordinates in mils (internal units) and mm (that
198 * cannot exactly converted in mils in many cases). In fact schematic must only use
199 * 50 and 25 mils to place labels, wires and symbols others values are useful only
200 * for graphic items (mainly in library editor) so use integer values in mils only.
201 * The 100 mil grid is added to help conform to the KiCad Library Convention which
202 * states: "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
203 */
204 aCfg->m_Window.grid.sizes = { "100 mil",
205 "50 mil",
206 "25 mil",
207 "10 mil",
208 "5 mil",
209 "2 mil",
210 "1 mil" };
211 }
212
213 // Currently values read from config file are not used because the user cannot
214 // change this config
215 // if( aCfg->m_Window.zoom_factors.empty() )
216 {
218 }
219}
220
221
223{
224 wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
225
227}
228
229
230static std::mutex s_symbolTableMutex;
231
232
233SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
234{
235 std::lock_guard<std::mutex> lock( s_symbolTableMutex );
236
237 // This is a lazy loading function, it loads the project specific table when
238 // that table is asked for, not before.
240
241 // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
242 wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
243
244 if( !tbl )
245 {
246 // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
247 // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
248 // stack this way, all using the same global fallback table.
250
252
253 wxString prjPath;
254
255 wxGetEnv( PROJECT_VAR_NAME, &prjPath );
256
257 if( !prjPath.IsEmpty() )
258 {
259 wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
260
261 try
262 {
263 tbl->Load( fn.GetFullPath() );
264 }
265 catch( const IO_ERROR& ioe )
266 {
267 wxString msg;
268 msg.Printf( _( "Error loading the symbol library table '%s'." ),
269 fn.GetFullPath() );
270 DisplayErrorMessage( nullptr, msg, ioe.What() );
271 }
272 }
273 }
274
275 return tbl;
276}
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
WINDOW_SETTINGS m_Window
Definition: app_settings.h:184
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
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 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:1478
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:572
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:569
static int GetSubpartFirstId()
Definition: lib_symbol.h:575
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)
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:96
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:283
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:293
@ ELEM_SYMBOL_LIB_TABLE
Definition: project.h:210
These settings were stored in SCH_BASE_FRAME previously.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
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:143
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:299
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:38
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:90
std::vector< double > zoom_factors
Definition: app_settings.h:87
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