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 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...
 
int m_ModalDialogCount
 
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 93 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 121 of file pgm_base.cpp.

122{
123 m_locale = nullptr;
124 m_Printing = false;
125 m_Quitting = false;
127 m_argcUtf8 = 0;
128 m_argvUtf8 = nullptr;
129
130 setLanguageId( wxLANGUAGE_DEFAULT );
131
132 ForceSystemPdfBrowser( false );
133}
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:354
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:303
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:314
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:337
char ** m_argvUtf8
Definition: pgm_base.h:351
bool m_Quitting
Definition: pgm_base.h:307
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:186
int m_ModalDialogCount
Definition: pgm_base.h:305

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

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 136 of file pgm_base.cpp.

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

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 161 of file pgm_base.cpp.

162{
163 wxASSERT( wxTheApp );
164 return *wxTheApp;
165}

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 211 of file pgm_base.cpp.

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

References _, name, and path.

Referenced by GetTextEditor().

◆ BuildArgvUtf8()

void PGM_BASE::BuildArgvUtf8 ( )

Builds the UTF8 based argv variable.

Definition at line 382 of file pgm_base.cpp.

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

References App(), m_argcUtf8, and m_argvUtf8.

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 149 of file pgm_base.cpp.

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

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 186 of file pgm_base.h.

186{ m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
Definition: pgm_base.h:340

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 607 of file pgm_base.cpp.

608{
609 return m_settings_manager ? m_settings_manager->GetCommonSettings() : nullptr;
610}
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:330

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 165 of file pgm_base.h.

165{ return m_bin_dir; }
wxString m_bin_dir
Definition: pgm_base.h:334

References m_bin_dir.

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

◆ GetKicadEnvVariable()

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

Definition at line 163 of file pgm_base.h.

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

References m_kicad_env.

◆ GetLocale()

virtual wxLocale * PGM_BASE::GetLocale ( )
inlinevirtual

Definition at line 167 of file pgm_base.h.

167{ return m_locale; }

References m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtual

Definition at line 822 of file pgm_base.cpp.

823{
824 return GetCommonSettings()->m_Env.vars;
825}
ENVIRONMENT m_Env
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:607

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 169 of file pgm_base.h.

169{ return m_pdf_browser; }
wxString m_pdf_browser
Definition: pgm_base.h:341

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 220 of file pgm_base.h.

220{ return m_language_id; }
int m_language_id
Definition: pgm_base.h:338

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 175 of file pgm_base.cpp.

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

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 397 of file pgm_base.cpp.

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

161{ return !m_kicad_env.IsEmpty(); }

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 571 of file pgm_base.cpp.

572{
574
575 for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
576 {
577 wxLogTrace( traceEnvVars, wxT( "PGM_BASE::loadSettings: Found entry %s = %s" ),
578 it.first, it.second.GetValue() );
579
580 // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
581 // it is found in config. (It is reserved and defined as project path)
582 if( it.first == PROJECT_VAR_NAME )
583 continue;
584
585 // Don't set bogus empty entries in the environment
586 if( it.first.IsEmpty() )
587 continue;
588
589 // Do not overwrite vars set by the system environment with values from the settings file
590 if( it.second.GetDefinedExternally() )
591 continue;
592
593 SetLocalEnvVariable( it.first, it.second.GetValue() );
594 }
595}
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:778
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:171

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 598 of file pgm_base.cpp.

599{
600 // GetCommonSettings() is not initialized until fairly late in the
601 // process startup: InitPgm(), so test before using:
602 if( GetCommonSettings() )
603 GetCommonSettings()->m_System.working_dir = wxGetCwd();
604}

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 710 of file pgm_base.cpp.

711{
712 setLanguageId( wxLANGUAGE_DEFAULT );
713
714 // dictionary file name without extend (full name is kicad.mo)
715 wxString dictionaryName( wxT( "kicad" ) );
716
717 delete m_locale;
718 m_locale = new wxLocale;
719 m_locale->Init();
720
721 // Try adding the dictionary if it is not currently loaded
722 if( !m_locale->IsLoaded( dictionaryName ) )
723 m_locale->AddCatalog( dictionaryName );
724
725 // Verify the Kicad dictionary was loaded properly
726 // However, for the English language, the dictionary is not mandatory, as
727 // all messages are already in English, just restricted to ASCII7 chars,
728 // the verification is skipped.
729 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
730 {
731 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
732 dictionaryName, m_locale->GetName() );
733
734 setLanguageId( wxLANGUAGE_DEFAULT );
735 delete m_locale;
736
737 m_locale = new wxLocale;
738 m_locale->Init();
739
740 aErrMsg = _( "The KiCad language file for this language is not installed." );
741 return false;
742 }
743
744 return true;
745}
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 529 of file pgm_base.cpp.

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

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 613 of file pgm_base.cpp.

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

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 314 of file pgm_base.h.

314{ 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 748 of file pgm_base.cpp.

749{
750 wxLogTrace( traceLocale, wxT( "Select language ID %d from %d possible languages." ),
751 menu_id, (int)arrayDim( LanguagesList )-1 );
752
753 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
754 {
755 if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
756 {
757 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
758 break;
759 }
760 }
761}
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 764 of file pgm_base.cpp.

765{
766 wxLocale::AddCatalogLookupPathPrefix( PATHS::GetLocaleDataPath() );
767
768 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
769 {
770 wxFileName fn( Pgm().GetExecutablePath() );
771 fn.RemoveLastDir();
772 fn.AppendDir( wxT( "translation" ) );
773 wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
774 }
775}
static wxString GetLocaleDataPath()
Gets the locales translation data path.
Definition: paths.cpp:252
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:165
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 778 of file pgm_base.cpp.

779{
780 wxString env;
781
782 if( aName.IsEmpty() )
783 {
784 wxLogTrace( traceEnvVars,
785 wxT( "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s" ),
786 aValue );
787 return false;
788 }
789
790 // Check to see if the environment variable is already set.
791 if( wxGetEnv( aName, &env ) )
792 {
793 wxLogTrace( traceEnvVars,
794 wxT( "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s" ),
795 aName, env );
796 return env == aValue;
797 }
798
799 wxLogTrace( traceEnvVars,
800 wxT( "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
801 aName, aValue );
802
803 return wxSetEnv( aName, aValue );
804}

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 807 of file pgm_base.cpp.

808{
809 // Overwrites externally defined environment variable until the next time the application
810 // is run.
811 for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
812 {
813 wxLogTrace( traceEnvVars,
814 wxT( "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s" ),
815 m_local_env_var.first,
816 m_local_env_var.second.GetValue() );
817 wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
818 }
819}

References GetCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

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

Definition at line 171 of file pgm_base.h.

171{ m_pdf_browser = aFileName; }

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ SetTextEditor()

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

Definition at line 168 of file pgm_base.cpp.

169{
170 m_text_editor = aFileName;
172}

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 178 of file pgm_base.h.

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

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 354 of file pgm_base.h.

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

◆ m_argvUtf8

char** PGM_BASE::m_argvUtf8
protected

Definition at line 351 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 334 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 335 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 337 of file pgm_base.h.

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

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount

Definition at line 305 of file pgm_base.h.

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

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protected

Definition at line 341 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 303 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 332 of file pgm_base.h.

Referenced by InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting

Definition at line 307 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 343 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 264 of file pgm_base.h.


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