diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index d335f57fa5..e64ab6241e 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -162,14 +162,13 @@ LIB_SYMBOL* SCH_SEXPR_PARSER::ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap, int aF wxString name; wxString error; LIB_ITEM* item; - LIB_FIELD* field; std::unique_ptr symbol = std::make_unique( wxEmptyString ); - std::set fieldIDsRead; m_requiredVersion = aFileVersion; symbol->SetUnitCount( 1 ); m_fieldId = MANDATORY_FIELDS; + m_fieldIDsRead.clear(); token = NextTok(); @@ -232,29 +231,7 @@ LIB_SYMBOL* SCH_SEXPR_PARSER::ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap, int aF break; case T_property: - field = parseProperty( symbol ); - - if( field ) - { - // Due to an bug when in #LIB_SYMBOL::Flatten, duplicate ids slipped through - // when writing files. This section replaces duplicate #LIB_FIELD indices on - // load. - if( fieldIDsRead.count( field->GetId() ) ) - { - int nextAvailableId = field->GetId() + 1; - - while( fieldIDsRead.count( nextAvailableId ) ) - nextAvailableId += 1; - - fieldIDsRead.insert( nextAvailableId ); - field->SetId( nextAvailableId ); - } - else if( field ) - { - fieldIDsRead.insert( field->GetId() ); - } - } - + parseProperty( symbol ); break; case T_extends: @@ -781,6 +758,19 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr& aSymbol } } + // Due to an bug when in #LIB_SYMBOL::Flatten, duplicate ids slipped through + // when writing files. This section replaces duplicate #LIB_FIELD indices on + // load. + if( m_fieldIDsRead.count( field->GetId() ) ) + { + int nextAvailableId = field->GetId() + 1; + + while( m_fieldIDsRead.count( nextAvailableId ) ) + nextAvailableId += 1; + + field->SetId( nextAvailableId ); + } + LIB_FIELD* existingField; if( field->GetId() < MANDATORY_FIELDS ) @@ -788,6 +778,7 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr& aSymbol existingField = aSymbol->GetFieldById( field->GetId() ); *existingField = *field; + m_fieldIDsRead.insert( field->GetId() ); return existingField; } else if( name == "ki_keywords" ) @@ -853,6 +844,7 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr& aSymbol if( !existingField ) { aSymbol->AddDrawItem( field.get(), false ); + m_fieldIDsRead.insert( field->GetId() ); return field.release(); } else diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h index 52f521f3c2..35e0a1e17c 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h @@ -82,6 +82,9 @@ class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER int m_convert; ///< The current body style being parsed. wxString m_symbolName; ///< The current symbol name. + /// Field IDs that have been read so far for the current symbol. + std::set m_fieldIDsRead; + std::set m_uuids; PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr