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
30
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 <future>
39#include <mutex>
40#include <vector>
41#include <memory>
42#include <search_stack.h>
44#include <wx/filename.h>
45
46class wxApp;
47class wxMenu;
48class wxWindow;
49class wxSplashScreen;
50class wxSingleInstanceChecker;
51
52class KISTATUSBAR;
53struct LOAD_MESSAGE;
54struct BACKGROUND_JOB;
57class COMMON_SETTINGS;
59class LIBRARY_MANAGER;
60class SCRIPTING;
61
62#ifdef KICAD_IPC_API
65#endif
66
88
89
94
109{
110public:
111 PGM_BASE();
112 virtual ~PGM_BASE();
113
117 void BuildArgvUtf8();
118
120
121 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
122
129 virtual void MacOpenFile( const wxString& aFileName ) = 0;
130
132
134
135 virtual COMMON_SETTINGS* GetCommonSettings() const;
136
141
146
147#ifdef KICAD_IPC_API
148 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
149
150 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
151#endif
152
153 virtual void SetTextEditor( const wxString& aFileName );
154
164 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
165
173 virtual const wxString AskUserForPreferredEditor(
174 const wxString& aDefaultEditor = wxEmptyString );
175
176 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
177
178 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
179
180 virtual const wxString& GetExecutablePath() const;
181
182 virtual wxLocale* GetLocale() { return m_locale; }
183
184 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
185
186 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
187
193 virtual bool UseSystemPdfBrowser() const
194 {
195 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
196 }
197
201 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
202
213 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
214
223 bool SetDefaultLanguage( wxString& aErrMsg );
224
232 virtual void SetLanguageIdentifier( int menu_id );
233
237 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
238
242 virtual wxString GetLanguageTag();
243
244 virtual void SetLanguagePath();
245
249 virtual void ReadPdfBrowserInfos();
250
254 virtual void WritePdfBrowserInfos();
255
268 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
269
276 virtual void SetLocalEnvVariables();
277
278 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
279
285 virtual wxApp& App();
286
287 static const wxChar workingDirKey[];
288
304 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
305
306 // The PGM_* classes can have difficulties at termination if they
307 // are not destroyed soon enough. Relying on a static destructor can be
308 // too late for contained objects like wxSingleInstanceChecker.
309 void Destroy();
310
314 void SaveCommonSettings();
315
323 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
324
336 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
337 const wxString& aCond, const wxString& aMsg );
338
344 bool IsGUI();
345
346
347 void ShowSplash();
348 void HideSplash();
349
353 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
354 {
355 return m_pgm_checker;
356 }
357
363 void PreloadDesignBlockLibraries( KIWAY* aKiway );
364
369 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
370
374 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
375
380 void AddLibraryLoadMessages( const std::vector<LOAD_MESSAGE>& aMessages );
381
385 void ClearLibraryLoadMessages();
386
391
392 std::vector<void*> m_ModalDialogs;
393
395
397
398protected:
400 void loadCommonSettings();
401
403 void setLanguageId( int aId ) { m_language_id = aId; }
404
405#ifdef KICAD_USE_SENTRY
406 void sentryInit();
407 wxString sentryCreateUid();
408#endif
409
410protected:
411 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
412 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
413 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
414 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
415
416 std::unique_ptr<SCRIPTING> m_python_scripting;
417
419 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
420
421#ifdef KICAD_IPC_API
422 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
423 std::unique_ptr<KICAD_API_SERVER> m_api_server;
424#endif
425
426 wxString m_kicad_env;
427
428 wxLocale* m_locale;
430
432 wxString m_pdf_browser;
433
435
437
438#ifdef KICAD_USE_SENTRY
439 wxFileName m_sentry_optin_fn;
440 wxFileName m_sentry_uid_fn;
441 wxString m_sentryUid;
442#endif
443
450
452
453 wxSplashScreen* m_splash;
454
455 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
456 std::future<void> m_libraryPreloadReturn;
458 std::atomic_bool m_libraryPreloadAbort;
459
460 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
462};
463
464
473KICOMMON_API extern PGM_BASE& Pgm();
474
478
479KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
480
481
482#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:295
Container for data for KiCad programs.
Definition pgm_base.h:109
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:414
int m_argcUtf8
Definition pgm_base.h:451
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:412
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:390
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:403
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:411
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:505
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:186
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:460
wxLocale * m_locale
Definition pgm_base.h:428
void Destroy()
Definition pgm_base.cpp:185
wxSplashScreen * m_splash
Definition pgm_base.h:453
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allow access to the wxSingleInstanceChecker to test for other running KiCads.
Definition pgm_base.h:353
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:137
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:322
virtual const wxString & GetKicadEnvVariable() const
Definition pgm_base.h:178
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
Definition pgm_base.h:449
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:146
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:193
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:802
bool IsGUI()
Determine if the application is running with a GUI.
Definition pgm_base.cpp:793
bool m_use_system_pdf_browser
Definition pgm_base.h:431
bool m_Quitting
Definition pgm_base.h:394
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:456
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:142
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:455
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:277
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:184
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:458
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition pgm_base.h:419
virtual int GetSelectedLanguageIdentifier() const
Definition pgm_base.h:237
wxString m_pdf_browser
Filename of the app selected for browsing PDFs.
Definition pgm_base.h:432
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:392
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:426
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition pgm_base.h:201
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:121
void ShowSplash()
Definition pgm_base.cpp:292
wxString m_text_editor
Definition pgm_base.h:434
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:457
std::unique_ptr< SCRIPTING > m_python_scripting
Definition pgm_base.h:416
int m_language_id
Definition pgm_base.h:429
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:413
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:839
virtual wxLocale * GetLocale()
Definition pgm_base.h:182
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:131
void HideSplash()
Definition pgm_base.cpp:311
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:176
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:133
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition pgm_base.cpp:532
bool m_PropertyGridInitialized
Definition pgm_base.h:396
static const wxChar workingDirKey[]
Definition pgm_base.h:287
KICAD_SINGLETON m_singleton
Definition pgm_base.h:436
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:461
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define KICOMMON_API
Definition kicommon.h:28
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:95
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:75
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition pgm_base.h:80
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition pgm_base.h:86
wxString m_Lang_Label
Labels used in menus.
Definition pgm_base.h:83
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition pgm_base.h:77
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:53