Sim: Skip param name when writing primary param in model's Value field
This commit is contained in:
parent
5f7213e419
commit
aa0e3666d1
|
@ -1021,7 +1021,12 @@ void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const std::str
|
|||
if( removePinsField )
|
||||
SetFieldValue( aFields, PINS_FIELD, "" );
|
||||
|
||||
SetFieldValue( aFields, VALUE_FIELD, aValue );
|
||||
std::string value = aValue;
|
||||
|
||||
if( value == "" )
|
||||
value = GenerateValueField( "=" );
|
||||
|
||||
SetFieldValue( aFields, VALUE_FIELD, value );
|
||||
SetFieldValue( aFields, DEVICE_TYPE_FIELD, "" );
|
||||
SetFieldValue( aFields, TYPE_FIELD, "" );
|
||||
SetFieldValue( aFields, PARAMS_FIELD, "" );
|
||||
|
@ -1053,6 +1058,35 @@ std::string SIM_MODEL::GenerateParamValuePair( const PARAM& aParam, bool& aIsFir
|
|||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::GenerateValueField( const std::string& aPairSeparator ) const
|
||||
{
|
||||
std::string result;
|
||||
bool isFirst = true;
|
||||
|
||||
for( int i = 0; i < GetParamCount(); ++i )
|
||||
{
|
||||
const PARAM& param = GetParam( i );
|
||||
|
||||
if( i == 0 && hasPrimaryValue() )
|
||||
{
|
||||
result.append( param.value->ToString() );
|
||||
isFirst = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( param.value->ToString() == "" )
|
||||
continue;
|
||||
|
||||
result.append( GenerateParamValuePair( param, isFirst ) );
|
||||
}
|
||||
|
||||
if( result == "" )
|
||||
result = GetDeviceTypeInfo().fieldValue;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string SIM_MODEL::GenerateParamsField( const std::string& aPairSeparator ) const
|
||||
{
|
||||
std::string result;
|
||||
|
@ -1185,13 +1219,12 @@ void SIM_MODEL::doReadDataFields( unsigned aSymbolPinCount, const std::vector<T>
|
|||
if( GetFieldValue( aFields, PARAMS_FIELD ) != "" )
|
||||
ParseParamsField( GetFieldValue( aFields, PARAMS_FIELD ) );
|
||||
else
|
||||
InferredReadDataFields( aSymbolPinCount, aFields, true );
|
||||
InferredReadDataFields( aSymbolPinCount, aFields );
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
||||
bool aAllowPrimaryValueWithoutName )
|
||||
void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields )
|
||||
{
|
||||
// TODO: Make a subclass SIM_MODEL_NONE.
|
||||
if( GetType() == SIM_MODEL::TYPE::NONE )
|
||||
|
@ -1219,7 +1252,7 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
|||
{
|
||||
if( node->is_type<SIM_MODEL_PARSER::fieldInferValuePrimaryValue>() )
|
||||
{
|
||||
if( aAllowPrimaryValueWithoutName )
|
||||
if( hasPrimaryValue() )
|
||||
{
|
||||
for( const auto& subnode : node->children )
|
||||
{
|
||||
|
@ -1250,13 +1283,6 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
|||
SetIsInferred( true );
|
||||
}
|
||||
|
||||
template void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount,
|
||||
const std::vector<SCH_FIELD>* aFields,
|
||||
bool aAllowOnlyFirstValue );
|
||||
template void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount,
|
||||
const std::vector<LIB_FIELD>* aFields,
|
||||
bool aAllowOnlyFirstValue );
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
|
||||
|
|
|
@ -621,10 +621,11 @@ protected:
|
|||
virtual void CreatePins( unsigned aSymbolPinCount );
|
||||
|
||||
template <typename T>
|
||||
void WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue ) const;
|
||||
void WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue = "" ) const;
|
||||
|
||||
virtual std::string GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
|
||||
|
||||
std::string GenerateValueField( const std::string& aPairSeparator ) const;
|
||||
std::string GenerateParamsField( const std::string& aPairSeparator ) const;
|
||||
void ParseParamsField( const std::string& aParamsField );
|
||||
|
||||
|
@ -632,8 +633,7 @@ protected:
|
|||
void ParseEnableField( const std::string& aDisabledField );
|
||||
|
||||
template <typename T>
|
||||
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
||||
bool aAllowPrimaryValueWithoutName = false );
|
||||
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
||||
std::vector<PARAM> m_params;
|
||||
const SIM_MODEL* m_baseModel;
|
||||
|
||||
|
@ -658,6 +658,7 @@ private:
|
|||
|
||||
std::string parseFieldFloatValue( std::string aFieldFloatValue );
|
||||
|
||||
virtual bool hasPrimaryValue() const { return false; }
|
||||
virtual bool requiresSpiceModelLine() const;
|
||||
|
||||
virtual std::vector<std::string> getPinNames() const { return {}; }
|
||||
|
|
|
@ -70,8 +70,7 @@ std::string SPICE_GENERATOR_BEHAVIORAL::ItemLine( const SPICE_ITEM& aItem ) cons
|
|||
|
||||
|
||||
SIM_MODEL_BEHAVIORAL::SIM_MODEL_BEHAVIORAL( TYPE aType ) :
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_BEHAVIORAL>( *this ) ),
|
||||
m_isInferred( false )
|
||||
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_BEHAVIORAL>( *this ) )
|
||||
{
|
||||
static PARAM::INFO resistor = makeParams( "r", "Expression for resistance", "Ω" );
|
||||
static PARAM::INFO capacitor = makeParams( "c", "Expression for capacitance", "F" );
|
||||
|
@ -116,7 +115,7 @@ void SIM_MODEL_BEHAVIORAL::WriteDataSchFields( std::vector<SCH_FIELD>& aFields )
|
|||
{
|
||||
SIM_MODEL::WriteDataSchFields( aFields );
|
||||
|
||||
if( m_isInferred )
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
}
|
||||
|
||||
|
@ -125,7 +124,7 @@ void SIM_MODEL_BEHAVIORAL::WriteDataLibFields( std::vector<LIB_FIELD>& aFields )
|
|||
{
|
||||
SIM_MODEL::WriteDataLibFields( aFields );
|
||||
|
||||
if( m_isInferred )
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
}
|
||||
|
||||
|
@ -157,7 +156,7 @@ void SIM_MODEL_BEHAVIORAL::inferredReadDataFields( unsigned aSymbolPinCount,
|
|||
// If Value is device type, this is an empty model
|
||||
|| GetFieldValue( aFields, VALUE_FIELD ) == DeviceTypeInfo( GetDeviceType() ).fieldValue )
|
||||
{
|
||||
m_isInferred = true;
|
||||
SetIsInferred( true );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,9 +65,6 @@ private:
|
|||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static PARAM::INFO makeParams( std::string aName, std::string aDescription, std::string aUnit );
|
||||
|
||||
|
||||
bool m_isInferred;
|
||||
};
|
||||
|
||||
#endif // SIM_MODEL_BEHAVIORAL_H
|
||||
|
|
|
@ -78,7 +78,7 @@ void SIM_MODEL_IDEAL::WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) cons
|
|||
SIM_MODEL::WriteDataSchFields( aFields );
|
||||
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
WriteInferredDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,19 +87,7 @@ void SIM_MODEL_IDEAL::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) cons
|
|||
SIM_MODEL::WriteDataLibFields( aFields );
|
||||
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL_IDEAL::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
std::string value = GetParam( 0 ).value->ToString();
|
||||
|
||||
if( value == "" )
|
||||
value = DeviceTypeInfo( GetDeviceType() ).fieldValue;
|
||||
|
||||
WriteInferredDataFields( aFields, value );
|
||||
WriteInferredDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
bool hasPrimaryValue() const override { return true; }
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static PARAM::INFO makeParamInfo( std::string aName, std::string aDescription, std::string aUnit );
|
||||
|
|
|
@ -45,7 +45,12 @@ std::string SPICE_GENERATOR_R_POT::ItemLine( const SPICE_ITEM& aItem ) const
|
|||
{
|
||||
// Swap pin order so that pos=1 is all +, and pos=0 is all -.
|
||||
SPICE_ITEM item = aItem;
|
||||
std::swap( item.pinNetNames[0], item.pinNetNames[2] );
|
||||
|
||||
// FIXME: This `if` is there because Preview() calls this function with empty pinNetNames vector.
|
||||
// This shouldn't be necessary.
|
||||
if( item.pinNetNames.size() >= 3 )
|
||||
std::swap( item.pinNetNames.at( 0 ), item.pinNetNames.at( 2 ) );
|
||||
|
||||
return SPICE_GENERATOR::ItemLine( item );
|
||||
}
|
||||
|
||||
|
@ -73,7 +78,7 @@ void SIM_MODEL_R_POT::WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) cons
|
|||
SIM_MODEL::WriteDataSchFields( aFields );
|
||||
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
WriteInferredDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,19 +87,7 @@ void SIM_MODEL_R_POT::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) cons
|
|||
SIM_MODEL::WriteDataLibFields( aFields );
|
||||
|
||||
if( IsInferred() )
|
||||
inferredWriteDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL_R_POT::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
std::string value = GetFieldValue( &aFields, PARAMS_FIELD );
|
||||
|
||||
if( value == "" )
|
||||
value = GetDeviceTypeInfo().fieldValue;
|
||||
|
||||
WriteInferredDataFields( aFields, value );
|
||||
WriteInferredDataFields( aFields );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "wiper", "-" }; }
|
||||
bool hasPrimaryValue() const override { return true; }
|
||||
|
||||
static const std::vector<PARAM::INFO> makeParamInfos();
|
||||
};
|
||||
|
|
|
@ -77,6 +77,8 @@ private:
|
|||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
|
||||
bool hasPrimaryValue() const override { return true; }
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static const std::vector<PARAM::INFO>& makeParamInfos( TYPE aType );
|
||||
|
|
Loading…
Reference in New Issue