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.)
This commit is contained in:
parent
d1a679e496
commit
90df7a8b22
|
@ -815,15 +815,6 @@ void SCH_REFERENCE::Split()
|
||||||
wxString SCH_REFERENCE_LIST::Shorthand( std::vector<SCH_REFERENCE> aList )
|
wxString SCH_REFERENCE_LIST::Shorthand( std::vector<SCH_REFERENCE> aList )
|
||||||
{
|
{
|
||||||
wxString retVal;
|
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() )
|
while( i < aList.size() )
|
||||||
|
|
|
@ -271,15 +271,25 @@ public:
|
||||||
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
|
if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
|
||||||
{
|
{
|
||||||
// Remove duplicates (other units of multi-unit parts)
|
// Remove duplicates (other units of multi-unit parts)
|
||||||
|
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;
|
||||||
|
} );
|
||||||
|
|
||||||
auto logicalEnd = std::unique( references.begin(), references.end(),
|
auto logicalEnd = std::unique( references.begin(), references.end(),
|
||||||
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r )
|
[]( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
|
||||||
{
|
{
|
||||||
// If unannotated then we can't tell what units belong together
|
// If unannotated then we can't tell what units belong together
|
||||||
// so we have to leave them all
|
// so we have to leave them all
|
||||||
if( l.GetRefNumber() == wxT( "?" ) )
|
if( l.GetRefNumber() == wxT( "?" ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return( l.GetRef() == r.GetRef() && l.GetRefNumber() == r.GetRefNumber() );
|
wxString l_ref( l.GetRef() << l.GetRefNumber() );
|
||||||
|
wxString r_ref( r.GetRef() << r.GetRefNumber() );
|
||||||
|
return l_ref == r_ref;
|
||||||
} );
|
} );
|
||||||
references.erase( logicalEnd, references.end() );
|
references.erase( logicalEnd, references.end() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue