31#include <wx/filename.h>
34#include <wx/stdpaths.h>
36#include <wx/cmdline.h>
67 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
69 throw std::logic_error(
"Unexpected call to Kiface() in kicad/kicad.cpp" );
97 App().SetAppDisplayName( wxT(
"KiCad" ) );
100 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
102 if( !wxIsAbsolutePath( absoluteArgv0 ) )
104 wxLogError( wxT(
"No meaningful argv[0]" ) );
112 static const wxCmdLineEntryDesc desc[] = {
113 { wxCMD_LINE_OPTION,
"f",
"frame",
"Frame to load", wxCMD_LINE_VAL_STRING, 0 },
114 { wxCMD_LINE_PARAM,
nullptr,
nullptr,
"File to load", wxCMD_LINE_VAL_STRING,
115 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
116 { wxCMD_LINE_NONE,
nullptr,
nullptr,
nullptr, wxCMD_LINE_VAL_NONE, 0 }
119 wxCmdLineParser parser(
App().argc,
App().argv );
120 parser.SetDesc( desc );
121 parser.Parse(
false );
140 if( parser.Found(
"frame", &frameName ) )
144 for(
const auto& it : frameTypes )
146 if( it.name == frameName )
152 wxLogError( wxT(
"Unknown frame: %s" ), frameName );
168 bool skipPythonInit =
false;
172 skipPythonInit =
true;
174 if( !
InitPgm(
false, skipPythonInit ) )
189 for(
unsigned i = 0; i < bases.GetCount(); ++i )
191 wxFileName fn( bases[i], wxEmptyString );
194 fn.AppendDir( wxT(
"template" ) );
197 if( fn.DirExists() && fn.IsDirReadable() )
218 wxFrame* frame =
nullptr;
226 frame = managerFrame;
236 if( frame ==
nullptr )
242 App().SetTopWindow( frame );
255 if( playerFrame && parser.GetParamCount() )
258 std::vector<wxString> fileArgs;
268 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
269 fileArgs.push_back( parser.GetParam( i ) );
272 if( fileArgs.size() == 1 )
274 wxFileName argv1( fileArgs[0] );
276#if defined( PGM_DATA_FILE_EXT )
281 if( !argv1.GetExt() )
282 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
284 argv1.MakeAbsolute();
286 fileArgs[0] = argv1.GetFullPath();
306 else if( managerFrame )
310 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 );
385 git_libgit2_shutdown();
391#if defined(__WXMAC__)
395 if( !aFileName.empty() && wxFileExists( aFileName ) )
417void CustomAssertHandler(
const wxString& file,
419 const wxString& func,
420 const wxString& cond,
443 wxSizerFlags::DisableConsistencyChecks();
444 wxDISABLE_DEBUG_SUPPORT();
445 wxSetAssertHandler( CustomAssertHandler );
466 wxLog::EnableLogging(
false );
468 return wxApp::OnExit();
475 return wxApp::OnRun();
487 if( aEvent.GetEventType() == wxEVT_SHOW )
489 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
490 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
496 if( event.IsShown() && dialog->IsModal() )
498 dlgs.push_back( dialog );
501 else if( !event.IsShown() && !dlgs.empty() )
504 if( dlgs.back() == dialog )
507 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
508 dlgs.erase( it, dlgs.end() );
520 bool ProcessEvent( wxEvent& aEvent )
override
522 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
524 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
543 bool OnExceptionInMainLoop()
override
563#if defined( __WXMAC__ )
564 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.
Container for data for KiCad programs.
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.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
const std::string LegacyProjectFileExtension
const std::string ProjectFileExtension
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
std::map< wxString, ENV_VAR_ITEM >::const_iterator ENV_VAR_MAP_CITER
PGM_BASE & Pgm()
The global Program "get" accessor.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
#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.
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.