From 74070afbc6509173de39c748c2686356db72d59b Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 10 Jun 2024 20:14:40 -0400 Subject: [PATCH] Fix a bunch of GCC build warnings compiling the schematic editor. Apparently GCC does not like competing definitions of the == operator. The recent refactoring away of all LIB_ITEM objects created a conflict with the SCH_ITEM == operator definition. This change required some rather ugly comparison changes. There were no unit test failures but that doesn't mean something didn't get broken. --- eeschema/lib_symbol.cpp | 600 ++++++++++++--------------- eeschema/lib_symbol.h | 15 +- eeschema/sch_io/sch_io_lib_cache.cpp | 4 +- eeschema/sch_pin.cpp | 231 ++++++----- eeschema/sch_pin.h | 25 +- eeschema/sch_screen.cpp | 2 - 6 files changed, 419 insertions(+), 458 deletions(-) diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index c2a1c5150f..927492dc1a 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -269,282 +269,6 @@ unsigned LIB_SYMBOL::GetInheritanceDepth() const return depth; } - - -#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); } -#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider ) - -int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const -{ - UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES ); - - if( m_me == aRhs.m_me ) - return 0; - - if( !aReporter && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 ) - { - if( int tmp = m_name.Cmp( aRhs.m_name ) ) - return tmp; - - if( int tmp = m_libId.compare( aRhs.m_libId ) ) - return tmp; - - if( m_parent.lock() < aRhs.m_parent.lock() ) - return -1; - - if( m_parent.lock() > aRhs.m_parent.lock() ) - return 1; - } - - int retv = 0; - - if( m_options != aRhs.m_options ) - { - retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1; - REPORT( _( "Power flag differs." ) ); - - if( !aReporter ) - return retv; - } - - if( int tmp = m_unitCount - aRhs.m_unitCount ) - { - retv = tmp; - REPORT( _( "Unit count differs." ) ); - - if( !aReporter ) - return retv; - } - - // Make sure shapes and pins are sorted. No need with fields as those are - // matched by id/name. - - std::set aShapes; - std::set aFields; - std::set aPins; - - for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it ) - { - if( it->Type() == SCH_SHAPE_T ) - aShapes.insert( &(*it) ); - else if( it->Type() == SCH_FIELD_T ) - aFields.insert( &(*it) ); - else if( it->Type() == SCH_PIN_T ) - aPins.insert( &(*it) ); - } - - std::set bShapes; - std::set bFields; - std::set bPins; - - for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it ) - { - if( it->Type() == SCH_SHAPE_T ) - bShapes.insert( &(*it) ); - else if( it->Type() == SCH_FIELD_T ) - bFields.insert( &(*it) ); - else if( it->Type() == SCH_PIN_T ) - bPins.insert( &(*it) ); - } - - if( int tmp = static_cast( aShapes.size() - bShapes.size() ) ) - { - retv = tmp; - REPORT( _( "Graphic item count differs." ) ); - - if( !aReporter ) - return retv; - } - else - { - for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ ) - { - if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) ) - { - retv = tmp2; - REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) ); - - if( !aReporter ) - return retv; - } - } - } - - if( int tmp = static_cast( aPins.size() - bPins.size() ) ) - { - retv = tmp; - REPORT( _( "Pin count differs." ) ); - - if( !aReporter ) - return retv; - } - else - { - for( const SCH_ITEM* aPinItem : aPins ) - { - const SCH_PIN* aPin = static_cast( aPinItem ); - const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(), - aPin->GetBodyStyle() ); - - if( !bPin ) - { - retv = 1; - REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) ); - - if( !aReporter ) - return retv; - } - else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) ) - { - retv = tmp2; - REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) ); - - if( !aReporter ) - return retv; - } - } - } - - for( const SCH_ITEM* aFieldItem : aFields ) - { - const SCH_FIELD* aField = static_cast( aFieldItem ); - const SCH_FIELD* bField = nullptr; - int tmp = 0; - - if( aField->IsMandatory() ) - bField = aRhs.GetFieldById( aField->GetId() ); - else - bField = aRhs.FindField( aField->GetName() ); - - if( !bField ) - tmp = 1; - else - tmp = aFieldItem->compare( *bField, aCompareFlags ); - - if( tmp ) - { - retv = tmp; - REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) ); - - if( !aReporter ) - return retv; - } - } - - if( int tmp = static_cast( aFields.size() - bFields.size() ) ) - { - retv = tmp; - REPORT( _( "Field count differs." ) ); - - if( !aReporter ) - return retv; - } - - if( int tmp = static_cast( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) ) - { - retv = tmp; - REPORT( _( "Footprint filters differs." ) ); - - if( !aReporter ) - return retv; - } - else - { - for( size_t i = 0; i < m_fpFilters.GetCount(); i++ ) - { - if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) ) - { - retv = tmp2; - REPORT( _( "Footprint filters differ." ) ); - - if( !aReporter ) - return retv; - } - } - } - - if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) ) - { - retv = tmp; - REPORT( _( "Symbol keywords differ." ) ); - - if( !aReporter ) - return retv; - } - - if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset ) - { - retv = tmp; - REPORT( _( "Symbol pin name offsets differ." ) ); - - if( !aReporter ) - return retv; - } - - if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 ) - { - if( m_showPinNames != aRhs.m_showPinNames ) - { - retv = ( m_showPinNames ) ? 1 : -1; - REPORT( _( "Show pin names settings differ." ) ); - - if( !aReporter ) - return retv; - } - - if( m_showPinNumbers != aRhs.m_showPinNumbers ) - { - retv = ( m_showPinNumbers ) ? 1 : -1; - REPORT( _( "Show pin numbers settings differ." ) ); - - if( !aReporter ) - return retv; - } - - if( m_excludedFromSim != aRhs.m_excludedFromSim ) - { - retv = ( m_excludedFromSim ) ? -1 : 1; - REPORT( _( "Exclude from simulation settings differ." ) ); - - if( !aReporter ) - return retv; - } - - if( m_excludedFromBOM != aRhs.m_excludedFromBOM ) - { - retv = ( m_excludedFromBOM ) ? -1 : 1; - REPORT( _( "Exclude from bill of materials settings differ." ) ); - - if( !aReporter ) - return retv; - } - - if( m_excludedFromBoard != aRhs.m_excludedFromBoard ) - { - retv = ( m_excludedFromBoard ) ? -1 : 1; - REPORT( _( "Exclude from board settings differ." ) ); - - if( !aReporter ) - return retv; - } - } - - if( !aReporter ) - { - if( m_unitsLocked != aRhs.m_unitsLocked ) - return ( m_unitsLocked ) ? 1 : -1; - - // Compare unit display names - if( m_unitDisplayNames < aRhs.m_unitDisplayNames ) - return -1; - else if( m_unitDisplayNames > aRhs.m_unitDisplayNames ) - return 1; - } - - return retv; -} - - LIB_SYMBOL_SPTR LIB_SYMBOL::GetRootSymbol() const { const LIB_SYMBOL_SPTR sp = m_parent.lock(); @@ -1820,64 +1544,292 @@ std::vector LIB_SYMBOL::GetUnitDrawItems() } -bool LIB_SYMBOL::operator==( const LIB_SYMBOL& aOther ) const + + +#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); } +#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider ) + +int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const { - if( m_libId != aOther.m_libId ) - return false; + UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES ); - if( m_excludedFromBoard != aOther.m_excludedFromBoard ) - return false; + if( m_me == aRhs.m_me ) + return 0; - if( m_excludedFromBOM != aOther.m_excludedFromBOM ) - return false; - - if( m_excludedFromSim != aOther.m_excludedFromSim ) - return false; - - if( m_flags != aOther.m_flags ) - return false; - - if( m_unitCount != aOther.m_unitCount ) - return false; - - if( m_pinNameOffset != aOther.m_pinNameOffset ) - return false; - - if( m_showPinNames != aOther.m_showPinNames ) - return false; - - if( m_showPinNumbers != aOther.m_showPinNumbers ) - return false; - - if( m_drawings.size() != aOther.m_drawings.size() ) - return false; - - for( auto it1 = m_drawings.begin(), it2 = aOther.m_drawings.begin(); - it1 != m_drawings.end(); ++it1, ++it2 ) + if( !aReporter && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 ) { - if( !( *it1 == *it2 ) ) - return false; + if( int tmp = m_name.Cmp( aRhs.m_name ) ) + return tmp; + + if( int tmp = m_libId.compare( aRhs.m_libId ) ) + return tmp; + + if( m_parent.lock() < aRhs.m_parent.lock() ) + return -1; + + if( m_parent.lock() > aRhs.m_parent.lock() ) + return 1; } - const std::vector thisPinList = GetAllLibPins(); - const std::vector otherPinList = aOther.GetAllLibPins(); + int retv = 0; - if( thisPinList.size() != otherPinList.size() ) - return false; + if( m_options != aRhs.m_options ) + { + retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1; + REPORT( _( "Power flag differs." ) ); - for( auto it1 = thisPinList.begin(), it2 = otherPinList.begin(); - it1 != thisPinList.end(); ++it1, ++it2 ) - { - if( **it1 != **it2 ) - return false; - } - for( size_t ii = 0; ii < thisPinList.size(); ++ii ) - { - if( *thisPinList[ii] != *otherPinList[ii] ) - return false; + if( !aReporter ) + return retv; } - return true; + if( int tmp = m_unitCount - aRhs.m_unitCount ) + { + retv = tmp; + REPORT( _( "Unit count differs." ) ); + + if( !aReporter ) + return retv; + } + + // Make sure shapes and pins are sorted. No need with fields as those are + // matched by id/name. + + std::set aShapes; + std::set aFields; + std::set aPins; + + for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it ) + { + if( it->Type() == SCH_SHAPE_T ) + aShapes.insert( &(*it) ); + else if( it->Type() == SCH_FIELD_T ) + aFields.insert( &(*it) ); + else if( it->Type() == SCH_PIN_T ) + aPins.insert( &(*it) ); + } + + std::set bShapes; + std::set bFields; + std::set bPins; + + for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it ) + { + if( it->Type() == SCH_SHAPE_T ) + bShapes.insert( &(*it) ); + else if( it->Type() == SCH_FIELD_T ) + bFields.insert( &(*it) ); + else if( it->Type() == SCH_PIN_T ) + bPins.insert( &(*it) ); + } + + if( int tmp = static_cast( aShapes.size() - bShapes.size() ) ) + { + retv = tmp; + REPORT( _( "Graphic item count differs." ) ); + + if( !aReporter ) + return retv; + } + else + { + for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ ) + { + if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) ) + { + retv = tmp2; + REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) ); + + if( !aReporter ) + return retv; + } + } + } + + if( int tmp = static_cast( aPins.size() - bPins.size() ) ) + { + retv = tmp; + REPORT( _( "Pin count differs." ) ); + + if( !aReporter ) + return retv; + } + else + { + for( const SCH_ITEM* aPinItem : aPins ) + { + const SCH_PIN* aPin = static_cast( aPinItem ); + const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(), + aPin->GetBodyStyle() ); + + if( !bPin ) + { + retv = 1; + REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) ); + + if( !aReporter ) + return retv; + } + else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) ) + { + retv = tmp2; + REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) ); + + if( !aReporter ) + return retv; + } + } + } + + for( const SCH_ITEM* aFieldItem : aFields ) + { + const SCH_FIELD* aField = static_cast( aFieldItem ); + const SCH_FIELD* bField = nullptr; + int tmp = 0; + + if( aField->IsMandatory() ) + bField = aRhs.GetFieldById( aField->GetId() ); + else + bField = aRhs.FindField( aField->GetName() ); + + if( !bField ) + tmp = 1; + else + tmp = aFieldItem->compare( *bField, aCompareFlags ); + + if( tmp ) + { + retv = tmp; + REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) ); + + if( !aReporter ) + return retv; + } + } + + if( int tmp = static_cast( aFields.size() - bFields.size() ) ) + { + retv = tmp; + REPORT( _( "Field count differs." ) ); + + if( !aReporter ) + return retv; + } + + if( int tmp = static_cast( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) ) + { + retv = tmp; + REPORT( _( "Footprint filters differs." ) ); + + if( !aReporter ) + return retv; + } + else + { + for( size_t i = 0; i < m_fpFilters.GetCount(); i++ ) + { + if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) ) + { + retv = tmp2; + REPORT( _( "Footprint filters differ." ) ); + + if( !aReporter ) + return retv; + } + } + } + + if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) ) + { + retv = tmp; + REPORT( _( "Symbol keywords differ." ) ); + + if( !aReporter ) + return retv; + } + + if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset ) + { + retv = tmp; + REPORT( _( "Symbol pin name offsets differ." ) ); + + if( !aReporter ) + return retv; + } + + if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 ) + { + if( m_showPinNames != aRhs.m_showPinNames ) + { + retv = ( m_showPinNames ) ? 1 : -1; + REPORT( _( "Show pin names settings differ." ) ); + + if( !aReporter ) + return retv; + } + + if( m_showPinNumbers != aRhs.m_showPinNumbers ) + { + retv = ( m_showPinNumbers ) ? 1 : -1; + REPORT( _( "Show pin numbers settings differ." ) ); + + if( !aReporter ) + return retv; + } + + if( m_excludedFromSim != aRhs.m_excludedFromSim ) + { + retv = ( m_excludedFromSim ) ? -1 : 1; + REPORT( _( "Exclude from simulation settings differ." ) ); + + if( !aReporter ) + return retv; + } + + if( m_excludedFromBOM != aRhs.m_excludedFromBOM ) + { + retv = ( m_excludedFromBOM ) ? -1 : 1; + REPORT( _( "Exclude from bill of materials settings differ." ) ); + + if( !aReporter ) + return retv; + } + + if( m_excludedFromBoard != aRhs.m_excludedFromBoard ) + { + retv = ( m_excludedFromBoard ) ? -1 : 1; + REPORT( _( "Exclude from board settings differ." ) ); + + if( !aReporter ) + return retv; + } + } + + if( !aReporter ) + { + if( m_unitsLocked != aRhs.m_unitsLocked ) + return ( m_unitsLocked ) ? 1 : -1; + + // Compare unit display names + if( m_unitDisplayNames < aRhs.m_unitDisplayNames ) + return -1; + else if( m_unitDisplayNames > aRhs.m_unitDisplayNames ) + return 1; + } + + return retv; +} + + +int LIB_SYMBOL::compare( const SCH_ITEM& aOther, int aCompareFlags ) const +{ + if( Type() != aOther.Type() ) + return Type() - aOther.Type(); + + const LIB_SYMBOL* tmp = static_cast( &aOther ); + + wxCHECK( tmp, -1 ); + + return Compare( *tmp, aCompareFlags ); } diff --git a/eeschema/lib_symbol.h b/eeschema/lib_symbol.h index fde69b4de6..fc0e2afb68 100644 --- a/eeschema/lib_symbol.h +++ b/eeschema/lib_symbol.h @@ -578,13 +578,6 @@ public: int Compare( const LIB_SYMBOL& aRhs, int aCompareFlags = 0, REPORTER* aReporter = nullptr ) const; - bool operator==( const LIB_SYMBOL* aSymbol ) const { return this == aSymbol; } - bool operator==( const LIB_SYMBOL& aSymbol ) const; - bool operator!=( const LIB_SYMBOL& aSymbol ) const - { - return Compare( aSymbol, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) != 0; - } - const LIB_SYMBOL& operator=( const LIB_SYMBOL& aSymbol ); /** @@ -631,6 +624,14 @@ private: // We create a different set parent function for this class, so we hide the inherited one. using EDA_ITEM::SetParent; + /** + * The library symbol specific sort order is as follows: + * + * - The result of #SCH_ITEM::compare() + */ + int compare( const SCH_ITEM& aOther, + int aCompareFlags = SCH_ITEM::COMPARE_FLAGS::EQUALITY ) const override; + void deleteAllFields(); private: diff --git a/eeschema/sch_io/sch_io_lib_cache.cpp b/eeschema/sch_io/sch_io_lib_cache.cpp index 97d09f37e2..1dd969e2db 100644 --- a/eeschema/sch_io/sch_io_lib_cache.cpp +++ b/eeschema/sch_io/sch_io_lib_cache.cpp @@ -103,7 +103,7 @@ LIB_SYMBOL* SCH_IO_LIB_CACHE::removeSymbol( LIB_SYMBOL* aSymbol ) // If the entry pointer doesn't match the name it is mapped to in the library, we // have done something terribly wrong. - wxCHECK_MSG( *it->second == aSymbol, nullptr, + wxCHECK_MSG( &*it->second == aSymbol, nullptr, "Pointer mismatch while attempting to remove alias entry <" + aSymbol->GetName() + "> from library cache <" + m_libFileName.GetName() + ">." ); @@ -185,4 +185,4 @@ LIB_SYMBOL* SCH_IO_LIB_CACHE::GetSymbol( const wxString& aName ) } return nullptr; -} \ No newline at end of file +} diff --git a/eeschema/sch_pin.cpp b/eeschema/sch_pin.cpp index 8fdd697345..0930814bf6 100644 --- a/eeschema/sch_pin.cpp +++ b/eeschema/sch_pin.cpp @@ -1345,78 +1345,6 @@ EDA_ITEM* SCH_PIN::Clone() const } -int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const -{ - wxASSERT( aOther.Type() == SCH_PIN_T ); - - const SCH_PIN* tmp = (SCH_PIN*) &aOther; - - // When comparing units, we do not compare the part numbers. If everything else is - // identical, then we can just renumber the parts for the inherited symbol. - if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number ) - return m_number.Cmp( tmp->m_number ); - - int result = m_name.Cmp( tmp->m_name ); - - if( result ) - return result; - - if( m_position.x != tmp->m_position.x ) - return m_position.x - tmp->m_position.x; - - if( m_position.y != tmp->m_position.y ) - return m_position.y - tmp->m_position.y; - - if( m_length != tmp->m_length ) - return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 ); - - if( m_orientation != tmp->m_orientation ) - return static_cast( m_orientation ) - static_cast( tmp->m_orientation ); - - if( m_shape != tmp->m_shape ) - return static_cast( m_shape ) - static_cast( tmp->m_shape ); - - if( m_type != tmp->m_type ) - return static_cast( m_type ) - static_cast( tmp->m_type ); - - if( m_hidden != tmp->m_hidden ) - return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false ); - - if( m_numTextSize != tmp->m_numTextSize ) - return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 ); - - if( m_nameTextSize != tmp->m_nameTextSize ) - return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 ); - - if( m_alternates.size() != tmp->m_alternates.size() ) - return static_cast( m_alternates.size() - tmp->m_alternates.size() ); - - auto lhsItem = m_alternates.begin(); - auto rhsItem = tmp->m_alternates.begin(); - - while( lhsItem != m_alternates.end() ) - { - const ALT& lhsAlt = lhsItem->second; - const ALT& rhsAlt = rhsItem->second; - - int retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name ); - - if( retv ) - return retv; - - if( lhsAlt.m_Type != rhsAlt.m_Type ) - return static_cast( lhsAlt.m_Type ) - static_cast( rhsAlt.m_Type ); - - if( lhsAlt.m_Shape != rhsAlt.m_Shape ) - return static_cast( lhsAlt.m_Shape ) - static_cast( rhsAlt.m_Shape ); - - ++lhsItem; - ++rhsItem; - } - - return 0; -} - void SCH_PIN::ChangeLength( int aLength ) { int lengthChange = GetLength() - aLength; @@ -2028,81 +1956,158 @@ wxString SCH_PIN::getItemDescription( ALT* aAlt ) const } -bool SCH_PIN::operator==( const SCH_PIN& aOther ) const -{ - if( m_number != aOther.m_number ) - return false; - if( m_position != aOther.m_position ) - return false; + +int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const +{ + // Ignore the UUID here. + int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY ); + + if( retv ) + return retv; + + const SCH_PIN* tmp = static_cast( &aOther ); + + wxCHECK( tmp, -1 ); + + // When comparing units, we do not compare the part numbers. If everything else is + // identical, then we can just renumber the parts for the inherited symbol. + // if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number ) + // return m_number.Cmp( tmp->m_number ); + + // int result = m_name.Cmp( tmp->m_name ); + + // if( result ) + // return result; + + // if( m_position.x != tmp->m_position.x ) + // return m_position.x - tmp->m_position.x; + + // if( m_position.y != tmp->m_position.y ) + // return m_position.y - tmp->m_position.y; + + // if( m_length != tmp->m_length ) + // return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 ); + + // if( m_orientation != tmp->m_orientation ) + // return static_cast( m_orientation ) - static_cast( tmp->m_orientation ); + + // if( m_shape != tmp->m_shape ) + // return static_cast( m_shape ) - static_cast( tmp->m_shape ); + + // if( m_type != tmp->m_type ) + // return static_cast( m_type ) - static_cast( tmp->m_type ); + + // if( m_hidden != tmp->m_hidden ) + // return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false ); + + // if( m_numTextSize != tmp->m_numTextSize ) + // return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 ); + + // if( m_nameTextSize != tmp->m_nameTextSize ) + // return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 ); + + // if( m_alternates.size() != tmp->m_alternates.size() ) + // return static_cast( m_alternates.size() - tmp->m_alternates.size() ); + + // auto lhsItem = m_alternates.begin(); + // auto rhsItem = tmp->m_alternates.begin(); + + // while( lhsItem != m_alternates.end() ) + // { + // const ALT& lhsAlt = lhsItem->second; + // const ALT& rhsAlt = rhsItem->second; + + // int retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name ); + + // if( retv ) + // return retv; + + // if( lhsAlt.m_Type != rhsAlt.m_Type ) + // return static_cast( lhsAlt.m_Type ) - static_cast( rhsAlt.m_Type ); + + // if( lhsAlt.m_Shape != rhsAlt.m_Shape ) + // return static_cast( lhsAlt.m_Shape ) - static_cast( rhsAlt.m_Shape ); + + // ++lhsItem; + // ++rhsItem; + // } + + if( m_number != tmp->m_number ) + return m_number.Cmp( tmp->m_number ); + + if( m_position.x != tmp->m_position.x ) + return m_position.x - tmp->m_position.x; + + if( m_position.y != tmp->m_position.y ) + return m_position.y - tmp->m_position.y; if( dynamic_cast( GetParentSymbol() ) ) { - if( m_libPin != aOther.m_libPin ) - return false; + wxCHECK( m_libPin && tmp->m_libPin, -1 ); - if( m_alt != aOther.m_alt ) - return false; + retv = m_libPin->compare( *tmp->m_libPin ); + + if( retv ) + return retv; + + retv = m_alt.Cmp( tmp->m_alt ); + + if( retv ) + return retv; } if( dynamic_cast( GetParentSymbol() ) ) { - if( m_length != aOther.m_length ) - return false; + if( m_length != tmp->m_length ) + return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 ); - if( m_orientation != aOther.m_orientation ) - return false; + if( m_orientation != tmp->m_orientation ) + return static_cast( m_orientation ) - static_cast( tmp->m_orientation ); - if( m_shape != aOther.m_shape ) - return false; + if( m_shape != tmp->m_shape ) + return static_cast( m_shape ) - static_cast( tmp->m_shape ); - if( m_type != aOther.m_type ) - return false; + if( m_type != tmp->m_type ) + return static_cast( m_type ) - static_cast( tmp->m_type ); - if( m_name != aOther.m_name ) - return false; + if( m_hidden != tmp->m_hidden ) + return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false ); - if( m_hidden != aOther.m_hidden ) - return false; + if( m_numTextSize != tmp->m_numTextSize ) + return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 ); - if( m_numTextSize != aOther.m_numTextSize ) - return false; + if( m_nameTextSize != tmp->m_nameTextSize ) + return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 ); - if( m_nameTextSize != aOther.m_nameTextSize ) - return false; - - if( m_alternates.size() != aOther.m_alternates.size() ) - return false; + if( m_alternates.size() != tmp->m_alternates.size() ) + return static_cast( m_alternates.size() - tmp->m_alternates.size() ); auto lhsItem = m_alternates.begin(); - auto rhsItem = aOther.m_alternates.begin(); + auto rhsItem = tmp->m_alternates.begin(); while( lhsItem != m_alternates.end() ) { - if( rhsItem == aOther.m_alternates.end() ) - return false; - const ALT& lhsAlt = lhsItem->second; const ALT& rhsAlt = rhsItem->second; - if( lhsAlt.m_Name != rhsAlt.m_Name ) - return false; + retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name ); + + if( retv ) + return retv; if( lhsAlt.m_Type != rhsAlt.m_Type ) - return false; + return static_cast( lhsAlt.m_Type ) - static_cast( rhsAlt.m_Type ); if( lhsAlt.m_Shape != rhsAlt.m_Shape ) - return false; + return static_cast( lhsAlt.m_Shape ) - static_cast( rhsAlt.m_Shape ); ++lhsItem; ++rhsItem; } - - if( rhsItem != aOther.m_alternates.end() ) - return false; } - return true; + return 0; } diff --git a/eeschema/sch_pin.h b/eeschema/sch_pin.h index 12afd7556d..fd9a250e47 100644 --- a/eeschema/sch_pin.h +++ b/eeschema/sch_pin.h @@ -285,9 +285,7 @@ public: double Similarity( const SCH_ITEM& aOther ) const override; - bool operator==( const SCH_PIN& aOther ) const; - bool operator<( const SCH_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) < 0; } - bool operator>( const SCH_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) > 0; } + bool operator>( const SCH_ITEM& aRhs ) const { return compare( aRhs, EQUALITY ) > 0; } protected: wxString getItemDescription( ALT* aAlt ) const; @@ -330,13 +328,20 @@ protected: private: /** - * @copydoc SCH_ITEM::compare() - * * The pin specific sort order is as follows: - * - Pin number. - * - Pin name, case insensitive compare. - * - Pin horizontal (X) position. - * - Pin vertical (Y) position. + * - The result of #SCH_ITEM::compare() + * - Number + * - Name, case sensitive compare + * - Horizontal (X) position + * - Vertical (Y) position + * - Length + * - Orientation + * - Shape + * - Electrical type + * - Visibility (true > false) + * - Number text size + * - Name text size + * - Alternates, name, type shape */ int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override; @@ -372,4 +377,4 @@ protected: }; -#endif // SCH_PIN_H \ No newline at end of file +#endif // SCH_PIN_H diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 53b3e5d151..004e186d54 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -942,8 +942,6 @@ void SCH_SCREEN::UpdateLocalLibSymbolLinks() auto it = m_libSymbols.find( symbol->GetSchSymbolLibraryName() ); - LIB_SYMBOL* libSymbol = nullptr; - if( it != m_libSymbols.end() ) symbol->SetLibSymbol( it->second );