KiCad PCB EDA Suite
PGM_KICAD Class Reference

PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP into KIFACE_I. More...

#include <pgm_kicad.h>

Inheritance diagram for PGM_KICAD:
PGM_BASE

Public Member Functions

 PGM_KICAD ()
 
 ~PGM_KICAD () throw ()
 
bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 Specific to MacOSX (not used under Linux or Windows). More...
 
APP_SETTINGS_BASEPgmSettings ()
 
SEARCH_STACKSysSearch ()
 
wxString GetHelpFileName ()
 
void Destroy ()
 
virtual SETTINGS_MANAGERGetSettingsManager () const
 
virtual COMMON_SETTINGSGetCommonSettings () const
 
virtual void SetEditorName (const wxString &aFileName)
 
virtual const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
virtual const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
virtual bool IsKicadEnvVariableDefined () const
 
virtual const wxString & GetKicadEnvVariable () const
 
virtual const wxString & GetExecutablePath () const
 
virtual wxLocale * GetLocale ()
 
virtual const wxString & GetPdfBrowserName () const
 
virtual void SetPdfBrowserName (const wxString &aFileName)
 
virtual bool UseSystemPdfBrowser () const
 
virtual void ForceSystemPdfBrowser (bool aFlg)
 Force the use of system PDF browser, even if a preferred PDF browser is set. More...
 
virtual bool SetLanguage (wxString &aErrMsg, bool first_time=false)
 Set the dictionary file name for internationalization. More...
 
bool SetDefaultLanguage (wxString &aErrMsg)
 Set the default language without reference to any preferences. More...
 
virtual void SetLanguageIdentifier (int menu_id)
 Set in .m_language_id member the wxWidgets language identifier ID fromthe KiCad menu id (internal menu identifier). More...
 
virtual int GetSelectedLanguageIdentifier () const
 
virtual void SetLanguagePath ()
 
virtual void ReadPdfBrowserInfos ()
 Read the PDF browser choice from the common configuration. More...
 
virtual void WritePdfBrowserInfos ()
 Save the PDF browser choice to the common configuration. More...
 
virtual bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Sets the environment variable aName to aValue. More...
 
virtual void SetLocalEnvVariables (const ENV_VAR_MAP &aEnvVarMap)
 Set the internal local environment variable map to aEnvVarMap, updates the entries in the .kicad_common configuration file and sets the environment variable to the new settings. More...
 
virtual const ENV_VAR_MAPGetLocalEnvVariables () const
 
virtual wxApp & App ()
 Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm ()
 Initialize this program. More...
 
void SaveCommonSettings ()
 Save the program (process) settings subset which are stored .kicad_common. More...
 

Public Attributes

bool m_Printing
 wxWidgets on MSW tends to crash if you spool up more than one print job at a time. More...
 
int m_ModalDialogCount
 

Static Public Attributes

static const wxChar workingDirKey []
 

Protected Member Functions

void loadCommonSettings ()
 Loads internal settings from COMMON_SETTINGS. More...
 
void setLanguageId (int aId)
 Trap all changes in here, simplifies debugging. More...
 
bool setExecutablePath ()
 Find the path to the executable and stores it in PGM_BASE::m_bin_dir. More...
 

Protected Attributes

BIN_MOD m_bm
 
std::unique_ptr< SETTINGS_MANAGERm_settings_manager
 
wxSingleInstanceChecker * m_pgm_checker
 prevents multiple instances of a program from being run at the same time. More...
 
wxString m_bin_dir
 full path to this program More...
 
wxString m_kicad_env
 The KICAD system environment variable. More...
 
wxLocale * m_locale
 The current locale. More...
 
int m_language_id
 The current language setting. More...
 
bool m_use_system_pdf_browser
 true to use the selected PDF browser, if exists, or false to use the default More...
 
wxString m_pdf_browser
 The file name of the the program selected for browsing pdf files. More...
 
wxString m_editor_name
 
wxSize m_help_size
 
ENV_VAR_MAP m_local_env_vars
 Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR. More...
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. More...
 

Detailed Description

PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP into KIFACE_I.

KIFACE_I is not applicable in the project manager since it is not a KIFACE. This header is in the kicad directory since nobody else needs to know about it.

Definition at line 38 of file pgm_kicad.h.

