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>();
252 if( playerFrame && parser.GetParamCount() )
255 std::vector<wxString> fileArgs;
265 for(
size_t i = 0; i < parser.GetParamCount(); i++ )
266 fileArgs.push_back( parser.GetParam( i ) );
269 if( fileArgs.size() == 1 )
271 wxFileName argv1( fileArgs[0] );
273#if defined( PGM_DATA_FILE_EXT )
278 if( !argv1.GetExt() )
279 argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
281 argv1.MakeAbsolute();
283 fileArgs[0] = argv1.GetFullPath();
303 else if( managerFrame )
307 wxFileName tmp =
App().argv[1];
314 msg.Printf(
_(
"File '%s'\ndoes not appear to be a valid KiCad project file." ),
316 wxMessageDialog dlg(
nullptr, msg,
_(
"Error" ), wxOK | wxICON_EXCLAMATION );
321 projToLoad = tmp.GetFullPath();
331 if( wxFileExists( last_pro ) )
335 projToLoad = last_pro;
340 if( !projToLoad.empty() )
342 wxFileName fn( projToLoad );
360 m_api_server->SetReadyToReply();
378 m_api_server.reset();
391 git_libgit2_shutdown();
397#if defined(__WXMAC__)
401 if( !aFileName.empty() && wxFileExists( aFileName ) )
423void CustomAssertHandler(
const wxString& file,
425 const wxString& func,
426 const wxString& cond,
451 wxSizerFlags::DisableConsistencyChecks();
452 wxDISABLE_DEBUG_SUPPORT();
453 wxSetAssertHandler( CustomAssertHandler );
464 if( wxGetEnv( wxS(
"KICAD_ENABLE_WXTRACE" ),
nullptr ) )
466 wxLog::EnableLogging(
true );
467 wxLog::SetLogLevel( wxLOG_Trace );
485 wxLog::EnableLogging(
false );
487 return wxApp::OnExit();
494 return wxApp::OnRun();
506 if( aEvent.GetEventType() == wxEVT_SHOW )
508 wxShowEvent&
event =
static_cast<wxShowEvent&
>( aEvent );
509 wxDialog* dialog =
dynamic_cast<wxDialog*
>(
event.GetEventObject() );
515 if( event.IsShown() && dialog->IsModal() )
517 dlgs.push_back( dialog );
520 else if( !event.IsShown() && !dlgs.empty() )
523 if( dlgs.back() == dialog )
526 else if(
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
527 dlgs.erase( it, dlgs.end() );
539 bool ProcessEvent( wxEvent& aEvent )
override
541 if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
543 wxKeyEvent* keyEvent =
static_cast<wxKeyEvent*
>( &aEvent );
562 bool OnExceptionInMainLoop()
override
582#if defined( __WXMAC__ )
583 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.