KiCad PCB EDA Suite
PGM_BASE Class Referenceabstract

Container for data for KiCad programs. More...

#include <pgm_base.h>

Inheritance diagram for PGM_BASE:
PGM_KICAD PGM_SINGLE_TOP PGM_TEST_FRAME

Public Member Functions

 PGM_BASE ()
 
virtual ~PGM_BASE ()
 
void BuildArgvUtf8 ()
 Builds the UTF8 based argv variable. More...
 
virtual void MacOpenFile (const wxString &aFileName)=0
 Specific to MacOSX (not used under Linux or Windows). More...
 
virtual SETTINGS_MANAGERGetSettingsManager () const
 
virtual COMMON_SETTINGSGetCommonSettings () const
 
virtual void SetTextEditor (const wxString &aFileName)
 
virtual const wxString & GetTextEditor (bool aCanShowFileChooser=true)
 Return the path to the preferred text editor application. More...
 
virtual const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
virtual bool IsKicadEnvVariableDefined () const
 
virtual const wxString & GetKicadEnvVariable () const
 
virtual const wxString & GetExecutablePath () const
 
virtual wxLocale * GetLocale ()
 
virtual const wxString & GetPdfBrowserName () const
 
virtual void SetPdfBrowserName (const wxString &aFileName)
 
virtual bool UseSystemPdfBrowser () const
 
virtual void ForceSystemPdfBrowser (bool aFlg)
 Force the use of system PDF browser, even if a preferred PDF browser is set. More...
 
virtual bool SetLanguage (wxString &aErrMsg, bool first_time=false)
 Set the dictionary file name for internationalization. More...
 
bool SetDefaultLanguage (wxString &aErrMsg)
 Set the default language without reference to any preferences. More...
 
virtual void SetLanguageIdentifier (int menu_id)
 Set in .m_language_id member the wxWidgets language identifier ID from the KiCad menu id (internal menu identifier). More...
 
virtual int GetSelectedLanguageIdentifier () const
 
virtual wxString GetLanguageTag ()
 
virtual void SetLanguagePath ()
 
virtual void ReadPdfBrowserInfos ()
 Read the PDF browser choice from the common configuration. More...
 
virtual void WritePdfBrowserInfos ()
 Save the PDF browser choice to the common configuration. More...
 
virtual bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Sets the environment variable aName to aValue. More...
 
virtual void SetLocalEnvVariables ()
 Updates the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTINGS. More...
 
virtual ENV_VAR_MAPGetLocalEnvVariables () const
 
virtual wxApp & App ()
 Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm (bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
 Initialize this program. More...
 
void Destroy ()
 
void SaveCommonSettings ()
 Save the program (process) settings subset which are stored .kicad_common. More...
 

Public Attributes

bool m_Printing
 wxWidgets on MSW tends to crash if you spool up more than one print job at a time. More...
 
std::vector< void * > m_ModalDialogs
 
bool m_Quitting
 

Static Public Attributes

static const wxChar workingDirKey []
 

Protected Member Functions

void loadCommonSettings ()
 Loads internal settings from COMMON_SETTINGS. More...
 
void setLanguageId (int aId)
 Trap all changes in here, simplifies debugging. More...
 
bool setExecutablePath ()
 Find the path to the executable and stores it in PGM_BASE::m_bin_dir. More...
 

Protected Attributes

std::unique_ptr< SETTINGS_MANAGERm_settings_manager
 
std::unique_ptr< SCRIPTING > m_python_scripting
 
wxString m_bin_dir
 
wxString m_kicad_env
 full path to this program More...
 
wxLocale * m_locale
 The KICAD system environment variable. More...
 
int m_language_id
 
bool m_use_system_pdf_browser
 
wxString m_pdf_browser
 
wxString m_text_editor
 Filename of the app selected for browsing PDFs. More...
 
char ** m_argvUtf8
 
int m_argcUtf8
 argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either force converted to ascii in char* or wchar_t only More...
 

Detailed Description

Container for data for KiCad programs.

The functions are virtual so we can do cross module calls without linking to them. This used to be a wxApp derivative, but that is difficult under wxPython which shapes the wxApp. So now this is a "side-car" (like a motorcycle side-car) object with a back pointer into the wxApp which initializes it.

  • OnPgmStart() is virtual, may be overridden, and parallels wxApp::OnInit(), from where it should called.
  • OnPgmEnd() is virtual, may be overridden, and parallels wxApp::OnExit(), from where it should be called.

Definition at line 94 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 124 of file pgm_base.cpp.

125{
126 m_locale = nullptr;
127 m_Printing = false;
128 m_Quitting = false;
129 m_argcUtf8 = 0;
130 m_argvUtf8 = nullptr;
131
132 setLanguageId( wxLANGUAGE_DEFAULT );
133
134 ForceSystemPdfBrowser( false );
135}
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:360
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:309
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:320
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:343
char ** m_argvUtf8
Definition: pgm_base.h:357
bool m_Quitting
Definition: pgm_base.h:313
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:187

References ForceSystemPdfBrowser(), m_argcUtf8, m_argvUtf8, m_locale, m_Printing, m_Quitting, and setLanguageId().

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 138 of file pgm_base.cpp.

139{
140 Destroy();
141
142 for( int n = 0; n < m_argcUtf8; n++ )
143 {
144 free( m_argvUtf8[n] );
145 }
146
147 delete[] m_argvUtf8;
148}
void Destroy()
Definition: pgm_base.cpp:151

References Destroy(), m_argcUtf8, and m_argvUtf8.

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
virtual

Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.

This should return what wxGetApp() returns.

Definition at line 163 of file pgm_base.cpp.

164{
165 wxASSERT( wxTheApp );
166 return *wxTheApp;
167}

Referenced by BuildArgvUtf8(), InitPgm(), PGM_SINGLE_TOP::MacOpenFile(), PGM_KICAD::MacOpenFile(), PGM_TEST_FRAME::MacOpenFile(), and PGM_KICAD::OnPgmInit().

◆ AskUserForPreferredEditor()

const wxString PGM_BASE::AskUserForPreferredEditor ( const wxString &  aDefaultEditor = wxEmptyString)
virtual

Shows a dialog that instructs the user to select a new preferred editor.

Parameters
aDefaultEditorDefault full path for the default editor this dialog should show by default.
Returns
Returns the full path of the editor, or an empty string if no editor was chosen.

Definition at line 213 of file pgm_base.cpp.

214{
215 // Create a mask representing the executable files in the current platform
216#ifdef __WINDOWS__
217 wxString mask( _( "Executable file" ) + wxT( " (*.exe)|*.exe" ) );
218#else
219 wxString mask( _( "Executable file" ) + wxT( " (*)|*" ) );
220#endif
221
222 // Extract the path, name and extension from the default editor (even if the editor's
223 // name was empty, this method will succeed and return empty strings).
224 wxString path, name, ext;
225 wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
226
227 // Show the modal editor and return the file chosen (may be empty if the user cancels
228 // the dialog).
229 return wxFileSelector( _( "Select Preferred Editor" ), path, name, wxT( "." ) + ext,
230 mask, wxFD_OPEN | wxFD_FILE_MUST_EXIST, nullptr );
231}
const char * name
Definition: DXF_plotter.cpp:56
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:121

References _, name, and path.

Referenced by GetTextEditor().

◆ BuildArgvUtf8()

void PGM_BASE::BuildArgvUtf8 ( )

Builds the UTF8 based argv variable.

Definition at line 383 of file pgm_base.cpp.

384{
385 const wxArrayString& argArray = App().argv.GetArguments();
386 m_argcUtf8 = argArray.size();
387
388 m_argvUtf8 = new char*[m_argcUtf8 + 1];
389 for( int n = 0; n < m_argcUtf8; n++ )
390 {
391 m_argvUtf8[n] = wxStrdup( argArray[n].ToUTF8() );
392 }
393
394 m_argvUtf8[m_argcUtf8] = NULL; // null terminator at end of argv
395}
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:163

References App(), m_argcUtf8, and m_argvUtf8.

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 151 of file pgm_base.cpp.

152{
153#ifdef KICAD_USE_SENTRY
154 sentry_close();
155#endif
156
157 // unlike a normal destructor, this is designed to be called more than once safely:
158 delete m_locale;
159 m_locale = nullptr;
160}

References m_locale.

Referenced by PGM_KICAD::Destroy(), PGM_SINGLE_TOP::OnPgmExit(), PGM_TEST_FRAME::OnPgmExit(), and ~PGM_BASE().

◆ ForceSystemPdfBrowser()

virtual void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlinevirtual

Force the use of system PDF browser, even if a preferred PDF browser is set.

Definition at line 187 of file pgm_base.h.

187{ m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
Definition: pgm_base.h:346

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 615 of file pgm_base.cpp.

616{
617 return m_settings_manager ? m_settings_manager->GetCommonSettings() : nullptr;
618}
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:336

References m_settings_manager.

Referenced by GetLocalEnvVariables(), InitPgm(), loadCommonSettings(), ReadPdfBrowserInfos(), SaveCommonSettings(), SetLanguage(), SetLocalEnvVariables(), SetTextEditor(), and WritePdfBrowserInfos().

◆ GetExecutablePath()

virtual const wxString & PGM_BASE::GetExecutablePath ( ) const
inlinevirtual

Definition at line 166 of file pgm_base.h.

166{ return m_bin_dir; }
wxString m_bin_dir
Definition: pgm_base.h:340

References m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit(), and SetLanguagePath().

◆ GetKicadEnvVariable()

virtual const wxString & PGM_BASE::GetKicadEnvVariable ( ) const
inlinevirtual

Definition at line 164 of file pgm_base.h.

164{ return m_kicad_env; }
wxString m_kicad_env
full path to this program
Definition: pgm_base.h:341

References m_kicad_env.

◆ GetLanguageTag()

wxString PGM_BASE::GetLanguageTag ( )
virtual
Returns
the current selected language in rfc3066 format

Definition at line 778 of file pgm_base.cpp.

779{
780 const wxLanguageInfo* langInfo = wxLocale::GetLanguageInfo( m_language_id );
781
782 if( !langInfo )
783 return "";
784 else
785 {
786 #if wxCHECK_VERSION( 3, 1, 6 )
787 wxString str = langInfo->GetCanonicalWithRegion();
788 #else
789 wxString str = langInfo->CanonicalName;
790 #endif
791 str.Replace( "_", "-" );
792
793 return str;
794 }
795}
int m_language_id
Definition: pgm_base.h:344

References m_language_id.

◆ GetLocale()

virtual wxLocale * PGM_BASE::GetLocale ( )
inlinevirtual

Definition at line 168 of file pgm_base.h.

168{ return m_locale; }

References m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtual

Definition at line 856 of file pgm_base.cpp.

857{
858 return GetCommonSettings()->m_Env.vars;
859}
ENVIRONMENT m_Env
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:615

References GetCommonSettings(), COMMON_SETTINGS::m_Env, and COMMON_SETTINGS::ENVIRONMENT::vars.

Referenced by FILENAME_RESOLVER::GetKicadPaths(), and PGM_KICAD::OnPgmInit().

◆ GetPdfBrowserName()

virtual const wxString & PGM_BASE::GetPdfBrowserName ( ) const
inlinevirtual

Definition at line 170 of file pgm_base.h.

170{ return m_pdf_browser; }
wxString m_pdf_browser
Definition: pgm_base.h:347

References m_pdf_browser.

Referenced by WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

virtual int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inlinevirtual
Returns
the wxWidgets language identifier Id of the language currently selected.

Definition at line 221 of file pgm_base.h.

221{ return m_language_id; }

References m_language_id.

◆ GetSettingsManager()

◆ GetTextEditor()

const wxString & PGM_BASE::GetTextEditor ( bool  aCanShowFileChooser = true)
virtual

Return the path to the preferred text editor application.

Parameters
aCanShowFileChooserIf no editor is currently set and this argument is 'true' then this method will show a file chooser dialog asking for the editor's executable.
Returns
Returns the full path of the editor, or an empty string if no editor has been set.

Definition at line 177 of file pgm_base.cpp.

178{
179 wxString editorname = m_text_editor;
180
181 if( !editorname )
182 {
183 if( !wxGetEnv( wxT( "EDITOR" ), &editorname ) )
184 {
185 // If there is no EDITOR variable set, try the desktop default
186#ifdef __WXMAC__
187 editorname = wxT( "/usr/bin/open -e" );
188#elif __WXX11__
189 editorname = wxT( "/usr/bin/xdg-open" );
190#endif
191 }
192 }
193
194 // If we still don't have an editor name show a dialog asking the user to select one
195 if( !editorname && aCanShowFileChooser )
196 {
197 DisplayInfoMessage( nullptr, _( "No default editor found, you must choose one." ) );
198
199 editorname = AskUserForPreferredEditor();
200 }
201
202 // If we finally have a new editor name request it to be copied to m_text_editor and
203 // saved to the preferences file.
204 if( !editorname.IsEmpty() )
205 SetTextEditor( editorname );
206
207 // m_text_editor already has the same value that editorname, or empty if no editor was
208 // found/chosen.
209 return m_text_editor;
210}
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:170
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:349
virtual const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:213
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:352

References _, AskUserForPreferredEditor(), DisplayInfoMessage(), m_text_editor, and SetTextEditor().

◆ InitPgm()

bool PGM_BASE::InitPgm ( bool  aHeadless = false,
bool  aSkipPyInit = false,
bool  aIsUnitTest = false 
)

Initialize this program.

Initialize the process in a KiCad standard way using some generalized techniques:

  • Default paths (help, libs, bin) and configuration file names
  • Language and locale
  • fonts
Note
Do not initialize anything relating to DSOs or projects.
Parameters
aHeadlessIf true, run in headless mode (e.g. for unit tests)
aSkipPyInitIf true, do not init python stuff. Useful in application that do not use python, to disable python dependency at run time
Returns
true if success, false if failure and program is to terminate.

Should never happen but boost unit_test isn't playing nicely in some cases

Definition at line 398 of file pgm_base.cpp.

399{
400#if defined( __WXMAC__ )
401 // Set the application locale to the system default
402 wxLogNull noLog;
403 wxLocale loc;
404 loc.Init();
405#endif
406
407 // Just make sure we init precreate any folders early for later code
408 // In particular, the user cache path is the most likely to be hit by startup code
410
411#ifdef KICAD_USE_SENTRY
412 sentryInit();
413#endif
414 wxString pgm_name;
415
417 if( App().argc == 0 )
418 pgm_name = wxT( "kicad" );
419 else
420 pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
421
422#ifdef KICAD_USE_SENTRY
423 sentry_set_tag( "kicad.app", pgm_name.c_str() );
424#endif
425
426 wxInitAllImageHandlers();
427
428 // Without this the wxPropertyGridManager segfaults on Windows.
429 if( !wxPGGlobalVars )
430 wxPGInitResourceModule();
431
432#ifndef __WINDOWS__
433 if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
434 {
435 DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
436 "Unable to continue." ) );
437 return false;
438 }
439#endif
440
441 // Init KiCad environment
442 // the environment variable KICAD (if exists) gives the kicad path:
443 // something like set KICAD=d:\kicad
444 bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_kicad_env );
445
446 if( isDefined ) // ensure m_kicad_env ends by "/"
447 {
449
450 if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
452 }
453
454 // Init parameters for configuration
455 App().SetVendorName( wxT( "KiCad" ) );
456 App().SetAppName( pgm_name );
457
458 // Install some image handlers, mainly for help
459 if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr )
460 wxImage::AddHandler( new wxPNGHandler );
461
462 if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr )
463 wxImage::AddHandler( new wxGIFHandler );
464
465 if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr )
466 wxImage::AddHandler( new wxJPEGHandler );
467
468 wxFileSystem::AddHandler( new wxZipFSHandler );
469
470 // Analyze the command line & initialize the binary path
471 wxString tmp;
474 SetDefaultLanguage( tmp );
475
476 m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
477
478 // Our unit test mocks break if we continue
479 // A bug caused InitPgm to terminate early in unit tests and the mocks are...simplistic
480 // TODO fix the unit tests so this can be removed
481 if( aIsUnitTest )
482 return false;
483
484 // Something got in the way of settings load: can't continue
485 if( !m_settings_manager->IsOK() )
486 return false;
487
488 // Set up built-in environment variables (and override them from the system environment if set)
490
491 // Load color settings after env is initialized
492 m_settings_manager->ReloadColorSettings();
493
494 // Load common settings from disk after setting up env vars
496
497 // Init user language *before* calling loadSettings, because
498 // env vars could be incorrectly initialized on Linux
499 // (if the value contains some non ASCII7 chars, the env var is not initialized)
500 SetLanguage( tmp, true );
501
502 // Now that translations are available, inform the user if the OS is unsupported
504
506
507#ifdef KICAD_USE_SENTRY
508 sentryPrompt();
509#endif
510
511 ReadPdfBrowserInfos(); // needs GetCommonSettings()
512
513 // Create the python scripting stuff
514 // Skip it fot applications that do not use it
515 if( !aSkipPyInit )
516 m_python_scripting = std::make_unique<SCRIPTING>();
517
518 // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
519 // Need to create a project early for now (it can have an empty path for the moment)
521
522 // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
523 // Windows as other platforms display tooltips while the mouse is not moving
524 if( !aHeadless )
525 {
526 wxToolTip::Enable( true );
527 wxToolTip::SetAutoPop( 10000 );
528 }
529
530 if( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval != 0 )
531 wxUpdateUIEvent::SetUpdateInterval( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval );
532
533 return true;
534}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
static void EnsureUserPathsExist()
Ensures/creates user default paths.
Definition: paths.cpp:369
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:537
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:579
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:37
virtual void SetLanguagePath()
Definition: pgm_base.cpp:798
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:721
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:338
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:135
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:621
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition: common.cpp:635
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:36
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:35
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars

References _, App(), DisplayErrorMessage(), PATHS::EnsureUserPathsExist(), ADVANCED_CFG::GetCfg(), GetCommonSettings(), GetSettingsManager(), COMMON_SETTINGS::InitializeEnvironment(), SETTINGS_MANAGER::Load(), loadCommonSettings(), SETTINGS_MANAGER::LoadProject(), m_kicad_env, m_python_scripting, m_settings_manager, ReadPdfBrowserInfos(), SetDefaultLanguage(), setExecutablePath(), SetLanguage(), SetLanguagePath(), UNIX_STRING_DIR_SEP, WarnUserIfOperatingSystemUnsupported(), WIN_STRING_DIR_SEP, and wxPGGlobalVars.

Referenced by PGM_KICAD::OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtual

Definition at line 162 of file pgm_base.h.

162{ return !m_kicad_env.IsEmpty(); }

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 579 of file pgm_base.cpp.

580{
582
583 for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
584 {
585 wxLogTrace( traceEnvVars, wxT( "PGM_BASE::loadSettings: Found entry %s = %s" ),
586 it.first, it.second.GetValue() );
587
588 // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
589 // it is found in config. (It is reserved and defined as project path)
590 if( it.first == PROJECT_VAR_NAME )
591 continue;
592
593 // Don't set bogus empty entries in the environment
594 if( it.first.IsEmpty() )
595 continue;
596
597 // Do not overwrite vars set by the system environment with values from the settings file
598 if( it.second.GetDefinedExternally() )
599 continue;
600
601 SetLocalEnvVariable( it.first, it.second.GetValue() );
602 }
603}
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:812
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:39

References GetCommonSettings(), COMMON_SETTINGS::m_System, m_text_editor, PROJECT_VAR_NAME, SetLocalEnvVariable(), COMMON_SETTINGS::SYSTEM::text_editor, and traceEnvVars.

Referenced by InitPgm().

◆ MacOpenFile()

virtual void PGM_BASE::MacOpenFile ( const wxString &  aFileName)
pure virtual

Specific to MacOSX (not used under Linux or Windows).

MacOSX requires it for file association.

See also
http://wiki.wxwidgets.org/WxMac-specific_topics

Implemented in PGM_SINGLE_TOP, PGM_KICAD, and PGM_TEST_FRAME.

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
virtual

Read the PDF browser choice from the common configuration.

Definition at line 37 of file eda_doc.cpp.

38{
39 SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
41}
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:172

References GetCommonSettings(), COMMON_SETTINGS::m_System, m_use_system_pdf_browser, SetPdfBrowserName(), and COMMON_SETTINGS::SYSTEM::use_system_pdf_viewer.

Referenced by InitPgm().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )

Save the program (process) settings subset which are stored .kicad_common.

Definition at line 606 of file pgm_base.cpp.

607{
608 // GetCommonSettings() is not initialized until fairly late in the
609 // process startup: InitPgm(), so test before using:
610 if( GetCommonSettings() )
611 GetCommonSettings()->m_System.working_dir = wxGetCwd();
612}