Constructor & Destructor Documentation

◆ PGM_KICAD()

PGM_KICAD::PGM_KICAD ( )
inline

Definition at line 41 of file pgm_kicad.h.

41  :
42  m_bm( "kicad" ) // indicates a "$HOME/.kicad wxConfig like" config file.
43  {}
BIN_MOD m_bm
Definition: pgm_kicad.h:68

◆ ~PGM_KICAD()

PGM_KICAD::~PGM_KICAD ( )
throw (
)
inline

Definition at line 45 of file pgm_kicad.h.

46  {
47  Destroy();
48  }
void Destroy()
Definition: kicad.cpp:239

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
virtualinherited

Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.

This should return what wxGetApp() returns.

Definition at line 141 of file pgm_base.cpp.

142 {
143  wxASSERT( wxTheApp );
144  return *wxTheApp;
145 }

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

◆ AskUserForPreferredEditor()

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

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

194 {
195  // Create a mask representing the executable files in the current platform
196 #ifdef __WINDOWS__
197  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
198 #else
199  wxString mask( _( "Executable file (*)|*" ) );
200 #endif
201 
202  // Extract the path, name and extension from the default editor (even if the editor's
203  // name was empty, this method will succeed and return empty strings).
204  wxString path, name, ext;
205  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
206 
207  // Show the modal editor and return the file chosen (may be empty if the user cancels
208  // the dialog).
209  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
210  name, ext, mask,
211  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
212  true );
213 }
#define NULL
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
A helper function that wraps a call to wxFileSelector.
Definition: gestfich.cpp:52
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:106

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

Referenced by PGM_BASE::GetEditorName().

◆ Destroy()

void PGM_KICAD::Destroy ( void  )

Definition at line 239 of file kicad.cpp.

240 {
241  // unlike a normal destructor, this is designed to be called more
242  // than once safely:
243 
244  m_bm.End();
245 
247 }
void Destroy()
Definition: pgm_base.cpp:130
BIN_MOD m_bm
Definition: pgm_kicad.h:68
void End()
Definition: bin_mod.cpp:53

References PGM_BASE::Destroy(), BIN_MOD::End(), and m_bm.

Referenced by OnPgmExit(), and ~PGM_KICAD().

◆ ForceSystemPdfBrowser()

virtual void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlinevirtualinherited

Force the use of system PDF browser, even if a preferred PDF browser is set.

Definition at line 219 of file pgm_base.h.

