KiCad PCB EDA Suite
PGM_SINGLE_TOP Struct Reference

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

Inheritance diagram for PGM_SINGLE_TOP:
PGM_BASE

Public Member Functions

bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 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 AddMenuLanguageList (wxMenu *MasterMenu)
 Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to MasterMenu. 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 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 void ConfigurePaths (wxWindow *aParent=NULL)
 Function ConfigurePaths. More...
 
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...
 
void SetIconsScale (double aValue)
 Scaling factor for menus and tool icons. More...
 
double GetIconsScale ()
 
void SetUseIconsInMenus (bool aUseIcons)
 True to use menu icons. More...
 
bool GetUseIconsInMenus ()
 

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...
 
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...
 
double m_iconsScale
 Scaling factor for menus and tool icons. More...
 
bool m_useIconsInMenus
 True to use menu icons. 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

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

Definition at line 61 of file single_top.cpp.

Member Function Documentation

void PGM_BASE::AddMenuLanguageList ( wxMenu *  MasterMenu)
inherited

Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to MasterMenu.

Parameters
MasterMenuThe main menu. The sub menu list will be accessible from the menu item with id ID_LANGUAGE_CHOICE

Definition at line 795 of file pgm_base.cpp.

References AddMenuItem(), DIM, ID_LANGUAGE_CHOICE, KiBitmap(), LANGUAGE_DESCR::m_Lang_Label, and PGM_BASE::m_language_id.

Referenced by preparePreferencesMenu(), CVPCB_MAINFRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), and GERBVIEW_FRAME::ReCreateMenuBar().

796 {
797  wxMenu* menu = NULL;
798  wxMenuItem* item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
799 
800  if( item ) // This menu exists, do nothing
801  return;
802 
803  menu = new wxMenu;
804 
805  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
806  {
807  wxString label;
808 
809  if( s_Languages[ii].m_DoNotTranslate )
810  label = s_Languages[ii].m_Lang_Label;
811  else
812  label = wxGetTranslation( s_Languages[ii].m_Lang_Label );
813 
814  AddMenuItem( menu, s_Languages[ii].m_KI_Lang_Identifier,
815  label, KiBitmap(s_Languages[ii].m_Lang_Icon ),
816  wxITEM_CHECK );
817  }
818 
819  AddMenuItem( MasterMenu, menu,
821  _( "Language" ),
822  _( "Select application language (only for testing!)" ),
823  KiBitmap( language_xpm ) );
824 
825  // Set Check mark on current selected language
826  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
827  {
828  if( m_language_id == s_Languages[ii].m_WX_Lang_Identifier )
829  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );
830  else
831  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, false );
832  }
833 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
int m_language_id
The current language setting.
Definition: pgm_base.h:356
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.cpp:92
static LANGUAGE_DESCR s_Languages[]
Variable s_Languages Note: because this list is not created on the fly, wxTranslation must be called ...
Definition: pgm_base.cpp:105
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 321 of file pgm_base.cpp.

Referenced by WS_DRAW_ITEM_LIST::BuildFullText(), DIALOG_SHIM::DIALOG_SHIM(), PCB_EDIT_FRAME::DoGenFootprintsPositionFile(), PCB_EDIT_FRAME::DoGenFootprintsReport(), PGM_BASE::InitPgm(), PGM_KICAD::MacOpenFile(), MacOpenFile(), PGM_KICAD::OnPgmInit(), and OnPgmInit().

322 {
323  wxASSERT( wxTheApp );
324  return *wxTheApp;
325 }
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 373 of file pgm_base.cpp.

References EDA_FILE_SELECTOR().

Referenced by PGM_BASE::GetEditorName(), and EDA_BASE_FRAME::OnSelectPreferredEditor().

374 {
375  // Create a mask representing the executable files in the current platform
376 #ifdef __WINDOWS__
377  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
378 #else
379  wxString mask( _( "Executable file (*)|*" ) );
380 #endif
381 
382  // Extract the path, name and extension from the default editor (even if the editor's
383  // name was empty, this method will succeed and return empty strings).
384  wxString path, name, ext;
385  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
386 
387  // Show the modal editor and return the file chosen (may be empty if the user cancels
388  // the dialog).
389  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
390  name, ext, mask,
391  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
392  true );
393 }
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
void PGM_BASE::ConfigurePaths ( wxWindow *  aParent = NULL)
inherited

Function ConfigurePaths.

presents a dialog to the user to edit local environment variable settings for use in the footprint library table and the 3D model importer. It was added to PGM_BASE because it will eventually find use for in schematic I/O design so it needs to accessible by almost every KiCad application.

Parameters
aParent- a pointer the wxWindow parent of the dialog or NULL to use the top level window.

Definition at line 876 of file pgm_base.cpp.

