KiCad PCB EDA Suite
PGM_SINGLE_TOP Struct Reference

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

Inheritance diagram for PGM_SINGLE_TOP:
PGM_BASE

Public Member Functions

bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 Function MacOpenFile is specific to MacOSX (not used under Linux or Windows). More...
 
VTBL_ENTRY wxConfigBase * CommonSettings () const
 
VTBL_ENTRY void SetEditorName (const wxString &aFileName)
 
VTBL_ENTRY const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
VTBL_ENTRY const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
VTBL_ENTRY bool IsKicadEnvVariableDefined () const
 
VTBL_ENTRY const wxString & GetKicadEnvVariable () const
 
VTBL_ENTRY const wxString & GetExecutablePath () const
 
VTBL_ENTRY wxLocale * GetLocale ()
 
VTBL_ENTRY const wxString & GetPdfBrowserName () const
 
VTBL_ENTRY void SetPdfBrowserName (const wxString &aFileName)
 
VTBL_ENTRY bool UseSystemPdfBrowser () const
 Function UseSystemPdfBrowser returns true if the PDF browser is the default (system) PDF browser and false if the PDF browser is the preferred (selected) browser, else returns false if there is no selected browser. More...
 
VTBL_ENTRY void ForceSystemPdfBrowser (bool aFlg)
 Function ForceSystemPdfBrowser forces the use of system PDF browser, even if a preferred PDF browser is set. More...
 
VTBL_ENTRY bool SetLanguage (bool first_time=false)
 Function SetLanguage sets the dictionary file name for internationalization. More...
 
VTBL_ENTRY void SetLanguageIdentifier (int menu_id)
 Function SetLanguageIdentifier sets in .m_language_id member the wxWidgets language identifier Id from the KiCad menu id (internal menu identifier). More...
 
VTBL_ENTRY int GetSelectedLanguageIdentifier () const
 
VTBL_ENTRY void SetLanguagePath ()
 
VTBL_ENTRY void ReadPdfBrowserInfos ()
 Function ReadPdfBrowserInfos reads the PDF browser choice from the common configuration. More...
 
VTBL_ENTRY void WritePdfBrowserInfos ()
 Function WritePdfBrowserInfos saves the PDF browser choice to the common configuration. More...
 
VTBL_ENTRY bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Function SetLocalEnvVariable. More...
 
VTBL_ENTRY void SetLocalEnvVariables (const ENV_VAR_MAP &aEnvVarMap)
 Function SetLocalEnvVariables. More...
 
VTBL_ENTRY const ENV_VAR_MAPGetLocalEnvVariables () const
 
VTBL_ENTRY wxApp & App ()
 Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm ()
 Function initPgm initializes this program (process) in a KiCad standard way, using some generalized techniques. More...
 
void Destroy ()
 
void SaveCommonSettings ()
 Function saveCommonSettings saves the program (process) settings subset which are stored .kicad_common. More...
 

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

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

Definition at line 62 of file single_top.cpp.

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
inherited

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

Should return what wxGetApp() returns.

Definition at line 163 of file pgm_base.cpp.

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

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

◆ AskUserForPreferredEditor()

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

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

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

Definition at line 215 of file pgm_base.cpp.

216 {
217  // Create a mask representing the executable files in the current platform
218 #ifdef __WINDOWS__
219  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
220 #else
221  wxString mask( _( "Executable file (*)|*" ) );
222 #endif
223 
224  // Extract the path, name and extension from the default editor (even if the editor's
225  // name was empty, this method will succeed and return empty strings).
226  wxString path, name, ext;
227  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
228 
229  // Show the modal editor and return the file chosen (may be empty if the user cancels
230  // the dialog).
231  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path,
232  name, ext, mask,
233  NULL, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
234  true );
235 }
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
Function EDA_FILE_SELECTOR.
Definition: gestfich.cpp:82
const char * name
Definition: DXF_plotter.cpp:61
#define _(s)
LanguagesList Note: because this list is not created on the fly, wxTranslation must be called when a ...
Definition: pgm_base.cpp:110

References _, EDA_FILE_SELECTOR(), and name.

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

◆ CommonSettings()

◆ Destroy()

void PGM_BASE::Destroy ( )
inherited

