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 KIGITHUB, 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 98 of file pgm_base.cpp.

99 {
101  m_locale = NULL;
102  m_Printing = false;
103 
104  m_show_env_var_dialog = true;
105 
106  setLanguageId( wxLANGUAGE_DEFAULT );
107 
108  ForceSystemPdfBrowser( false );
109 }
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 112 of file pgm_base.cpp.

113 {
114  Destroy();
115 }
void Destroy()
Definition: pgm_base.cpp:118

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

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

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

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

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

Referenced by GetEditorName().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 118 of file pgm_base.cpp.

119 {
120  // unlike a normal destructor, this is designed to be called more than once safely:
121  delete m_pgm_checker;
122  m_pgm_checker = 0;
123 
124  delete m_locale;
125  m_locale = 0;
126 }
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 PGM_KICAD::Destroy(), PGM_SINGLE_TOP::OnPgmExit(), PGM_MOCK_EESCHEMA_FRAME::OnPgmExit(), PGM_TEST_FRAME::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 571 of file pgm_base.cpp.

572 {
574 }
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 144 of file pgm_base.cpp.

145 {
146  wxString editorname = m_editor_name;
147 
148  if( !editorname )
149  {
150  if( !wxGetEnv( "EDITOR", &editorname ) )
151  {
152  // If there is no EDITOR variable set, try the desktop default
153 #ifdef __WXMAC__
154  editorname = "/usr/bin/open";
155 #elif __WXX11__
156  editorname = "/usr/bin/xdg-open";
157 #endif
158  }
159  }
160 
161  // If we still don't have an editor name show a dialog asking the user to select one
162  if( !editorname && aCanShowFileChooser )
163  {
165  _( "No default editor found, you must choose it" ) );
166 
167  editorname = AskUserForPreferredEditor();
168  }
169 
170  // If we finally have a new editor name request it to be copied to m_editor_name and
171  // saved to the preferences file.
172  if( !editorname.IsEmpty() )
173  SetEditorName( editorname );
174 
175  // m_editor_name already has the same value that editorname, or empty if no editor was
176  // found/chosen.
177  return m_editor_name;
178 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:136
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:181
#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:95
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:267

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 KIGITHUB, 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 204 of file pgm_base.cpp.

205 {
206  wxFileName pgm_name( App().argv[0] );
207 
208  wxInitAllImageHandlers();
209 
210  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
211  wxGetUserId(), GetKicadLockFilePath() );
212 
213  if( m_pgm_checker->IsAnotherRunning() )
214  {
215  wxString quiz = wxString::Format(
216  _( "%s is already running. Continue?" ),
217  GetChars( pgm_name.GetName() )
218  );
219 
220  if( !IsOK( NULL, quiz ) )
221  return false;
222  }
223 
224  m_settings_manager = std::unique_ptr<SETTINGS_MANAGER>( new SETTINGS_MANAGER );
225 
226  // Something got in the way of settings load: can't continue
227  if( !m_settings_manager->IsOK() )
228  return false;
229 
230  // Init KiCad environment
231  // the environment variable KICAD (if exists) gives the kicad path:
232  // something like set KICAD=d:\kicad
233  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
234 
235  if( isDefined ) // ensure m_kicad_env ends by "/"
236  {
238 
239  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
241  }
242 
243  // Init parameters for configuration
244  App().SetVendorName( "KiCad" );
245  App().SetAppName( pgm_name.GetName().Lower() );
246 
247  // Install some image handlers, mainly for help
248  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
249  wxImage::AddHandler( new wxPNGHandler );
250 
251  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
252  wxImage::AddHandler( new wxGIFHandler );
253 
254  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
255  wxImage::AddHandler( new wxJPEGHandler );
256 
257  wxFileSystem::AddHandler( new wxZipFSHandler );
258 
259  // Analyze the command line & initialize the binary path
261 
262  SetLanguagePath();
263 
264  wxString envVarName = wxT( "KIGITHUB" );
265  ENV_VAR_ITEM envVarItem;
266  wxString envValue;
267  wxFileName tmpFileName;
268 
269  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
270  {
271  tmpFileName.AssignDir( envValue );
272  envVarItem.SetDefinedExternally( true );
273  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
274  }
275  else
276  {
277  envVarItem.SetValue( wxString( wxT( "https://github.com/KiCad" ) ) );
278  envVarItem.SetDefinedExternally( false );
279  }
280 
281  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
282  m_local_env_vars[ envVarName ] = envVarItem;
283 
284  wxFileName baseSharePath;
285 #if defined( __WXMSW__ )
286  // Make the paths relative to the executable dir as KiCad might be installed anywhere
287  // It follows the Windows installer paths scheme, where binaries are installed in
288  // PATH/bin and extra files in PATH/share/kicad
289  baseSharePath.AssignDir( m_bin_dir + "\\.." );
290  baseSharePath.Normalize();
291 #else
292  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
293 #endif
294 
295 #if !defined( __WXMAC__ )
296  baseSharePath.AppendDir( "share" );
297  baseSharePath.AppendDir( "kicad" );
298 #endif
299 
300  // KISYSMOD
301  envVarName = wxT( "KISYSMOD" );
302 
303  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
304  {
305  tmpFileName.AssignDir( envValue );
306  envVarItem.SetDefinedExternally( true );
307  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
308  }
309  else
310  {
311  tmpFileName = baseSharePath;
312  tmpFileName.AppendDir( "modules" );
313  envVarItem.SetDefinedExternally( false );
314  }
315 
316  envVarItem.SetValue( tmpFileName.GetPath() );
317  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
318  m_local_env_vars[ envVarName ] = envVarItem;
319 
320  // KISYS3DMOD
321  envVarName = wxT( "KISYS3DMOD" );
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.AppendDir( "packages3d" );
332  envVarItem.SetDefinedExternally( false );
333  }
334 
335  envVarItem.SetValue( tmpFileName.GetFullPath() );
336  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
337  m_local_env_vars[ envVarName ] = envVarItem;
338 
339  // KICAD_TEMPLATE_DIR
340  envVarName = "KICAD_TEMPLATE_DIR";
341 
342  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
343  {
344  tmpFileName.AssignDir( envValue );
345  envVarItem.SetDefinedExternally( true );
346  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
347  }
348  else
349  {
350  // Attempt to find the best default template path.
351  SEARCH_STACK bases;
352  SEARCH_STACK templatePaths;
353 
354  SystemDirsAppend( &bases );
355 
356  for( unsigned i = 0; i < bases.GetCount(); ++i )
357  {
358  wxFileName fn( bases[i], wxEmptyString );
359 
360  // Add KiCad template file path to search path list.
361  fn.AppendDir( "template" );
362 
363  // Only add path if exists and can be read by the user.
364  if( fn.DirExists() && fn.IsDirReadable() )
365  {
366  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
367  fn.GetPath() );
368  templatePaths.AddPaths( fn.GetPath() );
369  }
370  }
371 
372  if( templatePaths.IsEmpty() )
373  {
374  tmpFileName = baseSharePath;
375  tmpFileName.AppendDir( "template" );
376  }
377  else
378  {
379  // Take the first one. There may be more but this will likely be the best option.
380  tmpFileName.AssignDir( templatePaths[0] );
381  }
382 
383  envVarItem.SetDefinedExternally( false );
384  }
385 
386  envVarItem.SetValue( tmpFileName.GetPath() );
387  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
388  m_local_env_vars[ envVarName ] = envVarItem;
389 
390  // KICAD_USER_TEMPLATE_DIR
391  envVarName = "KICAD_USER_TEMPLATE_DIR";
392 
393  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
394  {
395  tmpFileName.AssignDir( envValue );
396  envVarItem.SetDefinedExternally( true );
397  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
398  }
399  else
400  {
401  // Default user template path.
402  tmpFileName.AssignDir( wxStandardPaths::Get().GetDocumentsDir() );
403  tmpFileName.AppendDir( "kicad" );
404  tmpFileName.AppendDir( "template" );
405  envVarItem.SetDefinedExternally( false );
406  }
407 
408  envVarItem.SetValue( tmpFileName.GetPath() );
409  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
410  m_local_env_vars[ envVarName ] = envVarItem;
411 
412  // KICAD_SYMBOLS
413  envVarName = wxT( "KICAD_SYMBOL_DIR" );
414 
415  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
416  {
417  tmpFileName.AssignDir( envValue );
418  envVarItem.SetDefinedExternally( true );
419  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
420  }
421  else
422  {
423  tmpFileName = baseSharePath;
424  tmpFileName.AppendDir( "library" );
425  envVarItem.SetDefinedExternally( false );
426  }
427 
428  envVarItem.SetValue( tmpFileName.GetPath() );
429  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName, envVarItem.GetValue() );
430  m_local_env_vars[ envVarName ] = envVarItem;
431 
433 
434  // Init user language *before* calling loadCommonSettings, because
435  // env vars could be incorrectly initialized on Linux
436  // (if the value contains some non ASCII7 chars, the env var is not initialized)
437  wxString tmp;
438  SetLanguage( tmp, true );
439 
441 
442  ReadPdfBrowserInfos(); // needs GetCommonSettings()
443 
444 #ifdef __WXMAC__
445  // Always show filters on Open dialog to be able to choose plugin
446  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
447 #endif
448 
449  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
450  // Need to create a project early for now (it can have an empty path for the moment)
452 
453  return true;
454 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:499
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 KIGITHUB, 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:129
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:457
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:577
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:699
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354
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:43
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
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:95
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:283
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)

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

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

