KiCad PCB EDA Suite
PGM_BASE Class Referenceabstract

PGM_BASE keeps program (whole process) 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 ()
 
VTBL_ENTRY void MacOpenFile (const wxString &aFileName)=0
 Function MacOpenFile is specific to MacOSX (not used under Linux or Windows). More...
 
VTBL_ENTRY SETTINGS_MANAGERGetSettingsManager () const
 
VTBL_ENTRY COMMON_SETTINGSGetCommonSettings () const
 
VTBL_ENTRY void SetEditorName (const wxString &aFileName)
 
VTBL_ENTRY const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
VTBL_ENTRY const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
VTBL_ENTRY bool IsKicadEnvVariableDefined () const
 
VTBL_ENTRY const wxString & GetKicadEnvVariable () const
 
VTBL_ENTRY const wxString & GetExecutablePath () const
 
VTBL_ENTRY wxLocale * GetLocale ()
 
VTBL_ENTRY const wxString & GetPdfBrowserName () const
 
VTBL_ENTRY void SetPdfBrowserName (const wxString &aFileName)
 
VTBL_ENTRY bool UseSystemPdfBrowser () const
 Function UseSystemPdfBrowser 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. More...
 
VTBL_ENTRY void ForceSystemPdfBrowser (bool aFlg)
 Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set. More...
 
VTBL_ENTRY bool SetLanguage (wxString &aErrMsg, bool first_time=false)
 sets the dictionary file name for internationalization. More...
 
VTBL_ENTRY void SetLanguageIdentifier (int menu_id)
 Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id from the KiCad menu id (internal menu identifier). More...
 
VTBL_ENTRY int GetSelectedLanguageIdentifier () const
 
VTBL_ENTRY void SetLanguagePath ()
 
VTBL_ENTRY void ReadPdfBrowserInfos ()
 Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration. More...
 
VTBL_ENTRY void WritePdfBrowserInfos ()
 Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration. More...
 
VTBL_ENTRY bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Function SetLocalEnvVariable. More...
 
VTBL_ENTRY void SetLocalEnvVariables (const ENV_VAR_MAP &aEnvVarMap)
 Function SetLocalEnvVariables. More...
 
VTBL_ENTRY const ENV_VAR_MAPGetLocalEnvVariables () const
 
VTBL_ENTRY wxApp & App ()
 Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm ()
 Function initPgm initializes this program (process) in a KiCad standard way, using some generalized techniques. More...
 
void Destroy ()
 
void SaveCommonSettings ()
 Function saveCommonSettings saves 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...
 

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 ()
 Function setExecutablePath finds 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 KISYSMOD, and KISYS3DMOD. More...
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. More...
 

Detailed Description

PGM_BASE keeps program (whole process) data for KiCad programs.

The VTBL_ENTRY functions are VTBL_ENTRY 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 137 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 99 of file pgm_base.cpp.

100 {
102  m_locale = NULL;
103  m_Printing = false;
104 
105  m_show_env_var_dialog = true;
106 
107  setLanguageId( wxLANGUAGE_DEFAULT );
108 
109  ForceSystemPdfBrowser( false );
110 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:228
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351
#define NULL
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:369
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:341

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

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 113 of file pgm_base.cpp.

114 {
115  Destroy();
116 }
void Destroy()
Definition: pgm_base.cpp:119

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )

Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.

Should return what wxGetApp() returns.

Definition at line 130 of file pgm_base.cpp.

131 {
132  wxASSERT( wxTheApp );
133  return *wxTheApp;
134 }

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

◆ AskUserForPreferredEditor()

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

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

183 {
184  // Create a mask representing the executable files in the current platform
185 #ifdef __WINDOWS__
186  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
187 #else
188  wxString mask( _( "Executable file (*)|*" ) );
189 #endif
190 
191  // Extract the path, name and extension from the default editor (even if the editor's
192  // name was empty, this method will succeed and return empty strings).
193  wxString path, name, ext;
194  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
195 
196  // Show the modal editor and return the file chosen (may be empty if the user cancels
197  // the dialog).
198  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
199  name, ext, mask,
200  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
201  true );
202 }
#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)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:52
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:96

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

Referenced by GetEditorName().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 119 of file pgm_base.cpp.

