KiCad PCB EDA Suite
PGM_BASE Class Referenceabstract

PGM_BASE keeps program (whole process) data for KiCad programs. More...

#include <pgm_base.h>

Inheritance diagram for PGM_BASE:
PGM_KICAD PGM_MOCK_EESCHEMA_FRAME PGM_SINGLE_TOP PGM_TEST_FRAME PGM_TEST_FRAME

Public Member Functions

 PGM_BASE ()
 
virtual ~PGM_BASE ()
 
VTBL_ENTRY void MacOpenFile (const wxString &aFileName)=0
 Function MacOpenFile is specific to MacOSX (not used under Linux or Windows). More...
 
VTBL_ENTRY wxConfigBase * CommonSettings () 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 Destroy ()
 
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 [] = wxT( "WorkingDir" )
 

Protected Member Functions

void loadCommonSettings ()
 Function loadCommonSettings loads the program (process) settings subset which are stored in .kicad_common. 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

wxSingleInstanceChecker * m_pgm_checker
 prevents multiple instances of a program from being run at the same time. More...
 
std::unique_ptr< wxConfigBase > m_common_settings
 Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common. 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_BASE keeps program (whole process) data for KiCad programs.

The VTBL_ENTRY functions are VTBL_ENTRY so we can do cross module calls without linking to them. This used to be a wxApp derivative, but that is difficult under wxPython which shapes the wxApp. So now this is a "side-car" (like a motorcycle side-car) object with a back pointer into the wxApp which initializes it.

OnPgmStart() is virtual, may be overridden, and parallels wxApp::OnInit(), from where it should called.

OnPgmEnd() is virtual, may be overridden, and parallels wxApp::OnExit(), from where it should be called.

Definition at line 156 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 113 of file pgm_base.cpp.

114 {
116  m_locale = NULL;
117  m_Printing = false;
118 
119  m_show_env_var_dialog = true;
120 
121  setLanguageId( wxLANGUAGE_DEFAULT );
122 
123  ForceSystemPdfBrowser( false );
124 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:382
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:245
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:409
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:369
#define NULL
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:391
bool m_Printing
wxWidgets on MSW tends to crash if you spool up more than one print job at a time.
Definition: pgm_base.h:358

References ForceSystemPdfBrowser(), m_locale, m_pgm_checker, m_Printing, m_show_env_var_dialog, NULL, and setLanguageId().

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 127 of file pgm_base.cpp.

128 {
129  Destroy();
130 }
void Destroy()
Definition: pgm_base.cpp:133

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )

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

147 {
148  wxASSERT( wxTheApp );
149  return *wxTheApp;
150 }

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

◆ AskUserForPreferredEditor()

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

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

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

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

Referenced by GetEditorName().

◆ CommonSettings()

VTBL_ENTRY wxConfigBase* PGM_BASE::CommonSettings ( ) const
inline

Definition at line 194 of file pgm_base.h.

194 { return m_common_settings.get(); }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373

References m_common_settings.

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 133 of file pgm_base.cpp.

