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...
 
std::unique_ptr< wxConfigBase > m_common_settings
 Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common. More...
 
wxString m_bin_dir
 full path to this program More...
 
wxString m_kicad_env
 The KICAD system environment variable. More...
 
wxLocale * m_locale
 The current locale. More...
 
int m_language_id
 The current language setting. More...
 
bool m_use_system_pdf_browser
 true to use the selected PDF browser, if exists, or false to use the default More...
 
wxString m_pdf_browser
 The file name of the the program selected for browsing pdf files. More...
 
wxString m_editor_name
 
wxSize m_help_size
 
ENV_VAR_MAP m_local_env_vars
 Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD. More...
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. More...
 

Detailed Description

Class PGM_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 151 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 
158  m_show_env_var_dialog = true;
159 
160  setLanguageId( wxLANGUAGE_DEFAULT );
161 
162  ForceSystemPdfBrowser( false );
163 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:376
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:240
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:403
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:363
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:385
PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 166 of file pgm_base.cpp.

167 {
168  Destroy();
169 }
void Destroy()
Definition: pgm_base.cpp:172

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

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

808 {
809  wxMenu* menu = NULL;
810  wxMenuItem* item = MasterMenu->FindItem( ID_LANGUAGE_CHOICE );
811 
812  if( item ) // This menu exists, do nothing
813  return;
814 
815  menu = new wxMenu;
816 
817  for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
818  {
819  wxString label;
820 
821  if( s_Languages[ii].m_DoNotTranslate )
822  label = s_Languages[ii].m_Lang_Label;
823  else
824  label = wxGetTranslation( s_Languages[ii].m_Lang_Label );
825 
826  AddMenuItem( menu, s_Languages[ii].m_KI_Lang_Identifier,
827  label, KiBitmap(s_Languages[ii].m_Lang_Icon ),
828  wxITEM_CHECK );
829  }
830 
831  AddMenuItem( MasterMenu, menu,
833  _( "Set Language" ),
834  _( "Select application language (only for testing)" ),
835  KiBitmap( language_xpm ) );
836 
837  // Set Check mark on current selected language
838  for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
839  {
840  if( m_language_id == s_Languages[ii].m_WX_Lang_Identifier )
841  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, true );
842  else
843  menu->Check( s_Languages[ii].m_KI_Lang_Identifier, false );
844  }
845 }
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:379
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
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
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 185 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().

186 {
187  wxASSERT( wxTheApp );
188  return *wxTheApp;
189 }
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 237 of file pgm_base.cpp.

References EDA_FILE_SELECTOR(), and name.

Referenced by PANEL_COMMON_SETTINGS::OnTextEditorClick().

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

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

