7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 10:01:40 +00:00

Initialize field ordinals for LIB_SYMBOLs.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20263
This commit is contained in:
Jeff Young 2025-03-07 15:34:57 +00:00
parent 727fc9bd06
commit 0fae6a0db0
3 changed files with 18 additions and 0 deletions

View File

@ -1038,6 +1038,17 @@ void LIB_SYMBOL::CopyFields( std::vector<SCH_FIELD>& aList )
}
int LIB_SYMBOL::GetNextFieldOrdinal() const
{
int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T id
for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
ordinal = std::max( ordinal, static_cast<const SCH_FIELD*>( &item )->GetOrdinal() + 1 );
return ordinal;
}
const SCH_FIELD* LIB_SYMBOL::GetField( FIELD_T aFieldType ) const
{
for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )

View File

@ -314,6 +314,11 @@ public:
void AddField( SCH_FIELD& aField ) { AddField( new SCH_FIELD( aField ) ); }
/**
* Return the next ordinal for a user field for this symbol
*/
int GetNextFieldOrdinal() const;
/**
* Find a field within this symbol matching \a aFieldName; return nullptr if not found.
*/

View File

@ -84,6 +84,8 @@ SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, FIELD_T aFieldId, const wxString& aName
{
if( aParent->Type() == SCH_SYMBOL_T )
m_ordinal = static_cast<SCH_SYMBOL*>( aParent )->GetNextFieldOrdinal();
else if( aParent->Type() == LIB_SYMBOL_T )
m_ordinal = static_cast<LIB_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 ) )