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
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
315 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
316
328 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
329 const wxString& aCond, const wxString& aMsg );
330
336 bool IsGUI();
337
338
339 void ShowSplash();
340 void HideSplash();
341
345 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
346 {
347 return m_pgm_checker;
348 }
349
355 void PreloadDesignBlockLibraries( KIWAY* aKiway );
356
361 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
362
366 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
367
372 void AddLibraryLoadMessages( const std::vector<LOAD_MESSAGE>& aMessages );
373
377 void ClearLibraryLoadMessages();
378
383
384 std::vector<void*> m_ModalDialogs;
385
387
389
390protected:
392 void loadCommonSettings();
393
395 void setLanguageId( int aId ) { m_language_id = aId; }
396
397#ifdef KICAD_USE_SENTRY
398 void sentryInit();
399 wxString sentryCreateUid();
400#endif
401
402protected:
403 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
404 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
405 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
406 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
407
409 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
410
411 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
412 std::unique_ptr<KICAD_API_SERVER> m_api_server;
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 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
444 std::future<void> m_libraryPreloadReturn;
446 std::atomic_bool m_libraryPreloadAbort;
447
448 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
450};
451
452
461KICOMMON_API extern PGM_BASE& Pgm();
462
466
467KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
468
469
470#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:406
int m_argcUtf8
Definition pgm_base.h:439
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:404
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:382
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:395
std::unique_ptr< API_PLUGIN_MANAGER > m_plugin_manager
Definition pgm_base.h:411
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:403
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:492
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:179
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:448
virtual API_PLUGIN_MANAGER & GetPluginManager() const
Definition pgm_base.h:140
wxLocale * m_locale
Definition pgm_base.h:416
void Destroy()
Definition pgm_base.cpp:183
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:345
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:437
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:144
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:186
void HandleException(std::exception_ptr aPtr, bool aUnhandled=false)
A exception handler to be used at the top level if exceptions bubble up that for.
Definition pgm_base.cpp:789
bool IsGUI()
Determine if the application is running with a GUI.
Definition pgm_base.cpp:780
bool m_use_system_pdf_browser
Definition pgm_base.h:419
bool m_Quitting
Definition pgm_base.h:386
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:444
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:135
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:443
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:275
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:177
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:446
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition pgm_base.h:409
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:420
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:384
KICAD_API_SERVER & GetApiServer()
Definition pgm_base.h:142
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:320
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:194
std::unique_ptr< KICAD_API_SERVER > m_api_server
Definition pgm_base.h:412
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:114
void ShowSplash()
Definition pgm_base.cpp:290
wxString m_text_editor
Definition pgm_base.h:422
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:445
int m_language_id
Definition pgm_base.h:417
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:405
void HandleAssert(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
A common assert handler to be used between single_top and kicad.
Definition pgm_base.cpp:826
virtual wxLocale * GetLocale()
Definition pgm_base.h:175
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
void HideSplash()
Definition pgm_base.cpp:309
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:169
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition pgm_base.cpp:519
bool m_PropertyGridInitialized
Definition pgm_base.h:388
static const wxChar workingDirKey[]
Definition pgm_base.h:280
KICAD_SINGLETON m_singleton
Definition pgm_base.h:424
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:449
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