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 The 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 <singleton.h>
36#include <exception>
37#include <map>
38#include <vector>
39#include <memory>
40#include <search_stack.h>
42#include <wx/filename.h>
43
44class wxApp;
45class wxMenu;
46class wxWindow;
47class wxSplashScreen;
48class wxSingleInstanceChecker;
49
52class COMMON_SETTINGS;
54class SCRIPTING;
55
56#ifdef KICAD_IPC_API
59#endif
60
69{
72
75
77 wxString m_Lang_Label;
78
81};
82
83
88
103{
104public:
105 PGM_BASE();
106 virtual ~PGM_BASE();
107
111 void BuildArgvUtf8();
112
113 BS::thread_pool& GetThreadPool() { return *m_singleton.m_ThreadPool; }
114
115 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
116
123 virtual void MacOpenFile( const wxString& aFileName ) = 0;
124
125 virtual SETTINGS_MANAGER& GetSettingsManager() const { return *m_settings_manager; }
126
127 virtual COMMON_SETTINGS* GetCommonSettings() const;
128
130 {
131 return *m_background_jobs_monitor;
132 }
133
135 {
136 return *m_notifications_manager;
137 }
138
139#ifdef KICAD_IPC_API
140 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
141
142 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
143#endif
144
145 virtual void SetTextEditor( const wxString& aFileName );
146
156 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
157
165 virtual const wxString AskUserForPreferredEditor(
166 const wxString& aDefaultEditor = wxEmptyString );
167
168 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
169
170 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
171
172 virtual const wxString& GetExecutablePath() const;
173
174 virtual wxLocale* GetLocale() { return m_locale; }
175
176 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
177
178 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
179
185 virtual bool UseSystemPdfBrowser() const
186 {
187 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
188 }
189
193 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
194
205 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
206
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
268 virtual void SetLocalEnvVariables();
269
270 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
271
277 virtual wxApp& App();
278
279 static const wxChar workingDirKey[];
280
296 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
297
298 // The PGM_* classes can have difficulties at termination if they
299 // are not destroyed soon enough. Relying on a static destructor can be
300 // too late for contained objects like wxSingleInstanceChecker.
301 void Destroy();
302
306 void SaveCommonSettings();
307
308#ifdef KICAD_USE_SENTRY
312 bool IsSentryOptedIn();
313
320 void SetSentryOptIn( bool aOptIn );
321
325 void ResetSentryId();
326
330 const wxString& GetSentryId();
331#endif
332
340 void HandleException( std::exception_ptr aPtr );
341
353 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
354 const wxString& aCond, const wxString& aMsg );
355
361 bool IsGUI();
362
363
364 void ShowSplash();
365 void HideSplash();
366
370 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
371 {
372 return m_pgm_checker;
373 }
374
379
380 std::vector<void*> m_ModalDialogs;
381
383
385
386protected:
388 void loadCommonSettings();
389
391 void setLanguageId( int aId ) { m_language_id = aId; }
392
393#ifdef KICAD_USE_SENTRY
394 void sentryInit();
395 void sentryPrompt();
396 wxString sentryCreateUid();
397#endif
398
399protected:
400 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
401 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
402 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
403
404 std::unique_ptr<SCRIPTING> m_python_scripting;
405
407 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
408
409#ifdef KICAD_IPC_API
410 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
411 std::unique_ptr<KICAD_API_SERVER> m_api_server;
412#endif
413
414 wxString m_kicad_env;
415
416 wxLocale* m_locale;
418
420 wxString m_pdf_browser;
421
423
425
426#ifdef KICAD_USE_SENTRY
427 wxFileName m_sentry_optin_fn;
428 wxFileName m_sentry_uid_fn;
429 wxString m_sentryUid;
430#endif
431
438
440
441 wxSplashScreen* m_splash;
442};
443
444
453KICOMMON_API extern PGM_BASE& Pgm();
454
458
459KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
460
461
462#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:103
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition: pgm_base.h:402
int m_argcUtf8
Definition: pgm_base.h:439
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:378
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:391
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:400
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:178
wxLocale * m_locale
Definition: pgm_base.h:416
wxSplashScreen * m_splash
Definition: pgm_base.h:441
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allow access to the wxSingleInstanceChecker to test for other running KiCads.
Definition: pgm_base.h:370
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition: pgm_base.h:129
virtual const wxString & GetKicadEnvVariable() const
Definition: pgm_base.h:170
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
Definition: pgm_base.h:437
virtual bool UseSystemPdfBrowser() const
Definition: pgm_base.h:185
bool m_use_system_pdf_browser
Definition: pgm_base.h:419
bool m_Quitting
Definition: pgm_base.h:382
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition: pgm_base.h:134
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:176
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition: pgm_base.h:407
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:229
wxString m_pdf_browser
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:420
std::vector< void * > m_ModalDialogs
Definition: pgm_base.h:380
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:414
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:193
BS::thread_pool & GetThreadPool()
Definition: pgm_base.h:113
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition: pgm_base.h:115
wxString m_text_editor
Definition: pgm_base.h:422
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:404
int m_language_id
Definition: pgm_base.h:417
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition: pgm_base.h:401
virtual wxLocale * GetLocale()
Definition: pgm_base.h:174
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
virtual bool IsKicadEnvVariableDefined() const
Definition: pgm_base.h:168
bool m_PropertyGridInitialized
Definition: pgm_base.h:384
KICAD_SINGLETON m_singleton
Definition: pgm_base.h:424
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define KICOMMON_API
Definition: kicommon.h:28
KICOMMON_API PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
Definition: pgm_base.cpp:1081
KICOMMON_API void SetPgm(PGM_BASE *pgm)
Definition: pgm_base.cpp:1087
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:1073
A small class to handle the list of existing translations.
Definition: pgm_base.h:69
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:74
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition: pgm_base.h:80
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:77
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition: pgm_base.h:71