kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #22210
[PATCH 1/5] Split off pin number comparison
Pin numbers need to be ordered in more places in the future, so fold this
out of the pin table dialog into a utility class.
---
eeschema/CMakeLists.txt | 1 +
eeschema/dialogs/dialog_lib_edit_pin_table.cpp | 112 +--------------------
eeschema/pin_number.cpp | 134 +++++++++++++++++++++++++
eeschema/pin_number.h | 38 +++++++
4 files changed, 177 insertions(+), 108 deletions(-)
create mode 100644 eeschema/pin_number.cpp
create mode 100644 eeschema/pin_number.h
diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index 3079318..c8d9a46 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -132,6 +132,7 @@ set( EESCHEMA_SRCS
onrightclick.cpp
operations_on_items_lists.cpp
pinedit.cpp
+ pin_number.cpp
plot_schematic_DXF.cpp
plot_schematic_HPGL.cpp
plot_schematic_PS.cpp
diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
index dc39b53..b94cf26 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp
@@ -2,6 +2,8 @@
#include "lib_pin.h"
+#include "pin_number.h"
+
#include <boost/algorithm/string/join.hpp>
#include <queue>
@@ -283,118 +285,12 @@ unsigned int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::GetChildren( const wxData
namespace {
-wxString GetNextComponent( const wxString& str, wxString::size_type& cursor )
-{
- if( str.size() <= cursor )
- return wxEmptyString;
-
- wxString::size_type begin = cursor;
-
- wxUniChar c = str[cursor];
-
- if( isdigit( c ) || c == '+' || c == '-' )
- {
- // number, possibly with sign
- while( ++cursor < str.size() )
- {
- c = str[cursor];
-
- if( isdigit( c ) || c == 'v' || c == 'V' )
- continue;
- else
- break;
- }
- }
- else
- {
- while( ++cursor < str.size() )
- {
- c = str[cursor];
-
- if( isdigit( c ) )
- break;
- else
- continue;
- }
- }
-
- return str.substr( begin, cursor - begin );
-}
-
-
-int ComparePinNames( const wxString& lhs, const wxString& rhs )
-{
- wxString::size_type cursor1 = 0;
- wxString::size_type cursor2 = 0;
-
- wxString comp1, comp2;
-
- for( ; ; )
- {
- comp1 = GetNextComponent( lhs, cursor1 );
- comp2 = GetNextComponent( rhs, cursor2 );
-
- if( comp1.empty() && comp2.empty() )
- return 0;
-
- if( comp1.empty() )
- return -1;
-
- if( comp2.empty() )
- return 1;
-
- wxUniChar c1 = comp1[0];
- wxUniChar c2 = comp2[0];
-
- if( isdigit( c1 ) || c1 == '-' || c1 == '+' )
- {
- if( isdigit( c2 ) || c2 == '-' || c2 == '+' )
- {
- // numeric comparison
- wxString::size_type v1 = comp1.find_first_of( "vV" );
-
- if( v1 != wxString::npos )
- comp1[v1] = '.';
-
- wxString::size_type v2 = comp2.find_first_of( "vV" );
-
- if( v2 != wxString::npos )
- comp2[v2] = '.';
-
- double val1, val2;
-
- comp1.ToDouble( &val1 );
- comp2.ToDouble( &val2 );
-
- if( val1 < val2 )
- return -1;
-
- if( val1 > val2 )
- return 1;
- }
- else
- return -1;
- }
- else
- {
- if( isdigit( c2 ) || c2 == '-' || c2 == '+' )
- return 1;
-
- int res = comp1.Cmp( comp2 );
-
- if( res != 0 )
- return res;
- }
- }
-}
-
-
class CompareLess
{
public:
bool operator()( const wxString& lhs, const wxString& rhs )
{
- return ComparePinNames( lhs, rhs ) == -1;
+ return PinNumbers::Compare( lhs, rhs ) == -1;
}
};
}
@@ -413,7 +309,7 @@ int DIALOG_LIB_EDIT_PIN_TABLE::DataViewModel::Compare( const wxDataViewItem& aIt
GetValue( var2, aItem2, aCol );
wxString str2 = var2.GetString();
- int res = ComparePinNames( str1, str2 );
+ int res = PinNumbers::Compare( str1, str2 );
if( res == 0 )
res = ( aItem1.GetID() < aItem2.GetID() ) ? -1 : 1;
diff --git a/eeschema/pin_number.cpp b/eeschema/pin_number.cpp
new file mode 100644
index 0000000..9f5f9ea
--- /dev/null
+++ b/eeschema/pin_number.cpp
@@ -0,0 +1,134 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2015 Simon Richter
+ * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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
+ */
+
+#include "pin_number.h"
+
+namespace {
+
+wxString GetNextComponent( const wxString& str, wxString::size_type& cursor )
+{
+ if( str.size() <= cursor )
+ return wxEmptyString;
+
+ wxString::size_type begin = cursor;
+
+ wxUniChar c = str[cursor];
+
+ if( isdigit( c ) || c == '+' || c == '-' )
+ {
+ // number, possibly with sign
+ while( ++cursor < str.size() )
+ {
+ c = str[cursor];
+
+ if( isdigit( c ) || c == 'v' || c == 'V' )
+ continue;
+ else
+ break;
+ }
+ }
+ else
+ {
+ while( ++cursor < str.size() )
+ {
+ c = str[cursor];
+
+ if( isdigit( c ) )
+ break;
+ else
+ continue;
+ }
+ }
+
+ return str.substr( begin, cursor - begin );
+}
+
+}
+
+
+int PinNumbers::Compare( const PinNumber& lhs, const PinNumber& rhs )
+{
+ wxString::size_type cursor1 = 0;
+ wxString::size_type cursor2 = 0;
+
+ wxString comp1, comp2;
+
+ for( ; ; )
+ {
+ comp1 = GetNextComponent( lhs, cursor1 );
+ comp2 = GetNextComponent( rhs, cursor2 );
+
+ if( comp1.empty() && comp2.empty() )
+ return 0;
+
+ if( comp1.empty() )
+ return -1;
+
+ if( comp2.empty() )
+ return 1;
+
+ wxUniChar c1 = comp1[0];
+ wxUniChar c2 = comp2[0];
+
+ if( isdigit( c1 ) || c1 == '-' || c1 == '+' )
+ {
+ if( isdigit( c2 ) || c2 == '-' || c2 == '+' )
+ {
+ // numeric comparison
+ wxString::size_type v1 = comp1.find_first_of( "vV" );
+
+ if( v1 != wxString::npos )
+ comp1[v1] = '.';
+
+ wxString::size_type v2 = comp2.find_first_of( "vV" );
+
+ if( v2 != wxString::npos )
+ comp2[v2] = '.';
+
+ double val1, val2;
+
+ comp1.ToDouble( &val1 );
+ comp2.ToDouble( &val2 );
+
+ if( val1 < val2 )
+ return -1;
+
+ if( val1 > val2 )
+ return 1;
+ }
+ else
+ return -1;
+ }
+ else
+ {
+ if( isdigit( c2 ) || c2 == '-' || c2 == '+' )
+ return 1;
+
+ int res = comp1.Cmp( comp2 );
+
+ if( res != 0 )
+ return res;
+ }
+ }
+}
diff --git a/eeschema/pin_number.h b/eeschema/pin_number.h
new file mode 100644
index 0000000..c337d72
--- /dev/null
+++ b/eeschema/pin_number.h
@@ -0,0 +1,38 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2015 Simon Richter
+ * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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
+ */
+
+#ifndef PIN_NUMBER_H_
+#define PIN_NUMBER_H_ 1
+
+#include <wx/string.h>
+
+typedef wxString PinNumber;
+
+class PinNumbers
+{
+public:
+ static int Compare( PinNumber const &lhs, PinNumber const &rhs );
+};
+
+#endif
Follow ups
References