KiCad PCB EDA Suite
PGM_KICAD Class Reference

Class 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...
 
FILE_HISTORYGetFileHistory ()
 
wxConfigBase * PgmSettings ()
 
SEARCH_STACKSysSearch ()
 
wxString GetHelpFileName ()
 
void Destroy ()
 
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 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

BIN_MOD m_bm
 
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

Class 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 40 of file pgm_kicad.h.

Constructor & Destructor Documentation

◆ PGM_KICAD()

PGM_KICAD::PGM_KICAD ( )
inline

Definition at line 43 of file pgm_kicad.h.

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

◆ ~PGM_KICAD()

PGM_KICAD::~PGM_KICAD ( )
throw (
)
inline

Definition at line 47 of file pgm_kicad.h.

48  {
49  Destroy();
50  }
void Destroy()
Definition: kicad.cpp:194

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

165 {
166  wxASSERT( wxTheApp );
167  return *wxTheApp;
168 }

Referenced by WS_DRAW_ITEM_LIST::BuildFullText(), DIALOG_SHIM::DIALOG_SHIM(), PGM_BASE::InitPgm(), MacOpenFile(), PGM_SINGLE_TOP::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 216 of file pgm_base.cpp.

217 {
218  // Create a mask representing the executable files in the current platform
219 #ifdef __WINDOWS__
220  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
221 #else
222  wxString mask( _( "Executable file (*)|*" ) );
223 #endif
224 
225  // Extract the path, name and extension from the default editor (even if the editor's
226  // name was empty, this method will succeed and return empty strings).
227  wxString path, name, ext;
228  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
229 
230  // Show the modal editor and return the file chosen (may be empty if the user cancels
231  // the dialog).
232  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
233  name, ext, mask,
234  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
235  true );
236 }
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:82
const char * name
Definition: DXF_plotter.cpp:61
#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(), and name.

Referenced by PGM_BASE::GetEditorName(), and PANEL_COMMON_SETTINGS::OnTextEditorClick().

◆ CommonSettings()

◆ Destroy()

void PGM_KICAD::Destroy ( )

Definition at line 194 of file kicad.cpp.

195 {
196  // unlike a normal destructor, this is designed to be called more
197  // than once safely:
198 
199  m_bm.End();
200 
202 }
void Destroy()
Definition: pgm_base.cpp:151
BIN_MOD m_bm
Definition: pgm_kicad.h:72
void End()
Definition: bin_mod.cpp:63

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

255 { 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:398

References PGM_BASE::m_use_system_pdf_browser.

Referenced by PGM_BASE::PGM_BASE(), and PANEL_COMMON_SETTINGS::TransferDataFromWindow().

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

180 {
181  wxString editorname = m_editor_name;
182 
183  if( !editorname )
184  {
185  if( !wxGetEnv( "EDITOR", &editorname ) )
186  {
187  // If there is no EDITOR variable set, try the desktop default
188 #ifdef __WXMAC__
189  editorname = "/usr/bin/open";
190 #elif __WXX11__
191  editorname = "/usr/bin/xdg-open";
192 #endif
193  }
194  }
195 
196  // If we still don't have an editor name show a dialog asking the user to select one
197  if( !editorname && aCanShowFileChooser )
198  {
199  DisplayInfoMessage( NULL,
200  _( "No default editor found, you must choose it" ) );
201 
202  editorname = AskUserForPreferredEditor();
203  }
204 
205  // If we finally have a new editor name request it to be copied to m_editor_name and
206  // saved to the preferences file.
207  if( !editorname.IsEmpty() )
208  SetEditorName( editorname );
209 
210  // m_editor_name already has the same value that editorname, or empty if no editor was
211  // found/chosen.
212  return m_editor_name;
213 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:171
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:216
#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:412
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:276

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

Referenced by KICAD_MANAGER_CONTROL::Execute(), DIALOG_CONFIG_EQUFILES::OnEditEquFile(), DIALOG_BOM::OnEditGenerator(), KICAD_MANAGER_FRAME::OnOpenFileInTextEditor(), TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor(), and GERBVIEW_FRAME::OnShowGerberSourceFile().

◆ GetExecutablePath()

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

◆ GetFileHistory()

FILE_HISTORY& PGM_KICAD::GetFileHistory ( )
inline

◆ GetHelpFileName()

wxString PGM_KICAD::GetHelpFileName ( )
inline

Definition at line 63 of file pgm_kicad.h.

63 { return m_bm.m_help_file; }
wxString m_help_file
Definition: bin_mod.h:61
BIN_MOD m_bm
Definition: pgm_kicad.h:72

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

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

References PGM_BASE::m_kicad_env.

Referenced by FindKicadFile(), and KicadDatasPath().

◆ GetLocale()

VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inlineinherited

Definition at line 234 of file pgm_base.h.

234 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:392

References PGM_BASE::m_locale.

Referenced by TEMPLATE_FIELDNAME::GetDefaultFieldName(), LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT(), and SearchHelpFileFullPath().

◆ GetLocalEnvVariables()

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

◆ GetPdfBrowserName()

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

Definition at line 236 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PANEL_COMMON_SETTINGS::OnPDFViewerClick(), OpenPDF(), and 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 282 of file pgm_base.h.

282 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:395

References PGM_BASE::m_language_id.

Referenced by AddMenuLanguageList().

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

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

References _, SEARCH_STACK::AddPaths(), PGM_BASE::App(), Format(), GetChars(), GetKicadLockFilePath(), GetNewConfig(), i, IsOK(), KICAD_COMMON, PGM_BASE::loadCommonSettings(), PGM_BASE::m_bin_dir, PGM_BASE::m_common_settings, PGM_BASE::m_kicad_env, PGM_BASE::m_local_env_vars, PGM_BASE::m_pgm_checker, 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 228 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

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

Definition at line 514 of file pgm_base.cpp.

515 {
516  wxASSERT( m_common_settings );
517 
518  m_help_size.x = 500;
519  m_help_size.y = 400;
520 
521  // This only effect the first time KiCad is run. The user's setting will be used for all
522  // subsequent runs. Menu icons are off by default on OSX and on for all other platforms.
523 #if defined( __WXMAC__ )
524  bool defaultUseIconsInMenus = false;
525 #else
526  bool defaultUseIconsInMenus = true;
527 #endif
528 
530 
531  if( !m_common_settings->HasEntry( USE_ICONS_IN_MENUS_KEY ) )
532  m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
533 
534  if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
537  {
538  // 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
539  // options only in pcbnew (which was the only canvas to support them). Since there's
540  // no single right answer to where to pull the common settings from, we might as well
541  // get them along with the hardware antialiasing option from pcbnew.
542  auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
543  wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
544 
545  if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
546  {
547  int temp;
548  wxString msg;
549  bool option;
550 
551  pcbnewConfig->Read( "PcbIconScale", &temp, 0 );
552  m_common_settings->Write( ICON_SCALE_KEY, temp );
553 
554  pcbnewConfig->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
555  m_common_settings->Write( ENBL_MOUSEWHEEL_PAN_KEY, option );
556 
557  pcbnewConfig->Read( ENBL_ZOOM_NO_CENTER_KEY, &option, false );
558  m_common_settings->Write( ENBL_ZOOM_NO_CENTER_KEY, option );
559 
560  pcbnewConfig->Read( ENBL_AUTO_PAN_KEY, &option, true );
561  m_common_settings->Write( ENBL_AUTO_PAN_KEY, option );
562  }
563 
564  if( !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
565  {
566  int temp;
567  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + GAL_ANTIALIASING_MODE_KEY,
570  }
571 
573  {
574  int temp;
575  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + CAIRO_ANTIALIASING_MODE_KEY,
578  }
579  }
580 
581  m_editor_name = m_common_settings->Read( "Editor" );
582 
583  wxString entry, oldPath;
584  wxArrayString entries;
585  long index = 0L;
586 
587  oldPath = m_common_settings->GetPath();
589 
590  while( m_common_settings->GetNextEntry( entry, index ) )
591  {
592  wxLogTrace( traceEnvVars,
593  "Enumerating over entry %s, %ld.", GetChars( entry ), index );
594 
595  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
596  // it is found in config. (It is reserved and defined as project path)
597  if( entry == PROJECT_VAR_NAME )
598  continue;
599 
600  entries.Add( entry );
601  }
602 
603  for( unsigned i = 0; i < entries.GetCount(); i++ )
604  {
605  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
606 
607  if( m_local_env_vars[ entries[i] ].GetDefinedExternally() )
608  continue;
609 
610  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
611  }
612 
613  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
614  {
615  SetLocalEnvVariable( it->first, it->second.GetValue() );
616  }
617 
618  m_common_settings->SetPath( oldPath );
619 }
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:416
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:256
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:383
Class ENV_VAR_ITEM.
Definition: pgm_base.h:117
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:419
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:50
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:55
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:53
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:794
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:51
#define ICON_SCALE_KEY
Definition: pgm_base.h:47
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:56
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:413
size_t i
Definition: json11.cpp:597
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:46
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:57
wxString m_editor_name
Definition: pgm_base.h:412
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:147
#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(), i, ICON_SCALE_KEY, PGM_BASE::m_common_settings, PGM_BASE::m_editor_name, PGM_BASE::m_help_size, PGM_BASE::m_local_env_vars, PGM_BASE::m_show_env_var_dialog, KIGFX::NONE, pathEnvVariables, PCB_EDIT_FRAME_NAME, PROJECT_VAR_NAME, PGM_BASE::SetLocalEnvVariable(), showEnvVarWarningDialog, traceEnvVars, and USE_ICONS_IN_MENUS_KEY.

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 181 of file kicad.cpp.

182 {
183 #if defined(__WXMAC__)
184 
185  KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
186 
187  if( !aFileName.empty() && wxFileExists( aFileName ) )
188  frame->LoadProject( wxFileName( aFileName ) );
189 
190 #endif
191 }
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:164
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 168 of file kicad.cpp.

169 {
170  Kiway.OnKiwayEnd();
171 
173 
174  // write common settings to disk, and destroy everything in PGM_KICAD,
175  // especially wxSingleInstanceCheckerImpl earlier than wxApp and earlier
176  // than static destruction would.
177  Destroy();
178 }
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:622
void OnKiwayEnd()
Definition: kiway.cpp:517
void Destroy()
Definition: kicad.cpp:194
KIWAY Kiway

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

Referenced by APP_KICAD::OnExit().

◆ OnPgmInit()

bool PGM_KICAD::OnPgmInit ( )

Definition at line 77 of file kicad.cpp.

78 {
79 #if defined(DEBUG)
80  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
81 
82  if( !wxIsAbsolutePath( absoluteArgv0 ) )
83  {
84  wxLogError( wxT( "No meaningful argv[0]" ) );
85  return false;
86  }
87 #endif
88 
89  if( !InitPgm() )
90  return false;
91 
92  m_bm.Init();
93 
94  // Add search paths to feed the PGM_KICAD::SysSearch() function,
95  // currenly limited in support to only look for project templates
96  {
97  SEARCH_STACK bases;
98 
99  SystemDirsAppend( &bases );
100 
101  for( unsigned i = 0; i < bases.GetCount(); ++i )
102  {
103  wxFileName fn( bases[i], wxEmptyString );
104 
105  // Add KiCad template file path to search path list.
106  fn.AppendDir( wxT( "template" ) );
107 
108  // Only add path if exists and can be read by the user.
109  if( fn.DirExists() && fn.IsDirReadable() )
110  m_bm.m_search.AddPaths( fn.GetPath() );
111  }
112 
113  // The KICAD_TEMPLATE_DIR takes precedence over the search stack template path.
114  ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD_TEMPLATE_DIR" );
115 
116  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
117  m_bm.m_search.Insert( it->second.GetValue(), 0 );
118 
119  // The KICAD_USER_TEMPLATE_DIR takes precedence over KICAD_TEMPLATE_DIR and the search
120  // stack template path.
121  it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
122 
123  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
124  m_bm.m_search.Insert( it->second.GetValue(), 0 );
125  }
126 
127  KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
128  wxDefaultPosition, wxSize( 775, -1 ) );
129  App().SetTopWindow( frame );
130 
131  Kiway.SetTop( frame );
132 
133  wxString projToLoad;
134 
135  if( App().argc > 1 )
136  {
137  projToLoad = App().argv[1];
138  }
139  else if( GetFileHistory().GetCount() )
140  {
141  wxString last_pro = GetFileHistory().GetHistoryFile( 0 );
142 
143  if( !wxFileExists( last_pro ) )
144  {
145  GetFileHistory().RemoveFileFromHistory( 0 );
146  }
147  else
148  {
149  // Try to open the last opened project,
150  // if a project name is not given when starting Kicad
151  projToLoad = last_pro;
152  }
153  }
154 
155  // Do not attempt to load a non-existent project file.
156  if( !projToLoad.empty() && wxFileExists( projToLoad ) )
157  {
158  frame->LoadProject( projToLoad );
159  }
160 
161  frame->Show( true );
162  frame->Raise();
163 
164  return true;
165 }
FILE_HISTORY & GetFileHistory()
Definition: pgm_kicad.h:57
void Init()
Definition: bin_mod.cpp:38
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:164
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
Definition: pgm_base.h:148
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:325
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:77
SEARCH_STACK m_search
Definition: bin_mod.h:63
BIN_MOD m_bm
Definition: pgm_kicad.h:72
size_t i
Definition: json11.cpp:597
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:239
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(), GetFileHistory(), PGM_BASE::GetLocalEnvVariables(), i, BIN_MOD::Init(), PGM_BASE::InitPgm(), Kiway, KICAD_MANAGER_FRAME::LoadProject(), m_bm, BIN_MOD::m_search, KIWAY::SetTop(), and SystemDirsAppend().

Referenced by APP_KICAD::OnInit().

◆ PgmSettings()

wxConfigBase* PGM_KICAD::PgmSettings ( )
inline

Definition at line 59 of file pgm_kicad.h.

59 { return m_bm.m_config.get(); }
BIN_MOD m_bm
Definition: pgm_kicad.h:72
std::unique_ptr< wxConfigBase > m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:59

References m_bm, and BIN_MOD::m_config.

Referenced by KICAD_MANAGER_FRAME::config().

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
inherited

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:383
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:398
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:238

References PGM_BASE::m_common_settings, PGM_BASE::m_use_system_pdf_browser, and PGM_BASE::SetPdfBrowserName().

Referenced by PGM_BASE::InitPgm(), PANEL_COMMON_SETTINGS::OnPDFViewerClick(), and OpenPDF().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )
inherited

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

Definition at line 622 of file pgm_base.cpp.

623 {
624  // m_common_settings is not initialized until fairly late in the
625  // process startup: InitPgm(), so test before using:
626  if( m_common_settings )
627  {
628  wxString cur_dir = wxGetCwd();
629 
630  m_common_settings->Write( workingDirKey, cur_dir );
632 
633  // Save the local environment variables.
635 
636  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
637  {
638  if( it->second.GetDefinedExternally() )
639  continue;
640 
641  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
642  GetChars( it->first ), GetChars( it->second.GetValue() ) );
643  m_common_settings->Write( it->first, it->second.GetValue() );
644  }
645 
646  m_common_settings->SetPath( ".." );
647  }
648 }
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:416
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:383
static const wxChar workingDirKey[]
Definition: pgm_base.h:339
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:419
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:147

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

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

◆ SetEditorName()

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

Definition at line 171 of file pgm_base.cpp.

172 {
173  m_editor_name = aFileName;
174  wxASSERT( m_common_settings );
175  m_common_settings->Write( "Editor", aFileName );
176 }
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:383
wxString m_editor_name
Definition: pgm_base.h:412

References PGM_BASE::m_common_settings, and PGM_BASE::m_editor_name.

Referenced by PGM_BASE::GetEditorName(), and PANEL_COMMON_SETTINGS::TransferDataFromWindow().

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

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

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

652 {
653  bool retv = true;
654 
655  if( first_time )
656  {
657  setLanguageId( wxLANGUAGE_DEFAULT );
658  // First time SetLanguage is called, the user selected language id is set
659  // from commun user config settings
660  wxString languageSel;
661 
662  m_common_settings->Read( languageCfgKey, &languageSel );
663 
664  // Search for the current selection
665  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
666  {
667  if( LanguagesList[ii].m_Lang_Label == languageSel )
668  {
669  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
670  break;
671  }
672  }
673  }
674 
675  // dictionary file name without extend (full name is kicad.mo)
676  wxString dictionaryName( "kicad" );
677 
678  delete m_locale;
679  m_locale = new wxLocale;
680 
681  if( !m_locale->Init( m_language_id ) )
682  {
683  wxLogTrace( traceLocale, "This language is not supported by the system." );
684 
685  setLanguageId( wxLANGUAGE_DEFAULT );
686  delete m_locale;
687 
688  m_locale = new wxLocale;
689  m_locale->Init();
690  retv = false;
691  }
692  else if( !first_time )
693  {
694  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
695  GetChars( dictionaryName ), GetChars( m_locale->GetName() ) );
696  }
697 
698  if( !first_time )
699  {
700  // If we are here, the user has selected another language.
701  // Therefore the new prefered language name is stored in common config.
702  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
703  // versions, for a given language
704  wxString languageSel;
705 
706  // Search for the current selection language name
707  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
708  {
709  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
710  {
711  languageSel = LanguagesList[ii].m_Lang_Label;
712  break;
713  }
714  }
715 
716  m_common_settings->Write( languageCfgKey, languageSel );
717  }
718 
719  // Test if floating point notation is working (bug encountered in cross compilation)
720  // Make a conversion double <=> string
721  double dtst = 0.5;
722  wxString msg;
723 
724  msg << dtst;
725  double result;
726  msg.ToDouble( &result );
727 
728  if( result != dtst )
729  // string to double encode/decode does not work! Bug detected:
730  // Disable floating point localization:
731  setlocale( LC_NUMERIC, "C" );
732 
733  if( !m_locale->IsLoaded( dictionaryName ) )
734  m_locale->AddCatalog( dictionaryName );
735 
736  if( !retv )
737  return retv;
738 
739  return m_locale->IsOk();
740 }
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:383
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:392
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:84
int m_language_id
The current language setting.
Definition: pgm_base.h:395
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:401
const wxChar *const traceLocale
Flag to enable locale debug output.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:90
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, PGM_BASE::m_common_settings, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, PGM_BASE::m_language_id, PGM_BASE::m_locale, PGM_BASE::setLanguageId(), and traceLocale.

Referenced by PGM_BASE::InitPgm(), and KIWAY::SetLanguage().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotectedinherited

Trap all changes in here, simplifies debugging.

Definition at line 401 of file pgm_base.h.

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

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

744 {
745  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
746  menu_id, (int)arrayDim( LanguagesList )-1 );
747 
748  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
749  {
750  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
751  {
752  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
753  break;
754  }
755  }
756 }
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:84
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:401
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, PGM_BASE::setLanguageId(), and traceLocale.

Referenced by KIWAY::SetLanguage().

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
inherited

Definition at line 759 of file pgm_base.cpp.

760 {
761  SEARCH_STACK guesses;
762 
763  SystemDirsAppend( &guesses );
764 
765  // Add our internat dir to the wxLocale catalog of paths
766  for( unsigned i = 0; i < guesses.GetCount(); i++ )
767  {
768  wxFileName fn( guesses[i], wxEmptyString );
769 
770  // Append path for Windows and unix KiCad package install
771  fn.AppendDir( "share" );
772  fn.AppendDir( "internat" );
773 
774  if( fn.IsDirReadable() )
775  {
776  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
777  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
778  }
779 
780  // Append path for unix standard install
781  fn.RemoveLastDir();
782  fn.AppendDir( "kicad" );
783  fn.AppendDir( "internat" );
784 
785  if( fn.IsDirReadable() )
786  {
787  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
788  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
789  }
790  }
791 }
Class 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.
size_t i
Definition: json11.cpp:597

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

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

814 {
815  m_local_env_vars.clear();
816  m_local_env_vars = aEnvVarMap;
817 
818  if( m_common_settings )
819  m_common_settings->DeleteGroup( pathEnvVariables );
820 
822 
823  // Overwrites externally defined environment variable until the next time the application
824  // is run.
825  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
826  {
827  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
828  GetChars( it->first ), GetChars( it->second.GetValue() ) );
829  wxSetEnv( it->first, it->second.GetValue() );
830  }
831 }
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:416
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:622
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:383
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:147

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

Referenced by DIALOG_CONFIGURE_PATHS::TransferDataFromWindow().

◆ SetPdfBrowserName()

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

Definition at line 238 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos(), and PANEL_COMMON_SETTINGS::TransferDataFromWindow().

◆ SysSearch()

SEARCH_STACK& PGM_KICAD::SysSearch ( )
inline

Definition at line 61 of file pgm_kicad.h.

61 { return m_bm.m_search; }
SEARCH_STACK m_search
Definition: bin_mod.h:63
BIN_MOD m_bm
Definition: pgm_kicad.h:72

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

247  {
248  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
249  }
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:398
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:411

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 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:383
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:398
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:236

References PGM_BASE::GetPdfBrowserName(), PGM_BASE::m_common_settings, and PGM_BASE::m_use_system_pdf_browser.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protectedinherited

full path to this program

Definition at line 386 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 72 of file pgm_kicad.h.

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

◆ m_common_settings

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

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protectedinherited

◆ m_help_size

wxSize PGM_BASE::m_help_size
protectedinherited

Definition at line 413 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 389 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 395 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 416 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 392 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 411 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 379 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 368 of file pgm_base.h.

Referenced by DIALOG_PRINT_GENERIC::onPrintButtonClick(), PGM_BASE::PGM_BASE(), and DIALOG_PRINT_USING_PRINTER::TransferDataFromWindow().

◆ 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 419 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 398 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 = wxT( "WorkingDir" )
staticinherited

Definition at line 339 of file pgm_base.h.

Referenced by PGM_BASE::SaveCommonSettings().


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