219 { m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:367

References PGM_BASE::m_use_system_pdf_browser.

Referenced by PGM_BASE::PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtualinherited

Definition at line 584 of file pgm_base.cpp.

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

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

Referenced by PGM_BASE::InitPgm(), PGM_BASE::loadCommonSettings(), PGM_BASE::ReadPdfBrowserInfos(), PGM_BASE::SaveCommonSettings(), PGM_BASE::SetEditorName(), PGM_BASE::SetLanguage(), and PGM_BASE::WritePdfBrowserInfos().

◆ GetEditorName()

const wxString & PGM_BASE::GetEditorName ( bool  aCanShowFileChooser = true)
virtualinherited

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

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

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

◆ GetExecutablePath()

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

Definition at line 198 of file pgm_base.h.

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

References PGM_BASE::m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit(), and PGM_BASE::SetLanguagePath().

◆ GetHelpFileName()

wxString PGM_KICAD::GetHelpFileName ( )
inline

Definition at line 59 of file pgm_kicad.h.

59 { return m_bm.m_help_file; }
wxString m_help_file
Definition: bin_mod.h:66
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_help_file.

Referenced by KICAD_MANAGER_FRAME::help_name().

◆ GetKicadEnvVariable()

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

Definition at line 196 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtualinherited

Definition at line 200 of file pgm_base.h.

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

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

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

Definition at line 290 of file pgm_base.h.

291  {
292  return m_local_env_vars;
293  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:375

References PGM_BASE::m_local_env_vars.

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

◆ GetPdfBrowserName()

virtual const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inlinevirtualinherited

Definition at line 202 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

virtual int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inlinevirtualinherited
Returns
the wxWidgets language identifier Id of the language currently selected.

Definition at line 253 of file pgm_base.h.

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

References PGM_BASE::m_language_id.

◆ GetSettingsManager()

◆ InitPgm()

bool PGM_BASE::InitPgm ( )
inherited

Initialize this program.

Initialize the process in a KiCad standard way using some generalized techniques:

  • Default paths (help, libs, bin) and configuration file names
  • Language and locale
  • fonts
Note
Do not initialize anything relating to DSOs or projects.
Returns
true if success, false if failure and program is to terminate.

Definition at line 216 of file pgm_base.cpp.

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

References _, SEARCH_STACK::AddPaths(), PGM_BASE::App(), DisplayErrorMessage(), Format(), PGM_BASE::GetCommonSettings(), GetKicadLockFilePath(), PGM_BASE::GetSettingsManager(), PATHS::GetUserTemplatesPath(), ENV_VAR_ITEM::GetValue(), IsOK(), SETTINGS_MANAGER::Load(), PGM_BASE::loadCommonSettings(), SETTINGS_MANAGER::LoadProject(), PGM_BASE::m_bin_dir, PGM_BASE::m_kicad_env, PGM_BASE::m_local_env_vars, PGM_BASE::m_pgm_checker, PGM_BASE::m_settings_manager, NULL, PGM_BASE::ReadPdfBrowserInfos(), PGM_BASE::SetDefaultLanguage(), ENV_VAR_ITEM::SetDefinedExternally(), PGM_BASE::setExecutablePath(), PGM_BASE::SetLanguage(), PGM_BASE::SetLanguagePath(), ENV_VAR_ITEM::SetValue(), SystemDirsAppend(), traceEnvVars, tracePathsAndFiles, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by OnPgmInit(), and PGM_TEST_FRAME::OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtualinherited

Definition at line 194 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 509 of file pgm_base.cpp.

510 {
511  m_help_size.x = 500;
512  m_help_size.y = 400;
513 
516 
517  for( const auto& it : GetCommonSettings()->m_Env.vars )
518  {
519  wxString key( it.first.c_str(), wxConvUTF8 );
520  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s",
521  key, it.second );
522 
523  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
524  // it is found in config. (It is reserved and defined as project path)
525  if( key == PROJECT_VAR_NAME )
526  continue;
527 
528  if( m_local_env_vars[ key ].GetDefinedExternally() )
529  continue;
530 
531  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s",
532  key, it.second );
533 
534  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
535  }
536 
537  for( auto& m_local_env_var : m_local_env_vars )
538  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
539 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:584
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:375
A simple helper class to store environment variable values and the status of whether or not they were...
Definition: pgm_base.h:84
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:378
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:794
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxSize m_help_size
Definition: pgm_base.h:372
wxString m_editor_name
Definition: pgm_base.h:371

References COMMON_SETTINGS::SYSTEM::editor_name, PGM_BASE::GetCommonSettings(), PGM_BASE::m_editor_name, COMMON_SETTINGS::m_Env, PGM_BASE::m_help_size, PGM_BASE::m_local_env_vars, PGM_BASE::m_show_env_var_dialog, COMMON_SETTINGS::m_System, PROJECT_VAR_NAME, PGM_BASE::SetLocalEnvVariable(), COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, and traceEnvVars.

Referenced by PGM_BASE::InitPgm().

◆ MacOpenFile()

void PGM_KICAD::MacOpenFile ( const wxString &  aFileName)
overridevirtual

Specific to MacOSX (not used under Linux or Windows).

MacOSX requires it for file association.

See also
http://wiki.wxwidgets.org/WxMac-specific_topics

Implements PGM_BASE.

Definition at line 226 of file kicad.cpp.

227 {
228 #if defined(__WXMAC__)
229 
230  KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
231 
232  if( !aFileName.empty() && wxFileExists( aFileName ) )
233  frame->LoadProject( wxFileName( aFileName ) );
234 
235 #endif
236 }
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:141
void LoadProject(const wxFileName &aProjectFileName)
The main KiCad project manager frame.

References PGM_BASE::App(), and KICAD_MANAGER_FRAME::LoadProject().

◆ OnPgmExit()

void PGM_KICAD::OnPgmExit ( )

Definition at line 209 of file kicad.cpp.

210 {
211  Kiway.OnKiwayEnd();
212 
213  if( m_settings_manager && m_settings_manager->IsOK() )
214  {
216  m_settings_manager->Save();
217  }
218 
219  // Destroy everything in PGM_KICAD,
220  // especially wxSingleInstanceCheckerImpl earlier than wxApp and earlier
221  // than static destruction would.
222  Destroy();
223 }
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:542
void OnKiwayEnd()
Definition: kiway.cpp:602
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:349
void Destroy()
Definition: kicad.cpp:239
KIWAY Kiway

References Destroy(), Kiway, PGM_BASE::m_settings_manager, KIWAY::OnKiwayEnd(), and PGM_BASE::SaveCommonSettings().

Referenced by APP_KICAD::OnExit(), and APP_KICAD::OnInit().

◆ OnPgmInit()

bool PGM_KICAD::OnPgmInit ( )

Definition at line 91 of file kicad.cpp.

92 {
93 #if defined(DEBUG)
94  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
95 
96  if( !wxIsAbsolutePath( absoluteArgv0 ) )
97  {
98  wxLogError( wxT( "No meaningful argv[0]" ) );
99  return false;
100  }
101 #endif
102 
103  if( !InitPgm() )
104  return false;
105 
109  m_bm.Init();
110 
111  // Add search paths to feed the PGM_KICAD::SysSearch() function,
112  // currenly limited in support to only look for project templates
113  {
114  SEARCH_STACK bases;
115 
116  SystemDirsAppend( &bases );
117 
118  for( unsigned i = 0; i < bases.GetCount(); ++i )
119  {
120  wxFileName fn( bases[i], wxEmptyString );
121 
122  // Add KiCad template file path to search path list.
123  fn.AppendDir( wxT( "template" ) );
124 
125  // Only add path if exists and can be read by the user.
126  if( fn.DirExists() && fn.IsDirReadable() )
127  m_bm.m_search.AddPaths( fn.GetPath() );
128  }
129 
130  // The KICAD6_TEMPLATE_DIR takes precedence over the search stack template path.
131  ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD6_TEMPLATE_DIR" );
132 
133  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
134  m_bm.m_search.Insert( it->second.GetValue(), 0 );
135 
136  // We've been adding system (installed default) search paths so far, now for user paths
137  // The default user search path is inside KIPLATFORM::ENV::GetDocumentsPath()
139 
140  // ...but the user can override that default with the KICAD_USER_TEMPLATE_DIR env var
141  it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
142 
143  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
144  m_bm.m_search.Insert( it->second.GetValue(), 0 );
145  }
146 
147  KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
148  wxDefaultPosition, wxSize( 775, -1 ) );
149  App().SetTopWindow( frame );
150 
151  Kiway.SetTop( frame );
152 
153  KICAD_SETTINGS* settings = static_cast<KICAD_SETTINGS*>( PgmSettings() );
154 
155  wxString projToLoad;
156 
157  if( App().argc > 1 )
158  {
159  wxFileName tmp = App().argv[1];
160 
161  if( tmp.GetExt() != ProjectFileExtension && tmp.GetExt() != LegacyProjectFileExtension )
162  {
163  wxString msg;
164 
165  msg.Printf( _( "File '%s'\ndoes not appear to be a valid KiCad project file." ),
166  tmp.GetFullPath() );
167  wxMessageDialog dlg( nullptr, msg, _( "Error" ), wxOK | wxICON_EXCLAMATION );
168  dlg.ShowModal();
169  }
170  else
171  {
172  projToLoad = tmp.GetFullPath();
173  }
174  }
175 
176  // If no file was given as an argument, check that there was a file open.
177  if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() )
178  {
179  wxString last_pro = settings->m_OpenProjects.front();
180  settings->m_OpenProjects.erase( settings->m_OpenProjects.begin() );
181 
182  if( wxFileExists( last_pro ) )
183  {
184  // Try to open the last opened project,
185  // if a project name is not given when starting Kicad
186  projToLoad = last_pro;
187  }
188  }
189 
190  // Do not attempt to load a non-existent project file.
191  if( !projToLoad.empty() )
192  {
193  wxFileName fn( projToLoad );
194 
195  if( fn.Exists() )
196  {
197  fn.MakeAbsolute();
198  frame->LoadProject( fn );
199  }
200  }
201 
202  frame->Show( true );
203  frame->Raise();
204 
205  return true;
206 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
void Init()
Definition: bin_mod.cpp:41
const std::string ProjectFileExtension
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:141
virtual const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:290
Look for files in a number of paths.
Definition: search_stack.h:41
std::vector< wxString > m_OpenProjects
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
#define NULL
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:115
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:85
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:61
const std::string LegacyProjectFileExtension
void SetTop(wxFrame *aTop)
Tell this KIWAY about the top most frame in the program and optionally allows it to play the role of ...
Definition: kiway.cpp:80
SEARCH_STACK m_search
Definition: bin_mod.h:68
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
BIN_MOD m_bm
Definition: pgm_kicad.h:68
#define _(s)
Definition: 3d_actions.cpp:33
APP_SETTINGS_BASE * PgmSettings()
Definition: pgm_kicad.h:55
bool InitPgm()
Initialize this program.
Definition: pgm_base.cpp:216
void LoadProject(const wxFileName &aProjectFileName)
The main KiCad project manager frame.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
KIWAY Kiway