References DIALOG_ENV_VAR_CONFIG::ExternalDefsChanged(), GetChars(), DIALOG_ENV_VAR_CONFIG::GetEnvVarMap(), PGM_BASE::GetLocalEnvVariables(), PGM_BASE::m_show_env_var_dialog, PGM_BASE::SetLocalEnvVariables(), and traceEnvVars.

Referenced by DLG_3D_PATH_CONFIG::OnConfigEnvVar(), CVPCB_MAINFRAME::OnConfigurePaths(), FOOTPRINT_EDIT_FRAME::OnConfigurePaths(), KICAD_MANAGER_FRAME::OnConfigurePaths(), and PCB_EDIT_FRAME::OnConfigurePaths().

877 {
878  DIALOG_ENV_VAR_CONFIG dlg_envvars( aParent, GetLocalEnvVariables() );
879 
880  if( dlg_envvars.ShowModal() == wxID_CANCEL )
881  return;
882 
883  ENV_VAR_MAP envVarMap = dlg_envvars.GetEnvVarMap();
884 
885  for( ENV_VAR_MAP_ITER it = envVarMap.begin(); it != envVarMap.end(); ++it )
886  {
887  wxLogTrace( traceEnvVars, wxT( "Environment variable %s=%s defined externally = %d" ),
888  GetChars( it->first ), GetChars( it->second.GetValue() ),
889  it->second.GetDefinedExternally() );
890  }
891 
892  // If any of the environment variables are defined externally, warn the user that the
893  // next time kicad is run that the externally defined variables will be used instead of
894  // the user's settings. This is by design.
895  if( dlg_envvars.ExternalDefsChanged() && m_show_env_var_dialog )
896  {
897  wxString msg1 = _( "Warning! Some of paths you have configured have been defined \n"
898  "externally to the running process and will be temporarily overwritten." );
899  wxString msg2 = _( "The next time KiCad is launched, any paths that have already\n"
900  "been defined are honored and any settings defined in the path\n"
901  "configuration dialog are ignored. If you did not intend for this\n"
902  "behavior, either rename any conflicting entries or remove the\n"
903  "external environment variable definition(s) from your system." );
904  wxRichMessageDialog dlg( aParent, msg1, _( "Warning" ), wxOK | wxCENTRE );
905  dlg.ShowDetailedText( msg2 );
906  dlg.ShowCheckBox( _( "Do not show this message again." ) );
907  dlg.ShowModal();
908  m_show_env_var_dialog = !dlg.IsCheckBoxChecked();
909  }
910 
911  SetLocalEnvVariables( dlg_envvars.GetEnvVarMap() );
912 }
static const wxChar traceEnvVars[]
enable/disable icons in menus
Definition: pgm_base.cpp:67
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:385
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:270
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
Definition: pgm_base.h:87
DIALOG_ENV_VAR_CONFIG class declaration.
VTBL_ENTRY void SetLocalEnvVariables(const ENV_VAR_MAP &aEnvVarMap)
Function SetLocalEnvVariables.
Definition: pgm_base.cpp:855
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:92
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:88
void PGM_BASE::Destroy ( )
inherited

Definition at line 306 of file pgm_base.cpp.

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

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

307 {
308  // unlike a normal destructor, this is designed to be called more than once safely:
309 
310  delete m_common_settings;
311  m_common_settings = 0;
312 
313  delete m_pgm_checker;
314  m_pgm_checker = 0;
315 
316  delete m_locale;
317  m_locale = 0;
318 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:353
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:340
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
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 196 of file pgm_base.h.

References PGM_BASE::m_use_system_pdf_browser.

Referenced by KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser(), KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser(), and PGM_BASE::PGM_BASE().

196 { 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:359
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 336 of file pgm_base.cpp.

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

Referenced by TREEPROJECT_ITEM::Activate(), DIALOG_CONFIG_EQUFILES::OnEditEquFile(), DIALOG_BOM::OnEditPlugin(), KICAD_MANAGER_FRAME::OnOpenFileInTextEditor(), TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor(), KICAD_MANAGER_FRAME::OnOpenTextEditor(), EDA_BASE_FRAME::OnSelectPreferredEditor(), and GERBVIEW_FRAME::OnShowGerberSourceFile().

337 {
338  wxString editorname = m_editor_name;
339 
340  if( !editorname )
341  {
342  if( !wxGetEnv( wxT( "EDITOR" ), &editorname ) )
343  {
344  // If there is no EDITOR variable set, try the desktop default
345 #ifdef __WXMAC__
346  editorname = "/usr/bin/open";
347 #elif __WXX11__
348  editorname = "/usr/bin/xdg-open";
349 #endif
350  }
351  }
352 
353  // If we still don't have an editor name show a dialog asking the user to select one
354  if( !editorname && aCanShowFileChooser )
355  {
356  DisplayInfoMessage( NULL,
357  _( "No default editor found, you must choose it" ) );
358 
359  editorname = AskUserForPreferredEditor();
360  }
361 
362  // If we finally have a new editor name request it to be copied to m_editor_name and
363  // saved to the preferences file.
364  if( !editorname.IsEmpty() )
365  SetEditorName( editorname );
366 
367  // m_editor_name already has the same value that editorname, or empty if no editor was
368  // found/chosen.
369  return m_editor_name;
370 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:328
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:373
void DisplayInfoMessage(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:89
wxString m_editor_name
Definition: pgm_base.h:378
VTBL_ENTRY const wxString& PGM_BASE::GetExecutablePath ( ) const
inlineinherited
double PGM_BASE::GetIconsScale ( )
inlineinherited

Definition at line 325 of file pgm_base.h.

References PGM_BASE::m_iconsScale.

325 { return m_iconsScale; }
double m_iconsScale
Scaling factor for menus and tool icons.
Definition: pgm_base.h:362
VTBL_ENTRY const wxString& PGM_BASE::GetKicadEnvVariable ( ) const
inlineinherited

Definition at line 171 of file pgm_base.h.

References PGM_BASE::m_kicad_env.

Referenced by FindKicadFile(), and KicadDatasPath().

171 { return m_kicad_env; }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:350
VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inlineinherited

Definition at line 175 of file pgm_base.h.

References PGM_BASE::m_locale.

Referenced by SearchHelpFileFullPath().

175 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:353
VTBL_ENTRY const ENV_VAR_MAP& PGM_BASE::GetLocalEnvVariables ( ) const
inlineinherited

Definition at line 270 of file pgm_base.h.

References PGM_BASE::m_local_env_vars.

Referenced by PGM_BASE::ConfigurePaths(), and S3D_FILENAME_RESOLVER::GetKicadPaths().

271  {
272  return m_local_env_vars;
273  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:382
VTBL_ENTRY const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inlineinherited

Definition at line 177 of file pgm_base.h.

References PGM_BASE::m_pdf_browser.

Referenced by KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser(), OpenPDF(), and PGM_BASE::WritePdfBrowserInfos().

177 { return m_pdf_browser; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:377
bool PGM_BASE::GetUseIconsInMenus ( )
inlineinherited

Definition at line 328 of file pgm_base.h.

References PGM_BASE::m_useIconsInMenus.

Referenced by AddMenuItem().

328 { return m_useIconsInMenus; }
bool m_useIconsInMenus
True to use menu icons.
Definition: pgm_base.h:364
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 396 of file pgm_base.cpp.

References PGM_BASE::App(), Format(), GetChars(), GetKicadLockFilePath(), GetNewConfig(), IsOK(), KICAD_COMMON, PGM_BASE::loadCommonSettings(), PGM_BASE::m_common_settings, PGM_BASE::m_kicad_env, PGM_BASE::m_local_env_vars, PGM_BASE::m_pgm_checker, pathEnvVariables, PGM_BASE::ReadPdfBrowserInfos(), ENV_VAR_ITEM::SetDefinedExternally(), PGM_BASE::setExecutablePath(), PGM_BASE::SetLanguage(), PGM_BASE::SetLanguagePath(), ENV_VAR_ITEM::SetValue(), UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

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

397 {
398  wxFileName pgm_name( App().argv[0] );
399 
400  wxConfigBase::DontCreateOnDemand();
401 
402  wxInitAllImageHandlers();
403 
404  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
405  wxGetUserId(), GetKicadLockFilePath() );
406 
407  if( m_pgm_checker->IsAnotherRunning() )
408  {
409  wxString quiz = wxString::Format(
410  _( "%s is already running, Continue?" ),
411  GetChars( pgm_name.GetName() )
412  );
413 
414  if( !IsOK( NULL, quiz ) )
415  return false;
416  }
417 
418  // Init KiCad environment
419  // the environment variable KICAD (if exists) gives the kicad path:
420  // something like set KICAD=d:\kicad
421  bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_kicad_env );
422 
423  if( isDefined ) // ensure m_kicad_env ends by "/"
424  {
426 
427  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
429  }
430 
431  // Init parameters for configuration
432  App().SetVendorName( wxT( "KiCad" ) );
433  App().SetAppName( pgm_name.GetName().Lower() );
434 
435  // Install some image handlers, mainly for help
436  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
437  wxImage::AddHandler( new wxPNGHandler );
438 
439  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
440  wxImage::AddHandler( new wxGIFHandler );
441 
442  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
443  wxImage::AddHandler( new wxJPEGHandler );
444 
445  wxFileSystem::AddHandler( new wxZipFSHandler );
446 
447  // Analyze the command line & initialize the binary path
449 
450  SetLanguagePath();
451 
452  // OS specific instantiation of wxConfigBase derivative:
454 
455  // Only define the default environment variable if they haven't been set in the
456  // .kicad_common configuration file.
458  {
459  wxString envVarName = wxT( "KIGITHUB" );
460  ENV_VAR_ITEM envVarItem;
461  wxString envValue;
462  wxFileName tmpFileName;
463 
464  envVarItem.SetValue( wxString( wxT( "https://github.com/KiCad" ) ) );
465  envVarItem.SetDefinedExternally( wxGetEnv( envVarName, NULL ) );
466  m_local_env_vars[ envVarName ] = envVarItem;
467 
468  wxFileName baseSharePath;
469  baseSharePath.AssignDir( wxString( wxT( DEFAULT_INSTALL_PATH ) ) );
470 
471 #if !defined( __WXMAC__ )
472  baseSharePath.AppendDir( wxT( "share" ) );
473  baseSharePath.AppendDir( wxT( "kicad" ) );
474 #endif
475 
476  // KISYSMOD
477  envVarName = wxT( "KISYSMOD" );
478  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
479  {
480  tmpFileName.AssignDir( envValue );
481  envVarItem.SetDefinedExternally( true );
482  }
483  else
484  {
485  tmpFileName = baseSharePath;
486  tmpFileName.AppendDir( wxT( "modules" ) );
487  envVarItem.SetDefinedExternally( false );
488  }
489  envVarItem.SetValue( tmpFileName.GetFullPath() );
490  m_local_env_vars[ envVarName ] = envVarItem;
491 
492  // KISYS3DMOD
493  envVarName = wxT( "KISYS3DMOD" );
494  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
495  {
496  tmpFileName.AssignDir( envValue );
497  envVarItem.SetDefinedExternally( true );
498  }
499  else
500  {
501  tmpFileName.AppendDir( wxT( "packages3d" ) );
502  envVarItem.SetDefinedExternally( false );
503  }
504  envVarItem.SetValue( tmpFileName.GetFullPath() );
505  m_local_env_vars[ envVarName ] = envVarItem;
506 
507  // KICAD_PTEMPLATES
508  envVarName = wxT( "KICAD_PTEMPLATES" );
509  if( wxGetEnv( envVarName, &envValue ) == true && !envValue.IsEmpty() )
510  {
511  tmpFileName.AssignDir( envValue );
512  envVarItem.SetDefinedExternally( true );
513  }
514  else
515  {
516  tmpFileName = baseSharePath;
517  tmpFileName.AppendDir( wxT( "template" ) );
518  envVarItem.SetDefinedExternally( false );
519  }
520  envVarItem.SetValue( tmpFileName.GetFullPath() );
521  m_local_env_vars[ envVarName ] = envVarItem;
522  }
523 
524  ReadPdfBrowserInfos(); // needs m_common_settings
525 
526  // Init user language *before* calling loadCommonSettings, because
527  // env vars could be incorrectly initialized on Linux
528  // (if the value contains some non ASCII7 chars, the env var is not initialized)
529  SetLanguage( true );
530 
532 
533 #ifdef __WXMAC__
534  // Always show filters on Open dialog to be able to choose plugin
535  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
536 #endif
537 
538  return true;
539 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:65
void loadCommonSettings()
Function loadCommonSettings loads the program (process) settings subset which are stored in ...
Definition: pgm_base.cpp:584
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:382
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
Class ENV_VAR_ITEM.
Definition: pgm_base.h:58
wxConfigBase * GetNewConfig(const wxString &aProgName)
Function GetNewConfig.
Definition: common.cpp:205
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:321
bool setExecutablePath()
Function setExecutablePath finds the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:542
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:340
#define KICAD_COMMON
Definition: pgm_base.cpp:58
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:350
void SetDefinedExternally(bool aIsDefinedExternally)
Definition: pgm_base.h:70
VTBL_ENTRY void SetLanguagePath()
Definition: pgm_base.cpp:760
VTBL_ENTRY bool SetLanguage(bool first_time=false)
Function SetLanguage sets the dictionary file name for internationalization.
Definition: pgm_base.cpp:652
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
VTBL_ENTRY void ReadPdfBrowserInfos()
Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:41
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:92
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:76
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
VTBL_ENTRY bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlineinherited

Definition at line 169 of file pgm_base.h.

References PGM_BASE::m_kicad_env.

169 { return !m_kicad_env.IsEmpty(); }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:350
void PGM_BASE::loadCommonSettings ( )
protectedinherited

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

Definition at line 584 of file pgm_base.cpp.

References entryUseIconsInMenus, GetChars(), PGM_BASE::m_common_settings, PGM_BASE::m_editor_name, PGM_BASE::m_help_size, PGM_BASE::m_iconsScale, PGM_BASE::m_local_env_vars, PGM_BASE::m_show_env_var_dialog, PGM_BASE::m_useIconsInMenus, pathEnvVariables, PGM_BASE::SetLocalEnvVariable(), showEnvVarWarningDialog, and traceEnvVars.

Referenced by PGM_BASE::InitPgm().

585 {
586  wxASSERT( m_common_settings );
587 
588  m_help_size.x = 500;
589  m_help_size.y = 400;
590  m_iconsScale = 1.0;
591  m_useIconsInMenus = true;
592 
595 
596  m_editor_name = m_common_settings->Read( wxT( "Editor" ) );
597 
598  wxString entry, oldPath;
599  wxArrayString entries;
600  long index = 0L;
601 
602  oldPath = m_common_settings->GetPath();
604 
605  while( m_common_settings->GetNextEntry( entry, index ) )
606  {
607  wxLogTrace( traceEnvVars,
608  wxT( "Enumerating over entry %s, %ld." ), GetChars( entry ), index );
609  entries.Add( entry );
610  }
611 
612  for( unsigned i = 0; i < entries.GetCount(); i++ )
613  {
614  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
615  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
616  }
617 
618  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
619  SetLocalEnvVariable( it->first, it->second.GetValue() );
620 
621  m_common_settings->SetPath( oldPath );
622 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:65
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:382
Class ENV_VAR_ITEM.
Definition: pgm_base.h:58
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:66
static const wxChar traceEnvVars[]
enable/disable icons in menus
Definition: pgm_base.cpp:67
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:385
static const wxChar entryUseIconsInMenus[]
Definition: pgm_base.cpp:69
double m_iconsScale
Scaling factor for menus and tool icons.
Definition: pgm_base.h:362
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:836
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
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:92
wxSize m_help_size
Definition: pgm_base.h:379
wxString m_editor_name
Definition: pgm_base.h:378
bool m_useIconsInMenus
True to use menu icons.
Definition: pgm_base.h:364
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:88
void PGM_SINGLE_TOP::MacOpenFile ( const wxString &  aFileName)
inlineoverridevirtual

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

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

77  {
78  wxFileName filename( aFileName );
79 
80  if( filename.FileExists() )
81  {
82  #if 0
83  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
84  // the single_top link image.
85  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
86  #else
87  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
88  #endif
89  if( frame )
90  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
91  }
92  }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:321
VTBL_ENTRY bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList...
Definition: kiway_player.h:170
void PGM_SINGLE_TOP::OnPgmExit ( )
inline

Definition at line 65 of file single_top.cpp.

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

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

66  {
67  Kiway.OnKiwayEnd();
68 
70 
71  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
72  // earlier than wxApp and earlier than static destruction would.
74  }
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ...
Definition: pgm_base.cpp:625
void Destroy()
Definition: pgm_base.cpp:306
void OnKiwayEnd()
Definition: kiway.cpp:485
KIWAY Kiway
bool PGM_SINGLE_TOP::OnPgmInit ( )

Definition at line 208 of file single_top.cpp.

References PGM_BASE::App(), PGM_BASE::InitPgm(), kiface, KIFACE_GETTER(), KIFACE_VERSION, KIWAY::KifaceType(), Kiway, OnPgmExit(), KIWAY_PLAYER::OpenProjectFiles(), KIWAY::Player(), KIWAY::set_kiface(), and KIWAY::SetTop().

Referenced by APP_SINGLE_TOP::OnInit().

209 {
210 #if defined(DEBUG)
211  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
212 
213  if( !wxIsAbsolutePath( absoluteArgv0 ) )
214  {
215  wxLogError( wxT( "No meaningful argv[0]" ) );
216  return false;
217  }
218 #endif
219 
220  if( !InitPgm() )
221  return false;
222 
223 #if !defined(BUILD_KIWAY_DLL)
224 
225  // Only bitmap2component and pcb_calculator use this code currently, as they
226  // are not split to use single_top as a link image separate from a *.kiface.
227  // i.e. they are single part link images so don't need to load a *.kiface.
228 
229  // Get the getter, it is statically linked into this binary image.
231 
232  int kiface_version;
233 
234  // Get the KIFACE.
235  KIFACE* kiface = getter( &kiface_version, KIFACE_VERSION, this );
236 
237  // Trick the KIWAY into thinking it loaded a KIFACE, by recording the KIFACE
238  // in the KIWAY. It needs to be there for KIWAY::OnKiwayEnd() anyways.
239  Kiway.set_kiface( KIWAY::KifaceType( TOP_FRAME ), kiface );
240 #endif
241 
242  // Use KIWAY to create a top window, which registers its existence also.
243  // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
244  // and is one of the types in FRAME_T.
245  KIWAY_PLAYER* frame = Kiway.Player( TOP_FRAME, true );
246 
247  Kiway.SetTop( frame );
248 
249  App().SetTopWindow( frame ); // wxApp gets a face.
250 
251  // Open project or file specified on the command line:
252  int argc = App().argc;
253 
254  if( argc > 1 )
255  {
256  /*
257  gerbview handles multiple project data files, i.e. gerber files on
258  cmd line. Others currently do not, they handle only one. For common
259  code simplicity we simply pass all the arguments in however, each
260  program module can do with them what they want, ignore, complain
261  whatever. We don't establish policy here, as this is a multi-purpose
262  launcher.
263  */
264 
265  std::vector<wxString> argSet;
266 
267  for( int i=1; i<argc; ++i )
268  {
269  argSet.push_back( App().argv[i] );
270  }
271 
272  // special attention to the first argument: argv[1] (==argSet[0])
273  wxFileName argv1( argSet[0] );
274 
275  if( argc == 2 )
276  {
277 #if defined(PGM_DATA_FILE_EXT)
278  // PGM_DATA_FILE_EXT, if present, may be different for each compile,
279  // it may come from CMake on the compiler command line, but often does not.
280  // This facillity is mostly useful for those program modules
281  // supporting a single argv[1].
282  if( !argv1.GetExt() )
283  argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
284 #endif
285  argv1.MakeAbsolute();
286 
287  argSet[0] = argv1.GetFullPath();
288  }
289 
290  // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
291  if( !frame->OpenProjectFiles( argSet ) )
292  {
293  // OpenProjectFiles() API asks that it report failure to the UI.
294  // Nothing further to say here.
295 
296  // We've already initialized things at this point, but wx won't call OnExit if
297  // we fail out. Call our own cleanup routine here to ensure the relevant resources
298  // are freed at the right time (if they aren't, segfaults will occur).
299  OnPgmExit();
300 
301  // Fail the process startup if the file could not be opened,
302  // although this is an optional choice, one that can be reversed
303  // also in the KIFACE specific OpenProjectFiles() return value.
304  return false;
305  }
306  }
307 
308  frame->Show();
309 
310  return true;
311 }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:111
static FACE_T KifaceType(FRAME_T aFrameType)
Function KifaceType is a simple mapping function which returns the FACE_T which is known to implement...
Definition: kiway.cpp:252
void OnPgmExit()
Definition: single_top.cpp:65
#define KIFACE_VERSION
Definition: kiway.h:111
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:321
VTBL_ENTRY bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList...
Definition: kiway_player.h:170
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:394
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
KIFACE * KIFACE_GETTER(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
No name mangling. Each KIFACE (DSO/DLL) will implement this once.
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Function Pointer KIFACE_GETTER_FUNC points to the one and only KIFACE export.
Definition: kiway.h:450
void SetTop(wxFrame *aTop)
Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to ...
Definition: kiway.cpp:78
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:396
return & kiface
Definition: pcbnew.cpp:207
KIWAY Kiway
void PGM_BASE::ReadPdfBrowserInfos ( )
inherited

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

Definition at line 41 of file eda_doc.cpp.

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

Referenced by PGM_BASE::InitPgm(), KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser(), and OpenPDF().

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

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

Definition at line 625 of file pgm_base.cpp.

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

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

626 {
627  // m_common_settings is not initialized until fairly late in the
628  // process startup: InitPgm(), so test before using:
629  if( m_common_settings )
630  {
631  wxString cur_dir = wxGetCwd();
632 
633  m_common_settings->Write( workingDirKey, cur_dir );
636 
637  // Save the local environment variables.
639 
640  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
641  {
642  wxLogTrace( traceEnvVars, wxT( "Saving environment variable config entry %s as %s" ),
643  GetChars( it->first ), GetChars( it->second.GetValue() ) );
644  m_common_settings->Write( it->first, it->second.GetValue() );
645  }
646 
647  m_common_settings->SetPath( wxT( ".." ) );
648  }
649 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:65
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:382
static const wxChar workingDirKey[]
Definition: pgm_base.h:297
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:66
static const wxChar traceEnvVars[]
enable/disable icons in menus
Definition: pgm_base.cpp:67
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:385
static const wxChar entryUseIconsInMenus[]
Definition: pgm_base.cpp:69
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
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:92
bool m_useIconsInMenus
True to use menu icons.
Definition: pgm_base.h:364
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:88
void PGM_BASE::SetEditorName ( const wxString &  aFileName)
inherited

Definition at line 328 of file pgm_base.cpp.

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

Referenced by PGM_BASE::GetEditorName(), and EDA_BASE_FRAME::OnSelectPreferredEditor().

329 {
330  m_editor_name = aFileName;
331  wxASSERT( m_common_settings );
332  m_common_settings->Write( wxT( "Editor" ), aFileName );
333 }
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
wxString m_editor_name
Definition: pgm_base.h:378
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 542 of file pgm_base.cpp.

References PGM_BASE::m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_BASE::InitPgm().

543 {
544  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
545 
546 #ifdef __WXMAC__
547  // On OSX Pgm().GetExecutablePath() will always point to main
548  // bundle directory, e.g., /Applications/kicad.app/
549 
550  wxFileName fn( m_bin_dir );
551 
552  if( fn.GetName() == wxT( "kicad" ) )
553  {
554  // kicad launcher, so just remove the Contents/MacOS part
555  fn.RemoveLastDir();
556  fn.RemoveLastDir();
557  }
558  else
559  {
560  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
561  fn.RemoveLastDir();
562  fn.RemoveLastDir();
563  fn.RemoveLastDir();
564  fn.RemoveLastDir();
565  fn.RemoveLastDir();
566  }
567 
568  m_bin_dir = fn.GetPath() + wxT( "/" );
569 #else
570  // Use unix notation for paths. I am not sure this is a good idea,
571  // but it simplifies compatibility between Windows and Unices.
572  // However it is a potential problem in path handling under Windows.
574 
575  // Remove file name form command line:
576  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
577  m_bin_dir.RemoveLast();
578 #endif
579 
580  return true;
581 }
#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:347
void PGM_BASE::SetIconsScale ( double  aValue)
inlineinherited

Scaling factor for menus and tool icons.

Definition at line 324 of file pgm_base.h.

References PGM_BASE::m_iconsScale.

324 { m_iconsScale = aValue; }
double m_iconsScale
Scaling factor for menus and tool icons.
Definition: pgm_base.h:362
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 652 of file pgm_base.cpp.

References DIM, GetChars(), languageCfgKey, PGM_BASE::m_common_settings, LANGUAGE_DESCR::m_Lang_Label, PGM_BASE::m_language_id, PGM_BASE::m_locale, and PGM_BASE::setLanguageId().

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

653 {
654  bool retv = true;
655 
656  if( first_time )
657  {
658  setLanguageId( wxLANGUAGE_DEFAULT );
659  // First time SetLanguage is called, the user selected language id is set
660  // from commun user config settings
661  wxString languageSel;
662 
663  m_common_settings->Read( languageCfgKey, &languageSel );
664 
665  // Search for the current selection
666  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
667  {
668  if( s_Languages[ii].m_Lang_Label == languageSel )
669  {
670  setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
671  break;
672  }
673  }
674  }
675 
676  // dictionary file name without extend (full name is kicad.mo)
677  wxString dictionaryName( wxT( "kicad" ) );
678 
679  delete m_locale;
680  m_locale = new wxLocale;
681 
682  if( !m_locale->Init( m_language_id ) )
683  {
684  wxLogDebug( wxT( "This language is not supported by the system." ) );
685 
686  setLanguageId( wxLANGUAGE_DEFAULT );
687  delete m_locale;
688 
689  m_locale = new wxLocale;
690  m_locale->Init();
691  retv = false;
692  }
693  else if( !first_time )
694  {
695  wxLogDebug( wxT( "Search for dictionary %s.mo in %s" ),
696  GetChars( dictionaryName ), GetChars( m_locale->GetName() ) );
697  }
698 
699  if( !first_time )
700  {
701  // If we are here, the user has selected an other language.
702  // Therefore the new prefered language name is stored in common config.
703  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
704  // versions, for a given language
705  wxString languageSel;
706 
707  // Search for the current selection language name
708  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
709  {
710  if( s_Languages[ii].m_WX_Lang_Identifier == m_language_id )
711  {
712  languageSel = s_Languages[ii].m_Lang_Label;
713  break;
714  }
715  }
716 
717  m_common_settings->Write( languageCfgKey, languageSel );
718  }
719 
720  // Test if floating point notation is working (bug encountered in cross compilation)
721  // Make a conversion double <=> string
722  double dtst = 0.5;
723  wxString msg;
724 
725  msg << dtst;
726  double result;
727  msg.ToDouble( &result );
728 
729  if( result != dtst )
730  // string to double encode/decode does not work! Bug detected:
731  // Disable floating point localization:
732  setlocale( LC_ALL, "C" );
733 
734  if( !m_locale->IsLoaded( dictionaryName ) )
735  m_locale->AddCatalog( dictionaryName );
736 
737  if( !retv )
738  return retv;
739 
740  return m_locale->IsOk();
741 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:353
int m_language_id
The current language setting.
Definition: pgm_base.h:356
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:367
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.cpp:92
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
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:92
static const wxChar languageCfgKey[]
Definition: pgm_base.cpp:64
static LANGUAGE_DESCR s_Languages[]
Variable s_Languages Note: because this list is not created on the fly, wxTranslation must be called ...
Definition: pgm_base.cpp:105
void PGM_BASE::setLanguageId ( int  aId)
inlineprotectedinherited

Trap all changes in here, simplifies debugging.

Definition at line 367 of file pgm_base.h.

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

367 { m_language_id = aId; }
int m_language_id
The current language setting.
Definition: pgm_base.h:356
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 744 of file pgm_base.cpp.

References DIM, and PGM_BASE::setLanguageId().

Referenced by KIWAY::SetLanguage().

745 {
746  wxLogDebug( wxT( "Select language ID %d from %d possible languages." ),
747  menu_id, DIM( s_Languages ) );
748 
749  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
750  {
751  if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
752  {
753  setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
754  break;
755  }
756  }
757 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:367
static LANGUAGE_DESCR s_Languages[]
Variable s_Languages Note: because this list is not created on the fly, wxTranslation must be called ...
Definition: pgm_base.cpp:105
void PGM_BASE::SetLanguagePath ( )
inherited

Definition at line 760 of file pgm_base.cpp.

References SystemDirsAppend().

Referenced by PGM_BASE::InitPgm().

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

References GetChars(), and traceEnvVars.

Referenced by PGM_BASE::loadCommonSettings().

837 {
838  wxString env;
839 
840  // Check to see if the environment variable is already set.
841  if( wxGetEnv( aName, &env ) )
842  {
843  wxLogTrace( traceEnvVars, wxT( "Environment variable %s already set to %s." ),
844  GetChars( aName ), GetChars( env ) );
845  return env == aValue;
846  }
847 
848  wxLogTrace( traceEnvVars, wxT( "Setting local environment variable %s to %s." ),
849  GetChars( aName ), GetChars( aValue ) );
850 
851  return wxSetEnv( aName, aValue );
852 }
static const wxChar traceEnvVars[]
enable/disable icons in menus
Definition: pgm_base.cpp:67
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:92
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 855 of file pgm_base.cpp.

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

Referenced by PGM_BASE::ConfigurePaths().

856 {
857  m_local_env_vars.clear();
858  m_local_env_vars = aEnvVarMap;
859 
860  if( m_common_settings )
861  m_common_settings->DeleteGroup( pathEnvVariables );
862 
864 
865  // Overwrites externally defined environment variable until the next time the application
866  // is run.
867  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
868  {
869  wxLogTrace( traceEnvVars, wxT( "Setting local environment variable %s to %s." ),
870  GetChars( it->first ), GetChars( it->second.GetValue() ) );
871  wxSetEnv( it->first, it->second.GetValue() );
872  }
873 }
static const wxChar pathEnvVariables[]
Definition: pgm_base.cpp:65
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:382
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ...
Definition: pgm_base.cpp:625
static const wxChar traceEnvVars[]
enable/disable icons in menus
Definition: pgm_base.cpp:67
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:344
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:92
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:88
VTBL_ENTRY void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inlineinherited

Definition at line 179 of file pgm_base.h.

References PGM_BASE::m_pdf_browser.

Referenced by KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser(), and PGM_BASE::ReadPdfBrowserInfos().

179 { m_pdf_browser = aFileName; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:377
void PGM_BASE::SetUseIconsInMenus ( bool  aUseIcons)
inlineinherited

True to use menu icons.

Definition at line 327 of file pgm_base.h.

References PGM_BASE::m_useIconsInMenus.

Referenced by EDA_BASE_FRAME::OnChangeIconsOptions().

327 { m_useIconsInMenus = aUseIcons; }
bool m_useIconsInMenus
True to use menu icons.
Definition: pgm_base.h:364
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 187 of file pgm_base.h.

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

188  {
189  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
190  }
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:359
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:377
void PGM_BASE::WritePdfBrowserInfos ( )
inherited

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

Definition at line 54 of file eda_doc.cpp.

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

Referenced by KICAD_MANAGER_FRAME::OnSelectDefaultPdfBrowser(), and KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser().

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

Member Data Documentation

wxString PGM_BASE::m_bin_dir
protectedinherited

full path to this program

Definition at line 347 of file pgm_base.h.

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

wxConfigBase* PGM_BASE::m_common_settings
protectedinherited
wxString PGM_BASE::m_editor_name
protectedinherited
wxSize PGM_BASE::m_help_size
protectedinherited

Definition at line 379 of file pgm_base.h.

Referenced by PGM_BASE::loadCommonSettings().

double PGM_BASE::m_iconsScale
protectedinherited

Scaling factor for menus and tool icons.

Definition at line 362 of file pgm_base.h.

Referenced by PGM_BASE::GetIconsScale(), PGM_BASE::loadCommonSettings(), and PGM_BASE::SetIconsScale().

wxString PGM_BASE::m_kicad_env
protectedinherited

The KICAD system environment variable.

Definition at line 350 of file pgm_base.h.

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

int PGM_BASE::m_language_id
protectedinherited

The current language setting.

Definition at line 356 of file pgm_base.h.

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

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protectedinherited

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

Definition at line 382 of file pgm_base.h.

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

wxLocale* PGM_BASE::m_locale
protectedinherited

The current locale.

Definition at line 353 of file pgm_base.h.

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

wxString PGM_BASE::m_pdf_browser
protectedinherited

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

Definition at line 377 of file pgm_base.h.

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

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protectedinherited

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

Definition at line 340 of file pgm_base.h.

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

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

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

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

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

bool PGM_BASE::m_useIconsInMenus
protectedinherited
const wxChar PGM_BASE::workingDirKey = wxT( "WorkingDir" )
staticinherited

Definition at line 297 of file pgm_base.h.

Referenced by PGM_BASE::SaveCommonSettings().


The documentation for this struct was generated from the following file: