KiCad PCB EDA Suite
PGM_TEST_FRAME Struct Reference
Inheritance diagram for PGM_TEST_FRAME:
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

Definition at line 95 of file test_app_main.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 152 of file pgm_base.cpp.

153{
154 wxASSERT( wxTheApp );
155 return *wxTheApp;
156}

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

203{
204 // Create a mask representing the executable files in the current platform
205#ifdef __WINDOWS__
206 wxString mask( _( "Executable file" ) + wxT( " (*.exe)|*.exe" ) );
207#else
208 wxString mask( _( "Executable file" ) + wxT( " (*)|*" ) );
209#endif
210
211 // Extract the path, name and extension from the default editor (even if the editor's
212 // name was empty, this method will succeed and return empty strings).
213 wxString path, name, ext;
214 wxFileName::SplitPath( aDefaultEditor, &path, &name, &ext );
215
216 // Show the modal editor and return the file chosen (may be empty if the user cancels
217 // the dialog).
218 return wxFileSelector( _( "Select Preferred Editor" ), path, name, wxT( "." ) + ext,
219 mask, wxFD_OPEN | wxFD_FILE_MUST_EXIST, nullptr );
220}
const char * name
Definition: DXF_plotter.cpp:56
#define _(s)
Current list of languages supported by KiCad.
Definition: pgm_base.cpp:118

References _, name, and path.

Referenced by PGM_BASE::GetTextEditor().

◆ Destroy()

void PGM_BASE::Destroy ( )
inherited

Definition at line 140 of file pgm_base.cpp.

141{
142#ifdef KICAD_USE_SENTRY
143 sentry_close();
144#endif
145
146 // unlike a normal destructor, this is designed to be called more than once safely:
147 delete m_locale;
148 m_locale = nullptr;
149}
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:331

References PGM_BASE::m_locale.

Referenced by PGM_KICAD::Destroy(), PGM_SINGLE_TOP::OnPgmExit(), 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:334

References PGM_BASE::m_use_system_pdf_browser.

Referenced by PGM_BASE::PGM_BASE().

◆ GetCommonSettings()

COMMON_SETTINGS * PGM_BASE::GetCommonSettings ( ) const
virtualinherited

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

References PGM_BASE::m_bin_dir.

Referenced by PGM_SINGLE_TOP::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:329

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; }

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtualinherited

Definition at line 784 of file pgm_base.cpp.

785{
786 return GetCommonSettings()->m_Env.vars;
787}
ENVIRONMENT m_Env
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:569

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

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

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

167{
168 wxString editorname = m_text_editor;
169
170 if( !editorname )
171 {
172 if( !wxGetEnv( wxT( "EDITOR" ), &editorname ) )
173 {
174 // If there is no EDITOR variable set, try the desktop default
175#ifdef __WXMAC__
176 editorname = wxT( "/usr/bin/open -e" );
177#elif __WXX11__
178 editorname = wxT( "/usr/bin/xdg-open" );
179#endif
180 }
181 }
182
183 // If we still don't have an editor name show a dialog asking the user to select one
184 if( !editorname && aCanShowFileChooser )
185 {
186 DisplayInfoMessage( nullptr, _( "No default editor found, you must choose one." ) );
187
188 editorname = AskUserForPreferredEditor();
189 }
190
191 // If we finally have a new editor name request it to be copied to m_text_editor and
192 // saved to the preferences file.
193 if( !editorname.IsEmpty() )
194 SetTextEditor( editorname );
195
196 // m_text_editor already has the same value that editorname, or empty if no editor was
197 // found/chosen.
198 return m_text_editor;
199}
virtual void SetTextEditor(const wxString &aFileName)
Definition: pgm_base.cpp:159
wxString m_text_editor
Filename of the app selected for browsing PDFs.
Definition: pgm_base.h:337
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:202
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:320

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

370{
371 // Just make sure we init precreate any folders early for later code
372 // In particular, the user cache path is the most likely to be hit by startup code
374
375#ifdef KICAD_USE_SENTRY
376 sentryInit();
377#endif
378 wxString pgm_name;
379
381 if( App().argc == 0 )
382 pgm_name = wxT( "kicad" );
383 else
384 pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
385
386#ifdef KICAD_USE_SENTRY
387 sentry_set_tag( "kicad.app", pgm_name.c_str() );
388#endif
389
390 wxInitAllImageHandlers();
391
392 // Without this the wxPropertyGridManager segfaults on Windows.
393 wxPGInitResourceModule();
394
395#ifndef __WINDOWS__
396 if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
397 {
398 DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
399 "Unable to continue." ) );
400 return false;
401 }
402#endif
403
404 // Init KiCad environment
405 // the environment variable KICAD (if exists) gives the kicad path:
406 // something like set KICAD=d:\kicad
407 bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_kicad_env );
408
409 if( isDefined ) // ensure m_kicad_env ends by "/"
410 {
412
413 if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
415 }
416
417 // Init parameters for configuration
418 App().SetVendorName( wxT( "KiCad" ) );
419 App().SetAppName( pgm_name );
420
421 // Install some image handlers, mainly for help
422 if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr )
423 wxImage::AddHandler( new wxPNGHandler );
424
425 if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr )
426 wxImage::AddHandler( new wxGIFHandler );
427
428 if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr )
429 wxImage::AddHandler( new wxJPEGHandler );
430
431 wxFileSystem::AddHandler( new wxZipFSHandler );
432
433 // Analyze the command line & initialize the binary path
434 wxString tmp;
437 SetDefaultLanguage( tmp );
438
439 m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
440
441 // Something got in the way of settings load: can't continue
442 if( !m_settings_manager->IsOK() )
443 return false;
444
445 // Set up built-in environment variables (and override them from the system environment if set)
447
448 // Load color settings after env is initialized
449 m_settings_manager->ReloadColorSettings();
450
451 // Load common settings from disk after setting up env vars
453
454 // Init user language *before* calling loadSettings, because
455 // env vars could be incorrectly initialized on Linux
456 // (if the value contains some non ASCII7 chars, the env var is not initialized)
457 SetLanguage( tmp, true );
458
459 // Now that translations are available, inform the user if the OS is unsupported
461
463
464#ifdef KICAD_USE_SENTRY
465 sentryPrompt();
466#endif
467
468 ReadPdfBrowserInfos(); // needs GetCommonSettings()
469
470 // Create the python scripting stuff
471 // Skip it fot applications that do not use it
472 if( !aSkipPyInit )
473 m_python_scripting = std::make_unique<SCRIPTING>();
474
475 // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
476 // Need to create a project early for now (it can have an empty path for the moment)
478
479 // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
480 // Windows as other platforms display tooltips while the mouse is not moving
481 wxToolTip::Enable( true );
482 wxToolTip::SetAutoPop( 10000 );
483
484 if( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval != 0 )
485 wxUpdateUIEvent::SetUpdateInterval( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval );
486
487 return true;
488}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
static void EnsureUserPathsExist()
Ensures/creates user default paths.
Definition: paths.cpp:361
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:152
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:491
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:533
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:37
virtual void SetLanguagePath()
Definition: pgm_base.cpp:726
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:672
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:326
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:575
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
Definition: common.cpp:603
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:299
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:36
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:35

References _, PGM_BASE::App(), DisplayErrorMessage(), PATHS::EnsureUserPathsExist(), ADVANCED_CFG::GetCfg(), 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(); }

References PGM_BASE::m_kicad_env.

◆ loadCommonSettings()

void PGM_BASE::loadCommonSettings ( )
protectedinherited

Loads internal settings from COMMON_SETTINGS.

Definition at line 533 of file pgm_base.cpp.

534{
536
537 for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
538 {
539 wxLogTrace( traceEnvVars, wxT( "PGM_BASE::loadSettings: Found entry %s = %s" ),
540 it.first, it.second.GetValue() );
541
542 // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
543 // it is found in config. (It is reserved and defined as project path)
544 if( it.first == PROJECT_VAR_NAME )
545 continue;
546
547 // Don't set bogus empty entries in the environment
548 if( it.first.IsEmpty() )
549 continue;
550
551 // Do not overwrite vars set by the system environment with values from the settings file
552 if( it.second.GetDefinedExternally() )
553 continue;
554
555 SetLocalEnvVariable( it.first, it.second.GetValue() );
556 }
557}
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:740
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38

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_TEST_FRAME::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 110 of file test_app_main.cpp.

