KiCad PCB EDA Suite
PGM_SINGLE_TOP Struct Reference

Struct PGM_SINGLE_TOP implements PGM_BASE with its own OnPgmInit() and OnPgmExit(). More...

Inheritance diagram for PGM_SINGLE_TOP:
PGM_BASE

Public Member Functions

bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 Specific to MacOSX (not used under Linux or Windows). More...
 
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 Destroy ()
 
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

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

Struct PGM_SINGLE_TOP implements PGM_BASE with its own OnPgmInit() and OnPgmExit().

Definition at line 66 of file single_top.cpp.

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

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

Referenced by PGM_BASE::InitPgm(), PGM_KICAD::MacOpenFile(), PGM_TEST_FRAME::MacOpenFile(), MacOpenFile(), PGM_MOCK_EESCHEMA_FRAME::MacOpenFile(), and PGM_KICAD::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 192 of file pgm_base.cpp.

193 {
194  // Create a mask representing the executable files in the current platform
195 #ifdef __WINDOWS__
196  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
197 #else
198  wxString mask( _( "Executable file (*)|*" ) );
199 #endif
200 
201  // Extract the path, name and extension from the default editor (even if the editor's
202  // name was empty, this method will succeed and return empty strings).
203  wxString path, name, ext;
204  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
205 
206  // Show the modal editor and return the file chosen (may be empty if the user cancels
207  // the dialog).
208  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
209  name, ext, mask,
210  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
211  true );
212 }
#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:105

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

Referenced by PGM_BASE::GetEditorName().

◆ Destroy()

void PGM_BASE::Destroy ( )
inherited

Definition at line 129 of file pgm_base.cpp.

130 {
131  // unlike a normal destructor, this is designed to be called more than once safely:
132  delete m_pgm_checker;
133  m_pgm_checker = 0;
134 
135  delete m_locale;
136  m_locale = 0;
137 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:361
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:352

References PGM_BASE::m_locale, and PGM_BASE::m_pgm_checker.

Referenced by CreateWindow(), PGM_KICAD::Destroy(), OnPgmExit(), and PGM_BASE::~PGM_BASE().

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

584 {
586 }
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 155 of file pgm_base.cpp.

156 {
157  wxString editorname = m_editor_name;
158 
159  if( !editorname )
160  {
161  if( !wxGetEnv( "EDITOR", &editorname ) )
162  {
163  // If there is no EDITOR variable set, try the desktop default
164 #ifdef __WXMAC__
165  editorname = "/usr/bin/open";
166 #elif __WXX11__
167  editorname = "/usr/bin/xdg-open";
168 #endif
169  }
170  }
171 
172  // If we still don't have an editor name show a dialog asking the user to select one
173  if( !editorname && aCanShowFileChooser )
174  {
176  _( "No default editor found, you must choose it" ) );
177 
178  editorname = AskUserForPreferredEditor();
179  }
180 
181  // If we finally have a new editor name request it to be copied to m_editor_name and
182  // saved to the preferences file.
183  if( !editorname.IsEmpty() )
184  SetEditorName( editorname );
185 
186  // m_editor_name already has the same value that editorname, or empty if no editor was
187  // found/chosen.
188  return m_editor_name;
189 }
virtual void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:147
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:192
#define NULL
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:105
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 OnPgmInit(), and PGM_BASE::SetLanguagePath().

◆ 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 PGM_KICAD::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 215 of file pgm_base.cpp.

