← Back to team overview

kicad-developers team mailing list archive

[PATCH 12/27] PinShape: move text lookup

 

---
 eeschema/CMakeLists.txt |  1 +
 eeschema/lib_pin.cpp    | 29 +++------------------
 eeschema/pin_shape.cpp  | 67 +++++++++++++++++++++++++++++++++++++++++++++++++
 eeschema/pin_shape.h    |  5 ++++
 4 files changed, 76 insertions(+), 26 deletions(-)
 create mode 100644 eeschema/pin_shape.cpp

diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index a14ac02..026ea06 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -131,6 +131,7 @@ set( EESCHEMA_SRCS
     onrightclick.cpp
     operations_on_items_lists.cpp
     pinedit.cpp
+    pin_shape.cpp
     plot_schematic_DXF.cpp
     plot_schematic_HPGL.cpp
     plot_schematic_PS.cpp
diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index 813e912..8a31e34 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -184,29 +184,6 @@ const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType )
     return pin_electrical_type_names[ aPinsElectricalType ];
 }
 
-static const wxString getPinStyleName( PinShape aPinsStyle )
-{
-    const wxString pin_style_names[] =
-    {   // Keep these translated strings not static
-        _( "Line" ),
-        _( "Inverted" ),
-        _( "Clock" ),
-        _( "Inverted clock" ),
-        _( "Input low" ),
-        _( "Clock low" ),
-        _( "Output low" ),
-        _( "Falling edge clock" ),
-        _( "NonLogic" ),
-        wxT( "???" )
-    };
-
-    if( aPinsStyle < 0 || aPinsStyle > int( PINSHAPE_COUNT ) )
-        aPinsStyle = static_cast<PinShape>( PINSHAPE_COUNT );
-
-    return pin_style_names[ aPinsStyle ];
-}
-
-
 /// 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)
@@ -2052,7 +2029,7 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
                                      LIB_PIN::GetElectricalTypeName( m_type ),
                                      RED ) );
 
-    text = getPinStyleName( m_shape );
+    text = GetText( m_shape );
 
     aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
 
@@ -2252,7 +2229,7 @@ wxArrayString LIB_PIN::GetStyleNames( void )
     wxArrayString tmp;
 
     for( unsigned ii = 0; ii < PINSHAPE_COUNT; ii++ )
-        tmp.Add( getPinStyleName( static_cast<PinShape>( ii ) ) );
+        tmp.Add( GetText( static_cast<PinShape>( ii ) ) );
 
     return tmp;
 }
@@ -2298,7 +2275,7 @@ wxString LIB_PIN::GetSelectMenuText() const
     wxString tmp;
     wxString style;
 
-    style = getPinStyleName( m_shape );
+    style = GetText( m_shape );
 
     tmp.Printf( _( "Pin %s, %s, %s" ),
                 GetChars( GetNumberString() ),
diff --git a/eeschema/pin_shape.cpp b/eeschema/pin_shape.cpp
new file mode 100644
index 0000000..19a7ff2
--- /dev/null
+++ b/eeschema/pin_shape.cpp
@@ -0,0 +1,67 @@
+/*
+ * 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_shape.cpp
+ * @brief Pin shape handling
+ */
+
+#include "pin_shape.h"
+
+#include <macros.h>
+
+wxString GetText( PinShape shape )
+{
+    switch( shape )
+    {
+    case PINSHAPE_LINE:
+        return _( "Line" );
+
+    case PINSHAPE_INVERTED:
+        return _( "Inverted" );
+
+    case PINSHAPE_CLOCK:
+        return _( "Clock" );
+
+    case PINSHAPE_INVERTED_CLOCK:
+        return _( "Inverted clock" );
+
+    case PINSHAPE_INPUT_LOW:
+        return _( "Input low" );
+
+    case PINSHAPE_CLOCK_LOW:
+        return _( "Clock low" );
+
+    case PINSHAPE_OUTPUT_LOW:
+        return _( "Output low" );
+
+    case PINSHAPE_FALLING_EDGE_CLOCK:
+        return _( "Falling edge clock" );
+
+    case PINSHAPE_NONLOGIC:
+        return _( "NonLogic" );
+    }
+
+    assert( !"Invalid pin shape" );
+    return wxT( "?" );
+}
diff --git a/eeschema/pin_shape.h b/eeschema/pin_shape.h
index 1d96435..d5ea11d 100644
--- a/eeschema/pin_shape.h
+++ b/eeschema/pin_shape.h
@@ -29,6 +29,8 @@
 #ifndef _PIN_SHAPE_H_
 #define _PIN_SHAPE_H_
 
+#include <wx/string.h>
+
 enum PinShape
 {
     PINSHAPE_LINE,
@@ -47,4 +49,7 @@ enum
     PINSHAPE_COUNT = PINSHAPE_NONLOGIC + 1
 };
 
+// UI
+wxString    GetText( PinShape shape );
+
 #endif

Follow ups

References