Don't add duplicate SIM fields.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17970
This commit is contained in:
Jeff Young 2024-05-09 14:00:27 +01:00
parent 7aa3892ba3
commit a20a6e0787
2 changed files with 19 additions and 11 deletions

View File

@ -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;
}

View File

@ -1508,6 +1508,8 @@ void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject )
}
}
// Up until 8.0.3 we
return;
}