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 <bs_thread_pool.hpp>
35#include <kicommon.h>
36#include <singleton.h>
37#include <exception>
38#include <map>
39#include <future>
40#include <mutex>
41#include <vector>
42#include <memory>
43#include <search_stack.h>
45#include <wx/filename.h>
46
47class wxApp;
48class wxMenu;
49class wxWindow;
50class wxSplashScreen;
51class wxSingleInstanceChecker;
52
53class KISTATUSBAR;
54struct LOAD_MESSAGE;
55struct BACKGROUND_JOB;
58class COMMON_SETTINGS;
60class LIBRARY_MANAGER;
61class SCRIPTING;
62
63#ifdef KICAD_IPC_API
66#endif
67
89
90
95
110{
111public:
112 PGM_BASE();
113 virtual ~PGM_BASE();
114
118 void BuildArgvUtf8();
119
121
122 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
123
130 virtual void MacOpenFile( const wxString& aFileName ) = 0;
131
133
135
136 virtual COMMON_SETTINGS* GetCommonSettings() const;
137
142
147
148#ifdef KICAD_IPC_API
149 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
150
151 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
152#endif
153
154 virtual void SetTextEditor( const wxString& aFileName );
155
165 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
166
174 virtual const wxString AskUserForPreferredEditor(
175 const wxString& aDefaultEditor = wxEmptyString );
176
177 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
178
179 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
180
181 virtual const wxString& GetExecutablePath() const;
182
183 virtual wxLocale* GetLocale() { return m_locale; }
184
185 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
186
187 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
188
194 virtual bool UseSystemPdfBrowser() const
195 {
196 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
197 }
198
202 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
203
214 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
215
224 bool SetDefaultLanguage( wxString& aErrMsg );
225
233 virtual void SetLanguageIdentifier( int menu_id );
234
238 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
239
243 virtual wxString GetLanguageTag();
244
245 virtual void SetLanguagePath();
246
250 virtual void ReadPdfBrowserInfos();
251
255 virtual void WritePdfBrowserInfos();
256
269 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
270
277 virtual void SetLocalEnvVariables();
278
279 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
280
286 virtual wxApp& App();
287
288 static const wxChar workingDirKey[];
289
305 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
306
307 // The PGM_* classes can have difficulties at termination if they
308 // are not destroyed soon enough. Relying on a static destructor can be
309 // too late for contained objects like wxSingleInstanceChecker.
310 void Destroy();
311
315 void SaveCommonSettings();
316
324 void HandleException( std::exception_ptr aPtr, bool aUnhandled = false );
325
337 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
338 const wxString& aCond, const wxString& aMsg );
339
345 bool IsGUI();
346
347
348 void ShowSplash();
349 void HideSplash();
350
354 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
355 {
356 return m_pgm_checker;
357 }
358
364 void PreloadDesignBlockLibraries( KIWAY* aKiway );
365
370 void RegisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
371
375 void UnregisterLibraryLoadStatusBar( KISTATUSBAR* aStatusBar );
376
381 void AddLibraryLoadMessages( const std::vector<LOAD_MESSAGE>& aMessages );
382
386 void ClearLibraryLoadMessages();
387
392
393 std::vector<void*> m_ModalDialogs;
394
396
398
399protected:
401 void loadCommonSettings();
402
404 void setLanguageId( int aId ) { m_language_id = aId; }
405
406#ifdef KICAD_USE_SENTRY
407 void sentryInit();
408 wxString sentryCreateUid();
409#endif
410
411protected:
412 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
413 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
414 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
415 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
416
417 std::unique_ptr<SCRIPTING> m_python_scripting;
418
420 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
421
422#ifdef KICAD_IPC_API
423 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
424 std::unique_ptr<KICAD_API_SERVER> m_api_server;
425#endif
426
427 wxString m_kicad_env;
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:294
Container for data for KiCad programs.
Definition pgm_base.h:110
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:415
int m_argcUtf8
Definition pgm_base.h:452
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:413
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:391
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:404
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:412
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:511
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:187
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:461
wxLocale * m_locale
Definition pgm_base.h:429
void Destroy()
Definition pgm_base.cpp:179
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:354
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:138
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:316
virtual const wxString & GetKicadEnvVariable() const
Definition pgm_base.h:179
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.h:120
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:194
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:808
bool IsGUI()
Determine if the application is running with a GUI.
Definition pgm_base.cpp:799
bool m_use_system_pdf_browser
Definition pgm_base.h:432
bool m_Quitting
Definition pgm_base.h:395
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:457
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:143
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:456
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:271
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:185
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:238
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:393
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:427
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition pgm_base.h:202
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:122
void ShowSplash()
Definition pgm_base.cpp:286
wxString m_text_editor
Definition pgm_base.h:435
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:458
std::unique_ptr< SCRIPTING > m_python_scripting
Definition pgm_base.h:417
int m_language_id
Definition pgm_base.h:430
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:414
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:845
virtual wxLocale * GetLocale()
Definition pgm_base.h:183
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:132
void HideSplash()
Definition pgm_base.cpp:305
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:177
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:134
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition pgm_base.cpp:538
bool m_PropertyGridInitialized
Definition pgm_base.h:397
static const wxChar workingDirKey[]
Definition pgm_base.h:288
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:28
thread_pool< 1 > priority_thread_pool
Definition singleton.h:32
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:76
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition pgm_base.h:81
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition pgm_base.h:87
wxString m_Lang_Label
Labels used in menus.
Definition pgm_base.h:84
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition pgm_base.h:78
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:53