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_BASE. 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 SetTextEditor (const wxString &aFileName)
 
virtual const wxString & GetTextEditor (bool aCanShowFileChooser=true)
 Return the path to the preferred text editor application. 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 from the 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, bool aSkipPyInit=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
 
std::unique_ptr< SCRIPTING > m_python_scripting
 
wxString m_bin_dir
 
wxString m_kicad_env
 full path to this program More...
 
wxLocale * m_locale
 The KICAD system environment variable. More...
 
int m_language_id
 
bool m_use_system_pdf_browser
 
wxString m_pdf_browser
 
wxString m_text_editor
 Filename of the app selected for browsing PDFs. More...
 

Detailed Description

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

KIFACE_BASE 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 37 of file pgm_kicad.h.

Constructor & Destructor Documentation

◆ PGM_KICAD()

PGM_KICAD::PGM_KICAD ( )
inline

Definition at line 40 of file pgm_kicad.h.

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

◆ ~PGM_KICAD()

PGM_KICAD::~PGM_KICAD ( )
throw (
)
inline

Definition at line 44 of file pgm_kicad.h.

45  {
46  Destroy();
47  }
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 132 of file pgm_base.cpp.

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

Referenced by PGM_BASE::InitPgm(), 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 182 of file pgm_base.cpp.

183 {
184  // Create a mask representing the executable files in the current platform
185 #ifdef __WINDOWS__
186  wxString mask( _( "Executable file" ) + wxT( " (*.exe)|*.exe" ) );
187 #else
188  wxString mask( _( "Executable file" ) + wxT( " (*)|*" ) );
189 #endif
190 
191  // Extract the path, name and extension from the default editor (even if the editor's
192  // name was empty, this method will succeed and return empty strings).
193  wxString path, name, ext;
194  wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
195 
196  // Show the modal editor and return the file chosen (may be empty if the user cancels
197  // the dialog).
198  return wxFileSelector( _( "Select Preferred Editor" ), path, name, wxT( "." ) + ext,
199  mask, wxFD_OPEN | wxFD_FILE_MUST_EXIST, nullptr );
200 }
const char * name
Definition: DXF_plotter.cpp:56
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:103

References _, name, and path.

Referenced by PGM_BASE::GetTextEditor().

◆ 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:124
BIN_MOD m_bm
Definition: pgm_kicad.h:67
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 181 of file pgm_base.h.