173 {
174  // unlike a normal destructor, this is designed to be called more than once safely:
175  m_common_settings.reset();
176 
177  delete m_pgm_checker;
178  m_pgm_checker = 0;
179 
180  delete m_locale;
181  m_locale = 0;
182 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:376
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:363
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 240 of file pgm_base.h.

References VTBL_ENTRY.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

240 { 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:382
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 200 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().

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

Referenced by FindKicadFile(), and KicadDatasPath().

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

Definition at line 219 of file pgm_base.h.

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

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

Definition at line 314 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().

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

Definition at line 221 of file pgm_base.h.

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

221 { return m_pdf_browser; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:395
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 260 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().

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

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

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

Definition at line 535 of file pgm_base.cpp.

References CAIRO_ANTIALIASING_MODE_KEY, ENBL_AUTO_PAN_KEY, ENBL_MOUSEWHEEL_PAN_KEY, ENBL_ZOOM_NO_CENTER_KEY, GAL_ANTIALIASING_MODE_KEY, GAL_DISPLAY_OPTIONS_KEY, GetChars(), GetNewConfig(), i, ICON_SCALE_KEY, KIGFX::NONE, pathEnvVariables, PCB_EDIT_FRAME_NAME, showEnvVarWarningDialog, traceEnvVars, and USE_ICONS_IN_MENUS_KEY.

536 {
537  wxASSERT( m_common_settings );
538 
539  m_help_size.x = 500;
540  m_help_size.y = 400;
541 
542  // This only effect the first time KiCad is run. The user's setting will be used for all
543  // subsequent runs. Menu icons are off by default on OSX and on for all other platforms.
544 #if defined( __WXMAC__ )
545  bool defaultUseIconsInMenus = false;
546 #else
547  bool defaultUseIconsInMenus = true;
548 #endif
549 
551 
552  if( !m_common_settings->HasEntry( USE_ICONS_IN_MENUS_KEY ) )
553  m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
554 
555  if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
558  {
559  // 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
560  // options only in pcbnew (which was the only canvas to support them). Since there's
561  // no single right answer to where to pull the common settings from, we might as well
562  // get them along with the hardware antialiasing option from pcbnew.
563  auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
564  wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
565 
566  if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
567  {
568  int temp;
569  wxString msg;
570  bool option;
571 
572  pcbnewConfig->Read( "PcbIconScale", &temp, 0 );
573  m_common_settings->Write( ICON_SCALE_KEY, temp );
574 
575  pcbnewConfig->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
576  m_common_settings->Write( ENBL_MOUSEWHEEL_PAN_KEY, option );
577 
578  pcbnewConfig->Read( ENBL_ZOOM_NO_CENTER_KEY, &option, false );
579  m_common_settings->Write( ENBL_ZOOM_NO_CENTER_KEY, option );
580 
581  pcbnewConfig->Read( ENBL_AUTO_PAN_KEY, &option, true );
582  m_common_settings->Write( ENBL_AUTO_PAN_KEY, option );
583  }
584 
585  if( !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
586  {
587  int temp;
588  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + GAL_ANTIALIASING_MODE_KEY,
591  }
592 
594  {
595  int temp;
596  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + CAIRO_ANTIALIASING_MODE_KEY,
599  }
600  }
601 
602  m_editor_name = m_common_settings->Read( "Editor" );
603 
604  wxString entry, oldPath;
605  wxArrayString entries;
606  long index = 0L;
607 
608  oldPath = m_common_settings->GetPath();
610 
611  while( m_common_settings->GetNextEntry( entry, index ) )
612  {
613  wxLogTrace( traceEnvVars,
614  "Enumerating over entry %s, %ld.", GetChars( entry ), index );
615  entries.Add( entry );
616  }
617 
618  for( unsigned i = 0; i < entries.GetCount(); i++ )
619  {
620  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
621 
622  if( m_local_env_vars[ entries[i] ].GetDefinedExternally() )
623  continue;
624 
625  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
626  }
627 
628  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
629  SetLocalEnvVariable( it->first, it->second.GetValue() );
630 
631  m_common_settings->SetPath( oldPath );
632 }
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:400
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform...
Definition: common.cpp:251
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
Class ENV_VAR_ITEM.
Definition: pgm_base.h:102
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:403
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:48
#define PCB_EDIT_FRAME_NAME
Definition: draw_frame.h:56
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:53
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:51
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:848
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:49
#define ICON_SCALE_KEY
Definition: pgm_base.h:46
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:54
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:397
size_t i
Definition: json11.cpp:597
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:45
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:55
wxString m_editor_name
Definition: pgm_base.h:396
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:132
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 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
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:382
VTBL_ENTRY void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:223
void PGM_BASE::SaveCommonSettings ( )

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

Definition at line 635 of file pgm_base.cpp.

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

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

636 {
637  // m_common_settings is not initialized until fairly late in the
638  // process startup: InitPgm(), so test before using:
639  if( m_common_settings )
640  {
641  wxString cur_dir = wxGetCwd();
642 
643  m_common_settings->Write( workingDirKey, cur_dir );
645 
646  // Save the local environment variables.
648 
649  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
650  {
651  if( it->second.GetDefinedExternally() )
652  continue;
653 
654  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
655  GetChars( it->first ), GetChars( it->second.GetValue() ) );
656  m_common_settings->Write( it->first, it->second.GetValue() );
657  }
658 
659  m_common_settings->SetPath( ".." );
660  }
661 }
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:400
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
static const wxChar workingDirKey[]
Definition: pgm_base.h:328
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:403
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:132
void PGM_BASE::SetEditorName ( const wxString &  aFileName)

Definition at line 192 of file pgm_base.cpp.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

193 {
194  m_editor_name = aFileName;
195  wxASSERT( m_common_settings );
196  m_common_settings->Write( "Editor", aFileName );
197 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
wxString m_editor_name
Definition: pgm_base.h:396
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 493 of file pgm_base.cpp.

References UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

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

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

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

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

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

References arrayDim(), and traceLocale.

Referenced by KIWAY::SetLanguage().

757 {
758  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
759  menu_id, arrayDim( s_Languages ) );
760 
761  for( unsigned ii = 0; ii < arrayDim( s_Languages ); ii++ )
762  {
763  if( menu_id == s_Languages[ii].m_KI_Lang_Identifier )
764  {
765  setLanguageId( s_Languages[ii].m_WX_Lang_Identifier );
766  break;
767  }
768  }
769 }
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:385
const wxChar *const traceLocale
Flag to enable locale debug output.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
of elements in an array. This implements type-safe compile time checking
Definition: macros.h:99
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 772 of file pgm_base.cpp.

References i, SystemDirsAppend(), and traceLocale.

773 {
774  SEARCH_STACK guesses;
775 
776  SystemDirsAppend( &guesses );
777 
778  // Add our internat dir to the wxLocale catalog of paths
779  for( unsigned i = 0; i < guesses.GetCount(); i++ )
780  {
781  wxFileName fn( guesses[i], wxEmptyString );
782 
783  // Append path for Windows and unix KiCad package install
784  fn.AppendDir( "share" );
785  fn.AppendDir( "internat" );
786 
787  if( fn.IsDirReadable() )
788  {
789  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
790  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
791  }
792 
793  // Append path for unix standard install
794  fn.RemoveLastDir();
795  fn.AppendDir( "kicad" );
796  fn.AppendDir( "internat" );
797 
798  if( fn.IsDirReadable() )
799  {
800  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
801  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
802  }
803  }
804 }
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 848 of file pgm_base.cpp.

References GetChars(), and traceEnvVars.

849 {
850  wxString env;
851 
852  // Check to see if the environment variable is already set.
853  if( wxGetEnv( aName, &env ) )
854  {
855  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
856  GetChars( aName ), GetChars( env ) );
857  return env == aValue;
858  }
859 
860  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
861  GetChars( aName ), GetChars( aValue ) );
862 
863  return wxSetEnv( aName, aValue );
864 }
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 867 of file pgm_base.cpp.

References GetChars(), pathEnvVariables, and traceEnvVars.

Referenced by DIALOG_CONFIGURE_PATHS::TransferDataFromWindow().

868 {
869  m_local_env_vars.clear();
870  m_local_env_vars = aEnvVarMap;
871 
872  if( m_common_settings )
873  m_common_settings->DeleteGroup( pathEnvVariables );
874 
876 
877  // Overwrites externally defined environment variable until the next time the application
878  // is run.
879  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
880  {
881  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
882  GetChars( it->first ), GetChars( it->second.GetValue() ) );
883  wxSetEnv( it->first, it->second.GetValue() );
884  }
885 }
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:400
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ...
Definition: pgm_base.cpp:635
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
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
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:132
VTBL_ENTRY void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inline

