From e39c0b20ea3b66b411b7834fba5c3a488e7357fe Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 30 Nov 2022 12:40:50 +0100 Subject: [PATCH] Sim: Universally initialize enum parameters with their default values --- eeschema/sim/sim_model.cpp | 4 ++++ eeschema/sim/sim_model_switch.cpp | 16 ++-------------- eeschema/sim/sim_model_switch.h | 10 ---------- eeschema/sim/sim_serde.cpp | 4 ++++ 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index cac434672c..d5eafc3818 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -650,6 +650,10 @@ int SIM_MODEL::FindModelPinIndex( const std::string& aSymbolPinNumber ) void SIM_MODEL::AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant ) { m_params.emplace_back( aInfo, aIsOtherVariant ); + + // Enums are initialized with their default values. + if( aInfo.enumValues.size() >= 1 ) + m_params.back().value->FromString( aInfo.defaultValue ); } diff --git a/eeschema/sim/sim_model_switch.cpp b/eeschema/sim/sim_model_switch.cpp index 85efef31c1..b23ffe1dac 100644 --- a/eeschema/sim/sim_model_switch.cpp +++ b/eeschema/sim/sim_model_switch.cpp @@ -94,19 +94,9 @@ std::vector> SPICE_GENERATOR_SWITCH } -std::string SIM_SERDE_SWITCH::GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const -{ - if( aParam.info.name == "ic" && aParam.value->ToString() == "none" ) - return ""; - - return SIM_SERDE::GenerateParamValuePair( aParam ); -} - - SIM_MODEL_SWITCH::SIM_MODEL_SWITCH( TYPE aType ) : SIM_MODEL( aType, - std::make_unique( *this ), - std::make_unique( *this ) ) + std::make_unique( *this ) ) { static std::vector vsw = makeSwVParamInfos(); static std::vector isw = makeSwIParamInfos(); @@ -127,8 +117,6 @@ SIM_MODEL_SWITCH::SIM_MODEL_SWITCH( TYPE aType ) : wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_SWITCH" ); break; } - - SetParamValue( "ic", "none" ); } @@ -185,7 +173,7 @@ const std::vector SIM_MODEL_SWITCH::makeSwVParamInfos() paramInfo.type = SIM_VALUE::TYPE_STRING; paramInfo.unit = ""; paramInfo.category = PARAM::CATEGORY::PRINCIPAL; - paramInfo.defaultValue = "1"; + paramInfo.defaultValue = "none"; paramInfo.description = "Initial state"; paramInfo.isSpiceInstanceParam = true; paramInfo.spiceModelName = ""; diff --git a/eeschema/sim/sim_model_switch.h b/eeschema/sim/sim_model_switch.h index 1158c77bc8..0120f55acc 100644 --- a/eeschema/sim/sim_model_switch.h +++ b/eeschema/sim/sim_model_switch.h @@ -41,16 +41,6 @@ public: }; -class SIM_SERDE_SWITCH : public SIM_SERDE -{ -public: - using SIM_SERDE::SIM_SERDE; - -protected: - std::string GenerateParamValuePair( const SIM_MODEL::PARAM& aParam ) const override; -}; - - class SIM_MODEL_SWITCH : public SIM_MODEL { public: diff --git a/eeschema/sim/sim_serde.cpp b/eeschema/sim/sim_serde.cpp index 4516ee783a..16bb564b94 100644 --- a/eeschema/sim/sim_serde.cpp +++ b/eeschema/sim/sim_serde.cpp @@ -94,6 +94,10 @@ std::string SIM_SERDE::GenerateParams() const continue; } + // If the parameter is an enum and the value is default, don't write anything. + if( param.info.enumValues.size() >= 1 && param.value->ToString() == param.info.defaultValue ) + continue; + std::string paramValuePair = GenerateParamValuePair( param ); if( paramValuePair == "" )