2016-01-13 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Simon Richter
|
2021-10-06 02:46:53 +00:00
|
|
|
* Copyright (C) 2015 KiCad Developers, see AUTHORS.TXT for contributors.
|
2016-01-13 19:13:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-07-28 18:50:17 +00:00
|
|
|
#include "pin_numbers.h"
|
2019-03-14 16:17:02 +00:00
|
|
|
#include <wx/crt.h>
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
wxString GetNextSymbol( const wxString& str, wxString::size_type& cursor )
|
2016-01-13 19:13:38 +00:00
|
|
|
{
|
|
|
|
if( str.size() <= cursor )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxString::size_type begin = cursor;
|
|
|
|
|
2019-03-04 19:40:23 +00:00
|
|
|
wxChar c = str[cursor];
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c ) || c == '+' || c == '-' )
|
2016-01-13 19:13:38 +00:00
|
|
|
{
|
|
|
|
// number, possibly with sign
|
|
|
|
while( ++cursor < str.size() )
|
|
|
|
{
|
|
|
|
c = str[cursor];
|
|
|
|
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c ) || c == 'v' || c == 'V' )
|
2016-01-13 19:13:38 +00:00
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while( ++cursor < str.size() )
|
|
|
|
{
|
|
|
|
c = str[cursor];
|
|
|
|
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c ) )
|
2016-01-13 19:13:38 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str.substr( begin, cursor - begin );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-28 18:50:17 +00:00
|
|
|
wxString PIN_NUMBERS::GetSummary() const
|
2016-01-13 19:17:54 +00:00
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
|
|
|
|
const_iterator i = begin();
|
|
|
|
if( i == end() )
|
|
|
|
return ret;
|
|
|
|
|
2016-01-13 19:18:05 +00:00
|
|
|
const_iterator begin_of_range = i;
|
|
|
|
const_iterator last;
|
2016-01-13 19:17:54 +00:00
|
|
|
|
2016-01-13 19:18:05 +00:00
|
|
|
for( ;; )
|
2016-01-13 19:17:54 +00:00
|
|
|
{
|
2016-01-13 19:18:05 +00:00
|
|
|
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;
|
2016-01-13 19:17:54 +00:00
|
|
|
ret += ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-19 04:44:13 +00:00
|
|
|
wxString PIN_NUMBERS::GetDuplicates() const
|
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
|
|
|
|
for( const wxString& pinNumber : duplicate_pins )
|
|
|
|
{
|
|
|
|
ret += pinNumber;
|
|
|
|
ret += ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the trailing comma
|
|
|
|
ret.RemoveLast();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
int PIN_NUMBERS::Compare( const wxString& lhs, const wxString& rhs )
|
2016-01-13 19:13:38 +00:00
|
|
|
{
|
|
|
|
wxString::size_type cursor1 = 0;
|
|
|
|
wxString::size_type cursor2 = 0;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
wxString symbol1, symbol2;
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
2020-11-15 17:03:27 +00:00
|
|
|
symbol1 = GetNextSymbol( lhs, cursor1 );
|
|
|
|
symbol2 = GetNextSymbol( rhs, cursor2 );
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( symbol1.empty() && symbol2.empty() )
|
2016-01-13 19:13:38 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( symbol1.empty() )
|
2016-01-13 19:18:05 +00:00
|
|
|
return -2;
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( symbol2.empty() )
|
2016-01-13 19:18:05 +00:00
|
|
|
return 2;
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
wxChar c1 = symbol1[0];
|
|
|
|
wxChar c2 = symbol2[0];
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c1 ) || c1 == '-' || c1 == '+' )
|
2016-01-13 19:13:38 +00:00
|
|
|
{
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c2 ) || c2 == '-' || c2 == '+' )
|
2016-01-13 19:13:38 +00:00
|
|
|
{
|
|
|
|
// numeric comparison
|
2020-11-15 17:03:27 +00:00
|
|
|
wxString::size_type v1 = symbol1.find_first_of( "vV" );
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
if( v1 != wxString::npos )
|
2020-11-15 17:03:27 +00:00
|
|
|
symbol1[v1] = '.';
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
wxString::size_type v2 = symbol2.find_first_of( "vV" );
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
if( v2 != wxString::npos )
|
2020-11-15 17:03:27 +00:00
|
|
|
symbol2[v2] = '.';
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
double val1, val2;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
symbol1.ToCDouble( &val1 );
|
|
|
|
symbol2.ToCDouble( &val2 );
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
if( val1 < val2 )
|
2016-01-13 19:18:05 +00:00
|
|
|
{
|
|
|
|
if( val1 == val2 - 1 )
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return -2;
|
|
|
|
}
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
if( val1 > val2 )
|
2016-01-13 19:18:05 +00:00
|
|
|
{
|
|
|
|
if( val1 == val2 + 1 )
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
}
|
2016-01-13 19:13:38 +00:00
|
|
|
}
|
|
|
|
else
|
2016-01-13 19:18:05 +00:00
|
|
|
return -2;
|
2016-01-13 19:13:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 19:40:23 +00:00
|
|
|
if( wxIsdigit( c2 ) || c2 == '-' || c2 == '+' )
|
2016-01-13 19:18:05 +00:00
|
|
|
return 2;
|
2016-01-13 19:13:38 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
int res = symbol1.Cmp( symbol2 );
|
2016-01-13 19:13:38 +00:00
|
|
|
|
|
|
|
if( res != 0 )
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|