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 <bitmaps_png/bitmap_def.h>
35 #include <map>
36 #include <memory>
37 #include <search_stack.h>
38 #include <wx/filename.h>
39 #include <wx/gdicmn.h>
40 
41 
42 class wxSingleInstanceChecker;
43 class wxApp;
44 class wxMenu;
45 class wxWindow;
46 
47 class COMMON_SETTINGS;
48 class SETTINGS_MANAGER;
49 
58 {
61 
64 
66  wxString m_Lang_Label;
67 
70 };
71 
76 
77 // inter program module calling
78 #define VTBL_ENTRY virtual
79 
80 
89 {
90 public:
91  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
92  m_value( aValue ),
93  m_isDefinedExternally( aIsDefinedExternally )
94  {
95  }
96 
97  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
98 
100  void SetDefinedExternally( bool aIsDefinedExternally )
101  {
102  m_isDefinedExternally = aIsDefinedExternally;
103  }
104 
105  const wxString& GetValue() const { return m_value; }
106  void SetValue( const wxString& aValue ) { m_value = aValue; }
107 
108 private:
110  wxString m_value;
111 
114 };
115 
116 
117 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
118 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
119 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
120 
121 
137 class PGM_BASE
138 {
139 public:
140  PGM_BASE();
141  virtual ~PGM_BASE();
142 
143 #if 0
144  /*
145 
146  Derived classes must implement these two functions: OnPgmInit() and
147  OnPgmExit(), and since they are only called from same source file as their
148  implementation, these need not be virtual here. In fact, in the case of
149  python project manager's class PGM_PYTHON, these functions are actually
150  written in python. In total there are three implementations, corresponding
151  to the three defines given by kiface.h's KFCTL_* #defines.
152 
153  */
154 
160  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
161 
162  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
163 #endif
164 
165  //----<Cross Module API>-----------------------------------------------------
166 
173  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
174 
176 
178 
179  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
180 
189  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
190 
198  VTBL_ENTRY const wxString AskUserForPreferredEditor(
199  const wxString& aDefaultEditor = wxEmptyString );
200 
201  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
202 
203  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
204 
205  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
206 
207  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
208 
209  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
210 
211  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
212 
220  {
221  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
222  }
223 
229 
240  VTBL_ENTRY bool SetLanguage( wxString& aErrMsg, bool first_time = false );
241 
250  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
251 
256 
258 
264 
270 
285  VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
286 
296  VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
297 
299  {
300  return m_local_env_vars;
301  }
302 
308  VTBL_ENTRY wxApp& App();
309 
310  //----</Cross Module API>----------------------------------------------------
311 
312  static const wxChar workingDirKey[];
313 
325  bool InitPgm();
326 
327  // The PGM_* classes can have difficulties at termination if they
328  // are not destroyed soon enough. Relying on a static destructor can be
329  // too late for contained objects like wxSingleInstanceChecker.
330  void Destroy();
331 
336  void SaveCommonSettings();
337 
342 
343 protected:
344 
346  void loadCommonSettings();
347 
348  std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
349 
351  wxSingleInstanceChecker* m_pgm_checker;
352 
354  wxString m_bin_dir;
355 
357  wxString m_kicad_env;
358 
360  wxLocale* m_locale;
361 
364 
367 
369  void setLanguageId( int aId ) { m_language_id = aId; }
370 
376  bool setExecutablePath();
377 
379  wxString m_pdf_browser;
380  wxString m_editor_name;
381  wxSize m_help_size;
382 
385 
388 };
389 
390 
393 extern PGM_BASE& Pgm();
394 
397 extern PGM_BASE* PgmOrNull();
398 
399 
400 #endif // PGM_BASE_H_
PGM_BASE()
Definition: pgm_base.cpp:98
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:553
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:481
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:136
virtual ~PGM_BASE()
Definition: pgm_base.cpp:112
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
Definition: pgm_base.h:113
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:512
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
#define VTBL_ENTRY
Definition: pgm_base.h:78
wxString m_value
The environment variable string value.
Definition: pgm_base.h:110
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
ENV_VAR_ITEM.
Definition: pgm_base.h:88
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:228
const wxString & GetValue() const
Definition: pgm_base.h:105
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:129
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
void Destroy()
Definition: pgm_base.cpp:118
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:439
A small class to handle the list of existing translations.
Definition: pgm_base.h:57
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:69
VTBL_ENTRY void WritePdfBrowserInfos()
Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:49
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:181
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:366
int m_language_id
The current language setting.
Definition: pgm_base.h:363
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:348
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:357
static const wxChar workingDirKey[]
Definition: pgm_base.h:312
bool GetDefinedExternally() const
Definition: pgm_base.h:99
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:716
VTBL_ENTRY void MacOpenFile(const wxString &aFileName)=0
Function MacOpenFile is specific to MacOSX (not used under Linux or Windows).
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:665
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:117
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:100
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
VTBL_ENTRY int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:255
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:207
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: single_top.cpp:102
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:119
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:211
~ENV_VAR_ITEM()
Definition: pgm_base.h:97
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:209
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:369
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:60
VTBL_ENTRY bool SetLanguage(wxString &aErrMsg, bool first_time=false)
sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:559
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:66
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:298
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:203
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:681
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:201
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:737
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
bool m_Printing
wxWidgets on MSW tends to crash if you spool up more than one print job at a time.
Definition: pgm_base.h:341
void SetValue(const wxString &aValue)
Definition: pgm_base.h:106
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:205
wxSize m_help_size
Definition: pgm_base.h:381
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:204
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:379
wxString m_editor_name
Definition: pgm_base.h:380
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:118
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:144
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:91
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:71
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:219