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, see <https://www.gnu.org/licenses/>.
20 */
21
26
27#ifndef PGM_BASE_H_
28#define PGM_BASE_H_
29
30#include <kicommon.h>
31#include <singleton.h>
32#include <exception>
33#include <map>
34#include <future>
35#include <mutex>
36#include <vector>
37#include <memory>
38#include <search_stack.h>
40#include <wx/filename.h>
41
42class wxApp;
43class wxMenu;
44class wxWindow;
45class wxSplashScreen;
46
47class KISTATUSBAR;
48class KI_ERROR;
49struct BACKGROUND_JOB;
52class COMMON_SETTINGS;
54class LIBRARY_MANAGER;
55
58
80
81
86
101{
102public:
103 PGM_BASE();
104 virtual ~PGM_BASE();
105
109 void BuildArgvUtf8();
110
112
113 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
114
121 virtual void MacOpenFile( const wxString& aFileName ) = 0;
122
124
126
127 virtual COMMON_SETTINGS* GetCommonSettings() const;
128
133
138
140
142
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
295 bool InitPgm( bool aHeadless = false, bool aIsUnitTest = false );
296
304 static wxString DesktopAppIdForProgram( const wxString& aPgmName );
305
306 const wxString& GetDesktopAppId() const { return m_desktopAppId; }
307
308 // The PGM_* classes can have difficulties at termination if they
309 // are not destroyed soon enough. Relying on a static destructor can be
310 // too late for the objects they contain.
311 void Destroy();
312
316 void SaveCommonSettings();
317
325 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
326
338 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
339 const wxString& aCond, const wxString& aMsg );
340
346 bool IsGUI();
347
348
349 void ShowSplash();
350 void HideSplash();
351
357 void PreloadDesignBlockLibraries( KIWAY* aKiway );
358
363 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
364
368 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
369
374 void AddLibraryLoadMessages( const std::vector<KI_ERROR>& aMessages );
375
379 void ClearLibraryLoadMessages();
380
385
386 std::vector<void*> m_ModalDialogs;
387
389
391
392protected:
394 void loadCommonSettings();
395
397 void setLanguageId( int aId ) { m_language_id = aId; }
398
399#ifdef KICAD_USE_SENTRY
400 void sentryInit();
401 wxString sentryCreateUid();
402#endif
403
404protected:
405 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
406 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
407 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
408 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
409
410 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
411 std::unique_ptr<KICAD_API_SERVER> m_api_server;
412
413 wxString m_kicad_env;
414
415 wxString m_desktopAppId;
416
417 wxLocale* m_locale;
419
421 wxString m_pdf_browser;
422
424
426
427#ifdef KICAD_USE_SENTRY
428 wxFileName m_sentry_optin_fn;
429 wxFileName m_sentry_uid_fn;
430 wxString m_sentryUid;
431#endif
432
439
441
442 wxSplashScreen* m_splash;
443
444 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
445 std::future<void> m_libraryPreloadReturn;
447 std::atomic_bool m_libraryPreloadAbort;
448
449 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
451};
452
453
462KICOMMON_API extern PGM_BASE& Pgm();
463
467
468KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
469
470
471#endif // PGM_BASE_H_
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:340
Holds a structured error message.
Definition ki_error.h:38
Container for data for KiCad programs.
Definition pgm_base.h:101
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:408
int m_argcUtf8
Definition pgm_base.h:440
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:406
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:384
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:397
std::unique_ptr< API_PLUGIN_MANAGER > m_plugin_manager
Definition pgm_base.h:410
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:405
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:510
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:178
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:449
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:139
wxLocale * m_locale
Definition pgm_base.h:417
wxSplashScreen * m_splash
Definition pgm_base.h:442
KICAD_API_SERVER * ApiServerOrNull() const
Definition pgm_base.h:143
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:438
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:144
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:185
bool m_use_system_pdf_browser
Definition pgm_base.h:420
bool m_Quitting
Definition pgm_base.h:388
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:445
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:134
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:444
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:273
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:176
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:447
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:421
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:386
KICAD_API_SERVER & GetApiServer()
Definition pgm_base.h:141
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:340
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:413
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
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:411
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:113
wxString m_text_editor
Definition pgm_base.h:423
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:446
wxString m_desktopAppId
freedesktop app id of this process, or empty.
Definition pgm_base.h:415
int m_language_id
Definition pgm_base.h:418
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:407
virtual wxLocale * GetLocale()
Definition pgm_base.h:174
const wxString & GetDesktopAppId() const
Definition pgm_base.h:306
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:123
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:168
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:125
static wxString DesktopAppIdForProgram(const wxString &aPgmName)
Map a program name (argv[0] basename, lowercased) to the freedesktop application id of its installed ...
Definition pgm_base.cpp:318
bool m_PropertyGridInitialized
Definition pgm_base.h:390
static const wxChar workingDirKey[]
Definition pgm_base.h:279
KICAD_SINGLETON m_singleton
Definition pgm_base.h:425
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:450
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define KICOMMON_API
Definition kicommon.h:27
thread_pool< 1 > priority_thread_pool
Definition singleton.h:31
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition pgm_base.cpp:86
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.
KICOMMON_API void SetPgm(PGM_BASE *pgm)
KICOMMON_API PGM_BASE & Pgm()
The global program "get" accessor.
A small class to handle the list of existing translations.
Definition pgm_base.h:67
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition pgm_base.h:72
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition pgm_base.h:78
wxString m_Lang_Label
Labels used in menus.
Definition pgm_base.h:75
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition pgm_base.h:69