diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index 374e1e9593..2bbbb26f49 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -92,27 +92,8 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName, if( paramName == "level" || paramName == "version" ) return; - // Ignore the purely informative LTspice-specific parameters "mfg" and "type". - if( paramName == "mfg" || paramName == "type" ) - return; - - if( GetDeviceType() == DEVICE_TYPE_::NPN || GetDeviceType() == DEVICE_TYPE_::PNP ) - { - // Ignore the purely informative LTspice-specific parameters "icrating" and "vceo". - if( paramName == "icrating" || paramName == "vceo" ) - return; - - // Ignore unused parameters. - if( paramName == "bvcbo" || paramName == "nbvcbo" - || paramName == "tbvcbo1" || paramName == "tbvcbo2" - || paramName == "bvbe" || paramName == "ibvbe" || paramName == "nbvbe" ) - { - return; - } - } - // First we try to use the name as is. Note that you can't set instance parameters from this - // function, it's generally for ".model" cards, not for instantiations. + // function, it's for ".model" cards, not for instantiations. std::vector> params = GetParams(); @@ -139,25 +120,34 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName, auto ngspiceParamIt = std::find_if( ngspiceParams.begin(), ngspiceParams.end(), [paramName]( const PARAM& param ) { + // Now we search without excluding Spice instance + // parameters and superfluous parameters. return param.info.name == boost::to_lower_copy( paramName ); } ); if( ngspiceParamIt == ngspiceParams.end() ) { + if( canSilentlyIgnoreParam( paramName ) ) + return; + THROW_IO_ERROR( wxString::Format( "Failed to set parameter '%s' to value '%s'", aParamName, aParamValue ) ); } - // We obtain the id of the Ngspice param that is to be set. + // We obtain the id of the Ngspice param that is to be set. We use this id to address the + // parameter to be set here because a superfluous parameter may be an alias: this will + // dereference it. unsigned id = ngspiceParamIt->id; // Find an actual parameter with the same id. paramIt = std::find_if( params.begin(), params.end(), [id]( const PARAM& param ) { - return param.info.id == id; + // Look for any non-superfluous parameter with the same id. + return param.info.id == id + && param.info.category != PARAM::CATEGORY::SUPERFLUOUS; } ); if( paramIt == params.end() ) @@ -171,6 +161,50 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName, } +bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName ) +{ + // Ignore the purely informative LTspice-specific parameters "mfg" and "type". + if( aParamName == "mfg" || aParamName == "type" ) + return true; + + if( GetDeviceType() == DEVICE_TYPE_::D ) + { + if( aParamName == "perim" + || aParamName == "isw" + || aParamName == "ns" + || aParamName == "rsw" + || aParamName == "cjsw" + || aParamName == "vjsw" + || aParamName == "mjsw" + || aParamName == "fcs" ) + { + return true; + } + } + + if( GetDeviceType() == DEVICE_TYPE_::NPN || GetDeviceType() == DEVICE_TYPE_::PNP ) + { + // Ignore the purely informative LTspice-specific parameters "icrating" and "vceo". + if( aParamName == "icrating" || aParamName == "vceo" ) + return true; + + // Ignore unused parameters. + if( aParamName == "bvcbo" + || aParamName == "nbvcbo" + || aParamName == "tbvcbo1" + || aParamName == "tbvcbo2" + || aParamName == "bvbe" + || aParamName == "ibvbe" + || aParamName == "nbvbe" ) + { + return true; + } + } + + return false; +} + + std::vector SIM_MODEL_NGSPICE::getPinNames() const { return ModelInfo( getModelType() ).pinNames; diff --git a/eeschema/sim/sim_model_ngspice.h b/eeschema/sim/sim_model_ngspice.h index 29913bd8d6..5bef7bbf95 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -106,6 +106,8 @@ protected: private: bool requiresSpiceModelLine() const override { return false; } + bool canSilentlyIgnoreParam( const std::string& aParamName ); + std::vector getPinNames() const override; MODEL_TYPE getModelType() const;