500 {
501  m_help_size.x = 500;
502  m_help_size.y = 400;
503 
506 
507  for( const auto& it : GetCommonSettings()->m_Env.vars )
508  {
509  wxString key( it.first.c_str(), wxConvUTF8 );
510  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s", key, it.second );
511 
512  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
513  // it is found in config. (It is reserved and defined as project path)
514  if( key == PROJECT_VAR_NAME )
515  continue;
516 
517  if( m_local_env_vars[ key ].GetDefinedExternally() )
518  continue;
519 
520  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s", key, it.second );
521 
522  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
523  }
524 
525  for( auto& m_local_env_var : m_local_env_vars )
526  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
527 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, 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:734
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_SINGLE_TOP, PGM_TEST_FRAME, 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 43 of file eda_doc.cpp.

44 {
45  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
47 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
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 530 of file pgm_base.cpp.

531 {
532  // GetCommonSettings() is not initialized until fairly late in the
533  // process startup: InitPgm(), so test before using:
534  if( GetCommonSettings() )
535  {
536  GetCommonSettings()->m_System.working_dir = wxGetCwd();
538 
539  // remove only the old env vars that do not exist in list.
540  // We do not clear the full list because some are defined externally,
541  // and we cannot modify or delete them
542  std::map<std::string, wxString>& curr_vars = GetCommonSettings()->m_Env.vars;
543 
544  for( auto it = curr_vars.begin(); it != curr_vars.end(); )
545  {
546  const std::string& key = it->first;
547 
548  if( m_local_env_vars.find( key ) == m_local_env_vars.end() )
549  it = curr_vars.erase( it ); // This entry no longer exists in new list
550  else
551  it++;
552  }
553 
554  // Save the local environment variables.
555  for( auto& m_local_env_var : m_local_env_vars )
556  {
557  if( m_local_env_var.second.GetDefinedExternally() )
558  continue;
559 
560  wxLogTrace( traceEnvVars,
561  "PGM_BASE::SaveCommonSettings: Saving environment variable config entry %s as %s",
562  m_local_env_var.first, m_local_env_var.second.GetValue() );
563 
564  std::string key( m_local_env_var.first.ToUTF8() );
565  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
566  }
567  }
568 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, 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 136 of file pgm_base.cpp.

137 {
138  m_editor_name = aFileName;
139  wxASSERT( GetCommonSettings() );
140  GetCommonSettings()->m_System.editor_name = aFileName;
141 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
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 457 of file pgm_base.cpp.

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

578 {
579  if( first_time )
580  {
581  setLanguageId( wxLANGUAGE_DEFAULT );
582  // First time SetLanguage is called, the user selected language id is set
583  // from common user config settings
584  wxString languageSel = GetCommonSettings()->m_System.language;
585 
586  // Search for the current selection
587  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
588  {
589  if( LanguagesList[ii].m_Lang_Label == languageSel )
590  {
591  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
592  break;
593  }
594  }
595  }
596 
597  // dictionary file name without extend (full name is kicad.mo)
598  wxString dictionaryName( "kicad" );
599 
600  delete m_locale;
601  m_locale = new wxLocale;
602 
603  if( !m_locale->Init( m_language_id ) )
604  {
605  wxLogTrace( traceLocale, "This language is not supported by the system." );
606 
607  setLanguageId( wxLANGUAGE_DEFAULT );
608  delete m_locale;
609 
610  m_locale = new wxLocale;
611  m_locale->Init();
612 
613  aErrMsg = _( "This language is not supported by the operating system." );
614  return false;
615  }
616  else if( !first_time )
617  {
618  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
619  dictionaryName, m_locale->GetName() );
620  }
621 
622  if( !first_time )
623  {
624  // If we are here, the user has selected another language.
625  // Therefore the new prefered language name is stored in common config.
626  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
627  // versions, for a given language
628  wxString languageSel;
629 
630  // Search for the current selection language name
631  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
632  {
633  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
634  {
635  languageSel = LanguagesList[ii].m_Lang_Label;
636  break;
637  }
638  }
639 
641  cfg->m_System.language = languageSel;
642  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
643  }
644 
645  // Test if floating point notation is working (bug encountered in cross compilation)
646  // Make a conversion double <=> string
647  double dtst = 0.5;
648  wxString msg;
649 
650  msg << dtst;
651  double result;
652  msg.ToDouble( &result );
653 
654  // string to double encode/decode does not work! Bug detected:
655  // Disable floating point localization:
656  if( result != dtst )
657  setlocale( LC_NUMERIC, "C" );
658 
659  // Try adding the dictionary if it is not currently loaded
660  if( !m_locale->IsLoaded( dictionaryName ) )
661  m_locale->AddCatalog( dictionaryName );
662 
663  // Verify the dictionary was loaded properly
664  if( !m_locale->IsLoaded( dictionaryName ) )
665  {
666  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
667  dictionaryName, m_locale->GetName() );
668 
669  setLanguageId( wxLANGUAGE_DEFAULT );
670  delete m_locale;
671 
672  m_locale = new wxLocale;
673  m_locale->Init();
674 
675  aErrMsg = _( "The KiCad language file for this language is not installed." );
676  return false;
677  }
678 
679  return true;
680 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:71
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:95

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

684 {
685  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
686  menu_id, (int)arrayDim( LanguagesList )-1 );
687 
688  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
689  {
690  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
691  {
692  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
693  break;
694  }
695  }
696 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:71
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
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.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )

Definition at line 699 of file pgm_base.cpp.

700 {
701  SEARCH_STACK guesses;
702 
703  SystemDirsAppend( &guesses );
704 
705  // Add our internat dir to the wxLocale catalog of paths
706  for( unsigned i = 0; i < guesses.GetCount(); i++ )
707  {
708  wxFileName fn( guesses[i], wxEmptyString );
709 
710  // Append path for Windows and unix KiCad package install
711  fn.AppendDir( "share" );
712  fn.AppendDir( "internat" );
713 
714  if( fn.IsDirReadable() )
715  {
716  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
717  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
718  }
719 
720  // Append path for unix standard install
721  fn.RemoveLastDir();
722  fn.AppendDir( "kicad" );
723  fn.AppendDir( "internat" );
724 
725  if( fn.IsDirReadable() )
726  {
727  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
728  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
729  }
730  }
731 }
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 734 of file pgm_base.cpp.

735 {
736  wxString env;
737 
738  // Check to see if the environment variable is already set.
739  if( wxGetEnv( aName, &env ) )
740  {
741  wxLogTrace( traceEnvVars,
742  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
743  aName, env );
744  return env == aValue;
745  }
746 
747  wxLogTrace( traceEnvVars,
748  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
749  aName, aValue );
750 
751  return wxSetEnv( aName, aValue );
752 }
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 755 of file pgm_base.cpp.

756 {
757  m_local_env_vars.clear();
758  m_local_env_vars = aEnvVarMap;
759 
761 
762  // Overwrites externally defined environment variable until the next time the application
763  // is run.
764  for( auto& m_local_env_var : m_local_env_vars )
765  {
766  wxLogTrace( traceEnvVars,
767  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
768  m_local_env_var.first,
769  m_local_env_var.second.GetValue() );
770  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
771  }
772 }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, 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:530
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 50 of file eda_doc.cpp.

51 {
54 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:571
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 KIGITHUB, 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: