KiCad PCB EDA Suite
PGM_BASE Class Referenceabstract

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

#include <pgm_base.h>

Inheritance diagram for PGM_BASE:
PGM_KICAD PGM_SINGLE_TOP

Public Member Functions

 PGM_BASE ()
 
virtual ~PGM_BASE ()
 
VTBL_ENTRY void MacOpenFile (const wxString &aFileName)=0
 Function MacOpenFile is specific to MacOSX (not used under Linux or Windows). More...
 
VTBL_ENTRY wxConfigBase * CommonSettings () const
 
VTBL_ENTRY void SetEditorName (const wxString &aFileName)
 
VTBL_ENTRY const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
VTBL_ENTRY const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
VTBL_ENTRY bool IsKicadEnvVariableDefined () const
 
VTBL_ENTRY const wxString & GetKicadEnvVariable () const
 
VTBL_ENTRY const wxString & GetExecutablePath () const
 
VTBL_ENTRY wxLocale * GetLocale ()
 
VTBL_ENTRY const wxString & GetPdfBrowserName () const
 
VTBL_ENTRY void SetPdfBrowserName (const wxString &aFileName)
 
VTBL_ENTRY bool UseSystemPdfBrowser () const
 Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser. More...
 
VTBL_ENTRY void ForceSystemPdfBrowser (bool aFlg)
 Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set. More...
 
VTBL_ENTRY bool SetLanguage (bool first_time=false)
 Function SetLanguage sets the dictionary file name for internationalization. More...
 
VTBL_ENTRY void 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 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...
 

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...
 
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_BASE keeps program (whole process) data for KiCad programs.

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

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

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

Definition at line 149 of file pgm_base.h.

Constructor & Destructor Documentation

PGM_BASE::PGM_BASE ( )

Definition at line 153 of file pgm_base.cpp.

154 {
155  m_pgm_checker = NULL;
156  m_locale = NULL;
157  m_common_settings = NULL;
158 
159  m_show_env_var_dialog = true;
160 
161  setLanguageId( wxLANGUAGE_DEFAULT );
162 
163  ForceSystemPdfBrowser( false );
164 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:374
VTBL_ENTRY void ForceSystemPdfBrowser(bool aFlg)
Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser ...
Definition: pgm_base.h:238
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:401
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:361
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:383
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 167 of file pgm_base.cpp.

168 {
169  Destroy();
170 }
void Destroy()
Definition: pgm_base.cpp:173

Member Function Documentation

void PGM_BASE::AddMenuLanguageList ( wxMenu *  MasterMenu)

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

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

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

801 {
802  wxMenu* menu = NULL;
803  wxMenuItem* item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
804 
805  if( item ) // This menu exists, do nothing
806  return;
807 
808  menu = new wxMenu;
809 
810  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
811  {
812  wxString label;
813 
814  if( s_Languages[ii].m_DoNotTranslate )
815  label = s_Languages[ii].m_Lang_Label;
816  else
817  label = wxGetTranslation( s_Languages[ii].m_Lang_Label );
818 
819  AddMenuItem( menu, s_Languages[ii].m_KI_Lang_Identifier,
820  label, KiBitmap(s_Languages[ii].m_Lang_Icon ),
821  wxITEM_CHECK );
822  }
823 
824  AddMenuItem( MasterMenu, menu,
826  _( "Set Language" ),
827  _( "Select application language (only for testing)" ),
828  KiBitmap( language_xpm ) );
829 
830  // Set Check mark on current selected language
831  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
832  {
833  if( m_language_id == s_Languages[ii].m_WX_Lang_Identifier )
834  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );
835  else
836  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, false );
837  }
838 }
#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:223
int m_language_id
The current language setting.
Definition: pgm_base.h:377
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.cpp:110
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:123
wxApp & PGM_BASE::App ( )

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

Should return what wxGetApp() returns.

Definition at line 188 of file pgm_base.cpp.

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

189 {
190  wxASSERT( wxTheApp );
191  return *wxTheApp;
192 }
const wxString PGM_BASE::AskUserForPreferredEditor ( const wxString &  aDefaultEditor = wxEmptyString)

Shows a dialog that instructs the user to select a new preferred editor.

Parameters
aDefaultEditorDefault full path for the default editor this dialog should show by default.
Returns
Returns the full path of the editor, or an empty string if no editor was chosen.

