mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 18:23:15 +02:00
m_ordinal has no meaning for mandatory fields.
... but it should still be initialised.
This commit is contained in:
parent
141d50f0c1
commit
8f40feedbb
@ -404,8 +404,6 @@ public:
|
|||||||
|
|
||||||
void RemoveField( SCH_FIELD* aField ) { RemoveDrawItem( aField ); }
|
void RemoveField( SCH_FIELD* aField ) { RemoveDrawItem( aField ); }
|
||||||
|
|
||||||
size_t GetFieldCount() const { return m_drawings.size( SCH_FIELD_T ); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of pin object pointers from the draw item list.
|
* Return a list of pin object pointers from the draw item list.
|
||||||
*
|
*
|
||||||
|
@ -48,6 +48,7 @@ SCH_FIELD::SCH_FIELD() :
|
|||||||
SCH_ITEM( nullptr, SCH_FIELD_T ),
|
SCH_ITEM( nullptr, SCH_FIELD_T ),
|
||||||
EDA_TEXT( schIUScale, wxEmptyString ),
|
EDA_TEXT( schIUScale, wxEmptyString ),
|
||||||
m_id( FIELD_T::USER ),
|
m_id( FIELD_T::USER ),
|
||||||
|
m_ordinal( 0 ),
|
||||||
m_showName( false ),
|
m_showName( false ),
|
||||||
m_allowAutoPlace( true ),
|
m_allowAutoPlace( true ),
|
||||||
m_isNamedVariable( false ),
|
m_isNamedVariable( false ),
|
||||||
@ -79,6 +80,15 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, FIELD_T aFieldId, SCH_ITEM* aParent,
|
|||||||
SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, FIELD_T aFieldId, const wxString& aName ) :
|
SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, FIELD_T aFieldId, const wxString& aName ) :
|
||||||
SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
|
SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
|
||||||
{
|
{
|
||||||
|
if( aFieldId == FIELD_T::USER && aParent )
|
||||||
|
{
|
||||||
|
if( aParent->Type() == SCH_SYMBOL_T )
|
||||||
|
m_ordinal = static_cast<SCH_SYMBOL*>( aParent )->GetNextFieldOrdinal();
|
||||||
|
else if( aParent->Type() == SCH_SHEET_T )
|
||||||
|
m_ordinal = static_cast<SCH_SHEET*>( aParent )->GetNextFieldOrdinal();
|
||||||
|
else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aParent ) )
|
||||||
|
m_ordinal = label->GetNextFieldOrdinal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1372,8 +1382,19 @@ bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( IsMandatory() != aOther.IsMandatory() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( IsMandatory() )
|
||||||
|
{
|
||||||
if( GetId() != aOther.GetId() )
|
if( GetId() != aOther.GetId() )
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( GetOrdinal() != aOther.GetOrdinal() )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if( GetPosition() != aOther.GetPosition() )
|
if( GetPosition() != aOther.GetPosition() )
|
||||||
return false;
|
return false;
|
||||||
|
@ -353,6 +353,17 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline int NextFieldOrdinal( const std::vector<SCH_FIELD>& aFields )
|
||||||
|
{
|
||||||
|
int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T id
|
||||||
|
|
||||||
|
for( const SCH_FIELD& field : aFields )
|
||||||
|
ordinal = std::max( ordinal, field.GetOrdinal() + 1 );
|
||||||
|
|
||||||
|
return ordinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const SCH_FIELD* FindField( const std::vector<SCH_FIELD>& aFields, FIELD_T aFieldId )
|
inline const SCH_FIELD* FindField( const std::vector<SCH_FIELD>& aFields, FIELD_T aFieldId )
|
||||||
{
|
{
|
||||||
for( const SCH_FIELD& field : aFields )
|
for( const SCH_FIELD& field : aFields )
|
||||||
|
@ -212,6 +212,12 @@ const wxString SCH_LABEL_BASE::GetDefaultFieldName( const wxString& aName, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SCH_LABEL_BASE::GetNextFieldOrdinal() const
|
||||||
|
{
|
||||||
|
return NextFieldOrdinal( m_fields );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SCH_LABEL_BASE::IsType( const std::vector<KICAD_T>& aScanTypes ) const
|
bool SCH_LABEL_BASE::IsType( const std::vector<KICAD_T>& aScanTypes ) const
|
||||||
{
|
{
|
||||||
static const std::vector<KICAD_T> wireAndPinTypes = { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T };
|
static const std::vector<KICAD_T> wireAndPinTypes = { SCH_ITEM_LOCATE_WIRE_T, SCH_PIN_T };
|
||||||
|
@ -197,6 +197,11 @@ public:
|
|||||||
|
|
||||||
static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName );
|
static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next ordinal for a user field for this label
|
||||||
|
*/
|
||||||
|
int GetNextFieldOrdinal() const;
|
||||||
|
|
||||||
virtual int GetMandatoryFieldCount() { return 0; }
|
virtual int GetMandatoryFieldCount() { return 0; }
|
||||||
|
|
||||||
std::vector<SCH_FIELD>& GetFields() { return m_fields; }
|
std::vector<SCH_FIELD>& GetFields() { return m_fields; }
|
||||||
|
@ -386,6 +386,12 @@ const SCH_FIELD* SCH_SHEET::GetField( FIELD_T aFieldType ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SCH_SHEET::GetNextFieldOrdinal() const
|
||||||
|
{
|
||||||
|
return NextFieldOrdinal( m_fields );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SCH_SHEET::SetFields( const std::vector<SCH_FIELD>& aFields )
|
void SCH_SHEET::SetFields( const std::vector<SCH_FIELD>& aFields )
|
||||||
{
|
{
|
||||||
m_fields = aFields;
|
m_fields = aFields;
|
||||||
|
@ -94,6 +94,11 @@ public:
|
|||||||
SCH_FIELD* GetField( FIELD_T aFieldType );
|
SCH_FIELD* GetField( FIELD_T aFieldType );
|
||||||
const SCH_FIELD* GetField( FIELD_T aFieldNdx ) const;
|
const SCH_FIELD* GetField( FIELD_T aFieldNdx ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next ordinal for a user field for this sheet
|
||||||
|
*/
|
||||||
|
int GetNextFieldOrdinal() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set multiple schematic fields.
|
* Set multiple schematic fields.
|
||||||
*
|
*
|
||||||
|
@ -859,6 +859,12 @@ void SCH_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SCH_SYMBOL::GetNextFieldOrdinal() const
|
||||||
|
{
|
||||||
|
return NextFieldOrdinal( m_fields );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SCH_FIELD* SCH_SYMBOL::AddField( const SCH_FIELD& aField )
|
SCH_FIELD* SCH_SYMBOL::AddField( const SCH_FIELD& aField )
|
||||||
{
|
{
|
||||||
m_fields.push_back( aField );
|
m_fields.push_back( aField );
|
||||||
@ -1823,7 +1829,7 @@ void SCH_SYMBOL::Show( int nestLevel, std::ostream& os ) const
|
|||||||
<< '"' << ">\n";
|
<< '"' << ">\n";
|
||||||
|
|
||||||
// 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 < (int) GetFields().size(); ++i )
|
||||||
{
|
{
|
||||||
const wxString& value = GetFields()[i].GetText();
|
const wxString& value = GetFields()[i].GetText();
|
||||||
|
|
||||||
@ -2364,15 +2370,15 @@ bool SCH_SYMBOL::operator <( const SCH_ITEM& aItem ) const
|
|||||||
|
|
||||||
bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const
|
bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const
|
||||||
{
|
{
|
||||||
if( GetFieldCount() != aSymbol.GetFieldCount() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<SCH_FIELD*> fields, otherFields;
|
std::vector<SCH_FIELD*> fields, otherFields;
|
||||||
|
|
||||||
GetFields( fields, false );
|
GetFields( fields, false );
|
||||||
aSymbol.GetFields( otherFields, false );
|
aSymbol.GetFields( otherFields, false );
|
||||||
|
|
||||||
for( int ii = 0; ii < GetFieldCount(); ii++ )
|
if( fields.size() != otherFields.size() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for( int ii = 0; ii < (int) fields.size(); ii++ )
|
||||||
{
|
{
|
||||||
if( fields[ii]->GetId() == FIELD_T::REFERENCE )
|
if( fields[ii]->GetId() == FIELD_T::REFERENCE )
|
||||||
continue;
|
continue;
|
||||||
|
@ -570,11 +570,9 @@ public:
|
|||||||
PROPERTY_BASE* aProperty );
|
PROPERTY_BASE* aProperty );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of fields in this symbol.
|
* Return the next ordinal for a user field for this symbol
|
||||||
*/
|
*/
|
||||||
int GetFieldCount() const { return (int )m_fields.size(); }
|
int GetNextFieldOrdinal() const;
|
||||||
|
|
||||||
int GetNextFieldId() const { return (int) m_fields.size(); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically orient all the fields in the symbol.
|
* Automatically orient all the fields in the symbol.
|
||||||
|
@ -696,7 +696,7 @@ public:
|
|||||||
std::deque<PCB_FIELD*>& GetFields() { return m_fields; }
|
std::deque<PCB_FIELD*>& GetFields() { return m_fields; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the next ID for a field for this footprint
|
* Return the next ordinal for a user field for this footprint
|
||||||
*/
|
*/
|
||||||
int GetNextFieldOrdinal() const;
|
int GetNextFieldOrdinal() const;
|
||||||
|
|
||||||
|
@ -34,13 +34,11 @@
|
|||||||
PCB_FIELD::PCB_FIELD( FOOTPRINT* aParent, FIELD_T aFieldId, const wxString& aName ) :
|
PCB_FIELD::PCB_FIELD( FOOTPRINT* aParent, FIELD_T aFieldId, const wxString& aName ) :
|
||||||
PCB_TEXT( aParent, PCB_FIELD_T ),
|
PCB_TEXT( aParent, PCB_FIELD_T ),
|
||||||
m_id( aFieldId ),
|
m_id( aFieldId ),
|
||||||
m_ordinal( static_cast<int>( aFieldId ) ),
|
m_ordinal( 0 ),
|
||||||
m_name( aName )
|
m_name( aName )
|
||||||
{
|
{
|
||||||
if( m_id == FIELD_T::USER )
|
if( m_id == FIELD_T::USER )
|
||||||
m_ordinal = aParent->GetNextFieldOrdinal();
|
m_ordinal = aParent->GetNextFieldOrdinal();
|
||||||
else
|
|
||||||
m_ordinal = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -220,10 +218,21 @@ bool PCB_FIELD::operator==( const BOARD_ITEM& aOther ) const
|
|||||||
|
|
||||||
bool PCB_FIELD::operator==( const PCB_FIELD& aOther ) const
|
bool PCB_FIELD::operator==( const PCB_FIELD& aOther ) const
|
||||||
{
|
{
|
||||||
return m_id == aOther.m_id
|
if( IsMandatory() != aOther.IsMandatory() )
|
||||||
&& m_ordinal == aOther.m_ordinal
|
return false;
|
||||||
&& m_name == aOther.m_name
|
|
||||||
&& EDA_TEXT::operator==( aOther );
|
if( IsMandatory() )
|
||||||
|
{
|
||||||
|
if( m_id != aOther.m_id )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_ordinal != aOther.m_ordinal )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_name == aOther.m_name && EDA_TEXT::operator==( aOther );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user