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
This commit is contained in:
Jeff Young 2022-03-03 12:20:30 +00:00
parent 27db23eba0
commit 76535d8572
15 changed files with 39 additions and 34 deletions

View File

@ -756,8 +756,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

@ -190,7 +190,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

@ -187,8 +187,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

@ -71,7 +71,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
@ -294,8 +302,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

@ -884,7 +884,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

@ -275,8 +275,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:
VECTOR2I 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

@ -103,8 +103,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 VECTOR2I& 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,6 +322,8 @@ 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( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
{
if( m_showPinNames != aRhs.m_showPinNames )
return ( m_showPinNames ) ? 1 : -1;
@ -333,6 +335,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, LIB_ITEM::COMPARE_FLAGS aCompar
if( m_includeOnBoard != aRhs.m_includeOnBoard )
return ( m_includeOnBoard ) ? 1 : -1;
}
return 0;
}

View File

@ -618,8 +618,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

@ -119,8 +119,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 VECTOR2I& aOffset, void* aData,
const TRANSFORM& aTransform ) override;

View File

@ -138,7 +138,7 @@ VECTOR2I LIB_TEXTBOX::GetDrawPos() const
}
int LIB_TEXTBOX::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
int LIB_TEXTBOX::compare( const LIB_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_TEXTBOX_T );

View File

@ -96,8 +96,7 @@ public:
void ViewGetLayers( int aLayers[], int& aCount ) const override;
private:
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 VECTOR2I& aOffset, void* aData,
const TRANSFORM& aTransform ) override;