38#include <wx/cmdline.h>
40#include <wx/filename.h>
41#include <wx/stdpaths.h>
42#include <wx/snglinst.h>
43#include <wx/html/htmlwin.h>
67#ifdef KICAD_USE_SENTRY
110 git_libgit2_shutdown();
115 wxFileName filename( aFileName );
117 if( filename.FileExists() )
129 blocking_win->Close(
true );
148 virtual bool OnInit()
override { AddDependency( CLASSINFO( wxHtmlWinParser ) );
return true; };
160void CustomAssertHandler(
const wxString& file,
162 const wxString& func,
163 const wxString& cond,
164 const wxString& msg )
190 wxSizerFlags::DisableConsistencyChecks();
191 wxDISABLE_DEBUG_SUPPORT();
192 wxSetAssertHandler( CustomAssertHandler );
203 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
205 wxLog::EnableLogging(
true );
206 wxLog::SetLogLevel( wxLOG_Trace );
232 return wxApp::OnExit();
241 ret = wxApp::OnRun();
253 if( aEvent.GetEventType() == wxEVT_SHOW )
255 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
256 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
262 if( event.IsShown() && dialog->IsModal() )
264 dlgs.push_back( dialog );
267 else if( !event.IsShown() && !dlgs.empty() )
270 if( dlgs.back() == dialog )
273 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ); it != dlgs.end() )
274 dlgs.erase( it, dlgs.end() );
295 virtual bool OnExceptionInMainLoop()
override
319 void MacOpenFile(
const wxString& aFileName )
override
333 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
335 if( !wxIsAbsolutePath( absoluteArgv0 ) )
337 wxLogError( wxT(
"No meaningful argv[0]" ) );
343 int gitInit = git_libgit2_init();
347 const git_error* err = git_error_last();
348 wxString msg = wxS(
"Failed to initialize git library" );
350 if( err && err->message )
351 msg += wxS(
": " ) + wxString::FromUTF8( err->message );
359 bool skip_python_initialization =
false;
361#if defined( BITMAP_2_CMP ) || defined( PL_EDITOR ) || defined( GERBVIEW ) || \
362 defined( PCB_CALCULATOR_BUILD )
363 skip_python_initialization =
true;
366 if( !
InitPgm(
false, skip_python_initialization ) )
373#if !defined(BUILD_KIWAY_DLL)
399 m_api_server = std::make_unique<KICAD_API_SERVER>();
407 if( frame ==
nullptr )
414 Kiway.SetTop( frame );
424 topFrame->PreloadLibraries( &
Kiway );
428 App().SetTopWindow( frame );
444 std::vector<wxString> fileArgs;
447 static const wxCmdLineEntryDesc desc[] = {
448 { wxCMD_LINE_PARAM,
nullptr,
nullptr,
"File to load", wxCMD_LINE_VAL_STRING,
449 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
450 { wxCMD_LINE_NONE,
nullptr,
nullptr,
nullptr, wxCMD_LINE_VAL_NONE, 0 }
453 wxCmdLineParser parser(
App().argc,
App().argv );
454 parser.SetDesc( desc );
455 parser.Parse(
false );
457 if( parser.GetParamCount() )
468 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
469 fileArgs.push_back( parser.GetParam( i ) );
472 if( fileArgs.size() == 1 )
474 wxFileName argv1( fileArgs[0] );
476#if defined(PGM_DATA_FILE_EXT)
481 if( !argv1.GetExt() )
482 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
484 argv1.MakeAbsolute();
486 fileArgs[0] = argv1.GetFullPath();
493 m_api_server->SetReadyToReply();
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
const wxString & GetAboutTitle() const
virtual bool OnInit() override
virtual void OnExit() override
wxDECLARE_DYNAMIC_CLASS(HtmlModule)
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
static FACE_T KifaceType(FRAME_T aFrameType)
A simple mapping function which returns the FACE_T which is known to implement aFrameType.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
static const wxString & GetExecutablePath()
virtual wxApp & App()
Return a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
void PreloadDesignBlockLibraries(KIWAY *aKiway)
Starts a background job to preload the global and project design block libraries.
virtual void MacOpenFile(const wxString &aFileName)=0
Specific to MacOSX (not used under Linux or Windows).
std::unique_ptr< SETTINGS_MANAGER > m_settings_manager
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
void HandleException(std::exception_ptr aPtr, bool aUnhandled=false)
A exception handler to be used at the top level if exceptions bubble up that for.
std::vector< void * > m_ModalDialogs
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 LIBRARY_MANAGER & GetLibraryManager() const
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
void CheckAndRun(wxWindow *parent)
This file is part of the common library.
KIFACE * KIFACE_GETTER_FUNC(int *aKIFACEversion, int aKIWAYversion, PGM_BASE *aProgram)
Point to the one and only KIFACE export.
#define KIFACE_VERSION
The KIWAY and KIFACE classes are used to communicate between various process modules,...
#define KFCTL_STANDALONE
Running as a standalone Top.
This file contains miscellaneous commonly used macros and functions.
SETTINGS_MANAGER * GetSettingsManager()
void SetPgm(PGM_BASE *pgm)
PGM_BASE & Pgm()
The global program "get" accessor.
wxIMPLEMENT_DYNAMIC_CLASS(HtmlModule, wxModule)
KIWAY Kiway(KFCTL_STANDALONE)
Implement a bare naked wxApp (so that we don't become dependent on functionality in a wxApp derivativ...
void OnUnhandledException() override
int FilterEvent(wxEvent &aEvent) override
Implement a participant in the KIWAY alchemy.
Implement PGM_BASE with its own OnPgmInit() and OnPgmExit().
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.