Definition at line 150 of file pgm_base.cpp.

151 {
152  // unlike a normal destructor, this is designed to be called more than once safely:
153  m_common_settings.reset();
154 
155  delete m_pgm_checker;
156  m_pgm_checker = 0;
157 
158  delete m_locale;
159  m_locale = 0;
160 }
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:375
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:384
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:371

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

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

◆ ForceSystemPdfBrowser()

VTBL_ENTRY void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlineinherited

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

Definition at line 252 of file pgm_base.h.

252 { 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:390

References PGM_BASE::m_use_system_pdf_browser.

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

◆ GetEditorName()

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

Return the preferred editor name.

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

Definition at line 178 of file pgm_base.cpp.

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

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

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

◆ GetExecutablePath()

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

◆ GetKicadEnvVariable()

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

Definition at line 227 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

Referenced by FindKicadFile(), and KicadDatasPath().

◆ GetLocale()

VTBL_ENTRY wxLocale* PGM_BASE::GetLocale ( )
inlineinherited

Definition at line 231 of file pgm_base.h.

231 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:384

References PGM_BASE::m_locale.

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

◆ GetLocalEnvVariables()

◆ GetPdfBrowserName()

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

Definition at line 233 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

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

◆ GetSelectedLanguageIdentifier()

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

Definition at line 279 of file pgm_base.h.

279 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:387

References PGM_BASE::m_language_id.

Referenced by AddMenuLanguageList().

◆ InitPgm()

bool PGM_BASE::InitPgm ( )
inherited

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

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

But nothing relating to DSOs or projects.

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

Definition at line 238 of file pgm_base.cpp.

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

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

Referenced by PGM_KICAD::OnPgmInit().

◆ IsKicadEnvVariableDefined()

VTBL_ENTRY bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlineinherited

Definition at line 225 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

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

Definition at line 513 of file pgm_base.cpp.

514 {
515  wxASSERT( m_common_settings );
516 
517  m_help_size.x = 500;
518  m_help_size.y = 400;
519 
520  // This only effect the first time KiCad is run. The user's setting will be used for all
521  // subsequent runs. Menu icons are off by default on OSX and on for all other platforms.
522 #if defined( __WXMAC__ )
523  bool defaultUseIconsInMenus = false;
524 #else
525  bool defaultUseIconsInMenus = true;
526 #endif
527 
529 
530  if( !m_common_settings->HasEntry( USE_ICONS_IN_MENUS_KEY ) )
531  m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
532 
533  if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
536  {
537  // 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
538  // options only in pcbnew (which was the only canvas to support them). Since there's
539  // no single right answer to where to pull the common settings from, we might as well
540  // get them along with the hardware antialiasing option from pcbnew.
541  auto pcbnewConfig = GetNewConfig( wxString::FromUTF8( "pcbnew" ) );
542  wxString pcbFrameKey( PCB_EDIT_FRAME_NAME );
543 
544  if( !m_common_settings->HasEntry( ICON_SCALE_KEY ) )
545  {
546  int temp;
547  wxString msg;
548  bool option;
549 
550  pcbnewConfig->Read( "PcbIconScale", &temp, 0 );
551  m_common_settings->Write( ICON_SCALE_KEY, temp );
552 
553  pcbnewConfig->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option, false );
554  m_common_settings->Write( ENBL_MOUSEWHEEL_PAN_KEY, option );
555 
556  pcbnewConfig->Read( ENBL_ZOOM_NO_CENTER_KEY, &option, false );
557  m_common_settings->Write( ENBL_ZOOM_NO_CENTER_KEY, option );
558 
559  pcbnewConfig->Read( ENBL_AUTO_PAN_KEY, &option, true );
560  m_common_settings->Write( ENBL_AUTO_PAN_KEY, option );
561  }
562 
563  if( !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
564  {
565  int temp;
566  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + GAL_ANTIALIASING_MODE_KEY,
569  }
570 
572  {
573  int temp;
574  pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + CAIRO_ANTIALIASING_MODE_KEY,
577  }
578  }
579 
580  m_editor_name = m_common_settings->Read( "Editor" );
581 
582  wxString entry, oldPath;
583  wxArrayString entries;
584  long index = 0L;
585 
586  oldPath = m_common_settings->GetPath();
588 
589  while( m_common_settings->GetNextEntry( entry, index ) )
590  {
591  wxLogTrace( traceEnvVars,
592  "Enumerating over entry %s, %ld.", GetChars( entry ), index );
593 
594  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
595  // it is found in config. (It is reserved and defined as project path)
596  if( entry == PROJECT_VAR_NAME )
597  continue;
598 
599  entries.Add( entry );
600  }
601 
602  for( unsigned i = 0; i < entries.GetCount(); i++ )
603  {
604  wxString val = m_common_settings->Read( entries[i], wxEmptyString );
605 
606  if( m_local_env_vars[ entries[i] ].GetDefinedExternally() )
607  continue;
608 
609  m_local_env_vars[ entries[i] ] = ENV_VAR_ITEM( val, wxGetEnv( entries[i], NULL ) );
610  }
611 
612  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
613  {
614  SetLocalEnvVariable( it->first, it->second.GetValue() );
615  }
616 
617  m_common_settings->SetPath( oldPath );
618 }
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:408
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
Definition: common.cpp:256
std::unique_ptr< wxConfigBase > m_common_settings
Configuration settings common to all KiCad program modules, like as in $HOME/.kicad_common.
Definition: pgm_base.h:375
Class ENV_VAR_ITEM.
Definition: pgm_base.h:114
static const wxChar showEnvVarWarningDialog[]
Definition: pgm_base.cpp:68
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:411
#define ENBL_ZOOM_NO_CENTER_KEY
Definition: pgm_base.h:50
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:55
#define ENBL_AUTO_PAN_KEY
Definition: pgm_base.h:53
VTBL_ENTRY bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Function SetLocalEnvVariable.
Definition: pgm_base.cpp:793
#define ENBL_MOUSEWHEEL_PAN_KEY
Definition: pgm_base.h:51
#define ICON_SCALE_KEY
Definition: pgm_base.h:47
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:56
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
wxSize m_help_size
Definition: pgm_base.h:405
size_t i
Definition: json11.cpp:597
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:46
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:57
wxString m_editor_name
Definition: pgm_base.h:404
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:144
#define PCB_EDIT_FRAME_NAME

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

Referenced by PGM_BASE::InitPgm().

◆ MacOpenFile()

void PGM_SINGLE_TOP::MacOpenFile ( const wxString &  aFileName)
inlineoverridevirtual

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

MacOSX requires it for file association.

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

Implements PGM_BASE.

Definition at line 77 of file single_top.cpp.

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

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

◆ OnPgmExit()

void PGM_SINGLE_TOP::OnPgmExit ( )
inline

Definition at line 66 of file single_top.cpp.

67  {
68  Kiway.OnKiwayEnd();
69 
71 
72  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
73  // earlier than wxApp and earlier than static destruction would.
75  }
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:621
void Destroy()
Definition: pgm_base.cpp:150
void OnKiwayEnd()
Definition: kiway.cpp:517
KIWAY Kiway

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

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

◆ OnPgmInit()

bool PGM_SINGLE_TOP::OnPgmInit ( )

Definition at line 274 of file single_top.cpp.

275 {
276 #if defined(DEBUG)
277  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
278 
279  if( !wxIsAbsolutePath( absoluteArgv0 ) )
280  {
281  wxLogError( wxT( "No meaningful argv[0]" ) );
282  return false;
283  }
284 #endif
285 
286  if( !InitPgm() )
287  return false;
288 
289 #if !defined(BUILD_KIWAY_DLL)
290 
291  // Only bitmap2component and pcb_calculator use this code currently, as they
292  // are not split to use single_top as a link image separate from a *.kiface.
293  // i.e. they are single part link images so don't need to load a *.kiface.
294 
295  // Get the getter, it is statically linked into this binary image.
297 
298  int kiface_version;
299 
300  // Get the KIFACE.
301  KIFACE* kiface = getter( &kiface_version, KIFACE_VERSION, this );
302 
303  // Trick the KIWAY into thinking it loaded a KIFACE, by recording the KIFACE
304  // in the KIWAY. It needs to be there for KIWAY::OnKiwayEnd() anyways.
305  Kiway.set_kiface( KIWAY::KifaceType( TOP_FRAME ), kiface );
306 #endif
307 
308  // Open project or file specified on the command line:
309  int argc = App().argc;
310 
311  int args_offset = 1;
312 
313  FRAME_T appType = TOP_FRAME;
314 
315  const struct
316  {
317  wxString name;
318  FRAME_T type;
319  } frameTypes[] = {
320  { wxT( "pcb" ), FRAME_PCB },
321  { wxT( "fpedit" ), FRAME_PCB_MODULE_EDITOR },
322  { wxT( "" ), FRAME_T_COUNT }
323  };
324 
325  if( argc > 2 )
326  {
327  if( App().argv[1] == "--frame" )
328  {
329  wxString appName = App().argv[2];
330  appType = FRAME_T_COUNT;
331 
332  for( int i = 0; frameTypes[i].type != FRAME_T_COUNT; i++ )
333  {
334  const auto& frame = frameTypes[i];
335  if(frame.name == appName)
336  {
337  appType = frame.type;
338  }
339  }
340  args_offset += 2;
341 
342  if( appType == FRAME_T_COUNT )
343  {
344  wxLogError( wxT( "Unknown frame: %s" ), appName );
345  return false;
346  }
347  }
348  }
349 
350 
351  // Use KIWAY to create a top window, which registers its existence also.
352  // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
353  // and is one of the types in FRAME_T.
354  KIWAY_PLAYER* frame = Kiway.Player( appType, true );
355 
356  Kiway.SetTop( frame );
357 
358  App().SetTopWindow( frame ); // wxApp gets a face.
359 
360 
361  if( argc > args_offset )
362  {
363  /*
364  gerbview handles multiple project data files, i.e. gerber files on
365  cmd line. Others currently do not, they handle only one. For common
366  code simplicity we simply pass all the arguments in however, each
367  program module can do with them what they want, ignore, complain
368  whatever. We don't establish policy here, as this is a multi-purpose
369  launcher.
370  */
371 
372  std::vector<wxString> argSet;
373 
374  for( int i = args_offset; i < argc; ++i )
375  {
376  argSet.push_back( App().argv[i] );
377  }
378 
379  // special attention to a single argument: argv[1] (==argSet[0])
380  if( argc == args_offset + 1 )
381  {
382  wxFileName argv1( argSet[0] );
383 
384 #if defined(PGM_DATA_FILE_EXT)
385  // PGM_DATA_FILE_EXT, if present, may be different for each compile,
386  // it may come from CMake on the compiler command line, but often does not.
387  // This facillity is mostly useful for those program modules
388  // supporting a single argv[1].
389  if( !argv1.GetExt() )
390  argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
391 #endif
392  argv1.MakeAbsolute();
393 
394  argSet[0] = argv1.GetFullPath();
395  }
396 
397  // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
398  if( !frame->OpenProjectFiles( argSet ) )
399  {
400  // OpenProjectFiles() API asks that it report failure to the UI.
401  // Nothing further to say here.
402 
403  // We've already initialized things at this point, but wx won't call OnExit if
404  // we fail out. Call our own cleanup routine here to ensure the relevant resources
405  // are freed at the right time (if they aren't, segfaults will occur).
406  OnPgmExit();
407 
408  // Fail the process startup if the file could not be opened,
409  // although this is an optional choice, one that can be reversed
410  // also in the KIFACE specific OpenProjectFiles() return value.
411  return false;
412  }
413  }
414 
415  frame->Show();
416 
417  return true;
418 }
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Function OpenProjectFiles is abstract, and opens a project or set of files given by aFileList.
Definition: kiway_player.h:118
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
Definition: kiway_player.h:59
static FACE_T KifaceType(FRAME_T aFrameType)
Function KifaceType is a simple mapping function which returns the FACE_T which is known to implement...
Definition: kiway.cpp:271
void OnPgmExit()
Definition: single_top.cpp:66
#define KIFACE_VERSION
Definition: kiway.h:111
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
VTBL_ENTRY wxApp & App()
Function App returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP,...
Definition: pgm_base.cpp:163
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:398
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:321
KIFACE * KIFACE_GETTER(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
No name mangling. Each KIFACE (DSO/DLL) will implement this once.
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Function Pointer KIFACE_GETTER_FUNC points to the one and only KIFACE export.
Definition: kiway.h:454
void SetTop(wxFrame *aTop)
Function SetTop tells this KIWAY about the top most frame in the program and optionally allows it to ...
Definition: kiway.cpp:77
const char * name
Definition: DXF_plotter.cpp:61
size_t i
Definition: json11.cpp:597
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:151
bool InitPgm()
Function initPgm initializes this program (process) in a KiCad standard way, using some generalized t...
Definition: pgm_base.cpp:238
return & kiface
Definition: pcbnew.cpp:193
KIWAY Kiway

References FRAME_PCB, FRAME_PCB_MODULE_EDITOR, FRAME_T_COUNT, PGM_BASE::GetExecutablePath(), i, kiface, KIFACE_GETTER(), KIFACE_VERSION, KIWAY::KifaceType(), Kiway, name, KIWAY_PLAYER::OpenProjectFiles(), KIWAY::Player(), KIWAY::set_kiface(), and KIWAY::SetTop().

Referenced by APP_SINGLE_TOP::OnInit().

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
inherited

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

Definition at line 42 of file eda_doc.cpp.

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

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

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

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )
inherited

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

Definition at line 621 of file pgm_base.cpp.

622 {
623  // m_common_settings is not initialized until fairly late in the
624  // process startup: InitPgm(), so test before using:
625  if( m_common_settings )
626  {
627  wxString cur_dir = wxGetCwd();
628 
629  m_common_settings->Write( workingDirKey, cur_dir );
631 
632  // Save the local environment variables.
634 
635  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
636  {
637  if( it->second.GetDefinedExternally() )
638  continue;
639 
640  wxLogTrace( traceEnvVars, "Saving environment variable config entry %s as %s",
641  GetChars( it->first ), GetChars( it->second.GetValue() ) );
642  m_common_settings->Write( it->first, it->second.GetValue() );
643  }
644 
645  m_common_settings->SetPath( ".." );
646  }
647 }
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:408
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:375
static const wxChar workingDirKey[]
Definition: pgm_base.h:336
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:411
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:144

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

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

◆ SetEditorName()

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

Definition at line 170 of file pgm_base.cpp.

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

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

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

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protectedinherited

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

Returns
bool - true if success, else false.

Definition at line 471 of file pgm_base.cpp.

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

References PGM_BASE::m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by PGM_BASE::InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( bool  first_time = false)
inherited

Function SetLanguage sets the dictionary file name for internationalization.

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

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

Definition at line 650 of file pgm_base.cpp.

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

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

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

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotectedinherited

Trap all changes in here, simplifies debugging.

Definition at line 393 of file pgm_base.h.

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

References PGM_BASE::m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
inherited

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

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

Definition at line 742 of file pgm_base.cpp.

743 {
744  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
745  menu_id, (int)arrayDim( LanguagesList )-1 );
746 
747  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
748  {
749  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
750  {
751  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
752  break;
753  }
754  }
755 }
LANGUAGE_DESCR LanguagesList[]
Definition: pgm_base.cpp:80
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:81
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:393
const wxChar *const traceLocale
Flag to enable locale debug output.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108

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

