33#include <wx/html/htmlwin.h>
36#include <wx/filename.h>
38#include <wx/propgrid/propgrid.h>
39#include <wx/snglinst.h>
40#include <wx/stdpaths.h>
42#include <wx/filedlg.h>
44#include <wx/tooltip.h>
62#include <python_scripting.h>
75#include <python_manager.h>
79#include <winrt/base.h>
106 wxT(
"Español (Latinoamericano)" ),
true },
121 wxT(
"Português (Brasil)" ),
true },
134 wxT(
"简体中文" ),
true },
136 wxT(
"繁體中文" ),
true },
140#define _(s) wxGetTranslation((s))
185 winrt::uninit_apartment();
192 wxASSERT( wxTheApp );
210 if( !wxGetEnv( wxT(
"EDITOR" ), &editorname ) )
214 editorname = wxT(
"/usr/bin/open -e" );
216 editorname = wxT(
"/usr/bin/xdg-open" );
222 if( !editorname && aCanShowFileChooser )
231 if( !editorname.IsEmpty() )
244 wxString mask(
_(
"Executable file" ) + wxT(
" (*.exe)|*.exe" ) );
246 wxString mask(
_(
"Executable file" ) + wxT(
" (*)|*" ) );
252 wxFileName::SplitPath( aDefaultEditor, &
path, &
name, &ext );
256 return wxFileSelector(
_(
"Select Preferred Editor" ),
path,
name, wxT(
"." ) + ext,
257 mask, wxFD_OPEN | wxFD_FILE_MUST_EXIST,
nullptr );
261#ifdef KICAD_USE_SENTRY
262void PGM_BASE::sentryPrompt()
272 wxMessageDialog optIn = wxMessageDialog(
274 _(
"KiCad can anonymously report crashes and special event data to developers in order to "
275 "aid identifying critical bugs and help profile functionality to guide improvements. \n"
276 "If you choose to voluntarily participate, KiCad will automatically send said reports "
277 "when crashes or events occur. \n"
278 "Your design files such as schematic and PCB are not shared in this process." ),
279 _(
"Data Collection Opt In" ), wxYES_NO | wxCENTRE );
281 optIn.SetYesNoLabels(
_(
"Opt In" ),
_(
"Decline" ) );
282 int result = optIn.ShowModal();
293 m_settings_manager->GetCommonSettings()->m_DoNotShowAgain.data_collection_prompt =
true;
301 const wxArrayString& argArray =
App().argv.GetArguments();
307 m_argvUtf8[n] = wxStrdup( argArray[n].ToUTF8() );
326 NULL, -1, wxDefaultPosition, wxDefaultSize,
327 wxBORDER_NONE | wxSTAY_ON_TOP );
346#if defined( __WXMAC__ )
367 if(
App().argc == 0 )
368 pgm_name = wxT(
"kicad" );
370 pgm_name = wxFileName(
App().argv[0] ).GetName().Lower();
374 wxInitAllImageHandlers();
378 wxPGInitResourceModule();
381 if( wxString( wxGetenv(
"HOME" ) ).IsEmpty() )
384 "Unable to continue." ) );
395 wxChmod( instanceCheckerDir,
396 wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE |
397 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE |
398 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE );
400 wxString instanceCheckerName = wxString::Format( wxS(
"%s-%s" ), pgm_name,
404 m_pgm_checker->Create( instanceCheckerName, instanceCheckerDir );
409 bool isDefined = wxGetEnv( wxT(
"KICAD" ), &
m_kicad_env );
420 App().SetVendorName( wxT(
"KiCad" ) );
421 App().SetAppName( pgm_name );
424 if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) ==
nullptr )
425 wxImage::AddHandler(
new wxPNGHandler );
427 if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) ==
nullptr )
428 wxImage::AddHandler(
new wxGIFHandler );
430 if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) ==
nullptr )
431 wxImage::AddHandler(
new wxJPEGHandler );
433 wxFileSystem::AddHandler(
new wxZipFSHandler );
441 if( !wxGetEnv(
"FONTCONFIG_PATH", NULL ) )
447 wxSetEnv(
"FONTCONFIG_PATH", PATHS::GetWindowsFontConfigDir() );
452 winrt::init_apartment(winrt::apartment_type::single_threaded);
460 m_plugin_manager = std::make_unique<API_PLUGIN_MANAGER>( &
App() );
499#ifdef KICAD_USE_SENTRY
518 m_plugin_manager->ReloadPlugins();
525 wxToolTip::Enable(
true );
526 wxToolTip::SetAutoPop( 10000 );
544 for(
const std::pair<wxString, ENV_VAR_ITEM> it :
GetCommonSettings()->m_Env.vars )
546 wxLogTrace(
traceEnvVars, wxT(
"PGM_BASE::loadSettings: Found entry %s = %s" ),
547 it.first, it.second.GetValue() );
555 if( it.first.IsEmpty() )
559 if( it.second.GetDefinedExternally() )
596 for(
unsigned ii = 0;
LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
607 wxString dictionaryName( wxT(
"kicad" ) );
616 wxLogTrace(
traceLocale, wxT(
"This language is not supported by the system." ) );
622 m_locale->Init( wxLANGUAGE_DEFAULT );
624 aErrMsg =
_(
"This language is not supported by the operating system." );
627 else if( !first_time )
629 wxLogTrace(
traceLocale, wxT(
"Search for dictionary %s.mo in %s" ) ,
630 dictionaryName,
m_locale->GetName() );
639 wxString languageSel;
642 for(
unsigned ii = 0;
LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
657 if( !
m_locale->IsLoaded( dictionaryName ) )
658 m_locale->AddCatalog( dictionaryName );
666 wxLogTrace(
traceLocale, wxT(
"Unable to load dictionary %s.mo in %s" ),
667 dictionaryName,
m_locale->GetName() );
673 m_locale->Init( wxLANGUAGE_DEFAULT );
675 aErrMsg =
_(
"The KiCad language file for this language is not installed." );
691 wxString dictionaryName( wxT(
"kicad" ) );
698 if( !
m_locale->IsLoaded( dictionaryName ) )
699 m_locale->AddCatalog( dictionaryName );
707 wxLogTrace(
traceLocale, wxT(
"Unable to load dictionary %s.mo in %s" ),
708 dictionaryName,
m_locale->GetName() );
716 aErrMsg =
_(
"The KiCad language file for this language is not installed." );
726 wxLogTrace(
traceLocale, wxT(
"Select language ID %d from %d possible languages." ),
729 for(
unsigned ii = 0;
LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
742 const wxLanguageInfo* langInfo = wxLocale::GetLanguageInfo(
m_language_id );
750 wxString str = langInfo->GetCanonicalWithRegion();
751 str.Replace(
"_",
"-" );
761 wxLocale::AddCatalogLookupPathPrefix( PATHS::GetWindowsBaseSharePath() + wxT(
"locale" ) );
765 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
769 fn.AppendDir( wxT(
"translation" ) );
770 wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() );
779 if( aName.IsEmpty() )
782 wxT(
"PGM_BASE::SetLocalEnvVariable: Attempt to set empty variable to "
789 if( wxGetEnv( aName, &env ) )
792 wxT(
"PGM_BASE::SetLocalEnvVariable: Environment variable %s already set "
795 return env == aValue;
799 wxT(
"PGM_BASE::SetLocalEnvVariable: Setting local environment variable %s to %s" ),
802 return wxSetEnv( aName, aValue );
810 for(
const std::pair<wxString, ENV_VAR_ITEM> m_local_env_var :
GetCommonSettings()->m_Env.vars )
813 wxT(
"PGM_BASE::SetLocalEnvVariables: Setting local environment variable %s "
815 m_local_env_var.first,
816 m_local_env_var.second.GetValue() );
817 wxSetEnv( m_local_env_var.first, m_local_env_var.second.GetValue() );
833 return wxTheApp->IsGUI();
842 std::rethrow_exception( aPtr );
846 wxLogError( ioe.
What() );
848 catch(
const std::exception& e )
852 wxLogError( wxT(
"Unhandled exception class: %s what: %s" ),
857 wxLogError( wxT(
"Unhandled exception of unknown type" ) );
863 const wxString& aCond,
const wxString& aMsg )
870 assertStr = wxString::Format(
"Assertion failed at %s:%d in %s: %s - %s", aFile, aLine,
871 aFunc, aCond, aMsg );
875 assertStr = wxString::Format(
"Assertion failed at %s:%d in %s: %s", aFile, aLine, aFunc,
880 wxLogError( assertStr );
883#ifdef KICAD_USE_SENTRY
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void LogAssert(const ASSERT_CACHE_KEY &aKey, const wxString &aMsg)
void SetSentryOptIn(bool aOptIn)
void LogException(const wxString &aMsg)
void AddTag(const wxString &aKey, const wxString &aValue)
static SENTRY * Instance()
void InitializeEnvironment()
Creates the built-in environment variables and sets their default values.
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
static void Cleanup()
Call curl_global_cleanup for the application.
static void Init()
Call curl_global_init for the application.
void Load()
Load notifications stored from disk.
static wxString GetInstanceCheckerPath()
Gets the path used for wxSingleInstanceChecker lock files.
static void EnsureUserPathsExist()
Ensures/creates user default paths.
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
static wxString GetLocaleDataPath()
Gets the locales translation data path.
static const wxString & GetExecutablePath()
Container for data for KiCad programs.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
std::unique_ptr< NOTIFICATIONS_MANAGER > m_notifications_manager
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
bool m_Printing
wxWidgets on MSW tends to crash if you spool up more than one print job at a time.
void setLanguageId(int aId)
Trap all changes in here, simplifies debugging.
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
void loadCommonSettings()
Load internal settings from COMMON_SETTINGS.
virtual void SetPdfBrowserName(const wxString &aFileName)
wxSplashScreen * m_splash
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
char ** m_argvUtf8
argv parameters converted to utf8 form because wxWidgets has opinions.
virtual void ReadPdfBrowserInfos()
Read the PDF browser choice from the common configuration.
bool IsGUI()
Determine if the application is running with a GUI.
bool m_use_system_pdf_browser
virtual NOTIFICATIONS_MANAGER & GetNotificationsManager() const
void BuildArgvUtf8()
Builds the UTF8 based argv variable.
virtual const wxString & GetPdfBrowserName() const
virtual void SetTextEditor(const wxString &aFileName)
std::unique_ptr< wxSingleInstanceChecker > m_pgm_checker
Check if there is another copy of Kicad running at the same time.
virtual bool SetLocalEnvVariable(const wxString &aName, const wxString &aValue)
Set the environment variable aName to aValue.
wxString m_kicad_env
The KICAD system environment variable.
virtual void ForceSystemPdfBrowser(bool aFlg)
Force the use of system PDF browser, even if a preferred PDF browser is set.
virtual void SetLocalEnvVariables()
Update the local environment with the contents of the current ENV_VAR_MAP stored in the COMMON_SETTIN...
virtual void SetLanguagePath()
bool SetDefaultLanguage(wxString &aErrMsg)
Set the default language without reference to any preferences.
std::unique_ptr< SCRIPTING > m_python_scripting
virtual void SetLanguageIdentifier(int menu_id)
Set in .m_language_id member the wxWidgets language identifier ID from the KiCad menu id (internal me...
std::unique_ptr< BACKGROUND_JOBS_MONITOR > m_background_jobs_monitor
void HandleException(std::exception_ptr aPtr)
A exception handler to be used at the top level if exceptions bubble up that for.
void HandleAssert(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
A common assert handler to be used between single_top and kicad.
virtual wxString GetLanguageTag()
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
virtual const wxString & GetExecutablePath() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
virtual void WritePdfBrowserInfos()
Save the PDF browser choice to the common configuration.
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
bool m_PropertyGridInitialized
KICAD_SINGLETON m_singleton
virtual const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Show a dialog that instructs the user to select a new preferred editor.
virtual bool SetLanguage(wxString &aErrMsg, bool first_time=false)
Set the dictionary file name for internationalization.
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load 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.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define WIN_STRING_DIR_SEP
#define UNIX_STRING_DIR_SEP
const wxChar *const traceLocale
Flag to enable locale debug output.
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
@ ID_LANGUAGE_NORWEGIAN_BOKMAL
@ ID_LANGUAGE_CHINESE_SIMPLIFIED
@ ID_LANGUAGE_PORTUGUESE_BRAZILIAN
@ ID_LANGUAGE_SPANISH_MEXICAN
@ ID_LANGUAGE_CHINESE_TRADITIONAL
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
This file contains miscellaneous commonly used macros and functions.
void SetPgm(PGM_BASE *pgm)
static PGM_BASE * process
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
#define _(s)
Current list of languages supported by KiCad.
KICOMMON_API LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
KICOMMON_API PGM_BASE & Pgm()
The global program "get" accessor.
#define POLICY_KEY_DATACOLLECTION
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
wxString From_UTF8(const char *cstring)
This struct represents a key being used for the std::set that deduplicates asserts during this runnin...
wxString python_interpreter
bool data_collection_prompt
bool use_system_pdf_viewer
A small class to handle the list of existing translations.
System directories search utilities.
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.