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
 Function MacOpenFile is specific to MacOSX (not used under Linux or Windows). More...
 
APP_SETTINGS_BASEPgmSettings ()
 
SEARCH_STACKSysSearch ()
 
wxString GetHelpFileName ()
 
void Destroy ()
 
VTBL_ENTRY SETTINGS_MANAGERGetSettingsManager () const
 
VTBL_ENTRY COMMON_SETTINGSGetCommonSettings () const
 
VTBL_ENTRY void SetEditorName (const wxString &aFileName)
 
VTBL_ENTRY const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
VTBL_ENTRY const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
VTBL_ENTRY bool IsKicadEnvVariableDefined () const
 
VTBL_ENTRY const wxString & GetKicadEnvVariable () const
 
VTBL_ENTRY const wxString & GetExecutablePath () const
 
VTBL_ENTRY wxLocale * GetLocale ()
 
VTBL_ENTRY const wxString & GetPdfBrowserName () const
 
VTBL_ENTRY void SetPdfBrowserName (const wxString &aFileName)
 
VTBL_ENTRY bool UseSystemPdfBrowser () const
 Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser. More...
 
VTBL_ENTRY void ForceSystemPdfBrowser (bool aFlg)
 Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set. More...
 
VTBL_ENTRY bool SetLanguage (bool first_time=false)
 Function SetLanguage sets the dictionary file name for internationalization. More...
 
VTBL_ENTRY void SetLanguageIdentifier (int menu_id)
 Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id from the KiCad menu id (internal menu identifier). More...
 
VTBL_ENTRY int GetSelectedLanguageIdentifier () const
 
VTBL_ENTRY void SetLanguagePath ()
 
VTBL_ENTRY void ReadPdfBrowserInfos ()
 Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration. More...
 
VTBL_ENTRY void WritePdfBrowserInfos ()
 Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration. More...
 
VTBL_ENTRY bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Function SetLocalEnvVariable. More...
 
VTBL_ENTRY void SetLocalEnvVariables (const ENV_VAR_MAP &aEnvVarMap)
 Function SetLocalEnvVariables. More...
 
VTBL_ENTRY const ENV_VAR_MAPGetLocalEnvVariables () const
 
VTBL_ENTRY wxApp & App ()
 Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm ()
 Function initPgm initializes this program (process) in a KiCad standard way, using some generalized techniques. More...
 
void SaveCommonSettings ()
 Function saveCommonSettings saves the program (process) settings subset which are stored .kicad_common. More...
 

Public Attributes

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

Static Public Attributes

static const wxChar workingDirKey []
 

Protected Member Functions

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

Protected Attributes

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 KIGITHUB, KISYSMOD, and KISYS3DMOD. More...
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. More...
 

Detailed Description

PGM_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 39 of file pgm_kicad.h.

Constructor & Destructor Documentation

◆ PGM_KICAD()

PGM_KICAD::PGM_KICAD ( )
inline

Definition at line 42 of file pgm_kicad.h.

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

◆ ~PGM_KICAD()

PGM_KICAD::~PGM_KICAD ( )
throw (
)
inline

Definition at line 46 of file pgm_kicad.h.

47  {
48  Destroy();
49  }
void Destroy()
Definition: kicad.cpp:206

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
inherited

Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.

Should return what wxGetApp() returns.

Definition at line 138 of file pgm_base.cpp.

139 {
140  wxASSERT( wxTheApp );
141  return *wxTheApp;
142 }

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)
inherited

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

191 {
192  // Create a mask representing the executable files in the current platform
193 #ifdef __WINDOWS__
194  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
195 #else
196  wxString mask( _( "Executable file (*)|*" ) );
197 #endif
198 
199  // Extract the path, name and extension from the default editor (even if the editor's
200  // name was empty, this method will succeed and return empty strings).
201  wxString path, name, ext;
202  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
203 
204  // Show the modal editor and return the file chosen (may be empty if the user cancels
205  // the dialog).
206  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
207  name, ext, mask,
208  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
209  true );
210 }
#define NULL
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:52
const char * name
Definition: DXF_plotter.cpp:60
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:104

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