111 {
112 wxFileName filename( aFileName );
113
114 if( filename.FileExists() )
115 {
116 #if 0
117 // this pulls in EDA_DRAW_FRAME type info, which we don't want in
118 // the single_top link image.
119 KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
120 #else
121 KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
122 #endif
123
124 if( frame )
125 frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
126 }
127 }
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
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

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

◆ OnPgmExit()

void PGM_TEST_FRAME::OnPgmExit ( )
inline

Definition at line 99 of file test_app_main.cpp.

100 {
101 printf("Destroy\n");
103
104 // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
105 // earlier than wxApp and earlier than static destruction would.
107 }
void OnKiwayEnd()
Definition: kiway.cpp:672
void Destroy()
Definition: pgm_base.cpp:140
KIWAY Kiway

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

Referenced by APP_TEST::OnExit(), APP_TEST::OnInit(), and APP_TEST::OnRun().

◆ OnPgmInit()

bool PGM_TEST_FRAME::OnPgmInit ( )

Definition at line 236 of file test_app_main.cpp.

237{
238 return true;
239}

Referenced by APP_TEST::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 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 560 of file pgm_base.cpp.

561{
562 // GetCommonSettings() is not initialized until fairly late in the
563 // process startup: InitPgm(), so test before using:
564 if( GetCommonSettings() )
565 GetCommonSettings()->m_System.working_dir = wxGetCwd();
566}

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

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

673{
674 setLanguageId( wxLANGUAGE_DEFAULT );
675
676 // dictionary file name without extend (full name is kicad.mo)
677 wxString dictionaryName( wxT( "kicad" ) );
678
679 delete m_locale;
680 m_locale = new wxLocale;
681 m_locale->Init();
682
683 // Try adding the dictionary if it is not currently loaded
684 if( !m_locale->IsLoaded( dictionaryName ) )
685 m_locale->AddCatalog( dictionaryName );
686
687 // Verify the Kicad dictionary was loaded properly
688 // However, for the English language, the dictionary is not mandatory, as
689 // all messages are already in English, just restricted to ASCII7 chars,
690 // the verification is skipped.
691 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
692 {
693 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
694 dictionaryName, m_locale->GetName() );
695
696 setLanguageId( wxLANGUAGE_DEFAULT );
697 delete m_locale;
698
699 m_locale = new wxLocale;
700 m_locale->Init();
701
702 aErrMsg = _( "The KiCad language file for this language is not installed." );
703 return false;
704 }
705
706 return true;
707}
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:308
const wxChar *const traceLocale
Flag to enable locale debug output.

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

492{
493 m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
494
495#ifdef __WXMAC__
496 // On OSX Pgm().GetExecutablePath() will always point to main
497 // bundle directory, e.g., /Applications/kicad.app/
498
499 wxFileName fn( m_bin_dir );
500
501 if( fn.GetName() == wxT( "kicad" ) )
502 {
503 // kicad launcher, so just remove the Contents/MacOS part
504 fn.RemoveLastDir();
505 fn.RemoveLastDir();
506 }
507 else
508 {
509 // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
510 fn.RemoveLastDir();
511 fn.RemoveLastDir();
512 fn.RemoveLastDir();
513 fn.RemoveLastDir();
514 fn.RemoveLastDir();
515 }
516
517 m_bin_dir = fn.GetPath() + wxT( "/" );
518#else
519 // Use unix notation for paths. I am not sure this is a good idea,
520 // but it simplifies compatibility between Windows and Unices.
521 // However it is a potential problem in path handling under Windows.
523
524 // Remove file name form command line:
525 while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
526 m_bin_dir.RemoveLast();
527#endif
528
529 return true;
530}

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

