Do not use schematic object UUID comparisons when UUIDs are mutable.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19716
This commit is contained in:
Wayne Stambaugh 2025-01-24 14:00:43 -05:00
parent 60c2469c75
commit 1dfe3ebc54
5 changed files with 30 additions and 4 deletions

View File

@ -442,11 +442,14 @@ int SCH_ITEM::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
return 0;
}
if( m_Uuid < aOther.m_Uuid )
return -1;
if( isUuidImmutable() )
{
if( m_Uuid < aOther.m_Uuid )
return -1;
if( m_Uuid > aOther.m_Uuid )
return 1;
if( m_Uuid > aOther.m_Uuid )
return 1;
}
return 0;
}

View File

@ -665,6 +665,19 @@ protected:
void getSymbolEditorMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
/**
* Return the status of the #SCH_ITEM objects UUID immutability.
*
* This method is used by compare() to determine if the object's UUIDs should be compared.
* Most #SCH_ITEM object UUIDs are created at run time an therefore should not be compared
* so the default returns false. Override this method for #SCH_ITEM objects that have
* immutable UUIDs.
*
* @retval true if the item's UUID is immutable.
* @retval false if the item's UUID is not immutable.
*/
virtual bool isUuidImmutable() const { return false; }
/**
* Provide the draw object specific comparison called by the == and < operators.
*

View File

@ -1887,6 +1887,11 @@ wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
}
bool SCH_PIN::isUuidImmutable() const
{
// SCH_SYMBOL pin UUIDs are immutable. LIB_SYMBOL pins UUIDs are not immutable.
return ( static_cast<SCH_SYMBOL*>( GetParent() ) != nullptr );
}
int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const

View File

@ -333,6 +333,9 @@ protected:
*/
void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPosition,
PIN_ORIENTATION aOrientation, bool aDimmed );
virtual bool isUuidImmutable() const override;
std::ostream& operator<<( std::ostream& aStream );
private:

View File

@ -208,6 +208,8 @@ public:
std::vector<int> ViewGetLayers() const override;
protected:
virtual bool isUuidImmutable() const override { return true; }
TRANSFORM m_transform; ///< The rotation/mirror transformation.
int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to