Referenced by PGM_BASE::GetEditorName().

◆ Destroy()

void PGM_KICAD::Destroy ( void  )

Definition at line 206 of file kicad.cpp.

207 {
208  // unlike a normal destructor, this is designed to be called more
209  // than once safely:
210 
211  m_bm.End();
212 
214 }
void Destroy()
Definition: pgm_base.cpp:127
BIN_MOD m_bm
Definition: pgm_kicad.h:69
void End()
Definition: bin_mod.cpp:53

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

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

◆ ForceSystemPdfBrowser()

VTBL_ENTRY void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlineinherited

Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set.

Definition at line 228 of file pgm_base.h.

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

References PGM_BASE::m_use_system_pdf_browser.

Referenced by PGM_BASE::PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
inherited

Definition at line 550 of file pgm_base.cpp.

551 {
553 }
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.

References SETTINGS_MANAGER::GetCommonSettings(), and 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)
inherited

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

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

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

◆ GetExecutablePath()

VTBL_ENTRY const wxString& PGM_BASE::GetExecutablePath ( ) const
inlineinherited

Definition at line 205 of file pgm_base.h.

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

References PGM_BASE::m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit().

◆ GetHelpFileName()

wxString PGM_KICAD::GetHelpFileName ( )
inline

Definition at line 60 of file pgm_kicad.h.

60 { return m_bm.m_help_file; }
wxString m_help_file
Definition: bin_mod.h:65
BIN_MOD m_bm
Definition: pgm_kicad.h:69

References m_bm, and BIN_MOD::m_help_file.

Referenced by KICAD_MANAGER_FRAME::help_name().

◆ GetKicadEnvVariable()

VTBL_ENTRY const wxString& PGM_BASE::GetKicadEnvVariable ( ) const
inlineinherited

Definition at line 203 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ GetLocale()

VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inlineinherited

Definition at line 207 of file pgm_base.h.

207 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

VTBL_ENTRY const ENV_VAR_MAP& PGM_BASE::GetLocalEnvVariables ( ) const
inlineinherited

Definition at line 298 of file pgm_base.h.

