diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index ad574d41dc..a4b9b00bac 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -1394,7 +1394,24 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) || aSymbol.FindField( SIM_PINS_FIELD ) || aSymbol.FindField( SIM_PARAMS_FIELD ) ) { - // Has a V7 model field -- skip. + // Has a V7 model field. + + // Up until 7.0RC2 we used '+' and '-' for potentiometer pins, which doesn't match + // SPICE. Here we remap them to 'r0' and 'r1'. + if( T_field* deviceType = aSymbol.FindField( SIM_TYPE_FIELD ) ) + { + if( deviceType->GetShownText().Lower() == wxS( "pot" ) ) + { + if( T_field* pins = aSymbol.FindField( SIM_PINS_FIELD ) ) + { + wxString pinMap = pins->GetText(); + pinMap.Replace( wxS( "=+" ), wxS( "=r1" ) ); + pinMap.Replace( wxS( "=-" ), wxS( "=r0" ) ); + pins->SetText( pinMap ); + } + } + } + return; } diff --git a/eeschema/sim/sim_model_r_pot.cpp b/eeschema/sim/sim_model_r_pot.cpp index a5aad808a7..f7aac45358 100644 --- a/eeschema/sim/sim_model_r_pot.cpp +++ b/eeschema/sim/sim_model_r_pot.cpp @@ -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 @@ -41,37 +41,6 @@ std::string SPICE_GENERATOR_R_POT::ModelLine( const SPICE_ITEM& aItem ) const } -std::string SPICE_GENERATOR_R_POT::ItemPins( const SPICE_ITEM& aItem ) const -{ - std::string result; - int ncCounter = 0; - - wxCHECK( GetPins().size() == 3, "" ); - - // Swap pin order so that pos=1 is +, and pos=0 is -. - std::vector> inverted( GetPins() ); - std::swap( inverted[0], inverted[2] ); - - for( const SIM_MODEL::PIN& pin : GetPins() ) - { - auto it = std::find( aItem.pinNumbers.begin(), aItem.pinNumbers.end(), - pin.symbolPinNumber ); - - if( it != aItem.pinNumbers.end() ) - { - long symbolPinIndex = std::distance( aItem.pinNumbers.begin(), it ); - result.append( fmt::format( " {}", aItem.pinNetNames.at( symbolPinIndex ) ) ); - } - else - { - result.append( fmt::format( " NC-{}-{}", aItem.refName, ncCounter++ ) ); - } - } - - return result; -} - - std::string SPICE_GENERATOR_R_POT::TunerCommand( const SPICE_ITEM& aItem, const SIM_VALUE_FLOAT& aValue ) const { diff --git a/eeschema/sim/sim_model_r_pot.h b/eeschema/sim/sim_model_r_pot.h index c152f416d5..7376b3c1f5 100644 --- a/eeschema/sim/sim_model_r_pot.h +++ b/eeschema/sim/sim_model_r_pot.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 @@ -35,7 +35,6 @@ public: using SPICE_GENERATOR::SPICE_GENERATOR; std::string ModelLine( const SPICE_ITEM& aItem ) const override; - std::string ItemPins( const SPICE_ITEM& aItem ) const override; std::string TunerCommand( const SPICE_ITEM& aItem, const SIM_VALUE_FLOAT& aValue ) const override; }; @@ -48,7 +47,7 @@ public: const PARAM* GetTunerParam() const override { return FindParam( "pos" ); } bool HasPrimaryValue() const override { return true; } - std::vector GetPinNames() const override { return { "+", "wiper", "-" }; } + std::vector GetPinNames() const override { return { "r0", "wiper", "r1" }; } private: static const std::vector makeParamInfos(); diff --git a/qa/unittests/eeschema/test_netlist_exporter_spice.cpp b/qa/unittests/eeschema/test_netlist_exporter_spice.cpp index d1389550bc..f574911f57 100644 --- a/qa/unittests/eeschema/test_netlist_exporter_spice.cpp +++ b/qa/unittests/eeschema/test_netlist_exporter_spice.cpp @@ -102,8 +102,8 @@ BOOST_AUTO_TEST_CASE( Potentiometers ) { TestNetlist( "potentiometers" ); TestOpPoint( 0.5, "V(/out1)" ); - TestOpPoint( 0.3, "V(/out2)" ); - TestOpPoint( 0.1, "V(/out3)" ); + TestOpPoint( 0.7, "V(/out2)" ); + TestOpPoint( 0.9, "V(/out3)" ); }