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;
60
61#ifdef KICAD_IPC_API
64#endif
65
87
88
93
108{
109public:
110 PGM_BASE();
111 virtual ~PGM_BASE();
112
116 void BuildArgvUtf8();
117
119
120 GL_CONTEXT_MANAGER* GetGLContextManager() { return m_singleton.m_GLContextManager; }
121
128 virtual void MacOpenFile( const wxString& aFileName ) = 0;
129
131
133
134 virtual COMMON_SETTINGS* GetCommonSettings() const;
135
140
145
146#ifdef KICAD_IPC_API
147 virtual API_PLUGIN_MANAGER& GetPluginManager() const { return *m_plugin_manager; }
148
149 KICAD_API_SERVER& GetApiServer() { return *m_api_server; }
150
151 KICAD_API_SERVER* ApiServerOrNull() const { return m_api_server.get(); }
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
304 bool InitPgm( bool aHeadless = 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
417 std::unique_ptr<wxSingleInstanceChecker> m_pgm_checker;
418
419#ifdef KICAD_IPC_API
420 std::unique_ptr<API_PLUGIN_MANAGER> m_plugin_manager;
421 std::unique_ptr<KICAD_API_SERVER> m_api_server;
422#endif
423
424 wxString m_kicad_env;
425
426 wxLocale* m_locale;
428
430 wxString m_pdf_browser;
431
433
435
436#ifdef KICAD_USE_SENTRY
437 wxFileName m_sentry_optin_fn;
438 wxFileName m_sentry_uid_fn;
439 wxString m_sentryUid;
440#endif
441
448
450
451 wxSplashScreen* m_splash;
452
453 std::shared_ptr<BACKGROUND_JOB> m_libraryPreloadBackgroundJob;
454 std::future<void> m_libraryPreloadReturn;
456 std::atomic_bool m_libraryPreloadAbort;
457
458 std::vector<KISTATUSBAR*> m_libraryLoadStatusBars;
460};
461
462
471KICOMMON_API extern PGM_BASE& Pgm();
472
476
477KICOMMON_API extern void SetPgm( PGM_BASE* pgm );
478
479
480#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:315
Container for data for KiCad programs.
Definition pgm_base.h:108
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
Definition pgm_base.h:414
int m_argcUtf8
Definition pgm_base.h:449
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:187
std::vector< KISTATUSBAR * > m_libraryLoadStatusBars
Definition pgm_base.h:458
wxLocale * m_locale
Definition pgm_base.h:426
void Destroy()
Definition pgm_base.cpp:190
wxSplashScreen * m_splash
Definition pgm_base.h:451
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:136
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:447
BS::priority_thread_pool & GetThreadPool()
Definition pgm_base.cpp:151
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: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:429
bool m_Quitting
Definition pgm_base.h:394
std::future< void > m_libraryPreloadReturn
Definition pgm_base.h:454
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
Definition pgm_base.h:141
std::shared_ptr< BACKGROUND_JOB > m_libraryPreloadBackgroundJob
Definition pgm_base.h:453
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
Definition pgm_base.cpp:282
virtual const wxString & GetPdfBrowserName() const
Definition pgm_base.h:185
std::atomic_bool m_libraryPreloadAbort
Definition pgm_base.h:456
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
Definition pgm_base.h:417
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:430
std::vector< void * > m_ModalDialogs
Definition pgm_base.h:392
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
Definition pgm_base.cpp:327
wxString m_kicad_env
The KICAD system environment variable.
Definition pgm_base.h:424
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:120
void ShowSplash()
Definition pgm_base.cpp:297
wxString m_text_editor
Definition pgm_base.h:432
std::atomic_bool m_libraryPreloadInProgress
Definition pgm_base.h:455
int m_language_id
Definition pgm_base.h:427
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:183
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:130
void HideSplash()
Definition pgm_base.cpp:316
virtual bool IsKicadEnvVariableDefined() const
Definition pgm_base.h:177
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:132
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:288
KICAD_SINGLETON m_singleton
Definition pgm_base.h:434
std::mutex m_libraryLoadStatusBarsMutex
Definition pgm_base.h:459
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: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.
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:74
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition pgm_base.h:79
bool m_DoNotTranslate
Set to true if the m_Lang_Label must not be translated.
Definition pgm_base.h:85
wxString m_Lang_Label
Labels used in menus.
Definition pgm_base.h:82
int m_WX_Lang_Identifier
wxWidgets locale identifier (See wxWidgets doc)
Definition pgm_base.h:76
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:54