Better error reporting, and don't infer models with library references.

This commit is contained in:
Jeff Young 2023-02-04 20:55:52 +00:00
parent 9be872a85a
commit d1f6ba77e8
2 changed files with 28 additions and 14 deletions

View File

@ -212,7 +212,7 @@ SIM_MODEL::INFO SIM_MODEL::TypeInfo( TYPE aType )
//case TYPE::I_RANDPOISSON: return { DEVICE_TYPE::I, "RANDPOISSON", "Random Poisson" }; //case TYPE::I_RANDPOISSON: return { DEVICE_TYPE::I, "RANDPOISSON", "Random Poisson" };
case TYPE::I_BEHAVIORAL: return { DEVICE_T::I, "=", "Behavioral" }; case TYPE::I_BEHAVIORAL: return { DEVICE_T::I, "=", "Behavioral" };
case TYPE::SUBCKT: return { DEVICE_T::SUBCKT, "", "" }; case TYPE::SUBCKT: return { DEVICE_T::SUBCKT, "", "Subcircuit" };
case TYPE::XSPICE: return { DEVICE_T::XSPICE, "", "" }; case TYPE::XSPICE: return { DEVICE_T::XSPICE, "", "" };
case TYPE::KIBIS_DEVICE: return { DEVICE_T::KIBIS, "DEVICE", "Device" }; case TYPE::KIBIS_DEVICE: return { DEVICE_T::KIBIS, "DEVICE", "Device" };
@ -721,6 +721,28 @@ void SIM_MODEL::AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant )
} }
void SIM_MODEL::SetBaseModel( const SIM_MODEL& aBaseModel )
{
auto describe =
[]( const SIM_MODEL* aModel )
{
return fmt::format( "{} ({})",
aModel->GetDeviceInfo().fieldValue,
aModel->GetTypeInfo().description );
};
if( GetType() != aBaseModel.GetType() )
{
THROW_IO_ERROR( wxString::Format( _( "Simulation model type must be the same as of its "
"base class: '%s', but is '%s'" ),
describe( &aBaseModel ),
describe( this ) ) );
}
m_baseModel = &aBaseModel;
}
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SIM_MODEL::GetPins() const std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SIM_MODEL::GetPins() const
{ {
std::vector<std::reference_wrapper<const PIN>> pins; std::vector<std::reference_wrapper<const PIN>> pins;
@ -1232,6 +1254,8 @@ bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields,
}; };
wxString prefix = aSymbol.GetPrefix(); wxString prefix = aSymbol.GetPrefix();
wxString library = GetFieldValue( aFields, SIM_LIBRARY_FIELD, aResolve );
wxString modelName = GetFieldValue( aFields, SIM_NAME_FIELD, aResolve );
wxString value = GetFieldValue( aFields, SIM_VALUE_FIELD, aResolve ); wxString value = GetFieldValue( aFields, SIM_VALUE_FIELD, aResolve );
std::vector<LIB_PIN*> pins = aSymbol.GetAllLibPins(); std::vector<LIB_PIN*> pins = aSymbol.GetAllLibPins();
@ -1246,7 +1270,8 @@ bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields,
if( ( ( *aDeviceType == "R" || *aDeviceType == "L" || *aDeviceType == "C" ) if( ( ( *aDeviceType == "R" || *aDeviceType == "L" || *aDeviceType == "C" )
&& aModelType->IsEmpty() ) && aModelType->IsEmpty() )
|| ||
( aDeviceType->IsEmpty() ( library.IsEmpty() && modelName.IsEmpty()
&& aDeviceType->IsEmpty()
&& aModelType->IsEmpty() && aModelType->IsEmpty()
&& !value.IsEmpty() && !value.IsEmpty()
&& ( prefix.StartsWith( "R" ) || prefix.StartsWith( "L" ) || prefix.StartsWith( "C" ) ) ) ) && ( prefix.StartsWith( "R" ) || prefix.StartsWith( "L" ) || prefix.StartsWith( "C" ) ) ) )

View File

@ -462,18 +462,7 @@ public:
TYPE GetType() const { return m_type; } TYPE GetType() const { return m_type; }
const SIM_MODEL* GetBaseModel() const { return m_baseModel; } const SIM_MODEL* GetBaseModel() const { return m_baseModel; }
virtual void SetBaseModel( const SIM_MODEL& aBaseModel ) virtual void SetBaseModel( const SIM_MODEL& aBaseModel );
{
if( GetType() != aBaseModel.GetType() )
{
THROW_IO_ERROR( wxString::Format(
_( "Simulation model type must be the same as of its base class: '%s', but is '%s'" ),
aBaseModel.GetTypeInfo().fieldValue,
GetTypeInfo().fieldValue ) );
}
m_baseModel = &aBaseModel;
}
virtual std::vector<std::string> GetPinNames() const { return {}; } virtual std::vector<std::string> GetPinNames() const { return {}; }