From 5abe1a201b0ed4cb4ae480257dc42367758fa39c Mon Sep 17 00:00:00 2001 From: Graham Keeth Date: Fri, 3 Feb 2023 12:19:30 -0500 Subject: [PATCH] spice: generate .model lines for all device types - generate .model lines in spice netlist for all device types that need one - add "level=" to .model line for non-default model levels. This is necessary to allow more sophisticated models to be used, and some devices *always* need a level specified (e.g. JFETs) - add "version=" to .model line for models that have multiple versions available (AFAIK only affects HiSIM_HV MOSFET models) Fixes: https://gitlab.com/kicad/code/kicad/-/issues/13775 --- eeschema/sim/sim_model_ngspice.h | 2 +- eeschema/sim/spice_generator.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/eeschema/sim/sim_model_ngspice.h b/eeschema/sim/sim_model_ngspice.h index 4998350270..5348334655 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -111,7 +111,7 @@ protected: private: bool requiresSpiceModelLine() const override { - return getModelType() == MODEL_TYPE::DIODE; + return getModelType() != MODEL_TYPE::NONE; } bool canSilentlyIgnoreParam( const std::string& aParamName ); diff --git a/eeschema/sim/spice_generator.cpp b/eeschema/sim/spice_generator.cpp index bc9cf69f6d..5041385539 100644 --- a/eeschema/sim/spice_generator.cpp +++ b/eeschema/sim/spice_generator.cpp @@ -52,7 +52,16 @@ std::string SPICE_GENERATOR::ModelLine( const SPICE_ITEM& aItem ) const result.append( fmt::format( ".model {} ", aItem.modelName ) ); size_t indentLength = result.length(); - result.append( fmt::format( "{}\n", m_model.GetSpiceInfo().modelType ) ); + SIM_MODEL::SPICE_INFO spiceInfo = m_model.GetSpiceInfo(); + result.append( spiceInfo.modelType ); + + if ( !spiceInfo.isDefaultLevel && !spiceInfo.level.empty() ) + result.append( fmt::format( " level={}", spiceInfo.level ) ); + + if ( !spiceInfo.version.empty() ) + result.append( fmt::format( " version={}", spiceInfo.version ) ); + + result.append( "\n" ); for( const SIM_MODEL::PARAM& param : m_model.GetParams() ) {