299  {
300  return m_local_env_vars;
301  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384

References PGM_BASE::m_local_env_vars.

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

◆ GetPdfBrowserName()

VTBL_ENTRY const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inlineinherited

Definition at line 209 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

VTBL_ENTRY int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inlineinherited
Returns
the wxWidgets language identifier Id of the language currently selected

Definition at line 255 of file pgm_base.h.

255 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:363

References PGM_BASE::m_language_id.

◆ GetSettingsManager()

◆ InitPgm()

bool PGM_BASE::InitPgm ( )
inherited

Function initPgm initializes this program (process) in a KiCad standard way, using some generalized techniques.

  • Default paths (help, libs, bin) and configuration file names
  • Language and locale
  • fonts

But nothing relating to DSOs or projects.

Returns
bool - true if success, false if failure and program is to terminate.

Definition at line 213 of file pgm_base.cpp.

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

References _, SEARCH_STACK::AddPaths(), PGM_BASE::App(), Format(), GetChars(), PGM_BASE::GetCommonSettings(), GetKicadLockFilePath(), PGM_BASE::GetSettingsManager(), 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(), ENV_VAR_ITEM::SetDefinedExternally(), PGM_BASE::setExecutablePath(), PGM_BASE::SetLanguage(), PGM_BASE::SetLanguagePath(), ENV_VAR_ITEM::SetValue(), SystemDirsAppend(), tracePathsAndFiles, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by OnPgmInit().

◆ IsKicadEnvVariableDefined()

VTBL_ENTRY bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlineinherited

Definition at line 201 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 495 of file pgm_base.cpp.

496 {
497  m_help_size.x = 500;
498  m_help_size.y = 400;
499 
502 
503  for( const auto& it : GetCommonSettings()->m_Env.vars )
504  {
505  wxString key( it.first.c_str(), wxConvUTF8 );
506  wxLogTrace( traceEnvVars, "Enumerating over entry %s = %s.", key, it.second );
507 
508  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
509  // it is found in config. (It is reserved and defined as project path)
510  if( key == PROJECT_VAR_NAME )
511  continue;
512 
513  if( m_local_env_vars[ key ].GetDefinedExternally() )
514  continue;
515 
516  m_local_env_vars[ key ] = ENV_VAR_ITEM( it.second, wxGetEnv( it.first, nullptr ) );
517  }
518 
519  for( auto& m_local_env_var : m_local_env_vars )
520  SetLocalEnvVariable( m_local_env_var.first, m_local_env_var.second.GetValue() );
521 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
ENV_VAR_ITEM.
Definition: pgm_base.h:88
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:63
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:699
ENVIRONMENT m_Env
wxSize m_help_size
Definition: pgm_base.h:381
wxString m_editor_name
Definition: pgm_base.h:380

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

Function MacOpenFile is specific to MacOSX (not used under Linux or Windows).

MacOSX requires it for file association.

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

Implements PGM_BASE.

Definition at line 193 of file kicad.cpp.

194 {
195 #if defined(__WXMAC__)
196 
197  KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
198 
199  if( !aFileName.empty() && wxFileExists( aFileName ) )
200  frame->LoadProject( wxFileName( aFileName ) );
201 
202 #endif
203 }
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:138
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 176 of file kicad.cpp.

177 {
178  Kiway.OnKiwayEnd();
179 
180  if( m_settings_manager && m_settings_manager->IsOK() )
181  {
183  m_settings_manager->Save();
184  }
185 
186  // Destroy everything in PGM_KICAD,
187  // especially wxSingleInstanceCheckerImpl earlier than wxApp and earlier
188  // than static destruction would.
189  Destroy();
190 }
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:524
void OnKiwayEnd()
Definition: kiway.cpp:542
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:348
void Destroy()
Definition: kicad.cpp:206
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 78 of file kicad.cpp.

79 {
80 #if defined(DEBUG)
81  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
82 
83  if( !wxIsAbsolutePath( absoluteArgv0 ) )
84  {
85  wxLogError( wxT( "No meaningful argv[0]" ) );
86  return false;
87  }
88 #endif
89 
90  if( !InitPgm() )
91  return false;
92 
95  m_bm.Init();
96 
97  // Add search paths to feed the PGM_KICAD::SysSearch() function,
98  // currenly limited in support to only look for project templates
99  {
100  SEARCH_STACK bases;
101 
102  SystemDirsAppend( &bases );
103 
104  for( unsigned i = 0; i < bases.GetCount(); ++i )
105  {
106  wxFileName fn( bases[i], wxEmptyString );
107 
108  // Add KiCad template file path to search path list.
109  fn.AppendDir( wxT( "template" ) );
110 
111  // Only add path if exists and can be read by the user.
112  if( fn.DirExists() && fn.IsDirReadable() )
113  m_bm.m_search.AddPaths( fn.GetPath() );
114  }
115 
116  // The KICAD_TEMPLATE_DIR takes precedence over the search stack template path.
117  ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD_TEMPLATE_DIR" );
118 
119  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
120  m_bm.m_search.Insert( it->second.GetValue(), 0 );
121 
122  // The KICAD_USER_TEMPLATE_DIR takes precedence over KICAD_TEMPLATE_DIR and the search
123  // stack template path.
124  it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
125 
126  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
127  m_bm.m_search.Insert( it->second.GetValue(), 0 );
128  }
129 
130  KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
131  wxDefaultPosition, wxSize( 775, -1 ) );
132  App().SetTopWindow( frame );
133 
134  Kiway.SetTop( frame );
135 
136  wxString projToLoad;
137 
138  if( App().argc > 1 )
139  {
140  projToLoad = App().argv[1];
141  }
142  else if( frame->GetFileHistory().GetCount() )
143  {
144  wxString last_pro = frame->GetFileHistory().GetHistoryFile( 0 );
145 
146  if( !wxFileExists( last_pro ) )
147  {
148  frame->GetFileHistory().RemoveFileFromHistory( 0 );
149  }
150  else
151  {
152  // Try to open the last opened project,
153  // if a project name is not given when starting Kicad
154  projToLoad = last_pro;
155  }
156  }
157 
158  // Do not attempt to load a non-existent project file.
159  if( !projToLoad.empty() )
160  {
161  wxFileName fn( projToLoad );
162  if( fn.Exists() )
163  {
164  fn.MakeAbsolute();
165  frame->LoadProject( fn );
166  }
167  }
168 
169  frame->Show( true );
170  frame->Raise();
171 
172  return true;
173 }
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
void Init()
Definition: bin_mod.cpp:41
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:138
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
#define NULL
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:119
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:60
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:298
void SetTop(wxFrame *aTop)
Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to ...
Definition: kiway.cpp:78
SEARCH_STACK m_search
Definition: bin_mod.h:67
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
BIN_MOD m_bm
Definition: pgm_kicad.h:69
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
APP_SETTINGS_BASE * PgmSettings()
Definition: pgm_kicad.h:56
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:213
void LoadProject(const wxFileName &aProjectFileName)
The main KiCad project manager frame.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)
KIWAY Kiway

