schematic: legacy kicad schematic files don't have a default description field
Without this, we would parse a legacy schematic symbol field at the same index as the new description field's index into description, instead of into a user field. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/17202
This commit is contained in:
parent
b57184efe0
commit
1b5e18d95f
|
@ -1288,13 +1288,23 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader )
|
|||
int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
|
||||
int attributes = parseHex( aReader, line, &line );
|
||||
|
||||
if( index >= symbol->GetFieldCount() )
|
||||
// Description was not mandatory until v8.0, so any fields with an index
|
||||
// past this point should be user fields
|
||||
if( index > DATASHEET_FIELD )
|
||||
{
|
||||
// The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
|
||||
// constructor. This assert is simply here to guard against a change in that
|
||||
// constructor.
|
||||
wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
|
||||
|
||||
// We need to check for an existing field by name that happens to have the same
|
||||
// name and index as any field that was made mandatory after this point, e.g. Description
|
||||
// is now mandatory but a user could have easily added their own user field named Description
|
||||
// after Datasheet before it was mandatory, and we don't want to add a second Description field.
|
||||
SCH_FIELD* existingField = symbol->GetFieldByName( name );
|
||||
|
||||
if( !existingField )
|
||||
{
|
||||
// Ignore the _supplied_ fieldNdx. It is not important anymore if within the
|
||||
// user defined fields region (i.e. >= MANDATORY_FIELDS).
|
||||
// We freely renumber the index to fit the next available field slot.
|
||||
|
@ -1303,6 +1313,9 @@ SCH_SYMBOL* SCH_IO_KICAD_LEGACY::loadSymbol( LINE_READER& aReader )
|
|||
SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name );
|
||||
symbol->AddField( field );
|
||||
}
|
||||
else
|
||||
index = existingField->GetId();
|
||||
}
|
||||
|
||||
SCH_FIELD& field = symbol->GetFields()[index];
|
||||
|
||||
|
|
Loading…
Reference in New Issue