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...
 
void BuildArgvUtf8 ()
 Builds the UTF8 based argv variable. 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, bool aIsUnitTest=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...
 
std::vector< void * > m_ModalDialogs
 
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...
 
char ** m_argvUtf8
 
int m_argcUtf8
 argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either force converted to ascii in char* or wchar_t only 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 163 of file pgm_base.cpp.

164{
165 wxASSERT( wxTheApp );
166 return *wxTheApp;
167}

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

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

References _, name, and path.

Referenced by PGM_BASE::GetTextEditor().

◆ BuildArgvUtf8()

void PGM_BASE::BuildArgvUtf8 ( )
inherited

Builds the UTF8 based argv variable.

Definition at line 386 of file pgm_base.cpp.

387{
388 const wxArrayString& argArray = App().argv.GetArguments();
389 m_argcUtf8 = argArray.size();
390
391 m_argvUtf8 = new char*[m_argcUtf8 + 1];
392 for( int n = 0; n < m_argcUtf8; n++ )
393 {
394 m_argvUtf8[n] = wxStrdup( argArray[n].ToUTF8() );
395 }
396
397 m_argvUtf8[m_argcUtf8] = NULL; // null terminator at end of argv
398}
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
Definition: pgm_base.cpp:163
int m_argcUtf8
argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either...
Definition: pgm_base.h:355
char ** m_argvUtf8
Definition: pgm_base.h:352

References PGM_BASE::App(), PGM_BASE::m_argcUtf8, and PGM_BASE::m_argvUtf8.

◆ Destroy()

void PGM_BASE::Destroy ( )
inherited

Definition at line 151 of file pgm_base.cpp.

152{
153#ifdef KICAD_USE_SENTRY
154 sentry_close();
155#endif
156
157 // unlike a normal destructor, this is designed to be called more than once safely:
158 delete m_locale;
159 m_locale = nullptr;
160}
wxLocale * m_locale
The KICAD system environment variable.
Definition: pgm_base.h:338

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

187{ m_use_system_pdf_browser = aFlg; }
bool m_use_system_pdf_browser
Definition: pgm_base.h:341

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

166{ return m_bin_dir; }
wxString m_bin_dir
Definition: pgm_base.h:335

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

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

References PGM_BASE::m_kicad_env.

◆ GetLocale()

virtual wxLocale * PGM_BASE::GetLocale ( )
inlinevirtualinherited

Definition at line 168 of file pgm_base.h.

168{ return m_locale; }

References PGM_BASE::m_locale.

◆ GetLocalEnvVariables()

ENV_VAR_MAP & PGM_BASE::GetLocalEnvVariables ( ) const
virtualinherited

Definition at line 839 of file pgm_base.cpp.

840{
841 return GetCommonSettings()->m_Env.vars;
842}
ENVIRONMENT m_Env
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:618

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

170{ return m_pdf_browser; }
wxString m_pdf_browser
Definition: pgm_base.h:342

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

221{ return m_language_id; }
int m_language_id
Definition: pgm_base.h:339

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

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

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,
bool  aIsUnitTest = 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 401 of file pgm_base.cpp.

402{
403#if defined( __WXMAC__ )
404 // Set the application locale to the system default
405 wxLogNull noLog;
406 wxLocale loc;
407 loc.Init();
408#endif
409
410 // Just make sure we init precreate any folders early for later code
411 // In particular, the user cache path is the most likely to be hit by startup code
413
414#ifdef KICAD_USE_SENTRY
415 sentryInit();
416#endif
417 wxString pgm_name;
418
420 if( App().argc == 0 )
421 pgm_name = wxT( "kicad" );
422 else
423 pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
424
425#ifdef KICAD_USE_SENTRY
426 sentry_set_tag( "kicad.app", pgm_name.c_str() );
427#endif
428
429 wxInitAllImageHandlers();
430
431 // Without this the wxPropertyGridManager segfaults on Windows.
432 if( !wxPGGlobalVars )
433 wxPGInitResourceModule();
434
435#ifndef __WINDOWS__
436 if( wxString( wxGetenv( "HOME" ) ).IsEmpty() )
437 {
438 DisplayErrorMessage( nullptr, _( "Environment variable HOME is empty. "
439 "Unable to continue." ) );
440 return false;
441 }
442#endif
443
444 // Init KiCad environment
445 // the environment variable KICAD (if exists) gives the kicad path:
446 // something like set KICAD=d:\kicad
447 bool isDefined = wxGetEnv( wxT( "KICAD" ), &m_kicad_env );
448
449 if( isDefined ) // ensure m_kicad_env ends by "/"
450 {
452
453 if( !m_kicad_env.IsEmpty() && m_kicad_env.Last() != '/' )
455 }
456
457 // Init parameters for configuration
458 App().SetVendorName( wxT( "KiCad" ) );
459 App().SetAppName( pgm_name );
460
461 // Install some image handlers, mainly for help
462 if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr )
463 wxImage::AddHandler( new wxPNGHandler );
464
465 if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr )
466 wxImage::AddHandler( new wxGIFHandler );
467
468 if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr )
469 wxImage::AddHandler( new wxJPEGHandler );
470
471 wxFileSystem::AddHandler( new wxZipFSHandler );
472
473 // Analyze the command line & initialize the binary path
474 wxString tmp;
477 SetDefaultLanguage( tmp );
478
479 m_settings_manager = std::make_unique<SETTINGS_MANAGER>( aHeadless );
480
481 // Our unit test mocks break if we continue
482 // A bug caused InitPgm to terminate early in unit tests and the mocks are...simplistic
483 // TODO fix the unit tests so this can be removed
484 if( aIsUnitTest )
485 return false;
486
487 // Something got in the way of settings load: can't continue
488 if( !m_settings_manager->IsOK() )
489 return false;
490
491 // Set up built-in environment variables (and override them from the system environment if set)
493
494 // Load color settings after env is initialized
495 m_settings_manager->ReloadColorSettings();
496
497 // Load common settings from disk after setting up env vars
499
500 // Init user language *before* calling loadSettings, because
501 // env vars could be incorrectly initialized on Linux
502 // (if the value contains some non ASCII7 chars, the env var is not initialized)
503 SetLanguage( tmp, true );
504
505 // Now that translations are available, inform the user if the OS is unsupported
507
509
510#ifdef KICAD_USE_SENTRY
511 sentryPrompt();
512#endif
513
514 ReadPdfBrowserInfos(); // needs GetCommonSettings()
515
516 // Create the python scripting stuff
517 // Skip it fot applications that do not use it
518 if( !aSkipPyInit )
519 m_python_scripting = std::make_unique<SCRIPTING>();
520
521 // TODO(JE): Remove this if apps are refactored to not assume Prj() always works
522 // Need to create a project early for now (it can have an empty path for the moment)
524
525 // This sets the maximum tooltip display duration to 10s (up from 5) but only affects
526 // Windows as other platforms display tooltips while the mouse is not moving
527 if( !aHeadless )
528 {
529 wxToolTip::Enable( true );
530 wxToolTip::SetAutoPop( 10000 );
531 }
532
533 if( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval != 0 )
534 wxUpdateUIEvent::SetUpdateInterval( ADVANCED_CFG::GetCfg().m_UpdateUIEventInterval );
535
536 return true;
537}
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:369
bool setExecutablePath()
Find the path to the executable and stores it in PGM_BASE::m_bin_dir.
Definition: pgm_base.cpp:540
void loadCommonSettings()
Loads internal settings from COMMON_SETTINGS.
Definition: pgm_base.cpp:582
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
Definition: eda_doc.cpp:37
virtual void SetLanguagePath()
Definition: pgm_base.cpp:781
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
Definition: pgm_base.cpp:724
std::unique_ptr< SCRIPTING > m_python_scripting
Definition: pgm_base.h:333
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:135
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
Definition: pgm_base.cpp:624
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:635
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
#define WIN_STRING_DIR_SEP
Definition: gestfich.h:36
#define UNIX_STRING_DIR_SEP
Definition: gestfich.h:35
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars

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(), WIN_STRING_DIR_SEP, and wxPGGlobalVars.

Referenced by PGM_KICAD::OnPgmInit().

◆ IsKicadEnvVariableDefined()

virtual bool PGM_BASE::IsKicadEnvVariableDefined ( ) const
inlinevirtualinherited

Definition at line 162 of file pgm_base.h.

162{ 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 582 of file pgm_base.cpp.

583{
585
586 for( const std::pair<wxString, ENV_VAR_ITEM> it : GetCommonSettings()->m_Env.vars )
587 {
588 wxLogTrace( traceEnvVars, wxT( "PGM_BASE::loadSettings: Found entry %s = %s" ),
589 it.first, it.second.GetValue() );
590
591 // Do not store the env var PROJECT_VAR_NAME ("KIPRJMOD") definition if for some reason
592 // it is found in config. (It is reserved and defined as project path)
593 if( it.first == PROJECT_VAR_NAME )
594 continue;
595
596 // Don't set bogus empty entries in the environment
597 if( it.first.IsEmpty() )
598 continue;
599
600 // Do not overwrite vars set by the system environment with values from the settings file
601 if( it.second.GetDefinedExternally() )
602 continue;
603
604 SetLocalEnvVariable( it.first, it.second.GetValue() );
605 }
606}
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Sets the environment variable aName to aValue.
Definition: pgm_base.cpp:795
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:39

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:683
void Destroy()
Definition: pgm_base.cpp:151
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:172

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

610{
611 // GetCommonSettings() is not initialized until fairly late in the
612 // process startup: InitPgm(), so test before using:
613 if( GetCommonSettings() )
614 GetCommonSettings()->m_System.working_dir = wxGetCwd();
615}

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

725{
726 // Suppress error popups from wxLocale
727 wxLogNull doNotLog;
728
729 setLanguageId( wxLANGUAGE_DEFAULT );
730
731 // dictionary file name without extend (full name is kicad.mo)
732 wxString dictionaryName( wxT( "kicad" ) );
733
734 delete m_locale;
735 m_locale = new wxLocale;
736 m_locale->Init();
737
738 // Try adding the dictionary if it is not currently loaded
739 if( !m_locale->IsLoaded( dictionaryName ) )
740 m_locale->AddCatalog( dictionaryName );
741
742 // Verify the Kicad dictionary was loaded properly
743 // However, for the English language, the dictionary is not mandatory, as
744 // all messages are already in English, just restricted to ASCII7 chars,
745 // the verification is skipped.
746 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
747 {
748 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
749 dictionaryName, m_locale->GetName() );
750
751 setLanguageId( wxLANGUAGE_DEFAULT );
752 delete m_locale;
753
754 m_locale = new wxLocale;
755 m_locale->Init();
756
757 aErrMsg = _( "The KiCad language file for this language is not installed." );
758 return false;
759 }
760
761 return true;
762}
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
Definition: pgm_base.h:315
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 540 of file pgm_base.cpp.

541{
542 m_bin_dir = wxStandardPaths::Get().GetExecutablePath();
543
544#ifdef __WXMAC__
545 // On OSX Pgm().GetExecutablePath() will always point to main
546 // bundle directory, e.g., /Applications/kicad.app/
547
548 wxFileName fn( m_bin_dir );
549
550 if( fn.GetName() == wxT( "kicad" ) || fn.GetName() == wxT( "kicad-cli" ) )
551 {
552 // kicad launcher, so just remove the Contents/MacOS part
553 fn.RemoveLastDir();
554 fn.RemoveLastDir();
555 }
556 else
557 {
558 // standalone binaries live in Contents/Applications/<standalone>.app/Contents/MacOS
559 fn.RemoveLastDir();
560 fn.RemoveLastDir();
561 fn.RemoveLastDir();
562 fn.RemoveLastDir();
563 fn.RemoveLastDir();
564 }
565
566 m_bin_dir = fn.GetPath() + wxT( "/" );
567#else
568 // Use unix notation for paths. I am not sure this is a good idea,
569 // but it simplifies compatibility between Windows and Unices.
570 // However it is a potential problem in path handling under Windows.
572
573 // Remove file name form command line:
574 while( m_bin_dir.Last() != '/' && !m_bin_dir.IsEmpty() )
575 m_bin_dir.RemoveLast();
576#endif
577
578 return true;
579}

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

625{
626 // Suppress wxWidgets error popups if locale is not found
627 wxLogNull doNotLog;
628
629 if( first_time )
630 {
631 setLanguageId( wxLANGUAGE_DEFAULT );
632 // First time SetLanguage is called, the user selected language id is set
633 // from common user config settings
634 wxString languageSel = GetCommonSettings()->m_System.language;
635
636 // Search for the current selection
637 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
638 {
639 if( LanguagesList[ii].m_Lang_Label == languageSel )
640 {
641 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
642 break;
643 }
644 }
645 }
646
647 // dictionary file name without extend (full name is kicad.mo)
648 wxString dictionaryName( wxT( "kicad" ) );
649
650 delete m_locale;
651 m_locale = new wxLocale;
652
653 // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return
654 // false just because it failed to load wxstd catalog
655 if( !m_locale->Init( m_language_id, wxLOCALE_DONT_LOAD_DEFAULT ) )
656 {
657 wxLogTrace( traceLocale, wxT( "This language is not supported by the system." ) );
658
659 setLanguageId( wxLANGUAGE_DEFAULT );
660 delete m_locale;
661
662 m_locale = new wxLocale;
663 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
664
665 aErrMsg = _( "This language is not supported by the operating system." );
666 return false;
667 }
668 else if( !first_time )
669 {
670 wxLogTrace( traceLocale, wxT( "Search for dictionary %s.mo in %s" ) ,
671 dictionaryName, m_locale->GetName() );
672 }
673
674 if( !first_time )
675 {
676 // If we are here, the user has selected another language.
677 // Therefore the new preferred language name is stored in common config.
678 // Do NOT store the wxWidgets language Id, it can change between wxWidgets
679 // versions, for a given language
680 wxString languageSel;
681
682 // Search for the current selection language name
683 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
684 {
685 if( LanguagesList[ii].m_WX_Lang_Identifier == m_language_id )
686 {
687 languageSel = LanguagesList[ii].m_Lang_Label;
688 break;
689 }
690 }
691
693 cfg->m_System.language = languageSel;
694 cfg->SaveToFile( GetSettingsManager().GetPathForSettingsFile( cfg ) );
695 }
696
697 // Try adding the dictionary if it is not currently loaded
698 if( !m_locale->IsLoaded( dictionaryName ) )
699 m_locale->AddCatalog( dictionaryName );
700
701 // Verify the Kicad dictionary was loaded properly
702 // However, for the English language, the dictionary is not mandatory, as
703 // all messages are already in English, just restricted to ASCII7 chars,
704 // the verification is skipped.
705 if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
706 {
707 wxLogTrace( traceLocale, wxT( "Unable to load dictionary %s.mo in %s" ),
708 dictionaryName, m_locale->GetName() );
709
710 setLanguageId( wxLANGUAGE_DEFAULT );
711 delete m_locale;
712
713 m_locale = new wxLocale;
714 m_locale->Init( wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT);
715
716 aErrMsg = _( "The KiCad language file for this language is not installed." );
717 return false;
718 }
719
720 return true;
721}
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:85
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:66
wxString m_Lang_Label
Labels used in menus.
Definition: pgm_base.h:69

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

