KiCad PCB EDA Suite
PGM_BASE Class Referenceabstract

Container for data for KiCad programs. More...

#include <pgm_base.h>

Inheritance diagram for PGM_BASE:
PGM_KICAD PGM_MOCK_EESCHEMA_FRAME PGM_SINGLE_TOP PGM_TEST_FRAME PGM_TEST_FRAME PGM_TEST_FRAME

Public Member Functions

 PGM_BASE ()
 
virtual ~PGM_BASE ()
 
virtual void MacOpenFile (const wxString &aFileName)=0
 Specific to MacOSX (not used under Linux or Windows). More...
 
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 Destroy ()
 
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
 
bool m_Quitting
 

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

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

Container for data for KiCad programs.

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

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

Definition at line 93 of file pgm_base.h.

Constructor & Destructor Documentation

◆ PGM_BASE()

PGM_BASE::PGM_BASE ( )

Definition at line 108 of file pgm_base.cpp.

109 {
110  m_locale = nullptr;
111  m_Printing = false;
112  m_Quitting = false;
113  m_ModalDialogCount = 0;
114 
115  setLanguageId( wxLANGUAGE_DEFAULT );
116 
117  ForceSystemPdfBrowser( false );
118 }
int m_ModalDialogCount
Definition: pgm_base.h:293
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:319
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
Definition: pgm_base.h:181
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:302
bool m_Printing
wxWidgets on MSW tends to crash if you spool up more than one print job at a time.
Definition: pgm_base.h:291
bool m_Quitting
Definition: pgm_base.h:295

References ForceSystemPdfBrowser(), m_locale, m_ModalDialogCount, m_Printing, m_Quitting, and setLanguageId().

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 121 of file pgm_base.cpp.

122 {
123  Destroy();
124 }
void Destroy()
Definition: pgm_base.cpp:127

References Destroy().

Member Function Documentation

◆ App()

wxApp & PGM_BASE::App ( )
virtual

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

This should return what wxGetApp() returns.

Definition at line 135 of file pgm_base.cpp.

136 {
137  wxASSERT( wxTheApp );
138  return *wxTheApp;
139 }

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

◆ AskUserForPreferredEditor()

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

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

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

References _, name, and path.

Referenced by GetTextEditor().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 127 of file pgm_base.cpp.

128 {
129  // unlike a normal destructor, this is designed to be called more than once safely:
130  delete m_locale;
131  m_locale = nullptr;
132 }
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:319

References m_locale.

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

◆ ForceSystemPdfBrowser()

virtual void PGM_BASE::ForceSystemPdfBrowser ( bool  aFlg)
inlinevirtual

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:322

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 385 of file pgm_base.cpp.

386 {
387  return m_settings_manager ? m_settings_manager->GetCommonSettings() : nullptr;
388 }
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:312

References m_settings_manager.

Referenced by GetLocalEnvVariables(), InitPgm(), loadCommonSettings(), ReadPdfBrowserInfos(), SaveCommonSettings(), SetLanguage(), SetLocalEnvVariables(), SetTextEditor(), and WritePdfBrowserInfos().

◆ GetExecutablePath()

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

Definition at line 160 of file pgm_base.h.

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

References m_bin_dir.

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

◆ GetKicadEnvVariable()

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

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:317

References m_kicad_env.

◆ GetLocale()

virtual wxLocale* PGM_BASE::GetLocale ( )
inlinevirtual

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:319

References m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtual

Definition at line 600 of file pgm_base.cpp.

