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 <[email protected]>
6 * Copyright (C) 1992-2021 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 <vector>
36#include <memory>
37#include <search_stack.h>
39#include <wx/filename.h>
40
41#undef pid_t
42#include <pybind11/embed.h>
43
44class wxSingleInstanceChecker;
45class wxApp;
46class wxMenu;
47class wxWindow;
48
49class COMMON_SETTINGS;
51class SCRIPTING;
52
61{
64
67
69 wxString m_Lang_Label;
70
73};
74
75
80
95{
96public:
97 PGM_BASE();
98 virtual ~PGM_BASE();
99
100#if 0
101 /*
102
103 Derived classes must implement these two functions: OnPgmInit() and
104 OnPgmExit(), and since they are only called from same source file as their
105 implementation, these need not be virtual here. In fact, in the case of
106 python project manager's class PGM_PYTHON, these functions are actually
107 written in python. In total there are three implementations, corresponding
108 to the three defines given by kiface.h's KFCTL_* #defines.
109
110 */
111
117 virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
118
119 virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
120#endif
121
125 void BuildArgvUtf8();
126
133 virtual void MacOpenFile( const wxString& aFileName ) = 0;
134
136
137 virtual COMMON_SETTINGS* GetCommonSettings() const;
138
139 virtual void SetTextEditor( const wxString& aFileName );
140
150 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
151
159 virtual const wxString AskUserForPreferredEditor(
160 const wxString& aDefaultEditor = wxEmptyString );
161
162 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
163
164 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
165
166 virtual const wxString& GetExecutablePath() const { return m_bin_dir; }
167
168 virtual wxLocale* GetLocale() { return m_locale; }
169
170 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
171
172 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
173
179 virtual bool UseSystemPdfBrowser() const
180 {
181 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
182 }
183
187 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
188
199 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
200
207 bool SetDefaultLanguage( wxString& aErrMsg );
208
216 virtual void SetLanguageIdentifier( int menu_id );
217
221 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
222
223 virtual void SetLanguagePath();
224
228 virtual void ReadPdfBrowserInfos();
229
233 virtual void WritePdfBrowserInfos();
234
247 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
248
254 virtual void SetLocalEnvVariables();
255
256 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
257
263 virtual wxApp& App();
264
265 static const wxChar workingDirKey[];
266
282 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
283
284 // The PGM_* classes can have difficulties at termination if they
285 // are not destroyed soon enough. Relying on a static destructor can be
286 // too late for contained objects like wxSingleInstanceChecker.
287 void Destroy();
288
292 void SaveCommonSettings();
293
294#ifdef KICAD_USE_SENTRY
295 bool IsSentryOptedIn();
296 void SetSentryOptIn( bool aOptIn );
297 void ResetSentryId();
298 const wxString& GetSentryId();
299#endif
300
305
306 std::vector<void*> m_ModalDialogs;
307
309
310protected:
312 void loadCommonSettings();
313
315 void setLanguageId( int aId ) { m_language_id = aId; }
316
322 bool setExecutablePath();
323
324#ifdef KICAD_USE_SENTRY
325 void sentryInit();
326 void sentryPrompt();
327 wxString sentryCreateUid();
328#endif
329
330protected:
331 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
332
333 std::unique_ptr<SCRIPTING> m_python_scripting;
334
335 wxString m_bin_dir;
336 wxString m_kicad_env;
337
338 wxLocale* m_locale;
340
342 wxString m_pdf_browser;
343
345
346#ifdef KICAD_USE_SENTRY
347 wxFileName m_sentry_optin_fn;
348 wxFileName m_sentry_uid_fn;
349 wxString m_sentryUid;
350#endif
351
352 char** m_argvUtf8;
354
356};
357
358
361extern PGM_BASE& Pgm();
362
365extern PGM_BASE* PgmOrNull();
366
367
368#endif // PGM_BASE_H_
Container for data for KiCad programs.
Definition: pgm_base.h:95
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:615
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:163
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:355
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:836
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:537
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:304
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:315
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
wxString m_bin_dir
Definition: pgm_base.h:335
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:331
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:579
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:172
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:338
void Destroy()
Definition: pgm_base.cpp:151
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition: pgm_base.cpp:398
virtual const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:164
char ** m_argvUtf8
Definition: pgm_base.h:352
virtual bool UseSystemPdfBrowser() const
Definition: pgm_base.h:179
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:37
bool m_use_system_pdf_browser
Definition: pgm_base.h:341
bool m_Quitting
Definition: pgm_base.h:308
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition: pgm_base.cpp:383
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:170
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:170
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:166
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:221
wxString m_pdf_browser
Definition: pgm_base.h:342
std::vector< void * > m_ModalDialogs
Definition: pgm_base.h:306
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:792
wxString m_kicad_env
full path to this program
Definition: pgm_base.h:336
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:187
virtual void SetLocalEnvVariables()
Updates the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTI...
Definition: pgm_base.cpp:821
virtual void SetLanguagePath()
Definition: pgm_base.cpp:778
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:721
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:344
virtual ~PGM_BASE()
Definition: pgm_base.cpp:138
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:333
virtual void SetLanguageIdentifier(int menu_id)
Set in .m_language_id member the wxWidgets language identifier ID from the KiCad menu id (internal me...
Definition: pgm_base.cpp:762
int m_language_id
Definition: pgm_base.h:339
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:177
virtual wxLocale * GetLocale()
Definition: pgm_base.h:168
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:135
virtual bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:162
virtual void WritePdfBrowserInfos()
Save the PDF browser choice to the common configuration.
Definition: eda_doc.cpp:44
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:606
static const wxChar workingDirKey[]
Definition: pgm_base.h:265
virtual const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:213
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:621
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: single_top.cpp:111
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:125
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:85
A small class to handle the list of existing translations.
Definition: pgm_base.h:61
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:66
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:72
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:69
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:63