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#include <wx/snglinst.h>
42
43#undef pid_t
44#include <pybind11/embed.h>
45
46class wxApp;
47class wxMenu;
48class wxWindow;
49class wxSplashScreen;
50
53class COMMON_SETTINGS;
55class SCRIPTING;
56
65{
68
71
73 wxString m_Lang_Label;
74
77};
78
79
84
99{
100public:
101 PGM_BASE();
102 virtual ~PGM_BASE();
103
104#if 0
105 /*
106
107 Derived classes must implement these two functions: OnPgmInit() and
108 OnPgmExit(), and since they are only called from same source file as their
109 implementation, these need not be virtual here. In fact, in the case of
110 python project manager's class PGM_PYTHON, these functions are actually
111 written in python. In total there are three implementations, corresponding
112 to the three defines given by kiface.h's KFCTL_* #defines.
113
114 */
115
121 virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
122
123 virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
124#endif
125
129 void BuildArgvUtf8();
130
137 virtual void MacOpenFile( const wxString& aFileName ) = 0;
138
140
141 virtual COMMON_SETTINGS* GetCommonSettings() const;
142
144
146
147 virtual void SetTextEditor( const wxString& aFileName );
148
158 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
159
167 virtual const wxString AskUserForPreferredEditor(
168 const wxString& aDefaultEditor = wxEmptyString );
169
170 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
171
172 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
173
174 virtual const wxString& GetExecutablePath() const;
175
176 virtual wxLocale* GetLocale() { return m_locale; }
177
178 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
179
180 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
181
187 virtual bool UseSystemPdfBrowser() const
188 {
189 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
190 }
191
195 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
196
207 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
208
215 bool SetDefaultLanguage( wxString& aErrMsg );
216
224 virtual void SetLanguageIdentifier( int menu_id );
225
229 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
230
234 virtual wxString GetLanguageTag();
235
236 virtual void SetLanguagePath();
237
241 virtual void ReadPdfBrowserInfos();
242
246 virtual void WritePdfBrowserInfos();
247
260 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
261
267 virtual void SetLocalEnvVariables();
268
269 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
270
276 virtual wxApp& App();
277
278 static const wxChar workingDirKey[];
279
295 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
296
297 // The PGM_* classes can have difficulties at termination if they
298 // are not destroyed soon enough. Relying on a static destructor can be
299 // too late for contained objects like wxSingleInstanceChecker.
300 void Destroy();
301
305 void SaveCommonSettings();
306
307#ifdef KICAD_USE_SENTRY
311 bool IsSentryOptedIn();
312
319 void SetSentryOptIn( bool aOptIn );
320
324 void ResetSentryId();
325
329 const wxString& GetSentryId();
330#endif
331
339 void HandleException( std::exception_ptr aPtr );
340
352 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
353 const wxString& aCond, const wxString& aMsg );
354
360 bool IsGUI();
361
362
363 void ShowSplash();
364 void HideSplash();
365
369 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
370 {
371 return m_pgm_checker;
372 }
373
378
379 std::vector<void*> m_ModalDialogs;
380
382
383protected:
385 void loadCommonSettings();
386
388 void setLanguageId( int aId ) { m_language_id = aId; }
389
390#ifdef KICAD_USE_SENTRY
391 void sentryInit();
392 void sentryPrompt();
393 wxString sentryCreateUid();
394#endif
395
396protected:
397 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
398 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
399 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
400
401 std::unique_ptr<SCRIPTING> m_python_scripting;
402
404 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
405
406
407 wxString m_kicad_env;
408
409 wxLocale* m_locale;
411
413 wxString m_pdf_browser;
414
416
417#ifdef KICAD_USE_SENTRY
418 wxFileName m_sentry_optin_fn;
419 wxFileName m_sentry_uid_fn;
420 wxString m_sentryUid;
421#endif
422
423 char** m_argvUtf8;
425
427
428 wxSplashScreen* m_splash;
429};
430
431
434extern PGM_BASE& Pgm();
435
438extern PGM_BASE* PgmOrNull();
439
440
441#endif // PGM_BASE_H_
Container for data for KiCad programs.
Definition: pgm_base.h:99
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:634
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:173
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition: pgm_base.h:399
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:426
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:875
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:377
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:388
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:397
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:598
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:180
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:409
void Destroy()
Definition: pgm_base.cpp:157
wxSplashScreen * m_splash
Definition: pgm_base.h:428
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allows access to the wxSingleInstanceChecker to test for other running KiCads.
Definition: pgm_base.h:369
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition: pgm_base.h:143
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition: pgm_base.cpp:441
virtual const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:172
char ** m_argvUtf8
Definition: pgm_base.h:423
virtual bool UseSystemPdfBrowser() const
Definition: pgm_base.h:187
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:881
bool m_use_system_pdf_browser
Definition: pgm_base.h:412
bool m_Quitting
Definition: pgm_base.h:381
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition: pgm_base.h:145
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition: pgm_base.cpp:403
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:178
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:180
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Checks if there is another copy of Kicad running at the same time.
Definition: pgm_base.h:404
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:229
wxString m_pdf_browser
Definition: pgm_base.h:413
std::vector< void * > m_ModalDialogs
Definition: pgm_base.h:379
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:828
wxString m_kicad_env
Definition: pgm_base.h:407
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:195
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:859
virtual void SetLanguagePath()
Definition: pgm_base.cpp:814
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:741
void ShowSplash()
Definition: pgm_base.cpp:418
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:415
virtual ~PGM_BASE()
Definition: pgm_base.cpp:143
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:401
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:782
int m_language_id
Definition: pgm_base.h:410
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition: pgm_base.h:398
void HandleException(std::exception_ptr aPtr)
A exception handler to be used at the top level if exceptions bubble up that for.
Definition: pgm_base.cpp:890
void HandleAssert(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
A common assert handler to be used between single_top and kicad.
Definition: pgm_base.cpp:947
virtual wxString GetLanguageTag()
Definition: pgm_base.cpp:798
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:187
virtual wxLocale * GetLocale()
Definition: pgm_base.h:176
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.cpp:990
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:139
void HideSplash()
Definition: pgm_base.cpp:430
virtual bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:170
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:625
static const wxChar workingDirKey[]
Definition: pgm_base.h:278
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:223
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:640
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: single_top.cpp:119
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:65
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:70
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:76
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:73
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:67