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 ),
|
: DIALOG_SIM_MODEL_BASE( aParent ),
|
||||||
m_symbol( aSymbol ),
|
m_symbol( aSymbol ),
|
||||||
m_fields( aFields ),
|
m_fields( aFields ),
|
||||||
|
m_builtinModelMgr( Prj() ),
|
||||||
|
m_curModelType( SIM_MODEL::TYPE::NONE ),
|
||||||
m_library( std::make_shared<SIM_LIBRARY_SPICE>() ),
|
m_library( std::make_shared<SIM_LIBRARY_SPICE>() ),
|
||||||
m_prevModel( nullptr ),
|
m_prevModel( nullptr ),
|
||||||
m_scintillaTricks( 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;
|
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();
|
m_typeChoice->Clear();
|
||||||
|
|
||||||
|
@ -214,23 +206,29 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
||||||
{
|
{
|
||||||
// The model is sourced from the instance.
|
// The model is sourced from the instance.
|
||||||
m_useInstanceModelRadioButton->SetValue( true );
|
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
|
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 )
|
catch( const IO_ERROR& e )
|
||||||
{
|
{
|
||||||
DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
|
DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
|
||||||
+ wxT( "\n\n" )
|
+ wxT( "\n\n" )
|
||||||
+ e.What() );
|
+ 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() );
|
m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() );
|
||||||
|
@ -894,9 +892,7 @@ SIM_MODEL& DIALOG_SIM_MODEL<T>::curModel() const
|
||||||
return *m_libraryModels.at( m_modelNameCombobox->GetSelection() );
|
return *m_libraryModels.at( m_modelNameCombobox->GetSelection() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
return m_builtinModelMgr.GetModels().at( static_cast<int>( m_curModelType ) );
|
||||||
return *m_models.at( static_cast<int>( m_curModelType ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -960,21 +956,21 @@ void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
|
||||||
bool fromLibrary = m_useLibraryModelRadioButton->GetValue();
|
bool fromLibrary = m_useLibraryModelRadioButton->GetValue();
|
||||||
|
|
||||||
m_pathLabel->Enable( fromLibrary );
|
m_pathLabel->Enable( fromLibrary );
|
||||||
m_tclibraryPathName->Enable( fromLibrary );
|
m_tclibraryPathName->Enable( fromLibrary );
|
||||||
m_browseButton->Enable( fromLibrary );
|
m_browseButton->Enable( fromLibrary );
|
||||||
m_modelNameLabel->Enable( fromLibrary );
|
m_modelNameLabel->Enable( fromLibrary );
|
||||||
m_modelNameCombobox->Enable( fromLibrary );
|
m_modelNameCombobox->Enable( fromLibrary );
|
||||||
m_overrideCheckbox->Enable( fromLibrary );
|
m_overrideCheckbox->Enable( fromLibrary );
|
||||||
m_ibisPinLabel->Enable( fromLibrary );
|
m_ibisPinLabel->Enable( fromLibrary );
|
||||||
m_ibisPinCombobox->Enable( fromLibrary );
|
m_ibisPinCombobox->Enable( fromLibrary );
|
||||||
m_differentialCheckbox->Enable( fromLibrary );
|
m_differentialCheckbox->Enable( fromLibrary );
|
||||||
m_ibisModelLabel->Enable( fromLibrary );
|
m_ibisModelLabel->Enable( fromLibrary );
|
||||||
m_ibisModelCombobox->Enable( fromLibrary );
|
m_ibisModelCombobox->Enable( fromLibrary );
|
||||||
|
|
||||||
m_staticTextDevType->Enable( !fromLibrary );
|
m_staticTextDevType->Enable( !fromLibrary );
|
||||||
m_deviceTypeChoice->Enable( !fromLibrary );
|
m_deviceTypeChoice->Enable( !fromLibrary );
|
||||||
m_staticTextSpiceType->Enable( !fromLibrary );
|
m_staticTextSpiceType->Enable( !fromLibrary );
|
||||||
m_typeChoice->Enable( !fromLibrary || isIbisLoaded() );
|
m_typeChoice->Enable( !fromLibrary || isIbisLoaded() );
|
||||||
|
|
||||||
updateWidgets();
|
updateWidgets();
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,10 +141,10 @@ private:
|
||||||
SCH_SYMBOL& m_symbol;
|
SCH_SYMBOL& m_symbol;
|
||||||
std::vector<T>& m_fields;
|
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::vector<LIB_PIN*> m_sortedSymbolPins;
|
||||||
std::map<SIM_MODEL::DEVICE_TYPE_, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
|
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::shared_ptr<SIM_LIBRARY> m_library;
|
||||||
std::vector<std::unique_ptr<SIM_MODEL>> m_libraryModels;
|
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() ) );
|
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 libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD );
|
||||||
std::string baseModelName;
|
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>> 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 )
|
for( auto& [path, library] : m_libraries )
|
||||||
result.try_emplace( path, *library );
|
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.
|
// TODO: The argument can be made const.
|
||||||
SIM_LIBRARY::MODEL CreateModel( SCH_SYMBOL& aSymbol );
|
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::map<std::string, std::reference_wrapper<const SIM_LIBRARY>> GetLibraries() const;
|
||||||
|
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PROJECT& m_project;
|
const PROJECT& m_project;
|
||||||
|
|
Loading…
Reference in New Issue