Sort references before removing duplicates.

std::unique only works within consecutive blocks, so the list must
be sorted first.  (We need it sorted in the end anyway, so no
big deal.)

(cherry picked from commit 90df7a8b22)
This commit is contained in:
Jeff Young 2018-10-08 00:14:07 +01:00
parent e8c8bf8d11
commit 940b08ab85
2 changed files with 20 additions and 19 deletions

View File

@ -815,16 +815,7 @@ void SCH_REFERENCE::Split()
wxString SCH_REFERENCE_LIST::Shorthand( std::vector<SCH_REFERENCE> aList )
{
wxString retVal;
std::sort( aList.begin(), aList.end(),
[]( const SCH_REFERENCE& lhs, const SCH_REFERENCE& rhs ) -> bool
{
wxString lhRef( lhs.GetRef() << lhs.GetRefNumber() );
wxString rhRef( rhs.GetRef() << rhs.GetRefNumber() );
return RefDesStringCompare( lhRef, rhRef ) < 0;
} );
size_t i = 0;
size_t i = 0;
while( i < aList.size() )
{

View File

@ -203,16 +203,26 @@ public:
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
{
// Remove duplicates (other units of multi-unit parts)
auto logicalEnd = std::unique( references.begin(), references.end(),
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r )
{
// If unannotated then we can't tell what units belong together
// so we have to leave them all
if( l.GetRefNumber() == wxT( "?" ) )
return false;
std::sort( references.begin(), references.end(),
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
{
wxString l_ref( l.GetRef() << l.GetRefNumber() );
wxString r_ref( r.GetRef() << r.GetRefNumber() );
return RefDesStringCompare( l_ref, r_ref ) < 0;
} );
return( l.GetRef() == r.GetRef() && l.GetRefNumber() == r.GetRefNumber() );
} );
auto logicalEnd = std::unique( references.begin(), references.end(),
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
{
// If unannotated then we can't tell what units belong together
// so we have to leave them all
if( l.GetRefNumber() == wxT( "?" ) )
return false;
wxString l_ref( l.GetRef() << l.GetRefNumber() );
wxString r_ref( r.GetRef() << r.GetRefNumber() );
return l_ref == r_ref;
} );
references.erase( logicalEnd, references.end() );
}