31#include <wx/filename.h>
34#include <wx/stdpaths.h>
36#include <wx/cmdline.h>
72 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
74 throw std::logic_error(
"Unexpected call to Kiface() in kicad/kicad.cpp" );
88 App().SetAppDisplayName( wxT(
"KiCad" ) );
91 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
93 if( !wxIsAbsolutePath( absoluteArgv0 ) )
95 wxLogError( wxT(
"No meaningful argv[0]" ) );
103 static const wxCmdLineEntryDesc desc[] = {
104 { wxCMD_LINE_OPTION,
"f",
"frame",
"Frame to load", wxCMD_LINE_VAL_STRING, 0 },
105 { wxCMD_LINE_PARAM,
nullptr,
nullptr,
"File to load", wxCMD_LINE_VAL_STRING,
106 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
107 { wxCMD_LINE_NONE,
nullptr,
nullptr,
nullptr, wxCMD_LINE_VAL_NONE, 0 }
110 wxCmdLineParser parser(
App().argc,
App().argv );
111 parser.SetDesc( desc );
112 parser.Parse(
false );
131 if( parser.Found(
"frame", &frameName ) )
135 for(
const auto& it : frameTypes )
137 if( it.name == frameName )
143 wxLogError( wxT(
"Unknown frame: %s" ), frameName );
159 bool skipPythonInit =
false;
163 skipPythonInit =
true;
165 if( !
InitPgm(
false, skipPythonInit ) )
180 for(
unsigned i = 0; i < bases.GetCount(); ++i )
182 wxFileName fn( bases[i], wxEmptyString );
185 fn.AppendDir( wxT(
"template" ) );
188 if( fn.DirExists() && fn.IsDirReadable() )
194 wxT(
"TEMPLATE_DIR" ) ) )
211 wxFrame* frame =
nullptr;
218 wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
219 frame = managerFrame;
229 if( frame ==
nullptr )
235 App().SetTopWindow( frame );
245 m_api_server = std::make_unique<KICAD_API_SERVER>();
246 m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
247 m_api_server->RegisterHandler( m_api_common_handler.get() );
254 if( playerFrame && parser.GetParamCount() )
257 std::vector<wxString> fileArgs;
267 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
268 fileArgs.push_back( parser.GetParam( i ) );
271 if( fileArgs.size() == 1 )
273 wxFileName argv1( fileArgs[0] );
275#if defined( PGM_DATA_FILE_EXT )
280 if( !argv1.GetExt() )
281 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
283 argv1.MakeAbsolute();
285 fileArgs[0] = argv1.GetFullPath();
305 else if( managerFrame )
309 wxFileName tmp =
App().argv[1];
316 msg.Printf(
_(
"File '%s'\ndoes not appear to be a valid KiCad project file." ),
318 wxMessageDialog dlg(
nullptr, msg,
_(
"Error" ), wxOK | wxICON_EXCLAMATION );
323 projToLoad = tmp.GetFullPath();
333 if( wxFileExists( last_pro ) )
337 projToLoad = last_pro;
342 if( !projToLoad.empty() )
344 wxFileName fn( projToLoad );
362 m_api_server->SetReadyToReply();
380 m_api_server.reset();
393 git_libgit2_shutdown();
399#if defined(__WXMAC__)
403 if( !aFileName.empty() && wxFileExists( aFileName ) )
425void CustomAssertHandler(
const wxString& file,
427 const wxString& func,
428 const wxString& cond,
453 wxSizerFlags::DisableConsistencyChecks();
454 wxDISABLE_DEBUG_SUPPORT();
455 wxSetAssertHandler( CustomAssertHandler );
466 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
468 wxLog::EnableLogging(
true );
469 wxLog::SetLogLevel( wxLOG_Trace );
487 wxLog::EnableLogging(
false );
489 return wxApp::OnExit();
496 return wxApp::OnRun();
508 if( aEvent.GetEventType() == wxEVT_SHOW )
510 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
511 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
517 if( event.IsShown() && dialog->IsModal() )
519 dlgs.push_back( dialog );
522 else if( !event.IsShown() && !dlgs.empty() )
525 if( dlgs.back() == dialog )
528 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
529 dlgs.erase( it, dlgs.end() );
541 bool ProcessEvent( wxEvent& aEvent )
override
543 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
545 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
564 bool OnExceptionInMainLoop()
override
584#if defined( __WXMAC__ )
585 void MacOpenFile(
const wxString& aFileName )
override
const wxString & GetAboutTitle() const
The main KiCad project manager frame.
void LoadProject(const wxFileName &aProjectFileName)
std::vector< wxString > m_OpenProjects
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...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
void SetCtlBits(int aCtlBits)
Overwrites previously set ctl bits, only for use in kicad.cpp to flip between standalone and manager ...
void SetTop(wxFrame *aTop)
Tell this KIWAY about the top most frame in the program and optionally allows it to play the role of ...
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
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.
std::vector< void * > m_ModalDialogs
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 SETTINGS_MANAGER & GetSettingsManager() const
void SaveCommonSettings()
Save the program (process) settings subset which are stored .kicad_common.
PGM_KICAD extends PGM_BASE to bring in FileHistory() and PdfBrowser() which were moved from EDA_APP i...
void MacOpenFile(const wxString &aFileName) override
Specific to MacOSX (not used under Linux or Windows).
APP_SETTINGS_BASE * PgmSettings()
Container for project specific data.
Look for files in a number of paths.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
This file is part of the common library.
Functions related to environment variables, including help functions.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
KIWAY Kiway(KFCTL_CPP_PROJECT_SUITE)
#define KFCTL_CPP_PROJECT_SUITE
Running under C++ project mgr, possibly with others.
#define KFCTL_STANDALONE
Running as a standalone Top.
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API std::optional< wxString > GetVersionedEnvVarValue(const std::map< wxString, ENV_VAR_ITEM > &aMap, const wxString &aBaseName)
Attempts to retrieve the value of a versioned environment variable, such as KICAD8_TEMPLATE_DIR.
void SetPgm(PGM_BASE *pgm)
PGM_BASE & Pgm()
The global Program "get" accessor.
KIWAY Kiway(KFCTL_STANDALONE)
Not publicly visible because most of the action is in PGM_KICAD these days.
int FilterEvent(wxEvent &aEvent) override
void InitSettings(APP_SETTINGS_BASE *aPtr)
Takes ownership of a new application settings object.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.