134 {
135  // unlike a normal destructor, this is designed to be called more than once safely:
136  m_common_settings.reset();
137 
138  delete m_pgm_checker;
139  m_pgm_checker = 0;
140 
141  delete m_locale;
142  m_locale = 0;
143 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:382
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:369

References m_common_settings, m_locale, and m_pgm_checker.

Referenced by PGM_KICAD::Destroy(), PGM_SINGLE_TOP::OnPgmExit(), PGM_MOCK_EESCHEMA_FRAME::OnPgmExit(), PGM_TEST_FRAME::OnPgmExit(), and ~PGM_BASE().

◆ ForceSystemPdfBrowser()

VTBL_ENTRY void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inline

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

Definition at line 245 of file pgm_base.h.

245 { 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:388

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetEditorName()

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

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

162 {
163  wxString editorname = m_editor_name;
164 
165  if( !editorname )
166  {
167  if( !wxGetEnv( "EDITOR", &editorname ) )
168  {
169  // If there is no EDITOR variable set, try the desktop default
170 #ifdef __WXMAC__
171  editorname = "/usr/bin/open";
172 #elif __WXX11__
173  editorname = "/usr/bin/xdg-open";
174 #endif
175  }
176  }
177 
178  // If we still don't have an editor name show a dialog asking the user to select one
179  if( !editorname && aCanShowFileChooser )
180  {
182  _( "No default editor found, you must choose it" ) );
183 
184  editorname = AskUserForPreferredEditor();
185  }
186 
187  // If we finally have a new editor name request it to be copied to m_editor_name and
188  // saved to the preferences file.
189  if( !editorname.IsEmpty() )
190  SetEditorName( editorname );
191 
192  // m_editor_name already has the same value that editorname, or empty if no editor was
193  // found/chosen.
194  return m_editor_name;
195 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:153
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:198
#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:110
wxString m_editor_name
Definition: pgm_base.h:402
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:264

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

◆ GetExecutablePath()

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

Definition at line 222 of file pgm_base.h.

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

References m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit().

◆ GetKicadEnvVariable()

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

Definition at line 220 of file pgm_base.h.

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

References m_kicad_env.

◆ GetLocale()

VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inline

Definition at line 224 of file pgm_base.h.

224 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:382

References m_locale.

◆ GetLocalEnvVariables()

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

Definition at line 315 of file pgm_base.h.

316  {
317  return m_local_env_vars;
318  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406

References m_local_env_vars.

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

◆ GetPdfBrowserName()

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

Definition at line 226 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

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

Definition at line 272 of file pgm_base.h.

272 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:385

References m_language_id.

◆ InitPgm()

bool PGM_BASE::InitPgm ( )

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

222 {
223  wxFileName pgm_name( App().argv[0] );
224 
225  wxConfigBase::DontCreateOnDemand();
226 
227  wxInitAllImageHandlers();
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 = wxString::Format(
235  _( "%s is already running. Continue?" ),
236  GetChars( pgm_name.GetName() )
237  );
238 
239  if( !IsOK( NULL, quiz ) )
240  return false;
241  }
242 
243  // Init KiCad environment
244  // the environment variable KICAD (if exists) gives the kicad path:
245  // something like set KICAD=d:\kicad
246  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
247 
248  if( isDefined ) // ensure m_kicad_env ends by "/"
249  {
251 
252  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
254  }
255 
256  // Init parameters for configuration
257  App().SetVendorName( "KiCad" );
258  App().SetAppName( pgm_name.GetName().Lower() );
259 
260  // Install some image handlers, mainly for help
261  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
262  wxImage::AddHandler( new wxPNGHandler );
263 
264  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
265  wxImage::AddHandler( new wxGIFHandler );
266 
267  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
268  wxImage::AddHandler( new wxJPEGHandler );
269 
270  wxFileSystem::AddHandler( new wxZipFSHandler );
271 
272  // Analyze the command line & initialize the binary path
274 
275  SetLanguagePath();
276 
277  // OS specific instantiation of wxConfigBase derivative:
279 
280  wxString envVarName = wxT( "KIGITHUB" );
281  ENV_VAR_ITEM envVarItem;
282  wxString envValue;
283  wxFileName tmpFileName;
284 
285  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
286  {
287  tmpFileName.AssignDir( envValue );
288  envVarItem.SetDefinedExternally( true );
289  }
290  else
291  {
292  envVarItem.SetValue( wxString( wxT( "https://github.com/KiCad" ) ) );
293  envVarItem.SetDefinedExternally( false );
294  }
295 
296  m_local_env_vars[ envVarName ] = envVarItem;
297 
298  wxFileName baseSharePath;
299 #if defined( __WXMSW__ )
300  // Make the paths relative to the executable dir as KiCad might be installed anywhere
301  // It follows the Windows installer paths scheme, where binaries are installed in
302  // PATH/bin and extra files in PATH/share/kicad
303  baseSharePath.AssignDir( m_bin_dir + "\\.." );
304  baseSharePath.Normalize();
305 #else
306  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
307 #endif
308 
309 #if !defined( __WXMAC__ )
310  baseSharePath.AppendDir( "share" );
311  baseSharePath.AppendDir( "kicad" );
312 #endif
313 
314  // KISYSMOD
315  envVarName = wxT( "KISYSMOD" );
316 
317  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
318  {
319  tmpFileName.AssignDir( envValue );
320  envVarItem.SetDefinedExternally( true );
321  }
322  else
323  {
324  tmpFileName = baseSharePath;
325  tmpFileName.AppendDir( "modules" );
326  envVarItem.SetDefinedExternally( false );
327  }
328 
329  envVarItem.SetValue( tmpFileName.GetPath() );
330  m_local_env_vars[ envVarName ] = envVarItem;
331 
332  // KISYS3DMOD
333  envVarName = wxT( "KISYS3DMOD" );
334 
335  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
336  {
337  tmpFileName.AssignDir( envValue );
338  envVarItem.SetDefinedExternally( true );
339  }
340  else
341  {
342  tmpFileName.AppendDir( "packages3d" );
343  envVarItem.SetDefinedExternally( false );
344  }
345 
346  envVarItem.SetValue( tmpFileName.GetFullPath() );
347  m_local_env_vars[ envVarName ] = envVarItem;
348 
349  // KICAD_TEMPLATE_DIR
350  envVarName = "KICAD_TEMPLATE_DIR";
351 
352  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
353  {
354  tmpFileName.AssignDir( envValue );
355  envVarItem.SetDefinedExternally( true );
356  }
357  else
358  {
359  // Attempt to find the best default template path.
360  SEARCH_STACK bases;
361  SEARCH_STACK templatePaths;
362 
363  SystemDirsAppend( &bases );
364 
365  for( unsigned i = 0; i < bases.GetCount(); ++i )
366  {
367  wxFileName fn( bases[i], wxEmptyString );
368 
369  // Add KiCad template file path to search path list.
370  fn.AppendDir( "template" );
371 
372  // Only add path if exists and can be read by the user.
373  if( fn.DirExists() && fn.IsDirReadable() )
374  {
375  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
376  fn.GetPath() );
377  templatePaths.AddPaths( fn.GetPath() );
378  }
379  }
380 
381  if( templatePaths.IsEmpty() )
382  {
383  tmpFileName = baseSharePath;
384  tmpFileName.AppendDir( "template" );
385  }
386  else
387  {
388  // Take the first one. There may be more but this will likely be the best option.
389  tmpFileName.AssignDir( templatePaths[0] );
390  }
391 
392  envVarItem.SetDefinedExternally( false );
393  }
394 
395  envVarItem.SetValue( tmpFileName.GetPath() );
396  m_local_env_vars[ envVarName ] = envVarItem;
397 
398  // KICAD_USER_TEMPLATE_DIR
399  envVarName = "KICAD_USER_TEMPLATE_DIR";
400 
401  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
402  {
403  tmpFileName.AssignDir( envValue );
404  envVarItem.SetDefinedExternally( true );
405  }
406  else
407  {
408  // Default user template path.
409  tmpFileName.AssignDir( wxStandardPaths::Get().GetDocumentsDir() );
410  tmpFileName.AppendDir( "kicad" );
411  tmpFileName.AppendDir( "template" );
412  envVarItem.SetDefinedExternally( false );
413  }
414 
415  envVarItem.SetValue( tmpFileName.GetPath() );
416  m_local_env_vars[ envVarName ] = envVarItem;
417 
418  // KICAD_SYMBOLS
419  envVarName = wxT( "KICAD_SYMBOL_DIR" );
420 
421  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
422  {
423  tmpFileName.AssignDir( envValue );
424  envVarItem.SetDefinedExternally( true );
425  }
426  else
427  {
428  tmpFileName = baseSharePath;
429  tmpFileName.AppendDir( "library" );
430  envVarItem.SetDefinedExternally( false );
431  }
432 
433  envVarItem.SetValue( tmpFileName.GetPath() );
434  m_local_env_vars[ envVarName ] = envVarItem;
435 
436  ReadPdfBrowserInfos(); // needs m_common_settings
437 
438  // Init user language *before* calling loadCommonSettings, because
439  // env vars could be incorrectly initialized on Linux
440  // (if the value contains some non ASCII7 chars, the env var is not initialized)
441  SetLanguage( true );
442 
444 
445 #ifdef __WXMAC__
446  // Always show filters on Open dialog to be able to choose plugin
447  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
448 #endif
449 
450  return true;
451 }
void loadCommonSettings()
Function loadCommonSettings loads the program (process) settings subset which are stored in ....
Definition: pgm_base.cpp:496
wxString GetKicadLockFilePath()
Function GetKicadLockFilePath.
Definition: lockfile.cpp:59
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
Definition: common.cpp:231
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
ENV_VAR_ITEM.
Definition: pgm_base.h:107
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:146
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:454
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:369
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
#define KICAD_COMMON
Definition: pgm_base.cpp:60
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:379
#define NULL
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:119
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:741
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:633
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:376
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
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:101
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:125
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:110
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:280
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)

References _, SEARCH_STACK::AddPaths(), App(), Format(), GetChars(), GetKicadLockFilePath(), GetNewConfig(), IsOK(), KICAD_COMMON, loadCommonSettings(), m_bin_dir, m_common_settings, m_kicad_env, m_local_env_vars, m_pgm_checker, NULL, ReadPdfBrowserInfos(), ENV_VAR_ITEM::SetDefinedExternally(), setExecutablePath(), SetLanguage(), SetLanguagePath(), ENV_VAR_ITEM::SetValue(), SystemDirsAppend(), tracePathsAndFiles, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_KICAD::OnPgmInit().

◆ IsKicadEnvVariableDefined()

VTBL_ENTRY bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inline

Definition at line 218 of file pgm_base.h.

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

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Function loadCommonSettings loads the program (process) settings subset which are stored in .kicad_common.

Definition at line 496 of file pgm_base.cpp.

497 {
498  wxASSERT( m_common_settings );
499 
500  m_help_size.x = 500;
501  m_help_size.y = 400;
502 
503  // This only effect the first time KiCad is run. The user's setting will be used for all
504  // subsequent runs. Menu icons are off by default on OSX and on for all other platforms.
505 #if defined( __WXMAC__ )
506  bool defaultUseIconsInMenus = false;
507 #else
508  bool defaultUseIconsInMenus = true;
509 #endif
510 
512 
513  if( !m_common_settings->HasEntry( USE_ICONS_IN_MENUS_KEY ) )
514  m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
515 
516  if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
519  {
520  // 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
521  // options only in pcbnew (which was the only canvas to support them). Since there's
522  // no single right answer to where to pull the common settings from, we might as well
523  // get them along with the hardware antialiasing option from pcbnew.
524  auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
525  wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
526 
527  if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
528  {
529  int temp;
530  wxString msg;
531  bool option;
532 
533  pcbnewConfig->Read( "PcbIconScale", &temp, 0 );
534  m_common_settings->Write( ICON_SCALE_KEY, temp );
535 
536  pcbnewConfig->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
537  m_common_settings->Write( ENBL_MOUSEWHEEL_PAN_KEY, option );
538 
539  pcbnewConfig->Read( ENBL_ZOOM_NO_CENTER_KEY, &option, false );
540  m_common_settings->Write( ENBL_ZOOM_NO_CENTER_KEY, option );
541 
542  pcbnewConfig->Read( ENBL_AUTO_PAN_KEY, &option, true );
543  m_common_settings->Write( ENBL_AUTO_PAN_KEY, option );
544  }
545 
546  if( !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
547  {
548  int temp;
549  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + GAL_ANTIALIASING_MODE_KEY,
552  }
553 
555  {
556  int temp;
557  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + CAIRO_ANTIALIASING_MODE_KEY,
560  }
561  }
562 
563  m_editor_name = m_common_settings->Read( "Editor" );
564 
565  wxString entry, oldPath;
566  wxArrayString entries;
567  long index = 0L;
568 
569  oldPath = m_common_settings->GetPath();
571 
572  while( m_common_settings->GetNextEntry( entry, index ) )
573  {
574  wxLogTrace( traceEnvVars,
575  "Enumerating over entry %s, %ld.", GetChars( entry ), index );
576 
577  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
578  // it is found in config. (It is reserved and defined as project path)
579  if( entry == PROJECT_VAR_NAME )
580  continue;
581 
582  entries.Add( entry );
583  }
584 
585  for( unsigned i = 0; i < entries.GetCount(); i++ )
586  {
587  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
588 
589  if( m_local_env_vars[ entries[i] ].GetDefinedExternally() )
590  continue;
591 
592  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
593  }
594 
595  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
596  {
597  SetLocalEnvVariable( it->first, it->second.GetValue() );
598  }
599 
600  m_common_settings->SetPath( oldPath );
601 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:67
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
Definition: common.cpp:231
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
ENV_VAR_ITEM.
Definition: pgm_base.h:107
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:68
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:409
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:49
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:54
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:52
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:776
#define NULL
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:50
#define ICON_SCALE_KEY
Definition: pgm_base.h:46
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:55
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:101
wxSize m_help_size
Definition: pgm_base.h:403
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:45
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:56
wxString m_editor_name
Definition: pgm_base.h:402
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:137
#define PCB_EDIT_FRAME_NAME

References CAIRO_ANTIALIASING_MODE_KEY, ENBL_AUTO_PAN_KEY, ENBL_MOUSEWHEEL_PAN_KEY, ENBL_ZOOM_NO_CENTER_KEY, GAL_ANTIALIASING_MODE_KEY, GAL_DISPLAY_OPTIONS_KEY, GetChars(), GetNewConfig(), ICON_SCALE_KEY, m_common_settings, m_editor_name, m_help_size, m_local_env_vars, m_show_env_var_dialog, KIGFX::NONE, NULL, pathEnvVariables, PCB_EDIT_FRAME_NAME, PROJECT_VAR_NAME, SetLocalEnvVariable(), showEnvVarWarningDialog, traceEnvVars, and USE_ICONS_IN_MENUS_KEY.

Referenced by InitPgm().

◆ MacOpenFile()

VTBL_ENTRY void PGM_BASE::MacOpenFile ( const wxString &  aFileName)
pure virtual

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

Implemented in PGM_TEST_FRAME, PGM_MOCK_EESCHEMA_FRAME, PGM_SINGLE_TOP, PGM_KICAD, and PGM_TEST_FRAME.

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )

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

Definition at line 42 of file eda_doc.cpp.

43 {
44  wxASSERT( m_common_settings );
45 
46  wxString browser = m_common_settings->Read( wxT( "PdfBrowserName" ), wxEmptyString );
47  SetPdfBrowserName( browser );
48 
49  int tmp;
50  m_common_settings->Read( wxT( "UseSystemBrowser" ), &tmp, 0 );
51  m_use_system_pdf_browser = bool( tmp );
52 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
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:388
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:228

References m_common_settings, m_use_system_pdf_browser, and SetPdfBrowserName().

Referenced by InitPgm().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )

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

Definition at line 604 of file pgm_base.cpp.

605 {
606  // m_common_settings is not initialized until fairly late in the
607  // process startup: InitPgm(), so test before using:
608  if( m_common_settings )
609  {
610  wxString cur_dir = wxGetCwd();
611 
612  m_common_settings->Write( workingDirKey, cur_dir );
614 
615  // Save the local environment variables.
617 
618  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
619  {
620  if( it->second.GetDefinedExternally() )
621  continue;
622 
623  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
624  GetChars( it->first ), GetChars( it->second.GetValue() ) );
625  m_common_settings->Write( it->first, it->second.GetValue() );
626  }
627 
628  m_common_settings->SetPath( ".." );
629  }
630 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:67
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
static const wxChar workingDirKey[]
Definition: pgm_base.h:329
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:68
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:409
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:101
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:137

References GetChars(), m_common_settings, m_local_env_vars, m_show_env_var_dialog, pathEnvVariables, showEnvVarWarningDialog, traceEnvVars, and workingDirKey.

Referenced by PGM_KICAD::OnPgmExit(), PGM_SINGLE_TOP::OnPgmExit(), and SetLocalEnvVariables().

◆ SetEditorName()

void PGM_BASE::SetEditorName ( const wxString &  aFileName)

Definition at line 153 of file pgm_base.cpp.

154 {
155  m_editor_name = aFileName;
156  wxASSERT( m_common_settings );
157  m_common_settings->Write( "Editor", aFileName );
158 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
wxString m_editor_name
Definition: pgm_base.h:402

References m_common_settings, and m_editor_name.

Referenced by GetEditorName().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protected

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

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

References m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( bool  first_time = false)

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

634 {
635  bool retv = true;
636 
637  if( first_time )
638  {
639  setLanguageId( wxLANGUAGE_DEFAULT );
640  // First time SetLanguage is called, the user selected language id is set
641  // from commun user config settings
642  wxString languageSel;
643 
644  m_common_settings->Read( languageCfgKey, &languageSel );
645 
646  // Search for the current selection
647  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
648  {
649  if( LanguagesList[ii].m_Lang_Label == languageSel )
650  {
651  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
652  break;
653  }
654  }
655  }
656 
657  // dictionary file name without extend (full name is kicad.mo)
658  wxString dictionaryName( "kicad" );
659 
660  delete m_locale;
661  m_locale = new wxLocale;
662 
663  if( !m_locale->Init( m_language_id ) )
664  {
665  wxLogTrace( traceLocale, "This language is not supported by the system." );
666 
667  setLanguageId( wxLANGUAGE_DEFAULT );
668  delete m_locale;
669 
670  m_locale = new wxLocale;
671  m_locale->Init();
672  retv = false;
673  }
674  else if( !first_time )
675  {
676  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
677  GetChars( dictionaryName ), GetChars( m_locale->GetName() ) );
678  }
679 
680  if( !first_time )
681  {
682  // If we are here, the user has selected another language.
683  // Therefore the new prefered language name is stored in common config.
684  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
685  // versions, for a given language
686  wxString languageSel;
687 
688  // Search for the current selection language name
689  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
690  {
691  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
692  {
693  languageSel = LanguagesList[ii].m_Lang_Label;
694  break;
695  }
696  }
697 
698  m_common_settings->Write( languageCfgKey, languageSel );
699  }
700 
701  // Test if floating point notation is working (bug encountered in cross compilation)
702  // Make a conversion double <=> string
703  double dtst = 0.5;
704  wxString msg;
705 
706  msg << dtst;
707  double result;
708  msg.ToDouble( &result );
709 
710  if( result != dtst )
711  // string to double encode/decode does not work! Bug detected:
712  // Disable floating point localization:
713  setlocale( LC_NUMERIC, "C" );
714 
715  if( !m_locale->IsLoaded( dictionaryName ) )
716  m_locale->AddCatalog( dictionaryName );
717 
718  if( !retv )
719  return retv;
720 
721  return m_locale->IsOk();
722 }
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:80
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:382
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:83
int m_language_id
The current language setting.
Definition: pgm_base.h:385
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:391
const wxChar *const traceLocale
Flag to enable locale debug output.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:89
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:101
static const wxChar languageCfgKey[]
Definition: pgm_base.cpp:66

References GetChars(), languageCfgKey, LanguagesList, m_common_settings, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, m_language_id, m_locale, setLanguageId(), and traceLocale.

Referenced by InitPgm().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotected

Trap all changes in here, simplifies debugging.

Definition at line 391 of file pgm_base.h.

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

References m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::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).

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

Definition at line 725 of file pgm_base.cpp.

726 {
727  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
728  menu_id, (int)arrayDim( LanguagesList )-1 );
729 
730  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
731  {
732  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
733  {
734  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
735  break;
736  }
737  }
738 }
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:80
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:83
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:391
const wxChar *const traceLocale
Flag to enable locale debug output.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )

Definition at line 741 of file pgm_base.cpp.

742 {
743  SEARCH_STACK guesses;
744 
745  SystemDirsAppend( &guesses );
746 
747  // Add our internat dir to the wxLocale catalog of paths
748  for( unsigned i = 0; i < guesses.GetCount(); i++ )
749  {
750  wxFileName fn( guesses[i], wxEmptyString );
751 
752  // Append path for Windows and unix KiCad package install
753  fn.AppendDir( "share" );
754  fn.AppendDir( "internat" );
755 
756  if( fn.IsDirReadable() )
757  {
758  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
759  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
760  }
761 
762  // Append path for unix standard install
763  fn.RemoveLastDir();
764  fn.AppendDir( "kicad" );
765  fn.AppendDir( "internat" );
766 
767  if( fn.IsDirReadable() )
768  {
769  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
770  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
771  }
772  }
773 }
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 InitPgm().

◆ SetLocalEnvVariable()

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

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

777 {
778  wxString env;
779 
780  // Check to see if the environment variable is already set.
781  if( wxGetEnv( aName, &env ) )
782  {
783  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
784  GetChars( aName ), GetChars( env ) );
785  return env == aValue;
786  }
787 
788  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
789  GetChars( aName ), GetChars( aValue ) );
790 
791  return wxSetEnv( aName, aValue );
792 }
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
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:101

References GetChars(), and traceEnvVars.

Referenced by loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)

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

796 {
797  m_local_env_vars.clear();
798  m_local_env_vars = aEnvVarMap;
799 
800  if( m_common_settings )
801  m_common_settings->DeleteGroup( pathEnvVariables );
802 
804 
805  // Overwrites externally defined environment variable until the next time the application
806  // is run.
807  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
808  {
809  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
810  GetChars( it->first ), GetChars( it->second.GetValue() ) );
811  wxSetEnv( it->first, it->second.GetValue() );
812  }
813 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:67
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:406
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:604
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
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:101
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:137

References GetChars(), m_common_settings, m_local_env_vars, pathEnvVariables, SaveCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

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

Definition at line 228 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ UseSystemPdfBrowser()

VTBL_ENTRY bool PGM_BASE::UseSystemPdfBrowser ( ) const
inline

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 236 of file pgm_base.h.

237  {
238  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
239  }
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:388
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:401

References m_pdf_browser, and m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )

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

Definition at line 55 of file eda_doc.cpp.

56 {
57  wxASSERT( m_common_settings );
58 
59  m_common_settings->Write( wxT( "PdfBrowserName" ), GetPdfBrowserName() );
60  m_common_settings->Write( wxT( "UseSystemBrowser" ), m_use_system_pdf_browser );
61 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:373
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:388
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:226

References GetPdfBrowserName(), m_common_settings, and m_use_system_pdf_browser.

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protected

full path to this program

Definition at line 376 of file pgm_base.h.

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

◆ m_common_settings

std::unique_ptr<wxConfigBase> PGM_BASE::m_common_settings
protected

Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.

Definition at line 373 of file pgm_base.h.

Referenced by CommonSettings(), Destroy(), InitPgm(), loadCommonSettings(), ReadPdfBrowserInfos(), SaveCommonSettings(), SetEditorName(), SetLanguage(), SetLocalEnvVariables(), and WritePdfBrowserInfos().

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protected

Definition at line 402 of file pgm_base.h.

Referenced by GetEditorName(), loadCommonSettings(), and SetEditorName().

◆ m_help_size

wxSize PGM_BASE::m_help_size
protected

Definition at line 403 of file pgm_base.h.

Referenced by loadCommonSettings().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protected

The KICAD system environment variable.

Definition at line 379 of file pgm_base.h.

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

◆ m_language_id

int PGM_BASE::m_language_id
protected

The current language setting.

Definition at line 385 of file pgm_base.h.

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

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protected

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

Definition at line 406 of file pgm_base.h.

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

◆ m_locale

wxLocale* PGM_BASE::m_locale
protected

The current locale.

Definition at line 382 of file pgm_base.h.

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

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protected

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

Definition at line 401 of file pgm_base.h.

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

◆ m_pgm_checker

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protected

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

Definition at line 369 of file pgm_base.h.

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

◆ m_Printing

bool PGM_BASE::m_Printing

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

Definition at line 358 of file pgm_base.h.

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

◆ m_show_env_var_dialog

bool PGM_BASE::m_show_env_var_dialog
protected

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

Definition at line 409 of file pgm_base.h.

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

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protected

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

Definition at line 388 of file pgm_base.h.

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

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey = wxT( "WorkingDir" )
static

Definition at line 329 of file pgm_base.h.

Referenced by SaveCommonSettings().


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