← Back to team overview

kicad-developers team mailing list archive

[PATCH 22/27] ElectricPinType: move text lookup

 

---
 eeschema/CMakeLists.txt |  1 +
 eeschema/erc.cpp        |  8 +++---
 eeschema/lib_pin.cpp    | 27 ++----------------
 eeschema/lib_pin.h      |  9 +-----
 eeschema/pin_type.cpp   | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 eeschema/pin_type.h     |  5 ++++
 6 files changed, 86 insertions(+), 37 deletions(-)
 create mode 100644 eeschema/pin_type.cpp

diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index 16a57fc..bc911f0 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -132,6 +132,7 @@ set( EESCHEMA_SRCS
     operations_on_items_lists.cpp
     pinedit.cpp
     pin_shape.cpp
+    pin_type.cpp
     plot_schematic_DXF.cpp
     plot_schematic_HPGL.cpp
     plot_schematic_PS.cpp
diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp
index 7d78cd1..8fa25fc 100644
--- a/eeschema/erc.cpp
+++ b/eeschema/erc.cpp
@@ -282,7 +282,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
         {
             msg.Printf( _( "Pin %s (%s) of component %s is unconnected." ),
                         GetChars( string_pinnum ),
-                        GetChars( LIB_PIN::GetElectricalTypeName( ii ) ),
+                        GetChars( GetText( ii ) ),
                         GetChars( cmp_ref ) );
             marker->SetData( ERCE_PIN_NOT_CONNECTED,
                              aNetItemRef->m_Start,
@@ -299,7 +299,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
 
             msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ),
                         GetChars( string_pinnum ),
-                        GetChars( LIB_PIN::GetElectricalTypeName( ii ) ),
+                        GetChars( GetText( ii ) ),
                         GetChars( cmp_ref ),
                         aNetItemRef->GetNet() );
             marker->SetData( ERCE_PIN_NOT_DRIVEN,
@@ -341,12 +341,12 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
 
         msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
                     GetChars( string_pinnum ),
-                    GetChars( LIB_PIN::GetElectricalTypeName( ii ) ),
+                    GetChars( GetText( ii ) ),
                     GetChars( cmp_ref ) );
         marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
         msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
                     GetChars( alt_string_pinnum ),
-                    GetChars( LIB_PIN::GetElectricalTypeName( jj ) ),
+                    GetChars( GetText( jj ) ),
                     GetChars( alt_cmp ),
                     aNetItemRef->GetNet() );
         marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index b974438..b0852ef 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -145,29 +145,6 @@ static const wxString getPinOrientationName( unsigned aPinOrientationCode )
     return pin_orientation_names[ aPinOrientationCode ];
 }
 
-const wxString LIB_PIN::GetElectricalTypeName( ElectricPinType aPinsElectricalType )
-{
-    const wxString pin_electrical_type_names[] =
-    {   // Keep these translated strings not static
-        _( "Input" ),
-        _( "Output" ),
-        _( "Bidirectional" ),
-        _( "Tri-state" ),
-        _( "Passive" ),
-        _( "Unspecified" ),
-        _( "Power input" ),
-        _( "Power output" ),
-        _( "Open collector" ),
-        _( "Open emitter" ),
-        _( "Not connected" )
-    };
-
-    if( aPinsElectricalType > PIN_ELECTRICAL_TYPE_CNT )
-        return wxT( "???" );
-
-    return pin_electrical_type_names[ aPinsElectricalType ];
-}
-
 /// Utility for getting the size of the 'internal' pin decorators (as a radius)
 // i.e. the clock symbols (falling clock is actually external but is of
 // the same kind)
@@ -2006,7 +1983,7 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
     aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
 
     aList.push_back( MSG_PANEL_ITEM( _( "Type" ),
-                                     LIB_PIN::GetElectricalTypeName( m_type ),
+                                     GetText( m_type ),
                                      RED ) );
 
     text = GetText( m_shape );
@@ -2209,7 +2186,7 @@ wxArrayString LIB_PIN::GetElectricalTypeNames( void )
     wxArrayString tmp;
 
     for( unsigned ii = 0; ii < PIN_ELECTRICAL_TYPE_CNT; ii++ )
-        tmp.Add( LIB_PIN::GetElectricalTypeName( static_cast<ElectricPinType>( ii ) ) );
+        tmp.Add( GetText( static_cast<ElectricPinType>( ii ) ) );
 
     return tmp;
 }
diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h
index 3cfc8da..d77a2d9 100644
--- a/eeschema/lib_pin.h
+++ b/eeschema/lib_pin.h
@@ -254,19 +254,12 @@ public:
     }
 
     /**
-     * return a translated string for messages giving the electrical type of a pin.
-     * @param aType is the electrical type (see enum ElectricPinType )
-     * @return The electrical name of the pin (see enun MsgPinElectricType for names).
-     */
-    static const wxString GetElectricalTypeName( ElectricPinType aType );
-
-    /**
      * return a translated string for messages giving the electrical type of the pin.
      * @return The electrical name of the pin.
      */
     wxString const GetElectricalTypeName() const
     {
-        return GetElectricalTypeName( m_type );
+        return GetText( m_type );
     }
 
     /**
diff --git a/eeschema/pin_type.cpp b/eeschema/pin_type.cpp
new file mode 100644
index 0000000..b80e257
--- /dev/null
+++ b/eeschema/pin_type.cpp
@@ -0,0 +1,73 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2004-2015 KiCad Developers, see change_log.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 2
+ * 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
+ */
+
+/**
+ * @file pin_type.cpp
+ * @brief Electrical pin type handling
+ */
+
+#include "pin_type.h"
+
+#include <macros.h>
+
+wxString GetText( ElectricPinType aType )
+{
+    switch( aType )
+    {
+    case PIN_INPUT:
+        return _( "Input" );
+
+    case PIN_OUTPUT:
+        return _( "Output" );
+
+    case PIN_BIDI:
+        return _( "Bidirectional" );
+
+    case PIN_TRISTATE:
+        return _( "Tri-state" );
+
+    case PIN_PASSIVE:
+        return _( "Passive" );
+
+    case PIN_UNSPECIFIED:
+        return _( "Unspecified" );
+
+    case PIN_POWER_IN:
+        return _( "Power input" );
+
+    case PIN_POWER_OUT:
+        return _( "Power output" );
+
+    case PIN_OPENCOLLECTOR:
+        return _( "Open collector" );
+
+    case PIN_OPENEMITTER:
+        return _( "Open emitter" );
+
+    case PIN_NC:
+        return _( "Not connected" );
+    };
+
+    assert( !"invalid pin type" );
+    return wxT( "???" );
+}
diff --git a/eeschema/pin_type.h b/eeschema/pin_type.h
index d1bfbcc..3910cb2 100644
--- a/eeschema/pin_type.h
+++ b/eeschema/pin_type.h
@@ -28,6 +28,8 @@
 #ifndef PIN_TYPE_H_
 #define PIN_TYPE_H_
 
+#include <wx/string.h>
+
 /**
  * The component library pin object electrical types used in ERC tests.
  */
@@ -49,4 +51,7 @@ enum {
     PINTYPE_COUNT = PIN_NC + 1
 };
 
+// UI
+wxString GetText( ElectricPinType );
+
 #endif

Follow ups

References