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
 

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

106 {
107  m_locale = nullptr;
108  m_Printing = false;
109  m_ModalDialogCount = 0;
110 
111  setLanguageId( wxLANGUAGE_DEFAULT );
112 
113  ForceSystemPdfBrowser( false );
114 }
int m_ModalDialogCount
Definition: pgm_base.h:293
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:317
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:300
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

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

◆ ~PGM_BASE()

PGM_BASE::~PGM_BASE ( )
virtual

Definition at line 117 of file pgm_base.cpp.

118 {
119  Destroy();
120 }
void Destroy()
Definition: pgm_base.cpp:123

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

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

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

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

References _, name, and path.

Referenced by GetTextEditor().

◆ Destroy()

void PGM_BASE::Destroy ( )

Definition at line 123 of file pgm_base.cpp.

124 {
125  // unlike a normal destructor, this is designed to be called more than once safely:
126  delete m_locale;
127  m_locale = nullptr;
128 }
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:317

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

References m_use_system_pdf_browser.

Referenced by PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtual

Definition at line 380 of file pgm_base.cpp.

381 {
383 }
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(), GetSettingsManager(), and 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:314

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

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

References m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtual

Definition at line 634 of file pgm_base.cpp.

635 {
636  return GetCommonSettings()->m_Env.vars;
637 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:380
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:321

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

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

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

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.

Definition at line 202 of file pgm_base.cpp.

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

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

References m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protected

Loads internal settings from COMMON_SETTINGS.

Definition at line 344 of file pgm_base.cpp.

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

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

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

482 {
483  setLanguageId( wxLANGUAGE_DEFAULT );
484 
485  // dictionary file name without extend (full name is kicad.mo)
486  wxString dictionaryName( "kicad" );
487 
488  delete m_locale;
489  m_locale = new wxLocale;
490  m_locale->Init();
491 
492  // Try adding the dictionary if it is not currently loaded
493  if( !m_locale->IsLoaded( dictionaryName ) )
494  m_locale->AddCatalog( dictionaryName );
495 
496  // Verify the Kicad dictionary was loaded properly
497  // However, for the English language, the dictionary is not mandatory, as
498  // all messages are already in English, just restricted to ASCII7 chars,
499  // the verification is skipped.
500  if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
501  {
502  wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
503  dictionaryName, m_locale->GetName() );
504 
505  setLanguageId( wxLANGUAGE_DEFAULT );
506  delete m_locale;
507 
508  m_locale = new wxLocale;
509  m_locale->Init();
510 
511  aErrMsg = _( "The KiCad language file for this language is not installed." );
512  return false;
513  }
514 
515  return true;
516 }
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:102

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

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

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

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

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

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

520 {
521  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
522  menu_id, (int)arrayDim( LanguagesList )-1 );
523 
524  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
525  {
526  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
527  {
528  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
529  break;
530  }
531  }
532 }
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, setLanguageId(), and traceLocale.

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtual

Definition at line 535 of file pgm_base.cpp.

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

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

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

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

References m_pdf_browser.

Referenced by ReadPdfBrowserInfos().

◆ SetTextEditor()

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

Definition at line 138 of file pgm_base.cpp.

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

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:320
wxString m_pdf_browser
Definition: pgm_base.h:321

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

50 {
53 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:380
bool m_use_system_pdf_browser
Definition: pgm_base.h:320
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 314 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 315 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 317 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 321 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 312 of file pgm_base.h.

Referenced by InitPgm().

◆ 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 323 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: