2
* This program source code file is part of KiCad, a free EDA CAD application.
4
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
6
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
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.
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.
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
28
* @brief see class PGM_BASE
34
#include <wx/filename.h>
35
#include <search_stack.h>
36
#include <wx/gdicmn.h>
40
class wxSingleInstanceChecker;
41
class wxHtmlHelpController;
45
// inter program module calling
46
#define VTBL_ENTRY virtual
51
* keeps program (whole process) data for KiCad programs.
52
* The VTBL_ENTRY functions are VTBL_ENTRY so we can do cross module calls
53
* without linking to them. This used to be a wxApp derivative, but that
54
* is difficult under wxPython which shapes the wxApp. So now this is a "side-car"
55
* (like a motorcycle side-car) object with a back pointer into the wxApp
56
* which initializes it.
58
* OnPgmStart() is virtual, may be overridden, and parallels
59
* wxApp::OnInit(), from where it should called.
61
* OnPgmEnd() is virtual, may be overridden, and parallels wxApp::OnExit(),
62
* from where it should be called.
72
* this is the first executed function (like main() )
73
* @return true if the application can be started.
75
virtual bool OnPgmInit( wxApp* aWxApp ) = 0; // call this from wxApp::OnInit()
77
virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
80
* Function MacOpenFile
81
* is specific to MacOSX (not used under Linux or Windows).
82
* MacOSX requires it for file association.
83
* @see http://wiki.wxwidgets.org/WxMac-specific_topics
85
virtual void MacOpenFile( const wxString& aFileName ) = 0;
87
//----<Cross Module API>-----------------------------------------------------
89
VTBL_ENTRY wxHtmlHelpController* GetHtmlHelpController() { return m_html_ctrl; }
91
VTBL_ENTRY void SetHtmlHelpController( wxHtmlHelpController* aController );
93
VTBL_ENTRY wxConfigBase* CommonSettings() const { return m_common_settings; }
95
VTBL_ENTRY void SetEditorName( const wxString& aFileName );
98
* Return the preferred editor name.
100
VTBL_ENTRY const wxString& GetEditorName();
102
VTBL_ENTRY bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
104
VTBL_ENTRY const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
106
VTBL_ENTRY const wxString& GetExecutablePath() const { return m_bin_dir; }
108
VTBL_ENTRY wxLocale* GetLocale() { return m_locale; }
110
VTBL_ENTRY const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
112
VTBL_ENTRY void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
115
* Function UseSystemPdfBrowser
116
* returns true if the PDF browser is the default (system) PDF browser
117
* and false if the PDF browser is the prefered (selected) browser, else
118
* returns false if there is no selected browser
120
VTBL_ENTRY bool UseSystemPdfBrowser() const
122
return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
126
* Function ForceSystemPdfBrowser
127
* forces the use of system PDF browser, even if a preferend PDF browser is set.
129
VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
132
* Function SetLanguage
133
* sets the dictionary file name for internationalization.
135
* The files are in kicad/internat/xx or kicad/internat/xx_XX and are named kicad.mo
137
* @param first_time must be set to true the first time this funct is
138
* called, false otherwise
139
* @return true if the language can be set (i.e. if the locale is available)
141
VTBL_ENTRY bool SetLanguage( bool first_time = false );
144
* Function AddMenuLanguageList
145
* creates a menu list for language choice, and add it as submenu to \a MasterMenu.
147
* @param MasterMenu The main menu. The sub menu list will be accessible from the menu
148
* item with id ID_LANGUAGE_CHOICE
150
VTBL_ENTRY void AddMenuLanguageList( wxMenu* MasterMenu );
153
* Function SetLanguageIdentifier
154
* sets in .m_language_id member the wxWidgets language identifier Id from
155
* the KiCad menu id (internal menu identifier).
157
* @param menu_id The KiCad menuitem id (returned by Menu Event, when
158
* clicking on a menu item)
160
VTBL_ENTRY void SetLanguageIdentifier( int menu_id );
162
VTBL_ENTRY void SetLanguagePath();
165
* Function InitOnLineHelp
166
* initializes KiCad's online help.
168
VTBL_ENTRY void InitOnLineHelp();
171
* Function ReadPdfBrowserInfos
172
* reads the PDF browser choice from the common configuration.
174
VTBL_ENTRY void ReadPdfBrowserInfos();
177
* Function WritePdfBrowserInfos
178
* saves the PDF browser choice to the common configuration.
180
VTBL_ENTRY void WritePdfBrowserInfos();
184
* marks a file as being in use.
185
* @param aFileName = full path to the file.
186
* @return false if the file was already locked, true otherwise.
188
VTBL_ENTRY bool LockFile( const wxString& aFileName );
192
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
193
* Use this function instead of wxGetApp().
195
VTBL_ENTRY wxApp& App()
197
wxASSERT( m_wx_app );
201
//----</Cross Module API>----------------------------------------------------
203
static const wxChar workingDirKey[];
209
* initializes this program (process) in a KiCad standard way,
210
* using some generalized techniques.
211
* - Default paths (help, libs, bin) and configuration file names
212
* - Language and locale
215
* But nothing relating to DSOs or projects.
216
* @return bool - true if success, false if failure and program is to terminate.
221
* Function loadCommonSettings
222
* loads the program (process) settings subset which are stored in .kicad_common
224
void loadCommonSettings();
227
* Function saveCommonSettings
228
* saves the program (process) settings subset which are stored .kicad_common
230
void saveCommonSettings();
232
/// prevents multiple instances of a program from being run at the same time.
233
wxSingleInstanceChecker* m_pgm_checker;
235
/// prevents opening the same file multiple times.
236
wxSingleInstanceChecker* m_file_checker;
238
/// Configuration settings common to all KiCad program modules,
239
/// like as in $HOME/.kicad_common
240
wxConfigBase* m_common_settings;
242
/// full path to this program
245
/// The KICAD system environment variable.
246
wxString m_kicad_env;
248
/// The current locale.
251
/// The current language setting.
254
/// true to use the selected PDF browser, if exists, or false to use the default
255
bool m_use_system_pdf_browser;
257
/// Trap all changes in here, simplifies debugging
258
void setLanguageId( int aId ) { m_language_id = aId; }
261
* Function setExecutablePath
262
* finds the path to the executable and stores it in PGM_BASE::m_bin_dir
263
* @return bool - true if success, else false.
265
bool setExecutablePath();
267
/// The file name of the the program selected for browsing pdf files.
268
wxString m_pdf_browser;
269
wxString m_editor_name;
272
wxHtmlHelpController* m_html_ctrl;
276
// The PGM_* classes can have difficulties at termination if they
277
// are not destroyed soon enough. Relying on a static destructor can be
278
// too late for contained objects like wxSingleInstanceChecker.
283
#if !defined(PGM_KICAD_H_) // PGM_KICAD has an alternate
284
/// The global Program "get" accessor.
285
extern PGM_BASE& Pgm();
288
#endif // PGM_BASE_H_