315{ 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 765 of file pgm_base.cpp.

766{
767 wxLogTrace( traceLocale, wxT( "Select language ID %d from %d possible languages." ),
768 menu_id, (int)arrayDim( LanguagesList )-1 );
769
770 for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
771 {
772 if( menu_id == LanguagesList[ii].m_KI_Lang_Identifier )
773 {
774 setLanguageId( LanguagesList[ii].m_WX_Lang_Identifier );
775 break;
776 }
777 }
778}
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 781 of file pgm_base.cpp.

782{
783 wxLocale::AddCatalogLookupPathPrefix( PATHS::GetLocaleDataPath() );
784
785 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
786 {
787 wxFileName fn( Pgm().GetExecutablePath() );
788 fn.RemoveLastDir();
789 fn.AppendDir( wxT( "translation" ) );
790 wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
791 }
792}
static wxString GetLocaleDataPath()
Gets the locales translation data path.
Definition: paths.cpp:252
virtual const wxString & GetExecutablePath() const
Definition: pgm_base.h:166
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 795 of file pgm_base.cpp.

796{
797 wxString env;
798
799 if( aName.IsEmpty() )
800 {
801 wxLogTrace( traceEnvVars,
802 wxT( "PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to value %s" ),
803 aValue );
804 return false;
805 }
806
807 // Check to see if the environment variable is already set.
808 if( wxGetEnv( aName, &env ) )
809 {
810 wxLogTrace( traceEnvVars,
811 wxT( "PGM_BASE::SetLocalEnvVariable: Environment variable %s already set to %s" ),
812 aName, env );
813 return env == aValue;
814 }
815
816 wxLogTrace( traceEnvVars,
817 wxT( "PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
818 aName, aValue );
819
820 return wxSetEnv( aName, aValue );
821}

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

825{
826 // Overwrites externally defined environment variable until the next time the application
827 // is run.
828 for( const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var : GetCommonSettings()->m_Env.vars )
829 {
830 wxLogTrace( traceEnvVars,
831 wxT( "PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s to %s" ),
832 m_local_env_var.first,
833 m_local_env_var.second.GetValue() );
834 wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
835 }
836}

References PGM_BASE::GetCommonSettings(), and traceEnvVars.

◆ SetPdfBrowserName()

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

Definition at line 172 of file pgm_base.h.

172{ 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 179 of file pgm_base.h.

180 {
181 return m_use_system_pdf_browser || m_pdf_browser.IsEmpty();
182 }

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

◆ WritePdfBrowserInfos()

void PGM_BASE::WritePdfBrowserInfos ( )
virtualinherited

Member Data Documentation

◆ m_argcUtf8

int PGM_BASE::m_argcUtf8
protectedinherited

argv parameters converted to utf8 form, because wxwidgets has opinions and will return argv as either force converted to ascii in char* or wchar_t only

Definition at line 355 of file pgm_base.h.

Referenced by PGM_BASE::BuildArgvUtf8(), PGM_BASE::PGM_BASE(), and PGM_BASE::~PGM_BASE().

◆ m_argvUtf8

char** PGM_BASE::m_argvUtf8
protectedinherited

Definition at line 352 of file pgm_base.h.

Referenced by PGM_BASE::BuildArgvUtf8(), PGM_BASE::PGM_BASE(), and PGM_BASE::~PGM_BASE().

◆ m_bin_dir

wxString PGM_BASE::m_bin_dir
protectedinherited

Definition at line 335 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 336 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 338 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_ModalDialogs

std::vector<void*> PGM_BASE::m_ModalDialogs
inherited

Definition at line 306 of file pgm_base.h.

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

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

Referenced by PGM_BASE::InitPgm().

◆ m_Quitting

bool PGM_BASE::m_Quitting
inherited

Definition at line 308 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 344 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 265 of file pgm_base.h.


The documentation for this struct was generated from the following file: