KiCad PCB EDA Suite
PGM_KICAD Class Reference

PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP into KIFACE_I. More...

#include <pgm_kicad.h>

Inheritance diagram for PGM_KICAD:
PGM_BASE

Public Member Functions

 PGM_KICAD ()
 
 ~PGM_KICAD () throw ()
 
bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 Specific to MacOSX (not used under Linux or Windows). More...
 
APP_SETTINGS_BASEPgmSettings ()
 
SEARCH_STACKSysSearch ()
 
wxString GetHelpFileName ()
 
void Destroy ()
 
virtual SETTINGS_MANAGERGetSettingsManager () const
 
virtual COMMON_SETTINGSGetCommonSettings () const
 
virtual void SetEditorName (const wxString &aFileName)
 
virtual const wxString & GetEditorName (bool aCanShowFileChooser=true)
 Return the preferred editor name. More...
 
virtual const wxString AskUserForPreferredEditor (const wxString &aDefaultEditor=wxEmptyString)
 Shows a dialog that instructs the user to select a new preferred editor. More...
 
virtual bool IsKicadEnvVariableDefined () const
 
virtual const wxString & GetKicadEnvVariable () const
 
virtual const wxString & GetExecutablePath () const
 
virtual wxLocale * GetLocale ()
 
virtual const wxString & GetPdfBrowserName () const
 
virtual void SetPdfBrowserName (const wxString &aFileName)
 
virtual bool UseSystemPdfBrowser () const
 
virtual void ForceSystemPdfBrowser (bool aFlg)
 Force the use of system PDF browser, even if a preferred PDF browser is set. More...
 
virtual bool SetLanguage (wxString &aErrMsg, bool first_time=false)
 Set the dictionary file name for internationalization. More...
 
bool SetDefaultLanguage (wxString &aErrMsg)
 Set the default language without reference to any preferences. More...
 
virtual void SetLanguageIdentifier (int menu_id)
 Set in .m_language_id member the wxWidgets language identifier ID fromthe KiCad menu id (internal menu identifier). More...
 
virtual int GetSelectedLanguageIdentifier () const
 
virtual void SetLanguagePath ()
 
virtual void ReadPdfBrowserInfos ()
 Read the PDF browser choice from the common configuration. More...
 
virtual void WritePdfBrowserInfos ()
 Save the PDF browser choice to the common configuration. More...
 
virtual bool SetLocalEnvVariable (const wxString &aName, const wxString &aValue)
 Sets the environment variable aName to aValue. More...
 
virtual void SetLocalEnvVariables ()
 Updates the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTINGS. More...
 
virtual ENV_VAR_MAPGetLocalEnvVariables () const
 
virtual wxApp & App ()
 Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe. More...
 
bool InitPgm (bool aHeadless=false)
 Initialize this program. More...
 
void SaveCommonSettings ()
 Save the program (process) settings subset which are stored .kicad_common. More...
 

Public Attributes

bool m_Printing
 wxWidgets on MSW tends to crash if you spool up more than one print job at a time. More...
 
int m_ModalDialogCount
 

Static Public Attributes

static const wxChar workingDirKey []
 

Protected Member Functions

void loadCommonSettings ()
 Loads internal settings from COMMON_SETTINGS. More...
 
void setLanguageId (int aId)
 Trap all changes in here, simplifies debugging. More...
 
bool setExecutablePath ()
 Find the path to the executable and stores it in PGM_BASE::m_bin_dir. More...
 

Protected Attributes

BIN_MOD m_bm
 
std::unique_ptr< SETTINGS_MANAGERm_settings_manager
 
wxSingleInstanceChecker * m_pgm_checker
 prevents multiple instances of a program from being run at the same time. 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
 
bool m_show_env_var_dialog
 Flag to indicate if the environment variable overwrite warning dialog should be shown. More...
 

Detailed Description

PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP into KIFACE_I.

KIFACE_I is not applicable in the project manager since it is not a KIFACE. This header is in the kicad directory since nobody else needs to know about it.

Definition at line 38 of file pgm_kicad.h.

Constructor & Destructor Documentation

◆ PGM_KICAD()

PGM_KICAD::PGM_KICAD ( )
inline

Definition at line 41 of file pgm_kicad.h.

41  :
42  m_bm( "kicad" ) // indicates a "$HOME/.kicad wxConfig like" config file.
43  {}
BIN_MOD m_bm
Definition: pgm_kicad.h:68

◆ ~PGM_KICAD()

PGM_KICAD::~PGM_KICAD ( )
throw (
)
inline

Definition at line 45 of file pgm_kicad.h.

46  {
47  Destroy();
48  }
void Destroy()
Definition: kicad.cpp:243

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
virtualinherited

Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.

This should return what wxGetApp() returns.

Definition at line 133 of file pgm_base.cpp.

134 {
135  wxASSERT( wxTheApp );
136  return *wxTheApp;
137 }

Referenced by PGM_BASE::InitPgm(), MacOpenFile(), PGM_TEST_FRAME::MacOpenFile(), PGM_SINGLE_TOP::MacOpenFile(), PGM_MOCK_EESCHEMA_FRAME::MacOpenFile(), and OnPgmInit().

◆ AskUserForPreferredEditor()

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

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

185 {
186  // Create a mask representing the executable files in the current platform
187 #ifdef __WINDOWS__
188  wxString mask( _( "Executable file (*.exe)|*.exe" ) );
189 #else
190  wxString mask( _( "Executable file (*)|*" ) );
191 #endif
192 
193  // Extract the path, name and extension from the default editor (even if the editor's
194  // name was empty, this method will succeed and return empty strings).
195  wxString path, name, ext;
196  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
197 
198  // Show the modal editor and return the file chosen (may be empty if the user cancels
199  // the dialog).
200  return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path, name, ext, mask, NULL,
201  wxFD_OPEN | wxFD_FILE_MUST_EXIST, true );
202 }
#define NULL
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)
A helper function that wraps a call to wxFileSelector.
Definition: gestfich.cpp:52
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:98

References _, EDA_FILE_SELECTOR(), name, NULL, and path.

Referenced by PGM_BASE::GetEditorName().

◆ Destroy()

void PGM_KICAD::Destroy ( void  )

Definition at line 243 of file kicad.cpp.

244 {
245  // unlike a normal destructor, this is designed to be called more
246  // than once safely:
247 
248  m_bm.End();
249 
251 }
void Destroy()
Definition: pgm_base.cpp:122
BIN_MOD m_bm
Definition: pgm_kicad.h:68
void End()
Definition: bin_mod.cpp:50

References PGM_BASE::Destroy(), BIN_MOD::End(), and m_bm.

Referenced by OnPgmExit(), and ~PGM_KICAD().

◆ ForceSystemPdfBrowser()

virtual void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlinevirtualinherited

Force the use of system PDF browser, even if a preferred PDF browser is set.

Definition at line 179 of file pgm_base.h.

179 { 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:323

References PGM_BASE::m_use_system_pdf_browser.

Referenced by PGM_BASE::PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtualinherited

Definition at line 391 of file pgm_base.cpp.

392 {
394 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:127
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:305
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.

References SETTINGS_MANAGER::GetCommonSettings(), PGM_BASE::GetSettingsManager(), and PGM_BASE::m_settings_manager.

Referenced by PGM_BASE::GetLocalEnvVariables(), PGM_BASE::InitPgm(), PGM_BASE::loadCommonSettings(), PGM_BASE::ReadPdfBrowserInfos(), PGM_BASE::SaveCommonSettings(), PGM_BASE::SetEditorName(), PGM_BASE::SetLanguage(), PGM_BASE::SetLocalEnvVariables(), and PGM_BASE::WritePdfBrowserInfos().

◆ GetEditorName()

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

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

149 {
150  wxString editorname = m_editor_name;
151 
152  if( !editorname )
153  {
154  if( !wxGetEnv( "EDITOR", &editorname ) )
155  {
156  // If there is no EDITOR variable set, try the desktop default
157 #ifdef __WXMAC__
158  editorname = "/usr/bin/open";
159 #elif __WXX11__
160  editorname = "/usr/bin/xdg-open";
161 #endif
162  }
163  }
164 
165  // If we still don't have an editor name show a dialog asking the user to select one
166  if( !editorname && aCanShowFileChooser )
167  {
168  DisplayInfoMessage( NULL, _( "No default editor found, you must choose it" ) );
169 
170  editorname = AskUserForPreferredEditor();
171  }
172 
173  // If we finally have a new editor name request it to be copied to m_editor_name and
174  // saved to the preferences file.
175  if( !editorname.IsEmpty() )
176  SetEditorName( editorname );
177 
178  // m_editor_name already has the same value that editorname, or empty if no editor was
179  // found/chosen.
180  return m_editor_name;
181 }
virtual void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:140
virtual const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:184
#define NULL
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:98
wxString m_editor_name
Definition: pgm_base.h:327
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:280

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

◆ GetExecutablePath()

virtual const wxString& PGM_BASE::GetExecutablePath ( ) const
inlinevirtualinherited

Definition at line 158 of file pgm_base.h.

158 { return m_bin_dir; }
wxString m_bin_dir
full path to this program
Definition: pgm_base.h:311

References PGM_BASE::m_bin_dir.

Referenced by PGM_SINGLE_TOP::OnPgmInit(), and PGM_BASE::SetLanguagePath().

◆ GetHelpFileName()

wxString PGM_KICAD::GetHelpFileName ( )
inline

Definition at line 59 of file pgm_kicad.h.

59 { return m_bm.m_help_file; }
wxString m_help_file
Definition: bin_mod.h:58
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_help_file.

Referenced by KICAD_MANAGER_FRAME::help_name().

◆ GetKicadEnvVariable()

virtual const wxString& PGM_BASE::GetKicadEnvVariable ( ) const
inlinevirtualinherited

Definition at line 156 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtualinherited

Definition at line 160 of file pgm_base.h.

160 { return m_locale; }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:317

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtualinherited

Definition at line 645 of file pgm_base.cpp.

646 {
647  return GetCommonSettings()->m_Env.vars;
648 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
ENVIRONMENT m_Env

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_Env, and COMMON_SETTINGS::ENVIRONMENT::vars.

Referenced by FILENAME_RESOLVER::GetKicadPaths(), and OnPgmInit().

◆ GetPdfBrowserName()

virtual const wxString& PGM_BASE::GetPdfBrowserName ( ) const
inlinevirtualinherited

Definition at line 162 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

virtual int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inlinevirtualinherited
Returns
the wxWidgets language identifier Id of the language currently selected.

Definition at line 213 of file pgm_base.h.

213 { return m_language_id; }
int m_language_id
The current language setting.
Definition: pgm_base.h:320

References PGM_BASE::m_language_id.

◆ GetSettingsManager()

◆ InitPgm()

bool PGM_BASE::InitPgm ( bool  aHeadless = false)
inherited

Initialize this program.

Initialize the process in a KiCad standard way using some generalized techniques:

  • Default paths (help, libs, bin) and configuration file names
  • Language and locale
  • fonts
Note
Do not initialize anything relating to DSOs or projects.
Parameters
aHeadlessIf true, run in headless mode (e.g. for unit tests)
Returns
true if success, false if failure and program is to terminate.

Definition at line 205 of file pgm_base.cpp.

206 {
207  wxFileName pgm_name( App().argv[0] );
208 
209  wxInitAllImageHandlers();
210 
211 #ifndef __WINDOWS__
212  if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
213  {
214  DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
215  "Unable to continue." ) );
216  return false;
217  }
218 #endif
219 
220  m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
221  wxGetUserId(), GetKicadLockFilePath() );
222 
223  if( m_pgm_checker->IsAnotherRunning() )
224  {
225  if( !IsOK( NULL, wxString::Format( _( "%s is already running. Continue?" ),
226  App().GetAppDisplayName() ) ) )
227  {
228  return false;
229  }
230  }
231 
232  // Init KiCad environment
233  // the environment variable KICAD (if exists) gives the kicad path:
234  // something like set KICAD=d:\kicad
235  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
236 
237  if( isDefined ) // ensure m_kicad_env ends by "/"
238  {
240 
241  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
243  }
244 
245  // Init parameters for configuration
246  App().SetVendorName( "KiCad" );
247  App().SetAppName( pgm_name.GetName().Lower() );
248 
249  // Install some image handlers, mainly for help
250  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )
251  wxImage::AddHandler( new wxPNGHandler );
252 
253  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL )
254  wxImage::AddHandler( new wxGIFHandler );
255 
256  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL )
257  wxImage::AddHandler( new wxJPEGHandler );
258 
259  wxFileSystem::AddHandler( new wxZipFSHandler );
260 
261  // Analyze the command line & initialize the binary path
262  wxString tmp;
264  SetLanguagePath();
265  SetDefaultLanguage( tmp );
266 
267  m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
268 
269  // Something got in the way of settings load: can't continue
270  if( !m_settings_manager->IsOK() )
271  return false;
272 
273  // Set up built-in environment variables (and override them from the system enviroment if set)
275 
276  // Load common settings from disk after setting up env vars
278 
279  // Init user language *before* calling loadCommonSettings, because
280  // env vars could be incorrectly initialized on Linux
281  // (if the value contains some non ASCII7 chars, the env var is not initialized)
282  SetLanguage( tmp, true );
283 
285 
286  ReadPdfBrowserInfos(); // needs GetCommonSettings()
287 
288 #ifdef __WXMAC__
289  // Always show filters on Open dialog to be able to choose plugin
290  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
291 #endif
292 
293  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
294  // Need to create a project early for now (it can have an empty path for the moment)
296 
297  // TODO: Move tooltips into KIPLATFORM
298  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
299  // Windows as other platforms display tooltips while the mouse is not moving
300  wxToolTip::SetAutoPop( 10000 );
301 
302  return true;
303 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:127
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:348
wxString GetKicadLockFilePath()
Definition: lockfile.cpp:61
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:44
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:43
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:133
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:306
wxSingleInstanceChecker * m_pgm_checker
prevents multiple instances of a program from being run at the same time.
Definition: pgm_base.h:308
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:305
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
wxString m_kicad_env
The KICAD system environment variable.
Definition: pgm_base.h:314
#define NULL
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:397
virtual void SetLanguagePath()
Definition: pgm_base.cpp:546
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:42
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:98
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:492
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:296

References _, PGM_BASE::App(), DisplayErrorMessage(), Format(), PGM_BASE::GetCommonSettings(), GetKicadLockFilePath(), PGM_BASE::GetSettingsManager(), COMMON_SETTINGS::InitializeEnvironment(), IsOK(), SETTINGS_MANAGER::Load(), PGM_BASE::loadCommonSettings(), SETTINGS_MANAGER::LoadProject(), PGM_BASE::m_kicad_env, PGM_BASE::m_pgm_checker, PGM_BASE::m_settings_manager, NULL, PGM_BASE::ReadPdfBrowserInfos(), PGM_BASE::SetDefaultLanguage(), PGM_BASE::setExecutablePath(), PGM_BASE::SetLanguage(), PGM_BASE::SetLanguagePath(), UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

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

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtualinherited

Definition at line 154 of file pgm_base.h.

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 348 of file pgm_base.cpp.

349 {
350  m_help_size.x = 500;
351  m_help_size.y = 400;
352 
355 
356  for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
357  {
358  wxLogTrace( traceEnvVars, "PGM_BASE::loadCommonSettings: Found entry %s = %s",
359  it.first, it.second.GetValue() );
360 
361  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
362  // it is found in config. (It is reserved and defined as project path)
363  if( it.first == PROJECT_VAR_NAME )
364  continue;
365 
366  // Don't set bogus empty entries in the environment
367  if( it.first.IsEmpty() )
368  continue;
369 
370  // Do not overwrite vars set by the system environment with values from the settings file
371  if( it.second.GetDefinedExternally() )
372  continue;
373 
374  SetLocalEnvVariable( it.first, it.second.GetValue() );
375  }
376 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:331
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:601
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxSize m_help_size
Definition: pgm_base.h:328
wxString m_editor_name
Definition: pgm_base.h:327

References COMMON_SETTINGS::SYSTEM::editor_name, PGM_BASE::GetCommonSettings(), PGM_BASE::m_editor_name, COMMON_SETTINGS::m_Env, PGM_BASE::m_help_size, PGM_BASE::m_show_env_var_dialog, COMMON_SETTINGS::m_System, PROJECT_VAR_NAME, PGM_BASE::SetLocalEnvVariable(), COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, and traceEnvVars.

Referenced by PGM_BASE::InitPgm().

◆ MacOpenFile()

void PGM_KICAD::MacOpenFile ( const wxString &  aFileName)
overridevirtual

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

231 {
232 #if defined(__WXMAC__)
233 
234  KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) App().GetTopWindow();
235 
236  if( !aFileName.empty() && wxFileExists( aFileName ) )
237  frame->LoadProject( wxFileName( aFileName ) );
238 
239 #endif
240 }
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:133
void LoadProject(const wxFileName &aProjectFileName)
The main KiCad project manager frame.

References PGM_BASE::App(), and KICAD_MANAGER_FRAME::LoadProject().

◆ OnPgmExit()

void PGM_KICAD::OnPgmExit ( )

Definition at line 213 of file kicad.cpp.

214 {
215  Kiway.OnKiwayEnd();
216 
217  if( m_settings_manager && m_settings_manager->IsOK() )
218  {
220  m_settings_manager->Save();
221  }
222 
223  // Destroy everything in PGM_KICAD,
224  // especially wxSingleInstanceCheckerImpl earlier than wxApp and earlier
225  // than static destruction would.
226  Destroy();
227 }
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:379
void OnKiwayEnd()
Definition: kiway.cpp:625
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:305
void Destroy()
Definition: kicad.cpp:243
KIWAY Kiway

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

Referenced by APP_KICAD::OnExit(), and APP_KICAD::OnInit().

◆ OnPgmInit()

bool PGM_KICAD::OnPgmInit ( )

Definition at line 93 of file kicad.cpp.

94 {
95  App().SetAppDisplayName( wxT( "KiCad" ) );
96 
97 #if defined(DEBUG)
98  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
99 
100  if( !wxIsAbsolutePath( absoluteArgv0 ) )
101  {
102  wxLogError( wxT( "No meaningful argv[0]" ) );
103  return false;
104  }
105 #endif
106 
107  if( !InitPgm() )
108  return false;
109 
113  m_bm.Init();
114 
115  // Add search paths to feed the PGM_KICAD::SysSearch() function,
116  // currenly limited in support to only look for project templates
117  {
118  SEARCH_STACK bases;
119 
120  SystemDirsAppend( &bases );
121 
122  for( unsigned i = 0; i < bases.GetCount(); ++i )
123  {
124  wxFileName fn( bases[i], wxEmptyString );
125 
126  // Add KiCad template file path to search path list.
127  fn.AppendDir( wxT( "template" ) );
128 
129  // Only add path if exists and can be read by the user.
130  if( fn.DirExists() && fn.IsDirReadable() )
131  m_bm.m_search.AddPaths( fn.GetPath() );
132  }
133 
134  // The KICAD6_TEMPLATE_DIR takes precedence over the search stack template path.
135  ENV_VAR_MAP_CITER it = GetLocalEnvVariables().find( "KICAD6_TEMPLATE_DIR" );
136 
137  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
138  m_bm.m_search.Insert( it->second.GetValue(), 0 );
139 
140  // We've been adding system (installed default) search paths so far, now for user paths
141  // The default user search path is inside KIPLATFORM::ENV::GetDocumentsPath()
143 
144  // ...but the user can override that default with the KICAD_USER_TEMPLATE_DIR env var
145  it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
146 
147  if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
148  m_bm.m_search.Insert( it->second.GetValue(), 0 );
149  }
150 
151  KICAD_MANAGER_FRAME* frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
152  wxDefaultPosition, wxSize( 775, -1 ) );
153  App().SetTopWindow( frame );
154 
155  Kiway.SetTop( frame );
156 
157  KICAD_SETTINGS* settings = static_cast<KICAD_SETTINGS*>( PgmSettings() );
158 
159  wxString projToLoad;
160 
161  if( App().argc > 1 )
162  {
163  wxFileName tmp = App().argv[1];
164 
165  if( tmp.GetExt() != ProjectFileExtension && tmp.GetExt() != LegacyProjectFileExtension )
166  {
167  wxString msg;
168 
169  msg.Printf( _( "File '%s'\ndoes not appear to be a valid KiCad project file." ),
170  tmp.GetFullPath() );
171  wxMessageDialog dlg( nullptr, msg, _( "Error" ), wxOK | wxICON_EXCLAMATION );
172  dlg.ShowModal();
173  }
174  else
175  {
176  projToLoad = tmp.GetFullPath();
177  }
178  }
179 
180  // If no file was given as an argument, check that there was a file open.
181  if( projToLoad.IsEmpty() && settings->m_OpenProjects.size() )
182  {
183  wxString last_pro = settings->m_OpenProjects.front();
184  settings->m_OpenProjects.erase( settings->m_OpenProjects.begin() );
185 
186  if( wxFileExists( last_pro ) )
187  {
188  // Try to open the last opened project,
189  // if a project name is not given when starting Kicad
190  projToLoad = last_pro;
191  }
192  }
193 
194  // Do not attempt to load a non-existent project file.
195  if( !projToLoad.empty() )
196  {
197  wxFileName fn( projToLoad );
198 
199  if( fn.Exists() )
200  {
201  fn.MakeAbsolute();
202  frame->LoadProject( fn );
203  }
204  }
205 
206  frame->Show( true );
207  frame->Raise();
208 
209  return true;
210 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:127
void Init()
Definition: bin_mod.cpp:38
const std::string ProjectFileExtension
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:133
Look for files in a number of paths.
Definition: search_stack.h:41
std::vector< wxString > m_OpenProjects
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
#define NULL
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:86
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
Definition: bin_mod.h:53
const std::string LegacyProjectFileExtension
void SetTop(wxFrame *aTop)
Tell this KIWAY about the top most frame in the program and optionally allows it to play the role of ...
Definition: kiway.cpp:81
SEARCH_STACK m_search
Definition: bin_mod.h:60
JSON_SETTINGS * RegisterSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
bool InitPgm(bool aHeadless=false)
Initialize this program.
Definition: pgm_base.cpp:205
BIN_MOD m_bm
Definition: pgm_kicad.h:68
#define _(s)
Definition: 3d_actions.cpp:33
APP_SETTINGS_BASE * PgmSettings()
Definition: pgm_kicad.h:55
void LoadProject(const wxFileName &aProjectFileName)
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.cpp:645
The main KiCad project manager frame.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
KIWAY Kiway

References _, SEARCH_STACK::AddPaths(), PGM_BASE::App(), PGM_BASE::GetLocalEnvVariables(), PGM_BASE::GetSettingsManager(), PATHS::GetUserTemplatesPath(), BIN_MOD::Init(), PGM_BASE::InitPgm(), BIN_MOD::InitSettings(), Kiway, LegacyProjectFileExtension, KICAD_MANAGER_FRAME::LoadProject(), m_bm, KICAD_SETTINGS::m_OpenProjects, BIN_MOD::m_search, NULL, PgmSettings(), ProjectFileExtension, SETTINGS_MANAGER::RegisterSettings(), SETTINGS_MANAGER::SetKiway(), KIWAY::SetTop(), and SystemDirsAppend().

Referenced by APP_KICAD::OnInit().

◆ PgmSettings()

APP_SETTINGS_BASE* PGM_KICAD::PgmSettings ( )
inline

Definition at line 55 of file pgm_kicad.h.

55 { return m_bm.m_config; }
APP_SETTINGS_BASE * m_config
maybe from $HOME/.${m_name}
Definition: bin_mod.h:57
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_config.

Referenced by KICAD_MANAGER_FRAME::config(), and OnPgmInit().

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
virtualinherited

Read the PDF browser choice from the common configuration.

Definition at line 42 of file eda_doc.cpp.

43 {
44  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
46 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
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:323
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:164

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_System, PGM_BASE::m_use_system_pdf_browser, PGM_BASE::SetPdfBrowserName(), and COMMON_SETTINGS::SYSTEM::use_system_pdf_viewer.

Referenced by PGM_BASE::InitPgm().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )
inherited

Save the program (process) settings subset which are stored .kicad_common.

Definition at line 379 of file pgm_base.cpp.

380 {
381  // GetCommonSettings() is not initialized until fairly late in the
382  // process startup: InitPgm(), so test before using:
383  if( GetCommonSettings() )
384  {
385  GetCommonSettings()->m_System.working_dir = wxGetCwd();
387  }
388 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
bool m_show_env_var_dialog
Flag to indicate if the environment variable overwrite warning dialog should be shown.
Definition: pgm_base.h:331
ENVIRONMENT m_Env

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_Env, PGM_BASE::m_show_env_var_dialog, COMMON_SETTINGS::m_System, COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, and COMMON_SETTINGS::SYSTEM::working_dir.

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

◆ SetDefaultLanguage()

bool PGM_BASE::SetDefaultLanguage ( wxString &  aErrMsg)
inherited

Set the default language without reference to any preferences.

Can be used to set the language for dialogs that show before preferences are loaded

Parameters
aErrMsgString to return the error messsage(s) in
Returns
false if the language could not be set

Definition at line 492 of file pgm_base.cpp.

493 {
494  setLanguageId( wxLANGUAGE_DEFAULT );
495 
496  // dictionary file name without extend (full name is kicad.mo)
497  wxString dictionaryName( "kicad" );
498 
499  delete m_locale;
500  m_locale = new wxLocale;
501  m_locale->Init();
502 
503  // Try adding the dictionary if it is not currently loaded
504  if( !m_locale->IsLoaded( dictionaryName ) )
505  m_locale->AddCatalog( dictionaryName );
506 
507  // Verify the Kicad dictionary was loaded properly
508  // However, for the English language, the dictionary is not mandatory, as
509  // all messages are already in English, just restricted to ASCII7 chars,
510  // the verification is skipped.
511  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
512  {
513  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
514  dictionaryName, m_locale->GetName() );
515 
516  setLanguageId( wxLANGUAGE_DEFAULT );
517  delete m_locale;
518 
519  m_locale = new wxLocale;
520  m_locale->Init();
521 
522  aErrMsg = _( "The KiCad language file for this language is not installed." );
523  return false;
524  }
525 
526  return true;
527 }
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:317
int m_language_id
The current language setting.
Definition: pgm_base.h:320
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:296
const wxChar *const traceLocale
Flag to enable locale debug output.
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:98

