31#include <wx/filename.h>
34#include <wx/stdpaths.h>
36#include <wx/cmdline.h>
73 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
75 throw std::logic_error(
"Unexpected call to Kiface() in kicad/kicad.cpp" );
89 App().SetAppDisplayName( wxT(
"KiCad" ) );
92 wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
94 if( !wxIsAbsolutePath( absoluteArgv0 ) )
96 wxLogError( wxT(
"No meaningful argv[0]" ) );
105 static const wxCmdLineEntryDesc desc[] = {
106 { wxCMD_LINE_OPTION,
"f",
"frame",
"Frame to load", wxCMD_LINE_VAL_STRING, 0 },
107 { wxCMD_LINE_SWITCH,
"n",
"new",
"New instance of KiCad, does not attempt to load previously open files",
108 wxCMD_LINE_VAL_NONE, 0 },
110 { wxCMD_LINE_SWITCH,
nullptr,
"software-rendering",
"Use software rendering instead of OpenGL",
111 wxCMD_LINE_VAL_NONE, 0 },
113 { wxCMD_LINE_PARAM,
nullptr,
nullptr,
"File to load", wxCMD_LINE_VAL_STRING,
114 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
115 { wxCMD_LINE_NONE,
nullptr,
nullptr,
nullptr, wxCMD_LINE_VAL_NONE, 0 }
118 wxCmdLineParser parser(
App().argc,
App().argv );
119 parser.SetDesc( desc );
120 parser.Parse(
false );
139 if( parser.Found(
"frame", &frameName ) )
143 for(
const auto& it : frameTypes )
145 if( it.name == frameName )
151 wxLogError( wxT(
"Unknown frame: %s" ), frameName );
168 if( parser.Found(
"software-rendering" ) )
170 wxSetEnv(
"KICAD_SOFTWARE_RENDERING",
"1" );
174 bool skipPythonInit =
false;
178 skipPythonInit =
true;
180 if( !
InitPgm(
false, skipPythonInit ) )
195 for(
unsigned i = 0; i < bases.GetCount(); ++i )
197 wxFileName fn( bases[i], wxEmptyString );
200 fn.AppendDir( wxT(
"template" ) );
203 if( fn.DirExists() && fn.IsDirReadable() )
204 m_bm.m_search.AddPaths( fn.GetPath() );
209 wxT(
"TEMPLATE_DIR" ) ) )
212 m_bm.m_search.Insert( *v, 0 );
223 m_bm.m_search.Insert( it->second.GetValue(), 0 );
226 wxFrame* frame =
nullptr;
233 wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
234 frame = managerFrame;
241 playerFrame =
Kiway.Player( appType,
true );
244 if( frame ==
nullptr )
250 App().SetTopWindow( frame );
255 Kiway.SetTop( frame );
263 m_api_server = std::make_unique<KICAD_API_SERVER>();
264 m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
265 m_api_server->RegisterHandler( m_api_common_handler.get() );
272 if( playerFrame && parser.GetParamCount() )
275 std::vector<wxString> fileArgs;
285 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
286 fileArgs.push_back( parser.GetParam( i ) );
289 if( fileArgs.size() == 1 )
291 wxFileName argv1( fileArgs[0] );
293#if defined( PGM_DATA_FILE_EXT )
298 if( !argv1.GetExt() )
299 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
301 argv1.MakeAbsolute();
303 fileArgs[0] = argv1.GetFullPath();
323 else if( managerFrame )
325 if( parser.GetParamCount() > 0 )
327 wxFileName tmp = parser.GetParam( 0 );
332 "does not appear to be a KiCad project file." ),
333 tmp.GetFullPath() ) );
337 projToLoad = tmp.GetFullPath();
342 if( projToLoad.IsEmpty() && settings->
m_OpenProjects.size() && !parser.FoundSwitch(
"new" ) )
347 if( wxFileExists( last_pro ) )
351 projToLoad = last_pro;
356 if( !projToLoad.empty() )
358 wxFileName fn( projToLoad );
375 m_api_server->SetReadyToReply();
393 m_api_server.reset();
414#if defined(__WXMAC__)
418 if( !aFileName.empty() && wxFileExists( aFileName ) )
440void CustomAssertHandler(
const wxString& file,
442 const wxString& func,
443 const wxString& cond,
468 wxSizerFlags::DisableConsistencyChecks();
469 wxDISABLE_DEBUG_SUPPORT();
470 wxSetAssertHandler( CustomAssertHandler );
481 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
483 wxLog::EnableLogging(
true );
484 wxLog::SetLogLevel( wxLOG_Trace );
502 wxLog::EnableLogging(
false );
504 return wxApp::OnExit();
511 return wxApp::OnRun();
523 if( aEvent.GetEventType() == wxEVT_SHOW )
525 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
526 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
532 if( event.IsShown() && dialog->IsModal() )
534 dlgs.push_back( dialog );
537 else if( !event.IsShown() && !dlgs.empty() )
540 if( dlgs.back() == dialog )
543 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
544 dlgs.erase( it, dlgs.end() );
556 bool ProcessEvent( wxEvent& aEvent )
override
558 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
560 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
579 bool OnExceptionInMainLoop()
override
599#if defined( __WXMAC__ )
600 void MacOpenFile(
const wxString& aFileName )
override
const wxString & GetAboutTitle() const
virtual void Shutdown()=0
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...
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
virtual wxApp & App()
Return 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 const wxString & GetExecutablePath() const
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.
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 DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
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.
void SetGitBackend(GIT_BACKEND *aBackend)
GIT_BACKEND * GetGitBackend()
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)
Attempt 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 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.