576{
577 if( first_time )
578 {
579 setLanguageId( wxLANGUAGE_DEFAULT );
580 // First time SetLanguage is called, the user selected language id is set
581 // from common user config settings
582 wxString languageSel = GetCommonSettings()->m_System.language;
583
584 // Search for the current selection
585 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
586 {
587 if( LanguagesList[ii].m_Lang_Label == languageSel )
588 {
589 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
590 break;
591 }
592 }
593 }
594
595 // dictionary file name without extend (full name is kicad.mo)
596 wxString dictionaryName( wxT( "kicad" ) );
597
598 delete m_locale;
599 m_locale = new wxLocale;
600
601 // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
602 // false just because it failed to load wxstd catalog
603 if( !m_locale->Init( m_language_id, wxLOCALE_DONT_LOAD_DEFAULT ) )
604 {
605 wxLogTrace( traceLocale, wxT( "This language is not supported by the system." ) );
606
607 setLanguageId( wxLANGUAGE_DEFAULT );
608 delete m_locale;
609
610 m_locale = new wxLocale;
611 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
612
613 aErrMsg = _( "This language is not supported by the operating system." );
614 return false;
615 }
616 else if( !first_time )
617 {
618 wxLogTrace( traceLocale, wxT( "Search for dictionary %s.mo in %s" ) ,
619 dictionaryName, m_locale->GetName() );
620 }
621
622 if( !first_time )
623 {
624 // If we are here, the user has selected another language.
625 // Therefore the new preferred language name is stored in common config.
626 // Do NOT store the wxWidgets language Id, it can change between wxWidgets
627 // versions, for a given language
628 wxString languageSel;
629
630 // Search for the current selection language name
631 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
632 {
633 if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
634 {
635 languageSel = LanguagesList[ii].m_Lang_Label;
636 break;
637 }
638 }
639
641 cfg->m_System.language = languageSel;
642 cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
643 }
644
645 // Try adding the dictionary if it is not currently loaded
646 if( !m_locale->IsLoaded( dictionaryName ) )
647 m_locale->AddCatalog( dictionaryName );
648
649 // Verify the Kicad dictionary was loaded properly
650 // However, for the English language, the dictionary is not mandatory, as
651 // all messages are already in English, just restricted to ASCII7 chars,
652 // the verification is skipped.
653 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
654 {
655 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
656 dictionaryName, m_locale->GetName() );
657
658 setLanguageId( wxLANGUAGE_DEFAULT );
659 delete m_locale;
660
661 m_locale = new wxLocale;
662 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
663
664 aErrMsg = _( "The KiCad language file for this language is not installed." );
665 return false;
666 }
667
668 return true;
669}
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:83
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:65
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:68

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

308{ m_language_id = aId; }

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

711{
712 wxLogTrace( traceLocale, wxT( "Select language ID %d from %d possible languages." ),
713 menu_id, (int)arrayDim( LanguagesList )-1 );
714
715 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
716 {
717 if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
718 {
719 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
720 break;
721 }
722 }
723}
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31

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

◆ SetLanguagePath()

void PGM_BASE::SetLanguagePath ( )
virtualinherited

Definition at line 726 of file pgm_base.cpp.

727{
728 wxLocale::AddCatalogLookupPathPrefix( PATHS::GetLocaleDataPath() );
729
730 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
731 {
732 wxFileName fn( Pgm().GetExecutablePath() );
733 fn.RemoveLastDir();
734 fn.AppendDir( wxT( "translation" ) );
735 wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
736 }
737}
static wxString GetLocaleDataPath()
Gets the locales translation data path.
Definition: paths.cpp:252
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:160
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

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

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

741{
742 wxString env;
743
744 if( aName.IsEmpty() )
745 {
746 wxLogTrace( traceEnvVars,
747 wxT( "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s" ),
748 aValue );
749 return false;
750 }
751
752 // Check to see if the environment variable is already set.
753 if( wxGetEnv( aName, &env ) )
754 {
755 wxLogTrace( traceEnvVars,
756 wxT( "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s" ),
757 aName, env );
758 return env == aValue;
759 }
760
761 wxLogTrace( traceEnvVars,
762 wxT( "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
763 aName, aValue );
764
765 return wxSetEnv( aName, aValue );
766}

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

770{
771 // Overwrites externally defined environment variable until the next time the application
772 // is run.
773 for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
774 {
775 wxLogTrace( traceEnvVars,
776 wxT( "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s" ),
777 m_local_env_var.first,
778 m_local_env_var.second.GetValue() );
779 wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
780 }
781}

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; }

References PGM_BASE::m_pdf_browser.

Referenced by PGM_BASE::ReadPdfBrowserInfos().

◆ SetTextEditor()

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

◆ 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 }

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 328 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 329 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 331 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 299 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 297 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 326 of file pgm_base.h.

Referenced by PGM_BASE::InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting
inherited

Definition at line 301 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 337 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: