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-2021 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <mutex>
25 
26 #include <symbol_library.h>
27 #include <confirm.h>
35 #include <kiway.h>
36 #include <symbol_edit_frame.h>
38 #include <panel_hotkeys_editor.h>
39 #include <pgm_base.h>
40 #include <project/project_file.h>
41 #include <project/net_settings.h>
42 #include <sch_edit_frame.h>
43 #include <sch_painter.h>
44 #include <schematic.h>
45 #include <settings/app_settings.h>
47 #include <symbol_lib_table.h>
48 #include <widgets/paged_dialog.h>
51 #include <zoom_defines.h>
52 #include <wx/treebook.h>
53 
54 
57 {
58  return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
59 }
60 
61 
63  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
64 {
65  wxTreebook* book = aParent->GetTreebook();
66 
67  book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
68  book->AddSubPage( new PANEL_EESCHEMA_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) );
69  book->AddSubPage( new PANEL_EESCHEMA_EDITING_OPTIONS( this, book ), _( "Editing Options" ) );
70  book->AddSubPage( new PANEL_EESCHEMA_COLOR_SETTINGS( this, book ), _( "Colors" ) );
71  book->AddSubPage( new PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( this, book, true ),
72  _( "Field Name Templates" ) );
73 
74  aHotkeysPanel->AddHotKeys( GetToolManager() );
75 }
76 
77 
79 {
80  SCHEMATIC_SETTINGS& settings = Schematic().Settings();
82 
90 
91  // Verify some values, because the config file can be edited by hand, and have bad values:
94 
95  // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
96  // If empty, or not existing, the default drawing sheet is loaded.
98  Prj().GetProjectPath() );
99 
100  if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
101  ShowInfoBarError( _( "Error loading drawing sheet." ), true );
102 
103  return true;
104 }
105 
106 
107 void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
108 {
109  DIALOG_SCHEMATIC_SETUP dlg( this );
110 
111  if( !aInitialPage.IsEmpty() )
112  dlg.SetInitialPage( aInitialPage, wxEmptyString );
113 
114  if( dlg.ShowQuasiModal() == wxID_OK )
115  {
117 
119 
120  Kiway().CommonSettingsChanged( false, true );
121  GetCanvas()->Refresh();
122  }
123 }
124 
125 
127 {
128  std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
129 
130  NETCLASSPTR defaultNetclass = Prj().GetProjectFile().NetSettings().m_NetClasses.GetDefault();
131  int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
132  int junctionSize = defaultNetclass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
133 
134  return std::max( junctionSize, 1 );
135 }
136 
137 
139 {
140  wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
141 
142  fn.SetExt( ProjectFileExtension );
143 
144  if( !fn.HasName() || !IsWritable( fn ) )
145  return;
146 
148 
149  GetSettingsManager()->SaveProject( fn.GetFullPath() );
150 }
151 
152 
154 {
155  // For now, axes are forced off in Eeschema even if turned on in config
156  eeconfig()->m_Window.grid.axes_enabled = false;
157 
159 
166 
167  if( eeconfig() )
168  {
171  GetRenderSettings()->SetShowPageLimits( eeconfig()->m_Appearance.show_page_limits );
172  }
173 }
174 
175 
177 {
179 
180  // TODO(JE) do we need to keep m_userUnits around?
181  if( eeconfig() )
182  eeconfig()->m_System.units = static_cast<int>( m_userUnits );
183 }
184 
185 
187 {
188  wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
189 
191 
192  // Currently values read from config file are not used because the user cannot
193  // change this config
194  // if( aCfg->m_Window.grid.sizes.empty() ) // Will be probably never enabled
195  {
196  /*
197  * Do NOT add others values (mainly grid values in mm), because they can break the
198  * schematic: Because wires and pins are considered as connected when the are to the
199  * same coordinate we cannot mix coordinates in mils (internal units) and mm (that
200  * cannot exactly converted in mils in many cases). In fact schematic must only use
201  * 50 and 25 mils to place labels, wires and symbols others values are useful only
202  * for graphic items (mainly in library editor) so use integer values in mils only.
203  * The 100 mil grid is added to help conform to the KiCad Library Convention which
204  * states: "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
205  */
206  aCfg->m_Window.grid.sizes = { "100 mil",
207  "50 mil",
208  "25 mil",
209  "10 mil",
210  "5 mil",
211  "2 mil",
212  "1 mil" };
213  }
214 
215  // Currently values read from config file are not used because the user cannot
216  // change this config
217  // if( aCfg->m_Window.zoom_factors.empty() )
218  {
220  }
221 }
222 
223 
225 {
226  wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
227 
229 }
230 
231 
233  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
234 {
235  wxTreebook* book = aParent->GetTreebook();
236 
237  book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
238  book->AddSubPage( new PANEL_GAL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
239  book->AddSubPage( new PANEL_SYM_EDITING_OPTIONS( this, book ), _( "Editing Options" ) );
240  book->AddSubPage( new PANEL_SYM_COLOR_SETTINGS( this, book ), _( "Colors" ) );
241 
242  aHotkeysPanel->AddHotKeys( GetToolManager() );
243 }
244 
245 
246 static std::mutex s_symbolTableMutex;
247 
248 
249 SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
250 {
251  std::lock_guard<std::mutex> lock( s_symbolTableMutex );
252 
253  // This is a lazy loading function, it loads the project specific table when
254  // that table is asked for, not before.
256 
257  // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
258  wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
259 
260  if( !tbl )
261  {
262  // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
263  // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
264  // stack this way, all using the same global fallback table.
266 
268 
269  wxString prjPath;
270 
271  wxGetEnv( PROJECT_VAR_NAME, &prjPath );
272 
273  if( !prjPath.IsEmpty() )
274  {
275  wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
276 
277  try
278  {
279  tbl->Load( fn.GetFullPath() );
280  }
281  catch( const IO_ERROR& ioe )
282  {
283  wxString msg;
284  msg.Printf( _( "Error loading the symbol library table '%s'." ),
285  fn.GetFullPath() );
286  DisplayErrorMessage( nullptr, msg, ioe.What() );
287  }
288  }
289  }
290 
291  return tbl;
292 }
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
const wxString & GetFileName() const
Definition: sch_screen.h:145
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
SETTINGS_MANAGER * GetSettingsManager() const
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
This file is part of the common library.
const std::string ProjectFileExtension
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
NET_SETTINGS & NetSettings()
Definition: project_file.h:94
int GetSchematicJunctionSize()
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
void AddHotKeys(TOOL_MANAGER *aToolMgr)
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:246
void RebuildNetClassAssignments()
Rebuild netclass assignments from the netclass membership lists.
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
std::vector< double > zoom_factors
Definition: app_settings.h:86
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:258
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
EESCHEMA_SETTINGS * eeconfig() const
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
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...
static const wxString ResolvePath(const wxString &aPath, const wxString &aProjectPath)
Resolve a path which might be project-relative or contain env variable references.
static int GetSubpartFirstId()
Definition: lib_symbol.h:520
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
std::vector< wxString > sizes
Definition: app_settings.h:52
NETCLASSES m_NetClasses
Definition: net_settings.h:40
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:324
KICAD_T Type() override
GRID_SETTINGS grid
Definition: app_settings.h:89
int ShowQuasiModal()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
SCHEMATIC & Schematic() const
Definition of file extensions used in Kicad.
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Helper for all the old plotting/printing code while it still exists.
Definition for symbol library class.
#define _(s)
#define ZOOM_LIST_EESCHEMA
Definition: zoom_defines.h:38
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow the symbol editor to install its preferences panel into the preferences dialog.
static int GetSubpartIdSeparator()
Definition: lib_symbol.h:514
bool LoadProjectSettings()
Load the KiCad project file (*.pro) settings specific to Eeschema.
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
see class PGM_BASE
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow Eeschema to install its preferences panels into the preferences dialog.
static std::mutex s_symbolTableMutex
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
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...
EDA_UNITS m_userUnits
Map containing the UI update handlers registered with wx for each action.
These settings were stored in SCH_BASE_FRAME previously.
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:554
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
std::vector< double > junction_size_mult_list
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void SetDefaultPenWidth(int aWidth)
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
void SetShowPageLimits(bool aDraw)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103