SCH_COMPONENT::GetField() expects a vector index, not a field id.

Check this at compile time.  Callers wanting to use an index now must
use SCH_COMPONENT::GetFields()[i] instead.

Fixes https://gitlab.com/kicad/code/kicad/issues/7757
This commit is contained in:
Jeff Young 2021-02-28 13:28:23 +00:00
parent 13bcfc79a1
commit 8a33542bcd
23 changed files with 175 additions and 164 deletions

View File

@ -573,16 +573,16 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
for( unsigned i = 0; i < aSymbol->GetFields().size(); ++i ) for( unsigned i = 0; i < aSymbol->GetFields().size(); ++i )
{ {
SCH_FIELD* field = aSymbol->GetField( (int) i ) ; SCH_FIELD& field = aSymbol->GetFields()[i];
LIB_FIELD* libField = nullptr; LIB_FIELD* libField = nullptr;
if( !alg::contains( m_updateFields, field->GetName() ) ) if( !alg::contains( m_updateFields, field.GetName() ) )
continue; continue;
if( i < MANDATORY_FIELDS ) if( i < MANDATORY_FIELDS )
libField = libSymbol->GetField( (int) i ); libField = libSymbol->GetFieldById( (int) i );
else else
libField = libSymbol->FindField( field->GetName() ); libField = libSymbol->FindField( field.GetName() );
if( libField ) if( libField )
{ {
@ -598,30 +598,30 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE
else if( i == FOOTPRINT_FIELD ) else if( i == FOOTPRINT_FIELD )
aSymbol->SetFootprint( aInstance, libField->GetText() ); aSymbol->SetFootprint( aInstance, libField->GetText() );
else else
field->SetText( libField->GetText() ); field.SetText( libField->GetText() );
} }
if( resetVis ) if( resetVis )
field->SetVisible( libField->IsVisible() ); field.SetVisible( libField->IsVisible() );
if( resetEffects ) if( resetEffects )
{ {
// Careful: the visible bit and position are also in Effects // Careful: the visible bit and position are also in Effects
bool visible = field->IsVisible(); bool visible = field.IsVisible();
wxPoint pos = field->GetPosition(); wxPoint pos = field.GetPosition();
field->SetEffects( *libField ); field.SetEffects( *libField );
field->SetVisible( visible ); field.SetVisible( visible );
field->SetPosition( pos ); field.SetPosition( pos );
} }
if( resetPositions ) if( resetPositions )
field->SetTextPos( aSymbol->GetPosition() + libField->GetTextPos() ); field.SetTextPos( aSymbol->GetPosition() + libField->GetTextPos() );
} }
else if( i >= MANDATORY_FIELDS && removeExtras ) else if( i >= MANDATORY_FIELDS && removeExtras )
{ {
aSymbol->RemoveField( field->GetName() ); aSymbol->RemoveField( field.GetName() );
i--; i--;
} }
} }

View File

@ -407,7 +407,7 @@ void DIALOG_CHOOSE_SYMBOL::ShowFootprintFor( LIB_ID const& aLibId )
if( !symbol ) if( !symbol )
return; return;
LIB_FIELD* fp_field = symbol->GetField( FOOTPRINT_FIELD ); LIB_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" ); wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
ShowFootprint( fp_name ); ShowFootprint( fp_name );
@ -468,7 +468,7 @@ void DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector( LIB_ID const& aLibId )
if( symbol != nullptr ) if( symbol != nullptr )
{ {
LIB_PINS temp_pins; LIB_PINS temp_pins;
LIB_FIELD* fp_field = symbol->GetField( FOOTPRINT_FIELD ); LIB_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" ); wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
symbol->GetPins( temp_pins ); symbol->GetPins( temp_pins );

View File

@ -465,7 +465,7 @@ void DIALOG_SCH_EDIT_ONE_FIELD::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH*
else if( fieldType == FOOTPRINT_FIELD ) else if( fieldType == FOOTPRINT_FIELD )
otherUnit->SetFootprint( m_text ); otherUnit->SetFootprint( m_text );
else else
otherUnit->GetField( fieldType )->SetText( m_text ); otherUnit->GetField( DATASHEET_FIELD )->SetText( m_text );
editFrame->UpdateItem( otherUnit ); editFrame->UpdateItem( otherUnit );
} }

View File

@ -945,7 +945,7 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames()
SCH_COMPONENT* symbol = m_symbolsList[ i ].GetSymbol(); SCH_COMPONENT* symbol = m_symbolsList[ i ].GetSymbol();
for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j ) for( int j = MANDATORY_FIELDS; j < symbol->GetFieldCount(); ++j )
userFieldNames.insert( symbol->GetField( j )->GetName() ); userFieldNames.insert( symbol->GetFields()[j].GetName() );
} }
// Force References to always be shown // Force References to always be shown

View File

@ -377,13 +377,13 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( const SCH_SHEET_PATH& aShe
{ {
for( int i = 2; i < component->GetFieldCount(); ++i ) for( int i = 2; i < component->GetFieldCount(); ++i )
{ {
SCH_FIELD* field = component->GetField( i ); SCH_FIELD& field = component->GetFields()[i];
const wxString& fieldName = field->GetName(); const wxString& fieldName = field.GetName();
if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty() if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
|| WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) ) || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
{ {
processItem( aSheetPath, field ); processItem( aSheetPath, &field );
} }
} }
} }

View File