References GetCommonSettings(), COMMON_SETTINGS::m_System, and COMMON_SETTINGS::SYSTEM::working_dir.

Referenced by PGM_SINGLE_TOP::OnPgmExit(), and PGM_KICAD::OnPgmExit().

◆ SetDefaultLanguage()

bool PGM_BASE::SetDefaultLanguage ( wxString &  aErrMsg)

Set the default language without reference to any preferences.

Can be used to set the language for dialogs that show before preferences are loaded

Parameters
aErrMsgString to return the error message(s) in
Returns
false if the language could not be set

Definition at line 721 of file pgm_base.cpp.

722{
723 // Suppress error popups from wxLocale
724 wxLogNull doNotLog;
725
726 setLanguageId( wxLANGUAGE_DEFAULT );
727
728 // dictionary file name without extend (full name is kicad.mo)
729 wxString dictionaryName( wxT( "kicad" ) );
730
731 delete m_locale;
732 m_locale = new wxLocale;
733 m_locale->Init();
734
735 // Try adding the dictionary if it is not currently loaded
736 if( !m_locale->IsLoaded( dictionaryName ) )
737 m_locale->AddCatalog( dictionaryName );
738
739 // Verify the Kicad dictionary was loaded properly
740 // However, for the English language, the dictionary is not mandatory, as
741 // all messages are already in English, just restricted to ASCII7 chars,
742 // the verification is skipped.
743 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
744 {
745 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
746 dictionaryName, m_locale->GetName() );
747
748 setLanguageId( wxLANGUAGE_DEFAULT );
749 delete m_locale;
750
751 m_locale = new wxLocale;
752 m_locale->Init();
753
754 aErrMsg = _( "The KiCad language file for this language is not installed." );
755 return false;
756 }
757
758 return true;
759}
const wxChar *const traceLocale
Flag to enable locale debug output.

