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_MOCK_EESCHEMA_FRAME PGM_SINGLE_TOP PGM_TEST_FRAME PGM_TEST_FRAME PGM_TEST_FRAME

Public Member Functions

 PGM_BASE ()
 
virtual ~PGM_BASE ()
 
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 SetEditorName (const wxString &aFileName)
 
virtual const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. 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 fromthe 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 (const ENV_VAR_MAP &aEnvVarMap)
 Set the internal local environment variable map to aEnvVarMap, updates the entries in the .kicad_common configuration file and sets the environment variable to the new settings. More...
 
virtual const 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 ()
 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
 

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
 
wxSingleInstanceChecker * m_pgm_checker
 prevents multiple instances of a program from being run at the same time. More...
 
wxString m_bin_dir
 full path to this program More...
 
wxString m_kicad_env
 The KICAD system environment variable. More...
 
wxLocale * m_locale
 The current locale. More...
 
int m_language_id
 The current language setting. More...
 
bool m_use_system_pdf_browser
 true to use the selected PDF browser, if exists, or false to use the default More...
 
wxString m_pdf_browser
 The file name of the the program selected for browsing pdf files. More...
 
wxString m_editor_name
 
wxSize m_help_size
 
ENV_VAR_MAP m_local_env_vars
 Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR. More...
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. 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 130 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 109 of file pgm_base.cpp.

110 {
112  m_locale = NULL;
113  m_Printing = false;
114  m_ModalDialogCount = 0;
115 
116  m_show_env_var_dialog = true;
117 
118  setLanguageId( wxLANGUAGE_DEFAULT );
119 
120  ForceSystemPdfBrowser( false );
121 }
int m_ModalDialogCount
Definition: pgm_base.h:332
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:377
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:218
#define NULL
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:339
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:330

References ForceSystemPdfBrowser(), m_locale, m_ModalDialogCount, m_pgm_checker, m_Printing, m_show_env_var_dialog, NULL, and setLanguageId().

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 124 of file pgm_base.cpp.

125 {
126  Destroy();
127 }
void Destroy()
Definition: pgm_base.cpp:130

References Destroy().

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

142 {
143  wxASSERT( wxTheApp );
144  return *wxTheApp;
145 }

Referenced by InitPgm(), PGM_KICAD::MacOpenFile(), PGM_TEST_FRAME::MacOpenFile(), PGM_SINGLE_TOP::MacOpenFile(), PGM_MOCK_EESCHEMA_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 192 of file pgm_base.cpp.

193 {
194  // Create a mask representing the executable files in the current platform
195 #ifdef __WINDOWS__
196  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
197 #else
198  wxString mask( _( "Executable file (*)|*" ) );
199 #endif
200 
201  // Extract the path, name and extension from the default editor (even if the editor's
202  // name was empty, this method will succeed and return empty strings).
203  wxString path, name, ext;
204  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
205 
206  // Show the modal editor and return the file chosen (may be empty if the user cancels
207  // the dialog).
208  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path, name, ext, mask, NULL,
209  wxFD_OPEN | wxFD_FILE_MUST_EXIST, true );
210 }
#define NULL
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
A helper function that wraps a call to wxFileSelector.
Definition: gestfich.cpp:52
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106

References _, EDA_FILE_SELECTOR(), name, NULL, and path.

Referenced by GetEditorName().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 130 of file pgm_base.cpp.

