From a20a6e078706cf4ed3bf884637f485d433db71db Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 9 May 2024 14:00:27 +0100 Subject: [PATCH] Don't add duplicate SIM fields. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17970 --- eeschema/sim/sim_lib_mgr.cpp | 28 +++++++++++++++++----------- eeschema/sim/sim_model.cpp | 2 ++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/eeschema/sim/sim_lib_mgr.cpp b/eeschema/sim/sim_lib_mgr.cpp index 916a81848a..4fb22d71a6 100644 --- a/eeschema/sim/sim_lib_mgr.cpp +++ b/eeschema/sim/sim_lib_mgr.cpp @@ -204,6 +204,19 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S } } + auto getOrCreateField = + [&aSymbol, &fields]( const wxString& name ) -> SCH_FIELD* + { + for( SCH_FIELD& field : fields ) + { + if( field.GetName().IsSameAs( name ) ) + return &field; + } + + fields.emplace_back( &aSymbol, -1, name ); + return &fields.back(); + }; + wxString deviceType; wxString modelType; wxString modelParams; @@ -214,20 +227,13 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S if( SIM_MODEL::InferSimModel( aSymbol, &fields, true, SIM_VALUE_GRAMMAR::NOTATION::SI, &deviceType, &modelType, &modelParams, &pinMap ) ) { - fields.emplace_back( &aSymbol, -1, SIM_DEVICE_FIELD ); - fields.back().SetText( deviceType ); + getOrCreateField( SIM_DEVICE_FIELD )->SetText( deviceType ); if( !modelType.IsEmpty() ) - { - fields.emplace_back( &aSymbol, -1, SIM_DEVICE_SUBTYPE_FIELD ); - fields.back().SetText( modelType ); - } + getOrCreateField( SIM_DEVICE_SUBTYPE_FIELD )->SetText( modelType ); - fields.emplace_back( &aSymbol, -1, SIM_PARAMS_FIELD ); - fields.back().SetText( modelParams ); - - fields.emplace_back( &aSymbol, -1, SIM_PINS_FIELD ); - fields.back().SetText( pinMap ); + getOrCreateField( SIM_PARAMS_FIELD )->SetText( modelParams ); + getOrCreateField( SIM_PINS_FIELD )->SetText( pinMap ); storeInValue = true; } diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index ad535d51eb..70f3d46bbd 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -1508,6 +1508,8 @@ void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject ) } } + // Up until 8.0.3 we + return; }