From 5af18e553c575f00f89c9612b9298ae726169fe4 Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Wed, 13 Jan 2016 14:18:05 -0500 Subject: [PATCH] Compress consecutive numbers in pin summary. For pin numbers ending in digits, consecutive numbers are collapsed to ranges for a better overview. --- eeschema/pin_number.cpp | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/eeschema/pin_number.cpp b/eeschema/pin_number.cpp index dd98f92ec9..45a998f92b 100644 --- a/eeschema/pin_number.cpp +++ b/eeschema/pin_number.cpp @@ -75,13 +75,32 @@ wxString PinNumbers::GetSummary() const if( i == end() ) return ret; - ret = *i; - ++i; + const_iterator begin_of_range = i; + const_iterator last; - for( ; i != end(); ++i ) + for( ;; ) { + last = i; + ++i; + + int rc = ( i != end() ) ? Compare( *last, *i ) : -2; + + assert( rc == -1 || rc == -2 ); + + if( rc == -1 ) + // adjacent elements + continue; + + ret += *begin_of_range; + if( begin_of_range != last ) + { + ret += '-'; + ret += *last; + } + if( i == end() ) + break; + begin_of_range = i; ret += ','; - ret += *i; } return ret; @@ -104,10 +123,10 @@ int PinNumbers::Compare( const PinNumber& lhs, const PinNumber& rhs ) return 0; if( comp1.empty() ) - return -1; + return -2; if( comp2.empty() ) - return 1; + return 2; wxUniChar c1 = comp1[0]; wxUniChar c2 = comp2[0]; @@ -133,18 +152,28 @@ int PinNumbers::Compare( const PinNumber& lhs, const PinNumber& rhs ) comp2.ToDouble( &val2 ); if( val1 < val2 ) - return -1; + { + if( val1 == val2 - 1 ) + return -1; + else + return -2; + } if( val1 > val2 ) - return 1; + { + if( val1 == val2 + 1 ) + return 1; + else + return 2; + } } else - return -1; + return -2; } else { if( isdigit( c2 ) || c2 == '-' || c2 == '+' ) - return 1; + return 2; int res = comp1.Cmp( comp2 );