More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....More bug fixes for escaped model parameters.

Note that this whole escaping thing seems like a bad idea to me, but
I don't fully understand the difference between model parameters and
instance parameters so I don't know if there's a better way to handle
it or not....

Fixes https://gitlab.com/kicad/code/kicad/issues/13179
This commit is contained in:
Jeff Young 2022-12-16 16:31:39 +00:00
parent 08a8a20794
commit dba3c589d0
3 changed files with 43 additions and 12 deletions

View File

@ -579,7 +579,8 @@ std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const std::
// This specialization is used when no fields are passed.
template <>
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const std::string& aFieldName )
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields,
const std::string& aFieldName )
{
return "";
}
@ -727,14 +728,28 @@ const SIM_MODEL::PARAM& SIM_MODEL::GetParam( unsigned aParamIndex ) const
const SIM_MODEL::PARAM* SIM_MODEL::FindParam( const std::string& aParamName ) const
{
std::string lowerParamName = boost::to_lower_copy( aParamName );
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
auto it = std::find_if( params.begin(), params.end(),
[aParamName]( const PARAM& param )
[lowerParamName]( const PARAM& param )
{
return param.info.name == boost::to_lower_copy( aParamName );
return param.info.name == lowerParamName;
} );
// Also check for model params that had to be escaped due to collisions with instance
// params.
if( it == params.end() )
{
it = std::find_if( params.begin(), params.end(),
[lowerParamName]( const PARAM& param )
{
return param.info.name == lowerParamName + "_";
} );
}
if( it == params.end() )
return nullptr;
@ -784,14 +799,28 @@ void SIM_MODEL::SetParamValue( int aParamIndex, const std::string& aValue,
void SIM_MODEL::SetParamValue( const std::string& aParamName, const SIM_VALUE& aValue )
{
std::string lowerParamName = boost::to_lower_copy( aParamName );
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
auto it = std::find_if( params.begin(), params.end(),
[aParamName]( const PARAM& param )
[lowerParamName]( const PARAM& param )
{
return param.info.name == boost::to_lower_copy( aParamName );
return param.info.name == lowerParamName;
} );
// Also check for model params that had to be escaped due to collisions with instance
// params.
if( it == params.end() )
{
it = std::find_if( params.begin(), params.end(),
[lowerParamName]( const PARAM& param )
{
return param.info.name == lowerParamName + "_";
} );
}
if( it == params.end() )
{
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in "

View File

@ -95,15 +95,17 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName,
// First we try to use the name as is. Note that you can't set instance parameters from this
// function, it's for ".model" cards, not for instantiations.
std::string lowerParamName = boost::to_lower_copy( paramName );
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
auto paramIt = std::find_if( params.begin(), params.end(),
[paramName]( const PARAM& param )
[lowerParamName]( const PARAM& param )
{
return !param.info.isSpiceInstanceParam
&& param.info.category != PARAM::CATEGORY::SUPERFLUOUS
&& ( param.info.name == boost::to_lower_copy( paramName )
|| param.info.name == boost::to_lower_copy( paramName ) + "_" );
&& ( param.info.name == lowerParamName
|| param.info.name == lowerParamName + "_" );
} );
if( paramIt != params.end() )
@ -118,11 +120,11 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName,
std::vector<PARAM::INFO> ngspiceParams = ModelInfo( getModelType() ).modelParams;
auto ngspiceParamIt = std::find_if( ngspiceParams.begin(), ngspiceParams.end(),
[paramName]( const PARAM& param )
[lowerParamName]( const PARAM& param )
{
// Now we search without excluding Spice instance
// parameters and superfluous parameters.
return param.info.name == boost::to_lower_copy( paramName );
return param.info.name == lowerParamName;
} );
if( ngspiceParamIt == ngspiceParams.end() )

View File

@ -161,8 +161,8 @@ std::string SPICE_GENERATOR::ItemParams() const
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
{
std::string name = ( param.info.spiceInstanceName == "" ) ?
param.info.name : param.info.spiceInstanceName;
std::string name = param.info.spiceInstanceName.empty() ? param.info.name
: param.info.spiceInstanceName;
std::string value = param.value->ToSpiceString();
if( value != "" )