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;
46class wxSingleInstanceChecker;
47
48class KISTATUSBAR;
49struct LOAD_MESSAGE;
50struct BACKGROUND_JOB;
53class COMMON_SETTINGS;
55class LIBRARY_MANAGER;
56
59
81
82
87
102{
103public:
104 PGM_BASE();
105 virtual ~PGM_BASE();
106
110 void BuildArgvUtf8();
111
113
114 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
115
122 virtual void MacOpenFile( const wxString& aFileName ) = 0;
123
125
127
128 virtual COMMON_SETTINGS* GetCommonSettings() const;
129
134
139
141
143
145
146 virtual void SetTextEditor( const wxString& aFileName );
147
157 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
158
166 virtual const wxString AskUserForPreferredEditor(
167 const wxString& aDefaultEditor = wxEmptyString );
168
169 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
170
171 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
172
173 virtual const wxString& GetExecutablePath() const;
174
175 virtual wxLocale* GetLocale() { return m_locale; }
176
177 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
178
179 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
180
186 virtual bool UseSystemPdfBrowser() const
187 {
188 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
189 }
190
194 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
195
206 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
207
216 bool SetDefaultLanguage( wxString& aErrMsg );
217
225 virtual void SetLanguageIdentifier( int menu_id );
226
230 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
231
235 virtual wxString GetLanguageTag();
236
237 virtual void SetLanguagePath();
238
242 virtual void ReadPdfBrowserInfos();
243
247 virtual void WritePdfBrowserInfos();
248
261 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
262
269 virtual void SetLocalEnvVariables();
270
271 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
272
278 virtual wxApp& App();
279
280 static const wxChar workingDirKey[];
281
296 bool InitPgm( bool aHeadless = false, bool aIsUnitTest = false );
297
305 static wxString DesktopAppIdForProgram( const wxString& aPgmName );
306
307 const wxString& GetDesktopAppId() const { return m_desktopAppId; }
308
309 // The PGM_* classes can have difficulties at termination if they
310 // are not destroyed soon enough. Relying on a static destructor can be
311 // too late for contained objects like wxSingleInstanceChecker.
312 void Destroy();
313
317 void SaveCommonSettings();
318
326 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
327
339 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
340 const wxString& aCond, const wxString& aMsg );
341
347 bool IsGUI();
348
349
350 void ShowSplash();
351 void HideSplash();
352
356 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
357 {
358 return m_pgm_checker;
359 }
360
366 void PreloadDesignBlockLibraries( KIWAY* aKiway );
367
372 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
373
377 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
378
383 void AddLibraryLoadMessages( const std::vector<LOAD_MESSAGE>& aMessages );
384
388 void ClearLibraryLoadMessages();
389
394
395 std::vector<void*> m_ModalDialogs;
396
398
400
401protected:
403 void loadCommonSettings();
404
406 void setLanguageId( int aId ) { m_language_id = aId; }
407
408#ifdef KICAD_USE_SENTRY
409 void sentryInit();
410 wxString sentryCreateUid();
411#endif
412
413protected:
414 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
415 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
416 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
417 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
418
420 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
421
422 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
423 std::unique_ptr<KICAD_API_SERVER> m_api_server;
424
425 wxString m_kicad_env;
426
427 wxString m_desktopAppId;
428
429 wxLocale* m_locale;
431
433 wxString m_pdf_browser;
434
436
438
439#ifdef KICAD_USE_SENTRY
440 wxFileName m_sentry_optin_fn;
441 wxFileName m_sentry_uid_fn;
442 wxString m_sentryUid;
443#endif
444
451
453
454 wxSplashScreen* m_splash;
455
456 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
457 std::future<void> m_libraryPreloadReturn;
459 std::atomic_bool m_libraryPreloadAbort;
460
461 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
463};
464
465
474KICOMMON_API extern PGM_BASE& Pgm();
475
479
480KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
481
482
483#endif // PGM_BASE_H_
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
Container for data for KiCad programs.
Definition pgm_base.h:102
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:417
int m_argcUtf8
Definition pgm_base.h:452
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:415
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:393
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:406
std::unique_ptr< API_PLUGIN_MANAGER > m_plugin_manager
Definition pgm_base.h:422
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:414
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:526
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:179
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:461
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:140
wxLocale * m_locale
Definition pgm_base.h:429
wxSplashScreen * m_splash
Definition pgm_base.h:454
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allow access to the wxSingleInstanceChecker to test for other running KiCads.
Definition pgm_base.h:356
KICAD_API_SERVER * ApiServerOrNull() const
Definition pgm_base.h:144
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:130
virtual const wxString & GetKicadEnvVariable() const
Definition pgm_base.h:171
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
Definition pgm_base.h:450
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:145
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:186
bool m_use_system_pdf_browser
Definition pgm_base.h:432
bool m_Quitting
Definition pgm_base.h:397
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:457
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:135
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:456
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:276
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:177
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:459
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition pgm_base.h:420
virtual int GetSelectedLanguageIdentifier() const
Definition pgm_base.h:230
wxString m_pdf_browser
Filename of the app selected for browsing PDFs.
Definition pgm_base.h:433
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:395
KICAD_API_SERVER & GetApiServer()
Definition pgm_base.h:142
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:343
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:425
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition pgm_base.h:194
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:423
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:114
wxString m_text_editor
Definition pgm_base.h:435
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:458
wxString m_desktopAppId
freedesktop app id of this process, or empty.
Definition pgm_base.h:427
int m_language_id
Definition pgm_base.h:430
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:416
virtual wxLocale * GetLocale()
Definition pgm_base.h:175
const wxString & GetDesktopAppId() const
Definition pgm_base.h:307
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:169
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
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:321
bool m_PropertyGridInitialized
Definition pgm_base.h:399
static const wxChar workingDirKey[]
Definition pgm_base.h:280
KICAD_SINGLETON m_singleton
Definition pgm_base.h:437
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:462
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:87
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: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
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50