From f5edcf82f231b221519e16e23ad02902f5238170 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 1 Mar 2023 13:30:22 +0000 Subject: [PATCH] Move only-write-model-if-it-contains-overrides up to base class. It's necessary to keep us from writing out model lines for included models and fall-backs of included models. --- eeschema/sim/sim_model.cpp | 31 ++++++++++++++++++++++--- eeschema/sim/sim_model_ngspice.cpp | 37 ------------------------------ eeschema/sim/sim_model_ngspice.h | 2 -- eeschema/sim/sim_model_subckt.h | 2 -- eeschema/sim/spice_generator.cpp | 3 +-- 5 files changed, 29 insertions(+), 46 deletions(-) diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index 474909dbe6..fede1ecb4b 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -1064,10 +1064,35 @@ void SIM_MODEL::doWriteFields( std::vector& aFields ) const bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const { - for( const PARAM& param : GetParams() ) + // Model must be written if there's no base model or the base model is an internal model + if( !m_baseModel || aItem.baseModelName == "" ) + return true; + + for( int ii = 0; ii < GetParamCount(); ++ii ) { - if( !param.info.isSpiceInstanceParam ) - return true; + const PARAM& param = m_params[ii]; + + // Instance parameters are written in item lines + if( param.info.isSpiceInstanceParam ) + continue; + + // Empty parameters are interpreted as default-value + if ( param.value == "" ) + continue; + + const SIM_MODEL* baseModel = dynamic_cast( m_baseModel ); + std::string baseValue = baseModel->m_params[ii].value; + + if( param.value == baseValue ) + continue; + + // One more check for equivalence, mostly for early 7.0 files which wrote all parameters + // to the Sim.Params field in normalized format + if( param.value == SIM_VALUE::Normalize( SIM_VALUE::ToDouble( baseValue ) ) ) + continue; + + // Overrides must be written + return true; } return false; diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index 6d29232ee1..663bac8a7f 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -215,43 +215,6 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName ) } -bool SIM_MODEL_NGSPICE::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const -{ - // Model must be written if there's no base model or the base model is an internal model - if( !m_baseModel || aItem.baseModelName == "" ) - return true; - - for( int ii = 0; ii < GetParamCount(); ++ii ) - { - const PARAM& param = m_params[ii]; - - // Instance parameters are written in item lines - if( param.info.isSpiceInstanceParam ) - continue; - - // Empty parameters are interpreted as default-value - if ( param.value == "" ) - continue; - - const SIM_MODEL_NGSPICE* baseModel = dynamic_cast( m_baseModel ); - std::string baseValue = baseModel->m_params[ii].value; - - if( param.value == baseValue ) - continue; - - // One more check for equivalence, mostly for early 7.0 files which wrote all parameters - // to the Sim.Params field in normalized format - if( param.value == SIM_VALUE::Normalize( SIM_VALUE::ToDouble( baseValue ) ) ) - continue; - - // Overrides must be written - 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 deb39f10df..0683580c8c 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -109,8 +109,6 @@ protected: int doFindParam( const std::string& aParamName ) const override; private: - bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override; - bool canSilentlyIgnoreParam( const std::string& aParamName ); MODEL_TYPE getModelType() const; diff --git a/eeschema/sim/sim_model_subckt.h b/eeschema/sim/sim_model_subckt.h index e0d8515144..b38c2d217a 100644 --- a/eeschema/sim/sim_model_subckt.h +++ b/eeschema/sim/sim_model_subckt.h @@ -60,8 +60,6 @@ public: std::string GetSpiceCode() const; private: - bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return true; } - std::vector> m_paramInfos; }; diff --git a/eeschema/sim/spice_generator.cpp b/eeschema/sim/spice_generator.cpp index 3add2bed00..54d36be732 100644 --- a/eeschema/sim/spice_generator.cpp +++ b/eeschema/sim/spice_generator.cpp @@ -34,8 +34,7 @@ std::string SPICE_GENERATOR::ModelName( const SPICE_ITEM& aItem ) const if( aItem.baseModelName == "" ) return fmt::format( "__{}", aItem.refName ); - // FIXME: This ModelLine() call is relatively expensive. - if( ModelLine( aItem ) != "" ) + if( m_model.requiresSpiceModelLine( aItem ) ) return fmt::format( "{}.{}", aItem.refName, aItem.baseModelName ); return aItem.baseModelName;