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-2020 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 <wx/html/htmlwin.h>
34 #include <wx/fs_zip.h>
35 #include <wx/dir.h>
36 #include <wx/filename.h>
37 #include <wx/snglinst.h>
38 #include <wx/stdpaths.h>
39 #include <wx/sysopt.h>
40 #include <wx/richmsgdlg.h>
41 #include <wx/filedlg.h>
42 
43 #include <build_version.h>
44 #include <config_params.h>
45 #include <confirm.h>
46 #include <core/arraydim.h>
48 #include <eda_base_frame.h>
49 #include <eda_draw_frame.h>
51 #include <gestfich.h>
52 #include <hotkeys_basic.h>
53 #include <id.h>
54 #include <lockfile.h>
55 #include <macros.h>
56 #include <menus_helpers.h>
57 #include <pgm_base.h>
60 #include <systemdirsappend.h>
61 #include <trace_helpers.h>
62 
63 
70 #undef _
71 #define _(s) s
73 {
74  { wxLANGUAGE_DEFAULT, ID_LANGUAGE_DEFAULT, _( "Default" ), false },
75  { wxLANGUAGE_ENGLISH, ID_LANGUAGE_ENGLISH, wxT( "English" ), true },
76  { wxLANGUAGE_FRENCH, ID_LANGUAGE_FRENCH, wxT( "Français" ), true },
77  { wxLANGUAGE_SPANISH, ID_LANGUAGE_SPANISH, wxT( "Español" ), true },
78  { wxLANGUAGE_PORTUGUESE, ID_LANGUAGE_PORTUGUESE, wxT( "Português" ),true },
79  { wxLANGUAGE_ITALIAN, ID_LANGUAGE_ITALIAN, wxT( "Italiano" ), true },
80  { wxLANGUAGE_GERMAN, ID_LANGUAGE_GERMAN, wxT( "Deutsch" ), true },
81  { wxLANGUAGE_GREEK, ID_LANGUAGE_GREEK, wxT( "Ελληνικά" ), true },
82  { wxLANGUAGE_HUNGARIAN, ID_LANGUAGE_HUNGARIAN, wxT( "Magyar" ), true },
83  { wxLANGUAGE_POLISH, ID_LANGUAGE_POLISH, wxT( "Polski" ), true },
84  { wxLANGUAGE_CZECH, ID_LANGUAGE_CZECH, wxT( "Čeština" ), true },
85  { wxLANGUAGE_RUSSIAN, ID_LANGUAGE_RUSSIAN, wxT( "Русский" ), true },
86  { wxLANGUAGE_CHINESE_SIMPLIFIED, ID_LANGUAGE_CHINESE_SIMPLIFIED,
87  wxT( "简体中文" ), true },
88  { wxLANGUAGE_CHINESE_TRADITIONAL, ID_LANGUAGE_CHINESE_TRADITIONAL,
89  wxT( "繁體中文" ), false },
90  { wxLANGUAGE_CATALAN, ID_LANGUAGE_CATALAN, wxT( "Català" ), true },
91  { wxLANGUAGE_JAPANESE, ID_LANGUAGE_JAPANESE, wxT( "日本語" ), true },
92  { wxLANGUAGE_LITHUANIAN, ID_LANGUAGE_LITHUANIAN, wxT( "Lietuvių" ), true },
93  { 0, 0, "", false } // Sentinel
94 };
95 #undef _
96 #define _(s) wxGetTranslation((s))
97 
98 
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 }
111 
112 
114 {
115  Destroy();
116 }
117 
118 
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 }
128 
129 
131 {
132  wxASSERT( wxTheApp );
133  return *wxTheApp;
134 }
135 
136 
137 void PGM_BASE::SetEditorName( const wxString& aFileName )
138 {
139  m_editor_name = aFileName;
140  wxASSERT( GetCommonSettings() );
141  GetCommonSettings()->m_System.editor_name = aFileName;
142 }
143 
144 
145 const wxString& PGM_BASE::GetEditorName( bool aCanShowFileChooser )
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 }
180 
181 
182 const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEditor )
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 }
203 
204 
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 }
438 
439 
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 }
480 
481 
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 }
511 
512 
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 }
552 
553 
555 {
557 }
558 
559 
560 bool PGM_BASE::SetLanguage( wxString& aErrMsg, bool first_time )
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 }
667 
668 
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 }
683 
684 
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 }
718 
719 
720 bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValue )
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 }
739 
740 
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 }
PGM_BASE()
Definition: pgm_base.cpp:99
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:554
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:482
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:72
wxString GetKicadLockFilePath()
Function GetKicadLockFilePath.
Definition: lockfile.cpp:60
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:137
virtual ~PGM_BASE()
Definition: pgm_base.cpp:113
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 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:513
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
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
const wxString & GetValue() const
Definition: pgm_base.h:105
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
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 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:119
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:440
System directories search utilities.
A small class to handle the list of existing translations.
Definition: pgm_base.h:57
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
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
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
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:720
#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:669
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:117
std::map< std::string, wxString > vars
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:100
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.
Base window classes and related definitions.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
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 wxChar *const traceLocale
Flag to enable locale debug output.
ENVIRONMENT m_Env
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.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:66
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:685
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:354
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:741
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
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
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:59
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
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:205
wxString m_editor_name
Definition: pgm_base.h:380
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:145
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:268
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)
File locking utilities.