Referenced by KIWAY::SetLanguage().

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
inherited

Definition at line 758 of file pgm_base.cpp.

759 {
760  SEARCH_STACK guesses;
761 
762  SystemDirsAppend( &guesses );
763 
764  // Add our internat dir to the wxLocale catalog of paths
765  for( unsigned i = 0; i < guesses.GetCount(); i++ )
766  {
767  wxFileName fn( guesses[i], wxEmptyString );
768 
769  // Append path for Windows and unix KiCad package install
770  fn.AppendDir( "share" );
771  fn.AppendDir( "internat" );
772 
773  if( fn.IsDirReadable() )
774  {
775  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
776  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
777  }
778 
779  // Append path for unix standard install
780  fn.RemoveLastDir();
781  fn.AppendDir( "kicad" );
782  fn.AppendDir( "internat" );
783 
784  if( fn.IsDirReadable() )
785  {
786  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
787  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
788  }
789  }
790 }
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
const wxChar *const traceLocale
Flag to enable locale debug output.
size_t i
Definition: json11.cpp:597

References i, SystemDirsAppend(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ SetLocalEnvVariable()

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

Function SetLocalEnvVariable.

Sets the environment variable aName to aValue.

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

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

Definition at line 793 of file pgm_base.cpp.

794 {
795  wxString env;
796 
797  // Check to see if the environment variable is already set.
798  if( wxGetEnv( aName, &env ) )
799  {
800  wxLogTrace( traceEnvVars, "Environment variable %s already set to %s.",
801  GetChars( aName ), GetChars( env ) );
802  return env == aValue;
803  }
804 
805  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
806  GetChars( aName ), GetChars( aValue ) );
807 
808  return wxSetEnv( aName, aValue );
809 }
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101

