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 <memory>
36 #include <wx/filename.h>
37 #include <search_stack.h>
38 #include <wx/gdicmn.h>
39 #include <bitmaps_png/bitmap_def.h>
40 
41 
44 
45 #define USE_ICONS_IN_MENUS_KEY wxT( "UseIconsInMenus" )
46 #define ICON_SCALE_KEY wxT( "IconScale" )
47 #define CANVAS_SCALE_KEY wxT( "CanvasScale" )
48 #define AUTOSAVE_INTERVAL_KEY wxT( "AutoSaveInterval" )
49 #define ENBL_ZOOM_NO_CENTER_KEY wxT( "ZoomNoCenter" )
50 #define ENBL_MOUSEWHEEL_PAN_KEY wxT( "MousewheelPAN" )
51 #define MIDDLE_BUTT_PAN_LIMITED_KEY wxT( "MiddleBtnPANLimited" )
52 #define ENBL_AUTO_PAN_KEY wxT( "AutoPAN" )
53 #define FILE_HISTORY_SIZE_KEY wxT( "FileHistorySize" )
54 #define GAL_DISPLAY_OPTIONS_KEY wxT( "GalDisplayOptions" )
55 #define GAL_ANTIALIASING_MODE_KEY wxT( "OpenGLAntialiasingMode" )
56 #define CAIRO_ANTIALIASING_MODE_KEY wxT( "CairoAntialiasingMode" )
57 #define WARP_MOUSE_ON_MOVE_KEY wxT( "MoveWarpsCursor" )
58 #define IMMEDIATE_ACTIONS_KEY wxT( "ImmediateActions" )
59 #define PREFER_SELECT_TO_DRAG_KEY wxT( "PreferSelectionToDragging" )
60 
62 
63 class wxConfigBase;
64 class wxSingleInstanceChecker;
65 class wxApp;
66 class wxMenu;
67 class wxWindow;
68 
78 {
81 
84 
87 
89  wxString m_Lang_Label;
90 
93 };
94 
95 
96 // inter program module calling
97 #define VTBL_ENTRY virtual
98 
99 
108 {
109 public:
110  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
111  m_value( aValue ),
112  m_isDefinedExternally( aIsDefinedExternally )
113  {
114  }
115 
116  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
117 
119  void SetDefinedExternally( bool aIsDefinedExternally )
120  {
121  m_isDefinedExternally = aIsDefinedExternally;
122  }
123 
124  const wxString& GetValue() const { return m_value; }
125  void SetValue( const wxString& aValue ) { m_value = aValue; }
126 
127 private:
129  wxString m_value;
130 
133 };
134 
135 
136 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
137 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
138 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
139 
140 
156 class PGM_BASE
157 {
158 public:
159  PGM_BASE();
160  virtual ~PGM_BASE();
161 
162 #if 0
163  /*
164 
165  Derived classes must implement these two functions: OnPgmInit() and
166  OnPgmExit(), and since they are only called from same source file as their
167  implementation, these need not be virtual here. In fact, in the case of
168  python project manager's class PGM_PYTHON, these functions are actually
169  written in python. In total there are three implementations, corresponding
170  to the three defines given by kiface.h's KFCTL_* #defines.
171 
172  */
173 
179  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
180 
181  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
182 #endif
183 
184  //----<Cross Module API>-----------------------------------------------------
185 
192  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
193 
194  VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings.get(); }
195 
196  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
197 
206  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
207 
215  VTBL_ENTRY const wxString AskUserForPreferredEditor(
216  const wxString& aDefaultEditor = wxEmptyString );
217 
218  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
219 
220  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
221 
222  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
223 
224  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
225 
226  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
227 
228  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
229 
237  {
238  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
239  }
240 
246 
257  VTBL_ENTRY bool SetLanguage( bool first_time = false );
258 
267  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
268 
273 
275 
281 
287 
302  VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
303 
313  VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
314 
316  {
317  return m_local_env_vars;
318  }
319 
325  VTBL_ENTRY wxApp& App();
326 
327  //----</Cross Module API>----------------------------------------------------
328 
329  static const wxChar workingDirKey[];
330 
342  bool InitPgm();
343 
344  // The PGM_* classes can have difficulties at termination if they
345  // are not destroyed soon enough. Relying on a static destructor can be
346  // too late for contained objects like wxSingleInstanceChecker.
347  void Destroy();
348 
353  void SaveCommonSettings();
354 
359 
360 protected:
361 
366  void loadCommonSettings();
367 
369  wxSingleInstanceChecker* m_pgm_checker;
370 
373  std::unique_ptr<wxConfigBase> m_common_settings;
374 
376  wxString m_bin_dir;
377 
379  wxString m_kicad_env;
380 
382  wxLocale* m_locale;
383 
386 
389 
391  void setLanguageId( int aId ) { m_language_id = aId; }
392 
398  bool setExecutablePath();
399 
401  wxString m_pdf_browser;
402  wxString m_editor_name;
403  wxSize m_help_size;
404 
407 
410 };
411 
412 
415 extern PGM_BASE& Pgm();
416 
419 extern PGM_BASE* PgmOrNull();
420 
421 
422 #endif // PGM_BASE_H_
void loadCommonSettings()
Function loadCommonSettings loads the program (process) settings subset which are stored in ....
Definition: pgm_base.cpp:496
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:153
virtual ~PGM_BASE()
Definition: pgm_base.cpp:127
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
Definition: pgm_base.h:132
PNG memory record (file in memory).
Definition: bitmap_def.h:29
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:604
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:156
#define VTBL_ENTRY
Definition: pgm_base.h:97
wxString m_value
The environment variable string value.
Definition: pgm_base.h:129
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:382
ENV_VAR_ITEM.
Definition: pgm_base.h:107
static const wxChar workingDirKey[]
Definition: pgm_base.h:329
BITMAP_DEF m_Lang_Icon
The menu language icons.
Definition: pgm_base.h:86
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:245
const wxString & GetValue() const
Definition: pgm_base.h:124
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:83
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:146
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:409
void Destroy()
Definition: pgm_base.cpp:133
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:454
A small class to handle the list of existing translations.
Definition: pgm_base.h:77
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:369
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:92
VTBL_ENTRY void WritePdfBrowserInfos()
Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:55
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:198
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:388
int m_language_id
The current language setting.
Definition: pgm_base.h:385
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:379
bool GetDefinedExternally() const
Definition: pgm_base.h:118
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:776
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:725
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:136
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:119
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:272
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:224
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: single_top.cpp:98
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:138
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:228
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:226
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:391
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:80
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:89
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:315
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:194
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:220
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:741
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:633
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:376
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:218
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:795
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:358
void SetValue(const wxString &aValue)
Definition: pgm_base.h:125
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:222
wxSize m_help_size
Definition: pgm_base.h:403
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:221
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:401
wxString m_editor_name
Definition: pgm_base.h:402
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:137
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:161
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:110
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:236