References SEARCH_STACK::AddPaths(), PGM_BASE::App(), EDA_BASE_FRAME::GetFileHistory(), PGM_BASE::GetLocalEnvVariables(), PGM_BASE::GetSettingsManager(), BIN_MOD::Init(), PGM_BASE::InitPgm(), BIN_MOD::InitSettings(), Kiway, KICAD_MANAGER_FRAME::LoadProject(), m_bm, BIN_MOD::m_search, NULL, PgmSettings(), SETTINGS_MANAGER::RegisterSettings(), KIWAY::SetTop(), and SystemDirsAppend().

Referenced by APP_KICAD::OnInit().

◆ PgmSettings()

APP_SETTINGS_BASE* PGM_KICAD::PgmSettings ( )
inline

Definition at line 56 of file pgm_kicad.h.

56 { return m_bm.m_config; }
APP_SETTINGS_BASE * m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:64
BIN_MOD m_bm
Definition: pgm_kicad.h:69

References m_bm, and BIN_MOD::m_config.

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

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
inherited

Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.

Definition at line 43 of file eda_doc.cpp.

44 {
45  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
47 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:211

References 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

Function saveCommonSettings saves the program (process) settings subset which are stored .kicad_common.

Definition at line 524 of file pgm_base.cpp.

525 {
526  // GetCommonSettings() is not initialized until fairly late in the
527  // process startup: InitPgm(), so test before using:
528  if( GetCommonSettings() )
529  {
530  GetCommonSettings()->m_System.working_dir = wxGetCwd().ToStdString();
532 
533  // Save the local environment variables.
534  for( auto& m_local_env_var : m_local_env_vars )
535  {
536  if( m_local_env_var.second.GetDefinedExternally() )
537  continue;
538 
539  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
540  GetChars( m_local_env_var.first ),
541  GetChars( m_local_env_var.second.GetValue() ) );
542 
543  std::string key( m_local_env_var.first.ToUTF8() );
544  GetCommonSettings()->m_Env.vars[ key ] = m_local_env_var.second.GetValue();
545  }
546  }
547 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:63
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:387
std::map< std::string, wxString > vars
ENVIRONMENT m_Env
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153

References GetChars(), 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().

◆ SetEditorName()

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

Definition at line 145 of file pgm_base.cpp.

146 {
147  m_editor_name = aFileName;
148  wxASSERT( GetCommonSettings() );
149  GetCommonSettings()->m_System.editor_name = aFileName;
150 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
wxString m_editor_name
Definition: pgm_base.h:380

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

Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.

Returns
bool - true if success, else false.

Definition at line 453 of file pgm_base.cpp.

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

References PGM_BASE::m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_BASE::InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( bool  first_time = false)
inherited

Function SetLanguage sets the dictionary file name for internationalization.

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

Parameters
first_timemust be set to true the first time this funct is called, false otherwise
Returns
true if the language can be set (i.e. if the locale is available)

Definition at line 556 of file pgm_base.cpp.

557 {
558  bool retv = true;
559 
560  if( first_time )
561  {
562  setLanguageId( wxLANGUAGE_DEFAULT );
563  // First time SetLanguage is called, the user selected language id is set
564  // from common user config settings
565  wxString languageSel = GetCommonSettings()->m_System.language;
566 
567  // Search for the current selection
568  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
569  {
570  if( LanguagesList[ii].m_Lang_Label == languageSel )
571  {
572  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
573  break;
574  }
575  }
576  }
577 
578  // dictionary file name without extend (full name is kicad.mo)
579  wxString dictionaryName( "kicad" );
580 
581  delete m_locale;
582  m_locale = new wxLocale;
583 
584  if( !m_locale->Init( m_language_id ) )
585  {
586  wxLogTrace( traceLocale, "This language is not supported by the system." );
587 
588  setLanguageId( wxLANGUAGE_DEFAULT );
589  delete m_locale;
590 
591  m_locale = new wxLocale;
592  m_locale->Init();
593  retv = false;
594  }
595  else if( !first_time )
596  {
597  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
598  GetChars( dictionaryName ), GetChars( m_locale->GetName() ) );
599  }
600 
601  if( !first_time )
602  {
603  // If we are here, the user has selected another language.
604  // Therefore the new prefered language name is stored in common config.
605  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
606  // versions, for a given language
607  wxString languageSel;
608 
609  // Search for the current selection language name
610  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
611  {
612  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
613  {
614  languageSel = LanguagesList[ii].m_Lang_Label;
615  break;
616  }
617  }
618 
620  cfg->m_System.language = languageSel;
621  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
622  }
623 
624  // Test if floating point notation is working (bug encountered in cross compilation)
625  // Make a conversion double <=> string
626  double dtst = 0.5;
627  wxString msg;
628 
629  msg << dtst;
630  double result;
631  msg.ToDouble( &result );
632 
633  if( result != dtst )
634  // string to double encode/decode does not work! Bug detected:
635  // Disable floating point localization:
636  setlocale( LC_NUMERIC, "C" );
637 
638  if( !m_locale->IsLoaded( dictionaryName ) )
639  m_locale->AddCatalog( dictionaryName );
640 
641  if( !retv )
642  return retv;
643 
644  return m_locale->IsOk();
645 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:74
VTBL_ENTRY SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:175
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:360
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:64
int m_language_id
The current language setting.
Definition: pgm_base.h:363
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:369
const wxChar *const traceLocale
Flag to enable locale debug output.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:70
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153

References GetChars(), 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 369 of file pgm_base.h.

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

References PGM_BASE::m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
inherited

Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id from the KiCad menu id (internal menu identifier).

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

Definition at line 648 of file pgm_base.cpp.

649 {
650  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
651  menu_id, (int)arrayDim( LanguagesList )-1 );
652 
653  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
654  {
655  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
656  {
657  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
658  break;
659  }
660  }
661 }
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:74
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:64
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:369
const wxChar *const traceLocale
Flag to enable locale debug output.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
inherited

Definition at line 664 of file pgm_base.cpp.

665 {
666  SEARCH_STACK guesses;
667 
668  SystemDirsAppend( &guesses );
669 
670  // Add our internat dir to the wxLocale catalog of paths
671  for( unsigned i = 0; i < guesses.GetCount(); i++ )
672  {
673  wxFileName fn( guesses[i], wxEmptyString );
674 
675  // Append path for Windows and unix KiCad package install
676  fn.AppendDir( "share" );
677  fn.AppendDir( "internat" );
678 
679  if( fn.IsDirReadable() )
680  {
681  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
682  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
683  }
684 
685  // Append path for unix standard install
686  fn.RemoveLastDir();
687  fn.AppendDir( "kicad" );
688  fn.AppendDir( "internat" );
689 
690  if( fn.IsDirReadable() )
691  {
692  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
693  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
694  }
695  }
696 }
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
const wxChar *const traceLocale
Flag to enable locale debug output.

References SystemDirsAppend(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ SetLocalEnvVariable()

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

Function SetLocalEnvVariable.

Sets the environment variable aName to aValue.

This function first checks to see if the environment variable aName is already defined. If it is not defined, then the environment variable aName is set to a value. Otherwise, the environment variable is left unchanged. This allows the user to override environment variables for testing purposes.

Parameters
aNameis a wxString containing the environment variable name.
aValueis a wxString containing the environment variable value.
Returns
true if the environment variable Name was set to aValue.

Definition at line 699 of file pgm_base.cpp.

700 {
701  wxString env;
702 
703  // Check to see if the environment variable is already set.
704  if( wxGetEnv( aName, &env ) )
705  {
706  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
707  GetChars( aName ), GetChars( env ) );
708  return env == aValue;
709  }
710 
711  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
712  GetChars( aName ), GetChars( aValue ) );
713 
714  return wxSetEnv( aName, aValue );
715 }
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:63
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153

