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 <wx/filehistory.h>
37 #include <search_stack.h>
38 #include <wx/gdicmn.h>
39 
40 
43 
44 #define USE_ICONS_IN_MENUS_KEY wxT( "UseIconsInMenus" )
45 #define ICON_SCALE_KEY wxT( "IconScale" )
46 #define AUTOSAVE_INTERVAL_KEY wxT( "AutoSaveInterval" )
47 #define ENBL_ZOOM_NO_CENTER_KEY wxT( "ZoomNoCenter" )
48 #define ENBL_MOUSEWHEEL_PAN_KEY wxT( "MousewheelPAN" )
49 #define MIDDLE_BUTT_PAN_LIMITED_KEY wxT( "MiddleBtnPANLimited" )
50 #define ENBL_AUTO_PAN_KEY wxT( "AutoPAN" )
51 #define FILE_HISTORY_SIZE_KEY wxT( "FileHistorySize" )
52 #define GAL_DISPLAY_OPTIONS_KEY wxT( "GalDisplayOptions" )
53 #define GAL_ANTIALIASING_MODE_KEY wxT( "OpenGLAntialiasingMode" )
54 
56 
58 #define DEFAULT_FILE_HISTORY_SIZE 9
59 #define MAX_FILE_HISTORY_SIZE 99
60 
61 class wxConfigBase;
62 class wxSingleInstanceChecker;
63 class wxApp;
64 class wxMenu;
65 class wxWindow;
66 
67 class FILENAME_RESOLVER;
68 class EDA_DRAW_FRAME;
69 
70 
71 
73 {
74  ID_FILE = 4200,
77 };
78 
79 
80 class FILE_HISTORY : public wxFileHistory
81 {
82 public:
83  FILE_HISTORY( size_t aMaxFiles, int aBaseFileId );
84 
85  void SetMaxFiles( size_t aMaxFiles );
86 };
87 
88 
89 // inter program module calling
90 #define VTBL_ENTRY virtual
91 
92 
101 {
102 public:
103  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
104  m_value( aValue ),
105  m_isDefinedExternally( aIsDefinedExternally )
106  {
107  }
108 
109  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
110 
111  bool GetDefinedExternally() const { return m_isDefinedExternally; }
112  void SetDefinedExternally( bool aIsDefinedExternally )
113  {
114  m_isDefinedExternally = aIsDefinedExternally;
115  }
116 
117  const wxString& GetValue() const { return m_value; }
118  void SetValue( const wxString& aValue ) { m_value = aValue; }
119 
120 private:
122  wxString m_value;
123 
126 };
127 
128 
129 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
130 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
131 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
132 
133 
149 class PGM_BASE
150 {
151 public:
152  PGM_BASE();
153  virtual ~PGM_BASE();
154 
155 #if 0
156  /*
157 
158  Derived classes must implement these two functions: OnPgmInit() and
159  OnPgmExit(), and since they are only called from same source file as their
160  implementation, these need not be virtual here. In fact, in the case of
161  python project manager's class PGM_PYTHON, these functions are actually
162  written in python. In total there are three implementations, corresponding
163  to the three defines given by kiface.h's KFCTL_* #defines.
164 
165  */
166 
172  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
173 
174  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
175 #endif
176 
177  //----<Cross Module API>-----------------------------------------------------
178 
185  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
186 
187  VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
188 
189  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
190 
199  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
200 
208  VTBL_ENTRY const wxString AskUserForPreferredEditor(
209  const wxString& aDefaultEditor = wxEmptyString );
210 
211  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
212 
213  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
214 
215  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
216 
217  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
218 
219  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
220 
221  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
222 
230  {
231  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
232  }
233 
238  VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
239 
250  VTBL_ENTRY bool SetLanguage( bool first_time = false );
251 
259  VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
260 
269  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
270 
271  VTBL_ENTRY void SetLanguagePath();
272 
277  VTBL_ENTRY void ReadPdfBrowserInfos();
278 
283  VTBL_ENTRY void WritePdfBrowserInfos();
284 
299  VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
300 
310  VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
311 
313  {
314  return m_local_env_vars;
315  }
316 
322  VTBL_ENTRY wxApp& App();
323 
324  //----</Cross Module API>----------------------------------------------------
325 
326  static const wxChar workingDirKey[];
327 
339  bool InitPgm();
340 
341  // The PGM_* classes can have difficulties at termination if they
342  // are not destroyed soon enough. Relying on a static destructor can be
343  // too late for contained objects like wxSingleInstanceChecker.
344  void Destroy();
345 
350  void SaveCommonSettings();
351 
352 protected:
353 
358  void loadCommonSettings();
359 
361  wxSingleInstanceChecker* m_pgm_checker;
362 
365  wxConfigBase* m_common_settings;
366 
368  wxString m_bin_dir;
369 
371  wxString m_kicad_env;
372 
374  wxLocale* m_locale;
375 
378 
381 
383  void setLanguageId( int aId ) { m_language_id = aId; }
384 
390  bool setExecutablePath();
391 
393  wxString m_pdf_browser;
394  wxString m_editor_name;
395  wxSize m_help_size;
396 
399 
402 };
403 
404 
407 extern PGM_BASE& Pgm();
408 
409 #endif // PGM_BASE_H_
FILE_HISTORY(size_t aMaxFiles, int aBaseFileId)
Definition: pgm_base.cpp:72
bool m_isDefinedExternally
Flag to indicate if the environment variable was defined externally to the process.
Definition: pgm_base.h:125
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:398
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:213
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:215
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:149
const wxString & GetValue() const
Definition: pgm_base.h:117
#define VTBL_ENTRY
Definition: pgm_base.h:90
wxString m_value
The environment variable string value.
Definition: pgm_base.h:122
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:374
Class ENV_VAR_ITEM.
Definition: pgm_base.h:100
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:238
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:219
#define MAX_FILE_HISTORY_SIZE
Definition: pgm_base.h:59
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:401
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:361
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
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:380
int m_language_id
The current language setting.
Definition: pgm_base.h:377
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:211
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:371
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:312
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:129
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:112
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:217
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:131
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:221
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:383
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:368
void SetMaxFiles(size_t aMaxFiles)
Definition: pgm_base.cpp:79
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
void SetValue(const wxString &aValue)
Definition: pgm_base.h:118
wxSize m_help_size
Definition: pgm_base.h:395
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:187
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:393
wxString m_editor_name
Definition: pgm_base.h:394
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:130
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:103
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:229
bool GetDefinedExternally() const
Definition: pgm_base.h:111
FILE_HISTORY_IDS
Definition: pgm_base.h:72