diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 68c0471a28..50afaeca60 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -283,6 +283,7 @@ set( EESCHEMA_SRCS sim/sim_library.cpp sim/sim_library_spice.cpp sim/sim_library_kibis.cpp + sim/sim_lib_mgr.cpp sim/sim_model.cpp sim/sim_model_behavioral.cpp sim/sim_model_ideal.cpp diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 5a6bdaa17a..eba280aaea 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include "symbol_library_manager.h" #include #include @@ -883,52 +884,12 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) SCH_SYMBOL* symbol = static_cast( item->GetParent() ); std::vector pins = symbol->GetLibPins(); - // TODO: We need to unify this library-model inheritance stuff into one - // abstraction. - - // It might not be the best idea to have to load a file every time current is - // probed either. - - std::unique_ptr model; - std::unique_ptr library; - - SCH_FIELD* libraryField = symbol->FindField( SIM_LIBRARY::LIBRARY_FIELD ); - SCH_FIELD* nameField = symbol->FindField( SIM_LIBRARY::NAME_FIELD ); - - if( libraryField ) - { - wxString path = m_frame->Prj().AbsolutePath( libraryField->GetShownText() ); - - try - { - library = SIM_LIBRARY::Create( std::string( path.ToUTF8() ) ); - } - catch( const IO_ERROR& e ) - { - DisplayErrorMessage( m_frame, - wxString::Format( "Failed reading model library '%s'", path ), - e.What() ); - return true; - } - - if( !nameField ) - return true; - - SIM_MODEL* baseModel = library->FindModel( std::string( nameField->GetShownText().ToUTF8() ) ); - - if( !baseModel ) - return true; - - model = SIM_MODEL::Create( *baseModel, - static_cast( pins.size() ), - symbol->GetFields() ); - } - else - model = SIM_MODEL::Create( static_cast( pins.size() ), - symbol->GetFields() ); + SIM_LIB_MGR mgr( m_frame->Prj() ); + SIM_MODEL& model = mgr.CreateModel( *symbol ); auto ref = std::string( symbol->GetRef( &m_frame->GetCurrentSheet() ).ToUTF8() ); - std::vector currentNames = model->SpiceGenerator().CurrentNames( ref ); + std::vector currentNames = + model.SpiceGenerator().CurrentNames( ref ); if( currentNames.size() == 0 ) return true; @@ -938,7 +899,8 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) return true; } - int modelPinIndex = model->FindModelPinIndex( std::string( pin->GetNumber().ToUTF8() ) ); + int modelPinIndex = + model.FindModelPinIndex( std::string( pin->GetNumber().ToUTF8() ) ); if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED ) {