References _, SEARCH_STACK::AddPaths(), PGM_BASE::App(), PGM_BASE::GetLocalEnvVariables(), PGM_BASE::GetSettingsManager(), PATHS::GetUserTemplatesPath(), BIN_MOD::Init(), PGM_BASE::InitPgm(), BIN_MOD::InitSettings(), Kiway, LegacyProjectFileExtension, KICAD_MANAGER_FRAME::LoadProject(), m_bm, KICAD_SETTINGS::m_OpenProjects, BIN_MOD::m_search, NULL, PgmSettings(), ProjectFileExtension, SETTINGS_MANAGER::RegisterSettings(), SETTINGS_MANAGER::SetKiway(), KIWAY::SetTop(), and SystemDirsAppend().

Referenced by APP_KICAD::OnInit().

◆ PgmSettings()

APP_SETTINGS_BASE* PGM_KICAD::PgmSettings ( )
inline

Definition at line 55 of file pgm_kicad.h.

55 { return m_bm.m_config; }
APP_SETTINGS_BASE * m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:65
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_config.

Referenced by KICAD_MANAGER_FRAME::config(), and OnPgmInit().

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
virtualinherited

Read the PDF browser choice from the common configuration.

Definition at line 42 of file eda_doc.cpp.

43 {
44  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
46 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:584
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:367
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:204

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_System, PGM_BASE::m_use_system_pdf_browser, PGM_BASE::SetPdfBrowserName(), and COMMON_SETTINGS::SYSTEM::use_system_pdf_viewer.

Referenced by PGM_BASE::InitPgm().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )
inherited

