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:
parent
08a8a20794
commit
dba3c589d0
|
@ -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.
|
// This specialization is used when no fields are passed.
|
||||||
template <>
|
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 "";
|
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
|
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();
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
||||||
|
|
||||||
auto it = std::find_if( params.begin(), params.end(),
|
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() )
|
if( it == params.end() )
|
||||||
return nullptr;
|
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 )
|
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();
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
||||||
|
|
||||||
auto it = std::find_if( params.begin(), params.end(),
|
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() )
|
if( it == params.end() )
|
||||||
{
|
{
|
||||||
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in "
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in "
|
||||||
|
|
|
@ -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
|
// 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.
|
// 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();
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
||||||
|
|
||||||
auto paramIt = std::find_if( params.begin(), params.end(),
|
auto paramIt = std::find_if( params.begin(), params.end(),
|
||||||
[paramName]( const PARAM& param )
|
[lowerParamName]( const PARAM& param )
|
||||||
{
|
{
|
||||||
return !param.info.isSpiceInstanceParam
|
return !param.info.isSpiceInstanceParam
|
||||||
&& param.info.category != PARAM::CATEGORY::SUPERFLUOUS
|
&& param.info.category != PARAM::CATEGORY::SUPERFLUOUS
|
||||||
&& ( param.info.name == boost::to_lower_copy( paramName )
|
&& ( param.info.name == lowerParamName
|
||||||
|| param.info.name == boost::to_lower_copy( paramName ) + "_" );
|
|| param.info.name == lowerParamName + "_" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if( paramIt != params.end() )
|
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;
|
std::vector<PARAM::INFO> ngspiceParams = ModelInfo( getModelType() ).modelParams;
|
||||||
|
|
||||||
auto ngspiceParamIt = std::find_if( ngspiceParams.begin(), ngspiceParams.end(),
|
auto ngspiceParamIt = std::find_if( ngspiceParams.begin(), ngspiceParams.end(),
|
||||||
[paramName]( const PARAM& param )
|
[lowerParamName]( const PARAM& param )
|
||||||
{
|
{
|
||||||
// Now we search without excluding Spice instance
|
// Now we search without excluding Spice instance
|
||||||
// parameters and superfluous parameters.
|
// parameters and superfluous parameters.
|
||||||
return param.info.name == boost::to_lower_copy( paramName );
|
return param.info.name == lowerParamName;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if( ngspiceParamIt == ngspiceParams.end() )
|
if( ngspiceParamIt == ngspiceParams.end() )
|
||||||
|
|
|
@ -161,8 +161,8 @@ std::string SPICE_GENERATOR::ItemParams() const
|
||||||
|
|
||||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||||
{
|
{
|
||||||
std::string name = ( param.info.spiceInstanceName == "" ) ?
|
std::string name = param.info.spiceInstanceName.empty() ? param.info.name
|
||||||
param.info.name : param.info.spiceInstanceName;
|
: param.info.spiceInstanceName;
|
||||||
std::string value = param.value->ToSpiceString();
|
std::string value = param.value->ToSpiceString();
|
||||||
|
|
||||||
if( value != "" )
|
if( value != "" )
|
||||||
|
|
Loading…
Reference in New Issue