Definition at line 240 of file pgm_base.cpp.

References EDA_FILE_SELECTOR(), and name.

Referenced by PANEL_COMMON_SETTINGS::OnTextEditorClick().

241 {
242  // Create a mask representing the executable files in the current platform
243 #ifdef __WINDOWS__
244  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
245 #else
246  wxString mask( _( "Executable file (*)|*" ) );
247 #endif
248 
249  // Extract the path, name and extension from the default editor (even if the editor's
250  // name was empty, this method will succeed and return empty strings).
251  wxString path, name, ext;
252  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
253 
254  // Show the modal editor and return the file chosen (may be empty if the user cancels
255  // the dialog).
256  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
257  name, ext, mask,
258  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
259  true );
260 }
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
void PGM_BASE::Destroy ( )

Definition at line 173 of file pgm_base.cpp.

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

174 {
175  // unlike a normal destructor, this is designed to be called more than once safely:
176 
177  delete m_common_settings;
178  m_common_settings = 0;
179 
180  delete m_pgm_checker;
181  m_pgm_checker = 0;
182 
183  delete m_locale;
184  m_locale = 0;
185 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:374
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:361
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
VTBL_ENTRY void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inline

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

Definition at line 238 of file pgm_base.h.

References VTBL_ENTRY.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

238 { 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:380
const wxString & PGM_BASE::GetEditorName ( bool  aCanShowFileChooser = true)

Return the preferred editor name.

Parameters
aCanShowFileChooserIf no editor is currently set and this argument is 'true' then this method will show a file chooser dialog asking for the editor's executable.
Returns
Returns the full path of the editor, or an empty string if no editor has been set.

Definition at line 203 of file pgm_base.cpp.

References DisplayInfoMessage().

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

204 {
205  wxString editorname = m_editor_name;
206 
207  if( !editorname )
208  {
209  if( !wxGetEnv( "EDITOR", &editorname ) )
210  {
211  // If there is no EDITOR variable set, try the desktop default
212 #ifdef __WXMAC__
213  editorname = "/usr/bin/open";
214 #elif __WXX11__
215  editorname = "/usr/bin/xdg-open";
216 #endif
217  }
218  }
219 
220  // If we still don't have an editor name show a dialog asking the user to select one
221  if( !editorname && aCanShowFileChooser )
222  {
223  DisplayInfoMessage( NULL,
224  _( "No default editor found, you must choose it" ) );
225 
226  editorname = AskUserForPreferredEditor();
227  }
228 
229  // If we finally have a new editor name request it to be copied to m_editor_name and
230  // saved to the preferences file.
231  if( !editorname.IsEmpty() )
232  SetEditorName( editorname );
233 
234  // m_editor_name already has the same value that editorname, or empty if no editor was
235  // found/chosen.
236  return m_editor_name;
237 }
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:195
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:240
wxString m_editor_name
Definition: pgm_base.h:394
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:277
VTBL_ENTRY const wxString& PGM_BASE::GetExecutablePath ( ) const
inline
VTBL_ENTRY const wxString& PGM_BASE::GetKicadEnvVariable ( ) const
inline

Definition at line 213 of file pgm_base.h.

Referenced by FindKicadFile(), and KicadDatasPath().

213 { return m_kicad_env; }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:371
VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inline

Definition at line 217 of file pgm_base.h.

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

217 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:374
VTBL_ENTRY const ENV_VAR_MAP& PGM_BASE::GetLocalEnvVariables ( ) const
inline

Definition at line 312 of file pgm_base.h.

References VTBL_ENTRY.

Referenced by PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), FILENAME_RESOLVER::GetKicadPaths(), KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate(), PGM_KICAD::OnPgmInit(), and DIALOG_CONFIGURE_PATHS::TransferDataToWindow().

313  {
314  return m_local_env_vars;
315  }
ENV_VAR_MAP m_local_env_vars
Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
Definition: pgm_base.h:398
VTBL_ENTRY const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inline

Definition at line 219 of file pgm_base.h.

Referenced by PANEL_COMMON_SETTINGS::OnPDFViewerClick(), OpenPDF(), and WritePdfBrowserInfos().

219 { return m_pdf_browser; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:393
bool PGM_BASE::InitPgm ( )

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

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

But nothing relating to DSOs or projects.

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

Definition at line 263 of file pgm_base.cpp.

References SEARCH_STACK::AddPaths(), Format(), GetChars(), GetKicadLockFilePath(), GetNewConfig(), i, IsOK(), KICAD_COMMON, ENV_VAR_ITEM::SetDefinedExternally(), ENV_VAR_ITEM::SetValue(), SystemDirsAppend(), tracePathsAndFiles, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

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

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

Definition at line 211 of file pgm_base.h.

211 { return !m_kicad_env.IsEmpty(); }
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:371
void PGM_BASE::loadCommonSettings ( )
protected

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

Definition at line 538 of file pgm_base.cpp.

References 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, KIGFX::NONE, pathEnvVariables, PCB_EDIT_FRAME_NAME, showEnvVarWarningDialog, traceEnvVars, and USE_ICONS_IN_MENUS_KEY.

539 {
540  wxASSERT( m_common_settings );
541 
542  m_help_size.x = 500;
543  m_help_size.y = 400;
544 
545  // This only effect the first time KiCad is run. The user's setting will be used for all
546  // subsequent runs. Menu icons are off by default on OSX and on for all other platforms.
547 #if defined( __WXMAC__ )
548  bool defaultUseIconsInMenus = false;
549 #else
550  bool defaultUseIconsInMenus = true;
551 #endif
552 
554 
555  if( !m_common_settings->HasEntry( USE_ICONS_IN_MENUS_KEY ) )
556  m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
557 
558  if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
560  {
561  // 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
562  // options only in pcbnew (which was the only canvas to support them). Since there's
563  // no single right answer to where to pull the common settings from, we might as well
564  // get them along with the hardware antialiasing option from pcbnew.
565  wxConfigBase* pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
566  wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
567 
568  if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
569  {
570  wxString value;
571  bool option;
572 
573  pcbnewConfig->Read( "PcbIconScale", &value );
574  m_common_settings->Write( ICON_SCALE_KEY, value );
575 
576  pcbnewConfig->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
577  m_common_settings->Write( ENBL_MOUSEWHEEL_PAN_KEY, option );
578 
579  pcbnewConfig->Read( ENBL_ZOOM_NO_CENTER_KEY, &option, false );
580  m_common_settings->Write( ENBL_ZOOM_NO_CENTER_KEY, option );
581 
582  pcbnewConfig->Read( ENBL_AUTO_PAN_KEY, &option, true );
583  m_common_settings->Write( ENBL_AUTO_PAN_KEY, option );
584  }
585 
586  if( !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
587  {
588  int temp;
589  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + GAL_ANTIALIASING_MODE_KEY,
592  }
593  }
594 
595  m_editor_name = m_common_settings->Read( "Editor" );
596 
597  wxString entry, oldPath;
598  wxArrayString entries;
599  long index = 0L;
600 
601  oldPath = m_common_settings->GetPath();
603 
604  while( m_common_settings->GetNextEntry( entry, index ) )
605  {
606  wxLogTrace( traceEnvVars,
607  "Enumerating over entry %s, %ld.", GetChars( entry ), index );
608  entries.Add( entry );
609  }
610 
611  for( unsigned i = 0; i < entries.GetCount(); i++ )
612  {
613  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
614 
615  if( m_local_env_vars[ entries[i] ].GetDefinedExternally() )
616  continue;
617 
618  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
619  }
620 
621  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
622  SetLocalEnvVariable( it->first, it->second.GetValue() );
623 
624  m_common_settings->SetPath( oldPath );
625 }
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:398
Class ENV_VAR_ITEM.
Definition: pgm_base.h:100
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:68
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:251
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:401
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:47
#define PCB_EDIT_FRAME_NAME
Definition: draw_frame.h:56
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:52
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:50
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:841
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:48
#define ICON_SCALE_KEY
Definition: pgm_base.h:45
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:53
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
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:395
size_t i
Definition: json11.cpp:597
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:44
wxString m_editor_name
Definition: pgm_base.h:394
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:130
VTBL_ENTRY void PGM_BASE::MacOpenFile ( const wxString &  aFileName)
pure virtual

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

MacOSX requires it for file association.

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

Implemented in PGM_SINGLE_TOP, and PGM_KICAD.

Referenced by APP_KICAD::MacOpenFile().

void PGM_BASE::ReadPdfBrowserInfos ( )

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

Definition at line 42 of file eda_doc.cpp.

References m_common_settings, m_use_system_pdf_browser, and SetPdfBrowserName().

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

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 }
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:380
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:221
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
void PGM_BASE::SaveCommonSettings ( )

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

Definition at line 628 of file pgm_base.cpp.

References GetChars(), pathEnvVariables, showEnvVarWarningDialog, and traceEnvVars.

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

629 {
630  // m_common_settings is not initialized until fairly late in the
631  // process startup: InitPgm(), so test before using:
632  if( m_common_settings )
633  {
634  wxString cur_dir = wxGetCwd();
635 
636  m_common_settings->Write( workingDirKey, cur_dir );
638 
639  // Save the local environment variables.
641 
642  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
643  {
644  if( it->second.GetDefinedExternally() )
645  continue;
646 
647  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
648  GetChars( it->first ), GetChars( it->second.GetValue() ) );
649  m_common_settings->Write( it->first, it->second.GetValue() );
650  }
651 
652  m_common_settings->SetPath( ".." );
653  }
654 }
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:398
static const wxChar workingDirKey[]
Definition: pgm_base.h:326
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:401
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
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:130
void PGM_BASE::SetEditorName ( const wxString &  aFileName)

Definition at line 195 of file pgm_base.cpp.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

196 {
197  m_editor_name = aFileName;
198  wxASSERT( m_common_settings );
199  m_common_settings->Write( "Editor", aFileName );
200 }
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365
wxString m_editor_name
Definition: pgm_base.h:394
bool PGM_BASE::setExecutablePath ( )
protected

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

Returns
bool - true if success, else false.

Definition at line 496 of file pgm_base.cpp.

References UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

497 {
498  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
499 
500 #ifdef __WXMAC__
501  // On OSX Pgm().GetExecutablePath() will always point to main
502  // bundle directory, e.g., /Applications/kicad.app/
503 
504  wxFileName fn( m_bin_dir );
505 
506  if( fn.GetName() == wxT( "kicad" ) )
507  {
508  // kicad launcher, so just remove the Contents/MacOS part
509  fn.RemoveLastDir();
510  fn.RemoveLastDir();
511  }
512  else
513  {
514  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
515  fn.RemoveLastDir();
516  fn.RemoveLastDir();
517  fn.RemoveLastDir();
518  fn.RemoveLastDir();
519  fn.RemoveLastDir();
520  }
521 
522  m_bin_dir = fn.GetPath() + wxT( "/" );
523 #else
524  // Use unix notation for paths. I am not sure this is a good idea,
525  // but it simplifies compatibility between Windows and Unices.
526  // However it is a potential problem in path handling under Windows.
528 
529  // Remove file name form command line:
530  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
531  m_bin_dir.RemoveLast();
532 #endif
533 
534  return true;
535 }
#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:368
bool PGM_BASE::SetLanguage ( bool  first_time = false)

Function SetLanguage sets the dictionary file name for internationalization.

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

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

Definition at line 657 of file pgm_base.cpp.

References DIM, GetChars(), languageCfgKey, LANGUAGE_DESCR::m_Lang_Label, and traceLocale.

Referenced by KIWAY::SetLanguage(), and KIWAY::~KIWAY().

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

Trap all changes in here, simplifies debugging.

Definition at line 383 of file pgm_base.h.

383 { m_language_id = aId; }
int m_language_id
The current language setting.
Definition: pgm_base.h:377
void PGM_BASE::SetLanguageIdentifier ( int  menu_id)

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

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

Definition at line 749 of file pgm_base.cpp.

References DIM, and traceLocale.

Referenced by KIWAY::SetLanguage().

750 {
751  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
752  menu_id, DIM( s_Languages ) );
753 
754  for( unsigned ii = 0; ii < DIM( s_Languages ); ii++ )
755  {
756  if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
757  {
758  setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
759  break;
760  }
761  }
762 }
#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:383
const wxChar *const traceLocale
Flag to enable locale debug output.
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:123
void PGM_BASE::SetLanguagePath ( )

Definition at line 765 of file pgm_base.cpp.

References i, SystemDirsAppend(), and traceLocale.

766 {
767  SEARCH_STACK guesses;
768 
769  SystemDirsAppend( &guesses );
770 
771  // Add our internat dir to the wxLocale catalog of paths
772  for( unsigned i = 0; i < guesses.GetCount(); i++ )
773  {
774  wxFileName fn( guesses[i], wxEmptyString );
775 
776  // Append path for Windows and unix KiCad package install
777  fn.AppendDir( "share" );
778  fn.AppendDir( "internat" );
779 
780  if( fn.IsDirReadable() )
781  {
782  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
783  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
784  }
785 
786  // Append path for unix standard install
787  fn.RemoveLastDir();
788  fn.AppendDir( "kicad" );
789  fn.AppendDir( "internat" );
790 
791  if( fn.IsDirReadable() )
792  {
793  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
794  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
795  }
796  }
797 }
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
bool PGM_BASE::SetLocalEnvVariable ( const wxString &  aName,
const wxString &  aValue 
)

Function SetLocalEnvVariable.

Sets the environment variable aName to aValue.

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

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

Definition at line 841 of file pgm_base.cpp.

References GetChars(), and traceEnvVars.

842 {
843  wxString env;
844 
845  // Check to see if the environment variable is already set.
846  if( wxGetEnv( aName, &env ) )
847  {
848  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
849  GetChars( aName ), GetChars( env ) );
850  return env == aValue;
851  }
852 
853  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
854  GetChars( aName ), GetChars( aValue ) );
855 
856  return wxSetEnv( aName, aValue );
857 }
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:92
void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)

Function SetLocalEnvVariables.

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

Parameters
aEnvVarMapis a ENV_VAR_MAP object containing the new environment variables.

Definition at line 860 of file pgm_base.cpp.

References GetChars(), pathEnvVariables, and traceEnvVars.

Referenced by DIALOG_CONFIGURE_PATHS::TransferDataFromWindow().

861 {
862  m_local_env_vars.clear();
863  m_local_env_vars = aEnvVarMap;
864 
865  if( m_common_settings )
866  m_common_settings->DeleteGroup( pathEnvVariables );
867 
869 
870  // Overwrites externally defined environment variable until the next time the application
871  // is run.
872  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
873  {
874  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
875  GetChars( it->first ), GetChars( it->second.GetValue() ) );
876  wxSetEnv( it->first, it->second.GetValue() );
877  }
878 }
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:398
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ...
Definition: pgm_base.cpp:628
static const wxChar traceEnvVars[]
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:365
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:130
VTBL_ENTRY void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inline

Definition at line 221 of file pgm_base.h.

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

221 { m_pdf_browser = aFileName; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:393
VTBL_ENTRY bool PGM_BASE::UseSystemPdfBrowser ( ) const
inline

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

Definition at line 229 of file pgm_base.h.

230  {
231  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
232  }
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:380
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:393
void PGM_BASE::WritePdfBrowserInfos ( )

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

Definition at line 55 of file eda_doc.cpp.

References GetPdfBrowserName(), m_common_settings, and m_use_system_pdf_browser.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

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 }
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:219
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:380
wxConfigBase * m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:365