120 {
121  // unlike a normal destructor, this is designed to be called more than once safely:
122  delete m_pgm_checker;
123  m_pgm_checker = 0;
124 
125  delete m_locale;
126  m_locale = 0;
127 }
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()

VTBL_ENTRY void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inline

Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set.

Definition at line 228 of file pgm_base.h.

228 { 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

Definition at line 554 of file pgm_base.cpp.

555 {
557 }
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
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)

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

146 {
147  wxString editorname = m_editor_name;
148 
149  if( !editorname )
150  {
151  if( !wxGetEnv( "EDITOR", &editorname ) )
152  {
153  // If there is no EDITOR variable set, try the desktop default
154 #ifdef __WXMAC__
155  editorname = "/usr/bin/open";
156 #elif __WXX11__
157  editorname = "/usr/bin/xdg-open";
158 #endif
159  }
160  }
161 
162  // If we still don't have an editor name show a dialog asking the user to select one
163  if( !editorname && aCanShowFileChooser )
164  {
166  _( "No default editor found, you must choose it" ) );
167 
168  editorname = AskUserForPreferredEditor();
169  }
170 
171  // If we finally have a new editor name request it to be copied to m_editor_name and
172  // saved to the preferences file.
173  if( !editorname.IsEmpty() )
174  SetEditorName( editorname );
175 
176  // m_editor_name already has the same value that editorname, or empty if no editor was
177  // found/chosen.
178  return m_editor_name;
179 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:137
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:182
#define NULL
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:96
wxString m_editor_name
Definition: pgm_base.h:380
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:268

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

◆ GetExecutablePath()

VTBL_ENTRY const wxString& PGM_BASE::GetExecutablePath ( ) const
inline

Definition at line 205 of file pgm_base.h.

205 { 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().

◆ GetKicadEnvVariable()

VTBL_ENTRY const wxString& PGM_BASE::GetKicadEnvVariable ( ) const
inline

Definition at line 203 of file pgm_base.h.

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

References m_kicad_env.

◆ GetLocale()

VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inline

Definition at line 207 of file pgm_base.h.

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

References m_locale.

◆ GetLocalEnvVariables()

VTBL_ENTRY const ENV_VAR_MAP& PGM_BASE::GetLocalEnvVariables ( ) const
inline

Definition at line 298 of file pgm_base.h.

299  {
300  return m_local_env_vars;
301  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384

References m_local_env_vars.

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

◆ GetPdfBrowserName()

VTBL_ENTRY const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inline

Definition at line 209 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

VTBL_ENTRY int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inline
Returns
the wxWidgets language identifier Id of the language currently selected

Definition at line 255 of file pgm_base.h.

255 { 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 ( )

Function initPgm initializes this program (process) in a KiCad standard way, using some generalized techniques.

  • Default paths (help, libs, bin) and configuration file names
  • Language and locale
  • fonts

But nothing relating to DSOs or projects.

Returns
bool - true if success, false if failure and program is to terminate.

Definition at line 205 of file pgm_base.cpp.

206 {
207  wxFileName pgm_name( App().argv[0] );
208 
209  wxInitAllImageHandlers();
210 
211  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
212  wxGetUserId(), GetKicadLockFilePath() );
213 
214  if( m_pgm_checker->IsAnotherRunning() )
215  {
216  wxString quiz =
217  wxString::Format( _( "%s is already running. Continue?" ), pgm_name.GetName() );
218 
219  if( !IsOK( NULL, quiz ) )
220  return false;
221  }
222 
223  m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
224 
225  // Something got in the way of settings load: can't continue
226  if( !m_settings_manager->IsOK() )
227  return false;
228 
229  // Init KiCad environment
230  // the environment variable KICAD (if exists) gives the kicad path:
231  // something like set KICAD=d:\kicad
232  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
233 
234  if( isDefined ) // ensure m_kicad_env ends by "/"
235  {
237 
238  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
240  }
241 
242  // Init parameters for configuration
243  App().SetVendorName( "KiCad" );
244  App().SetAppName( pgm_name.GetName().Lower() );
245 
246  // Install some image handlers, mainly for help
247  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
248  wxImage::AddHandler( new wxPNGHandler );
249 
250  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
251  wxImage::AddHandler( new wxGIFHandler );
252 
253  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
254  wxImage::AddHandler( new wxJPEGHandler );
255 
256  wxFileSystem::AddHandler( new wxZipFSHandler );
257 
258  // Analyze the command line & initialize the binary path
260 
261  SetLanguagePath();
262 
263  wxFileName baseSharePath;
264 #if defined( __WXMSW__ )
265  // Make the paths relative to the executable dir as KiCad might be installed anywhere
266  // It follows the Windows installer paths scheme, where binaries are installed in
267  // PATH/bin and extra files in PATH/share/kicad
268  baseSharePath.AssignDir( m_bin_dir + "\\.." );
269  baseSharePath.Normalize();
270 #else
271  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
272 #endif
273 
274 #if !defined( __WXMAC__ )
275  baseSharePath.AppendDir( "share" );
276  baseSharePath.AppendDir( "kicad" );
277 #endif
278 
279  // KISYSMOD
280  wxString envVarName = wxT( "KISYSMOD" );
281  ENV_VAR_ITEM envVarItem;
282  wxString envValue;
283  wxFileName tmpFileName;
284 
285  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
286  {
287  tmpFileName.AssignDir( envValue );
288  envVarItem.SetDefinedExternally( true );
289  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
290  }
291  else
292  {
293  tmpFileName = baseSharePath;
294  tmpFileName.AppendDir( "modules" );
295  envVarItem.SetDefinedExternally( false );
296  }
297 
298  envVarItem.SetValue( tmpFileName.GetPath() );
299  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
300  m_local_env_vars[ envVarName ] = envVarItem;
301 
302  // KISYS3DMOD
303  envVarName = wxT( "KISYS3DMOD" );
304 
305  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
306  {
307  tmpFileName.AssignDir( envValue );
308  envVarItem.SetDefinedExternally( true );
309  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
310  }
311  else
312  {
313  tmpFileName = baseSharePath;
314  tmpFileName.AppendDir( "3dmodels" );
315  envVarItem.SetDefinedExternally( false );
316  }
317 
318  envVarItem.SetValue( tmpFileName.GetFullPath() );
319  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
320  m_local_env_vars[ envVarName ] = envVarItem;
321 
322  // KICAD_TEMPLATE_DIR
323  envVarName = "KICAD_TEMPLATE_DIR";
324 
325  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
326  {
327  tmpFileName.AssignDir( envValue );
328  envVarItem.SetDefinedExternally( true );
329  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
330  }
331  else
332  {
333  // Attempt to find the best default template path.
334  SEARCH_STACK bases;
335  SEARCH_STACK templatePaths;
336 
337  SystemDirsAppend( &bases );
338 
339  for( unsigned i = 0; i < bases.GetCount(); ++i )
340  {
341  wxFileName fn( bases[i], wxEmptyString );
342 
343  // Add KiCad template file path to search path list.
344  fn.AppendDir( "template" );
345 
346  // Only add path if exists and can be read by the user.
347  if( fn.DirExists() && fn.IsDirReadable() )
348  {
349  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
350  fn.GetPath() );
351  templatePaths.AddPaths( fn.GetPath() );
352  }
353  }
354 
355  if( templatePaths.IsEmpty() )
356  {
357  tmpFileName = baseSharePath;
358  tmpFileName.AppendDir( "template" );
359  }
360  else
361  {
362  // Take the first one. There may be more but this will likely be the best option.
363  tmpFileName.AssignDir( templatePaths[0] );
364  }
365 
366  envVarItem.SetDefinedExternally( false );
367  }
368 
369  envVarItem.SetValue( tmpFileName.GetPath() );
370  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
371  m_local_env_vars[ envVarName ] = envVarItem;
372 
373  // KICAD_USER_TEMPLATE_DIR
374  envVarName = "KICAD_USER_TEMPLATE_DIR";
375 
376  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
377  {
378  tmpFileName.AssignDir( envValue );
379  envVarItem.SetDefinedExternally( true );
380  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
381  }
382  else
383  {
384  // Default user template path.
385  tmpFileName.AssignDir( wxStandardPaths::Get().GetDocumentsDir() );
386  tmpFileName.AppendDir( "kicad" );
387  tmpFileName.AppendDir( "template" );
388  envVarItem.SetDefinedExternally( false );
389  }
390 
391  envVarItem.SetValue( tmpFileName.GetPath() );
392  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
393  m_local_env_vars[ envVarName ] = envVarItem;
394 
395  // KICAD_SYMBOLS
396  envVarName = wxT( "KICAD_SYMBOL_DIR" );
397 
398  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
399  {
400  tmpFileName.AssignDir( envValue );
401  envVarItem.SetDefinedExternally( true );
402  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
403  }
404  else
405  {
406  tmpFileName = baseSharePath;
407  tmpFileName.AppendDir( "library" );
408  envVarItem.SetDefinedExternally( false );
409  }
410 
411  envVarItem.SetValue( tmpFileName.GetPath() );
412  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
413  m_local_env_vars[ envVarName ] = envVarItem;
414 
416 
417  // Init user language *before* calling loadCommonSettings, because
418  // env vars could be incorrectly initialized on Linux
419  // (if the value contains some non ASCII7 chars, the env var is not initialized)
420  wxString tmp;
421  SetLanguage( tmp, true );
422 
424 
425  ReadPdfBrowserInfos(); // needs GetCommonSettings()
426 
427 #ifdef __WXMAC__
428  // Always show filters on Open dialog to be able to choose plugin
429  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
430 #endif
431 
432  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
433  // Need to create a project early for now (it can have an empty path for the moment)
435 
436  return true;
437 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:482
wxString GetKicadLockFilePath()
Function GetKicadLockFilePath.
Definition: lockfile.cpp:60
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
ENV_VAR_ITEM.
Definition: pgm_base.h:88
const wxString & GetValue() const
Definition: pgm_base.h:105
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:130
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:440
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:351
SEARCH_STACK looks for files in a number of places.
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:100
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
VTBL_ENTRY bool SetLanguage(wxString &aErrMsg, bool first_time=false)
sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:560
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:685
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs 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.
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
void SetValue(const wxString &aValue)
Definition: pgm_base.h:106
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:96
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:284
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)

References _, SEARCH_STACK::AddPaths(), App(), 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(), 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()

VTBL_ENTRY bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inline

Definition at line 201 of file pgm_base.h.

201 { 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 482 of file pgm_base.cpp.

483 {
484  m_help_size.x = 500;
485  m_help_size.y = 400;
486 
489 
490  for( const auto& it : GetCommonSettings()->m_Env.vars )
491  {
492  wxString key( it.first.c_str(), wxConvUTF8 );
493  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s", key, it.second );
494 
495  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
496  // it is found in config. (It is reserved and defined as project path)
497  if( key == PROJECT_VAR_NAME )
498  continue;
499 
500  if( m_local_env_vars[ key ].GetDefinedExternally() )
501  continue;
502 
503  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s", key, it.second );
504 
505  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
506  }
507 
508  for( auto& m_local_env_var : m_local_env_vars )
509  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
510 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
ENV_VAR_ITEM.
Definition: pgm_base.h:88
#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:387
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:720
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxSize m_help_size
Definition: pgm_base.h:381
wxString m_editor_name
Definition: pgm_base.h:380

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()

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

Function MacOpenFile is 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_TEST_FRAME, PGM_SINGLE_TOP, PGM_KICAD, and PGM_TEST_FRAME.

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )

Function ReadPdfBrowserInfos reads 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 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
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
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:211

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 ( )

Function saveCommonSettings saves the program (process) settings subset which are stored .kicad_common.

Definition at line 513 of file pgm_base.cpp.

514 {
515  // GetCommonSettings() is not initialized until fairly late in the
516  // process startup: InitPgm(), so test before using:
517  if( GetCommonSettings() )
518  {
519  GetCommonSettings()->m_System.working_dir = wxGetCwd();
521 
522  // remove only the old env vars that do not exist in list.
523  // We do not clear the full list because some are defined externally,
524  // and we cannot modify or delete them
525  std::map<std::string, wxString>& curr_vars = GetCommonSettings()->m_Env.vars;
526 
527  for( auto it = curr_vars.begin(); it != curr_vars.end(); )
528  {
529  const std::string& key = it->first;
530 
531  if( m_local_env_vars.find( key ) == m_local_env_vars.end() )
532  it = curr_vars.erase( it ); // This entry no longer exists in new list
533  else
534  it++;
535  }
536 
537  // Save the local environment variables.
538  for( auto& m_local_env_var : m_local_env_vars )
539  {
540  if( m_local_env_var.second.GetDefinedExternally() )
541  continue;
542 
543  wxLogTrace( traceEnvVars,
544  "PGM_BASE::SaveCommonSettings: Saving environment variable config entry %s as %s",
545  m_local_env_var.first, m_local_env_var.second.GetValue() );
546 
547  std::string key( m_local_env_var.first.ToUTF8() );
548  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
549  }
550  }
551 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
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().

◆ SetEditorName()

void PGM_BASE::SetEditorName ( const wxString &  aFileName)

Definition at line 137 of file pgm_base.cpp.

138 {
139  m_editor_name = aFileName;
140  wxASSERT( GetCommonSettings() );
141  GetCommonSettings()->m_System.editor_name = aFileName;
142 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
wxString m_editor_name
Definition: pgm_base.h:380

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

Referenced by GetEditorName().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protected

Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.

Returns
bool - true if success, else false.

Definition at line 440 of file pgm_base.cpp.

441 {
442  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
443 
444 #ifdef __WXMAC__
445  // On OSX Pgm().GetExecutablePath() will always point to main
446  // bundle directory, e.g., /Applications/kicad.app/
447 
448  wxFileName fn( m_bin_dir );
449 
450  if( fn.GetName() == wxT( "kicad" ) )
451  {
452  // kicad launcher, so just remove the Contents/MacOS part
453  fn.RemoveLastDir();
454  fn.RemoveLastDir();
455  }
456  else
457  {
458  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
459  fn.RemoveLastDir();
460  fn.RemoveLastDir();
461  fn.RemoveLastDir();
462  fn.RemoveLastDir();
463  fn.RemoveLastDir();
464  }
465 
466  m_bin_dir = fn.GetPath() + wxT( "/" );
467 #else
468  // Use unix notation for paths. I am not sure this is a good idea,
469  // but it simplifies compatibility between Windows and Unices.
470  // However it is a potential problem in path handling under Windows.
472 
473  // Remove file name form command line:
474  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
475  m_bin_dir.RemoveLast();
476 #endif
477 
478  return true;
479 }
#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 
)

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

561 {
562  if( first_time )
563  {
564  setLanguageId( wxLANGUAGE_DEFAULT );
565  // First time SetLanguage is called, the user selected language id is set
566  // from common user config settings
567  wxString languageSel = GetCommonSettings()->m_System.language;
568 
569  // Search for the current selection
570  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
571  {
572  if( LanguagesList[ii].m_Lang_Label == languageSel )
573  {
574  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
575  break;
576  }
577  }
578  }
579 
580  // dictionary file name without extend (full name is kicad.mo)
581  wxString dictionaryName( "kicad" );
582 
583  delete m_locale;
584  m_locale = new wxLocale;
585 
586  if( !m_locale->Init( m_language_id ) )
587  {
588  wxLogTrace( traceLocale, "This language is not supported by the system." );
589 
590  setLanguageId( wxLANGUAGE_DEFAULT );
591  delete m_locale;
592 
593  m_locale = new wxLocale;
594  m_locale->Init();
595 
596  aErrMsg = _( "This language is not supported by the operating system." );
597  return false;
598  }
599  else if( !first_time )
600  {
601  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
602  dictionaryName, m_locale->GetName() );
603  }
604 
605  if( !first_time )
606  {
607  // If we are here, the user has selected another language.
608  // Therefore the new prefered language name is stored in common config.
609  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
610  // versions, for a given language
611  wxString languageSel;
612 
613  // Search for the current selection language name
614  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
615  {
616  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
617  {
618  languageSel = LanguagesList[ii].m_Lang_Label;
619  break;
620  }
621  }
622 
624  cfg->m_System.language = languageSel;
625  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
626  }
627 
628  // Test if floating point notation is working (bug encountered in cross compilation)
629  // Make a conversion double <=> string
630  double dtst = 0.5;
631  wxString msg;
632 
633  msg << dtst;
634  double result;
635  msg.ToDouble( &result );
636 
637  // string to double encode/decode does not work! Bug detected:
638  // Disable floating point localization:
639  if( result != dtst )
640  setlocale( LC_NUMERIC, "C" );
641 
642  // Try adding the dictionary if it is not currently loaded
643  if( !m_locale->IsLoaded( dictionaryName ) )
644  m_locale->AddCatalog( dictionaryName );
645 
646  // Verify the Kicad dictionary was loaded properly
647  // However, for the English language, the dictionnary is not mandatory, as
648  // all messages are already in English, just restricted to ASCII7 chars,
649  // the verification is skipped.
650  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
651  {
652  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
653  dictionaryName, m_locale->GetName() );
654 
655  setLanguageId( wxLANGUAGE_DEFAULT );
656  delete m_locale;
657 
658  m_locale = new wxLocale;
659  m_locale->Init();
660 
661  aErrMsg = _( "The KiCad language file for this language is not installed." );
662  return false;
663  }
664 
665  return true;
666 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:72
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
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:63
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:369
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)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:96

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

369 { 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(), SetLanguage(), and SetLanguageIdentifier().

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)

Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id from the KiCad menu id (internal menu identifier).

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

Definition at line 669 of file pgm_base.cpp.

670 {
671  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
672  menu_id, (int)arrayDim( LanguagesList )-1 );
673 
674  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
675  {
676  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
677  {
678  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
679  break;
680  }
681  }
682 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:72
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:369
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 ( )

Definition at line 685 of file pgm_base.cpp.

686 {
687  SEARCH_STACK guesses;
688 
689  SystemDirsAppend( &guesses );
690 
691  // Add our internat dir to the wxLocale catalog of paths
692  for( unsigned i = 0; i < guesses.GetCount(); i++ )
693  {
694  wxFileName fn( guesses[i], wxEmptyString );
695 
696  // Append path for Windows and unix KiCad package install
697  fn.AppendDir( "share" );
698  fn.AppendDir( "internat" );
699 
700  if( fn.IsDirReadable() )
701  {
702  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
703  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
704  }
705 
706  // Append path for unix standard install
707  fn.RemoveLastDir();
708  fn.AppendDir( "kicad" );
709  fn.AppendDir( "internat" );
710 
711  if( fn.IsDirReadable() )
712  {
713  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
714  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
715  }
716  }
717 }
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
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 
)

