Make LIB_ITEM::COMPARE_FLAGS really a flags field, and add ERC.

Before they were 1/2 treated as flags and 1/2 treated as a mode enum.

The ERC flag relaxes constraints on data that is settable in the
schematic editor.

Fixes https://gitlab.com/kicad/code/kicad/issues/11018

(cherry picked from commit 76535d8572)
This commit is contained in:
Jeff Young 2022-03-03 12:20:30 +00:00
parent 802d20c409
commit 912c2eac09
13 changed files with 37 additions and 31 deletions

View File

@ -744,8 +744,9 @@ int ERC_TESTER::TestLibSymbolIssues()
}
std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
constexpr int flags = LIB_ITEM::COMPARE_FLAGS::EQUALITY | LIB_ITEM::COMPARE_FLAGS::ERC;
if( *flattenedSymbol != *libSymbolInSchematic )
if( flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol );

View File

@ -179,7 +179,7 @@ void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
}
int LIB_FIELD::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_FIELD::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_FIELD_T );

View File

@ -185,8 +185,7 @@ private:
* - Field width.
* - Field height.
*/
int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
/**
* Print the field.

View File

@ -64,7 +64,7 @@ void LIB_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_IT
}
int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_ITEM::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
if( Type() != aOther.Type() )
return Type() - aOther.Type();

View File

@ -73,11 +73,19 @@ public:
/**
* The list of flags used by the #compare function.
*
* - NORMAL This compares everything between two #LIB_ITEM objects.
* - UNIT This compare flag ignores unit and convert and pin number information when
* comparing #LIB_ITEM objects for unit comparison.
* - UNIT This flag relaxes unit, conversion and pin number constraints. It is used for
* #LIB_ITEM object unit comparisons.
* - EQUALITY This flag relaxes ordering contstraints so that fields, etc. don't have to
* appear in the same order to be considered equal.
* - ERC This flag relaxes constraints on data that is settable in the schematic editor. It
* compares only symbol-editor-only data.
*/
enum COMPARE_FLAGS : int { NORMAL = 0x00, UNIT = 0x01, EQUALITY = 0x02 };
enum COMPARE_FLAGS : int
{
UNIT = 0x01,
EQUALITY = 0x02,
ERC = 0x04
};
/**
* Provide a user-consumable name of the object type. Perform localization when
@ -285,8 +293,7 @@ protected:
* zero if the object is equal to \a aOther object, or greater than 0 if the
* object is greater than \a aOther object.
*/
virtual int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
virtual int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const;
/**
* Print the item to \a aDC.

View File

@ -870,7 +870,7 @@ EDA_ITEM* LIB_PIN::Clone() const
}
int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_PIN::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_PIN_T );

View File

@ -273,8 +273,7 @@ private:
* - Pin horizontal (X) position.
* - Pin vertical (Y) position.
*/
int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
protected:
wxPoint m_position; // Position of the pin.

View File

@ -66,7 +66,7 @@ EDA_ITEM* LIB_SHAPE::Clone() const
}
int LIB_SHAPE::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_SHAPE::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
int retv = LIB_ITEM::compare( aOther, aCompareFlags );

View File

@ -113,8 +113,7 @@ private:
* - Circle vertical (Y) position.
* - Circle radius.
*/
int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform ) override;

View File

@ -209,7 +209,7 @@ const LIB_SYMBOL& LIB_SYMBOL::operator=( const LIB_SYMBOL& aSymbol )
}
int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags ) const
{
if( m_me == aRhs.m_me )
return 0;
@ -322,17 +322,20 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, LIB_ITEM::COMPARE_FLAGS aCompar
if( m_unitsLocked != aRhs.m_unitsLocked )
return ( m_unitsLocked ) ? 1 : -1;
if( m_showPinNames != aRhs.m_showPinNames )
return ( m_showPinNames ) ? 1 : -1;
if( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
{
if( m_showPinNames != aRhs.m_showPinNames )
return ( m_showPinNames ) ? 1 : -1;
if( m_showPinNumbers != aRhs.m_showPinNumbers )
return ( m_showPinNumbers ) ? 1 : -1;
if( m_showPinNumbers != aRhs.m_showPinNumbers )
return ( m_showPinNumbers ) ? 1 : -1;
if( m_includeInBom != aRhs.m_includeInBom )
return ( m_includeInBom ) ? 1 : -1;
if( m_includeInBom != aRhs.m_includeInBom )
return ( m_includeInBom ) ? 1 : -1;
if( m_includeOnBoard != aRhs.m_includeOnBoard )
return ( m_includeOnBoard ) ? 1 : -1;
if( m_includeOnBoard != aRhs.m_includeOnBoard )
return ( m_includeOnBoard ) ? 1 : -1;
}
return 0;
}

View File

@ -612,8 +612,7 @@ public:
* 1 if this symbol is greater than \a aRhs
* 0 if this symbol is the same as \a aRhs
*/
int Compare( const LIB_SYMBOL& aRhs,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
int Compare( const LIB_SYMBOL& aRhs, int aCompareFlags = 0 ) const;
bool operator==( const LIB_SYMBOL* aSymbol ) const { return this == aSymbol; }
bool operator==( const LIB_SYMBOL& aSymbol ) const

View File

@ -84,7 +84,7 @@ EDA_ITEM* LIB_TEXT::Clone() const
}
int LIB_TEXT::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_TEXT::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_TEXT_T );

View File

@ -117,8 +117,7 @@ private:
* - Text width.
* - Text height.
*/
int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
const TRANSFORM& aTransform ) override;