216 {
217  wxFileName pgm_name( App().argv[0] );
218 
219  wxInitAllImageHandlers();
220 
221 #ifndef __WINDOWS__
222  if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
223  {
224  DisplayErrorMessage( nullptr, _( "Environmental variable HOME is empty. Unable to continue." ) );
225  return false;
226  }
227 #endif
228 
229  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
230  wxGetUserId(), GetKicadLockFilePath() );
231 
232  if( m_pgm_checker->IsAnotherRunning() )
233  {
234  wxString quiz =
235  wxString::Format( _( "%s is already running. Continue?" ), pgm_name.GetName() );
236 
237  if( !IsOK( NULL, quiz ) )
238  return false;
239  }
240 
241  // Init KiCad environment
242  // the environment variable KICAD (if exists) gives the kicad path:
243  // something like set KICAD=d:\kicad
244  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
245 
246  if( isDefined ) // ensure m_kicad_env ends by "/"
247  {
249 
250  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
252  }
253 
254  // Init parameters for configuration
255  App().SetVendorName( "KiCad" );
256  App().SetAppName( pgm_name.GetName().Lower() );
257 
258  // Install some image handlers, mainly for help
259  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
260  wxImage::AddHandler( new wxPNGHandler );
261 
262  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
263  wxImage::AddHandler( new wxGIFHandler );
264 
265  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
266  wxImage::AddHandler( new wxJPEGHandler );
267 
268  wxFileSystem::AddHandler( new wxZipFSHandler );
269 
270  // Analyze the command line & initialize the binary path
271  wxString tmp;
273  SetLanguagePath();
274  SetDefaultLanguage( tmp );
275 
276  m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
277 
278  // Something got in the way of settings load: can't continue
279  if( !m_settings_manager->IsOK() )
280  return false;
281 
282  wxFileName baseSharePath;
283 #if defined( __WXMSW__ )
284  // Make the paths relative to the executable dir as KiCad might be installed anywhere
285  // It follows the Windows installer paths scheme, where binaries are installed in
286  // PATH/bin and extra files in PATH/share/kicad
287  baseSharePath.AssignDir( m_bin_dir + "\\.." );
288  baseSharePath.Normalize();
289 #else
290  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
291 #endif
292 
293 #if !defined( __WXMAC__ )
294  baseSharePath.AppendDir( "share" );
295  baseSharePath.AppendDir( "kicad" );
296 #endif
297 
298  // KICAD6_FOOTPRINT_DIR
299  wxString envVarName = wxT( "KICAD6_FOOTPRINT_DIR" );
300  ENV_VAR_ITEM envVarItem;
301  wxString envValue;
302  wxFileName tmpFileName;
303 
304  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
305  {
306  tmpFileName.AssignDir( envValue );
307  envVarItem.SetDefinedExternally( true );
308  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
309  }
310  else
311  {
312  tmpFileName = baseSharePath;
313  tmpFileName.AppendDir( "modules" );
314  envVarItem.SetDefinedExternally( false );
315  }
316 
317  envVarItem.SetValue( tmpFileName.GetPath() );
318  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
319  envVarName, envVarItem.GetValue() );
320  m_local_env_vars[ envVarName ] = envVarItem;
321 
322  // KICAD6_3DMODEL_DIR
323  envVarName = wxT( "KICAD6_3DMODEL_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  tmpFileName = baseSharePath;
334  tmpFileName.AppendDir( "3dmodels" );
335  envVarItem.SetDefinedExternally( false );
336  }
337 
338  envVarItem.SetValue( tmpFileName.GetFullPath() );
339  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
340  envVarName, envVarItem.GetValue() );
341  m_local_env_vars[ envVarName ] = envVarItem;
342 
343  // KICAD6_TEMPLATE_DIR
344  envVarName = "KICAD6_TEMPLATE_DIR";
345 
346  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
347  {
348  tmpFileName.AssignDir( envValue );
349  envVarItem.SetDefinedExternally( true );
350  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
351  }
352  else
353  {
354  // Attempt to find the best default template path.
355  SEARCH_STACK bases;
356  SEARCH_STACK templatePaths;
357 
358  SystemDirsAppend( &bases );
359 
360  for( unsigned i = 0; i < bases.GetCount(); ++i )
361  {
362  wxFileName fn( bases[i], wxEmptyString );
363 
364  // Add KiCad template file path to search path list.
365  fn.AppendDir( "template" );
366 
367  // Only add path if exists and can be read by the user.
368  if( fn.DirExists() && fn.IsDirReadable() )
369  {
370  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
371  fn.GetPath() );
372  templatePaths.AddPaths( fn.GetPath() );
373  }
374  }
375 
376  if( templatePaths.IsEmpty() )
377  {
378  tmpFileName = baseSharePath;
379  tmpFileName.AppendDir( "template" );
380  }
381  else
382  {
383  // Take the first one. There may be more but this will likely be the best option.
384  tmpFileName.AssignDir( templatePaths[0] );
385  }
386 
387  envVarItem.SetDefinedExternally( false );
388  }
389 
390  envVarItem.SetValue( tmpFileName.GetPath() );
391  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s", envVarName,
392  envVarItem.GetValue() );
393  m_local_env_vars[ envVarName ] = envVarItem;
394 
395  // KICAD_USER_TEMPLATE_DIR
396  envVarName = "KICAD_USER_TEMPLATE_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  // Default user template path.
407  tmpFileName.AssignDir( PATHS::GetUserTemplatesPath() );
408  envVarItem.SetDefinedExternally( false );
409  }
410 
411  envVarItem.SetValue( tmpFileName.GetPath() );
412  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
413  envVarName, envVarItem.GetValue() );
414  m_local_env_vars[ envVarName ] = envVarItem;
415 
416  // KICAD_SYMBOLS
417  envVarName = wxT( "KICAD6_SYMBOL_DIR" );
418 
419  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
420  {
421  tmpFileName.AssignDir( envValue );
422  envVarItem.SetDefinedExternally( true );
423  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Found entry %s externally", envVarName );
424  }
425  else
426  {
427  tmpFileName = baseSharePath;
428  tmpFileName.AppendDir( "library" );
429  envVarItem.SetDefinedExternally( false );
430  }
431 
432  envVarItem.SetValue( tmpFileName.GetPath() );
433  wxLogTrace( traceEnvVars, "PGM_BASE::InitPgm: Setting entry %s = %s",
434  envVarName, envVarItem.GetValue() );
435  m_local_env_vars[ envVarName ] = envVarItem;
436 
438 
439  // Init user language *before* calling loadCommonSettings, because
440  // env vars could be incorrectly initialized on Linux
441  // (if the value contains some non ASCII7 chars, the env var is not initialized)
442  SetLanguage( tmp, true );
443 
445 
446  ReadPdfBrowserInfos(); // needs GetCommonSettings()
447 
448 #ifdef __WXMAC__
449  // Always show filters on Open dialog to be able to choose plugin
450  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
451 #endif
452 
453  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
454  // Need to create a project early for now (it can have an empty path for the moment)
456 
457  // TODO: Move tooltips into KIPLATFORM
458  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
459  // Windows as other platforms display tooltips while the mouse is not moving
460  wxToolTip::SetAutoPop( 10000 );
461 
462  return true;
463 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:508
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:140
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:466
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:589
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
virtual void SetLanguagePath()
Definition: pgm_base.cpp:738
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:105
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:684
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 PGM_KICAD::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 508 of file pgm_base.cpp.

