diff --git a/eeschema/read_from_file_schematic_items_descriptions.cpp b/eeschema/read_from_file_schematic_items_descriptions.cpp index 683458a579..25f5f41a01 100644 --- a/eeschema/read_from_file_schematic_items_descriptions.cpp +++ b/eeschema/read_from_file_schematic_items_descriptions.cpp @@ -703,16 +703,19 @@ int ReadPartDescr( wxWindow* frame, char* Line, FILE* f, wxString& aMsgDiag, if( fieldNdx >= component->GetFieldCount() ) { - // add as many fields as needed so the m_FieldId's are - // contiguous, no gaps. - while( fieldNdx >= component->GetFieldCount() ) - { - int newNdx = component->GetFieldCount(); + // The first MANDATOR_FIELDS _must_ be constructed within + // the SCH_COMPONENT constructor. This assert is simply here + // to guard against a change in that constructor. + wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS ); - SCH_FIELD field( wxPoint( 0, 0 ), newNdx, component, - fieldName ); - component->AddField( field ); - } + // 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. + + fieldNdx = component->GetFieldCount(); // new has this index after insertion + + SCH_FIELD field( wxPoint( 0, 0 ), fieldNdx, component, fieldName ); + component->AddField( field ); } else { diff --git a/eeschema/template_fieldnames.h b/eeschema/template_fieldnames.h index c66e0585ff..dadf36a359 100644 --- a/eeschema/template_fieldnames.h +++ b/eeschema/template_fieldnames.h @@ -24,7 +24,9 @@ enum NumFieldType { FOOTPRINT, ///< Field Name Module PCB, i.e. "16DIP300" DATASHEET, ///< name of datasheet - MANDATORY_FIELDS, ///< the first 4 are mandatory or fixed, and instantiated in FIELD constructors + /// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT + /// and LIB_COMPONENT constructors + MANDATORY_FIELDS, FIELD1 = MANDATORY_FIELDS, FIELD2,