From 5eca8dd8de9a56b7d3b35c70051a99263d7543e0 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 30 Oct 2022 11:01:59 +0100 Subject: [PATCH] Undo hardcoding swapping of diode pins Revert commits d1e2acd3 70b4d1aa cff508fb --- eeschema/CMakeLists.txt | 1 - eeschema/sim/sim_model.cpp | 4 -- eeschema/sim/sim_model_diode.cpp | 50 ------------------- eeschema/sim/sim_model_diode.h | 47 ----------------- eeschema/sim/sim_model_ngspice.cpp | 43 ++++++++-------- eeschema/sim/sim_model_ngspice.h | 2 - eeschema/sim/sim_model_ngspice_data.cpp | 2 +- .../rectifier/rectifier.kicad_sch | 9 ++-- 8 files changed, 28 insertions(+), 130 deletions(-) delete mode 100644 eeschema/sim/sim_model_diode.cpp delete mode 100644 eeschema/sim/sim_model_diode.h diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index fb3bfdf722..7bd1aeea11 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -284,7 +284,6 @@ 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 52cfe92dba..a8083e0039 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -916,9 +915,6 @@ 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_diode.cpp b/eeschema/sim/sim_model_diode.cpp deleted file mode 100644 index 48e6401ec1..0000000000 --- a/eeschema/sim/sim_model_diode.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * https://www.gnu.org/licenses/gpl-3.0.html - * or you may search the http://www.gnu.org website for the version 3 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include - - -std::string SPICE_GENERATOR_DIODE::ItemLine( const SPICE_ITEM& aItem ) const -{ - SPICE_ITEM item = aItem; - - // FIXME: This `if` is there because Preview() calls this function with empty pinNetNames vector. - // This shouldn't be necessary. - if( item.pinNetNames.size() >= 2 ) - std::swap( item.pinNetNames.at( 0 ), item.pinNetNames.at( 1 ) ); - - return SPICE_GENERATOR::ItemLine( item ); -} - - -std::vector SPICE_GENERATOR_DIODE::CurrentNames( const SPICE_ITEM& aItem ) const -{ - return SPICE_GENERATOR::CurrentNames( aItem ); // NOLINT -} - - -SIM_MODEL_DIODE::SIM_MODEL_DIODE() : - SIM_MODEL_NGSPICE( TYPE::D, std::make_unique( *this ) ) -{ -} diff --git a/eeschema/sim/sim_model_diode.h b/eeschema/sim/sim_model_diode.h deleted file mode 100644 index 911947b5b2..0000000000 --- a/eeschema/sim/sim_model_diode.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 3 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * https://www.gnu.org/licenses/gpl-3.0.html - * or you may search the http://www.gnu.org website for the version 3 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef SIM_MODEL_DIODE_H -#define SIM_MODEL_DIODE_H - -#include - - -class SPICE_GENERATOR_DIODE : public SPICE_GENERATOR_NGSPICE -{ -public: - using SPICE_GENERATOR_NGSPICE::SPICE_GENERATOR_NGSPICE; - - std::string ItemLine( const SPICE_ITEM& aItem ) const override; - std::vector CurrentNames( const SPICE_ITEM& aItem ) const override; -}; - - -class SIM_MODEL_DIODE : public SIM_MODEL_NGSPICE -{ -public: - SIM_MODEL_DIODE(); -}; - -#endif // SIM_MODEL_DIODE_H diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index f2a118a38c..3d9d271964 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -48,6 +48,12 @@ 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 {}; @@ -56,8 +62,22 @@ std::vector SPICE_GENERATOR_NGSPICE::CurrentNames( const SPICE_ITEM SIM_MODEL_NGSPICE::SIM_MODEL_NGSPICE( TYPE aType ) : - SIM_MODEL_NGSPICE( aType, std::make_unique( *this ) ) + SIM_MODEL_SPICE( 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() ); } @@ -141,27 +161,6 @@ 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 249553560e..5bef7bbf95 100644 --- a/eeschema/sim/sim_model_ngspice.h +++ b/eeschema/sim/sim_model_ngspice.h @@ -103,8 +103,6 @@ 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/eeschema/sim/sim_model_ngspice_data.cpp b/eeschema/sim/sim_model_ngspice_data.cpp index ad2609223a..c83a278d19 100644 --- a/eeschema/sim/sim_model_ngspice_data.cpp +++ b/eeschema/sim/sim_model_ngspice_data.cpp @@ -105,7 +105,7 @@ struct MODEL_INFO_MAP modelInfos[MODEL_TYPE::CSWITCH].instanceParams.emplace_back( "p", 7, SIM_MODEL::PARAM::DIR_OUT, SIM_VALUE::TYPE_FLOAT, SIM_MODEL::PARAM::FLAGS(), "", SIM_MODEL::PARAM::CATEGORY::SUPERFLUOUS, "", "", "Instantaneous power", true );*/ - modelInfos[MODEL_TYPE::DIODE] = { "Diode", "D", "", { "Cathode", "Anode" }, "Junction Diode model", {}, {} }; + modelInfos[MODEL_TYPE::DIODE] = { "Diode", "D", "", { "Anode", "Cathode" }, "Junction Diode model", {}, {} }; // Model parameters modelInfos[MODEL_TYPE::DIODE].modelParams.emplace_back( "level", 100, SIM_MODEL::PARAM::DIR_INOUT, SIM_VALUE::TYPE_INT, SIM_MODEL::PARAM::FLAGS(), "", SIM_MODEL::PARAM::CATEGORY::SUPERFLUOUS, "1", "", "Diode level selector" ); modelInfos[MODEL_TYPE::DIODE].modelParams.emplace_back( "is", 101, SIM_MODEL::PARAM::DIR_INOUT, SIM_VALUE::TYPE_FLOAT, SIM_MODEL::PARAM::FLAGS(), "A", SIM_MODEL::PARAM::CATEGORY::DC, "1e-14", "", "Saturation current" ); diff --git a/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch b/qa/data/eeschema/spice_netlists/rectifier/rectifier.kicad_sch index 7badfc6ad8..c9c713ff2e 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.6323) (end -1.27 0) + (arc (start 0 0) (mid -0.635 0.635) (end -1.27 0) (stroke (width 0) (type default)) (fill (type none)) ) - (arc (start 0 0) (mid 0.635 -0.6323) (end 1.27 0) + (arc (start 0 0) (mid 0.635 -0.635) (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" "D" (at 151.765 96.52 0) + (property "Sim_Device" "DIODE" (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,6 +409,9 @@ (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