31#include <wx/filename.h> 
   34#include <wx/stdpaths.h> 
   36#include <wx/cmdline.h> 
   77    wxLogFatalError( wxT( 
"Unexpected call to Kiface() in kicad/kicad.cpp" ) );
 
   79    throw std::logic_error( 
"Unexpected call to Kiface() in kicad/kicad.cpp" );
 
 
   93    App().SetAppDisplayName( wxT( 
"KiCad" ) );
 
   96    wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();
 
   98    if( !wxIsAbsolutePath( absoluteArgv0 ) )
 
  100        wxLogError( wxT( 
"No meaningful argv[0]" ) );
 
  109    static const wxCmdLineEntryDesc desc[] = {
 
  110        { wxCMD_LINE_OPTION, 
"f", 
"frame", 
"Frame to load", wxCMD_LINE_VAL_STRING, 0 },
 
  111        { wxCMD_LINE_SWITCH, 
"n", 
"new", 
"New instance of KiCad, does not attempt to load previously open files",
 
  112          wxCMD_LINE_VAL_NONE, 0 },
 
  114        { wxCMD_LINE_SWITCH, 
nullptr, 
"software-rendering", 
"Use software rendering instead of OpenGL",
 
  115          wxCMD_LINE_VAL_NONE, 0 },
 
  117        { wxCMD_LINE_PARAM, 
nullptr, 
nullptr, 
"File to load", wxCMD_LINE_VAL_STRING,
 
  118          wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
 
  119        { wxCMD_LINE_NONE, 
nullptr, 
nullptr, 
nullptr, wxCMD_LINE_VAL_NONE, 0 }
 
  122    wxCmdLineParser parser( 
App().argc, 
App().argv );
 
  123    parser.SetDesc( desc );
 
  124    parser.Parse( 
false );
 
  143    if( parser.Found( 
"frame", &frameName ) )
 
  147        for( 
const auto& it : frameTypes )
 
  149            if( it.name == frameName )
 
  155            wxLogError( wxT( 
"Unknown frame: %s" ), frameName );
 
  172    if( parser.Found( 
"software-rendering" ) )
 
  174        wxSetEnv( 
"KICAD_SOFTWARE_RENDERING", 
"1" );
 
  178    bool skipPythonInit = 
false;
 
  182        skipPythonInit = 
true;
 
  184    if( !
InitPgm( 
false, skipPythonInit ) )
 
  201        for( 
unsigned i = 0; i < bases.GetCount(); ++i )
 
  203            wxFileName fn( bases[i], wxEmptyString );
 
  206            fn.AppendDir( wxT( 
"template" ) );
 
  209            if( fn.DirExists() && fn.IsDirReadable() )
 
  210                m_bm.m_search.AddPaths( fn.GetPath() );
 
  215                                                                          wxT( 
"TEMPLATE_DIR" ) ) )
 
  218                m_bm.m_search.Insert( *v, 0 );
 
  229            m_bm.m_search.Insert( it->second.GetValue(), 0 );
 
  232    wxFrame*      frame = 
nullptr;
 
  239                                                wxWindow::FromDIP( wxSize( 775, -1 ), NULL ) );
 
  240        frame = managerFrame;
 
  250        playerFrame = 
Kiway.Player( appType, 
true );
 
  253        if( frame == 
nullptr )
 
  259    App().SetTopWindow( frame );
 
  264    Kiway.SetTop( frame );
 
  274    m_api_server = std::make_unique<KICAD_API_SERVER>();
 
  275    m_api_common_handler = std::make_unique<API_HANDLER_COMMON>();
 
  276    m_api_server->RegisterHandler( m_api_common_handler.get() );
 
  283    if( playerFrame && parser.GetParamCount() )
 
  286        std::vector<wxString> fileArgs;
 
  296        for( 
size_t i = 0; i < parser.GetParamCount(); i++ )
 
  297            fileArgs.push_back( parser.GetParam( i ) );
 
  300        if( fileArgs.size() == 1 )
 
  302            wxFileName argv1( fileArgs[0] );
 
  304#if defined( PGM_DATA_FILE_EXT ) 
  309            if( !argv1.GetExt() )
 
  310                argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) );
 
  312            argv1.MakeAbsolute();
 
  314            fileArgs[0] = argv1.GetFullPath();
 
  334    else if( managerFrame )
 
  336        if( parser.GetParamCount() > 0 )
 
  338            wxFileName tmp = parser.GetParam( 0 );
 
  343                                                                   "does not appear to be a KiCad project file." ),
 
  344                                                                tmp.GetFullPath() ) );
 
  348                projToLoad = tmp.GetFullPath();
 
  353        if( projToLoad.IsEmpty() && settings->
m_OpenProjects.size() && !parser.FoundSwitch( 
"new" ) )
 
  358            if( wxFileExists( last_pro ) )
 
  362                projToLoad = last_pro;
 
  367        if( !projToLoad.empty() )
 
  369            wxFileName fn( projToLoad );
 
  386    m_api_server->SetReadyToReply();
 
 
  404    m_api_server.reset();
 
 
  425#if defined(__WXMAC__) 
  429    if( !aFileName.empty() && wxFileExists( aFileName ) )
 
 
  451void CustomAssertHandler(
const wxString& file,
 
  453                         const wxString& func,
 
  454                         const wxString& cond,
 
  479        wxSizerFlags::DisableConsistencyChecks();
 
  480        wxDISABLE_DEBUG_SUPPORT();
 
  481        wxSetAssertHandler( CustomAssertHandler );
 
  492        if( wxGetEnv( wxS( 
"KICAD_ENABLE_WXTRACE" ), 
nullptr ) )
 
  494            wxLog::EnableLogging( 
true );
 
  495            wxLog::SetLogLevel( wxLOG_Trace );
 
 
  513        wxLog::EnableLogging( 
false );
 
  515        return wxApp::OnExit();
 
 
  522            return wxApp::OnRun();
 
 
  534        if( aEvent.GetEventType() == wxEVT_SHOW )
 
  536            wxShowEvent& 
event = 
static_cast<wxShowEvent&
>( aEvent );
 
  537            wxDialog*    dialog = 
dynamic_cast<wxDialog*
>( 
event.GetEventObject() );
 
  543                if( event.IsShown() && dialog->IsModal() )
 
  545                    dlgs.push_back( dialog );
 
  548                else if( !event.IsShown() && !dlgs.empty() )
 
  551                    if( dlgs.back() == dialog )
 
  554                    else if( 
auto it = std::find( dlgs.begin(), dlgs.end(), dialog ) ; it != dlgs.end() )
 
  555                        dlgs.erase( it, dlgs.end() );
 
 
  567    bool ProcessEvent( wxEvent& aEvent )
 override 
  569        if( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
 
  571            wxKeyEvent* keyEvent = 
static_cast<wxKeyEvent*
>( &aEvent );
 
  590    bool OnExceptionInMainLoop()
 override 
  610#if defined( __WXMAC__ ) 
  611    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...
 
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 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
 
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)
 
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.