@ -219,7 +219,7 @@ void DIALOG_RESCUE_EACH::PopulateInstanceList()
if( each_component->GetLibId().Format() != UTF8( selected_part.GetRequestedName() ) ) if( each_component->GetLibId().Format() != UTF8( selected_part.GetRequestedName() ) )
continue; continue;
SCH_FIELD* valueField = each_component->GetField( 1 ); SCH_FIELD* valueField = each_component->GetField( VALUE_FIELD );
data.clear(); data.clear();
data.push_back( each_component->GetRef( m_currentSheet ) ); data.push_back( each_component->GetRef( m_currentSheet ) );

View File

@ -412,7 +412,7 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow()
// Push a copy of each field into m_updateFields // Push a copy of each field into m_updateFields
for( int i = 0; i < m_comp->GetFieldCount(); ++i ) for( int i = 0; i < m_comp->GetFieldCount(); ++i )
{ {
SCH_FIELD field( *m_comp->GetField( i ) ); SCH_FIELD field( m_comp->GetFields()[i] );
// change offset to be symbol-relative // change offset to be symbol-relative
field.Offset( -m_comp->GetPosition() ); field.Offset( -m_comp->GetPosition() );

View File

@ -54,11 +54,11 @@ class SCH_LEGACY_PLUGIN_CACHE;
* others = free fields * others = free fields
* </p> * </p>
* *
* @see enum NumFieldType * @see enum MANDATORY_FIELD_T
*/ */
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
{ {
int m_id; ///< @see enum NumFieldType int m_id; ///< @see enum MANDATORY_FIELD_T
wxString m_name; ///< Name (not the field text value itself, that is .m_Text) wxString m_name; ///< Name (not the field text value itself, that is .m_Text)
/** /**

View File

@ -343,13 +343,13 @@ std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
// Now add the inherited part mandatory field (this) information. // Now add the inherited part mandatory field (this) information.
for( int i = 0; i < MANDATORY_FIELDS; i++ ) for( int i = 0; i < MANDATORY_FIELDS; i++ )
{ {
wxString tmp = GetField( i )->GetText(); wxString tmp = GetFieldById( i )->GetText();
// If the field isn't defined then inherit the parent field value. // If the field isn't defined then inherit the parent field value.
if( tmp.IsEmpty() ) if( tmp.IsEmpty() )
retv->GetField( i )->SetText( parent->GetField( i )->GetText() ); retv->GetFieldById( i )->SetText( parent->GetFieldById( i )->GetText() );
else else
*retv->GetField( i ) = *GetField( i ); *retv->GetFieldById( i ) = *GetFieldById( i );
} }
// Grab all the rest of derived symbol fields. // Grab all the rest of derived symbol fields.
@ -893,9 +893,9 @@ void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
void LIB_PART::GetFields( std::vector<LIB_FIELD*>& aList ) void LIB_PART::GetFields( std::vector<LIB_FIELD*>& aList )
{ {
// Grab the MANDATORY_FIELDS first, in expected order given by enum NumFieldType // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
for( int id = 0; id < MANDATORY_FIELDS; ++id ) for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( GetField( id ) ); aList.push_back( GetFieldById( id ) );
// Now grab all the rest of fields. // Now grab all the rest of fields.
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
@ -910,9 +910,9 @@ void LIB_PART::GetFields( std::vector<LIB_FIELD*>& aList )
void LIB_PART::GetFields( std::vector<LIB_FIELD>& aList ) void LIB_PART::GetFields( std::vector<LIB_FIELD>& aList )
{ {
// Grab the MANDATORY_FIELDS first, in expected order given by enum NumFieldType // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
for( int id = 0; id < MANDATORY_FIELDS; ++id ) for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( *GetField( id ) ); aList.push_back( *GetFieldById( id ) );
// Now grab all the rest of fields. // Now grab all the rest of fields.
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
@ -925,7 +925,7 @@ void LIB_PART::GetFields( std::vector<LIB_FIELD>& aList )
} }
LIB_FIELD* LIB_PART::GetField( int aId ) const LIB_FIELD* LIB_PART::GetFieldById( int aId ) const
{ {
for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] ) for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
{ {
@ -965,7 +965,7 @@ const LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName ) const
LIB_FIELD& LIB_PART::GetValueField() LIB_FIELD& LIB_PART::GetValueField()
{ {
LIB_FIELD* field = GetField( VALUE_FIELD ); LIB_FIELD* field = GetFieldById( VALUE_FIELD );
wxASSERT( field != NULL ); wxASSERT( field != NULL );
return *field; return *field;
} }
@ -973,7 +973,7 @@ LIB_FIELD& LIB_PART::GetValueField()
LIB_FIELD& LIB_PART::GetReferenceField() LIB_FIELD& LIB_PART::GetReferenceField()
{ {
LIB_FIELD* field = GetField( REFERENCE_FIELD ); LIB_FIELD* field = GetFieldById( REFERENCE_FIELD );
wxASSERT( field != NULL ); wxASSERT( field != NULL );
return *field; return *field;
} }
@ -981,7 +981,7 @@ LIB_FIELD& LIB_PART::GetReferenceField()
LIB_FIELD& LIB_PART::GetFootprintField() LIB_FIELD& LIB_PART::GetFootprintField()
{ {
LIB_FIELD* field = GetField( FOOTPRINT_FIELD ); LIB_FIELD* field = GetFieldById( FOOTPRINT_FIELD );
wxASSERT( field != NULL ); wxASSERT( field != NULL );
return *field; return *field;
} }
@ -989,7 +989,7 @@ LIB_FIELD& LIB_PART::GetFootprintField()
LIB_FIELD& LIB_PART::GetDatasheetField() LIB_FIELD& LIB_PART::GetDatasheetField()
{ {
LIB_FIELD* field = GetField( DATASHEET_FIELD ); LIB_FIELD* field = GetFieldById( DATASHEET_FIELD );
wxASSERT( field != NULL ); wxASSERT( field != NULL );
return *field; return *field;
} }

View File

@ -274,7 +274,7 @@ public:
* @param aId - Id of field to return. * @param aId - Id of field to return.
* @return The field if found, otherwise NULL. * @return The field if found, otherwise NULL.
*/ */
LIB_FIELD* GetField( int aId ) const; LIB_FIELD* GetFieldById( int aId ) const;
/** Return reference to the value field. */ /** Return reference to the value field. */
LIB_FIELD& GetValueField(); LIB_FIELD& GetValueField();

View File

@ -143,17 +143,17 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_COMPONENT* aSymbol
fields.datasheet = comp2->GetField( DATASHEET_FIELD )->GetText(); fields.datasheet = comp2->GetField( DATASHEET_FIELD )->GetText();
} }
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp2->GetFieldCount(); ++fldNdx ) for( int ii = MANDATORY_FIELDS; ii < comp2->GetFieldCount(); ++ii )
{ {
SCH_FIELD* f = comp2->GetField( fldNdx ); const SCH_FIELD& f = comp2->GetFields()[ ii ];
if( f->GetText().size() if( f.GetText().size()
&& ( unit < minUnit || fields.f.count( f->GetName() ) == 0 ) ) && ( unit < minUnit || fields.f.count( f.GetName() ) == 0 ) )
{ {
if( m_resolveTextVars ) if( m_resolveTextVars )
fields.f[ f->GetName() ] = f->GetShownText(); fields.f[ f.GetName() ] = f.GetShownText();
else else
fields.f[ f->GetName() ] = f->GetText(); fields.f[ f.GetName() ] = f.GetText();
} }
} }
@ -171,16 +171,16 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_COMPONENT* aSymbol
else else
fields.datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetText(); fields.datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetText();
for( int fldNdx = MANDATORY_FIELDS; fldNdx < aSymbol->GetFieldCount(); ++fldNdx ) for( int ii = MANDATORY_FIELDS; ii < aSymbol->GetFieldCount(); ++ii )
{ {
SCH_FIELD* f = aSymbol->GetField( fldNdx ); const SCH_FIELD& f = aSymbol->GetFields()[ ii ];
if( f->GetText().size() ) if( f.GetText().size() )
{ {
if( m_resolveTextVars ) if( m_resolveTextVars )
fields.f[ f->GetName() ] = f->GetShownText(); fields.f[ f.GetName() ] = f.GetShownText();
else else
fields.f[ f->GetName() ] = f->GetText(); fields.f[ f.GetName() ] = f.GetText();
} }
} }
} }