601 {
602  return GetCommonSettings()->m_Env.vars;
603 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
ENVIRONMENT m_Env

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

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

◆ GetPdfBrowserName()

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

Definition at line 164 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by WritePdfBrowserInfos().

◆ GetSelectedLanguageIdentifier()

virtual int PGM_BASE::GetSelectedLanguageIdentifier ( ) const
inlinevirtual
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:320

References m_language_id.

◆ GetSettingsManager()

◆ GetTextEditor()

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

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

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

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

◆ InitPgm()

bool PGM_BASE::InitPgm ( bool  aHeadless = false,
bool  aSkipPyInit = false 
)

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.

Should never happen but boost unit_test isn't playing nicely in some cases

Definition at line 206 of file pgm_base.cpp.

207 {
208  wxString pgm_name;
209 
211  if( App().argc == 0 )
212  pgm_name = wxT( "kicad" );
213  else
214  pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
215 
216  wxInitAllImageHandlers();
217 
218 #ifndef __WINDOWS__
219  if( wxString( wxGetenv( wxT( "HOME" ) ) ).IsEmpty() )
220  {
221  DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
222  "Unable to continue." ) );
223  return false;
224  }
225 #endif
226 
227  // Init KiCad environment
228  // the environment variable KICAD (if exists) gives the kicad path:
229  // something like set KICAD=d:\kicad
230  bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_kicad_env );
231 
232  if( isDefined ) // ensure m_kicad_env ends by "/"
233  {
235 
236  if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
238  }
239 
240  // Init parameters for configuration
241  App().SetVendorName( wxT( "KiCad" ) );
242  App().SetAppName( pgm_name );
243 
244  // Install some image handlers, mainly for help
245  if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr )
246  wxImage::AddHandler( new wxPNGHandler );
247 
248  if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr )
249  wxImage::AddHandler( new wxGIFHandler );
250 
251  if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr )
252  wxImage::AddHandler( new wxJPEGHandler );
253 
254  wxFileSystem::AddHandler( new wxZipFSHandler );
255 
256  // Analyze the command line & initialize the binary path
257  wxString tmp;
259  SetLanguagePath();
260  SetDefaultLanguage( tmp );
261 
262  m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
263 
264  // Something got in the way of settings load: can't continue
265  if( !m_settings_manager->IsOK() )
266  return false;
267 
268  // Set up built-in environment variables (and override them from the system environment if set)
270 
271  // Load color settings after env is initialized
272  m_settings_manager->ReloadColorSettings();
273 
274  // Load common settings from disk after setting up env vars
276 
277  // Init user language *before* calling loadSettings, because
278  // env vars could be incorrectly initialized on Linux
279  // (if the value contains some non ASCII7 chars, the env var is not initialized)
280  SetLanguage( tmp, true );
281 
282  // Now that translations are available, inform the user if the OS is unsupported
284 
286 
287  ReadPdfBrowserInfos(); // needs GetCommonSettings()
288 
289  // Create the python scripting stuff
290  // Skip it fot applications that do not use it
291  if( !aSkipPyInit )
292  m_python_scripting = std::make_unique<SCRIPTING>();
293 
294  // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
295  // Need to create a project early for now (it can have an empty path for the moment)
297 
298  // TODO: Move tooltips into KIPLATFORM
299  // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
300  // Windows as other platforms display tooltips while the mouse is not moving
301  wxToolTip::SetAutoPop( 10000 );
302 
303  return true;
304 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:314
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:349
#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:135
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:307
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:312
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:317
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:391
virtual void SetLanguagePath()
Definition: pgm_base.cpp:542
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:105
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:488

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

Referenced by PGM_KICAD::OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtual

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:317

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 349 of file pgm_base.cpp.

350 {
352 
353  for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
354  {
355  wxLogTrace( traceEnvVars, wxT( "PGM_BASE::loadSettings: Found entry %s = %s" ),
356  it.first, it.second.GetValue() );
357 
358  // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
359  // it is found in config. (It is reserved and defined as project path)
360  if( it.first == PROJECT_VAR_NAME )
361  continue;
362 
363  // Don't set bogus empty entries in the environment
364  if( it.first.IsEmpty() )
365  continue;
366 
367  // Do not overwrite vars set by the system environment with values from the settings file
368  if( it.second.GetDefinedExternally() )
369  continue;
370 
371  SetLocalEnvVariable( it.first, it.second.GetValue() );
372  }
373 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
#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:556
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:325

References GetCommonSettings(), COMMON_SETTINGS::m_System, m_text_editor, PROJECT_VAR_NAME, SetLocalEnvVariable(), COMMON_SETTINGS::SYSTEM::text_editor, and traceEnvVars.

Referenced by InitPgm().

◆ MacOpenFile()

virtual void PGM_BASE::MacOpenFile ( const wxString &  aFileName)
pure virtual

Specific to MacOSX (not used under Linux or Windows).

MacOSX requires it for file association.

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

Implemented in PGM_TEST_FRAME, PGM_MOCK_EESCHEMA_FRAME, PGM_SINGLE_TOP, PGM_TEST_FRAME, PGM_KICAD, and PGM_TEST_FRAME.

◆ ReadPdfBrowserInfos()

void PGM_BASE::ReadPdfBrowserInfos ( )
virtual

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:385
bool m_use_system_pdf_browser
Definition: pgm_base.h:322
virtual void SetPdfBrowserName(const wxString &aFileName)
Definition: pgm_base.h:166

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

Referenced by InitPgm().

◆ SaveCommonSettings()

void PGM_BASE::SaveCommonSettings ( )

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

Definition at line 376 of file pgm_base.cpp.

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

References GetCommonSettings(), COMMON_SETTINGS::m_System, and COMMON_SETTINGS::SYSTEM::working_dir.

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

◆ SetDefaultLanguage()

bool PGM_BASE::SetDefaultLanguage ( wxString &  aErrMsg)

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

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

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

Referenced by InitPgm().

◆ setExecutablePath()

bool PGM_BASE::setExecutablePath ( )
protected

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

Returns
true if success, else false.

Definition at line 307 of file pgm_base.cpp.

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

References m_bin_dir, UNIX_STRING_DIR_SEP, and WIN_STRING_DIR_SEP.

Referenced by InitPgm().

◆ SetLanguage()

bool PGM_BASE::SetLanguage ( wxString &  aErrMsg,
bool  first_time = false 
)
virtual

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

392 {
393  if( first_time )
394  {
395  setLanguageId( wxLANGUAGE_DEFAULT );
396  // First time SetLanguage is called, the user selected language id is set
397  // from common user config settings
398  wxString languageSel = GetCommonSettings()->m_System.language;
399 
400  // Search for the current selection
401  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
402  {
403  if( LanguagesList[ii].m_Lang_Label == languageSel )
404  {
405  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
406  break;
407  }
408  }
409  }
410 
411  // dictionary file name without extend (full name is kicad.mo)
412  wxString dictionaryName( wxT( "kicad" ) );
413 
414  delete m_locale;
415  m_locale = new wxLocale;
416 
417  // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
418  // false just because it failed to load wxstd catalog
419  if( !m_locale->Init( m_language_id, wxLOCALE_DONT_LOAD_DEFAULT ) )
420  {
421  wxLogTrace( traceLocale, wxT( "This language is not supported by the system." ) );
422 
423  setLanguageId( wxLANGUAGE_DEFAULT );
424  delete m_locale;
425 
426  m_locale = new wxLocale;
427  m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
428 
429  aErrMsg = _( "This language is not supported by the operating system." );
430  return false;
431  }
432  else if( !first_time )
433  {
434  wxLogTrace( traceLocale, wxT( "Search for dictionary %s.mo in %s" ),
435  dictionaryName, m_locale->GetName() );
436  }
437 
438  if( !first_time )
439  {
440  // If we are here, the user has selected another language.
441  // Therefore the new preferred language name is stored in common config.
442  // Do NOT store the wxWidgets language Id, it can change between wxWidgets
443  // versions, for a given language
444  wxString languageSel;
445 
446  // Search for the current selection language name
447  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
448  {
449  if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
450  {
451  languageSel = LanguagesList[ii].m_Lang_Label;
452  break;
453  }
454  }
455 
457  cfg->m_System.language = languageSel;
458  cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
459  }
460 
461  // Try adding the dictionary if it is not currently loaded
462  if( !m_locale->IsLoaded( dictionaryName ) )
463  m_locale->AddCatalog( dictionaryName );
464 
465  // Verify the Kicad dictionary was loaded properly
466  // However, for the English language, the dictionary is not mandatory, as
467  // all messages are already in English, just restricted to ASCII7 chars,
468  // the verification is skipped.
469  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
470  {
471  wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
472  dictionaryName, m_locale->GetName() );
473 
474  setLanguageId( wxLANGUAGE_DEFAULT );
475  delete m_locale;
476 
477  m_locale = new wxLocale;
478  m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
479 
480  aErrMsg = _( "The KiCad language file for this language is not installed." );
481  return false;
482  }
483 
484  return true;
485 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
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:71
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:319
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: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:302
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:105

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

Referenced by InitPgm().

◆ setLanguageId()

void PGM_BASE::setLanguageId ( int  aId)
inlineprotected

Trap all changes in here, simplifies debugging.

Definition at line 302 of file pgm_base.h.

302 { m_language_id = aId; }
int m_language_id
Definition: pgm_base.h:320

References m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
virtual

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

527 {
528  wxLogTrace( traceLocale, wxT( "Select language ID %d from %d possible languages." ),
529  menu_id, (int)arrayDim( LanguagesList )-1 );
530 
531  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
532  {
533  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
534  {
535  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
536  break;
537  }
538  }
539 }
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:71
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:302
const wxChar *const traceLocale
Flag to enable locale debug output.

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtual

Definition at line 542 of file pgm_base.cpp.

543 {
544  wxLocale::AddCatalogLookupPathPrefix( PATHS::GetLocaleDataPath() );
545 
546  if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
547  {
548  wxFileName fn( Pgm().GetExecutablePath() );
549  fn.RemoveLastDir();
550  fn.AppendDir( wxT( "translation" ) );
551  wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
552  }
553 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:160
static wxString GetLocaleDataPath()
Gets the locales translation data path.
Definition: paths.cpp:252

References GetExecutablePath(), PATHS::GetLocaleDataPath(), and Pgm().

Referenced by InitPgm().

◆ SetLocalEnvVariable()

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

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

557 {
558  wxString env;
559 
560  if( aName.IsEmpty() )
561  {
562  wxLogTrace( traceEnvVars,
563  wxT( "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s" ),
564  aValue );
565  return false;
566  }
567 
568  // Check to see if the environment variable is already set.
569  if( wxGetEnv( aName, &env ) )
570  {
571  wxLogTrace( traceEnvVars,
572  wxT( "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s" ),
573  aName, env );
574  return env == aValue;
575  }
576 
577  wxLogTrace( traceEnvVars,
578  wxT( "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
579  aName, aValue );
580 
581  return wxSetEnv( aName, aValue );
582 }
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References traceEnvVars.

Referenced by loadCommonSettings().

◆ SetLocalEnvVariables()

void PGM_BASE::SetLocalEnvVariables ( )
virtual

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

See also
GetLocalEnvVariables()

Definition at line 585 of file pgm_base.cpp.

586 {
587  // Overwrites externally defined environment variable until the next time the application
588  // is run.
589  for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
590  {
591  wxLogTrace( traceEnvVars,
592  wxT( "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s" ),
593  m_local_env_var.first,
594  m_local_env_var.second.GetValue() );
595  wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
596  }
597 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.

References GetCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

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

Definition at line 166 of file pgm_base.h.

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

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ SetTextEditor()

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

Definition at line 142 of file pgm_base.cpp.

143 {
144  m_text_editor = aFileName;
145  GetCommonSettings()->m_System.text_editor = aFileName;
146 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:325

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

Referenced by GetTextEditor().

◆ UseSystemPdfBrowser()

virtual bool PGM_BASE::UseSystemPdfBrowser ( ) const
inlinevirtual
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:322
wxString m_pdf_browser
Definition: pgm_base.h:323

References m_pdf_browser, and m_use_system_pdf_browser.

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtual

Save the PDF browser choice to the common configuration.

Definition at line 44 of file eda_doc.cpp.

45 {
48 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:385
bool m_use_system_pdf_browser
Definition: pgm_base.h:322
virtual const wxString & GetPdfBrowserName() const
Definition: pgm_base.h:164

References GetCommonSettings(), GetPdfBrowserName(), COMMON_SETTINGS::m_System, 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
protected

Definition at line 316 of file pgm_base.h.

Referenced by GetExecutablePath(), and setExecutablePath().

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protected

full path to this program

Definition at line 317 of file pgm_base.h.

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

◆ m_language_id

int PGM_BASE::m_language_id
protected

◆ m_locale

wxLocale* PGM_BASE::m_locale
protected

The KICAD system environment variable.

Definition at line 319 of file pgm_base.h.

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

◆ m_ModalDialogCount

int PGM_BASE::m_ModalDialogCount

Definition at line 293 of file pgm_base.h.

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

◆ m_pdf_browser

wxString PGM_BASE::m_pdf_browser
protected

Definition at line 323 of file pgm_base.h.

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

◆ m_Printing

bool PGM_BASE::m_Printing

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().

◆ m_python_scripting

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

Definition at line 314 of file pgm_base.h.

Referenced by InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting

Definition at line 295 of file pgm_base.h.

Referenced by PGM_BASE().

◆ m_settings_manager

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

◆ m_text_editor

wxString PGM_BASE::m_text_editor
protected

Filename of the app selected for browsing PDFs.

Definition at line 325 of file pgm_base.h.

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

◆ m_use_system_pdf_browser

bool PGM_BASE::m_use_system_pdf_browser
protected

◆ workingDirKey

const wxChar PGM_BASE::workingDirKey[]
static

Definition at line 259 of file pgm_base.h.


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