509 {
510  m_help_size.x = 500;
511  m_help_size.y = 400;
512 
515 
516  for( const auto& it : GetCommonSettings()->m_Env.vars )
517  {
518  wxString key( it.first.c_str(), wxConvUTF8 );
519  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s",
520  key, it.second );
521 
522  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
523  // it is found in config. (It is reserved and defined as project path)
524  if( key == PROJECT_VAR_NAME )
525  continue;
526 
527  if( m_local_env_vars[ key ].GetDefinedExternally() )
528  continue;
529 
530  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Updating entry %s = %s",
531  key, it.second );
532 
533  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
534  }
535 
536  for( auto& m_local_env_var : m_local_env_vars )
537  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
538 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
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:793
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_SINGLE_TOP::MacOpenFile ( const wxString &  aFileName)
inlineoverridevirtual

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 85 of file single_top.cpp.

86  {
87  wxFileName filename( aFileName );
88 
89  if( filename.FileExists() )
90  {
91  #if 0
92  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
93  // the single_top link image.
94  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
95  #else
96  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
97  #endif
98  if( frame )
99  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
100  }
101  }
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:115
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:140

References PGM_BASE::App(), and KIWAY_PLAYER::OpenProjectFiles().

◆ OnPgmExit()

void PGM_SINGLE_TOP::OnPgmExit ( )
inline

