diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 7bd1aeea11..fb3bfdf722 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -284,6 +284,7 @@ set( EESCHEMA_SRCS sim/sim_lib_mgr.cpp sim/sim_model.cpp sim/sim_model_behavioral.cpp + sim/sim_model_diode.cpp sim/sim_model_ideal.cpp sim/sim_model_mutual_inductor.cpp sim/sim_model_kibis.cpp diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index a8083e0039..52cfe92dba 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -915,6 +916,9 @@ std::unique_ptr SIM_MODEL::Create( TYPE aType ) case TYPE::SW_I: return std::make_unique( aType ); + case TYPE::D: + return std::make_unique(); + case TYPE::V: case TYPE::I: case TYPE::V_SIN: diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index 3d9d271964..f2a118a38c 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -48,12 +48,6 @@ std::vector SPICE_GENERATOR_NGSPICE::CurrentNames( const SPICE_ITEM fmt::format( "I({}:g)", aItem.refName ), fmt::format( "I({}:s)", aItem.refName ) }; - case SIM_MODEL::DEVICE_TYPE_::R: - case SIM_MODEL::DEVICE_TYPE_::C: - case SIM_MODEL::DEVICE_TYPE_::L: - case SIM_MODEL::DEVICE_TYPE_::D: - return SPICE_GENERATOR::CurrentNames( aItem ); - default: wxFAIL_MSG( "Unhandled model device type in SIM_MODEL_NGSPICE" ); return {}; @@ -62,22 +56,8 @@ std::vector SPICE_GENERATOR_NGSPICE::CurrentNames( const SPICE_ITEM SIM_MODEL_NGSPICE::SIM_MODEL_NGSPICE( TYPE aType ) : - SIM_MODEL_SPICE( aType, std::make_unique( *this ) ) + SIM_MODEL_NGSPICE( aType, std::make_unique( *this ) ) { - const MODEL_INFO& modelInfo = ModelInfo( getModelType() ); - - for( const SIM_MODEL::PARAM::INFO& paramInfo : modelInfo.instanceParams ) - { - // For now, only the geometry parameters. - if( paramInfo.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL - || paramInfo.category == SIM_MODEL::PARAM::CATEGORY::GEOMETRY ) - { - AddParam( paramInfo, getIsOtherVariant() ); - } - } - - for( const SIM_MODEL::PARAM::INFO& paramInfo : modelInfo.modelParams ) - AddParam( paramInfo, getIsOtherVariant() ); } @@ -161,6 +141,27 @@ void SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName, } +SIM_MODEL_NGSPICE::SIM_MODEL_NGSPICE( TYPE aType, + std::unique_ptr aSpiceGenerator ) : + SIM_MODEL_SPICE( aType, std::move( aSpiceGenerator ) ) +{ + const MODEL_INFO& modelInfo = ModelInfo( getModelType() ); + + for( const SIM_MODEL::PARAM::INFO& paramInfo : modelInfo.instanceParams ) + { + // For now, only the geometry parameters. + if( paramInfo.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL + || paramInfo.category == SIM_MODEL::PARAM::CATEGORY::GEOMETRY ) + { + AddParam( paramInfo, getIsOtherVariant() ); + } + } + + for( const SIM_MODEL::PARAM::INFO& paramInfo : modelInfo.modelParams ) + AddParam( paramInfo, getIsOtherVariant() ); +} + + bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName ) { // Ignore the purely informative LTspice-specific parameters "mfg" and "type". diff --git a/eeschema/sim/sim_model_ngspice.h b/eeschema/sim/sim_model_ngspice.h index 5bef7bbf95..249553560e 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -103,6 +103,8 @@ protected: static const MODEL_INFO& ModelInfo( MODEL_TYPE aType ); + SIM_MODEL_NGSPICE( TYPE aType, std::unique_ptr aSpiceGenerator ); + private: bool requiresSpiceModelLine() const override { return false; } diff --git a/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch b/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch index c9c713ff2e..7badfc6ad8 100644 --- a/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch +++ b/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch @@ -185,11 +185,11 @@ (effects (font (size 1.27 1.27)) hide) ) (symbol "VSIN_0_0" - (arc (start 0 0) (mid -0.635 0.635) (end -1.27 0) + (arc (start 0 0) (mid -0.635 0.6323) (end -1.27 0) (stroke (width 0) (type default)) (fill (type none)) ) - (arc (start 0 0) (mid 0.635 -0.635) (end 1.27 0) + (arc (start 0 0) (mid 0.635 -0.6323) (end 1.27 0) (stroke (width 0) (type default)) (fill (type none)) ) @@ -400,7 +400,7 @@ (property "Datasheet" "~" (at 151.765 96.52 0) (effects (font (size 1.27 1.27)) hide) ) - (property "Sim_Device" "DIODE" (at 151.765 96.52 0) + (property "Sim_Device" "D" (at 151.765 96.52 0) (effects (font (size 1.27 1.27)) hide) ) (property "Sim_Name" "DIODE1" (at 151.765 96.52 0) @@ -409,9 +409,6 @@ (property "Sim_Library" "diode.lib" (at 151.765 96.52 0) (effects (font (size 1.27 1.27)) hide) ) - (property "Sim_Pins" "2 1" (at 151.765 96.52 0) - (effects (font (size 1.27 1.27)) hide) - ) (pin "1" (uuid cb1986eb-8b78-41be-ab05-5001090a2a65)) (pin "2" (uuid edfbe61b-6d1d-45a6-bfef-e48a694e79db)) (instances