KiCad PCB EDA Suite
pgm_base.h
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) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef PGM_BASE_H_
32 #define PGM_BASE_H_
33 
34 #include <map>
35 #include <wx/filename.h>
36 #include <search_stack.h>
37 #include <wx/gdicmn.h>
38 
39 
40 class wxConfigBase;
41 class wxSingleInstanceChecker;
42 class wxApp;
43 class wxMenu;
44 class wxWindow;
45 
46 
47 // inter program module calling
48 #define VTBL_ENTRY virtual
49 
50 
59 {
60 public:
61  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
62  m_value( aValue ),
63  m_isDefinedExternally( aIsDefinedExternally )
64  {
65  }
66 
67  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
68 
70  void SetDefinedExternally( bool aIsDefinedExternally )
71  {
72  m_isDefinedExternally = aIsDefinedExternally;
73  }
74 
75  const wxString& GetValue() const { return m_value; }
76  void SetValue( const wxString& aValue ) { m_value = aValue; }
77 
78 private:
80  wxString m_value;
81 
84 };
85 
86 
87 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
88 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
89 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
90 
91 
107 class PGM_BASE
108 {
109 public:
110  PGM_BASE();
111  virtual ~PGM_BASE();
112 
113 #if 0
114  /*
115 
116  Derived classes must implement these two functions: OnPgmInit() and
117  OnPgmExit(), and since they are only called from same source file as their
118  implementation, these need not be virtual here. In fact, in the case of
119  python project manager's class PGM_PYTHON, these functions are actually
120  written in python. In total there are three implementations, corresponding
121  to the three defines given by kiface.h's KFCTL_* #defines.
122 
123  */
124 
130  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
131 
132  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
133 #endif
134 
135  //----<Cross Module API>-----------------------------------------------------
136 
143  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
144 
145  VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
146 
147  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
148 
157  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
158 
166  VTBL_ENTRY const wxString AskUserForPreferredEditor(
167  const wxString& aDefaultEditor = wxEmptyString );
168 
169  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
170 
171  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
172 
173  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
174 
175  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
176 
177  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
178 
179  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
180 
188  {
189  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
190  }
191 
197 
208  VTBL_ENTRY bool SetLanguage( bool first_time = false );
209 
217  VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
218 
227  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
228 
230 
236 
242 
257  VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
258 
268  VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
269 
271  {
272  return m_local_env_vars;
273  }
274 
286  VTBL_ENTRY void ConfigurePaths( wxWindow* aParent = NULL );
287 
293  VTBL_ENTRY wxApp& App();
294 
295  //----</Cross Module API>----------------------------------------------------
296 
297  static const wxChar workingDirKey[];
298 
310  bool InitPgm();
311 
312  // The PGM_* classes can have difficulties at termination if they
313  // are not destroyed soon enough. Relying on a static destructor can be
314  // too late for contained objects like wxSingleInstanceChecker.
315  void Destroy();
316 
321  void SaveCommonSettings();
322 
324  void SetIconsScale( double aValue ) { m_iconsScale = aValue; }
325  double GetIconsScale() { return m_iconsScale; }
327  void SetUseIconsInMenus( bool aUseIcons ) { m_useIconsInMenus = aUseIcons; }
329 
330 
331 protected:
332 
337  void loadCommonSettings();
338 
340  wxSingleInstanceChecker* m_pgm_checker;
341 
344  wxConfigBase* m_common_settings;
345 
347  wxString m_bin_dir;
348 
350  wxString m_kicad_env;
351 
353  wxLocale* m_locale;
354 
357 
360 
362  double m_iconsScale;
365 
367  void setLanguageId( int aId ) { m_language_id = aId; }
368 
374  bool setExecutablePath();
375 
377  wxString m_pdf_browser;
378  wxString m_editor_name;
379  wxSize m_help_size;
380 
383 
386 };
387 
388 
391 extern PGM_BASE& Pgm();
392 
393 #endif // PGM_BASE_H_
void loadCommonSettings()
Function loadCommonSettings loads the program (process) settings subset which are stored in ...
Definition: pgm_base.cpp:600
void SetUseIconsInMenus(bool aUseIcons)
True to use menu icons.
Definition: pgm_base.h:327
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:328
virtual ~PGM_BASE()
Definition: pgm_base.cpp:300
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
Definition: pgm_base.h:83
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:382
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:171
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ...
Definition: pgm_base.cpp:646
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:173
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
const wxString & GetValue() const
Definition: pgm_base.h:75
double GetIconsScale()
Definition: pgm_base.h:325
#define VTBL_ENTRY
Definition: pgm_base.h:48
wxString m_value
The environment variable string value.
Definition: pgm_base.h:80
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:353
Class ENV_VAR_ITEM.
Definition: pgm_base.h:58
static const wxChar workingDirKey[]
Definition: pgm_base.h:297
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:196
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:177
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:321
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:385
void Destroy()
Definition: pgm_base.cpp:306
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:558
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:340
VTBL_ENTRY void WritePdfBrowserInfos()
Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:54
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:373
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:359
double m_iconsScale
Scaling factor for menus and tool icons.
Definition: pgm_base.h:362
int m_language_id
The current language setting.
Definition: pgm_base.h:356
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:169
VTBL_ENTRY void ConfigurePaths(wxWindow *aParent=NULL)
Function ConfigurePaths.
Definition: pgm_base.cpp:897
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:350
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:857
VTBL_ENTRY void MacOpenFile(const wxString &aFileName)=0
Function MacOpenFile is specific to MacOSX (not used under Linux or Windows).
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:270
VTBL_ENTRY void SetLanguageIdentifier(int menu_id)
Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id fro...
Definition: pgm_base.cpp:765
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:87
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:70
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:175
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:89
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:179
~ENV_VAR_ITEM()
Definition: pgm_base.h:67
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:367
bool GetUseIconsInMenus()
Definition: pgm_base.h:328
void SetIconsScale(double aValue)
Scaling factor for menus and tool icons.
Definition: pgm_base.h:324
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:781
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:673
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:347
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:876
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:41
void SetValue(const wxString &aValue)
Definition: pgm_base.h:76
wxSize m_help_size
Definition: pgm_base.h:379
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:145
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:396
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:377
wxString m_editor_name
Definition: pgm_base.h:378
bool m_useIconsInMenus
True to use menu icons.
Definition: pgm_base.h:364
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:88
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:336
VTBL_ENTRY void AddMenuLanguageList(wxMenu *MasterMenu)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Definition: pgm_base.cpp:816
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:61
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:187
bool GetDefinedExternally() const
Definition: pgm_base.h:69