References GetChars(), and traceEnvVars.

Referenced by PGM_BASE::loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)
inherited

Function SetLocalEnvVariables.

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

Parameters
aEnvVarMapis a ENV_VAR_MAP object containing the new environment variables.

Definition at line 718 of file pgm_base.cpp.

719 {
720  m_local_env_vars.clear();
721  m_local_env_vars = aEnvVarMap;
722 
724 
725  // Overwrites externally defined environment variable until the next time the application
726  // is run.
727  for( auto& m_local_env_var : m_local_env_vars )
728  {
729  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
730  GetChars( m_local_env_var.first ),
731  GetChars( m_local_env_var.second.GetValue() ) );
732  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
733  }
734 }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:384
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:524
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:63
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:153

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

◆ SetPdfBrowserName()

VTBL_ENTRY void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inlineinherited

Definition at line 211 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SysSearch()

SEARCH_STACK& PGM_KICAD::SysSearch ( )
inline

Definition at line 58 of file pgm_kicad.h.

58 { return m_bm.m_search; }
SEARCH_STACK m_search
Definition: bin_mod.h:67
BIN_MOD m_bm
Definition: pgm_kicad.h:69

References m_bm, and BIN_MOD::m_search.

Referenced by KICAD_MANAGER_FRAME::sys_search().

◆ UseSystemPdfBrowser()

VTBL_ENTRY bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlineinherited

Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser.

Definition at line 219 of file pgm_base.h.

220  {
221  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
222  }
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:379

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

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
inherited

Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration.

Definition at line 50 of file eda_doc.cpp.

51 {
54 }
VTBL_ENTRY COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:550
bool m_use_system_pdf_browser
true to use the selected PDF browser, if exists, or false to use the default
Definition: pgm_base.h:366
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:209

References 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 354 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 69 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 381 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 357 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

The current language setting.

Definition at line 363 of file pgm_base.h.

Referenced by PGM_BASE::GetSelectedLanguageIdentifier(), PGM_BASE::SetLanguage(), and PGM_BASE::setLanguageId().

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protectedinherited

Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.

Definition at line 384 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

The current locale.

Definition at line 360 of file pgm_base.h.

Referenced by PGM_BASE::Destroy(), PGM_BASE::GetLocale(), PGM_BASE::PGM_BASE(), and PGM_BASE::SetLanguage().

◆ 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 379 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 351 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 341 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 387 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 366 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 312 of file pgm_base.h.


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