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

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 106 of file pgm_base.cpp.

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

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

122 {
123  Destroy();
124 }
void Destroy()
Definition: pgm_base.cpp:127

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

139 {
140  wxASSERT( wxTheApp );
141  return *wxTheApp;
142 }

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

191 {
192  // Create a mask representing the executable files in the current platform
193 #ifdef __WINDOWS__
194  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
195 #else
196  wxString mask( _( "Executable file (*)|*" ) );
197 #endif
198 
199  // Extract the path, name and extension from the default editor (even if the editor's
200  // name was empty, this method will succeed and return empty strings).
201  wxString path, name, ext;
202  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
203 
204  // Show the modal editor and return the file chosen (may be empty if the user cancels
205  // the dialog).
206  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
207  name, ext, mask,
208  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
209  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:103

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

Referenced by GetEditorName().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 127 of file pgm_base.cpp.

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

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

219 { 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:367

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 583 of file pgm_base.cpp.

584 {
586 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.

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

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

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

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

◆ GetExecutablePath()

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

Definition at line 198 of file pgm_base.h.

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

References m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit().

◆ GetKicadEnvVariable()

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

Definition at line 196 of file pgm_base.h.

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

References m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtual

Definition at line 200 of file pgm_base.h.

200 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:361

References m_locale.

◆ GetLocalEnvVariables()

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

Definition at line 290 of file pgm_base.h.

291  {
292  return m_local_env_vars;
293  }
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:375

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

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

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

253 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:364

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, _( "Environmental variable HOME is empty. Unable to continue." ) );
223  return false;
224  }
225 #endif
226 
227  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
228  wxGetUserId(), GetKicadLockFilePath() );
229 
230  if( m_pgm_checker->IsAnotherRunning() )
231  {
232  wxString quiz =
233  wxString::Format( _( "%s is already running. Continue?" ), pgm_name.GetName() );
234 
235  if( !IsOK( NULL, quiz ) )
236  return false;
237  }
238 
239  // Init KiCad environment
240  // the environment variable KICAD (if exists) gives the kicad path:
241  // something like set KICAD=d:\kicad
242  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
243 
244  if( isDefined ) // ensure m_kicad_env ends by "/"
245  {
247 
248  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
250  }
251 
252  // Init parameters for configuration
253  App().SetVendorName( "KiCad" );
254  App().SetAppName( pgm_name.GetName().Lower() );
255 
256  // Install some image handlers, mainly for help
257  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
258  wxImage::AddHandler( new wxPNGHandler );
259 
260  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
261  wxImage::AddHandler( new wxGIFHandler );
262 
263  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
264  wxImage::AddHandler( new wxJPEGHandler );
265 
266  wxFileSystem::AddHandler( new wxZipFSHandler );
267 
268  // Analyze the command line & initialize the binary path
269  wxString tmp;
271  SetLanguagePath();
272  SetDefaultLanguage( tmp );
273 
274  m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
275 
276  // Something got in the way of settings load: can't continue
277  if( !m_settings_manager->IsOK() )
278  return false;
279 
280  wxFileName baseSharePath;
281 #if defined( __WXMSW__ )
282  // Make the paths relative to the executable dir as KiCad might be installed anywhere
283  // It follows the Windows installer paths scheme, where binaries are installed in
284  // PATH/bin and extra files in PATH/share/kicad
285  baseSharePath.AssignDir( m_bin_dir + "\\.." );
286  baseSharePath.Normalize();
287 #else
288  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
289 #endif
290 
291 #if !defined( __WXMAC__ )
292  baseSharePath.AppendDir( "share" );
293  baseSharePath.AppendDir( "kicad" );
294 #endif
295 
296  // KICAD6_FOOTPRINT_DIR
297  wxString envVarName = wxT( "KICAD6_FOOTPRINT_DIR" );
298  ENV_VAR_ITEM envVarItem;
299  wxString envValue;
300  wxFileName tmpFileName;
301 
302  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
303  {
304  tmpFileName.AssignDir( envValue );
305  envVarItem.SetDefinedExternally( true );
306  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
307  }
308  else
309  {
310  tmpFileName = baseSharePath;
311  tmpFileName.AppendDir( "modules" );
312  envVarItem.SetDefinedExternally( false );
313  }
314 
315  envVarItem.SetValue( tmpFileName.GetPath() );
316  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
317  envVarName, envVarItem.GetValue() );
318  m_local_env_vars[ envVarName ] = envVarItem;
319 
320  // KICAD6_3DMODEL_DIR
321  envVarName = wxT( "KICAD6_3DMODEL_DIR" );
322 
323  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
324  {
325  tmpFileName.AssignDir( envValue );
326  envVarItem.SetDefinedExternally( true );
327  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
328  }
329  else
330  {
331  tmpFileName = baseSharePath;
332  tmpFileName.AppendDir( "3dmodels" );
333  envVarItem.SetDefinedExternally( false );
334  }
335 
336  envVarItem.SetValue( tmpFileName.GetFullPath() );
337  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
338  envVarName, envVarItem.GetValue() );
339  m_local_env_vars[ envVarName ] = envVarItem;
340 
341  // KICAD6_TEMPLATE_DIR
342  envVarName = "KICAD6_TEMPLATE_DIR";
343 
344  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
345  {
346  tmpFileName.AssignDir( envValue );
347  envVarItem.SetDefinedExternally( true );
348  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
349  }
350  else
351  {
352  // Attempt to find the best default template path.
353  SEARCH_STACK bases;
354  SEARCH_STACK templatePaths;
355 
356  SystemDirsAppend( &bases );
357 
358  for( unsigned i = 0; i < bases.GetCount(); ++i )
359  {
360  wxFileName fn( bases[i], wxEmptyString );
361 
362  // Add KiCad template file path to search path list.
363  fn.AppendDir( "template" );
364 
365  // Only add path if exists and can be read by the user.
366  if( fn.DirExists() && fn.IsDirReadable() )
367  {
368  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
369  fn.GetPath() );
370  templatePaths.AddPaths( fn.GetPath() );
371  }
372  }
373 
374  if( templatePaths.IsEmpty() )
375  {
376  tmpFileName = baseSharePath;
377  tmpFileName.AppendDir( "template" );
378  }
379  else
380  {
381  // Take the first one. There may be more but this will likely be the best option.
382  tmpFileName.AssignDir( templatePaths[0] );
383  }
384 
385  envVarItem.SetDefinedExternally( false );
386  }
387 
388  envVarItem.SetValue( tmpFileName.GetPath() );
389  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName,
390  envVarItem.GetValue() );
391  m_local_env_vars[ envVarName ] = envVarItem;
392 
393  // KICAD_USER_TEMPLATE_DIR
394  envVarName = "KICAD_USER_TEMPLATE_DIR";
395 
396  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
397  {
398  tmpFileName.AssignDir( envValue );
399  envVarItem.SetDefinedExternally( true );
400  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
401  }
402  else
403  {
404  // Default user template path.
405  tmpFileName.AssignDir( wxStandardPaths::Get().GetDocumentsDir() );
406  tmpFileName.AppendDir( "kicad" );
407  tmpFileName.AppendDir( "template" );
408  envVarItem.SetDefinedExternally( false );
409  }
410 
411  envVarItem.SetValue( tmpFileName.GetPath() );
412  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
413  envVarName, envVarItem.GetValue() );
414  m_local_env_vars[ envVarName ] = envVarItem;
415 
416  // KICAD_SYMBOLS
417  envVarName = wxT( "KICAD6_SYMBOL_DIR" );
418 
419  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
420  {
421  tmpFileName.AssignDir( envValue );
422  envVarItem.SetDefinedExternally( true );
423  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
424  }
425  else
426  {
427  tmpFileName = baseSharePath;
428  tmpFileName.AppendDir( "library" );
429  envVarItem.SetDefinedExternally( false );
430  }
431 
432  envVarItem.SetValue( tmpFileName.GetPath() );
433  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
434  envVarName, envVarItem.GetValue() );
435  m_local_env_vars[ envVarName ] = envVarItem;
436 
438 
439  // Init user language *before* calling loadCommonSettings, because
440  // env vars could be incorrectly initialized on Linux
441  // (if the value contains some non ASCII7 chars, the env var is not initialized)
442  SetLanguage( tmp, true );
443 
445 
446  ReadPdfBrowserInfos(); // needs GetCommonSettings()
447 
448 #ifdef __WXMAC__
449  // Always show filters on Open dialog to be able to choose plugin
450  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
451 #endif
452 
453  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
454  // Need to create a project early for now (it can have an empty path for the moment)
456 
457  // TODO: Move tooltips into KIPLATFORM
458  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
459  // Windows as other platforms display tooltips while the mouse is not moving
460  wxToolTip::SetAutoPop( 10000 );
461 
462  return true;
463 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:508
wxString GetKicadLockFilePath()
Definition: lockfile.cpp:60
#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:266
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:375
#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:84
const wxString & GetValue() const
Definition: pgm_base.h:101
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:138
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:466
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:352
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:349
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:358
#define NULL
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:96
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:589
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
virtual void SetLanguagePath()
Definition: pgm_base.cpp:738
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:355
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:102
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:103
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:684
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:297
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).

References _, SEARCH_STACK::AddPaths(), App(), DisplayErrorMessage(), Format(), GetCommonSettings(), GetKicadLockFilePath(), GetSettingsManager(), ENV_VAR_ITEM::GetValue(), IsOK(), SETTINGS_MANAGER::Load(), loadCommonSettings(), SETTINGS_MANAGER::LoadProject(), m_bin_dir, 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 194 of file pgm_base.h.

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

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 508 of file pgm_base.cpp.

509 {
510  m_help_size.x = 500;
511  m_help_size.y = 400;
512 
515 
516  for( const auto& it : GetCommonSettings()->m_Env.vars )
517  {
518  wxString key( it.first.c_str(), wxConvUTF8 );
519  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s",
520  key, it.second );
521 
522  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
523  // it is found in config. (It is reserved and defined as project path)
524  if( key == PROJECT_VAR_NAME )
525  continue;
526 
527  if( m_local_env_vars[ key ].GetDefinedExternally() )
528  continue;
529 
530  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s",
531  key, it.second );
532 
533  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
534  }
535 
536  for( auto& m_local_env_var : m_local_env_vars )
537  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
538 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
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:375
A simple helper class to store environment variable values and the status of whether or not they were...
Definition: pgm_base.h:84
#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:378
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:773
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxSize m_help_size
Definition: pgm_base.h:372
wxString m_editor_name
Definition: pgm_base.h:371

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:583
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:367
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:204

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

542 {
543  // GetCommonSettings() is not initialized until fairly late in the
544  // process startup: InitPgm(), so test before using:
545  if( GetCommonSettings() )
546  {
547  GetCommonSettings()->m_System.working_dir = wxGetCwd();
549 
550  // remove only the old env vars that do not exist in list.
551  // We do not clear the full list because some are defined externally,
552  // and we cannot modify or delete them
553  std::map<std::string, wxString>& curr_vars = GetCommonSettings()->m_Env.vars;
554 
555  for( auto it = curr_vars.begin(); it != curr_vars.end(); )
556  {
557  const std::string& key = it->first;
558 
559  if( m_local_env_vars.find( key ) == m_local_env_vars.end() )
560  it = curr_vars.erase( it ); // This entry no longer exists in new list
561  else
562  it++;
563  }
564 
565  // Save the local environment variables.
566  for( auto& m_local_env_var : m_local_env_vars )
567  {
568  if( m_local_env_var.second.GetDefinedExternally() )
569  continue;
570 
571  wxLogTrace( traceEnvVars,
572  "PGM_BASE::SaveCommonSettings: Saving environment variable config "
573  "entry %s as %s",
574  m_local_env_var.first, m_local_env_var.second.GetValue() );
575 
576  std::string key( m_local_env_var.first.ToUTF8() );
577  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
578  }
579  }
580 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
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:375
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:378
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 684 of file pgm_base.cpp.

685 {
686  setLanguageId( wxLANGUAGE_DEFAULT );
687 
688  // dictionary file name without extend (full name is kicad.mo)
689  wxString dictionaryName( "kicad" );
690 
691  delete m_locale;
692  m_locale = new wxLocale;
693  m_locale->Init();
694 
695  // Try adding the dictionary if it is not currently loaded
696  if( !m_locale->IsLoaded( dictionaryName ) )
697  m_locale->AddCatalog( dictionaryName );
698 
699  // Verify the Kicad dictionary was loaded properly
700  // However, for the English language, the dictionary is not mandatory, as
701  // all messages are already in English, just restricted to ASCII7 chars,
702  // the verification is skipped.
703  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
704  {
705  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
706  dictionaryName, m_locale->GetName() );
707 
708  setLanguageId( wxLANGUAGE_DEFAULT );
709  delete m_locale;
710 
711  m_locale = new wxLocale;
712  m_locale->Init();
713 
714  aErrMsg = _( "The KiCad language file for this language is not installed." );
715  return false;
716  }
717 
718  return true;
719 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:361
int m_language_id
The current language setting.
Definition: pgm_base.h:364
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:340
const wxChar *const traceLocale
Flag to enable locale debug output.
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:103

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

Referenced by InitPgm().

◆ SetEditorName()

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

Definition at line 145 of file pgm_base.cpp.

146 {
147  m_editor_name = aFileName;
148  wxASSERT( GetCommonSettings() );
149  GetCommonSettings()->m_System.editor_name = aFileName;
150 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
wxString m_editor_name
Definition: pgm_base.h:371

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

467 {
468  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
469 
470 #ifdef __WXMAC__
471  // On OSX Pgm().GetExecutablePath() will always point to main
472  // bundle directory, e.g., /Applications/kicad.app/
473 
474  wxFileName fn( m_bin_dir );
475 
476  if( fn.GetName() == wxT( "kicad" ) )
477  {
478  // kicad launcher, so just remove the Contents/MacOS part
479  fn.RemoveLastDir();
480  fn.RemoveLastDir();
481  }
482  else
483  {
484  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
485  fn.RemoveLastDir();
486  fn.RemoveLastDir();
487  fn.RemoveLastDir();
488  fn.RemoveLastDir();
489  fn.RemoveLastDir();
490  }
491 
492  m_bin_dir = fn.GetPath() + wxT( "/" );
493 #else
494  // Use unix notation for paths. I am not sure this is a good idea,
495  // but it simplifies compatibility between Windows and Unices.
496  // However it is a potential problem in path handling under Windows.
498 
499  // Remove file name form command line:
500  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
501  m_bin_dir.RemoveLast();
502 #endif
503 
504  return true;
505 }
#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:355

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

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

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

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

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

723 {
724  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
725  menu_id, (int)arrayDim( LanguagesList )-1 );
726 
727  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
728  {
729  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
730  {
731  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
732  break;
733  }
734  }
735 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:74
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
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:340
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 738 of file pgm_base.cpp.

739 {
740  SEARCH_STACK guesses;
741 
742  SystemDirsAppend( &guesses );
743 
744  // Add our internat dir to the wxLocale catalog of paths
745  for( unsigned i = 0; i < guesses.GetCount(); i++ )
746  {
747  wxFileName fn( guesses[i], wxEmptyString );
748 
749  // Append path for Windows and unix KiCad package install
750  fn.AppendDir( "share" );
751  fn.AppendDir( "internat" );
752 
753  if( fn.IsDirReadable() )
754  {
755  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
756  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
757  }
758 
759  // Append path for unix standard install
760  fn.RemoveLastDir();
761  fn.AppendDir( "kicad" );
762  fn.AppendDir( "internat" );
763 
764  if( fn.IsDirReadable() )
765  {
766  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
767  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
768  }
769  }
770 }
Look for files in a number of paths.
Definition: search_stack.h:41
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.

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

774 {
775  wxString env;
776 
777  // Check to see if the environment variable is already set.
778  if( wxGetEnv( aName, &env ) )
779  {
780  wxLogTrace( traceEnvVars,
781  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
782  aName, env );
783  return env == aValue;
784  }
785 
786  wxLogTrace( traceEnvVars,
787  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
788  aName, aValue );
789 
790  return wxSetEnv( aName, aValue );
791 }
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 794 of file pgm_base.cpp.

795 {
796  m_local_env_vars.clear();
797  m_local_env_vars = aEnvVarMap;
798 
800 
801  // Overwrites externally defined environment variable until the next time the application
802  // is run.
803  for( auto& m_local_env_var : m_local_env_vars )
804  {
805  wxLogTrace( traceEnvVars,
806  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
807  m_local_env_var.first,
808  m_local_env_var.second.GetValue() );
809  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
810  }
811 }
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:375
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:541
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 204 of file pgm_base.h.

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

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

212  {
213  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
214  }
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:367
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:370

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:583
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:367
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:202

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

Referenced by GetExecutablePath(), InitPgm(), and setExecutablePath().

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protected

Definition at line 371 of file pgm_base.h.

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

◆ m_help_size

wxSize PGM_BASE::m_help_size
protected

Definition at line 372 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 358 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 364 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 375 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 361 of file pgm_base.h.

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

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount

Definition at line 333 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 370 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 352 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 331 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 378 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 367 of file pgm_base.h.

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

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
static

Definition at line 302 of file pgm_base.h.


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