Fix schematic field index bug in s-expression file format plugin.
This commit is contained in:
parent
169f63a6c0
commit
a8407fba4c
|
@ -571,7 +571,8 @@ SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
|
||||||
else
|
else
|
||||||
field = NULL;
|
field = NULL;
|
||||||
|
|
||||||
wxASSERT( field );
|
wxASSERT_MSG( field, wxString::Format( "No field ID %d found in symbol %s.",
|
||||||
|
aFieldNdx, m_Uuid.AsString() ) );
|
||||||
|
|
||||||
return const_cast<SCH_FIELD*>( field );
|
return const_cast<SCH_FIELD*>( field );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2115,7 +2115,9 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol()
|
||||||
symbol->AddField( *field );
|
symbol->AddField( *field );
|
||||||
}
|
}
|
||||||
|
|
||||||
*symbol->GetField( field->GetId() ) = *field;
|
if( symbol->GetField( field->GetId() ) )
|
||||||
|
*symbol->GetField( field->GetId() ) = *field;
|
||||||
|
|
||||||
delete field;
|
delete field;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -877,6 +877,8 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_COMPONENT* aSymbol, int aNestLevel )
|
||||||
m_out->Print( aNestLevel + 1, "(uuid %s)\n",
|
m_out->Print( aNestLevel + 1, "(uuid %s)\n",
|
||||||
m_out->Quotew( aSymbol->m_Uuid.AsString() ).c_str() );
|
m_out->Quotew( aSymbol->m_Uuid.AsString() ).c_str() );
|
||||||
|
|
||||||
|
m_fieldId = MANDATORY_FIELDS;
|
||||||
|
|
||||||
for( SCH_FIELD& field : aSymbol->GetFields() )
|
for( SCH_FIELD& field : aSymbol->GetFields() )
|
||||||
{
|
{
|
||||||
saveField( &field, aNestLevel + 1 );
|
saveField( &field, aNestLevel + 1 );
|
||||||
|
@ -899,6 +901,12 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel )
|
||||||
else
|
else
|
||||||
fieldName = aField->GetName();
|
fieldName = aField->GetName();
|
||||||
|
|
||||||
|
if( aField->GetId() == -1 /* undefined ID */ )
|
||||||
|
{
|
||||||
|
aField->SetId( m_fieldId );
|
||||||
|
m_fieldId += 1;
|
||||||
|
}
|
||||||
|
|
||||||
m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
|
m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
|
||||||
m_out->Quotew( fieldName ).c_str(),
|
m_out->Quotew( fieldName ).c_str(),
|
||||||
m_out->Quotew( aField->GetText() ).c_str(),
|
m_out->Quotew( aField->GetText() ).c_str(),
|
||||||
|
|
|
@ -144,6 +144,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_version; ///< Version of file being loaded.
|
int m_version; ///< Version of file being loaded.
|
||||||
|
int m_fieldId; ///< Non-mandatory schematic field ID counter.
|
||||||
|
|
||||||
/** For throwing exceptions or errors on partial schematic loads. */
|
/** For throwing exceptions or errors on partial schematic loads. */
|
||||||
wxString m_error;
|
wxString m_error;
|
||||||
|
|
Loading…
Reference in New Issue