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-2020 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 <class_library.h>
25 #include <confirm.h>
33 #include <kiway.h>
34 #include <symbol_edit_frame.h>
36 #include <panel_hotkeys_editor.h>
37 #include <pgm_base.h>
38 #include <project/project_file.h>
39 #include <project/net_settings.h>
40 #include <sch_edit_frame.h>
41 #include <sch_painter.h>
42 #include <schematic.h>
43 #include <settings/app_settings.h>
45 #include <symbol_lib_table.h>
46 #include <widgets/paged_dialog.h>
49 #include <zoom_defines.h>
50 
51 
54 {
55  return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
56 }
57 
58 
60  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
61 {
62  wxTreebook* book = aParent->GetTreebook();
63 
64  book->AddPage( new wxPanel( book ), _( "Eeschema" ) );
65  book->AddSubPage( new PANEL_EESCHEMA_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) );
66  book->AddSubPage( new PANEL_EESCHEMA_EDITING_OPTIONS( this, book ), _( "Editing Options" ) );
67  book->AddSubPage( new PANEL_EESCHEMA_COLOR_SETTINGS( this, book ), _( "Colors" ) );
68  book->AddSubPage( new PANEL_EESCHEMA_TEMPLATE_FIELDNAMES( this, book, true ),
69  _( "Field Name Templates" ) );
70 
71  aHotkeysPanel->AddHotKeys( GetToolManager() );
72 }
73 
74 
76 {
83 
84  // Verify some values, because the config file can be edited by hand,
85  // and have bad values:
88 
89  // Load the page layout decr file, from the filename stored in
90  // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
91  // If empty, or not existing, the default descr is loaded
94  Prj().GetProjectPath() );
95 
96  pglayout.SetPageLayout( filename );
97 
98  return true;
99 }
100 
101 
102 void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
103 {
104  DIALOG_SCHEMATIC_SETUP dlg( this );
105 
106  if( !aInitialPage.IsEmpty() )
107  dlg.SetInitialPage( aInitialPage, wxEmptyString );
108 
109  if( dlg.ShowQuasiModal() == wxID_OK )
110  {
113 
114  Kiway().CommonSettingsChanged( false, true );
115  GetCanvas()->Refresh();
116  }
117 }
118 
119 
121 {
122  wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
123 
124  fn.SetExt( ProjectFileExtension );
125 
126  if( !fn.HasName() || !IsWritable( fn ) )
127  return;
128 
130 
131  GetSettingsManager()->SaveProject( fn.GetFullPath() );
132 }
133 
134 
136 {
137  // For now, axes are forced off in eeschema even if turned on in config
138  eeconfig()->m_Window.grid.axes_enabled = false;
139 
141 
148 
149  if( eeconfig() )
150  {
153  GetRenderSettings()->SetShowPageLimits( eeconfig()->m_Appearance.show_page_limits );
154  }
155 }
156 
157 
159 {
161 
162  // TODO(JE) do we need to keep m_userUnits around?
163  if( eeconfig() )
164  eeconfig()->m_System.units = static_cast<int>( m_userUnits );
165 }
166 
167 
169 {
170  wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
171 
173 
174  // Currently values read from config file are not used because the user cannot
175  // change this config
176  // if( aCfg->m_Window.grid.sizes.empty() ) // Will be probably never enabled
177  {
178  /*
179  * Do NOT add others values (mainly grid values in mm), because they can break the
180  * schematic: Because wires and pins are considered as connected when the are to the
181  * same coordinate we cannot mix coordinates in mils (internal units) and mm (that
182  * cannot exactly converted in mils in many cases). In fact schematic must only use
183  * 50 and 25 mils to place labels, wires and components others values are useful only
184  * for graphic items (mainly in library editor) so use integer values in mils only.
185  * The 100 mil grid is added to help conform to the KiCad Library Convention which
186  * states: "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
187  */
188  aCfg->m_Window.grid.sizes = { "100 mil",
189  "50 mil",
190  "25 mil",
191  "10 mil",
192  "5 mil",
193  "2 mil",
194  "1 mil" };
195  }
196 
197  // Currently values read from config file are not used because the user cannot
198  // change this config
199  // if( aCfg->m_Window.zoom_factors.empty() )
200  {
202  }
203 }
204 
205 
207 {
208  wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::SaveSettings with null settings" );
209 
211 }
212 
213 
215  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
216 {
217  wxTreebook* book = aParent->GetTreebook();
218 
219  book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
220  book->AddSubPage( new PANEL_GAL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
221  book->AddSubPage( new PANEL_SYM_EDITING_OPTIONS( this, book ), _( "Editing Options" ) );
222  book->AddSubPage( new PANEL_SYM_COLOR_SETTINGS( this, book ), _( "Colors" ) );
223 
224  aHotkeysPanel->AddHotKeys( GetToolManager() );
225 }
226 
227 
228 SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable()
229 {
230  // This is a lazy loading function, it loads the project specific table when
231  // that table is asked for, not before.
233 
234  // its gotta be NULL or a SYMBOL_LIB_TABLE, or a bug.
235  wxASSERT( !tbl || tbl->Type() == SYMBOL_LIB_TABLE_T );
236 
237  if( !tbl )
238  {
239  // Stack the project specific SYMBOL_LIB_TABLE overlay on top of the global table.
240  // ~SYMBOL_LIB_TABLE() will not touch the fallback table, so multiple projects may
241  // stack this way, all using the same global fallback table.
243 
245 
246  wxString prjPath;
247 
248  wxGetEnv( PROJECT_VAR_NAME, &prjPath );
249 
250  if( !prjPath.IsEmpty() )
251  {
252  wxFileName fn( prjPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
253 
254  try
255  {
256  tbl->Load( fn.GetFullPath() );
257  }
258  catch( const IO_ERROR& ioe )
259  {
260  wxString msg;
261  msg.Printf( _( "An error occurred loading the symbol library table \"%s\"." ),
262  fn.GetFullPath() );
263  DisplayErrorMessage( NULL, msg, ioe.What() );
264  }
265  }
266  }
267 
268  return tbl;
269 }
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:38
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
const wxString & GetFileName() const
Definition: sch_screen.h:186
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:253
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)
#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:92
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
void AddHotKeys(TOOL_MANAGER *aToolMgr)
void SetPageLayout(const wxString &aFullFileName=wxEmptyString, bool Append=false)
Populates the list with a custom layout, or the default layout, if no custom layout available.
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:246
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:102
std::vector< double > zoom_factors
Definition: app_settings.h:86
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
VTBL_ENTRY 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.
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:84
EESCHEMA_SETTINGS * eeconfig() const
wxTreebook * GetTreebook()
Definition: paged_dialog.h:50
static int GetSubpartIdSeparator()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
std::vector< wxString > sizes
Definition: app_settings.h:52
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
KICAD_T Type() override
static int GetSubpartFirstId()
GRID_SETTINGS grid
Definition: app_settings.h:89
int ShowQuasiModal()
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:143
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explodes the list of netclass assignments to include atomic members of composite labels (buses).
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.
SCH_LAYER_ID
Eeschema drawing layers.
#define ZOOM_LIST_EESCHEMA
Definition: zoom_defines.h:38
SCHEMATIC_SETTINGS * m_defaults
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
Allows Libedit to install its preferences panel into the preferences dialog.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool LoadProjectSettings()
Loads the KiCad project file (*.pro) settings specific to Eeschema.
WINDOW_SETTINGS m_Window
Definition: app_settings.h:173
see class PGM_BASE
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows Eeschema to install its preferences panels into the preferences dialog.
static const wxString MakeFullFileName(const wxString &aShortFileName, const wxString &aProjectPath)
Static function.
#define _(s)
Definition: 3d_actions.cpp:33
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
EDA_UNITS m_userUnits
VTBL_ENTRY void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:515
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
Definition for part library class.
SCH_SCREEN * RootScreen() const
Helper to retreive the screen of the root sheet.
Definition: schematic.cpp:113
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)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
void SetShowPageLimits(bool aDraw)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100