KiCad PCB EDA Suite
pgm_base.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
33 #include <fctsys.h>
34 #include <wx/html/htmlwin.h>
35 #include <wx/fs_zip.h>
36 #include <wx/dir.h>
37 #include <wx/filename.h>
38 #include <wx/snglinst.h>
39 #include <wx/stdpaths.h>
40 #include <wx/sysopt.h>
41 #include <wx/richmsgdlg.h>
42 
43 #include <build_version.h>
44 #include <config_params.h>
45 #include <confirm.h>
46 #include <dialog_configure_paths.h>
47 #include <eda_base_frame.h>
48 #include <eda_draw_frame.h>
50 #include <gestfich.h>
51 #include <hotkeys_basic.h>
52 #include <id.h>
53 #include <lockfile.h>
54 #include <macros.h>
55 #include <menus_helpers.h>
56 #include <pgm_base.h>
59 #include <systemdirsappend.h>
60 #include <trace_helpers.h>
61 
62 
63 static const wxChar traceEnvVars[] = wxT( "KIENVVARS" );
64 
65 
72 #undef _
73 #define _(s) s
75 {
76  { wxLANGUAGE_DEFAULT, ID_LANGUAGE_DEFAULT, lang_def_xpm, _( "Default" ), false },
77  { wxLANGUAGE_ENGLISH, ID_LANGUAGE_ENGLISH, lang_en_xpm, wxT( "English" ), true },
78  { wxLANGUAGE_FRENCH, ID_LANGUAGE_FRENCH, lang_fr_xpm, _( "French" ), false },
79  { wxLANGUAGE_FINNISH, ID_LANGUAGE_FINNISH, lang_fi_xpm, _( "Finnish" ), false },
80  { wxLANGUAGE_SPANISH, ID_LANGUAGE_SPANISH, lang_es_xpm, _( "Spanish" ), false },
81  { wxLANGUAGE_PORTUGUESE, ID_LANGUAGE_PORTUGUESE, lang_pt_xpm, _( "Portuguese" ), false },
82  { wxLANGUAGE_ITALIAN, ID_LANGUAGE_ITALIAN, lang_it_xpm, _( "Italian" ), false },
83  { wxLANGUAGE_GERMAN, ID_LANGUAGE_GERMAN, lang_de_xpm, _( "German" ), false },
84  { wxLANGUAGE_GREEK, ID_LANGUAGE_GREEK, lang_gr_xpm, _( "Greek" ), false },
85  { wxLANGUAGE_SLOVENIAN, ID_LANGUAGE_SLOVENIAN, lang_sl_xpm, _( "Slovenian" ), false },
86  { wxLANGUAGE_SLOVAK, ID_LANGUAGE_SLOVAK, lang_sk_xpm, _( "Slovak" ), false },
87  { wxLANGUAGE_HUNGARIAN, ID_LANGUAGE_HUNGARIAN, lang_hu_xpm, _( "Hungarian" ), false },
88  { wxLANGUAGE_POLISH, ID_LANGUAGE_POLISH, lang_pl_xpm, _( "Polish" ), false },
89  { wxLANGUAGE_CZECH, ID_LANGUAGE_CZECH, lang_cs_xpm, _( "Czech" ), false },
90  { wxLANGUAGE_RUSSIAN, ID_LANGUAGE_RUSSIAN, lang_ru_xpm, _( "Russian" ), false },
91  { wxLANGUAGE_KOREAN, ID_LANGUAGE_KOREAN, lang_ko_xpm, _( "Korean" ), false },
92  { wxLANGUAGE_CHINESE_SIMPLIFIED, ID_LANGUAGE_CHINESE_SIMPLIFIED, lang_zh_xpm,
93  _( "Chinese simplified" ), false },
94  { wxLANGUAGE_CHINESE_TRADITIONAL, ID_LANGUAGE_CHINESE_TRADITIONAL, lang_zh_xpm,
95  _( "Chinese traditional" ), false },
96  { wxLANGUAGE_CATALAN, ID_LANGUAGE_CATALAN, lang_ca_xpm, _( "Catalan" ), false },
97  { wxLANGUAGE_DUTCH, ID_LANGUAGE_DUTCH, lang_nl_xpm, _( "Dutch" ), false },
98  { wxLANGUAGE_JAPANESE, ID_LANGUAGE_JAPANESE, lang_jp_xpm, _( "Japanese" ), false },
99  { wxLANGUAGE_BULGARIAN, ID_LANGUAGE_BULGARIAN, lang_bg_xpm, _( "Bulgarian" ), false },
100  { wxLANGUAGE_LITHUANIAN, ID_LANGUAGE_LITHUANIAN, lang_lt_xpm, _( "Lithuanian" ), false },
101  { 0, 0, lang_def_xpm, "", false } // Sentinel
102 };
103 #undef _
104 #define _(s) wxGetTranslation((s))
105 
106 
108 {
110  m_locale = NULL;
111  m_Printing = false;
112 
113  m_show_env_var_dialog = true;
114 
115  setLanguageId( wxLANGUAGE_DEFAULT );
116 
117  ForceSystemPdfBrowser( false );
118 }
119 
120 
122 {
123  Destroy();
124 }
125 
126 
128 {
129  // unlike a normal destructor, this is designed to be called more than once safely:
130  delete m_pgm_checker;
131  m_pgm_checker = 0;
132 
133  delete m_locale;
134  m_locale = 0;
135 }
136 
137 
139 {
140  wxASSERT( wxTheApp );
141  return *wxTheApp;
142 }
143 
144 
145 void PGM_BASE::SetEditorName( const wxString& aFileName )
146 {
147  m_editor_name = aFileName;
148  wxASSERT( GetCommonSettings() );
149  GetCommonSettings()->m_System.editor_name = aFileName;
150 }
151 
152 
153 const wxString& PGM_BASE::GetEditorName( bool aCanShowFileChooser )
154 {
155  wxString editorname = m_editor_name;
156 
157  if( !editorname )
158  {
159  if( !wxGetEnv( "EDITOR", &editorname ) )
160  {
161  // If there is no EDITOR variable set, try the desktop default
162 #ifdef __WXMAC__
163  editorname = "/usr/bin/open";
164 #elif __WXX11__
165  editorname = "/usr/bin/xdg-open";
166 #endif
167  }
168  }
169 
170  // If we still don't have an editor name show a dialog asking the user to select one
171  if( !editorname && aCanShowFileChooser )
172  {
174  _( "No default editor found, you must choose it" ) );
175 
176  editorname = AskUserForPreferredEditor();
177  }
178 
179  // If we finally have a new editor name request it to be copied to m_editor_name and
180  // saved to the preferences file.
181  if( !editorname.IsEmpty() )
182  SetEditorName( editorname );
183 
184  // m_editor_name already has the same value that editorname, or empty if no editor was
185  // found/chosen.
186  return m_editor_name;
187 }
188 
189 
190 const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEditor )
191 {
192  // Create a mask representing the executable files in the current platform
193 #ifdef __WINDOWS__
194  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
195 #else
196  wxString mask( _( "Executable file (*)|*" ) );
197 #endif
198 
199  // Extract the path, name and extension from the default editor (even if the editor's
200  // name was empty, this method will succeed and return empty strings).
201  wxString path, name, ext;
202  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
203 
204  // Show the modal editor and return the file chosen (may be empty if the user cancels
205  // the dialog).
206  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
207  name, ext, mask,
208  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
209  true );
210 }
211 
212 
214 {
215  wxFileName pgm_name( App().argv[0] );
216 
217  wxInitAllImageHandlers();
218 
219  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
220  wxGetUserId(), GetKicadLockFilePath() );
221 
222  if( m_pgm_checker->IsAnotherRunning() )
223  {
224  wxString quiz = wxString::Format(
225  _( "%s is already running. Continue?" ),
226  GetChars( pgm_name.GetName() )
227  );
228 
229  if( !IsOK( NULL, quiz ) )
230  return false;
231  }
232 
233  m_settings_manager = std::unique_ptr<SETTINGS_MANAGER>( new SETTINGS_MANAGER );
234 
235  // Something got in the way of settings load: can't continue
236  if( !m_settings_manager->IsOK() )
237  return false;
238 
239  // Init KiCad environment
240  // the environment variable KICAD (if exists) gives the kicad path:
241  // something like set KICAD=d:\kicad
242  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
243 
244  if( isDefined ) // ensure m_kicad_env ends by "/"
245  {
247 
248  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
250  }
251 
252  // Init parameters for configuration
253  App().SetVendorName( "KiCad" );
254  App().SetAppName( pgm_name.GetName().Lower() );
255 
256  // Install some image handlers, mainly for help
257  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
258  wxImage::AddHandler( new wxPNGHandler );
259 
260  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
261  wxImage::AddHandler( new wxGIFHandler );
262 
263  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
264  wxImage::AddHandler( new wxJPEGHandler );
265 
266  wxFileSystem::AddHandler( new wxZipFSHandler );
267 
268  // Analyze the command line & initialize the binary path
270 
271  SetLanguagePath();
272 
273  wxString envVarName = wxT( "KIGITHUB" );
274  ENV_VAR_ITEM envVarItem;
275  wxString envValue;
276  wxFileName tmpFileName;
277 
278  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
279  {
280  tmpFileName.AssignDir( envValue );
281  envVarItem.SetDefinedExternally( true );
282  }
283  else
284  {
285  envVarItem.SetValue( wxString( wxT( "https://github.com/KiCad" ) ) );
286  envVarItem.SetDefinedExternally( false );
287  }
288 
289  m_local_env_vars[ envVarName ] = envVarItem;
290 
291  wxFileName baseSharePath;
292 #if defined( __WXMSW__ )
293  // Make the paths relative to the executable dir as KiCad might be installed anywhere
294  // It follows the Windows installer paths scheme, where binaries are installed in
295  // PATH/bin and extra files in PATH/share/kicad
296  baseSharePath.AssignDir( m_bin_dir + "\\.." );
297  baseSharePath.Normalize();
298 #else
299  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
300 #endif
301 
302 #if !defined( __WXMAC__ )
303  baseSharePath.AppendDir( "share" );
304  baseSharePath.AppendDir( "kicad" );
305 #endif
306 
307  // KISYSMOD
308  envVarName = wxT( "KISYSMOD" );
309 
310  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
311  {
312  tmpFileName.AssignDir( envValue );
313  envVarItem.SetDefinedExternally( true );
314  }
315  else
316  {
317  tmpFileName = baseSharePath;
318  tmpFileName.AppendDir( "modules" );
319  envVarItem.SetDefinedExternally( false );
320  }
321 
322  envVarItem.SetValue( tmpFileName.GetPath() );
323  m_local_env_vars[ envVarName ] = envVarItem;
324 
325  // KISYS3DMOD
326  envVarName = wxT( "KISYS3DMOD" );
327 
328  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
329  {
330  tmpFileName.AssignDir( envValue );
331  envVarItem.SetDefinedExternally( true );
332  }
333  else
334  {
335  tmpFileName.AppendDir( "packages3d" );
336  envVarItem.SetDefinedExternally( false );
337  }
338 
339  envVarItem.SetValue( tmpFileName.GetFullPath() );
340  m_local_env_vars[ envVarName ] = envVarItem;
341 
342  // KICAD_TEMPLATE_DIR
343  envVarName = "KICAD_TEMPLATE_DIR";
344 
345  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
346  {
347  tmpFileName.AssignDir( envValue );
348  envVarItem.SetDefinedExternally( true );
349  }
350  else
351  {
352  // Attempt to find the best default template path.
353  SEARCH_STACK bases;
354  SEARCH_STACK templatePaths;
355 
356  SystemDirsAppend( &bases );
357 
358  for( unsigned i = 0; i < bases.GetCount(); ++i )
359  {
360  wxFileName fn( bases[i], wxEmptyString );
361 
362  // Add KiCad template file path to search path list.
363  fn.AppendDir( "template" );
364 
365  // Only add path if exists and can be read by the user.
366  if( fn.DirExists() && fn.IsDirReadable() )
367  {
368  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
369  fn.GetPath() );
370  templatePaths.AddPaths( fn.GetPath() );
371  }
372  }
373 
374  if( templatePaths.IsEmpty() )
375  {
376  tmpFileName = baseSharePath;
377  tmpFileName.AppendDir( "template" );
378  }
379  else
380  {
381  // Take the first one. There may be more but this will likely be the best option.
382  tmpFileName.AssignDir( templatePaths[0] );
383  }
384 
385  envVarItem.SetDefinedExternally( false );
386  }
387 
388  envVarItem.SetValue( tmpFileName.GetPath() );
389  m_local_env_vars[ envVarName ] = envVarItem;
390 
391  // KICAD_USER_TEMPLATE_DIR
392  envVarName = "KICAD_USER_TEMPLATE_DIR";
393 
394  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
395  {
396  tmpFileName.AssignDir( envValue );
397  envVarItem.SetDefinedExternally( true );
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  m_local_env_vars[ envVarName ] = envVarItem;
410 
411  // KICAD_SYMBOLS
412  envVarName = wxT( "KICAD_SYMBOL_DIR" );
413 
414  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
415  {
416  tmpFileName.AssignDir( envValue );
417  envVarItem.SetDefinedExternally( true );
418  }
419  else
420  {
421  tmpFileName = baseSharePath;
422  tmpFileName.AppendDir( "library" );
423  envVarItem.SetDefinedExternally( false );
424  }
425 
426  envVarItem.SetValue( tmpFileName.GetPath() );
427  m_local_env_vars[ envVarName ] = envVarItem;
428 
430 
431  // Init user language *before* calling loadCommonSettings, because
432  // env vars could be incorrectly initialized on Linux
433  // (if the value contains some non ASCII7 chars, the env var is not initialized)
434  SetLanguage( true );
435 
437 
438  ReadPdfBrowserInfos(); // needs GetCommonSettings()
439 
440 #ifdef __WXMAC__
441  // Always show filters on Open dialog to be able to choose plugin
442  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
443 #endif
444 
445  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
446  // Need to create a project early for now (it can have an empty path for the moment)
448 
449  return true;
450 }
451 
452 
454 {
455  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
456 
457 #ifdef __WXMAC__
458  // On OSX Pgm().GetExecutablePath() will always point to main
459  // bundle directory, e.g., /Applications/kicad.app/
460 
461  wxFileName fn( m_bin_dir );
462 
463  if( fn.GetName() == wxT( "kicad" ) )
464  {
465  // kicad launcher, so just remove the Contents/MacOS part
466  fn.RemoveLastDir();
467  fn.RemoveLastDir();
468  }
469  else
470  {
471  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
472  fn.RemoveLastDir();
473  fn.RemoveLastDir();
474  fn.RemoveLastDir();
475  fn.RemoveLastDir();
476  fn.RemoveLastDir();
477  }
478 
479  m_bin_dir = fn.GetPath() + wxT( "/" );
480 #else
481  // Use unix notation for paths. I am not sure this is a good idea,
482  // but it simplifies compatibility between Windows and Unices.
483  // However it is a potential problem in path handling under Windows.
485 
486  // Remove file name form command line:
487  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
488  m_bin_dir.RemoveLast();
489 #endif
490 
491  return true;
492 }
493 
494 
496 {
497  m_help_size.x = 500;
498  m_help_size.y = 400;
499 
502 
503  for( const auto& it : GetCommonSettings()->m_Env.vars )
504  {
505  wxString key( it.first.c_str(), wxConvUTF8 );
506  wxLogTrace( traceEnvVars, "Enumerating over entry %s = %s.", key, it.second );
507 
508  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
509  // it is found in config. (It is reserved and defined as project path)
510  if( key == PROJECT_VAR_NAME )
511  continue;
512 
513  if( m_local_env_vars[ key ].GetDefinedExternally() )
514  continue;
515 
516  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
517  }
518 
519  for( auto& m_local_env_var : m_local_env_vars )
520  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
521 }
522 
523 
525 {
526  // GetCommonSettings() is not initialized until fairly late in the
527  // process startup: InitPgm(), so test before using:
528  if( GetCommonSettings() )
529  {
530  GetCommonSettings()->m_System.working_dir = wxGetCwd().ToStdString();
532 
533  // Save the local environment variables.
534  for( auto& m_local_env_var : m_local_env_vars )
535  {
536  if( m_local_env_var.second.GetDefinedExternally() )
537  continue;
538 
539  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
540  GetChars( m_local_env_var.first ),
541  GetChars( m_local_env_var.second.GetValue() ) );
542 
543  std::string key( m_local_env_var.first.ToUTF8() );
544  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
545  }
546  }
547 }
548 
549 
551 {
553 }
554 
555 
556 bool PGM_BASE::SetLanguage( bool first_time )
557 {
558  bool retv = true;
559 
560  if( first_time )
561  {
562  setLanguageId( wxLANGUAGE_DEFAULT );
563  // First time SetLanguage is called, the user selected language id is set
564  // from common user config settings
565  wxString languageSel = GetCommonSettings()->m_System.language;
566 
567  // Search for the current selection
568  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
569  {
570  if( LanguagesList[ii].m_Lang_Label == languageSel )
571  {
572  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
573  break;
574  }
575  }
576  }
577 
578  // dictionary file name without extend (full name is kicad.mo)
579  wxString dictionaryName( "kicad" );
580 
581  delete m_locale;
582  m_locale = new wxLocale;
583 
584  if( !m_locale->Init( m_language_id ) )
585  {
586  wxLogTrace( traceLocale, "This language is not supported by the system." );
587 
588  setLanguageId( wxLANGUAGE_DEFAULT );
589  delete m_locale;
590 
591  m_locale = new wxLocale;
592  m_locale->Init();
593  retv = false;
594  }
595  else if( !first_time )
596  {
597  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
598  GetChars( dictionaryName ), GetChars( m_locale->GetName() ) );
599  }
600 
601  if( !first_time )
602  {
603  // If we are here, the user has selected another language.
604  // Therefore the new prefered language name is stored in common config.
605  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
606  // versions, for a given language
607  wxString languageSel;
608 
609  // Search for the current selection language name
610  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
611  {
612  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
613  {
614  languageSel = LanguagesList[ii].m_Lang_Label;
615  break;
616  }
617  }
618 
620  cfg->m_System.language = languageSel;
621  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
622  }
623 
624  // Test if floating point notation is working (bug encountered in cross compilation)
625  // Make a conversion double <=> string
626  double dtst = 0.5;
627  wxString msg;
628 
629  msg << dtst;
630  double result;
631  msg.ToDouble( &result );
632 
633  if( result != dtst )
634  // string to double encode/decode does not work! Bug detected:
635  // Disable floating point localization:
636  setlocale( LC_NUMERIC, "C" );
637 
638  if( !m_locale->IsLoaded( dictionaryName ) )
639  m_locale->AddCatalog( dictionaryName );
640 
641  if( !retv )
642  return retv;
643 
644  return m_locale->IsOk();
645 }
646 
647 
649 {
650  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
651  menu_id, (int)arrayDim( LanguagesList )-1 );
652 
653  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
654  {
655  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
656  {
657  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
658  break;
659  }
660  }
661 }
662 
663 
665 {
666  SEARCH_STACK guesses;
667 
668  SystemDirsAppend( &guesses );
669 
670  // Add our internat dir to the wxLocale catalog of paths
671  for( unsigned i = 0; i < guesses.GetCount(); i++ )
672  {
673  wxFileName fn( guesses[i], wxEmptyString );
674 
675  // Append path for Windows and unix KiCad package install
676  fn.AppendDir( "share" );
677  fn.AppendDir( "internat" );
678 
679  if( fn.IsDirReadable() )
680  {
681  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
682  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
683  }
684 
685  // Append path for unix standard install
686  fn.RemoveLastDir();
687  fn.AppendDir( "kicad" );
688  fn.AppendDir( "internat" );
689 
690  if( fn.IsDirReadable() )
691  {
692  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
693  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
694  }
695  }
696 }
697 
698 
699 bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValue )
700 {
701  wxString env;
702 
703  // Check to see if the environment variable is already set.
704  if( wxGetEnv( aName, &env ) )
705  {
706  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
707  GetChars( aName ), GetChars( env ) );
708  return env == aValue;
709  }
710 
711  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
712  GetChars( aName ), GetChars( aValue ) );
713 
714  return wxSetEnv( aName, aValue );
715 }
716 
717 
719 {
720  m_local_env_vars.clear();
721  m_local_env_vars = aEnvVarMap;
722 
724 
725  // Overwrites externally defined environment variable until the next time the application
726  // is run.
727  for( auto& m_local_env_var : m_local_env_vars )
728  {
729  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
730  GetChars( m_local_env_var.first ),
731  GetChars( m_local_env_var.second.GetValue() ) );
732  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
733  }
734 }
const BITMAP_OPAQUE lang_hu_xpm[1]
Definition: lang_hu.cpp:24
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:495
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:74
wxString GetKicadLockFilePath()
Function GetKicadLockFilePath.
Definition: lockfile.cpp:59
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:145
virtual ~PGM_BASE()
Definition: pgm_base.cpp:121
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
This file is part of the common library TODO brief description.
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
This file is part of the common library.
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:524
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
const BITMAP_OPAQUE lang_def_xpm[1]
Definition: lang_def.cpp:115
const BITMAP_OPAQUE lang_ca_xpm[1]
Definition: lang_ca.cpp:27
const BITMAP_OPAQUE lang_nl_xpm[1]
Definition: lang_nl.cpp:23
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
ENV_VAR_ITEM.
Definition: pgm_base.h:88
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
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:64
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
const BITMAP_OPAQUE lang_sl_xpm[1]
Definition: lang_sl.cpp:29
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:138
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:63
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
void Destroy()
Definition: pgm_base.cpp:127
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:453
const BITMAP_OPAQUE lang_bg_xpm[1]
Definition: lang_bg.cpp:19
const BITMAP_OPAQUE lang_cs_xpm[1]
Definition: lang_cs.cpp:33
System directories search utilities.
A small class to handle the list of existing translations.
Definition: pgm_base.h:58
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
const BITMAP_OPAQUE lang_fr_xpm[1]
Definition: lang_fr.cpp:24
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:190
const BITMAP_OPAQUE lang_sk_xpm[1]
Definition: lang_sk.cpp:38
const BITMAP_OPAQUE lang_es_xpm[1]
Definition: lang_es.cpp:30
const BITMAP_OPAQUE lang_zh_xpm[1]
Definition: lang_zh.cpp:28
int m_language_id
The current language setting.
Definition: pgm_base.h:363
This file contains miscellaneous commonly used macros and functions.
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:348
const BITMAP_OPAQUE lang_jp_xpm[1]
Definition: lang_jp.cpp:31
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:357
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:699
#define NULL
VTBL_ENTRY void SetLanguageIdentifier(int menu_id)
Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id fro...
Definition: pgm_base.cpp:648
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:117
std::map< std::string, wxString > vars
const BITMAP_OPAQUE lang_ru_xpm[1]
Definition: lang_ru.cpp:23
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:100
const BITMAP_OPAQUE lang_fi_xpm[1]
Definition: lang_fi.cpp:27
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
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.
const BITMAP_OPAQUE lang_lt_xpm[1]
Definition: lang_lt.cpp:23
Base window classes and related definitions.
const BITMAP_OPAQUE lang_gr_xpm[1]
Definition: lang_gr.cpp:32
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
wxLogTrace helper definitions.
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:369
const BITMAP_OPAQUE lang_en_xpm[1]
Definition: lang_en.cpp:53
const wxChar *const traceLocale
Flag to enable locale debug output.
ENVIRONMENT m_Env
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:70
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:664
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:556
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354
const BITMAP_OPAQUE lang_de_xpm[1]
Definition: lang_de.cpp:24
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:718
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
const BITMAP_OPAQUE lang_ko_xpm[1]
Definition: lang_ko.cpp:53
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:43
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
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
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:60
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:205
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:104
wxSize m_help_size
Definition: pgm_base.h:381
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:213
const BITMAP_OPAQUE lang_pl_xpm[1]
Definition: lang_pl.cpp:22
wxString m_editor_name
Definition: pgm_base.h:380
const BITMAP_OPAQUE lang_pt_xpm[1]
Definition: lang_pt.cpp:35
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:153
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:267
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)
const BITMAP_OPAQUE lang_it_xpm[1]
Definition: lang_it.cpp:24
File locking utilities.