KiCad PCB EDA Suite
PGM_SINGLE_TOP Struct Reference

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

Inheritance diagram for PGM_SINGLE_TOP:
PGM_BASE

Public Member Functions

bool OnPgmInit ()
 
void OnPgmExit ()
 
void MacOpenFile (const wxString &aFileName) override
 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

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

Definition at line 66 of file single_top.cpp.

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

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

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

◆ AskUserForPreferredEditor()

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

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

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

Definition at line 184 of file pgm_base.cpp.

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

References _, name, and path.

Referenced by PGM_BASE::GetTextEditor().

◆ Destroy()

void PGM_BASE::Destroy ( )
inherited

Definition at line 126 of file pgm_base.cpp.

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

References PGM_BASE::m_locale.

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

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

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

385 {
387 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:312
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:316

References PGM_BASE::m_bin_dir.

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

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

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

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtualinherited

Definition at line 640 of file pgm_base.cpp.

641 {
642  return GetCommonSettings()->m_Env.vars;
643 }
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:384
ENVIRONMENT m_Env

References PGM_BASE::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
inlinevirtualinherited

Definition at line 164 of file pgm_base.h.

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

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

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

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

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

Definition at line 205 of file pgm_base.cpp.

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

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

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 348 of file pgm_base.cpp.

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

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 85 of file single_top.cpp.

86  {
87  wxFileName filename( aFileName );
88 
89  if( filename.FileExists() )
90  {
91  #if 0
92  // this pulls in EDA_DRAW_FRAME type info, which we don't want in
93  // the single_top link image.
94  KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
95  #else
96  KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
97  #endif
98  if( frame )
99  frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
100  }
101  }
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:118
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:134

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

◆ OnPgmExit()

void PGM_SINGLE_TOP::OnPgmExit ( )
inline

Definition at line 70 of file single_top.cpp.

71  {
72  Kiway.OnKiwayEnd();
73 
74  if( m_settings_manager && m_settings_manager->IsOK() )
75  {
77  m_settings_manager->Save();
78  }
79 
80  // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
81  // earlier than wxApp and earlier than static destruction would.
83  }
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
Definition: pgm_base.cpp:375
void Destroy()
Definition: pgm_base.cpp:126
void OnKiwayEnd()
Definition: kiway.cpp:641
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
Definition: pgm_base.h:312
KIWAY Kiway

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

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

◆ OnPgmInit()

bool PGM_SINGLE_TOP::OnPgmInit ( )

Definition at line 272 of file single_top.cpp.

273 {
274 #if defined(DEBUG)
275  wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
276 
277  if( !wxIsAbsolutePath( absoluteArgv0 ) )
278  {
279  wxLogError( wxT( "No meaningful argv[0]" ) );
280  return false;
281  }
282 #endif
283 
284  // Not all kicad applications use the python stuff. skip python init
285  // for these apps.
286  bool skip_python_initialization = false;
287 #if defined( BITMAP_2_CMP ) || defined( PL_EDITOR ) || defined( GERBVIEW ) ||\
288  defined( PCB_CALCULATOR_BUILD )
289  skip_python_initialization = true;
290 #endif
291 
292  if( !InitPgm( false, skip_python_initialization ) )
293  {
294  // Clean up
295  OnPgmExit();
296  return false;
297  }
298 
299 #if !defined(BUILD_KIWAY_DLL)
300 
301  // Only bitmap2component and pcb_calculator use this code currently, as they
302  // are not split to use single_top as a link image separate from a *.kiface.
303  // i.e. they are single part link images so don't need to load a *.kiface.
304 
305  // Get the getter, it is statically linked into this binary image.
306  KIFACE_GETTER_FUNC* ki_getter = &KIFACE_GETTER;
307 
308  int kiface_version;
309 
310  // Get the KIFACE.
311  KIFACE* kiface = ki_getter( &kiface_version, KIFACE_VERSION, this );
312 
313  // Trick the KIWAY into thinking it loaded a KIFACE, by recording the KIFACE
314  // in the KIWAY. It needs to be there for KIWAY::OnKiwayEnd() anyways.
315  Kiway.set_kiface( KIWAY::KifaceType( TOP_FRAME ), kiface );
316 #endif
317 
318  static const wxCmdLineEntryDesc desc[] = {
319  { wxCMD_LINE_OPTION, "f", "frame", "Frame to load", wxCMD_LINE_VAL_STRING, 0 },
320  { wxCMD_LINE_PARAM, nullptr, nullptr, "File to load", wxCMD_LINE_VAL_STRING,
321  wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
322  { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
323  };
324 
325  wxCmdLineParser parser( App().argc, App().argv );
326  parser.SetDesc( desc );
327  parser.Parse( false );
328 
329  FRAME_T appType = TOP_FRAME;
330 
331  const struct
332  {
333  wxString name;
334  FRAME_T type;
335  } frameTypes[] = {
336  { wxT( "pcb" ), FRAME_PCB_EDITOR },
337  { wxT( "fpedit" ), FRAME_FOOTPRINT_EDITOR },
338  { wxT( "" ), FRAME_T_COUNT }
339  };
340 
341  wxString frameName;
342 
343  if( parser.Found( "frame", &frameName ) )
344  {
345  appType = FRAME_T_COUNT;
346 
347  for( const auto& it : frameTypes )
348  {
349  if( it.name == frameName )
350  appType = it.type;
351  }
352 
353  if( appType == FRAME_T_COUNT )
354  {
355  wxLogError( wxT( "Unknown frame: %s" ), frameName );
356  // Clean up
357  OnPgmExit();
358  return false;
359  }
360  }
361 
362  // Tell the settings manager about the current Kiway
364 
365  // Use KIWAY to create a top window, which registers its existence also.
366  // "TOP_FRAME" is a macro that is passed on compiler command line from CMake,
367  // and is one of the types in FRAME_T.
368  KIWAY_PLAYER* frame = Kiway.Player( appType, true );
369 
370  if( frame == nullptr )
371  {
372  return false;
373  }
374 
375  Kiway.SetTop( frame );
376 
377  App().SetTopWindow( frame ); // wxApp gets a face.
378  App().SetAppDisplayName( frame->GetAboutTitle() );
379 
380  // Allocate a slice of time to show the frame and update wxWidgets widgets
381  // (especially setting valid sizes) after creating frame and before calling
382  // OpenProjectFiles() that can update/use some widgets.
383  // The 2 calls to wxSafeYield are needed on wxGTK for best results.
384  wxSafeYield();
385  frame->Show();
386  wxSafeYield();
387 
388  // Individual frames may provide additional option/switch processing, but for compatibility,
389  // any positional arguments are treated as a list of files to pass to OpenProjectFiles
390  frame->ParseArgs( parser );
391 
392  // Now after the frame processing, the rest of the positional args are files
393  std::vector<wxString> fileArgs;
394 
395  if( parser.GetParamCount() )
396  {
397  /*
398  gerbview handles multiple project data files, i.e. gerber files on
399  cmd line. Others currently do not, they handle only one. For common
400  code simplicity we simply pass all the arguments in however, each
401  program module can do with them what they want, ignore, complain
402  whatever. We don't establish policy here, as this is a multi-purpose
403  launcher.
404  */
405 
406  for( size_t i = 0; i < parser.GetParamCount(); i++ )
407  fileArgs.push_back( parser.GetParam( i ) );
408 
409  // special attention to a single argument: argv[1] (==argSet[0])
410  if( fileArgs.size() == 1 )
411  {
412  wxFileName argv1( fileArgs[0] );
413 
414 #if defined(PGM_DATA_FILE_EXT)
415  // PGM_DATA_FILE_EXT, if present, may be different for each compile,
416  // it may come from CMake on the compiler command line, but often does not.
417  // This facility is mostly useful for those program footprints
418  // supporting a single argv[1].
419  if( !argv1.GetExt() )
420  argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
421 #endif
422  argv1.MakeAbsolute();
423 
424  fileArgs[0] = argv1.GetFullPath();
425  }
426 
427  // Use the KIWAY_PLAYER::OpenProjectFiles() API function:
428  if( !frame->OpenProjectFiles( fileArgs ) )
429  {
430  // OpenProjectFiles() API asks that it report failure to the UI.
431  // Nothing further to say here.
432 
433  // We've already initialized things at this point, but wx won't call OnExit if
434  // we fail out. Call our own cleanup routine here to ensure the relevant resources
435  // are freed at the right time (if they aren't, segfaults will occur).
436  OnPgmExit();
437 
438  // Fail the process startup if the file could not be opened,
439  // although this is an optional choice, one that can be reversed
440  // also in the KIFACE specific OpenProjectFiles() return value.
441  return false;
442  }
443  }
444 
445  return true;
446 }
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:118
BITMAP2CMP_SETTINGS kiface
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false)
Initialize this program.
Definition: pgm_base.cpp:205
static FACE_T KifaceType(FRAME_T aFrameType)
A simple mapping function which returns the FACE_T which is known to implement aFrameType.
Definition: kiway.cpp:321
void OnPgmExit()
Definition: single_top.cpp:70
#define KIFACE_VERSION
The KIWAY and KIFACE classes are used to communicate between various process modules,...
Definition: kiway.h:109
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:134
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
bool set_kiface(FACE_T aFaceType, KIFACE *aKiface)
Definition: kiway.h:404
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
Definition: kiway.h:458
#define KIFACE_GETTER
Definition: kiway.h:110
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
const char * name
Definition: DXF_plotter.cpp:56
const wxString & GetAboutTitle() const
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:148
virtual void ParseArgs(wxCmdLineParser &aParser)
Handle command-line arguments in a frame-specific way.
Definition: kiway_player.h:139
KIWAY Kiway

References FRAME_FOOTPRINT_EDITOR, FRAME_PCB_EDITOR, FRAME_T_COUNT, EDA_BASE_FRAME::GetAboutTitle(), PGM_BASE::GetExecutablePath(), GetSettingsManager(), kiface, KIFACE_GETTER, KIFACE_VERSION, KIWAY::KifaceType(), Kiway, name, KIWAY_PLAYER::OpenProjectFiles(), KIWAY_PLAYER::ParseArgs(), KIWAY::Player(), KIWAY::set_kiface(), SETTINGS_MANAGER::SetKiway(), and KIWAY::SetTop().

Referenced by APP_SINGLE_TOP::OnInit().

◆ 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:384
bool m_use_system_pdf_browser
Definition: pgm_base.h:322
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 375 of file pgm_base.cpp.

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

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

Referenced by PGM_KICAD::OnPgmExit(), and 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 487 of file pgm_base.cpp.

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

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

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

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

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

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

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

References PGM_BASE::m_language_id.

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

◆ SetLanguageIdentifier()

void PGM_BASE::SetLanguageIdentifier ( int  menu_id)
virtualinherited

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

526 {
527  wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",
528  menu_id, (int)arrayDim( LanguagesList )-1 );
529 
530  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
531  {
532  if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
533  {
534  setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
535  break;
536  }
537  }
538 }
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:302
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 541 of file pgm_base.cpp.

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

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

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

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SetTextEditor()

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

Definition at line 141 of file pgm_base.cpp.

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

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

Referenced by PGM_BASE::GetTextEditor().

◆ 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:322
wxString m_pdf_browser
Definition: pgm_base.h:323

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

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

◆ m_kicad_env

wxString PGM_BASE::m_kicad_env
protectedinherited

full path to this program

Definition at line 317 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 319 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 314 of file pgm_base.h.

Referenced by PGM_BASE::InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting
inherited

Definition at line 295 of file pgm_base.h.

Referenced by PGM_BASE::PGM_BASE().

◆ 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 325 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 struct was generated from the following file: