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 AUTOSAVE_INTERVAL_KEY wxT( "AutoSaveInterval" )
48 #define ENBL_ZOOM_NO_CENTER_KEY wxT( "ZoomNoCenter" )
49 #define ENBL_MOUSEWHEEL_PAN_KEY wxT( "MousewheelPAN" )
50 #define MIDDLE_BUTT_PAN_LIMITED_KEY wxT( "MiddleBtnPANLimited" )
51 #define ENBL_AUTO_PAN_KEY wxT( "AutoPAN" )
52 #define FILE_HISTORY_SIZE_KEY wxT( "FileHistorySize" )
53 #define GAL_DISPLAY_OPTIONS_KEY wxT( "GalDisplayOptions" )
54 #define GAL_ANTIALIASING_MODE_KEY wxT( "OpenGLAntialiasingMode" )
55 #define CAIRO_ANTIALIASING_MODE_KEY wxT( "CairoAntialiasingMode" )
56 
58 
60 #define DEFAULT_FILE_HISTORY_SIZE 9
61 #define MAX_FILE_HISTORY_SIZE 99
62 
63 class wxConfigBase;
64 class wxSingleInstanceChecker;
65 class wxApp;
66 class wxMenu;
67 class wxWindow;
68 
69 class FILENAME_RESOLVER;
70 class EDA_DRAW_FRAME;
71 
72 
73 
75 {
76  ID_FILE = 4200,
79 };
80 
81 
82 class FILE_HISTORY : public wxFileHistory
83 {
84 public:
85  FILE_HISTORY( size_t aMaxFiles, int aBaseFileId );
86 
87  void SetMaxFiles( size_t aMaxFiles );
88 };
89 
90 
91 // inter program module calling
92 #define VTBL_ENTRY virtual
93 
94 
103 {
104 public:
105  ENV_VAR_ITEM( const wxString& aValue = wxEmptyString, bool aIsDefinedExternally = false ) :
106  m_value( aValue ),
107  m_isDefinedExternally( aIsDefinedExternally )
108  {
109  }
110 
111  ~ENV_VAR_ITEM() throw() {} // tell SWIG no exception
112 
113  bool GetDefinedExternally() const { return m_isDefinedExternally; }
114  void SetDefinedExternally( bool aIsDefinedExternally )
115  {
116  m_isDefinedExternally = aIsDefinedExternally;
117  }
118 
119  const wxString& GetValue() const { return m_value; }
120  void SetValue( const wxString& aValue ) { m_value = aValue; }
121 
122 private:
124  wxString m_value;
125 
128 };
129 
130 
131 typedef std::map<wxString, ENV_VAR_ITEM> ENV_VAR_MAP;
132 typedef std::map<wxString, ENV_VAR_ITEM>::iterator ENV_VAR_MAP_ITER;
133 typedef std::map<wxString, ENV_VAR_ITEM>::const_iterator ENV_VAR_MAP_CITER;
134 
135 
151 class PGM_BASE
152 {
153 public:
154  PGM_BASE();
155  virtual ~PGM_BASE();
156 
157 #if 0
158  /*
159 
160  Derived classes must implement these two functions: OnPgmInit() and
161  OnPgmExit(), and since they are only called from same source file as their
162  implementation, these need not be virtual here. In fact, in the case of
163  python project manager's class PGM_PYTHON, these functions are actually
164  written in python. In total there are three implementations, corresponding
165  to the three defines given by kiface.h's KFCTL_* #defines.
166 
167  */
168 
174  virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
175 
176  virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
177 #endif
178 
179  //----<Cross Module API>-----------------------------------------------------
180 
187  VTBL_ENTRY void MacOpenFile( const wxString& aFileName ) = 0;
188 
189  VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings.get(); }
190 
191  VTBL_ENTRY void SetEditorName( const wxString& aFileName );
192 
201  VTBL_ENTRY const wxString& GetEditorName( bool aCanShowFileChooser = true );
202 
210  VTBL_ENTRY const wxString AskUserForPreferredEditor(
211  const wxString& aDefaultEditor = wxEmptyString );
212 
213  VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
214 
215  VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
216 
217  VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
218 
219  VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
220 
221  VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
222 
223  VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
224 
232  {
233  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
234  }
235 
240  VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
241 
252  VTBL_ENTRY bool SetLanguage( bool first_time = false );
253 
261  VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
262 
271  VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
272 
273  VTBL_ENTRY void SetLanguagePath();
274 
279  VTBL_ENTRY void ReadPdfBrowserInfos();
280 
285  VTBL_ENTRY void WritePdfBrowserInfos();
286 
301  VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
302 
312  VTBL_ENTRY void SetLocalEnvVariables( const ENV_VAR_MAP& aEnvVarMap );
313 
315  {
316  return m_local_env_vars;
317  }
318 
324  VTBL_ENTRY wxApp& App();
325 
326  //----</Cross Module API>----------------------------------------------------
327 
328  static const wxChar workingDirKey[];
329 
341  bool InitPgm();
342 
343  // The PGM_* classes can have difficulties at termination if they
344  // are not destroyed soon enough. Relying on a static destructor can be
345  // too late for contained objects like wxSingleInstanceChecker.
346  void Destroy();
347 
352  void SaveCommonSettings();
353 
354 protected:
355 
360  void loadCommonSettings();
361 
363  wxSingleInstanceChecker* m_pgm_checker;
364 
367  std::unique_ptr<wxConfigBase> m_common_settings;
368 
370  wxString m_bin_dir;
371 
373  wxString m_kicad_env;
374 
376  wxLocale* m_locale;
377 
380 
383 
385  void setLanguageId( int aId ) { m_language_id = aId; }
386 
392  bool setExecutablePath();
393 
395  wxString m_pdf_browser;
396  wxString m_editor_name;
397  wxSize m_help_size;
398 
401 
404 };
405 
406 
409 extern PGM_BASE& Pgm();
410 
411 #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:127
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:400
VTBL_ENTRY const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:215
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:367
VTBL_ENTRY const wxString & GetExecutablePath() const
Definition: pgm_base.h:217
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:151
const wxString & GetValue() const
Definition: pgm_base.h:119
#define VTBL_ENTRY
Definition: pgm_base.h:92
wxString m_value
The environment variable string value.
Definition: pgm_base.h:124
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:376
Class ENV_VAR_ITEM.
Definition: pgm_base.h:102
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:240
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:221
#define MAX_FILE_HISTORY_SIZE
Definition: pgm_base.h:61
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:403
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:363
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:382
int m_language_id
The current language setting.
Definition: pgm_base.h:379
VTBL_ENTRY bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:213
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:373
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:314
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:131
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:114
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:219
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:133
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:223
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:385
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:370
void SetMaxFiles(size_t aMaxFiles)
Definition: pgm_base.cpp:79
void SetValue(const wxString &aValue)
Definition: pgm_base.h:120
wxSize m_help_size
Definition: pgm_base.h:397
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:189
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:395
wxString m_editor_name
Definition: pgm_base.h:396
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:132
ENV_VAR_ITEM(const wxString &aValue=wxEmptyString, bool aIsDefinedExternally=false)
Definition: pgm_base.h:105
VTBL_ENTRY bool UseSystemPdfBrowser() const
Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and ...
Definition: pgm_base.h:231
bool GetDefinedExternally() const
Definition: pgm_base.h:113
FILE_HISTORY_IDS
Definition: pgm_base.h:74