181 { m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
Definition: pgm_base.h:320

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

382 {
384 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:310
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::SetLanguage(), PGM_BASE::SetLocalEnvVariables(), PGM_BASE::SetTextEditor(), and PGM_BASE::WritePdfBrowserInfos().

◆ GetExecutablePath()

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

Definition at line 160 of file pgm_base.h.

160 { return m_bin_dir; }
wxString m_bin_dir
Definition: pgm_base.h:314

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 58 of file pgm_kicad.h.

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

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

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

References PGM_BASE::m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtualinherited

Definition at line 162 of file pgm_base.h.

162 { return m_locale; }
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:317

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtualinherited

Definition at line 635 of file pgm_base.cpp.

636 {
637  return GetCommonSettings()->m_Env.vars;
638 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
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 164 of file pgm_base.h.

164 { return m_pdf_browser; }
wxString m_pdf_browser
Definition: pgm_base.h:321

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

215 { return m_language_id; }
int m_language_id
Definition: pgm_base.h:318

References PGM_BASE::m_language_id.

◆ GetSettingsManager()

◆ GetTextEditor()

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

Return the path to the preferred text editor application.

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

147 {
148  wxString editorname = m_text_editor;
149 
150  if( !editorname )
151  {
152  if( !wxGetEnv( "EDITOR", &editorname ) )
153  {
154  // If there is no EDITOR variable set, try the desktop default
155 #ifdef __WXMAC__
156  editorname = "/usr/bin/open -e";
157 #elif __WXX11__
158  editorname = "/usr/bin/xdg-open";
159 #endif
160  }
161  }
162 
163  // If we still don't have an editor name show a dialog asking the user to select one
164  if( !editorname && aCanShowFileChooser )
165  {
166  DisplayInfoMessage( nullptr, _( "No default editor found, you must choose one." ) );
167 
168  editorname = AskUserForPreferredEditor();
169  }
170 
171  // If we finally have a new editor name request it to be copied to m_text_editor and
172  // saved to the preferences file.
173  if( !editorname.IsEmpty() )
174  SetTextEditor( editorname );
175 
176  // m_text_editor already has the same value that editorname, or empty if no editor was
177  // found/chosen.
178  return m_text_editor;
179 }
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:182
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:323
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:103
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:139
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:307

References _, PGM_BASE::AskUserForPreferredEditor(), DisplayInfoMessage(), PGM_BASE::m_text_editor, and PGM_BASE::SetTextEditor().

◆ InitPgm()

bool PGM_BASE::InitPgm ( bool  aHeadless = false,
bool  aSkipPyInit = 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)
aSkipPyInitIf true, do not init python stuff. Useful in application that do not use python, to disable python dependency at run time
Returns
true if success, false if failure and program is to terminate.

Definition at line 203 of file pgm_base.cpp.

204 {
205  wxString pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
206 
207  wxInitAllImageHandlers();
208 
209 #ifndef __WINDOWS__
210  if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
211  {
212  DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
213  "Unable to continue." ) );
214  return false;
215  }
216 #endif
217 
218  // Init KiCad environment
219  // the environment variable KICAD (if exists) gives the kicad path:
220  // something like set KICAD=d:\kicad
221  bool isDefined = wxGetEnv( "KICAD", &m_kicad_env );
222 
223  if( isDefined ) // ensure m_kicad_env ends by "/"
224  {
226 
227  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
229  }
230 
231  // Init parameters for configuration
232  App().SetVendorName( "KiCad" );
233  App().SetAppName( pgm_name );
234 
235  // Install some image handlers, mainly for help
236  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr )
237  wxImage::AddHandler( new wxPNGHandler );
238 
239  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr )
240  wxImage::AddHandler( new wxGIFHandler );
241 
242  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr )
243  wxImage::AddHandler( new wxJPEGHandler );
244 
245  wxFileSystem::AddHandler( new wxZipFSHandler );
246 
247  // Analyze the command line & initialize the binary path
248  wxString tmp;
250  SetLanguagePath();
251  SetDefaultLanguage( tmp );
252 
253  m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
254 
255  // Something got in the way of settings load: can't continue
256  if( !m_settings_manager->IsOK() )
257  return false;
258 
259  // Set up built-in environment variables (and override them from the system environment if set)
261 
262  // Load color settings after env is initialized
263  m_settings_manager->ReloadColorSettings();
264 
265  // Load common settings from disk after setting up env vars
267 
268  // Init user language *before* calling loadSettings, because
269  // env vars could be incorrectly initialized on Linux
270  // (if the value contains some non ASCII7 chars, the env var is not initialized)
271  SetLanguage( tmp, true );
272 
273  // Now that translations are available, inform the user if the OS is unsupported
275 
277 
278  ReadPdfBrowserInfos(); // needs GetCommonSettings()
279 
280  // Create the python scripting stuff
281  // Skip it fot applications that do not use it
282  if( !aSkipPyInit )
283  m_python_scripting = std::make_unique<SCRIPTING>();
284 
285 #ifdef __WXMAC__
286  // Always show filters on Open dialog to be able to choose plugin
287  wxSystemOptions::SetOption( wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1 );
288 #endif
289 
290  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
291  // Need to create a project early for now (it can have an empty path for the moment)
293 
294  // TODO: Move tooltips into KIPLATFORM
295  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
296  // Windows as other platforms display tooltips while the mouse is not moving
297  wxToolTip::SetAutoPop( 10000 );
298 
299  return true;
300 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:312
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:345
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:36
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:35
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:132
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:303
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:310
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
wxString m_kicad_env
full path to this program
Definition: pgm_base.h:315
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:387
virtual void SetLanguagePath()
Definition: pgm_base.cpp:536
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:37
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition: common.cpp:603
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:103
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:482

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

Referenced by OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtualinherited

Definition at line 156 of file pgm_base.h.

156 { return !m_kicad_env.IsEmpty(); }
wxString m_kicad_env
full path to this program
Definition: pgm_base.h:315

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 345 of file pgm_base.cpp.

346 {
348 
349  for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
350  {
351  wxLogTrace( traceEnvVars, "PGM_BASE::loadSettings: Found entry %s = %s",
352  it.first, it.second.GetValue() );
353 
354  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
355  // it is found in config. (It is reserved and defined as project path)
356  if( it.first == PROJECT_VAR_NAME )
357  continue;
358 
359  // Don't set bogus empty entries in the environment
360  if( it.first.IsEmpty() )
361  continue;
362 
363  // Do not overwrite vars set by the system environment with values from the settings file
364  if( it.second.GetDefinedExternally() )
365  continue;
366 
367  SetLocalEnvVariable( it.first, it.second.GetValue() );
368  }
369 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:591
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:323

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_System, PGM_BASE::m_text_editor, PROJECT_VAR_NAME, PGM_BASE::SetLocalEnvVariable(), COMMON_SETTINGS::SYSTEM::text_editor, 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:132
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:372
void OnKiwayEnd()
Definition: kiway.cpp:641
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:310
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  // currently 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( nullptr, 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:129
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false)
Initialize this program.
Definition: pgm_base.cpp:203
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
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:132
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.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:86
#define _(s)
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:82
SEARCH_STACK m_search
Definition: bin_mod.h:60
BIN_MOD m_bm
Definition: pgm_kicad.h:67
APP_SETTINGS_BASE * PgmSettings()
Definition: pgm_kicad.h:54
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:635
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, 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 54 of file pgm_kicad.h.

