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 <wx/filehistory.h>
38 #include <search_stack.h>
39 #include <wx/gdicmn.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 
59 
61 #define DEFAULT_FILE_HISTORY_SIZE 9
62 #define MAX_FILE_HISTORY_SIZE 99
63 
64 class wxConfigBase;
65 class wxSingleInstanceChecker;
66 class wxApp;
67 class wxMenu;
68 class wxWindow;
69 
70 class FILENAME_RESOLVER;
71 class EDA_DRAW_FRAME;
72 
73 
74 
76 {
77  ID_FILE = 4200,
80 };
81 
82 
83 class FILE_HISTORY : public wxFileHistory
84 {
85 public:
86  FILE_HISTORY( size_t aMaxFiles, int aBaseFileId );
87 
88  void SetMaxFiles( size_t aMaxFiles );
89 };
90 
91 
92 // inter program module calling
93 #define VTBL_ENTRY virtual
94 
95 
104 {
105 public:
106  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
107  m_value( aValue ),
108  m_isDefinedExternally( aIsDefinedExternally )
109  {
110  }
111 
112  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
113 
115  void SetDefinedExternally( bool aIsDefinedExternally )
116  {
117  m_isDefinedExternally = aIsDefinedExternally;
118  }
119 
120  const wxString& GetValue() const { return m_value; }
121  void SetValue( const wxString& aValue ) { m_value = aValue; }
122 
123 private:
125  wxString m_value;
126 
129 };
130 
131 
132 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
133 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
134 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
135 
136 
152 class PGM_BASE
153 {
154 public:
155  PGM_BASE();
156  virtual ~PGM_BASE();
157 
158 #if 0
159  /*
160 
161  Derived classes must implement these two functions: OnPgmInit() and
162  OnPgmExit(), and since they are only called from same source file as their
163  implementation, these need not be virtual here. In fact, in the case of
164  python project manager's class PGM_PYTHON, these functions are actually
165  written in python. In total there are three implementations, corresponding
166  to the three defines given by kiface.h's KFCTL_* #defines.
167 
168  */
169 
175  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
176 
177  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
178 #endif
179 
180  //----<Cross Module API>-----------------------------------------------------
181 
188  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
189 
190  VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings.get(); }
191 
192  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
193 
202  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
203 
211  VTBL_ENTRY const wxString AskUserForPreferredEditor(
212  const wxString& aDefaultEditor = wxEmptyString );
213 
214  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
215 
216  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
217 
218  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
219 
220  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
221 
222  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
223 
224  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
225 
233  {
234  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
235  }
236 
242 
253  VTBL_ENTRY bool SetLanguage( bool first_time = false );
254 
262  VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
263 
272  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
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 
355 protected:
356 
361  void loadCommonSettings();
362 
364  wxSingleInstanceChecker* m_pgm_checker;
365 
368  std::unique_ptr<wxConfigBase> m_common_settings;
369 
371  wxString m_bin_dir;
372 
374  wxString m_kicad_env;
375 
377  wxLocale* m_locale;
378 
381 
384 
386  void setLanguageId( int aId ) { m_language_id = aId; }
387 
393  bool setExecutablePath();
394 
396  wxString m_pdf_browser;
397  wxString m_editor_name;
398  wxSize m_help_size;
399 
402 
405 };
406 
407 
410 extern PGM_BASE& Pgm();
411 
412 #endif // PGM_BASE_H_
FILE_HISTORY(size_t aMaxFiles, int aBaseFileId)
Definition: pgm_base.cpp:72
void loadCommonSettings()
Function loadCommonSettings loads the program (process) settings subset which are stored in ....
Definition: pgm_base.cpp:535
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:192
virtual ~PGM_BASE()
Definition: pgm_base.cpp:166
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
Definition: pgm_base.h:128
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:401
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:643
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:368
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:152
#define VTBL_ENTRY
Definition: pgm_base.h:93
wxString m_value
The environment variable string value.
Definition: pgm_base.h:125
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:377
Class ENV_VAR_ITEM.
Definition: pgm_base.h:103
static const wxChar workingDirKey[]
Definition: pgm_base.h:329
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:241
const wxString & GetValue() const
Definition: pgm_base.h:120
#define MAX_FILE_HISTORY_SIZE
Definition: pgm_base.h:62
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:185
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:404
void Destroy()
Definition: pgm_base.cpp:172
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:493
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:364
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:237
The base class for create windows for drawing purpose.
Definition: draw_frame.h:82
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:383
int m_language_id
The current language setting.
Definition: pgm_base.h:380
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:374
bool GetDefinedExternally() const
Definition: pgm_base.h:114
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:856
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:764
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:132
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:115
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:220
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:134
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:224
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:222
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:386
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:315
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:190
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:216
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:780
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:672
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:371
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:214
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:875
void SetMaxFiles(size_t aMaxFiles)
Definition: pgm_base.cpp:79
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
void SetValue(const wxString &aValue)
Definition: pgm_base.h:121
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:218
wxSize m_help_size
Definition: pgm_base.h:398
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:260
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:396
wxString m_editor_name
Definition: pgm_base.h:397
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:133
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:200
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:815
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:106
FILE_HISTORY_IDS
Definition: pgm_base.h:75
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:232