From 6d59fef9a50a94c57ecbf337451185445ab848db Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 11 Aug 2022 15:48:33 +0200 Subject: [PATCH] Sim: Fix reading the legacy Spice_Node_Sequence field (2nd attempt) bd809bf31cd982040cdf32bd970fdfd447bd8951 was botched and broke QA tests, this will fix the problem. --- eeschema/sim/sim_model_spice.cpp | 18 +++++++++++++----- eeschema/sim/sim_model_spice.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/eeschema/sim/sim_model_spice.cpp b/eeschema/sim/sim_model_spice.cpp index f808f81e42..d24bdc2d34 100644 --- a/eeschema/sim/sim_model_spice.cpp +++ b/eeschema/sim/sim_model_spice.cpp @@ -124,7 +124,7 @@ wxString SIM_MODEL_SPICE::GenerateSpiceItemLine( const wxString& aRefName, void SIM_MODEL_SPICE::CreatePins( unsigned aSymbolPinCount ) { for( unsigned i = 0; i < aSymbolPinCount; ++i ) - AddPin( { "", PIN::NOT_CONNECTED } ); + AddPin( { "", i + 1 } ); } @@ -243,9 +243,17 @@ void SIM_MODEL_SPICE::readLegacyDataFields( unsigned aSymbolPinCount, const std: } -void SIM_MODEL_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount, const wxString& aPinsField ) +void SIM_MODEL_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount, + const wxString& aLegacyPinsField ) { - tao::pegtl::string_input<> in( aPinsField.ToUTF8(), PINS_FIELD ); + if( aLegacyPinsField == "" ) + return; + + // Initially set all pins to Not Connected to match the legacy behavior. + for( unsigned i = 0; i < GetPinCount(); ++i ) + SetPinSymbolPinNumber( static_cast( i ), PIN::NOT_CONNECTED ); + + tao::pegtl::string_input<> in( aLegacyPinsField.ToUTF8(), PINS_FIELD ); std::unique_ptr root; try @@ -261,7 +269,7 @@ void SIM_MODEL_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount, const wxSt for( unsigned i = 0; i < root->children.size(); ++i ) { - SetPinSymbolPinNumber( std::stoi( root->children.at( i )->string() ) - 1, - static_cast( i + 1 ) ); + SetPinSymbolPinNumber( static_cast( i ), + std::stoi( root->children.at( i )->string() ) ); } } diff --git a/eeschema/sim/sim_model_spice.h b/eeschema/sim/sim_model_spice.h index 63151f83da..5e02264227 100644 --- a/eeschema/sim/sim_model_spice.h +++ b/eeschema/sim/sim_model_spice.h @@ -73,7 +73,7 @@ private: template void readLegacyDataFields( unsigned aSymbolPinCount, const std::vector* aFields ); - void parseLegacyPinsField( unsigned aSymbolPinCount, const wxString& aPinsField ); + void parseLegacyPinsField( unsigned aSymbolPinCount, const wxString& aLegacyPinsField ); std::vector> m_paramInfos; };