Function SetLocalEnvVariable.

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

721 {
722  wxString env;
723 
724  // Check to see if the environment variable is already set.
725  if( wxGetEnv( aName, &env ) )
726  {
727  wxLogTrace( traceEnvVars,
728  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
729  aName, env );
730  return env == aValue;
731  }
732 
733  wxLogTrace( traceEnvVars,
734  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
735  aName, aValue );
736 
737  return wxSetEnv( aName, aValue );
738 }
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)

Function SetLocalEnvVariables.

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

742 {
743  m_local_env_vars.clear();
744  m_local_env_vars = aEnvVarMap;
745 
747 
748  // Overwrites externally defined environment variable until the next time the application
749  // is run.
750  for( auto& m_local_env_var : m_local_env_vars )
751  {
752  wxLogTrace( traceEnvVars,
753  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
754  m_local_env_var.first,
755  m_local_env_var.second.GetValue() );
756  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
757  }
758 }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:513
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References m_local_env_vars, SaveCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

VTBL_ENTRY void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inline

Definition at line 211 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ UseSystemPdfBrowser()

VTBL_ENTRY bool PGM_BASE::UseSystemPdfBrowser ( ) const
inline

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

220  {
221  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
222  }
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:379

References m_pdf_browser, and m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )

Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.

Definition at line 49 of file eda_doc.cpp.

50 {
53 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
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
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:209

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(), InitPgm(), and setExecutablePath().

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protected

Definition at line 380 of file pgm_base.h.

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

◆ m_help_size

wxSize PGM_BASE::m_help_size
protected

Definition at line 381 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(), SetLanguage(), and setLanguageId().

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protected

Local environment variable expansion settings such as KISYSMOD, and KISYS3DMOD.

Definition at line 384 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(), and SetLanguage().

◆ 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 379 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 341 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 387 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 312 of file pgm_base.h.


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