Member Data Documentation

wxString PGM_BASE::m_bin_dir
protected

full path to this program

Definition at line 368 of file pgm_base.h.

wxConfigBase* PGM_BASE::m_common_settings
protected

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

Definition at line 365 of file pgm_base.h.

Referenced by ReadPdfBrowserInfos(), and WritePdfBrowserInfos().

wxString PGM_BASE::m_editor_name
protected

Definition at line 394 of file pgm_base.h.

wxSize PGM_BASE::m_help_size
protected

Definition at line 395 of file pgm_base.h.

wxString PGM_BASE::m_kicad_env
protected

The KICAD system environment variable.

Definition at line 371 of file pgm_base.h.

int PGM_BASE::m_language_id
protected

The current language setting.

Definition at line 377 of file pgm_base.h.

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protected

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

Definition at line 398 of file pgm_base.h.

wxLocale* PGM_BASE::m_locale
protected

The current locale.

Definition at line 374 of file pgm_base.h.

wxString PGM_BASE::m_pdf_browser
protected

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

Definition at line 393 of file pgm_base.h.

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protected

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

Definition at line 361 of file pgm_base.h.

bool PGM_BASE::m_show_env_var_dialog
protected

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

Definition at line 401 of file pgm_base.h.

bool PGM_BASE::m_use_system_pdf_browser
protected

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

Definition at line 380 of file pgm_base.h.

Referenced by ReadPdfBrowserInfos(), and WritePdfBrowserInfos().

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

Definition at line 326 of file pgm_base.h.


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