diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index 9332d71a17..266dbd4b71 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -883,42 +883,6 @@ void SIM_MODEL::SetParamValue( const std::string& aParamName, const std::string& } -bool SIM_MODEL::HasOverrides() const -{ - for( const PARAM& param : m_params ) - { - if( param.value != "" ) - return true; - } - - return false; -} - - -bool SIM_MODEL::HasNonInstanceOverrides() const -{ - for( const PARAM& param : m_params ) - { - if( !param.info.isInstanceParam && param.value != "" ) - return true; - } - - return false; -} - - -bool SIM_MODEL::HasSpiceNonInstanceOverrides() const -{ - for( const PARAM& param : m_params ) - { - if( !param.info.isSpiceInstanceParam && param.value != "" ) - return true; - } - - return false; -} - - std::unique_ptr SIM_MODEL::Create( TYPE aType ) { switch( aType ) diff --git a/eeschema/sim/sim_model.h b/eeschema/sim/sim_model.h index e1e00b40e2..9d5e75ed0e 100644 --- a/eeschema/sim/sim_model.h +++ b/eeschema/sim/sim_model.h @@ -480,10 +480,6 @@ public: void SetParamValue( const std::string& aParamName, const std::string& aValue, SIM_VALUE::NOTATION aNotation = SIM_VALUE::NOTATION::SI ); - bool HasOverrides() const; - bool HasNonInstanceOverrides() const; - bool HasSpiceNonInstanceOverrides() const; - // Can modifying a model parameter also modify other parameters? virtual bool HasAutofill() const { return false; } virtual bool HasPrimaryValue() const { return false; } diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index 6dfdbf307e..2d1a31adde 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -215,6 +215,43 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName ) } +bool SIM_MODEL_NGSPICE::requiresSpiceModelLine() const +{ + 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; + + // Any non-empty parameter must be written if there's no base model + if( !m_baseModel ) + return true; + + 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; @@ -289,41 +326,3 @@ SIM_MODEL_NGSPICE::MODEL_TYPE SIM_MODEL_NGSPICE::getModelType() const return MODEL_TYPE::NONE; } } - - -bool SIM_MODEL_NGSPICE::getIsOtherVariant() -{ - switch( GetType() ) - { - case TYPE::PNP_GUMMELPOON: - case TYPE::PNP_VBIC: - case TYPE::PNP_HICUM2: - case TYPE::PJFET_SHICHMANHODGES: - case TYPE::PJFET_PARKERSKELLERN: - case TYPE::PMES_STATZ: - case TYPE::PMES_YTTERDAL: - case TYPE::PMES_HFET1: - case TYPE::PMES_HFET2: - case TYPE::PMOS_VDMOS: - case TYPE::PMOS_MOS1: - case TYPE::PMOS_MOS2: - case TYPE::PMOS_MOS3: - case TYPE::PMOS_BSIM1: - case TYPE::PMOS_BSIM2: - case TYPE::PMOS_MOS6: - case TYPE::PMOS_BSIM3: - case TYPE::PMOS_MOS9: - case TYPE::PMOS_B4SOI: - case TYPE::PMOS_BSIM4: - case TYPE::PMOS_B3SOIFD: - case TYPE::PMOS_B3SOIDD: - case TYPE::PMOS_B3SOIPD: - case TYPE::PMOS_HISIM2: - case TYPE::PMOS_HISIMHV1: - case TYPE::PMOS_HISIMHV2: - return true; - - default: - return false; - } -} diff --git a/eeschema/sim/sim_model_ngspice.h b/eeschema/sim/sim_model_ngspice.h index 5348334655..e41fa1143d 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2022 Mikolaj Wielgus - * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -109,15 +109,11 @@ protected: int doFindParam( const std::string& aParamName ) const override; private: - bool requiresSpiceModelLine() const override - { - return getModelType() != MODEL_TYPE::NONE; - } + bool requiresSpiceModelLine() const override; bool canSilentlyIgnoreParam( const std::string& aParamName ); MODEL_TYPE getModelType() const; - bool getIsOtherVariant(); }; #endif /* SIM_MODEL_NGSPICE_H */ diff --git a/eeschema/sim/spice_generator.cpp b/eeschema/sim/spice_generator.cpp index 96361be4bf..2e952f10a1 100644 --- a/eeschema/sim/spice_generator.cpp +++ b/eeschema/sim/spice_generator.cpp @@ -44,7 +44,7 @@ std::string SPICE_GENERATOR::ModelName( const SPICE_ITEM& aItem ) const std::string SPICE_GENERATOR::ModelLine( const SPICE_ITEM& aItem ) const { - if( !m_model.HasSpiceNonInstanceOverrides() && !m_model.requiresSpiceModelLine() ) + if( !m_model.requiresSpiceModelLine() ) return ""; std::string result;