Save the program (process) settings subset which are stored .kicad_common.

Definition at line 542 of file pgm_base.cpp.

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

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_Env, PGM_BASE::m_local_env_vars, PGM_BASE::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 OnPgmExit(), PGM_SINGLE_TOP::OnPgmExit(), and PGM_BASE::SetLocalEnvVariables().

◆ SetDefaultLanguage()

bool PGM_BASE::SetDefaultLanguage ( wxString &  aErrMsg)
inherited

Set the default language without reference to any preferences.

Can be used to set the language for dialogs that show before preferences are loaded

Parameters
aErrMsgString to return the error messsage(s) in
Returns
false if the language could not be set

Definition at line 685 of file pgm_base.cpp.

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

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

Referenced by PGM_BASE::InitPgm().

◆ SetEditorName()

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

Definition at line 148 of file pgm_base.cpp.

149 {
150  m_editor_name = aFileName;
151  wxASSERT( GetCommonSettings() );
152  GetCommonSettings()->m_System.editor_name = aFileName;
153 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:584
wxString m_editor_name
Definition: pgm_base.h:371

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

Referenced by PGM_BASE::GetEditorName().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protectedinherited

Find the path to the executable and stores it in PGM_BASE::m_bin_dir.

Returns
true if success, else false.

Definition at line 467 of file pgm_base.cpp.

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

References PGM_BASE::m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_BASE::InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( wxString &  aErrMsg,
bool  first_time = false 
)
virtualinherited

Set the dictionary file name for internationalization.

The files are in kicad/internat/xx or kicad/internat/xx_XX and are named kicad.mo

Parameters
aErrMsgis the string to return the error message it.
first_timemust be set to true the first time this function is called, false otherwise.
Returns
false if there was an error setting the language.

Definition at line 590 of file pgm_base.cpp.

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

References _, PGM_BASE::GetCommonSettings(), PGM_BASE::GetSettingsManager(), COMMON_SETTINGS::SYSTEM::language, LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, PGM_BASE::m_language_id, PGM_BASE::m_locale, COMMON_SETTINGS::m_System, JSON_SETTINGS::SaveToFile(), PGM_BASE::setLanguageId(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotectedinherited

Trap all changes in here, simplifies debugging.

Definition at line 340 of file pgm_base.h.

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

References PGM_BASE::m_language_id.

Referenced by PGM_BASE::PGM_BASE(), PGM_BASE::SetDefaultLanguage(), PGM_BASE::SetLanguage(), and PGM_BASE::SetLanguageIdentifier().

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
virtualinherited

Set in .m_language_id member the wxWidgets language identifier ID fromthe KiCad menu id (internal menu identifier).

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

Definition at line 723 of file pgm_base.cpp.

724 {
725  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
726  menu_id, (int)arrayDim( LanguagesList )-1 );
727 
728  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
729  {
730  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
731  {
732  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
733  break;
734  }
735  }
736 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:76
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:340
const wxChar *const traceLocale
Flag to enable locale debug output.

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtualinherited

Definition at line 739 of file pgm_base.cpp.

740 {
741  SEARCH_STACK guesses;
742 
743  SystemDirsAppend( &guesses );
744 
745  // Add our internat dir to the wxLocale catalog of paths
746  for( unsigned i = 0; i < guesses.GetCount(); i++ )
747  {
748  wxFileName fn( guesses[i], wxEmptyString );
749 
750  // Append path for Windows and unix KiCad package install
751  fn.AppendDir( "share" );
752  fn.AppendDir( "internat" );
753 
754  if( fn.IsDirReadable() )
755  {
756  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
757  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
758  }
759 
760  // Append path for unix standard install
761  fn.RemoveLastDir();
762  fn.AppendDir( "kicad" );
763  fn.AppendDir( "internat" );
764 
765  if( fn.IsDirReadable() )
766  {
767  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
768  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
769  }
770 
771  // Append path for macOS install
772  fn.RemoveLastDir();
773  fn.RemoveLastDir();
774  fn.RemoveLastDir();
775  fn.AppendDir( "internat" );
776 
777  if( fn.IsDirReadable() )
778  {
779  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
780  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
781  }
782  }
783 
784  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
785  {
786  wxFileName fn( Pgm().GetExecutablePath() );
787  fn.RemoveLastDir();
788  fn.AppendDir( "translation" );
789  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
790  }
791 }
Look for files in a number of paths.
Definition: search_stack.h:41
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
const wxChar *const traceLocale
Flag to enable locale debug output.
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:198

References PGM_BASE::GetExecutablePath(), Pgm(), SystemDirsAppend(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ SetLocalEnvVariable()

bool PGM_BASE::SetLocalEnvVariable ( const wxString &  aName,
const wxString &  aValue 
)
virtualinherited

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

795 {
796  wxString env;
797 
798  // Check to see if the environment variable is already set.
799  if( wxGetEnv( aName, &env ) )
800  {
801  wxLogTrace( traceEnvVars,
802  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
803  aName, env );
804  return env == aValue;
805  }
806 
807  wxLogTrace( traceEnvVars,
808  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
809  aName, aValue );
810 
811  return wxSetEnv( aName, aValue );
812 }
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References traceEnvVars.

Referenced by PGM_BASE::loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)
virtualinherited

Set the internal local environment variable map to aEnvVarMap, updates the entries in the .kicad_common configuration file and sets the environment variable to the new settings.

Parameters
aEnvVarMapis a ENV_VAR_MAP object containing the new environment variables.

Definition at line 815 of file pgm_base.cpp.

816 {
817  m_local_env_vars.clear();
818  m_local_env_vars = aEnvVarMap;
819 
821 
822  // Overwrites externally defined environment variable until the next time the application
823  // is run.
824  for( auto& m_local_env_var : m_local_env_vars )
825  {
826  wxLogTrace( traceEnvVars,
827  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
828  m_local_env_var.first,
829  m_local_env_var.second.GetValue() );
830  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
831  }
832 }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.
Definition: pgm_base.h:375
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:542
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References PGM_BASE::m_local_env_vars, PGM_BASE::SaveCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

virtual void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inlinevirtualinherited

Definition at line 204 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SysSearch()

SEARCH_STACK& PGM_KICAD::SysSearch ( )
inline

Definition at line 57 of file pgm_kicad.h.

57 { return m_bm.m_search; }
SEARCH_STACK m_search
Definition: bin_mod.h:68
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_search.

Referenced by KICAD_MANAGER_FRAME::sys_search().

◆ UseSystemPdfBrowser()

virtual bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlinevirtualinherited
Returns
true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser.

Definition at line 211 of file pgm_base.h.

212  {
213  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
214  }
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:367
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:370

References PGM_BASE::m_pdf_browser, and PGM_BASE::m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtualinherited

Save the PDF browser choice to the common configuration.

Definition at line 49 of file eda_doc.cpp.

50 {
53 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:584
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:367
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:202

References PGM_BASE::GetCommonSettings(), PGM_BASE::GetPdfBrowserName(), COMMON_SETTINGS::m_System, PGM_BASE::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
protectedinherited

full path to this program

Definition at line 355 of file pgm_base.h.

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

◆ m_bm

BIN_MOD PGM_KICAD::m_bm
protected

Definition at line 68 of file pgm_kicad.h.

Referenced by Destroy(), GetHelpFileName(), OnPgmInit(), PgmSettings(), and SysSearch().

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protectedinherited

◆ m_help_size

wxSize PGM_BASE::m_help_size
protectedinherited

Definition at line 372 of file pgm_base.h.

Referenced by PGM_BASE::loadCommonSettings().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protectedinherited

The KICAD system environment variable.

Definition at line 358 of file pgm_base.h.

Referenced by PGM_BASE::GetKicadEnvVariable(), PGM_BASE::InitPgm(), and PGM_BASE::IsKicadEnvVariableDefined().

◆ m_language_id

int PGM_BASE::m_language_id
protectedinherited

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protectedinherited

Local environment variable expansion settings such as KICAD6_FOOTPRINT_DIR, and KICAD6_3DMODEL_DIR.

Definition at line 375 of file pgm_base.h.

Referenced by PGM_BASE::GetLocalEnvVariables(), PGM_BASE::InitPgm(), PGM_BASE::loadCommonSettings(), PGM_BASE::SaveCommonSettings(), and PGM_BASE::SetLocalEnvVariables().

◆ m_locale

wxLocale* PGM_BASE::m_locale
protectedinherited

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount
inherited

Definition at line 333 of file pgm_base.h.

Referenced by APP_KICAD::FilterEvent(), and PGM_BASE::PGM_BASE().

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protectedinherited

The file name of the the program selected for browsing pdf files.

Definition at line 370 of file pgm_base.h.

Referenced by PGM_BASE::GetPdfBrowserName(), PGM_BASE::SetPdfBrowserName(), and PGM_BASE::UseSystemPdfBrowser().

◆ m_pgm_checker

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protectedinherited

prevents multiple instances of a program from being run at the same time.

Definition at line 352 of file pgm_base.h.

Referenced by PGM_BASE::Destroy(), PGM_BASE::InitPgm(), and PGM_BASE::PGM_BASE().

◆ m_Printing

bool PGM_BASE::m_Printing
inherited

wxWidgets on MSW tends to crash if you spool up more than one print job at a time.

Definition at line 331 of file pgm_base.h.

Referenced by BOARD::ComputeBoundingBox(), and PGM_BASE::PGM_BASE().

◆ m_settings_manager

std::unique_ptr<SETTINGS_MANAGER> PGM_BASE::m_settings_manager
protectedinherited

◆ m_show_env_var_dialog

bool PGM_BASE::m_show_env_var_dialog
protectedinherited

Flag to indicate if the environment variable overwrite warning dialog should be shown.

Definition at line 378 of file pgm_base.h.

Referenced by PGM_BASE::loadCommonSettings(), PGM_BASE::PGM_BASE(), and PGM_BASE::SaveCommonSettings().

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protectedinherited

true to use the selected PDF browser, if exists, or false to use the default

Definition at line 367 of file pgm_base.h.

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

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
staticinherited

Definition at line 302 of file pgm_base.h.


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