Sim Model Editor: Use SIM_LIB_MGR to store instance models
This commit is contained in:
parent
7c9f3981ef
commit
d66d810edc
|
@ -46,6 +46,8 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
|||
: DIALOG_SIM_MODEL_BASE( aParent ),
|
||||
m_symbol( aSymbol ),
|
||||
m_fields( aFields ),
|
||||
m_builtinModelMgr( Prj() ),
|
||||
m_curModelType( SIM_MODEL::TYPE::NONE ),
|
||||
m_library( std::make_shared<SIM_LIBRARY_SPICE>() ),
|
||||
m_prevModel( nullptr ),
|
||||
m_scintillaTricks( nullptr ),
|
||||
|
@ -64,16 +66,6 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
|||
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
|
||||
} );
|
||||
|
||||
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
||||
{
|
||||
m_models.push_back( SIM_MODEL::Create( type, m_sortedSymbolPins.size() ) );
|
||||
|
||||
SIM_MODEL::DEVICE_TYPE_ deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
|
||||
|
||||
if( !m_curModelTypeOfDeviceType.count( deviceType ) )
|
||||
m_curModelTypeOfDeviceType[deviceType] = type;
|
||||
}
|
||||
|
||||
|
||||
m_typeChoice->Clear();
|
||||
|
||||
|
@ -214,23 +206,29 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
|||
{
|
||||
// The model is sourced from the instance.
|
||||
m_useInstanceModelRadioButton->SetValue( true );
|
||||
SIM_MODEL::TYPE type = SIM_MODEL::ReadTypeFromFields( m_fields, pinCount );
|
||||
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, pinCount );
|
||||
}
|
||||
|
||||
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_models.at( static_cast<int>( type ) ) = SIM_MODEL::Create( pinCount, m_fields );
|
||||
if( m_useInstanceModelRadioButton->GetValue() && type == m_curModelType )
|
||||
m_builtinModelMgr.CreateModel( m_fields, m_sortedSymbolPins.size() );
|
||||
else
|
||||
m_builtinModelMgr.CreateModel( type, m_sortedSymbolPins.size() );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
|
||||
+ wxT( "\n\n" )
|
||||
+ e.What() );
|
||||
|
||||
onRadioButton( dummyEvent );
|
||||
return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
|
||||
}
|
||||
|
||||
m_curModelType = type;
|
||||
SIM_MODEL::DEVICE_TYPE_ deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
|
||||
|
||||
if( !m_curModelTypeOfDeviceType.count( deviceType ) )
|
||||
m_curModelTypeOfDeviceType[deviceType] = type;
|
||||
}
|
||||
|
||||
m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() );
|
||||
|
@ -894,9 +892,7 @@ SIM_MODEL& DIALOG_SIM_MODEL<T>::curModel() const
|
|||
return *m_libraryModels.at( m_modelNameCombobox->GetSelection() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return *m_models.at( static_cast<int>( m_curModelType ) );
|
||||
}
|
||||
return m_builtinModelMgr.GetModels().at( static_cast<int>( m_curModelType ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -141,10 +141,10 @@ private:
|
|||
SCH_SYMBOL& m_symbol;
|
||||
std::vector<T>& m_fields;
|
||||
|
||||
std::vector<std::unique_ptr<SIM_MODEL>> m_models;
|
||||
SIM_LIB_MGR m_builtinModelMgr;
|
||||
std::vector<LIB_PIN*> m_sortedSymbolPins;
|
||||
std::map<SIM_MODEL::DEVICE_TYPE_, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
|
||||
SIM_MODEL::TYPE m_curModelType = SIM_MODEL::TYPE::NONE;
|
||||
SIM_MODEL::TYPE m_curModelType;
|
||||
|
||||
std::shared_ptr<SIM_LIBRARY> m_library;
|
||||
std::vector<std::unique_ptr<SIM_MODEL>> m_libraryModels;
|
||||
|
|
|
@ -61,8 +61,14 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( SCH_SYMBOL& aSymbol )
|
|||
return CreateModel( aSymbol.GetFields(), static_cast<int>( aSymbol.GetLibPins().size() ) );
|
||||
}
|
||||
|
||||
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
|
||||
int aSymbolPinCount )
|
||||
|
||||
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
|
||||
int aSymbolPinCount );
|
||||
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<LIB_FIELD>& aFields,
|
||||
int aSymbolPinCount );
|
||||
|
||||
template <typename T>
|
||||
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields, int aSymbolPinCount )
|
||||
{
|
||||
std::string libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD );
|
||||
std::string baseModelName;
|
||||
|
@ -115,10 +121,21 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFiel
|
|||
|
||||
std::map<std::string, std::reference_wrapper<const SIM_LIBRARY>> SIM_LIB_MGR::GetLibraries() const
|
||||
{
|
||||
std::map<std::string, std::reference_wrapper<const SIM_LIBRARY>> result;
|
||||
std::map<std::string, std::reference_wrapper<const SIM_LIBRARY>> libraries;
|
||||
|
||||
for( auto&& [path, library] : m_libraries )
|
||||
result.try_emplace( path, *library );
|
||||
for( auto& [path, library] : m_libraries )
|
||||
libraries.try_emplace( path, *library );
|
||||
|
||||
return result;
|
||||
return libraries;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::reference_wrapper<SIM_MODEL>> SIM_LIB_MGR::GetModels() const
|
||||
{
|
||||
std::vector<std::reference_wrapper<SIM_MODEL>> models;
|
||||
|
||||
for( const std::unique_ptr<SIM_MODEL>& model : m_models )
|
||||
models.emplace_back( *model );
|
||||
|
||||
return models;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,11 @@ public:
|
|||
// TODO: The argument can be made const.
|
||||
SIM_LIBRARY::MODEL CreateModel( SCH_SYMBOL& aSymbol );
|
||||
|
||||
SIM_LIBRARY::MODEL CreateModel( const std::vector<SCH_FIELD>& aFields, int aSymbolPinCount );
|
||||
template <typename T>
|
||||
SIM_LIBRARY::MODEL CreateModel( const std::vector<T>& aFields, int aSymbolPinCount );
|
||||
|
||||
std::map<std::string, std::reference_wrapper<const SIM_LIBRARY>> GetLibraries() const;
|
||||
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
||||
|
||||
private:
|
||||
const PROJECT& m_project;
|
||||
|
|
Loading…
Reference in New Issue