View File

@ -50,7 +50,7 @@ class LIB_FIELD;
class SCH_FIELD : public SCH_ITEM, public EDA_TEXT class SCH_FIELD : public SCH_ITEM, public EDA_TEXT
{ {
int m_id; ///< Field index, @see enum NumFieldType int m_id; ///< Field index, @see enum MANDATORY_FIELD_T
wxString m_name; wxString m_name;

View File

@ -46,6 +46,9 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
constexpr int PART_NAME = MANDATORY_FIELDS; // First field after mandatory ones
void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
SCH_PLUGIN::SCH_PLUGIN_RELEASER* aSchPlugin, const wxFileName& aLibraryFileName ) SCH_PLUGIN::SCH_PLUGIN_RELEASER* aSchPlugin, const wxFileName& aLibraryFileName )
{ {
@ -403,14 +406,14 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
if( sym.HasPartRef ) if( sym.HasPartRef )
{ {
SCH_FIELD* partField = component->GetField( FIELD1 ); SCH_FIELD* partField = component->GetFieldById( PART_NAME );
if( !partField ) if( !partField )
{ {
component->AddField( component->AddField( SCH_FIELD( wxPoint(), PART_NAME, component,
SCH_FIELD( wxPoint(), FIELD1, component, wxT( "Part Name" ) ) ); wxT( "Part Name" ) ) );
partField = component->GetField( FIELD1 ); partField = component->GetFieldById( PART_NAME );
} }
wxString partname = getPart( sym.PartRef.RefID ).Name; wxString partname = getPart( sym.PartRef.RefID ).Name;
@ -425,7 +428,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
partField->SetVisible( SymbolPartNameColor.IsVisible ); partField->SetVisible( SymbolPartNameColor.IsVisible );
} }
int fieldIdx = FIELD1; int fieldId = PART_NAME;
for( auto attr : sym.AttributeValues ) for( auto attr : sym.AttributeValues )
{ {
@ -440,10 +443,10 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
if( !attrField ) if( !attrField )
{ {
component->AddField( component->AddField( SCH_FIELD( wxPoint(), ++fieldId, component,
SCH_FIELD( wxPoint(), ++fieldIdx, component, attrName ) ); attrName ) );
attrField = component->GetField( fieldIdx ); attrField = component->GetFieldById( fieldId );
} }
attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) ); attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
@ -1242,11 +1245,11 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( symbol.TextLocations.find( PART_NAME_ATTRID ) != symbol.TextLocations.end() ) if( symbol.TextLocations.find( PART_NAME_ATTRID ) != symbol.TextLocations.end() )
{ {
TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID ); TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID );
LIB_FIELD* field = aPart->GetField( FIELD1 ); LIB_FIELD* field = aPart->GetFieldById( PART_NAME );
if( !field ) if( !field )
{ {
field = new LIB_FIELD( aPart, FIELD1 ); field = new LIB_FIELD( aPart, PART_NAME );
aPart->AddField( field ); aPart->AddField( field );
} }
@ -1268,7 +1271,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( aCadstarPart ) if( aCadstarPart )
{ {
int fieldIdx = FIELD1; int fieldId = PART_NAME;
wxString footprintRefName = wxEmptyString; wxString footprintRefName = wxEmptyString;
wxString footprintAlternateName = wxEmptyString; wxString footprintAlternateName = wxEmptyString;
@ -1315,8 +1318,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
if( !attrField ) if( !attrField )
{ {
aPart->AddField( new LIB_FIELD( aPart, ++fieldIdx ) ); aPart->AddField( new LIB_FIELD( aPart, ++fieldId ) );
attrField = aPart->GetField( fieldIdx ); attrField = aPart->GetFieldById( fieldId );
attrField->SetName( attrName ); attrField->SetName( attrName );
} }

View File

@ -1208,9 +1208,9 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
for( const LIB_FIELD* field : partFields ) for( const LIB_FIELD* field : partFields )
{ {
component->GetField( field->GetId() )->ImportValues( *field ); component->GetFieldById( field->GetId() )->ImportValues( *field );
component->GetField( field->GetId() )->SetTextPos( component->GetPosition() component->GetFieldById( field->GetId() )->SetTextPos( component->GetPosition()
+ field->GetTextPos() ); + field->GetTextPos() );
} }
// If there is no footprint assigned, then prepend the reference value // If there is no footprint assigned, then prepend the reference value
@ -1236,8 +1236,8 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
component->GetField( VALUE_FIELD )->SetText( kisymbolname ); component->GetField( VALUE_FIELD )->SetText( kisymbolname );
// Set the visibility of fields. // Set the visibility of fields.
component->GetField( REFERENCE_FIELD )->SetVisible( part->GetField( REFERENCE_FIELD )->IsVisible() ); component->GetField( REFERENCE_FIELD )->SetVisible( part->GetFieldById( REFERENCE_FIELD )->IsVisible() );
component->GetField( VALUE_FIELD )->SetVisible( part->GetField( VALUE_FIELD )->IsVisible() ); component->GetField( VALUE_FIELD )->SetVisible( part->GetFieldById( VALUE_FIELD )->IsVisible() );
for( const auto& a : epart->attribute ) for( const auto& a : epart->attribute )
{ {
@ -1408,7 +1408,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary(
kpart->SetUnitCount( gates_count ); kpart->SetUnitCount( gates_count );
kpart->LockUnits( true ); kpart->LockUnits( true );
LIB_FIELD* reference = kpart->GetField( REFERENCE_FIELD ); LIB_FIELD* reference = kpart->GetFieldById( REFERENCE_FIELD );
if( prefix.length() == 0 ) if( prefix.length() == 0 )
reference->SetVisible( false ); reference->SetVisible( false );
@ -1550,13 +1550,13 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_P
if( libtext->GetText().Upper() == ">NAME" ) if( libtext->GetText().Upper() == ">NAME" )
{ {
LIB_FIELD* field = aPart->GetField( REFERENCE_FIELD ); LIB_FIELD* field = aPart->GetFieldById( REFERENCE_FIELD );
loadFieldAttributes( field, libtext.get() ); loadFieldAttributes( field, libtext.get() );
foundName = true; foundName = true;
} }
else if( libtext->GetText().Upper() == ">VALUE" ) else if( libtext->GetText().Upper() == ">VALUE" )
{ {
LIB_FIELD* field = aPart->GetField( VALUE_FIELD ); LIB_FIELD* field = aPart->GetFieldById( VALUE_FIELD );
loadFieldAttributes( field, libtext.get() ); loadFieldAttributes( field, libtext.get() );
foundValue = true; foundValue = true;
} }
@ -1595,10 +1595,10 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_P
} }
if( foundName == false ) if( foundName == false )
aPart->GetField( REFERENCE_FIELD )->SetVisible( false ); aPart->GetFieldById( REFERENCE_FIELD )->SetVisible( false );
if( foundValue == false ) if( foundValue == false )
aPart->GetField( VALUE_FIELD )->SetVisible( false ); aPart->GetFieldById( VALUE_FIELD )->SetVisible( false );
return pincount == 1 ? ispower : false; return pincount == 1 ? ispower : false;
} }

View File

@ -797,7 +797,7 @@ void SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol )
if( field->GetId() < MANDATORY_FIELDS ) if( field->GetId() < MANDATORY_FIELDS )
{ {
existingField = aSymbol->GetField( field->GetId() ); existingField = aSymbol->GetFieldById( field->GetId() );
*existingField = *field; *existingField = *field;
} }
@ -830,7 +830,7 @@ void SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_PART>& aSymbol )
} }
else else
{ {
existingField = aSymbol->GetField( field->GetId() ); existingField = aSymbol->GetFieldById( field->GetId() );
if( !existingField ) if( !existingField )
{ {
@ -2313,8 +2313,8 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol()
symbol->SetPrefix( prefix ); symbol->SetPrefix( prefix );
} }
if( symbol->GetField( field->GetId() ) ) if( symbol->GetFieldById( field->GetId() ) )
*symbol->GetField( field->GetId() ) = *field; *symbol->GetFieldById( field->GetId() ) = *field;
else else
symbol->AddField( *field ); symbol->AddField( *field );

View File

@ -1671,6 +1671,8 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
component->AddField( field ); component->AddField( field );
} }
SCH_FIELD& field = component->GetFields()[index];
// Prior to version 2 of the schematic file format, none of the following existed. // Prior to version 2 of the schematic file format, none of the following existed.
if( m_version > 1 ) if( m_version > 1 )
{ {
@ -1683,9 +1685,9 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
parseQuotedString( name, aReader, line, &line, true ); parseQuotedString( name, aReader, line, &line, true );
if( hjustify == 'L' ) if( hjustify == 'L' )
component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); field.SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
else if( hjustify == 'R' ) else if( hjustify == 'R' )
component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); field.SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
else if( hjustify != 'C' ) else if( hjustify != 'C' )
SCH_PARSE_ERROR( "component field text horizontal justification must be " SCH_PARSE_ERROR( "component field text horizontal justification must be "
"L, R, or C", aReader, line ); "L, R, or C", aReader, line );
@ -1693,9 +1695,9 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
// We are guaranteed to have a least one character here for older file formats // We are guaranteed to have a least one character here for older file formats
// otherwise an exception would have been raised.. // otherwise an exception would have been raised..
if( textAttrs[0] == 'T' ) if( textAttrs[0] == 'T' )
component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); field.SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
else if( textAttrs[0] == 'B' ) else if( textAttrs[0] == 'B' )
component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); field.SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
else if( textAttrs[0] != 'C' ) else if( textAttrs[0] != 'C' )
SCH_PARSE_ERROR( "component field text vertical justification must be " SCH_PARSE_ERROR( "component field text vertical justification must be "
"B, T, or C", aReader, line ); "B, T, or C", aReader, line );
@ -1708,36 +1710,35 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
aReader, line ); aReader, line );
if( textAttrs[1] == 'I' ) if( textAttrs[1] == 'I' )
component->GetField( index )->SetItalic( true ); field.SetItalic( true );
else if( textAttrs[1] != 'N' ) else if( textAttrs[1] != 'N' )
SCH_PARSE_ERROR( "component field text italics indicator must be I or N", SCH_PARSE_ERROR( "component field text italics indicator must be I or N",
aReader, line ); aReader, line );
if( textAttrs[2] == 'B' ) if( textAttrs[2] == 'B' )
component->GetField( index )->SetBold( true ); field.SetBold( true );
else if( textAttrs[2] != 'N' ) else if( textAttrs[2] != 'N' )
SCH_PARSE_ERROR( "component field text bold indicator must be B or N", SCH_PARSE_ERROR( "component field text bold indicator must be B or N",
aReader, line ); aReader, line );
} }
} }
component->GetField( index )->SetText( text ); field.SetText( text );
component->GetField( index )->SetTextPos( pos ); field.SetTextPos( pos );
component->GetField( index )->SetVisible( !attributes ); field.SetVisible( !attributes );
component->GetField( index )->SetTextSize( wxSize( size, size ) ); field.SetTextSize( wxSize( size, size ) );
if( orientation == 'H' ) if( orientation == 'H' )
component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ ); field.SetTextAngle( TEXT_ANGLE_HORIZ );
else if( orientation == 'V' ) else if( orientation == 'V' )
component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT ); field.SetTextAngle( TEXT_ANGLE_VERT );
else else
SCH_PARSE_ERROR( "component field orientation must be H or V", SCH_PARSE_ERROR( "component field orientation must be H or V", aReader, line );
aReader, line );
if( name.IsEmpty() ) if( name.IsEmpty() )
name = TEMPLATE_FIELDNAME::GetDefaultFieldName( index ); name = TEMPLATE_FIELDNAME::GetDefaultFieldName( index );
component->GetField( index )->SetName( name ); field.SetName( name );
} }
else if( strCompare( "$EndComp", line ) ) else if( strCompare( "$EndComp", line ) )
{ {
@ -2062,15 +2063,15 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent )
} }
} }
// update the ugly field index, which I would like to see go away someday soon. // update the ugly field id, which I would like to see go away someday soon.
for( int i = 0; i < aComponent->GetFieldCount(); ++i ) for( int i = 0; i < aComponent->GetFieldCount(); ++i )
aComponent->GetField( i )->SetId( i ); aComponent->GetFields()[i].SetId( i );
// Fixed fields: // Fixed fields:
// Save mandatory fields even if they are blank, // Save mandatory fields even if they are blank,
// because the visibility, size and orientation are set from library editor. // because the visibility, size and orientation are set from library editor.
for( unsigned i = 0; i < MANDATORY_FIELDS; ++i ) for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
saveField( aComponent->GetField( i ) ); saveField( &aComponent->GetFields()[i] );
// User defined fields: // User defined fields:
// The *policy* about which user defined fields are part of a symbol is now // The *policy* about which user defined fields are part of a symbol is now
@ -2078,7 +2079,7 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent )
// save all the user defined fields, they are present because a dialog editor // save all the user defined fields, they are present because a dialog editor
// thought they should be. If you disagree, go fix the dialog editors. // thought they should be. If you disagree, go fix the dialog editors.
for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i ) for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
saveField( aComponent->GetField( i ) ); saveField( &aComponent->GetFields()[i] );
// Unit number, position, box ( old standard ) // Unit number, position, box ( old standard )
m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(),
@ -2122,10 +2123,8 @@ void SCH_LEGACY_PLUGIN::saveField( SCH_FIELD* aField )
aField->IsBold() ? 'B' : 'N' ); aField->IsBold() ? 'B' : 'N' );
// Save field name, if the name is user definable // Save field name, if the name is user definable
if( aField->GetId() >= FIELD1 ) if( aField->GetId() >= MANDATORY_FIELDS )
{
m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() ); m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
}
m_out->Print( 0, "\n" ); m_out->Print( 0, "\n" );
} }
@ -2728,7 +2727,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
case 'F': case 'F':
if( symbol ) if( symbol )
symbol->GetField( DATASHEET_FIELD )->SetText( text ); symbol->GetFieldById( DATASHEET_FIELD )->SetText( text );
break; break;
case 0: case 0:
@ -2963,14 +2962,14 @@ void SCH_LEGACY_PLUGIN_CACHE::loadAliases( std::unique_ptr<LIB_PART>& aPart,
LIB_PART* newPart = new LIB_PART( newAliasName ); LIB_PART* newPart = new LIB_PART( newAliasName );
// Inherit the parent mandatory field attributes. // Inherit the parent mandatory field attributes.
for( int id=0; id<MANDATORY_FIELDS; ++id ) for( int id = 0; id < MANDATORY_FIELDS; ++id )
{ {
LIB_FIELD* field = newPart->GetField( id ); LIB_FIELD* field = newPart->GetFieldById( id );
// the MANDATORY_FIELDS are exactly that in RAM. // the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field ); wxASSERT( field );
LIB_FIELD* parentField = aPart->GetField( id ); LIB_FIELD* parentField = aPart->GetFieldById( id );
wxASSERT( parentField ); wxASSERT( parentField );
@ -3008,7 +3007,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadField( std::unique_ptr<LIB_PART>& aPart,
if( id >= 0 && id < MANDATORY_FIELDS ) if( id >= 0 && id < MANDATORY_FIELDS )
{ {
field = aPart->GetField( id ); field = aPart->GetFieldById( id );
// this will fire only if somebody broke a constructor or editor. // this will fire only if somebody broke a constructor or editor.
// MANDATORY_FIELDS are always present in ram resident components, no // MANDATORY_FIELDS are always present in ram resident components, no
@ -3982,7 +3981,7 @@ void SCH_LEGACY_PLUGIN_CACHE::saveField( const LIB_FIELD* aField, OUTPUTFORMATTE
*/ */
wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id ); wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName ) if( id >= MANDATORY_FIELDS && !aField->m_name.IsEmpty() && aField->m_name != defName )
aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() ); aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
aFormatter.Print( 0, "\n" ); aFormatter.Print( 0, "\n" );

View File

@ -136,9 +136,9 @@ SCH_COMPONENT::SCH_COMPONENT( const LIB_PART& aPart, const SCH_SHEET_PATH* aShee
SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos ) SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos )
{ {
// Set any fields that were modified as part of the component selection // Set any fields that were modified as part of the component selection
for( auto const& i : aSel.Fields ) for( const std::pair<int, wxString>& i : aSel.Fields )
{ {
auto field = this->GetField( i.first ); SCH_FIELD* field = GetFieldById( i.first );
if( field ) if( field )
field->SetText( i.second ); field->SetText( i.second );
@ -684,19 +684,25 @@ void SCH_COMPONENT::SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& a
} }
SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) SCH_FIELD* SCH_COMPONENT::GetField( MANDATORY_FIELD_T aFieldType )
{ {
if( (unsigned) aFieldNdx < m_fields.size() ) return &m_fields[aFieldType];
return &m_fields[aFieldNdx];
return nullptr;
} }
const SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const const SCH_FIELD* SCH_COMPONENT::GetField( MANDATORY_FIELD_T aFieldType ) const
{ {
if( (unsigned) aFieldNdx < m_fields.size() ) return &m_fields[aFieldType];
return &m_fields[aFieldNdx]; }
SCH_FIELD* SCH_COMPONENT::GetFieldById( int aFieldId )
{
for( size_t ii = 0; ii < m_fields.size(); ++ii )
{
if( m_fields[ii].GetId() == aFieldId )
return &m_fields[ii];
}
return nullptr; return nullptr;
} }
@ -771,15 +777,15 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
for( const LIB_FIELD* libField : fields ) for( const LIB_FIELD* libField : fields )
{ {
int idx = libField->GetId(); int id = libField->GetId();
SCH_FIELD* schField; SCH_FIELD* schField;
if( idx == REFERENCE_FIELD && !aResetRef ) if( id == REFERENCE_FIELD && !aResetRef )
continue; continue;
if( idx >= 0 && idx < MANDATORY_FIELDS ) if( id >= 0 && id < MANDATORY_FIELDS )
{ {
schField = GetField( idx ); schField = GetFieldById( id );
} }
else else
{ {
@ -799,12 +805,12 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
schField->SetTextPos( m_pos + libField->GetTextPos() ); schField->SetTextPos( m_pos + libField->GetTextPos() );
} }
if( idx == VALUE_FIELD ) if( id == VALUE_FIELD )
{ {
schField->SetText( m_lib_id.GetLibItemName() ); // fetch alias-specific value schField->SetText( m_lib_id.GetLibItemName() ); // fetch alias-specific value
symbolName = m_lib_id.GetLibItemName(); symbolName = m_lib_id.GetLibItemName();
} }
else if( idx == DATASHEET_FIELD ) else if( id == DATASHEET_FIELD )
{ {
schField->SetText( GetDatasheet() ); // fetch alias-specific value schField->SetText( GetDatasheet() ); // fetch alias-specific value
} }
@ -1265,7 +1271,7 @@ void SCH_COMPONENT::Show( int nestLevel, std::ostream& os ) const
{ {
// for now, make it look like XML: // for now, make it look like XML:
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
<< " ref=\"" << TO_UTF8( GetField( 0 )->GetName() ) << " ref=\"" << TO_UTF8( GetField( REFERENCE_FIELD )->GetName() )
<< '"' << " chipName=\"" << '"' << " chipName=\""
<< GetLibId().Format() << '"' << m_pos << GetLibId().Format() << '"' << m_pos
<< " layer=\"" << m_layer << " layer=\"" << m_layer
@ -1274,12 +1280,12 @@ void SCH_COMPONENT::Show( int nestLevel, std::ostream& os ) const
// skip the reference, it's been output already. // skip the reference, it's been output already.
for( int i = 1; i < GetFieldCount(); ++i ) for( int i = 1; i < GetFieldCount(); ++i )
{ {
wxString value = GetField( i )->GetText(); const wxString& value = GetFields()[i].GetText();
if( !value.IsEmpty() ) if( !value.IsEmpty() )
{ {
NestedSpace( nestLevel + 1, os ) << "<field" << " name=\"" NestedSpace( nestLevel + 1, os ) << "<field" << " name=\""
<< TO_UTF8( GetField( i )->GetName() ) << TO_UTF8( GetFields()[i].GetName() )
<< '"' << " value=\"" << '"' << " value=\""
<< TO_UTF8( value ) << "\"/>\n"; << TO_UTF8( value ) << "\"/>\n";
} }
@ -1727,7 +1733,7 @@ bool SCH_COMPONENT::operator==( const SCH_COMPONENT& aComponent ) const
for( int i = VALUE_FIELD; i < GetFieldCount(); i++ ) for( int i = VALUE_FIELD; i < GetFieldCount(); i++ )
{ {
if( GetField( i )->GetText().Cmp( aComponent.GetField( i )->GetText() ) != 0 ) if( GetFields()[i].GetText().Cmp( aComponent.GetFields()[i].GetText() ) != 0 )
return false; return false;
} }

View File

@ -366,16 +366,27 @@ public:
//-----<Fields>----------------------------------------------------------- //-----<Fields>-----------------------------------------------------------
/**
* Returns a mandatory field in this symbol.
*
* NB: If you need to fetch a user field, use GetFieldById.
*
* @param aFieldType is one of the mandatory field types (REFERENCE_FIELD, VALUE_FIELD, etc.).
*
* @return is the field at \a aFieldType or NULL if the field does not exist.
*/
SCH_FIELD* GetField( MANDATORY_FIELD_T aFieldType );
const SCH_FIELD* GetField( MANDATORY_FIELD_T aFieldNdx ) const;
/** /**
* Returns a field in this symbol. * Returns a field in this symbol.
* *
* @param aFieldNdx is the index into the array of fields, not a field id. * @param aFieldId is the id of the field requested. Note that this id ONLY SOMETIMES equates
* to the field's position in the vector.
* *
* @return is the field at \a aFieldNdx or NULL if the field does not exist. * @return is the field at \a aFieldType or NULL if the field does not exist.
*/ */
SCH_FIELD* GetField( int aFieldNdx ); SCH_FIELD* GetFieldById( int aFieldId );
const SCH_FIELD* GetField( int aFieldNdx ) const;
/** /**
* Search for a field named \a aFieldName and returns text associated with this field. * Search for a field named \a aFieldName and returns text associated with this field.
@ -396,6 +407,7 @@ public:
* Returns a vector of fields from the component * Returns a vector of fields from the component
*/ */
std::vector<SCH_FIELD>& GetFields() { return m_fields; } std::vector<SCH_FIELD>& GetFields() { return m_fields; }
const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
/** /**
* Add a field to the symbol. * Add a field to the symbol.

View File

@ -1269,15 +1269,15 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol )
for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i ) for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i )
{ {
SCH_FIELD* field = aSymbol->GetField( i ); const SCH_FIELD& field = aSymbol->GetFields()[i];
wxPoint pos = field->GetPosition() - aSymbol->GetPosition(); wxPoint pos = field.GetPosition() - aSymbol->GetPosition();
LIB_FIELD libField( part.get(), field->GetId() ); LIB_FIELD libField( part.get(), field.GetId() );
if( i >= MANDATORY_FIELDS && !field->GetName( false ).IsEmpty() ) if( i >= MANDATORY_FIELDS && !field.GetName( false ).IsEmpty() )
libField.SetName( field->GetName( false ) ); libField.SetName( field.GetName( false ) );
libField.SetText( field->GetText() ); libField.SetText( field.GetText() );
libField.SetEffects( *field ); libField.SetEffects( field );
libField.SetPosition( wxPoint( pos.x, -pos.y ) ); libField.SetPosition( wxPoint( pos.x, -pos.y ) );
fullSetOfFields.emplace_back( std::move( libField ) ); fullSetOfFields.emplace_back( std::move( libField ) );
@ -1289,7 +1289,7 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol )
SetCurPart( nullptr, false ); SetCurPart( nullptr, false );
m_isSymbolFromSchematic = true; m_isSymbolFromSchematic = true;
m_reference = part->GetField( REFERENCE_FIELD )->GetText(); m_reference = part->GetFieldById( REFERENCE_FIELD )->GetText();
m_unit = std::max( 1, aSymbol->GetUnit() ); m_unit = std::max( 1, aSymbol->GetUnit() );
m_convert = std::max( 1, aSymbol->GetConvert() ); m_convert = std::max( 1, aSymbol->GetConvert() );

View File

@ -463,14 +463,14 @@ void SYMBOL_EDIT_FRAME::CreateNewPart()
new_part.SetParent( parent ); new_part.SetParent( parent );
// Inherit the parent mandatory field attributes. // Inherit the parent mandatory field attributes.
for( int id=0; id<MANDATORY_FIELDS; ++id ) for( int id = 0; id < MANDATORY_FIELDS; ++id )
{ {
LIB_FIELD* field = new_part.GetField( id ); LIB_FIELD* field = new_part.GetFieldById( id );
// the MANDATORY_FIELDS are exactly that in RAM. // the MANDATORY_FIELDS are exactly that in RAM.
wxCHECK( field, /* void */ ); wxCHECK( field, /* void */ );
LIB_FIELD* parentField = parent->GetField( id ); LIB_FIELD* parentField = parent->GetFieldById( id );
wxCHECK( parentField, /* void */ ); wxCHECK( parentField, /* void */ );

View File

@ -39,7 +39,7 @@ class TEMPLATE_FIELDNAMES_LEXER;
* The first fields are fixed fields and are defined by #MANDATORY_FIELDS. After that come * The first fields are fixed fields and are defined by #MANDATORY_FIELDS. After that come
* an unlimited number of user defined fields, only some of which have indices defined here. * an unlimited number of user defined fields, only some of which have indices defined here.
*/ */
enum NumFieldType { enum MANDATORY_FIELD_T {
REFERENCE_FIELD = 0, ///< Field Reference of part, i.e. "IC21" REFERENCE_FIELD = 0, ///< Field Reference of part, i.e. "IC21"
VALUE_FIELD, ///< Field Value of part, i.e. "3.3K" VALUE_FIELD, ///< Field Value of part, i.e. "3.3K"
FOOTPRINT_FIELD, ///< Field Name Module PCB, i.e. "16DIP300" FOOTPRINT_FIELD, ///< Field Name Module PCB, i.e. "16DIP300"
@ -47,16 +47,7 @@ enum NumFieldType {
/// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT /// The first 4 are mandatory, and must be instantiated in SCH_COMPONENT
/// and LIB_PART constructors /// and LIB_PART constructors
MANDATORY_FIELDS, MANDATORY_FIELDS
FIELD1 = MANDATORY_FIELDS,
FIELD2,
FIELD3,
FIELD4,
FIELD5,
FIELD6,
FIELD7,
FIELD8
}; };

View File

@ -97,7 +97,7 @@ bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedNa
*/ */
bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields ) bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields )
{ {
const unsigned expectedCount = NumFieldType::MANDATORY_FIELDS; const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
if( aFields.size() < expectedCount ) if( aFields.size() < expectedCount )
{ {
BOOST_TEST_INFO( BOOST_TEST_INFO(
@ -107,10 +107,10 @@ bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields )
bool ok = true; bool ok = true;
ok &= FieldNameIdMatches( aFields[0], "Reference", NumFieldType::REFERENCE_FIELD ); ok &= FieldNameIdMatches( aFields[0], "Reference", MANDATORY_FIELD_T::REFERENCE_FIELD );
ok &= FieldNameIdMatches( aFields[1], "Value", NumFieldType::VALUE_FIELD ); ok &= FieldNameIdMatches( aFields[1], "Value", MANDATORY_FIELD_T::VALUE_FIELD );
ok &= FieldNameIdMatches( aFields[2], "Footprint", NumFieldType::FOOTPRINT_FIELD ); ok &= FieldNameIdMatches( aFields[2], "Footprint", MANDATORY_FIELD_T::FOOTPRINT_FIELD );
ok &= FieldNameIdMatches( aFields[3], "Datasheet", NumFieldType::DATASHEET_FIELD ); ok &= FieldNameIdMatches( aFields[3], "Datasheet", MANDATORY_FIELD_T::DATASHEET_FIELD );
return ok; return ok;
} }

View File

@ -102,15 +102,15 @@ BOOST_AUTO_TEST_CASE( DefaultFields )
BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) ); BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
// but no more (we didn't set them) // but no more (we didn't set them)
BOOST_CHECK_EQUAL( fields.size(), NumFieldType::MANDATORY_FIELDS ); BOOST_CHECK_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS );
// also check the default field accessors // also check the default field accessors
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
( m_part_no_data.GetReferenceField() )( "Reference" )( NumFieldType::REFERENCE_FIELD ) ); ( m_part_no_data.GetReferenceField() )( "Reference" )( MANDATORY_FIELD_T::REFERENCE_FIELD ) );
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
( m_part_no_data.GetValueField() )( "Value" )( NumFieldType::VALUE_FIELD ) ); ( m_part_no_data.GetValueField() )( "Value" )( MANDATORY_FIELD_T::VALUE_FIELD ) );
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
( m_part_no_data.GetFootprintField() )( "Footprint" )( NumFieldType::FOOTPRINT_FIELD ) ); ( m_part_no_data.GetFootprintField() )( "Footprint" )( MANDATORY_FIELD_T::FOOTPRINT_FIELD ) );
} }
@ -134,14 +134,14 @@ BOOST_AUTO_TEST_CASE( AddedFields )
BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) ); BOOST_CHECK_PREDICATE( KI_TEST::AreDefaultFieldsCorrect, ( fields ) );
// and our new one // and our new one
BOOST_REQUIRE_EQUAL( fields.size(), NumFieldType::MANDATORY_FIELDS + 1 ); BOOST_REQUIRE_EQUAL( fields.size(), MANDATORY_FIELD_T::MANDATORY_FIELDS + 1 );
BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches, BOOST_CHECK_PREDICATE( KI_TEST::FieldNameIdMatches,
( fields[NumFieldType::MANDATORY_FIELDS] )( newFieldName )( 42 ) ); ( fields[MANDATORY_FIELD_T::MANDATORY_FIELDS] )( newFieldName )( 42 ) );
// Check by-id lookup // Check by-id lookup
LIB_FIELD* gotNewField = m_part_no_data.GetField( 42 ); LIB_FIELD* gotNewField = m_part_no_data.GetFieldById( 42 );
BOOST_REQUIRE_NE( gotNewField, nullptr ); BOOST_REQUIRE_NE( gotNewField, nullptr );