diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index def323d68d..8f7a9bb6bc 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -70,7 +70,6 @@ SCH_SEXPR_PARSER::SCH_SEXPR_PARSER( LINE_READER* aLineReader, PROGRESS_REPORTER* bool aIsAppending ) : SCHEMATIC_LEXER( aLineReader ), m_requiredVersion( 0 ), - m_fieldId( 0 ), m_unit( 1 ), m_convert( 1 ), m_appending( aIsAppending ), @@ -206,9 +205,14 @@ LIB_SYMBOL* SCH_SEXPR_PARSER::parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLibMap ) symbol->SetUnitCount( 1 ); - m_fieldId = MANDATORY_FIELDS; m_fieldIDsRead.clear(); + // Make sure the mandatory field IDs are reserved as already read, + // the field parser will set the field IDs to the correct value if + // the field name matches a mandatory field name + for( int i = 0; i < MANDATORY_FIELDS; i++ ) + m_fieldIDsRead.insert( i ); + token = NextTok(); if( !IsSymbol( token ) ) @@ -869,7 +873,7 @@ 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() ) ) + if( ( field->GetId() >= MANDATORY_FIELDS ) && m_fieldIDsRead.count( field->GetId() ) ) { int nextAvailableId = field->GetId() + 1; @@ -1974,8 +1978,8 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) // Empty property values are valid. wxString value = FromUTF8(); - std::unique_ptr field = std::make_unique( VECTOR2I(-1,-1), -1, - aParent, name ); + std::unique_ptr field = + std::make_unique( VECTOR2I( -1, -1 ), MANDATORY_FIELDS, aParent, name ); field->SetText( value ); field->SetVisible( true ); @@ -2595,9 +2599,14 @@ SCH_SYMBOL* SCH_SEXPR_PARSER::parseSchematicSymbol() // We'll reset this if we find a fields_autoplaced token symbol->ClearFieldsAutoplaced(); - m_fieldId = MANDATORY_FIELDS; m_fieldIDsRead.clear(); + // Make sure the mandatory field IDs are reserved as already read, + // the field parser will set the field IDs to the correct value if + // the field name matches a mandatory field name + for( int i = 0; i < MANDATORY_FIELDS; i++ ) + m_fieldIDsRead.insert( i ); + for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { if( token != T_LEFT ) @@ -2846,7 +2855,7 @@ SCH_SYMBOL* SCH_SEXPR_PARSER::parseSchematicSymbol() // the field positions are set. field = parseSchField( symbol.get() ); - if( m_fieldIDsRead.count( field->GetId() ) ) + if( ( field->GetId() >= MANDATORY_FIELDS ) && m_fieldIDsRead.count( field->GetId() ) ) { int nextAvailableId = field->GetId() + 1; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h index e59eb8d088..cd7739abdd 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h @@ -207,7 +207,6 @@ private: void parseBusAlias( SCH_SCREEN* aScreen ); int m_requiredVersion; ///< Set to the symbol library file version required. - int m_fieldId; ///< The current field ID. int m_unit; ///< The current unit being parsed. int m_convert; ///< The current body style being parsed. wxString m_symbolName; ///< The current symbol name.