KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <exception>
35#include <map>
36#include <vector>
37#include <memory>
38#include <search_stack.h>
40#include <wx/filename.h>
41
42#undef pid_t
43#include <pybind11/embed.h>
44
45class wxSingleInstanceChecker;
46class wxApp;
47class wxMenu;
48class wxWindow;
49
50class COMMON_SETTINGS;
52class SCRIPTING;
53
62{
65
68
70 wxString m_Lang_Label;
71
74};
75
76
81
96{
97public:
98 PGM_BASE();
99 virtual ~PGM_BASE();
100
101#if 0
102 /*
103
104 Derived classes must implement these two functions: OnPgmInit() and
105 OnPgmExit(), and since they are only called from same source file as their
106 implementation, these need not be virtual here. In fact, in the case of
107 python project manager's class PGM_PYTHON, these functions are actually
108 written in python. In total there are three implementations, corresponding
109 to the three defines given by kiface.h's KFCTL_* #defines.
110
111 */
112
118 virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
119
120 virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
121#endif
122
126 void BuildArgvUtf8();
127
134 virtual void MacOpenFile( const wxString& aFileName ) = 0;
135
137
138 virtual COMMON_SETTINGS* GetCommonSettings() const;
139
140 virtual void SetTextEditor( const wxString& aFileName );
141
151 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
152
160 virtual const wxString AskUserForPreferredEditor(
161 const wxString& aDefaultEditor = wxEmptyString );
162
163 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
164
165 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
166
167 virtual const wxString& GetExecutablePath() const { return m_bin_dir; }
168
169 virtual wxLocale* GetLocale() { return m_locale; }
170
171 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
172
173 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
174
180 virtual bool UseSystemPdfBrowser() const
181 {
182 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
183 }
184
188 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
189
200 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
201
208 bool SetDefaultLanguage( wxString& aErrMsg );
209
217 virtual void SetLanguageIdentifier( int menu_id );
218
222 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
223
227 virtual wxString GetLanguageTag();
228
229 virtual void SetLanguagePath();
230
234 virtual void ReadPdfBrowserInfos();
235
239 virtual void WritePdfBrowserInfos();
240
253 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
254
260 virtual void SetLocalEnvVariables();
261
262 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
263
269 virtual wxApp& App();
270
271 static const wxChar workingDirKey[];
272
288 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
289
290 // The PGM_* classes can have difficulties at termination if they
291 // are not destroyed soon enough. Relying on a static destructor can be
292 // too late for contained objects like wxSingleInstanceChecker.
293 void Destroy();
294
298 void SaveCommonSettings();
299
300#ifdef KICAD_USE_SENTRY
304 bool IsSentryOptedIn();
305
312 void SetSentryOptIn( bool aOptIn );
313
317 void ResetSentryId();
318
322 const wxString& GetSentryId();
323#endif
324
332 void HandleException( std::exception_ptr aPtr );
333
339 bool IsGUI();
340
345
346 std::vector<void*> m_ModalDialogs;
347
349
350protected:
352 void loadCommonSettings();
353
355 void setLanguageId( int aId ) { m_language_id = aId; }
356
362 bool setExecutablePath();
363
364#ifdef KICAD_USE_SENTRY
365 void sentryInit();
366 void sentryPrompt();
367 wxString sentryCreateUid();
368#endif
369
370protected:
371 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
372
373 std::unique_ptr<SCRIPTING> m_python_scripting;
374
375 wxString m_bin_dir;
376 wxString m_kicad_env;
377
378 wxLocale* m_locale;
380
382 wxString m_pdf_browser;
383
385
386#ifdef KICAD_USE_SENTRY
387 wxFileName m_sentry_optin_fn;
388 wxFileName m_sentry_uid_fn;
389 wxString m_sentryUid;
390#endif
391
392 char** m_argvUtf8;
394
396};
397
398
401extern PGM_BASE& Pgm();
402
405extern PGM_BASE* PgmOrNull();
406
407
408#endif // PGM_BASE_H_
Container for data for KiCad programs.
Definition: pgm_base.h:96
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:621
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:167
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:395
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:862
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:543
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:344
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:355
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
wxString m_bin_dir
Definition: pgm_base.h:375
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:371
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:585
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:173
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:378
void Destroy()
Definition: pgm_base.cpp:153
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition: pgm_base.cpp:402
virtual const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:165
char ** m_argvUtf8
Definition: pgm_base.h:392
virtual bool UseSystemPdfBrowser() const
Definition: pgm_base.h:180
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:37
bool IsGUI()
Determine if the application is running with a GUI.
Definition: pgm_base.cpp:868
bool m_use_system_pdf_browser
Definition: pgm_base.h:381
bool m_Quitting
Definition: pgm_base.h:348
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition: pgm_base.cpp:387
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:171
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:174
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:167
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:222
wxString m_pdf_browser
Definition: pgm_base.h:382
std::vector< void * > m_ModalDialogs
Definition: pgm_base.h:346
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:818
wxString m_kicad_env
full path to this program
Definition: pgm_base.h:376
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:188
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:847
virtual void SetLanguagePath()
Definition: pgm_base.cpp:804
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:727
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:384
virtual ~PGM_BASE()
Definition: pgm_base.cpp:140
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:373
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:768
int m_language_id
Definition: pgm_base.h:379
void HandleException(std::exception_ptr aPtr)
A excepion handler to be used at the top level if exceptions bubble up that for.
Definition: pgm_base.cpp:886
virtual wxString GetLanguageTag()
Definition: pgm_base.cpp:784
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:181
virtual wxLocale * GetLocale()
Definition: pgm_base.h:169
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:136
virtual bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:163
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:612
static const wxChar workingDirKey[]
Definition: pgm_base.h:271
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:217
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:627
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: single_top.cpp:115
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:87
A small class to handle the list of existing translations.
Definition: pgm_base.h:62
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:67
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:73
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:70
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:64