Definition at line 223 of file pgm_base.h.

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

223 { m_pdf_browser = aFileName; }
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:395
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 231 of file pgm_base.h.

232  {
233  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
234  }
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:382
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:395
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 }
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:367
VTBL_ENTRY const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:221
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:382

Member Data Documentation

wxString PGM_BASE::m_bin_dir
protected

full path to this program

Definition at line 370 of file pgm_base.h.

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

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

Definition at line 367 of file pgm_base.h.

Referenced by ReadPdfBrowserInfos(), and WritePdfBrowserInfos().

wxString PGM_BASE::m_editor_name
protected

Definition at line 396 of file pgm_base.h.

wxSize PGM_BASE::m_help_size
protected

Definition at line 397 of file pgm_base.h.

wxString PGM_BASE::m_kicad_env
protected

The KICAD system environment variable.

Definition at line 373 of file pgm_base.h.

int PGM_BASE::m_language_id
protected

The current language setting.

Definition at line 379 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 400 of file pgm_base.h.

wxLocale* PGM_BASE::m_locale
protected

The current locale.

Definition at line 376 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 395 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 363 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 403 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 382 of file pgm_base.h.

Referenced by ReadPdfBrowserInfos(), and WritePdfBrowserInfos().

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

Definition at line 328 of file pgm_base.h.


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