131 {
132  // unlike a normal destructor, this is designed to be called more than once safely:
133  delete m_pgm_checker;
134  m_pgm_checker = 0;
135 
136  delete m_locale;
137  m_locale = 0;
138 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351

References m_locale, and m_pgm_checker.

Referenced by CreateWindow(), PGM_KICAD::Destroy(), PGM_SINGLE_TOP::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 218 of file pgm_base.h.

218 { m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 569 of file pgm_base.cpp.

570 {
572 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:166
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:348
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.

References SETTINGS_MANAGER::GetCommonSettings(), GetSettingsManager(), and m_settings_manager.

Referenced by InitPgm(), loadCommonSettings(), ReadPdfBrowserInfos(), SaveCommonSettings(), SetEditorName(), SetLanguage(), and WritePdfBrowserInfos().

◆ GetEditorName()

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

Return the preferred editor name.

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

157 {
158  wxString editorname = m_editor_name;
159 
160  if( !editorname )
161  {
162  if( !wxGetEnv( "EDITOR", &editorname ) )
163  {
164  // If there is no EDITOR variable set, try the desktop default
165 #ifdef __WXMAC__
166  editorname = "/usr/bin/open";
167 #elif __WXX11__
168  editorname = "/usr/bin/xdg-open";
169 #endif
170  }
171  }
172 
173  // If we still don't have an editor name show a dialog asking the user to select one
174  if( !editorname && aCanShowFileChooser )
175  {
176  DisplayInfoMessage( NULL, _( "No default editor found, you must choose it" ) );
177 
178  editorname = AskUserForPreferredEditor();
179  }
180 
181  // If we finally have a new editor name request it to be copied to m_editor_name and
182  // saved to the preferences file.
183  if( !editorname.IsEmpty() )
184  SetEditorName( editorname );
185 
186  // m_editor_name already has the same value that editorname, or empty if no editor was
187  // found/chosen.
188  return m_editor_name;
189 }
virtual void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:148
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:192
#define NULL
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106
wxString m_editor_name
Definition: pgm_base.h:370
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:280

References _, AskUserForPreferredEditor(), DisplayInfoMessage(), m_editor_name, NULL, and SetEditorName().

◆ GetExecutablePath()

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

Definition at line 197 of file pgm_base.h.

197 { return m_bin_dir; }
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354

References m_bin_dir.

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

◆ GetKicadEnvVariable()

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

Definition at line 195 of file pgm_base.h.

195 { return m_kicad_env; }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:357

References m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtual

Definition at line 199 of file pgm_base.h.

199 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360

References m_locale.

◆ GetLocalEnvVariables()

virtual const ENV_VAR_MAP& PGM_BASE::GetLocalEnvVariables ( ) const
inlinevirtual

Definition at line 289 of file pgm_base.h.

290  {
291  return m_local_env_vars;
292  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:374

References m_local_env_vars.

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

◆ GetPdfBrowserName()

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

Definition at line 201 of file pgm_base.h.

201 { return m_pdf_browser; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:369

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

252 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:363

References m_language_id.

◆ GetSettingsManager()

◆ InitPgm()

bool PGM_BASE::InitPgm ( )

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.
Returns
true if success, false if failure and program is to terminate.

Definition at line 213 of file pgm_base.cpp.

214 {
215  wxFileName pgm_name( App().argv[0] );
216 
217  wxInitAllImageHandlers();
218 
219 #ifndef __WINDOWS__
220  if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
221  {
222  DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
223  "Unable to continue." ) );
224  return false;
225  }
226 #endif
227 
228  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
229  wxGetUserId(), GetKicadLockFilePath() );
230 
231  if( m_pgm_checker->IsAnotherRunning() )
232  {
233  if( !IsOK( NULL, wxString::Format( _( "%s is already running. Continue?" ),
234  App().GetAppDisplayName() ) ) )
235  {
236  return false;
237  }
238  }
239 
240  // Init KiCad environment
241  // the environment variable KICAD (if exists) gives the kicad path:
242  // something like set KICAD=d:\kicad
243  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
244 
245  if( isDefined ) // ensure m_kicad_env ends by "/"
246  {
248 
249  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
251  }
252 
253  // Init parameters for configuration
254  App().SetVendorName( "KiCad" );
255  App().SetAppName( pgm_name.GetName().Lower() );
256 
257  // Install some image handlers, mainly for help
258  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
259  wxImage::AddHandler( new wxPNGHandler );
260 
261  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
262  wxImage::AddHandler( new wxGIFHandler );
263 
264  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
265  wxImage::AddHandler( new wxJPEGHandler );
266 
267  wxFileSystem::AddHandler( new wxZipFSHandler );
268 
269  // Analyze the command line & initialize the binary path
270  wxString tmp;
272  SetLanguagePath();
273  SetDefaultLanguage( tmp );
274 
275  m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
276 
277  // Something got in the way of settings load: can't continue
278  if( !m_settings_manager->IsOK() )
279  return false;
280 
281  wxFileName baseSharePath;
282  baseSharePath.AssignDir( PATHS::GetStockEDALibraryPath() );
283 
284  // KICAD6_FOOTPRINT_DIR
285  wxString envVarName = wxT( "KICAD6_FOOTPRINT_DIR" );
286  ENV_VAR_ITEM envVarItem;
287  wxString envValue;
288  wxFileName tmpFileName;
289 
290  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
291  {
292  tmpFileName.AssignDir( envValue );
293  envVarItem.SetDefinedExternally( true );
294  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
295  }
296  else
297  {
298  tmpFileName = baseSharePath;
299  tmpFileName.AppendDir( "modules" );
300  envVarItem.SetDefinedExternally( false );
301  }
302 
303  envVarItem.SetValue( tmpFileName.GetPath() );
304  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
305  envVarName, envVarItem.GetValue() );
306  m_local_env_vars[ envVarName ] = envVarItem;
307 
308  // KICAD6_3DMODEL_DIR
309  envVarName = wxT( "KICAD6_3DMODEL_DIR" );
310 
311  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
312  {
313  tmpFileName.AssignDir( envValue );
314  envVarItem.SetDefinedExternally( true );
315  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
316  }
317  else
318  {
319  tmpFileName = baseSharePath;
320  tmpFileName.AppendDir( "3dmodels" );
321  envVarItem.SetDefinedExternally( false );
322  }
323 
324  envVarItem.SetValue( tmpFileName.GetFullPath() );
325  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
326  envVarName, envVarItem.GetValue() );
327  m_local_env_vars[ envVarName ] = envVarItem;
328 
329  // KICAD6_TEMPLATE_DIR
330  envVarName = "KICAD6_TEMPLATE_DIR";
331 
332  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
333  {
334  tmpFileName.AssignDir( envValue );
335  envVarItem.SetDefinedExternally( true );
336  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
337  }
338  else
339  {
340  // Attempt to find the best default template path.
341  SEARCH_STACK bases;
342  SEARCH_STACK templatePaths;
343 
344  SystemDirsAppend( &bases );
345 
346  for( unsigned i = 0; i < bases.GetCount(); ++i )
347  {
348  wxFileName fn( bases[i], wxEmptyString );
349 
350  // Add KiCad template file path to search path list.
351  fn.AppendDir( "template" );
352 
353  // Only add path if exists and can be read by the user.
354  if( fn.DirExists() && fn.IsDirReadable() )
355  {
356  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
357  fn.GetPath() );
358  templatePaths.AddPaths( fn.GetPath() );
359  }
360  }
361 
362  if( templatePaths.IsEmpty() )
363  {
364  tmpFileName = baseSharePath;
365  tmpFileName.AppendDir( "template" );
366  }
367  else
368  {
369  // Take the first one. There may be more but this will likely be the best option.
370  tmpFileName.AssignDir( templatePaths[0] );
371  }
372 
373  envVarItem.SetDefinedExternally( false );
374  }
375 
376  envVarItem.SetValue( tmpFileName.GetPath() );
377  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName,
378  envVarItem.GetValue() );
379  m_local_env_vars[ envVarName ] = envVarItem;
380 
381  // KICAD_USER_TEMPLATE_DIR
382  envVarName = "KICAD_USER_TEMPLATE_DIR";
383 
384  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
385  {
386  tmpFileName.AssignDir( envValue );
387  envVarItem.SetDefinedExternally( true );
388  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
389  }
390  else
391  {
392  // Default user template path.
393  tmpFileName.AssignDir( PATHS::GetUserTemplatesPath() );
394  envVarItem.SetDefinedExternally( false );
395  }
396 
397  envVarItem.SetValue( tmpFileName.GetPath() );
398  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
399  envVarName, envVarItem.GetValue() );
400  m_local_env_vars[ envVarName ] = envVarItem;
401 
402  // KICAD_SYMBOLS
403  envVarName = wxT( "KICAD6_SYMBOL_DIR" );
404 
405  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
406  {
407  tmpFileName.AssignDir( envValue );
408  envVarItem.SetDefinedExternally( true );
409  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
410  }
411  else
412  {
413  tmpFileName = baseSharePath;
414  tmpFileName.AppendDir( "library" );
415  envVarItem.SetDefinedExternally( false );
416  }
417 
418  envVarItem.SetValue( tmpFileName.GetPath() );
419  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
420  envVarName, envVarItem.GetValue() );
421  m_local_env_vars[ envVarName ] = envVarItem;
422 
424 
425  // Init user language *before* calling loadCommonSettings, because
426  // env vars could be incorrectly initialized on Linux
427  // (if the value contains some non ASCII7 chars, the env var is not initialized)
428  SetLanguage( tmp, true );
429 
431 
432  ReadPdfBrowserInfos(); // needs GetCommonSettings()
433 
434 #ifdef __WXMAC__
435  // Always show filters on Open dialog to be able to choose plugin
436  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
437 #endif
438 
439  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
440  // Need to create a project early for now (it can have an empty path for the moment)
442 
443  // TODO: Move tooltips into KIPLATFORM
444  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
445  // Windows as other platforms display tooltips while the mouse is not moving
446  wxToolTip::SetAutoPop( 10000 );
447 
448  return true;
449 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:166
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:494
wxString GetKicadLockFilePath()
Definition: lockfile.cpp:61
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:374
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
A simple helper class to store environment variable values and the status of whether or not they were...
Definition: pgm_base.h:83
const wxString & GetValue() const
Definition: pgm_base.h:100
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:141
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:452
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351
Look for files in a number of paths.
Definition: search_stack.h:41
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:348
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:357
#define NULL
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:95
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:86
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:575
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
virtual void SetLanguagePath()
Definition: pgm_base.cpp:724
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
void SetValue(const wxString &aValue)
Definition: pgm_base.h:101
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
Definition: paths.cpp:165
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:670
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:296
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).

References _, SEARCH_STACK::AddPaths(), App(), DisplayErrorMessage(), Format(), GetCommonSettings(), GetKicadLockFilePath(), GetSettingsManager(), PATHS::GetStockEDALibraryPath(), PATHS::GetUserTemplatesPath(), ENV_VAR_ITEM::GetValue(), IsOK(), SETTINGS_MANAGER::Load(), loadCommonSettings(), SETTINGS_MANAGER::LoadProject(), m_kicad_env, m_local_env_vars, m_pgm_checker, m_settings_manager, NULL, ReadPdfBrowserInfos(), SetDefaultLanguage(), ENV_VAR_ITEM::SetDefinedExternally(), setExecutablePath(), SetLanguage(), SetLanguagePath(), ENV_VAR_ITEM::SetValue(), SystemDirsAppend(), traceEnvVars, tracePathsAndFiles, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_KICAD::OnPgmInit(), and PGM_TEST_FRAME::OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtual

Definition at line 193 of file pgm_base.h.

193 { return !m_kicad_env.IsEmpty(); }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:357

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 494 of file pgm_base.cpp.

495 {
496  m_help_size.x = 500;
497  m_help_size.y = 400;
498 
501 
502  for( const auto& it : GetCommonSettings()->m_Env.vars )
503  {
504  wxString key( it.first.c_str(), wxConvUTF8 );
505  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s",
506  key, it.second );
507 
508  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
509  // it is found in config. (It is reserved and defined as project path)
510  if( key == PROJECT_VAR_NAME )
511  continue;
512 
513  if( m_local_env_vars[ key ].GetDefinedExternally() )
514  continue;
515 
516  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s",
517  key, it.second );
518 
519  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
520  }
521 
522  for( auto& m_local_env_var : m_local_env_vars )
523  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
524 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:374
A simple helper class to store environment variable values and the status of whether or not they were...
Definition: pgm_base.h:83
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:377
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:779
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxSize m_help_size
Definition: pgm_base.h:371
wxString m_editor_name
Definition: pgm_base.h:370

References COMMON_SETTINGS::SYSTEM::editor_name, GetCommonSettings(), m_editor_name, COMMON_SETTINGS::m_Env, m_help_size, m_local_env_vars, m_show_env_var_dialog, COMMON_SETTINGS::m_System, PROJECT_VAR_NAME, SetLocalEnvVariable(), COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, 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_TEST_FRAME, PGM_MOCK_EESCHEMA_FRAME, PGM_SINGLE_TOP, PGM_TEST_FRAME, PGM_KICAD, and PGM_TEST_FRAME.

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
virtual

Read the PDF browser choice from the common configuration.

Definition at line 42 of file eda_doc.cpp.

43 {
44  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
46 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:203

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

528 {
529  // GetCommonSettings() is not initialized until fairly late in the
530  // process startup: InitPgm(), so test before using:
531  if( GetCommonSettings() )
532  {
533  GetCommonSettings()->m_System.working_dir = wxGetCwd();
535 
536  // remove only the old env vars that do not exist in list.
537  // We do not clear the full list because some are defined externally,
538  // and we cannot modify or delete them
539  std::map<std::string, wxString>& curr_vars = GetCommonSettings()->m_Env.vars;
540 
541  for( auto it = curr_vars.begin(); it != curr_vars.end(); )
542  {
543  const std::string& key = it->first;
544 
545  if( m_local_env_vars.find( key ) == m_local_env_vars.end() )
546  it = curr_vars.erase( it ); // This entry no longer exists in new list
547  else
548  it++;
549  }
550 
551  // Save the local environment variables.
552  for( auto& m_local_env_var : m_local_env_vars )
553  {
554  if( m_local_env_var.second.GetDefinedExternally() )
555  continue;
556 
557  wxLogTrace( traceEnvVars,
558  "PGM_BASE::SaveCommonSettings: Saving environment variable config "
559  "entry %s as %s",
560  m_local_env_var.first, m_local_env_var.second.GetValue() );
561 
562  std::string key( m_local_env_var.first.ToUTF8() );
563  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
564  }
565  }
566 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:374
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:377
std::map< std::string, wxString > vars
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References GetCommonSettings(), COMMON_SETTINGS::m_Env, m_local_env_vars, m_show_env_var_dialog, COMMON_SETTINGS::m_System, COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, traceEnvVars, COMMON_SETTINGS::ENVIRONMENT::vars, and COMMON_SETTINGS::SYSTEM::working_dir.

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

◆ 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 messsage(s) in
Returns
false if the language could not be set

Definition at line 670 of file pgm_base.cpp.

671 {
672  setLanguageId( wxLANGUAGE_DEFAULT );
673 
674  // dictionary file name without extend (full name is kicad.mo)
675  wxString dictionaryName( "kicad" );
676 
677  delete m_locale;
678  m_locale = new wxLocale;
679  m_locale->Init();
680 
681  // Try adding the dictionary if it is not currently loaded
682  if( !m_locale->IsLoaded( dictionaryName ) )
683  m_locale->AddCatalog( dictionaryName );
684 
685  // Verify the Kicad dictionary was loaded properly
686  // However, for the English language, the dictionary is not mandatory, as
687  // all messages are already in English, just restricted to ASCII7 chars,
688  // the verification is skipped.
689  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
690  {
691  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
692  dictionaryName, m_locale->GetName() );
693 
694  setLanguageId( wxLANGUAGE_DEFAULT );
695  delete m_locale;
696 
697  m_locale = new wxLocale;
698  m_locale->Init();
699 
700  aErrMsg = _( "The KiCad language file for this language is not installed." );
701  return false;
702  }
703 
704  return true;
705 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
int m_language_id
The current language setting.
Definition: pgm_base.h:363
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:339
const wxChar *const traceLocale
Flag to enable locale debug output.
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106

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

Referenced by InitPgm().

◆ SetEditorName()

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

Definition at line 148 of file pgm_base.cpp.

149 {
150  m_editor_name = aFileName;
151  wxASSERT( GetCommonSettings() );
152  GetCommonSettings()->m_System.editor_name = aFileName;
153 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
wxString m_editor_name
Definition: pgm_base.h:370

References COMMON_SETTINGS::SYSTEM::editor_name, GetCommonSettings(), m_editor_name, and COMMON_SETTINGS::m_System.

Referenced by GetEditorName().

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

453 {
454  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
455 
456 #ifdef __WXMAC__
457  // On OSX Pgm().GetExecutablePath() will always point to main
458  // bundle directory, e.g., /Applications/kicad.app/
459 
460  wxFileName fn( m_bin_dir );
461 
462  if( fn.GetName() == wxT( "kicad" ) )
463  {
464  // kicad launcher, so just remove the Contents/MacOS part
465  fn.RemoveLastDir();
466  fn.RemoveLastDir();
467  }
468  else
469  {
470  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
471  fn.RemoveLastDir();
472  fn.RemoveLastDir();
473  fn.RemoveLastDir();
474  fn.RemoveLastDir();
475  fn.RemoveLastDir();
476  }
477 
478  m_bin_dir = fn.GetPath() + wxT( "/" );
479 #else
480  // Use unix notation for paths. I am not sure this is a good idea,
481  // but it simplifies compatibility between Windows and Unices.
482  // However it is a potential problem in path handling under Windows.
484 
485  // Remove file name form command line:
486  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
487  m_bin_dir.RemoveLast();
488 #endif
489 
490  return true;
491 }
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354

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

576 {
577  if( first_time )
578  {
579  setLanguageId( wxLANGUAGE_DEFAULT );
580  // First time SetLanguage is called, the user selected language id is set
581  // from common user config settings
582  wxString languageSel = GetCommonSettings()->m_System.language;
583 
584  // Search for the current selection
585  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
586  {
587  if( LanguagesList[ii].m_Lang_Label == languageSel )
588  {
589  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
590  break;
591  }
592  }
593  }
594 
595  // dictionary file name without extend (full name is kicad.mo)
596  wxString dictionaryName( "kicad" );
597 
598  delete m_locale;
599  m_locale = new wxLocale;
600 
601  if( !m_locale->Init( m_language_id ) )
602  {
603  wxLogTrace( traceLocale, "This language is not supported by the system." );
604 
605  setLanguageId( wxLANGUAGE_DEFAULT );
606  delete m_locale;
607 
608  m_locale = new wxLocale;
609  m_locale->Init();
610 
611  aErrMsg = _( "This language is not supported by the operating system." );
612  return false;
613  }
614  else if( !first_time )
615  {
616  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
617  dictionaryName, m_locale->GetName() );
618  }
619 
620  if( !first_time )
621  {
622  // If we are here, the user has selected another language.
623  // Therefore the new preferred language name is stored in common config.
624  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
625  // versions, for a given language
626  wxString languageSel;
627 
628  // Search for the current selection language name
629  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
630  {
631  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
632  {
633  languageSel = LanguagesList[ii].m_Lang_Label;
634  break;
635  }
636  }
637 
639  cfg->m_System.language = languageSel;
640  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
641  }
642 
643  // Try adding the dictionary if it is not currently loaded
644  if( !m_locale->IsLoaded( dictionaryName ) )
645  m_locale->AddCatalog( dictionaryName );
646 
647  // Verify the Kicad dictionary was loaded properly
648  // However, for the English language, the dictionary is not mandatory, as
649  // all messages are already in English, just restricted to ASCII7 chars,
650  // the verification is skipped.
651  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
652  {
653  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
654  dictionaryName, m_locale->GetName() );
655 
656  setLanguageId( wxLANGUAGE_DEFAULT );
657  delete m_locale;
658 
659  m_locale = new wxLocale;
660  m_locale->Init();
661 
662  aErrMsg = _( "The KiCad language file for this language is not installed." );
663  return false;
664  }
665 
666  return true;
667 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:166
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:76
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:62
int m_language_id
The current language setting.
Definition: pgm_base.h:363
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:339
const wxChar *const traceLocale
Flag to enable locale debug output.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:65
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106

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

339 { m_language_id = aId; }
int m_language_id
The current language setting.
Definition: pgm_base.h:363

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

709 {
710  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
711  menu_id, (int)arrayDim( LanguagesList )-1 );
712 
713  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
714  {
715  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
716  {
717  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
718  break;
719  }
720  }
721 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:76
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:62
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:339
const wxChar *const traceLocale
Flag to enable locale debug output.

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtual

Definition at line 724 of file pgm_base.cpp.

725 {
726  SEARCH_STACK guesses;
727 
728  SystemDirsAppend( &guesses );
729 
730  // Add our internat dir to the wxLocale catalog of paths
731  for( unsigned i = 0; i < guesses.GetCount(); i++ )
732  {
733  wxFileName fn( guesses[i], wxEmptyString );
734 
735  // Append path for Windows and unix KiCad package install
736  fn.AppendDir( "share" );
737  fn.AppendDir( "internat" );
738 
739  if( fn.IsDirReadable() )
740  {
741  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
742  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
743  }
744 
745  // Append path for unix standard install
746  fn.RemoveLastDir();
747  fn.AppendDir( "kicad" );
748  fn.AppendDir( "internat" );
749 
750  if( fn.IsDirReadable() )
751  {
752  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
753  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
754  }
755 
756  // Append path for macOS install
757  fn.RemoveLastDir();
758  fn.RemoveLastDir();
759  fn.RemoveLastDir();
760  fn.AppendDir( "internat" );
761 
762  if( fn.IsDirReadable() )
763  {
764  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
765  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
766  }
767  }
768 
769  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
770  {
771  wxFileName fn( Pgm().GetExecutablePath() );
772  fn.RemoveLastDir();
773  fn.AppendDir( "translation" );
774  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
775  }
776 }
Look for files in a number of paths.
Definition: search_stack.h:41
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
const wxChar *const traceLocale
Flag to enable locale debug output.
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:197

References GetExecutablePath(), Pgm(), SystemDirsAppend(), and traceLocale.

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

780 {
781  wxString env;
782 
783  // Check to see if the environment variable is already set.
784  if( wxGetEnv( aName, &env ) )
785  {
786  wxLogTrace( traceEnvVars,
787  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
788  aName, env );
789  return env == aValue;
790  }
791 
792  wxLogTrace( traceEnvVars,
793  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
794  aName, aValue );
795 
796  return wxSetEnv( aName, aValue );
797 }
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References traceEnvVars.

Referenced by loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)
virtual

Set the internal local environment variable map to aEnvVarMap, updates the entries in the .kicad_common configuration file and sets the environment variable to the new settings.

Parameters
aEnvVarMapis a ENV_VAR_MAP object containing the new environment variables.

Definition at line 800 of file pgm_base.cpp.

801 {
802  m_local_env_vars.clear();
803  m_local_env_vars = aEnvVarMap;
804 
806 
807  // Overwrites externally defined environment variable until the next time the application
808  // is run.
809  for( auto& m_local_env_var : m_local_env_vars )
810  {
811  wxLogTrace( traceEnvVars,
812  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
813  m_local_env_var.first,
814  m_local_env_var.second.GetValue() );
815  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
816  }
817 }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:374
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:527
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References m_local_env_vars, SaveCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

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

Definition at line 203 of file pgm_base.h.

203 { m_pdf_browser = aFileName; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:369

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

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

211  {
212  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
213  }
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:369

References m_pdf_browser, and m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtual

Save the PDF browser choice to the common configuration.

Definition at line 49 of file eda_doc.cpp.

50 {
53 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:201

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

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protected

full path to this program

Definition at line 354 of file pgm_base.h.

Referenced by GetExecutablePath(), and setExecutablePath().

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protected

Definition at line 370 of file pgm_base.h.

Referenced by GetEditorName(), loadCommonSettings(), and SetEditorName().

◆ m_help_size

wxSize PGM_BASE::m_help_size
protected

Definition at line 371 of file pgm_base.h.

Referenced by loadCommonSettings().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protected

The KICAD system environment variable.

Definition at line 357 of file pgm_base.h.

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

◆ m_language_id

int PGM_BASE::m_language_id
protected

The current language setting.

Definition at line 363 of file pgm_base.h.

Referenced by GetSelectedLanguageIdentifier(), SetDefaultLanguage(), SetLanguage(), and setLanguageId().

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protected

Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.

Definition at line 374 of file pgm_base.h.

Referenced by GetLocalEnvVariables(), InitPgm(), loadCommonSettings(), SaveCommonSettings(), and SetLocalEnvVariables().

◆ m_locale

wxLocale* PGM_BASE::m_locale
protected

The current locale.

Definition at line 360 of file pgm_base.h.

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

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount

Definition at line 332 of file pgm_base.h.

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

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protected

The file name of the the program selected for browsing pdf files.

Definition at line 369 of file pgm_base.h.

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

◆ m_pgm_checker

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protected

prevents multiple instances of a program from being run at the same time.

Definition at line 351 of file pgm_base.h.

Referenced by Destroy(), InitPgm(), and PGM_BASE().

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

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

◆ m_settings_manager

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

◆ m_show_env_var_dialog

bool PGM_BASE::m_show_env_var_dialog
protected

Flag to indicate if the environment variable overwrite warning dialog should be shown.

Definition at line 377 of file pgm_base.h.

Referenced by loadCommonSettings(), PGM_BASE(), and SaveCommonSettings().

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protected

true to use the selected PDF browser, if exists, or false to use the default

Definition at line 366 of file pgm_base.h.

Referenced by ForceSystemPdfBrowser(), ReadPdfBrowserInfos(), UseSystemPdfBrowser(), and WritePdfBrowserInfos().

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
static

Definition at line 301 of file pgm_base.h.


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