Definition at line 70 of file single_top.cpp.

71  {
72  Kiway.OnKiwayEnd();
73 
74  if( m_settings_manager && m_settings_manager->IsOK() )
75  {
77  m_settings_manager->Save();
78  }
79 
80  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
81  // earlier than wxApp and earlier than static destruction would.
83  }
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:541
void Destroy()
Definition: pgm_base.cpp:129
void OnKiwayEnd()
Definition: kiway.cpp:602
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:349
KIWAY Kiway

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

Referenced by APP_SINGLE_TOP::OnExit(), APP_SINGLE_TOP::OnInit(), and APP_SINGLE_TOP::OnRun().

◆ OnPgmInit()

bool PGM_SINGLE_TOP::OnPgmInit ( )

Definition at line 313 of file single_top.cpp.

314 {
315 #if defined(DEBUG)
316  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
317 
318  if( !wxIsAbsolutePath( absoluteArgv0 ) )
319  {
320  wxLogError( wxT( "No meaningful argv[0]" ) );
321  return false;
322  }
323 #endif
324 
325  if( !InitPgm() )
326  {
327  // Clean up
328  OnPgmExit();
329  return false;
330  }
331 
332 #if !defined(BUILD_KIWAY_DLL)
333 
334  // Only bitmap2component and pcb_calculator use this code currently, as they
335  // are not split to use single_top as a link image separate from a *.kiface.
336  // i.e. they are single part link images so don't need to load a *.kiface.
337 
338  // Get the getter, it is statically linked into this binary image.
340 
341  int kiface_version;
342 
343  // Get the KIFACE.
344  KIFACE* kiface = getter( &kiface_version, KIFACE_VERSION, this );
345 
346  // Trick the KIWAY into thinking it loaded a KIFACE, by recording the KIFACE
347  // in the KIWAY. It needs to be there for KIWAY::OnKiwayEnd() anyways.
348  Kiway.set_kiface( KIWAY::KifaceType( TOP_FRAME ), kiface );
349 #endif
350 
351  static const wxCmdLineEntryDesc desc[] = {
352  { wxCMD_LINE_OPTION, "f", "frame", "Frame to load", wxCMD_LINE_VAL_STRING, 0 },
353  { wxCMD_LINE_PARAM, nullptr, nullptr, "File to load", wxCMD_LINE_VAL_STRING,
354  wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
355  { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
356  };
357 
358  wxCmdLineParser parser( App().argc, App().argv );
359  parser.SetDesc( desc );
360  parser.Parse( false );
361 
362  FRAME_T appType = TOP_FRAME;
363 
364  const struct
365  {
366  wxString name;
367  FRAME_T type;
368  } frameTypes[] = {
369  { wxT( "pcb" ), FRAME_PCB_EDITOR },
370  { wxT( "fpedit" ), FRAME_FOOTPRINT_EDITOR },
371  { wxT( "" ), FRAME_T_COUNT }
372  };
373 
374  wxString frameName;
375 
376  if( parser.Found( "frame", &frameName ) )
377  {
378  appType = FRAME_T_COUNT;
379 
380  for( const auto& it : frameTypes )
381  {
382  if( it.name == frameName )
383  appType = it.type;
384  }
385 
386  if( appType == FRAME_T_COUNT )
387  {
388  wxLogError( wxT( "Unknown frame: %s" ), frameName );
389  // Clean up
390  OnPgmExit();
391  return false;
392  }
393  }
394 
395  // Tell the settings manager about the current Kiway
397 
398  // Use KIWAY to create a top window, which registers its existence also.
399  // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
400  // and is one of the types in FRAME_T.
401  KIWAY_PLAYER* frame = Kiway.Player( appType, true );
402 
403  if( frame == nullptr )
404  {
405  return false;
406  }
407 
408  Kiway.SetTop( frame );
409 
410  App().SetTopWindow( frame ); // wxApp gets a face.
411 
412  // Allocate a slice of time to show the frame and update wxWidgets widgets
413  // (especially setting valid sizes) after creating frame and before calling
414  // OpenProjectFiles() that can update/use some widgets.
415  // The 2 calls to wxSafeYield are needed on wxGTK for best results.
416  wxSafeYield();
417  frame->Show();
418  wxSafeYield();
419 
420  // Individual frames may provide additional option/switch processing, but for compatibility,
421  // any positional arguments are treated as a list of files to pass to OpenProjectFiles
422  frame->ParseArgs( parser );
423 
424  // Now after the frame processing, the rest of the positional args are files
425  std::vector<wxString> fileArgs;
426 
427  if( parser.GetParamCount() )
428  {
429  /*
430  gerbview handles multiple project data files, i.e. gerber files on
431  cmd line. Others currently do not, they handle only one. For common
432  code simplicity we simply pass all the arguments in however, each
433  program module can do with them what they want, ignore, complain
434  whatever. We don't establish policy here, as this is a multi-purpose
435  launcher.
436  */
437 
438  for( size_t i = 0; i < parser.GetParamCount(); i++ )
439  fileArgs.push_back( parser.GetParam( i ) );
440 
441  // special attention to a single argument: argv[1] (==argSet[0])
442  if( fileArgs.size() == 1 )
443  {
444  wxFileName argv1( fileArgs[0] );
445 
446 #if defined(PGM_DATA_FILE_EXT)
447  // PGM_DATA_FILE_EXT, if present, may be different for each compile,
448  // it may come from CMake on the compiler command line, but often does not.
449  // This facility is mostly useful for those program footprints
450  // supporting a single argv[1].
451  if( !argv1.GetExt() )
452  argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
453 #endif
454  argv1.MakeAbsolute();
455 
456  fileArgs[0] = argv1.GetFullPath();
457  }
458 
459  // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
460  if( !frame->OpenProjectFiles( fileArgs ) )
461  {
462  // OpenProjectFiles() API asks that it report failure to the UI.
463  // Nothing further to say here.
464 
465  // We've already initialized things at this point, but wx won't call OnExit if
466  // we fail out. Call our own cleanup routine here to ensure the relevant resources
467  // are freed at the right time (if they aren't, segfaults will occur).
468  OnPgmExit();
469 
470  // Fail the process startup if the file could not be opened,
471  // although this is an optional choice, one that can be reversed
472  // also in the KIFACE specific OpenProjectFiles() return value.
473  return false;
474  }
475  }
476 
477  return true;
478 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:115
BITMAP2CMP_SETTINGS kiface
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
static FACE_T KifaceType(FRAME_T aFrameType)
A simple mapping function which returns the FACE_T which is known to implement aFrameType.
Definition: kiway.cpp:295
void OnPgmExit()
Definition: single_top.cpp:70
#define KIFACE_VERSION
The KIWAY and KIFACE classes are used to communicate between various process modules,...
Definition: kiway.h:108
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:140
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:345
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:402
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition: kiway.h:456
#define KIFACE_GETTER
Definition: kiway.h:109
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
const char * name
Definition: DXF_plotter.cpp:59
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:147
bool InitPgm()
Initialize this program.
Definition: pgm_base.cpp:215
virtual void ParseArgs(wxCmdLineParser &aParser)
Handle command-line arguments in a frame-specific way.
Definition: kiway_player.h:136
KIWAY Kiway

References FRAME_FOOTPRINT_EDITOR, FRAME_PCB_EDITOR, FRAME_T_COUNT, PGM_BASE::GetExecutablePath(), GetSettingsManager(), kiface, KIFACE_GETTER, KIFACE_VERSION, KIWAY::KifaceType(), Kiway, name, KIWAY_PLAYER::OpenProjectFiles(), KIWAY_PLAYER::ParseArgs(), KIWAY::Player(), KIWAY::set_kiface(), SETTINGS_MANAGER::SetKiway(), and KIWAY::SetTop().

Referenced by APP_SINGLE_TOP::OnInit().

◆ 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:583
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 541 of file pgm_base.cpp.

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

685 {
686  setLanguageId( wxLANGUAGE_DEFAULT );
687 
688  // dictionary file name without extend (full name is kicad.mo)
689  wxString dictionaryName( "kicad" );
690 
691  delete m_locale;
692  m_locale = new wxLocale;
693  m_locale->Init();
694 
695  // Try adding the dictionary if it is not currently loaded
696  if( !m_locale->IsLoaded( dictionaryName ) )
697  m_locale->AddCatalog( dictionaryName );
698 
699  // Verify the Kicad dictionary was loaded properly
700  // However, for the English language, the dictionary is not mandatory, as
701  // all messages are already in English, just restricted to ASCII7 chars,
702  // the verification is skipped.
703  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
704  {
705  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
706  dictionaryName, m_locale->GetName() );
707 
708  setLanguageId( wxLANGUAGE_DEFAULT );
709  delete m_locale;
710 
711  m_locale = new wxLocale;
712  m_locale->Init();
713 
714  aErrMsg = _( "The KiCad language file for this language is not installed." );
715  return false;
716  }
717 
718  return true;
719 }
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:105

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

148 {
149  m_editor_name = aFileName;
150  wxASSERT( GetCommonSettings() );
151  GetCommonSettings()->m_System.editor_name = aFileName;
152 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:583
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 466 of file pgm_base.cpp.

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

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

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

723 {
724  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
725  menu_id, (int)arrayDim( LanguagesList )-1 );
726 
727  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
728  {
729  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
730  {
731  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
732  break;
733  }
734  }
735 }
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 738 of file pgm_base.cpp.

739 {
740  SEARCH_STACK guesses;
741 
742  SystemDirsAppend( &guesses );
743 
744  // Add our internat dir to the wxLocale catalog of paths
745  for( unsigned i = 0; i < guesses.GetCount(); i++ )
746  {
747  wxFileName fn( guesses[i], wxEmptyString );
748 
749  // Append path for Windows and unix KiCad package install
750  fn.AppendDir( "share" );
751  fn.AppendDir( "internat" );
752 
753  if( fn.IsDirReadable() )
754  {
755  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
756  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
757  }
758 
759  // Append path for unix standard install
760  fn.RemoveLastDir();
761  fn.AppendDir( "kicad" );
762  fn.AppendDir( "internat" );
763 
764  if( fn.IsDirReadable() )
765  {
766  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
767  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
768  }
769 
770  // Append path for macOS install
771  fn.RemoveLastDir();
772  fn.RemoveLastDir();
773  fn.RemoveLastDir();
774  fn.AppendDir( "internat" );
775 
776  if( fn.IsDirReadable() )
777  {
778  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
779  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
780  }
781  }
782 
783  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
784  {
785  wxFileName fn( Pgm().GetExecutablePath() );
786  fn.RemoveLastDir();
787  fn.AppendDir( "translation" );
788  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
789  }
790 }
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 793 of file pgm_base.cpp.

794 {
795  wxString env;
796 
797  // Check to see if the environment variable is already set.
798  if( wxGetEnv( aName, &env ) )
799  {
800  wxLogTrace( traceEnvVars,
801  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
802  aName, env );
803  return env == aValue;
804  }
805 
806  wxLogTrace( traceEnvVars,
807  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
808  aName, aValue );
809 
810  return wxSetEnv( aName, aValue );
811 }
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 814 of file pgm_base.cpp.

815 {
816  m_local_env_vars.clear();
817  m_local_env_vars = aEnvVarMap;
818 
820 
821  // Overwrites externally defined environment variable until the next time the application
822  // is run.
823  for( auto& m_local_env_var : m_local_env_vars )
824  {
825  wxLogTrace( traceEnvVars,
826  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
827  m_local_env_var.first,
828  m_local_env_var.second.GetValue() );
829  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
830  }
831 }
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:541
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().

◆ 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:583
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_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 struct was generated from the following file: