Ensure fields are properly ordered

When reading sheet fields, we need to maintain a consistent order for
the mandatory fields as they are dereferenced by place.  We force this
during the `SetFields()` call.
This commit is contained in:
Seth Hillbrand 2022-03-01 17:08:54 -08:00
parent 0b98acfe12
commit 8385ce3021
1 changed files with 14 additions and 1 deletions

View File

@ -97,7 +97,20 @@ public:
*/
void SetFields( const std::vector<SCH_FIELD>& aFields )
{
m_fields = aFields; // vector copying, length is changed possibly
m_fields = aFields;
int next_id = SHEET_MANDATORY_FIELDS;
for( int ii = 0; ii < int( m_fields.size() ); )
{
if( m_fields[ii].GetId() < 0 || m_fields[ii].GetId() >= ssize_t( m_fields.size() ) )
m_fields[ii].SetId( next_id++ );
if( m_fields[ii].GetId() != ii )
std::swap( m_fields[ii], m_fields[m_fields[ii].GetId()]);
if( m_fields[ii].GetId() == ii )
++ii;
}
}
wxString GetName() const { return m_fields[ SHEETNAME ].GetText(); }