References _, PGM_BASE::m_language_id, PGM_BASE::m_locale, PGM_BASE::setLanguageId(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ SetEditorName()

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

Definition at line 140 of file pgm_base.cpp.

141 {
142  m_editor_name = aFileName;
143  wxASSERT( GetCommonSettings() );
144  GetCommonSettings()->m_System.editor_name = aFileName;
145 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
wxString m_editor_name
Definition: pgm_base.h:327

References COMMON_SETTINGS::SYSTEM::editor_name, PGM_BASE::GetCommonSettings(), PGM_BASE::m_editor_name, and COMMON_SETTINGS::m_System.

Referenced by PGM_BASE::GetEditorName().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protectedinherited

Find the path to the executable and stores it in PGM_BASE::m_bin_dir.

Returns
true if success, else false.

Definition at line 306 of file pgm_base.cpp.

307 {
308  m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
309 
310 #ifdef __WXMAC__
311  // On OSX Pgm().GetExecutablePath() will always point to main
312  // bundle directory, e.g., /Applications/kicad.app/
313 
314  wxFileName fn( m_bin_dir );
315 
316  if( fn.GetName() == wxT( "kicad" ) )
317  {
318  // kicad launcher, so just remove the Contents/MacOS part
319  fn.RemoveLastDir();
320  fn.RemoveLastDir();
321  }
322  else
323  {
324  // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
325  fn.RemoveLastDir();
326  fn.RemoveLastDir();
327  fn.RemoveLastDir();
328  fn.RemoveLastDir();
329  fn.RemoveLastDir();
330  }
331 
332  m_bin_dir = fn.GetPath() + wxT( "/" );
333 #else
334  // Use unix notation for paths. I am not sure this is a good idea,
335  // but it simplifies compatibility between Windows and Unices.
336  // However it is a potential problem in path handling under Windows.
338 
339  // Remove file name form command line:
340  while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
341  m_bin_dir.RemoveLast();
342 #endif
343 
344  return true;
345 }
#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:311

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 ( wxString &  aErrMsg,
bool  first_time = false 
)
virtualinherited

Set the dictionary file name for internationalization.

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

Parameters
aErrMsgis the string to return the error message it.
first_timemust be set to true the first time this function is called, false otherwise.
Returns
false if there was an error setting the language.

Definition at line 397 of file pgm_base.cpp.

398 {
399  if( first_time )
400  {
401  setLanguageId( wxLANGUAGE_DEFAULT );
402  // First time SetLanguage is called, the user selected language id is set
403  // from common user config settings
404  wxString languageSel = GetCommonSettings()->m_System.language;
405 
406  // Search for the current selection
407  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
408  {
409  if( LanguagesList[ii].m_Lang_Label == languageSel )
410  {
411  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
412  break;
413  }
414  }
415  }
416 
417  // dictionary file name without extend (full name is kicad.mo)
418  wxString dictionaryName( "kicad" );
419 
420  delete m_locale;
421  m_locale = new wxLocale;
422 
423  if( !m_locale->Init( m_language_id ) )
424  {
425  wxLogTrace( traceLocale, "This language is not supported by the system." );
426 
427  setLanguageId( wxLANGUAGE_DEFAULT );
428  delete m_locale;
429 
430  m_locale = new wxLocale;
431  m_locale->Init();
432 
433  aErrMsg = _( "This language is not supported by the operating system." );
434  return false;
435  }
436  else if( !first_time )
437  {
438  wxLogTrace( traceLocale, "Search for dictionary %s.mo in %s",
439  dictionaryName, m_locale->GetName() );
440  }
441 
442  if( !first_time )
443  {
444  // If we are here, the user has selected another language.
445  // Therefore the new preferred language name is stored in common config.
446  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
447  // versions, for a given language
448  wxString languageSel;
449 
450  // Search for the current selection language name
451  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
452  {
453  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
454  {
455  languageSel = LanguagesList[ii].m_Lang_Label;
456  break;
457  }
458  }
459 
461  cfg->m_System.language = languageSel;
462  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
463  }
464 
465  // Try adding the dictionary if it is not currently loaded
466  if( !m_locale->IsLoaded( dictionaryName ) )
467  m_locale->AddCatalog( dictionaryName );
468 
469  // Verify the Kicad dictionary was loaded properly
470  // However, for the English language, the dictionary is not mandatory, as
471  // all messages are already in English, just restricted to ASCII7 chars,
472  // the verification is skipped.
473  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
474  {
475  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
476  dictionaryName, m_locale->GetName() );
477 
478  setLanguageId( wxLANGUAGE_DEFAULT );
479  delete m_locale;
480 
481  m_locale = new wxLocale;
482  m_locale->Init();
483 
484  aErrMsg = _( "The KiCad language file for this language is not installed." );
485  return false;
486  }
487 
488  return true;
489 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:127
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:68
wxLocale * m_locale
The current locale.
Definition: pgm_base.h:317
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
int m_language_id
The current language setting.
Definition: pgm_base.h:320
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:296
const wxChar *const traceLocale
Flag to enable locale debug output.
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:66
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:98

References _, PGM_BASE::GetCommonSettings(), PGM_BASE::GetSettingsManager(), COMMON_SETTINGS::SYSTEM::language, LanguagesList, LANGUAGE_DESCR::m_KI_Lang_Identifier, LANGUAGE_DESCR::m_Lang_Label, PGM_BASE::m_language_id, PGM_BASE::m_locale, COMMON_SETTINGS::m_System, JSON_SETTINGS::SaveToFile(), PGM_BASE::setLanguageId(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotectedinherited

Trap all changes in here, simplifies debugging.

Definition at line 296 of file pgm_base.h.

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

References PGM_BASE::m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
virtualinherited

Set in .m_language_id member the wxWidgets language identifier ID fromthe 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 530 of file pgm_base.cpp.

531 {
532  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
533  menu_id, (int)arrayDim( LanguagesList )-1 );
534 
535  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
536  {
537  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
538  {
539  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
540  break;
541  }
542  }
543 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:68
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:63
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:296
const wxChar *const traceLocale
Flag to enable locale debug output.

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtualinherited

Definition at line 546 of file pgm_base.cpp.

547 {
548  SEARCH_STACK guesses;
549 
550  SystemDirsAppend( &guesses );
551 
552  // Add our internat dir to the wxLocale catalog of paths
553  for( unsigned i = 0; i < guesses.GetCount(); i++ )
554  {
555  wxFileName fn( guesses[i], wxEmptyString );
556 
557  // Append path for Windows and unix KiCad package install
558  fn.AppendDir( "share" );
559  fn.AppendDir( "internat" );
560 
561  if( fn.IsDirReadable() )
562  {
563  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
564  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
565  }
566 
567  // Append path for unix standard install
568  fn.RemoveLastDir();
569  fn.AppendDir( "kicad" );
570  fn.AppendDir( "internat" );
571 
572  if( fn.IsDirReadable() )
573  {
574  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
575  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
576  }
577 
578  // Append path for macOS install
579  fn.RemoveLastDir();
580  fn.RemoveLastDir();
581  fn.RemoveLastDir();
582  fn.AppendDir( "internat" );
583 
584  if( fn.IsDirReadable() )
585  {
586  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
587  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
588  }
589  }
590 
591  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
592  {
593  wxFileName fn( Pgm().GetExecutablePath() );
594  fn.RemoveLastDir();
595  fn.AppendDir( "translation" );
596  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
597  }
598 }
Look for files in a number of paths.
Definition: search_stack.h:41
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
const wxChar *const traceLocale
Flag to enable locale debug output.
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:158

References PGM_BASE::GetExecutablePath(), Pgm(), SystemDirsAppend(), and traceLocale.

Referenced by PGM_BASE::InitPgm().

◆ SetLocalEnvVariable()

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

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

602 {
603  wxString env;
604 
605  if( aName.IsEmpty() )
606  {
607  wxLogTrace( traceEnvVars,
608  "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s",
609  aValue );
610  return false;
611  }
612 
613  // Check to see if the environment variable is already set.
614  if( wxGetEnv( aName, &env ) )
615  {
616  wxLogTrace( traceEnvVars,
617  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
618  aName, env );
619  return env == aValue;
620  }
621 
622  wxLogTrace( traceEnvVars,
623  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
624  aName, aValue );
625 
626  return wxSetEnv( aName, aValue );
627 }
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References traceEnvVars.

Referenced by PGM_BASE::loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( )
virtualinherited

Updates the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTINGS.

See also
GetLocalEnvVariables()

Definition at line 630 of file pgm_base.cpp.

631 {
632  // Overwrites externally defined environment variable until the next time the application
633  // is run.
634  for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
635  {
636  wxLogTrace( traceEnvVars,
637  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
638  m_local_env_var.first,
639  m_local_env_var.second.GetValue() );
640  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
641  }
642 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References PGM_BASE::GetCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

virtual void PGM_BASE::SetPdfBrowserName ( const wxString &  aFileName)
inlinevirtualinherited

Definition at line 164 of file pgm_base.h.

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SysSearch()

SEARCH_STACK& PGM_KICAD::SysSearch ( )
inline

Definition at line 57 of file pgm_kicad.h.

57 { return m_bm.m_search; }
SEARCH_STACK m_search
Definition: bin_mod.h:60
BIN_MOD m_bm
Definition: pgm_kicad.h:68

References m_bm, and BIN_MOD::m_search.

Referenced by KICAD_MANAGER_FRAME::sys_search().

◆ UseSystemPdfBrowser()

virtual bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlinevirtualinherited
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 171 of file pgm_base.h.

172  {
173  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
174  }
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:323
wxString m_pdf_browser
The file name of the the program selected for browsing pdf files.
Definition: pgm_base.h:326

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

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtualinherited

Save the PDF browser choice to the common configuration.

Definition at line 49 of file eda_doc.cpp.

50 {
53 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:391
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:323
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:162

References PGM_BASE::GetCommonSettings(), PGM_BASE::GetPdfBrowserName(), COMMON_SETTINGS::m_System, PGM_BASE::m_use_system_pdf_browser, COMMON_SETTINGS::SYSTEM::pdf_viewer_name, and COMMON_SETTINGS::SYSTEM::use_system_pdf_viewer.

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protectedinherited

full path to this program

Definition at line 311 of file pgm_base.h.

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

◆ m_bm

BIN_MOD PGM_KICAD::m_bm
protected

Definition at line 68 of file pgm_kicad.h.

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

◆ m_editor_name

wxString PGM_BASE::m_editor_name
protectedinherited

◆ m_help_size

wxSize PGM_BASE::m_help_size
protectedinherited

Definition at line 328 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 314 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

◆ m_locale

wxLocale* PGM_BASE::m_locale
protectedinherited

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount
inherited

Definition at line 289 of file pgm_base.h.

Referenced by APP_KICAD::FilterEvent(), and PGM_BASE::PGM_BASE().

◆ 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 326 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 308 of file pgm_base.h.

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

◆ m_Printing

bool PGM_BASE::m_Printing
inherited

wxWidgets on MSW tends to crash if you spool up more than one print job at a time.

Definition at line 287 of file pgm_base.h.

Referenced by BOARD::ComputeBoundingBox(), and PGM_BASE::PGM_BASE().

◆ m_settings_manager

std::unique_ptr<SETTINGS_MANAGER> PGM_BASE::m_settings_manager
protectedinherited

◆ 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 331 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 323 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[]
staticinherited

Definition at line 257 of file pgm_base.h.


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