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 wxEvent;
44class wxMenu;
45class wxWindow;
46class wxSplashScreen;
47
48class KISTATUSBAR;
49class KI_ERROR;
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
297 bool InitPgm( bool aHeadless = false, bool aIsUnitTest = false );
298
306 static wxString DesktopAppIdForProgram( const wxString& aPgmName );
307
308 const wxString& GetDesktopAppId() const { return m_desktopAppId; }
309
310 // The PGM_* classes can have difficulties at termination if they
311 // are not destroyed soon enough. Relying on a static destructor can be
312 // too late for the objects they contain.
313 void Destroy();
314
316 void SetRunResult( int aResult ) { m_runResult = aResult; }
317
322 void ExitIfTeardownUnsafe();
323
327 void SaveCommonSettings();
328
337 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
338
350 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
351 const wxString& aCond, const wxString& aMsg );
352
358 bool IsGUI();
359
360
361 void ShowSplash();
362 void HideSplash();
363
369 void PreloadDesignBlockLibraries( KIWAY* aKiway );
370
376 void CancelDesignBlockPreload();
377
382 void WaitForDesignBlockPreload();
383
388 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
389
393 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
394
399 void AddLibraryLoadMessages( const std::vector<KI_ERROR>& aMessages );
400
404 void ClearLibraryLoadMessages();
405
410 int FilterAppEvent( wxEvent& aEvent );
411
416 bool IsSessionEnding() const { return m_sessionEnding; }
417
422
423 std::vector<void*> m_ModalDialogs;
424
426
428
429protected:
431 void loadCommonSettings();
432
434 void setLanguageId( int aId ) { m_language_id = aId; }
435
436#ifdef KICAD_USE_SENTRY
437 void sentryInit();
438 wxString sentryCreateUid();
439#endif
440
441protected:
442 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
443 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
444 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
445 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
446
447 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
448 std::unique_ptr<KICAD_API_SERVER> m_api_server;
449
450 wxString m_kicad_env;
451
452 wxString m_desktopAppId;
453
454 wxLocale* m_locale;
456
458 wxString m_pdf_browser;
459
462
464
465#ifdef KICAD_USE_SENTRY
466 wxFileName m_sentry_optin_fn;
467 wxFileName m_sentry_uid_fn;
468 wxString m_sentryUid;
469#endif
470
477
479
480 wxSplashScreen* m_splash;
481
482 int m_runResult = 0;
483
484 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
485 std::future<void> m_libraryPreloadReturn;
487 std::atomic_bool m_libraryPreloadAbort;
488
489 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
491};
492
493
502KICOMMON_API extern PGM_BASE& Pgm();
503
507
508KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
509
510
511#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:348
Holds a structured error message.
Definition ki_error.h:38
Container for data for KiCad programs.
Definition pgm_base.h:102
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:445
int m_argcUtf8
Definition pgm_base.h:478
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:443
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:421
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:434
std::unique_ptr< API_PLUGIN_MANAGER > m_plugin_manager
Definition pgm_base.h:447
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
bool IsSessionEnding() const
Return true while the operating system is closing the application because the user session is ending,...
Definition pgm_base.h:416
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition pgm_base.h:442
void SetRunResult(int aResult)
Records the code the application's run loop returned, which a fast exit still reports.
Definition pgm_base.h:316
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:564
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:179
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:489
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:140
wxLocale * m_locale
Definition pgm_base.h:454
wxSplashScreen * m_splash
Definition pgm_base.h:480
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:476
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:150
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:186
bool m_use_system_pdf_browser
Definition pgm_base.h:457
bool m_Quitting
Definition pgm_base.h:425
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:485
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:135
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:484
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:307
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:177
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:487
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:458
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:423
KICAD_API_SERVER & GetApiServer()
Definition pgm_base.h:142
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:373
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:450
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
int m_runResult
Definition pgm_base.h:482
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:448
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:114
wxString m_text_editor
Definition pgm_base.h:460
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:486
bool m_sessionEnding
Set while wx handles a session-end event.
Definition pgm_base.h:461
wxString m_desktopAppId
freedesktop app id of this process, or empty.
Definition pgm_base.h:452
int m_language_id
Definition pgm_base.h:455
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:444
virtual wxLocale * GetLocale()
Definition pgm_base.h:175
const wxString & GetDesktopAppId() const
Definition pgm_base.h:308
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:352
bool m_PropertyGridInitialized
Definition pgm_base.h:427
static const wxChar workingDirKey[]
Definition pgm_base.h:280
KICAD_SINGLETON m_singleton
Definition pgm_base.h:463
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:490
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:92
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