From 04f50ce68741220830d201bdde107eefae2f9688 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 19 Dec 2022 11:35:05 +0000 Subject: [PATCH] Generate default pinMap from symbol's pins when we don't know SIM_MODEL's pins. --- eeschema/sim/sim_model.cpp | 46 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index d3742a17ae..ad228f008a 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -1256,6 +1256,27 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) return value; }; + auto generateDefaultPinMapFromSymbol = + []( const std::vector& sourcePins ) + { + wxString pinMap; + + // If we're creating the pinMap from the symbol it means we don't know what the + // SIM_MODEL's pin names are, so just use indexes. + + for( unsigned ii = 0; ii < sourcePins.size(); ++ii ) + { + if( ii > 0 ) + pinMap.Append( wxS( " " ) ); + + pinMap.Append( wxString::Format( wxT( "%s=%u" ), + sourcePins[ii]->GetNumber(), + ii + 1 ) ); + } + + return pinMap; + }; + wxString prefix = aSymbol.GetPrefix(); T_field* valueField = aSymbol.FindField( wxT( "Value" ) ); std::vector sourcePins = aSymbol.GetAllLibPins(); @@ -1436,9 +1457,14 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) if( pinMap.IsEmpty() ) { - // Generate a default pin map + // Try to generate a default pin map from the SIM_MODEL's pins; if that fails, + // generate one from the symbol's pins + model.model.SIM_MODEL::CreatePins( sourcePins ); pinMap = wxString( model.model.Serde().GeneratePins() ); + + if( pinMap.IsEmpty() ) + pinMap = generateDefaultPinMapFromSymbol( sourcePins ); } } catch( ... ) @@ -1493,7 +1519,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) if( pinMap.IsEmpty() ) { - // Generate a default pin map + // Generate a default pin map from the SIM_MODEL's pins model->CreatePins( sourcePins ); pinMap = wxString( model->Serde().GeneratePins() ); } @@ -1577,19 +1603,11 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) valueField->SetText( wxT( "${SIM.PARAMS}" ) ); } - if( pinMap.IsEmpty() ) - { - // Generate a 1:1 pin map. We don't know the SPICE model pinNames, so just use indexes. - for( unsigned ii = 0; ii < sourcePins.size(); ++ii ) - { - if( ii > 0 ) - pinMap.Append( wxS( " " ) ); + // We know nothing about the SPICE model here, so we've got no choice but to generate + // the default pin map from the symbol's pins. - pinMap.Append( wxString::Format( wxT( "%s=%u" ), - sourcePins[ii]->GetNumber(), - ii + 1 ) ); - } - } + if( pinMap.IsEmpty() ) + pinMap = generateDefaultPinMapFromSymbol( sourcePins ); } if( !pinMap.IsEmpty() )