31#include <wx/filename.h>
34#include <wx/stdpaths.h>
36#include <wx/cmdline.h>
81 wxLogFatalError( wxT(
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
83 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]" ) );
113 static const wxCmdLineEntryDesc desc[] = {
114 { wxCMD_LINE_OPTION,
"f",
"frame",
"Frame to load", wxCMD_LINE_VAL_STRING, 0 },
115 { wxCMD_LINE_SWITCH,
"n",
"new",
"New instance of KiCad, does not attempt to load previously open files",
116 wxCMD_LINE_VAL_NONE, 0 },
118 { wxCMD_LINE_SWITCH,
nullptr,
"software-rendering",
"Use software rendering instead of OpenGL",
119 wxCMD_LINE_VAL_NONE, 0 },
121 { wxCMD_LINE_PARAM,
nullptr,
nullptr,
"File to load", wxCMD_LINE_VAL_STRING,
122 wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
123 { wxCMD_LINE_NONE,
nullptr,
nullptr,
nullptr, wxCMD_LINE_VAL_NONE, 0 }
126 wxCmdLineParser parser(
App().argc,
App().argv );
127 parser.SetDesc( desc );
128 parser.Parse(
false );
147 if( parser.Found(
"frame", &frameName ) )
151 for(
const auto& it : frameTypes )
153 if( it.name == frameName )
159 wxLogError( wxT(
"Unknown frame: %s" ), frameName );
176 if( parser.Found(
"software-rendering" ) )
178 wxSetEnv(
"KICAD_SOFTWARE_RENDERING",
"1" );
206 for(
unsigned i = 0; i < bases.GetCount(); ++i )
208 wxFileName fn( bases[i], wxEmptyString );
211 fn.AppendDir( wxT(
"template" ) );
214 if( fn.DirExists() && fn.IsDirReadable() )
215 m_bm.m_search.AddPaths( fn.GetPath() );
218 auto insertExpanded = [&](
const wxString& aValue )
224 if( resolved.Contains( wxT(
"${" ) ) || resolved.Contains( wxT(
"$(" ) ) )
227 m_bm.m_search.Insert( resolved, 0 );
232 wxT(
"TEMPLATE_DIR" ) ) )
235 insertExpanded( *v );
247 insertExpanded( it->second.GetValue() );
250 wxFrame* frame =
nullptr;
257 wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
258 frame = managerFrame;
268 playerFrame =
Kiway.Player( appType,
true );
271 if( frame ==
nullptr )
277 App().SetTopWindow( frame );
282 Kiway.SetTop( frame );
292 m_api_server = std::make_unique<KICAD_API_SERVER>();
293 m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
294 m_api_server->RegisterHandler( m_api_common_handler.get() );
301 if( playerFrame && parser.GetParamCount() )
304 std::vector<wxString> fileArgs;
314 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
315 fileArgs.push_back( parser.GetParam( i ) );
318 if( fileArgs.size() == 1 )
320 wxFileName argv1( fileArgs[0] );
322#if defined( PGM_DATA_FILE_EXT )
327 if( !argv1.GetExt() )
328 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
330 argv1.MakeAbsolute();
332 fileArgs[0] = argv1.GetFullPath();
352 else if( managerFrame )
354 if( parser.GetParamCount() > 0 )
356 wxFileName tmp = parser.GetParam( 0 );
361 "does not appear to be a KiCad project file." ),
362 tmp.GetFullPath() ) );
366 projToLoad = tmp.GetFullPath();
371 if( projToLoad.IsEmpty() && settings->
m_OpenProjects.size() && !parser.FoundSwitch(
"new" ) )
376 if( wxFileExists( last_pro ) )
380 projToLoad = last_pro;
387 if( !projToLoad.empty() )
389 wxFileName fn( projToLoad );
409 m_api_server->SetReadyToReply();
436 m_api_server.reset();
457#if defined(__WXMAC__)
461 if( !aFileName.empty() && wxFileExists( aFileName ) )
483void CustomAssertHandler(
const wxString& file,
485 const wxString& func,
486 const wxString& cond,
511 wxSizerFlags::DisableConsistencyChecks();
512 wxDISABLE_DEBUG_SUPPORT();
513 wxSetAssertHandler( CustomAssertHandler );
524 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
526 wxLog::EnableLogging(
true );
527 wxLog::SetLogLevel( wxLOG_Trace );
547 int ret = wxApp::OnExit();
550 wxLog::EnableLogging(
false );
561 return wxApp::OnRun();
580 if( aEvent.GetEventType() == wxEVT_SHOW )
582 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
583 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
589 if( event.IsShown() && dialog->IsModal() )
591 dlgs.push_back( dialog );
594 else if( !event.IsShown() && !dlgs.empty() )
597 if( dlgs.back() == dialog )
600 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
601 dlgs.erase( it, dlgs.end() );
613 bool ProcessEvent( wxEvent& aEvent )
override
615 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
617 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
636 bool OnExceptionInMainLoop()
override
656#if defined( __WXMAC__ )
657 void MacOpenFile(
const wxString& aFileName )
override
wxString GetAboutTitle() const
virtual void Shutdown()=0
The main KiCad project manager frame.
void PreloadAllLibraries()
bool LoadProject(const wxFileName &aProjectFileName)
Loads a new project.
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...
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
virtual COMMON_SETTINGS * GetCommonSettings() const
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
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::atomic_bool m_libraryPreloadAbort
std::vector< void * > m_ModalDialogs
bool InitPgm(bool aHeadless=false, bool aIsUnitTest=false)
Initialize this program.
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
virtual LIBRARY_MANAGER & GetLibraryManager() 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 CheckAndRun(wxWindow *parent)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
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.
void OnUnhandledException() override
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.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.