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 <vector>
40#include <memory>
41#include <search_stack.h>
43#include <wx/filename.h>
44
45class wxApp;
46class wxMenu;
47class wxWindow;
48class wxSplashScreen;
49class wxSingleInstanceChecker;
50
51struct BACKGROUND_JOB;
54class COMMON_SETTINGS;
56class LIBRARY_MANAGER;
57class SCRIPTING;
58
59#ifdef KICAD_IPC_API
62#endif
63
85
86
91
106{
107public:
108 PGM_BASE();
109 virtual ~PGM_BASE();
110
114 void BuildArgvUtf8();
115
116 BS::thread_pool<0>& GetThreadPool() { return *m_singleton.m_ThreadPool; }
117
118 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
119
126 virtual void MacOpenFile( const wxString& aFileName ) = 0;
127
129
131
132 virtual COMMON_SETTINGS* GetCommonSettings() const;
133
138
143
144#ifdef KICAD_IPC_API
145 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
146
147 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
148#endif
149
150 virtual void SetTextEditor( const wxString& aFileName );
151
161 virtual const wxString& GetTextEditor( bool aCanShowFileChooser = true );
162
170 virtual const wxString AskUserForPreferredEditor(
171 const wxString& aDefaultEditor = wxEmptyString );
172
173 virtual bool IsKicadEnvVariableDefined() const { return !m_kicad_env.IsEmpty(); }
174
175 virtual const wxString& GetKicadEnvVariable() const { return m_kicad_env; }
176
177 virtual const wxString& GetExecutablePath() const;
178
179 virtual wxLocale* GetLocale() { return m_locale; }
180
181 virtual const wxString& GetPdfBrowserName() const { return m_pdf_browser; }
182
183 virtual void SetPdfBrowserName( const wxString& aFileName ) { m_pdf_browser = aFileName; }
184
190 virtual bool UseSystemPdfBrowser() const
191 {
192 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
193 }
194
198 virtual void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
199
210 virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
211
220 bool SetDefaultLanguage( wxString& aErrMsg );
221
229 virtual void SetLanguageIdentifier( int menu_id );
230
234 virtual int GetSelectedLanguageIdentifier() const { return m_language_id; }
235
239 virtual wxString GetLanguageTag();
240
241 virtual void SetLanguagePath();
242
246 virtual void ReadPdfBrowserInfos();
247
251 virtual void WritePdfBrowserInfos();
252
265 virtual bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
266
273 virtual void SetLocalEnvVariables();
274
275 virtual ENV_VAR_MAP& GetLocalEnvVariables() const;
276
282 virtual wxApp& App();
283
284 static const wxChar workingDirKey[];
285
301 bool InitPgm( bool aHeadless = false, bool aSkipPyInit = false, bool aIsUnitTest = false );
302
303 // The PGM_* classes can have difficulties at termination if they
304 // are not destroyed soon enough. Relying on a static destructor can be
305 // too late for contained objects like wxSingleInstanceChecker.
306 void Destroy();
307
311 void SaveCommonSettings();
312
320 void HandleException( std::exception_ptr aPtr );
321
333 void HandleAssert( const wxString& aFile, int aLine, const wxString& aFunc,
334 const wxString& aCond, const wxString& aMsg );
335
341 bool IsGUI();
342
343
344 void ShowSplash();
345 void HideSplash();
346
350 std::unique_ptr<wxSingleInstanceChecker>& SingleInstance()
351 {
352 return m_pgm_checker;
353 }
354
360 void PreloadDesignBlockLibraries( KIWAY* aKiway );
361
366
367 std::vector<void*> m_ModalDialogs;
368
370
372
373protected:
375 void loadCommonSettings();
376
378 void setLanguageId( int aId ) { m_language_id = aId; }
379
380#ifdef KICAD_USE_SENTRY
381 void sentryInit();
382 wxString sentryCreateUid();
383#endif
384
385protected:
386 std::unique_ptr<SETTINGS_MANAGER> m_settings_manager;
387 std::unique_ptr<LIBRARY_MANAGER> m_library_manager;
388 std::unique_ptr<BACKGROUND_JOBS_MONITOR> m_background_jobs_monitor;
389 std::unique_ptr<NOTIFICATIONS_MANAGER> m_notifications_manager;
390
391 std::unique_ptr<SCRIPTING> m_python_scripting;
392
394 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
395
396#ifdef KICAD_IPC_API
397 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
398 std::unique_ptr<KICAD_API_SERVER> m_api_server;
399#endif
400
401 wxString m_kicad_env;
402
403 wxLocale* m_locale;
405
407 wxString m_pdf_browser;
408
410
412
413#ifdef KICAD_USE_SENTRY
414 wxFileName m_sentry_optin_fn;
415 wxFileName m_sentry_uid_fn;
416 wxString m_sentryUid;
417#endif
418
425
427
428 wxSplashScreen* m_splash;
429
430 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
431 std::future<void> m_libraryPreloadReturn;
433 std::atomic_bool m_libraryPreloadAbort;
434};
435
436
445KICOMMON_API extern PGM_BASE& Pgm();
446
450
451KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
452
453
454#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:292
Container for data for KiCad programs.
Definition pgm_base.h:106
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:389
int m_argcUtf8
Definition pgm_base.h:426
std::unique_ptr< LIBRARY_MANAGER > m_library_manager
Definition pgm_base.h:387
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:365
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition pgm_base.h:378
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:386
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
Definition pgm_base.cpp:501
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition pgm_base.h:183
wxLocale * m_locale
Definition pgm_base.h:403
void Destroy()
Definition pgm_base.cpp:178
wxSplashScreen * m_splash
Definition pgm_base.h:428
std::unique_ptr< wxSingleInstanceChecker > & SingleInstance()
Allow access to the wxSingleInstanceChecker to test for other running KiCads.
Definition pgm_base.h:350
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
Definition pgm_base.h:134
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:308
virtual const wxString & GetKicadEnvVariable() const
Definition pgm_base.h:175
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
Definition pgm_base.h:424
virtual bool UseSystemPdfBrowser() const
Definition pgm_base.h:190
bool IsGUI()
Determine if the application is running with a GUI.
Definition pgm_base.cpp:789
bool m_use_system_pdf_browser
Definition pgm_base.h:406
bool m_Quitting
Definition pgm_base.h:369
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:431
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:139
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:430
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:263
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:181
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:433
BS::thread_pool< 0 > & GetThreadPool()
Definition pgm_base.h:116
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition pgm_base.h:394
virtual int GetSelectedLanguageIdentifier() const
Definition pgm_base.h:234
wxString m_pdf_browser
Filename of the app selected for browsing PDFs.
Definition pgm_base.h:407
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:367
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:401
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition pgm_base.h:198
GL_CONTEXT_MANAGER * GetGLContextManager()
Definition pgm_base.h:118
void ShowSplash()
Definition pgm_base.cpp:278
wxString m_text_editor
Definition pgm_base.h:409
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:432
std::unique_ptr< SCRIPTING > m_python_scripting
Definition pgm_base.h:391
int m_language_id
Definition pgm_base.h:404
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
Definition pgm_base.h:388
void HandleException(std::exception_ptr aPtr)
A exception handler to be used at the top level if exceptions bubble up that for.
Definition pgm_base.cpp:798
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:823
virtual wxLocale * GetLocale()
Definition pgm_base.h:179
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:128
void HideSplash()
Definition pgm_base.cpp:297
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:173
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:130
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition pgm_base.cpp:528
bool m_PropertyGridInitialized
Definition pgm_base.h:371
static const wxChar workingDirKey[]
Definition pgm_base.h:284
KICAD_SINGLETON m_singleton
Definition pgm_base.h:411
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
#define KICOMMON_API
Definition kicommon.h:28
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition pgm_base.cpp:94
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.
Definition pgm_base.cpp:954
KICOMMON_API void SetPgm(PGM_BASE *pgm)
Definition pgm_base.cpp:960
KICOMMON_API PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
A small class to handle the list of existing translations.
Definition pgm_base.h:72
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition pgm_base.h:77
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition pgm_base.h:83
wxString m_Lang_Label
Labels used in menus.
Definition pgm_base.h:80
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition pgm_base.h:74