References GetChars(), and traceEnvVars.

Referenced by PGM_BASE::loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( const ENV_VAR_MAP aEnvVarMap)
inherited

Function SetLocalEnvVariables.

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

Parameters
aEnvVarMapis a ENV_VAR_MAP object containing the new environment variables.

Definition at line 812 of file pgm_base.cpp.

813 {
814  m_local_env_vars.clear();
815  m_local_env_vars = aEnvVarMap;
816 
817  if( m_common_settings )
818  m_common_settings->DeleteGroup( pathEnvVariables );
819 
821 
822  // Overwrites externally defined environment variable until the next time the application
823  // is run.
824  for( ENV_VAR_MAP_ITER it = m_local_env_vars.begin(); it != m_local_env_vars.end(); ++it )
825  {
826  wxLogTrace( traceEnvVars, "Setting local environment variable %s to %s.",
827  GetChars( it->first ), GetChars( it->second.GetValue() ) );
828  wxSetEnv( it->first, it->second.GetValue() );
829  }
830 }
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:408
void SaveCommonSettings()
Function saveCommonSettings saves the program (process) settings subset which are stored ....
Definition: pgm_base.cpp:621
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:375
static const wxChar traceEnvVars[]
Definition: pgm_base.cpp:69
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
std::map< wxString, ENV_VAR_ITEM >::iterator ENV_VAR_MAP_ITER
Definition: pgm_base.h:144

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

Referenced by DIALOG_CONFIGURE_PATHS::TransferDataFromWindow().

◆ SetPdfBrowserName()

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

Definition at line 235 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

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

◆ UseSystemPdfBrowser()

VTBL_ENTRY bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlineinherited

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

Definition at line 243 of file pgm_base.h.

244  {
245  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
246  }
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:390
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:403

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

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
inherited

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

Definition at line 55 of file eda_doc.cpp.

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

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

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protectedinherited

full path to this program

Definition at line 378 of file pgm_base.h.

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

◆ m_common_settings

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

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protectedinherited

◆ m_help_size

wxSize PGM_BASE::m_help_size
protectedinherited

Definition at line 405 of file pgm_base.h.

Referenced by PGM_BASE::loadCommonSettings().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protectedinherited

The KICAD system environment variable.

Definition at line 381 of file pgm_base.h.

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

◆ m_language_id

int PGM_BASE::m_language_id
protectedinherited

The current language setting.

Definition at line 387 of file pgm_base.h.

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

◆ m_local_env_vars

ENV_VAR_MAP PGM_BASE::m_local_env_vars
protectedinherited

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

Definition at line 408 of file pgm_base.h.

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

◆ m_locale

wxLocale* PGM_BASE::m_locale
protectedinherited

The current locale.

Definition at line 384 of file pgm_base.h.

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

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protectedinherited

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

Definition at line 403 of file pgm_base.h.

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

◆ m_pgm_checker

wxSingleInstanceChecker* PGM_BASE::m_pgm_checker
protectedinherited

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

Definition at line 371 of file pgm_base.h.

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

◆ m_show_env_var_dialog

bool PGM_BASE::m_show_env_var_dialog
protectedinherited

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

Definition at line 411 of file pgm_base.h.

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

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protectedinherited

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

Definition at line 390 of file pgm_base.h.

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

◆ workingDirKey

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

Definition at line 336 of file pgm_base.h.

Referenced by PGM_BASE::SaveCommonSettings().


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