54 { 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:67

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 37 of file eda_doc.cpp.

38 {
39  SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
41 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
bool m_use_system_pdf_browser
Definition: pgm_base.h:320
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:166

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

373 {
374  // GetCommonSettings() is not initialized until fairly late in the
375  // process startup: InitPgm(), so test before using:
376  if( GetCommonSettings() )
377  GetCommonSettings()->m_System.working_dir = wxGetCwd();
378 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_System, 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 message(s) in
Returns
false if the language could not be set

Definition at line 482 of file pgm_base.cpp.

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

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

Referenced by PGM_BASE::InitPgm().

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

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

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

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

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

300 { m_language_id = aId; }
int m_language_id
Definition: pgm_base.h:318

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

521 {
522  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
523  menu_id, (int)arrayDim( LanguagesList )-1 );
524 
525  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
526  {
527  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
528  {
529  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
530  break;
531  }
532  }
533 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:70
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:65
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:300
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 536 of file pgm_base.cpp.

537 {
538  SEARCH_STACK guesses;
539 
540  SystemDirsAppend( &guesses );
541 
542  // Add our internat dir to the wxLocale catalog of paths
543  for( unsigned i = 0; i < guesses.GetCount(); i++ )
544  {
545  wxFileName fn( guesses[i], wxEmptyString );
546 
547  // Append path for Windows and unix KiCad package install
548  fn.AppendDir( "share" );
549  fn.AppendDir( "internat" );
550 
551  if( fn.IsDirReadable() )
552  {
553  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
554  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
555  }
556 
557  // Append path for unix standard install
558  fn.RemoveLastDir();
559  fn.AppendDir( "kicad" );
560  fn.AppendDir( "internat" );
561 
562  if( fn.IsDirReadable() )
563  {
564  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
565  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
566  }
567 
568  // Append path for macOS install
569  fn.RemoveLastDir();
570  fn.RemoveLastDir();
571  fn.RemoveLastDir();
572  fn.AppendDir( "internat" );
573 
574  if( fn.IsDirReadable() )
575  {
576  wxLogTrace( traceLocale, "Adding locale lookup path: " + fn.GetPath() );
577  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
578  }
579  }
580 
581  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
582  {
583  wxFileName fn( Pgm().GetExecutablePath() );
584  fn.RemoveLastDir();
585  fn.AppendDir( "translation" );
586  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
587  }
588 }
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:160

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

592 {
593  wxString env;
594 
595  if( aName.IsEmpty() )
596  {
597  wxLogTrace( traceEnvVars,
598  "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s",
599  aValue );
600  return false;
601  }
602 
603  // Check to see if the environment variable is already set.
604  if( wxGetEnv( aName, &env ) )
605  {
606  wxLogTrace( traceEnvVars,
607  "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s",
608  aName, env );
609  return env == aValue;
610  }
611 
612  wxLogTrace( traceEnvVars,
613  "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s",
614  aName, aValue );
615 
616  return wxSetEnv( aName, aValue );
617 }
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 620 of file pgm_base.cpp.

621 {
622  // Overwrites externally defined environment variable until the next time the application
623  // is run.
624  for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
625  {
626  wxLogTrace( traceEnvVars,
627  "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s",
628  m_local_env_var.first,
629  m_local_env_var.second.GetValue() );
630  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
631  }
632 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
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 166 of file pgm_base.h.

166 { m_pdf_browser = aFileName; }
wxString m_pdf_browser
Definition: pgm_base.h:321

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SetTextEditor()

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

Definition at line 139 of file pgm_base.cpp.

140 {
141  m_text_editor = aFileName;
142  GetCommonSettings()->m_System.text_editor = aFileName;
143 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:381
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:323

References PGM_BASE::GetCommonSettings(), COMMON_SETTINGS::m_System, PGM_BASE::m_text_editor, and COMMON_SETTINGS::SYSTEM::text_editor.

Referenced by PGM_BASE::GetTextEditor().

◆ SysSearch()

SEARCH_STACK& PGM_KICAD::SysSearch ( )
inline

Definition at line 56 of file pgm_kicad.h.

56 { return m_bm.m_search; }
SEARCH_STACK m_search
Definition: bin_mod.h:60
BIN_MOD m_bm
Definition: pgm_kicad.h:67

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

174  {
175  return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
176  }
bool m_use_system_pdf_browser
Definition: pgm_base.h:320
wxString m_pdf_browser
Definition: pgm_base.h:321

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

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtualinherited

Member Data Documentation

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protectedinherited

Definition at line 314 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 67 of file pgm_kicad.h.

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

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protectedinherited

full path to this program

Definition at line 315 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

The KICAD system environment variable.

Definition at line 317 of file pgm_base.h.

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

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount
inherited

Definition at line 293 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

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

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

◆ m_python_scripting

std::unique_ptr<SCRIPTING> PGM_BASE::m_python_scripting
protectedinherited

Definition at line 312 of file pgm_base.h.

Referenced by PGM_BASE::InitPgm().

◆ m_settings_manager

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

◆ m_text_editor

wxString PGM_BASE::m_text_editor
protectedinherited

Filename of the app selected for browsing PDFs.

Definition at line 323 of file pgm_base.h.

Referenced by PGM_BASE::GetTextEditor(), PGM_BASE::loadCommonSettings(), and PGM_BASE::SetTextEditor().

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protectedinherited

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
staticinherited

Definition at line 259 of file pgm_base.h.


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