References _, m_language_id, m_locale, setLanguageId(), and traceLocale.

Referenced by InitPgm().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protected

Find the path to the executable and stores it in PGM_BASE::m_bin_dir.

Returns
true if success, else false.

Definition at line 537 of file pgm_base.cpp.

538{
539 m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
540
541#ifdef __WXMAC__
542 // On OSX Pgm().GetExecutablePath() will always point to main
543 // bundle directory, e.g., /Applications/kicad.app/
544
545 wxFileName fn( m_bin_dir );
546
547 if( fn.GetName() == wxT( "kicad" ) || fn.GetName() == wxT( "kicad-cli" ) )
548 {
549 // kicad launcher, so just remove the Contents/MacOS part
550 fn.RemoveLastDir();
551 fn.RemoveLastDir();
552 }
553 else
554 {
555 // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
556 fn.RemoveLastDir();
557 fn.RemoveLastDir();
558 fn.RemoveLastDir();
559 fn.RemoveLastDir();
560 fn.RemoveLastDir();
561 }
562
563 m_bin_dir = fn.GetPath() + wxT( "/" );
564#else
565 // Use unix notation for paths. I am not sure this is a good idea,
566 // but it simplifies compatibility between Windows and Unices.
567 // However it is a potential problem in path handling under Windows.
569
570 // Remove file name form command line:
571 while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
572 m_bin_dir.RemoveLast();
573#endif
574
575 return true;
576}

References m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( wxString &  aErrMsg,
bool  first_time = false 
)
virtual

Set the dictionary file name for internationalization.

The files are in kicad/internat/xx or kicad/internat/xx_XX and are named kicad.mo

Parameters
aErrMsgis the string to return the error message it.
first_timemust be set to true the first time this function is called, false otherwise.
Returns
false if there was an error setting the language.

Definition at line 621 of file pgm_base.cpp.

