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 <kicommon.h>
35#include <exception>
36#include <map>
37#include <vector>
38#include <memory>
39#include <search_stack.h>
41#include <wx/filename.h>
42
43class wxApp;
44class wxMenu;
45class wxWindow;
46class wxSplashScreen;
47class wxSingleInstanceChecker;
48
51class COMMON_SETTINGS;
53class SCRIPTING;
54
55#ifdef KICAD_IPC_API
58#endif
59
68{
71
74
76 wxString m_Lang_Label;
77
80};
81
82
87
102{
103public:
104 PGM_BASE();
105 virtual ~PGM_BASE();
106
107#if 0
108 /*
109
110 Derived classes must implement these two functions: OnPgmInit() and
111 OnPgmExit(), and since they are only called from same source file as their
112 implementation, these need not be virtual here. In fact, in the case of
113 python project manager's class PGM_PYTHON, these functions are actually
114 written in python. In total there are three implementations, corresponding
115 to the three defines given by kiface.h's KFCTL_* #defines.
116
117 */
118
124 virtual bool OnPgmInit() = 0; // call this from wxApp::OnInit()
125
126 virtual void OnPgmExit() = 0; // call this from wxApp::OnExit()
127#endif
128
132 void BuildArgvUtf8();
133
140 virtual void MacOpenFile( const wxString& aFileName ) = 0;
141
142 virtual SETTINGS_MANAGER& GetSettingsManager() const { return *m_settings_manager; }
143
144 virtual COMMON_SETTINGS* GetCommonSettings() const;
145
146 virtual BACKGROUND_JOBS_MONITOR& GetBackgroundJobMonitor() const { return *m_background_jobs_monitor; }
147
148 virtual NOTIFICATIONS_MANAGER& GetNotificationsManager() const { return *m_notifications_manager; }
149
150#ifdef KICAD_IPC_API
151 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
152
153 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
154#endif
155
156 virtual void SetTextEditor( const wxString& aFileName );
157
167 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
168
176 virtual const wxString AskUserForPreferredEditor(
177 const wxString& aDefaultEditor = wxEmptyString );
178
179 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
180
181 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
182
183 virtual const wxString& GetExecutablePath() const;
184
185 virtual wxLocale* GetLocale() { return m_locale; }
186
187 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
188
189 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
190
196 virtual bool UseSystemPdfBrowser() const
197 {
198 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
199 }
200
204 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
205
216 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
217
224 bool SetDefaultLanguage( wxString& aErrMsg );
225
233 virtual void SetLanguageIdentifier( int menu_id );
234
238 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
239
243 virtual wxString GetLanguageTag();
244
245 virtual void SetLanguagePath();
246
250 virtual void ReadPdfBrowserInfos();
251
255 virtual void WritePdfBrowserInfos();
256
269 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
270
276 virtual void SetLocalEnvVariables();
277
278 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
279
285 virtual wxApp& App();
286
287 static const wxChar workingDirKey[];
288
304 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
305
306 // The PGM_* classes can have difficulties at termination if they
307 // are not destroyed soon enough. Relying on a static destructor can be
308 // too late for contained objects like wxSingleInstanceChecker.
309 void Destroy();
310
314 void SaveCommonSettings();
315
316#ifdef KICAD_USE_SENTRY
320 bool IsSentryOptedIn();
321
328 void SetSentryOptIn( bool aOptIn );
329
333 void ResetSentryId();
334
338 const wxString& GetSentryId();
339#endif
340
348 void HandleException( std::exception_ptr aPtr );
349
361 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
362 const wxString& aCond, const wxString& aMsg );
363
369 bool IsGUI();
370
371
372 void ShowSplash();
373 void HideSplash();
374
378 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
379 {
380 return m_pgm_checker;
381 }
382
387
388 std::vector<void*> m_ModalDialogs;
389
391
393
394protected:
396 void loadCommonSettings();
397
399 void setLanguageId( int aId ) { m_language_id = aId; }
400
401#ifdef KICAD_USE_SENTRY
402 void sentryInit();
403 void sentryPrompt();
404 wxString sentryCreateUid();
405#endif
406
407protected:
408 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
409 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
410 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
411
412 std::unique_ptr<SCRIPTING> m_python_scripting;
413
415 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
416
417#ifdef KICAD_IPC_API
418 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
419 std::unique_ptr<KICAD_API_SERVER> m_api_server;
420#endif
421
422 wxString m_kicad_env;
423
424 wxLocale* m_locale;
426
428 wxString m_pdf_browser;
429
431
432#ifdef KICAD_USE_SENTRY
433 wxFileName m_sentry_optin_fn;
434 wxFileName m_sentry_uid_fn;
435 wxString m_sentryUid;
436#endif
437
438 char** m_argvUtf8;
440
442
443 wxSplashScreen* m_splash;
444};
445
446
449KICOMMON_API extern PGM_BASE& Pgm();
450
454
455KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
456
457
458#endif // PGM_BASE_H_
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
Container for data for KiCad programs.
Definition: pgm_base.h:102
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition: pgm_base.h:410
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:441
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:386
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:399
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:408
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:189
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:424
wxSplashScreen * m_splash
Definition: pgm_base.h:443
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allows access to the wxSingleInstanceChecker to test for other running KiCads.
Definition: pgm_base.h:378
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition: pgm_base.h:146
virtual const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:181
char ** m_argvUtf8
Definition: pgm_base.h:438
virtual bool UseSystemPdfBrowser() const
Definition: pgm_base.h:196
bool m_use_system_pdf_browser
Definition: pgm_base.h:427
bool m_Quitting
Definition: pgm_base.h:390
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition: pgm_base.h:148
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:187
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Checks if there is another copy of Kicad running at the same time.
Definition: pgm_base.h:415
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:238
wxString m_pdf_browser
Definition: pgm_base.h:428
std::vector< void * > m_ModalDialogs
Definition: pgm_base.h:388
wxString m_kicad_env
Definition: pgm_base.h:422
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:204
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:430
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:412
int m_language_id
Definition: pgm_base.h:425
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition: pgm_base.h:409
virtual wxLocale * GetLocale()
Definition: pgm_base.h:185
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
virtual bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:179
bool m_PropertyGridInitialized
Definition: pgm_base.h:392
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define KICOMMON_API
Definition: kicommon.h:28
KICOMMON_API PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: pgm_base.cpp:1066
KICOMMON_API void SetPgm(PGM_BASE *pgm)
Definition: pgm_base.cpp:1071
KICOMMON_API LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:95
KICOMMON_API PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
A small class to handle the list of existing translations.
Definition: pgm_base.h:68
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:73
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:79
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:76
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:70