622{
623 // Suppress wxWidgets error popups if locale is not found
624 wxLogNull doNotLog;
625
626 if( first_time )
627 {
628 setLanguageId( wxLANGUAGE_DEFAULT );
629 // First time SetLanguage is called, the user selected language id is set
630 // from common user config settings
631 wxString languageSel = GetCommonSettings()->m_System.language;
632
633 // Search for the current selection
634 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
635 {
636 if( LanguagesList[ii].m_Lang_Label == languageSel )
637 {
638 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
639 break;
640 }
641 }
642 }
643
644 // dictionary file name without extend (full name is kicad.mo)
645 wxString dictionaryName( wxT( "kicad" ) );
646
647 delete m_locale;
648 m_locale = new wxLocale;
649
650 // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
651 // false just because it failed to load wxstd catalog
652 if( !m_locale->Init( m_language_id, wxLOCALE_DONT_LOAD_DEFAULT ) )
653 {
654 wxLogTrace( traceLocale, wxT( "This language is not supported by the system." ) );
655
656 setLanguageId( wxLANGUAGE_DEFAULT );
657 delete m_locale;
658
659 m_locale = new wxLocale;
660 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
661
662 aErrMsg = _( "This language is not supported by the operating system." );
663 return false;
664 }
665 else if( !first_time )
666 {
667 wxLogTrace( traceLocale, wxT( "Search for dictionary %s.mo in %s" ) ,
668 dictionaryName, m_locale->GetName() );
669 }
670
671 if( !first_time )
672 {
673 // If we are here, the user has selected another language.
674 // Therefore the new preferred language name is stored in common config.
675 // Do NOT store the wxWidgets language Id, it can change between wxWidgets
676 // versions, for a given language
677 wxString languageSel;
678
679 // Search for the current selection language name
680 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
681 {
682 if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
683 {
684 languageSel = LanguagesList[ii].m_Lang_Label;
685 break;
686 }
687 }
688
690 cfg->m_System.language = languageSel;
691 cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
692 }
693
694 // Try adding the dictionary if it is not currently loaded
695 if( !m_locale->IsLoaded( dictionaryName ) )
696 m_locale->AddCatalog( dictionaryName );
697
698 // Verify the Kicad dictionary was loaded properly
699 // However, for the English language, the dictionary is not mandatory, as
700 // all messages are already in English, just restricted to ASCII7 chars,
701 // the verification is skipped.
702 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
703 {
704 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
705 dictionaryName, m_locale->GetName() );
706
707 setLanguageId( wxLANGUAGE_DEFAULT );
708 delete m_locale;
709
710 m_locale = new wxLocale;
711 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
712
713 aErrMsg = _( "The KiCad language file for this language is not installed." );
714 return false;
715 }
716
717 return true;
718}
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:85
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:66
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:69

References _, GetCommonSettings(), GetSettingsManager(), COMMON_SETTINGS::SYSTEM::language, LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, m_language_id, m_locale, COMMON_SETTINGS::m_System, JSON_SETTINGS::SaveToFile(), setLanguageId(), and traceLocale.

Referenced by InitPgm().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotected

Trap all changes in here, simplifies debugging.

Definition at line 320 of file pgm_base.h.

320{ m_language_id = aId; }

References m_language_id.

Referenced by PGM_BASE(), SetDefaultLanguage(), SetLanguage(), and SetLanguageIdentifier().

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
virtual

Set in .m_language_id member the wxWidgets language identifier ID from the KiCad menu id (internal menu identifier).

Parameters
menu_idThe KiCad menuitem id (returned by Menu Event, when clicking on a menu item)

Definition at line 762 of file pgm_base.cpp.

763{
764 wxLogTrace( traceLocale, wxT( "Select language ID %d from %d possible languages." ),
765 menu_id, (int)arrayDim( LanguagesList )-1 );
766
767 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
768 {
769 if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
770 {
771 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
772 break;
773 }
774 }
775}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31

References arrayDim(), LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, setLanguageId(), and traceLocale.

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtual

Definition at line 798 of file pgm_base.cpp.

799{
800 wxLocale::AddCatalogLookupPathPrefix( PATHS::GetLocaleDataPath() );
801
802 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
803 {
804 wxFileName fn( Pgm().GetExecutablePath() );
805 fn.RemoveLastDir();
806 fn.AppendDir( wxT( "translation" ) );
807 wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
808 }
809}
static wxString GetLocaleDataPath()
Gets the locales translation data path.
Definition: paths.cpp:252
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:166
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References GetExecutablePath(), PATHS::GetLocaleDataPath(), and Pgm().

Referenced by InitPgm().

◆ SetLocalEnvVariable()

bool PGM_BASE::SetLocalEnvVariable ( const wxString &  aName,
const wxString &  aValue 
)
virtual

Sets the environment variable aName to aValue.

This function first checks to see if the environment variable aName is already defined. If it is not defined, then the environment variable aName is set to a value. Otherwise, the environment variable is left unchanged. This allows the user to override environment variables for testing purposes.

Parameters
aNameis a wxString containing the environment variable name.
aValueis a wxString containing the environment variable value.
Returns
true if the environment variable Name was set to aValue.

Definition at line 812 of file pgm_base.cpp.

813{
814 wxString env;
815
816 if( aName.IsEmpty() )
817 {
818 wxLogTrace( traceEnvVars,
819 wxT( "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s" ),
820 aValue );
821 return false;
822 }
823
824 // Check to see if the environment variable is already set.
825 if( wxGetEnv( aName, &env ) )
826 {
827 wxLogTrace( traceEnvVars,
828 wxT( "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s" ),
829 aName, env );
830 return env == aValue;
831 }
832
833 wxLogTrace( traceEnvVars,
834 wxT( "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
835 aName, aValue );
836
837 return wxSetEnv( aName, aValue );
838}

References traceEnvVars.

Referenced by loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( )
virtual

Updates the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTINGS.

See also
GetLocalEnvVariables()

Definition at line 841 of file pgm_base.cpp.

842{
843 // Overwrites externally defined environment variable until the next time the application
844 // is run.
845 for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
846 {
847 wxLogTrace( traceEnvVars,
848 wxT( "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s" ),
849 m_local_env_var.first,
850 m_local_env_var.second.GetValue() );
851 wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
852 }
853}

References GetCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

virtual void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inlinevirtual

Definition at line 172 of file pgm_base.h.

172{ m_pdf_browser = aFileName; }

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ SetTextEditor()

void PGM_BASE::SetTextEditor ( const wxString &  aFileName)
virtual

Definition at line 170 of file pgm_base.cpp.

171{
172 m_text_editor = aFileName;
174}

References GetCommonSettings(), COMMON_SETTINGS::m_System, m_text_editor, and COMMON_SETTINGS::SYSTEM::text_editor.

Referenced by GetTextEditor().

◆ UseSystemPdfBrowser()

virtual bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlinevirtual
Returns
true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser.

Definition at line 179 of file pgm_base.h.

180 {
181 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
182 }

References m_pdf_browser, and m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtual

Member Data Documentation

◆ m_argcUtf8

int PGM_BASE::m_argcUtf8
protected

argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either force converted to ascii in char* or wchar_t only

Definition at line 360 of file pgm_base.h.

Referenced by BuildArgvUtf8(), PGM_BASE(), and ~PGM_BASE().

◆ m_argvUtf8

char** PGM_BASE::m_argvUtf8
protected

Definition at line 357 of file pgm_base.h.

Referenced by BuildArgvUtf8(), PGM_BASE(), and ~PGM_BASE().

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protected

Definition at line 340 of file pgm_base.h.

Referenced by GetExecutablePath(), and setExecutablePath().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protected

full path to this program

Definition at line 341 of file pgm_base.h.

Referenced by GetKicadEnvVariable(), InitPgm(), and IsKicadEnvVariableDefined().

◆ m_language_id

int PGM_BASE::m_language_id
protected

◆ m_locale

wxLocale* PGM_BASE::m_locale
protected

The KICAD system environment variable.

Definition at line 343 of file pgm_base.h.

Referenced by Destroy(), GetLocale(), PGM_BASE(), SetDefaultLanguage(), and SetLanguage().

◆ m_ModalDialogs

std::vector<void*> PGM_BASE::m_ModalDialogs

Definition at line 311 of file pgm_base.h.

Referenced by APP_KICAD::FilterEvent(), and APP_KICAD_CLI::FilterEvent().

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protected

Definition at line 347 of file pgm_base.h.

Referenced by GetPdfBrowserName(), SetPdfBrowserName(), and UseSystemPdfBrowser().

◆ m_Printing

bool PGM_BASE::m_Printing

wxWidgets on MSW tends to crash if you spool up more than one print job at a time.

Definition at line 309 of file pgm_base.h.

Referenced by BOARD::ComputeBoundingBox(), and PGM_BASE().

◆ m_python_scripting

std::unique_ptr<SCRIPTING> PGM_BASE::m_python_scripting
protected

Definition at line 338 of file pgm_base.h.

Referenced by InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting

Definition at line 313 of file pgm_base.h.

Referenced by PGM_BASE().

◆ m_settings_manager

std::unique_ptr<SETTINGS_MANAGER> PGM_BASE::m_settings_manager
protected

◆ m_text_editor

wxString PGM_BASE::m_text_editor
protected

Filename of the app selected for browsing PDFs.

Definition at line 349 of file pgm_base.h.

Referenced by GetTextEditor(), loadCommonSettings(), and SetTextEditor().

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protected

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
static

Definition at line 270 of file pgm_base.h.


The documentation for this class was generated from the following files: