← Back to team overview

kicad-developers team mailing list archive

[PATCH 2/5] Refactor DrawPinShape

 

DrawPinShape is a bitmask, where only a limited set of values is valid.

 - Replace this with an enum that contains exactly the allowed values
 - Move UI text and bitmap lookups out of LIB_PIN
 - Move widget init code out of dialog, into own widget class
---
 eeschema/CMakeLists.txt                       |   3 +
 eeschema/dialogs/dialog_lib_edit_pin.cpp      |  14 +-
 eeschema/dialogs/dialog_lib_edit_pin.h        |   6 +-
 eeschema/dialogs/dialog_lib_edit_pin_base.cpp |   3 +-
 eeschema/dialogs/dialog_lib_edit_pin_base.fbp |   2 +-
 eeschema/dialogs/dialog_lib_edit_pin_base.h   |   3 +-
 eeschema/lib_pin.cpp                          | 265 ++++++++++++--------------
 eeschema/lib_pin.h                            |  55 +-----
 eeschema/pin_shape.cpp                        | 104 ++++++++++
 eeschema/pin_shape.h                          |  57 ++++++
 eeschema/pinedit.cpp                          |   7 +-
 eeschema/widgets/pin_shape_combobox.cpp       |  69 +++++++
 eeschema/widgets/pin_shape_combobox.h         |  51 +++++
 13 files changed, 426 insertions(+), 213 deletions(-)
 create mode 100644 eeschema/pin_shape.cpp
 create mode 100644 eeschema/pin_shape.h
 create mode 100644 eeschema/widgets/pin_shape_combobox.cpp
 create mode 100644 eeschema/widgets/pin_shape_combobox.h

diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index 1537547..036322c 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -13,6 +13,7 @@ include_directories( BEFORE ${INC_BEFORE} )
 include_directories(
     ./dialogs
     ./netlist_exporters
+    ./widgets
     ../common
     ../common/dialogs
     ${INC_AFTER}
@@ -72,6 +73,7 @@ set( EESCHEMA_DLGS
 
 set( EESCHEMA_WIDGETS
     widgets/widget_eeschema_color_config.cpp
+    widgets/pin_shape_combobox.cpp
     )
 
 
@@ -137,6 +139,7 @@ set( EESCHEMA_SRCS
     operations_on_items_lists.cpp
     pinedit.cpp
     pin_number.cpp
+    pin_shape.cpp
     plot_schematic_DXF.cpp
     plot_schematic_HPGL.cpp
     plot_schematic_PS.cpp
diff --git a/eeschema/dialogs/dialog_lib_edit_pin.cpp b/eeschema/dialogs/dialog_lib_edit_pin.cpp
index f19c125..736d145 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_pin.cpp
@@ -133,7 +133,7 @@ void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event )
     int pinNumSize = ValueFromString( g_UserUnit, GetPadNameTextSize());
     int pinOrient = LIB_PIN::GetOrientationCode( GetOrientation() );
     int pinLength = ValueFromString( g_UserUnit, GetLength() );
-    int pinShape = LIB_PIN::GetStyleCode( GetStyle() );
+    GRAPHIC_PINSHAPE pinShape = GetStyle();
     ELECTRICAL_PINTYPE pinType = GetElectricalType();
 
     m_dummyPin->SetName( GetPinName() );
@@ -174,15 +174,3 @@ void DIALOG_LIB_EDIT_PIN::SetElectricalTypeList( const wxArrayString& list,
             m_choiceElectricalType->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii );
     }
 }
-
-
-void DIALOG_LIB_EDIT_PIN::SetStyleList( const wxArrayString& list, const BITMAP_DEF* aBitmaps )
-{
-    for ( unsigned ii = 0; ii < list.GetCount(); ii++ )
-    {
-        if( aBitmaps == NULL )
-            m_choiceStyle->Append( list[ii] );
-        else
-            m_choiceStyle->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii );
-    }
-}
diff --git a/eeschema/dialogs/dialog_lib_edit_pin.h b/eeschema/dialogs/dialog_lib_edit_pin.h
index 7df0792..a7ddedb 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin.h
+++ b/eeschema/dialogs/dialog_lib_edit_pin.h
@@ -31,6 +31,7 @@
  */
 
 #include <wx/bmpcbox.h>
+#include <pin_shape_combobox.h>
 
 #include <dialog_lib_edit_pin_base.h>
 
@@ -72,9 +73,8 @@ public:
         return (ELECTRICAL_PINTYPE)m_choiceElectricalType->GetSelection();
     }
 
-    void SetStyleList( const wxArrayString& list, const BITMAP_DEF* aBitmaps );
-    void SetStyle( int style ) { m_choiceStyle->SetSelection( style ); }
-    int GetStyle( void ) { return m_choiceStyle->GetSelection(); }
+    void SetStyle( GRAPHIC_PINSHAPE style ) { m_choiceStyle->SetSelection( style ); }
+    GRAPHIC_PINSHAPE GetStyle( void ) { return m_choiceStyle->GetSelection(); }
 
     void SetPinName( const wxString& name ) { m_textPinName->SetValue( name ); }
     wxString GetPinName( void ) { return m_textPinName->GetValue(); }
diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.cpp b/eeschema/dialogs/dialog_lib_edit_pin_base.cpp
index e0f439b..af770d7 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin_base.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_pin_base.cpp
@@ -5,6 +5,7 @@
 // PLEASE DO "NOT" EDIT THIS FILE!
 ///////////////////////////////////////////////////////////////////////////
 
+#include "pin_shape_combobox.h"
 #include "wx/bmpcbox.h"
 
 #include "dialog_lib_edit_pin_base.h"
@@ -68,7 +69,7 @@ DIALOG_LIB_EDIT_PIN_BASE::DIALOG_LIB_EDIT_PIN_BASE( wxWindow* parent, wxWindowID
 	m_staticTextGstyle->Wrap( -1 );
 	fgSizerPins->Add( m_staticTextGstyle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
 	
-	m_choiceStyle = new wxBitmapComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); 
+	m_choiceStyle = new PinShapeComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); 
 	fgSizerPins->Add( m_choiceStyle, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
 	
 	
diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.fbp b/eeschema/dialogs/dialog_lib_edit_pin_base.fbp
index 9afa0bf..f1647ae 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin_base.fbp
+++ b/eeschema/dialogs/dialog_lib_edit_pin_base.fbp
@@ -958,7 +958,7 @@
                                                 <property name="show">1</property>
                                                 <property name="size"></property>
                                                 <property name="style">wxCB_READONLY</property>
-                                                <property name="subclass">wxBitmapComboBox; wx/bmpcbox.h</property>
+                                                <property name="subclass">PinShapeComboBox; pin_shape_combobox.h</property>
                                                 <property name="toolbar_pane">0</property>
                                                 <property name="tooltip"></property>
                                                 <property name="validator_data_type"></property>
diff --git a/eeschema/dialogs/dialog_lib_edit_pin_base.h b/eeschema/dialogs/dialog_lib_edit_pin_base.h
index 0472980..890623b 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin_base.h
+++ b/eeschema/dialogs/dialog_lib_edit_pin_base.h
@@ -12,6 +12,7 @@
 #include <wx/xrc/xmlres.h>
 #include <wx/intl.h>
 class DIALOG_SHIM;
+class PinShapeComboBox;
 class wxBitmapComboBox;
 
 #include "dialog_shim.h"
@@ -66,7 +67,7 @@ class DIALOG_LIB_EDIT_PIN_BASE : public DIALOG_SHIM
 		wxStaticText* m_staticTextEType;
 		wxBitmapComboBox* m_choiceElectricalType;
 		wxStaticText* m_staticTextGstyle;
-		wxBitmapComboBox* m_choiceStyle;
+		PinShapeComboBox* m_choiceStyle;
 		wxCheckBox* m_checkApplyToAllParts;
 		wxCheckBox* m_checkApplyToAllConversions;
 		wxCheckBox* m_checkShow;
diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index bbf7819..976f11e 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -70,38 +70,6 @@ static const BITMAP_DEF iconsPinsOrientations[] =
 };
 
 
-// bitmaps to show pins shapes in dialog editor
-// must have same order than pin_style_names
-static BITMAP_DEF iconsPinsShapes[] =
-{
-    pinshape_normal_xpm,
-    pinshape_invert_xpm,
-    pinshape_clock_normal_xpm,
-    pinshape_clock_invert_xpm,
-    pinshape_active_low_input_xpm,
-    pinshape_clock_active_low_xpm,
-    pinshape_active_low_output_xpm,
-    pinshape_clock_fall_xpm,
-    pinshape_nonlogic_xpm
-};
-
-
-
-static const int pin_style_codes[] =
-{
-    NONE,
-    INVERT,
-    CLOCK,
-    CLOCK | INVERT,
-    LOWLEVEL_IN,
-    LOWLEVEL_IN | CLOCK,
-    LOWLEVEL_OUT,
-    CLOCK_FALL,
-    NONLOGIC
-};
-
-#define PIN_STYLE_CNT DIM( pin_style_codes )
-
 // bitmaps to show pins electrical type in dialog editor
 // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
 static const BITMAP_DEF iconsPinsElectricalType[] =
@@ -200,29 +168,6 @@ const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType )
     return pin_electrical_type_names[ aPinsElectricalType ];
 }
 
-static const wxString getPinStyleName( unsigned 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 > PIN_STYLE_CNT )
-        aPinsStyle = PIN_STYLE_CNT;
-
-    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)
@@ -241,11 +186,11 @@ static int ExternalPinDecoSize( const LIB_PIN &aPin )
 }
 
 LIB_PIN::LIB_PIN( LIB_PART*      aParent ) :
-    LIB_ITEM( LIB_PIN_T, aParent )
+    LIB_ITEM( LIB_PIN_T, aParent ),
+    m_shape( PINSHAPE_LINE )
 {
     m_length = LIB_EDIT_FRAME::GetDefaultPinLength();
     m_orientation = PIN_RIGHT;                  // Pin orient: Up, Down, Left, Right
-    m_shape = NONE;                             // Pin shape, bitwise.
     m_type = PIN_UNSPECIFIED;                   // electrical type of pin
     m_attributes = 0;                           // bit 0 != 0: pin invisible
     m_number = 0;                               // pin number (i.e. 4 ASCII chars)
@@ -378,8 +323,10 @@ void LIB_PIN::SetOrientation( int orientation )
 }
 
 
-void LIB_PIN::SetShape( int aShape )
+void LIB_PIN::SetShape( GRAPHIC_PINSHAPE aShape )
 {
+    assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) );
+
     if( m_shape != aShape )
     {
         m_shape = aShape;
@@ -691,23 +638,55 @@ bool LIB_PIN::Save( OUTPUTFORMATTER& aFormatter )
     if( !IsVisible() && aFormatter.Print( 0, "N" ) < 0 )
         return false;
 
-    if( m_shape & INVERT && aFormatter.Print( 0, "I" ) < 0 )
-        return false;
+    switch( m_shape )
+    {
+    case PINSHAPE_LINE:
+        break;
 
-    if( m_shape & CLOCK && aFormatter.Print( 0, "C" ) < 0 )
-        return false;
+    case PINSHAPE_INVERTED:
+        if( aFormatter.Print( 0, "I" ) < 0 )
+            return false;
+        break;
 
-    if( m_shape & LOWLEVEL_IN && aFormatter.Print( 0, "L" ) < 0 )
-        return false;
+    case PINSHAPE_CLOCK:
+        if( aFormatter.Print( 0, "C" ) < 0 )
+            return false;
+        break;
 
-    if( m_shape & LOWLEVEL_OUT && aFormatter.Print( 0, "V" ) < 0 )
-        return false;
+    case PINSHAPE_INVERTED_CLOCK:
+        if( aFormatter.Print( 0, "IC" ) < 0 )
+            return false;
+        break;
 
-    if( m_shape & CLOCK_FALL && aFormatter.Print( 0, "F" ) < 0 )
-        return false;
+    case PINSHAPE_INPUT_LOW:
+        if( aFormatter.Print( 0, "L" ) < 0 )
+            return false;
+        break;
+
+    case PINSHAPE_CLOCK_LOW:
+        if( aFormatter.Print( 0, "CL" ) < 0 )
+            return false;
+        break;
+
+    case PINSHAPE_OUTPUT_LOW:
+        if( aFormatter.Print( 0, "V" ) < 0 )
+            return false;
+        break;
 
-    if( m_shape & NONLOGIC && aFormatter.Print( 0, "X" ) < 0 )
+    case PINSHAPE_FALLING_EDGE_CLOCK:
+        if( aFormatter.Print( 0, "F" ) < 0 )
+            return false;
+        break;
+
+    case PINSHAPE_NONLOGIC:
+        if( aFormatter.Print( 0, "X" ) < 0 )
+            return false;
+        break;
+
+    default:
+        assert( !"Invalid pin shape" );
         return false;
+    }
 
     if( aFormatter.Print( 0, "\n" ) < 0 )
         return false;
@@ -831,6 +810,18 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
 
     if( prms_count >= 12 )       /* Special Symbol defined */
     {
+        enum
+        {
+            INVERTED        = 1 << 0,
+            CLOCK           = 1 << 1,
+            LOWLEVEL_IN     = 1 << 2,
+            LOWLEVEL_OUT    = 1 << 3,
+            FALLING_EDGE    = 1 << 4,
+            NONLOGIC        = 1 << 5
+        };
+
+        int flags = 0;
+
         for( int j = strlen( pinAttrs ); j > 0; )
         {
             switch( pinAttrs[--j] )
@@ -843,27 +834,27 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
                 break;
 
             case 'I':
-                m_shape |= INVERT;
+                flags |= INVERTED;
                 break;
 
             case 'C':
-                m_shape |= CLOCK;
+                flags |= CLOCK;
                 break;
 
             case 'L':
-                m_shape |= LOWLEVEL_IN;
+                flags |= LOWLEVEL_IN;
                 break;
 
             case 'V':
-                m_shape |= LOWLEVEL_OUT;
+                flags |= LOWLEVEL_OUT;
                 break;
 
             case 'F':
-                m_shape |= CLOCK_FALL;
+                flags |= FALLING_EDGE;
                 break;
 
             case 'X':
-                m_shape |= NONLOGIC;
+                flags |= NONLOGIC;
                 break;
 
             default:
@@ -871,6 +862,49 @@ bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
                 return false;
             }
         }
+
+        switch( flags )
+        {
+        case 0:
+            m_shape = PINSHAPE_LINE;
+            break;
+
+        case INVERTED:
+            m_shape = PINSHAPE_INVERTED;
+            break;
+
+        case CLOCK:
+            m_shape = PINSHAPE_CLOCK;
+            break;
+
+        case INVERTED | CLOCK:
+            m_shape = PINSHAPE_INVERTED_CLOCK;
+            break;
+
+        case LOWLEVEL_IN:
+            m_shape = PINSHAPE_INPUT_LOW;
+            break;
+
+        case LOWLEVEL_IN | CLOCK:
+            m_shape = PINSHAPE_CLOCK_LOW;
+            break;
+
+        case LOWLEVEL_OUT:
+            m_shape = PINSHAPE_OUTPUT_LOW;
+            break;
+
+        case FALLING_EDGE:
+            m_shape = PINSHAPE_FALLING_EDGE_CLOCK;
+            break;
+
+        case NONLOGIC:
+            m_shape = PINSHAPE_NONLOGIC;
+            break;
+
+        default:
+            aErrorMsg.Printf( wxT( "pin attributes do not give a valid pin shape [%s]" ), pinAttrs );
+            return false;
+        }
     }
 
     return true;
@@ -1021,7 +1055,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
         return;
 
 
-    if( m_shape & INVERT )
+    if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK )
     {
         const int radius = ExternalPinDecoSize( *this );
         GRCircle( clipbox, aDC, MapX1 * radius + x1,
@@ -1032,7 +1066,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
                   MapY1 * radius * 2 + y1 );
         GRLineTo( clipbox, aDC, posX, posY, width, color );
     }
-    else if( m_shape & CLOCK_FALL ) /* an alternative for Inverted Clock */
+    else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
     {
         const int clock_size = InternalPinDecoSize( *this );
         if( MapY1 == 0 ) /* MapX1 = +- 1 */
@@ -1059,7 +1093,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
         GRLineTo( clipbox, aDC, posX, posY, width, color );
     }
 
-    if( m_shape & CLOCK )
+    if( m_shape == PINSHAPE_CLOCK || m_shape == PINSHAPE_INVERTED_CLOCK || m_shape == PINSHAPE_CLOCK_LOW )
     {
         const int clock_size = InternalPinDecoSize( *this );
         if( MapY1 == 0 ) /* MapX1 = +- 1 */
@@ -1080,7 +1114,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
         }
     }
 
-    if( m_shape & LOWLEVEL_IN )     /* IEEE symbol "Active Low Input" */
+    if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW )
     {
         const int symbol_size = ExternalPinDecoSize( *this );
         if( MapY1 == 0 )            /* MapX1 = +- 1 */
@@ -1101,7 +1135,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
     }
 
 
-    if( m_shape & LOWLEVEL_OUT )    /* IEEE symbol "Active Low Output" */
+    if( m_shape == PINSHAPE_OUTPUT_LOW )    /* IEEE symbol "Active Low Output" */
     {
         const int symbol_size = ExternalPinDecoSize( *this );
         if( MapY1 == 0 )            /* MapX1 = +- 1 */
@@ -1121,7 +1155,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
                       width, color );
         }
     }
-    else if( m_shape & NONLOGIC ) /* NonLogic pin symbol */
+    else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
     {
         const int symbol_size = ExternalPinDecoSize( *this );
         GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
@@ -1397,7 +1431,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
         break;
     }
 
-    if( m_shape & INVERT )
+    if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK )
     {
         const int radius = ExternalPinDecoSize( *this );
         aPlotter->Circle( wxPoint( MapX1 * radius + x1,
@@ -1410,7 +1444,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
                                     MapY1 * radius * 2 + y1 ) );
         aPlotter->FinishTo( aPosition );
     }
-    else if( m_shape & CLOCK_FALL )
+    else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
     {
         const int clock_size = InternalPinDecoSize( *this );
         if( MapY1 == 0 ) /* MapX1 = +- 1 */
@@ -1436,7 +1470,8 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
         aPlotter->FinishTo( aPosition );
     }
 
-    if( m_shape & CLOCK )
+    if( m_shape == PINSHAPE_CLOCK || m_shape == PINSHAPE_INVERTED_CLOCK ||
+        m_shape == PINSHAPE_CLOCK_LOW )
     {
         const int clock_size = InternalPinDecoSize( *this );
         if( MapY1 == 0 ) /* MapX1 = +- 1 */
@@ -1453,7 +1488,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
         }
     }
 
-    if( m_shape & LOWLEVEL_IN )   /* IEEE symbol "Active Low Input" */
+    if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW )    /* IEEE symbol "Active Low Input" */
     {
         const int symbol_size = ExternalPinDecoSize( *this );
 
@@ -1474,7 +1509,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
     }
 
 
-    if( m_shape & LOWLEVEL_OUT )  /* IEEE symbol "Active Low Output" */
+    if( m_shape == PINSHAPE_OUTPUT_LOW )    /* IEEE symbol "Active Low Output" */
     {
         const int symbol_size = ExternalPinDecoSize( *this );
 
@@ -1489,7 +1524,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
             aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
         }
     }
-    else if( m_shape & NONLOGIC ) /* NonLogic pin symbol */
+    else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
     {
         const int symbol_size = ExternalPinDecoSize( *this );
         aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
@@ -1987,12 +2022,7 @@ void LIB_PIN::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
                                      LIB_PIN::GetElectricalTypeName( m_type ),
                                      RED ) );
 
-    int styleCodeIndex = GetStyleCodeIndex( m_shape );
-
-    if( styleCodeIndex >= 0 )
-        text = getPinStyleName( styleCodeIndex );
-    else
-        text = wxT( "?" );
+    text = GetText( m_shape );
 
     aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
 
@@ -2042,7 +2072,7 @@ const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
     // Actual text height is bigger than text size
     int numberTextHeight  = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
 
-    if( m_shape & INVERT )
+    if( m_shape == PINSHAPE_INVERTED || m_shape == PINSHAPE_INVERTED_CLOCK )
         minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
 
     // calculate top left corner position
@@ -2187,40 +2217,6 @@ void LIB_PIN::Rotate()
 }
 
 
-wxArrayString LIB_PIN::GetStyleNames( void )
-{
-    wxArrayString tmp;
-
-    for( unsigned ii = 0; ii < PIN_STYLE_CNT; ii++ )
-        tmp.Add( getPinStyleName( ii ) );
-
-    return tmp;
-}
-
-
-int LIB_PIN::GetStyleCode( int index )
-{
-    if( index >= 0 && index < (int) PIN_STYLE_CNT )
-        return pin_style_codes[ index ];
-
-    return NONE;
-}
-
-
-int LIB_PIN::GetStyleCodeIndex( int code )
-{
-    size_t i;
-
-    for( i = 0; i < PIN_STYLE_CNT; i++ )
-    {
-        if( pin_style_codes[i] == code )
-            return (int) i;
-    }
-
-    return wxNOT_FOUND;
-}
-
-
 wxArrayString LIB_PIN::GetElectricalTypeNames( void )
 {
     wxArrayString tmp;
@@ -2244,12 +2240,6 @@ const BITMAP_DEF* LIB_PIN::GetOrientationSymbols()
 }
 
 
-const BITMAP_DEF* LIB_PIN::GetStyleSymbols()
-{
-    return iconsPinsShapes;
-}
-
-
 BITMAP_DEF LIB_PIN::GetMenuImage() const
 {
     return iconsPinsElectricalType[m_type];
@@ -2261,12 +2251,7 @@ wxString LIB_PIN::GetSelectMenuText() const
     wxString tmp;
     wxString style;
 
-    int styleCode = GetStyleCodeIndex( m_shape );
-
-    if( styleCode >= 0 )
-        style = getPinStyleName( styleCode );
-    else
-        style = wxT( "?" );
+    style = GetText( m_shape );
 
     tmp.Printf( _( "Pin %s, %s, %s" ),
                 GetChars( GetNumberString() ),
diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h
index 15d5412..a0adef3 100644
--- a/eeschema/lib_pin.h
+++ b/eeschema/lib_pin.h
@@ -32,6 +32,7 @@
 
 #include <lib_draw_item.h>
 
+#include "pin_shape.h"
 
 #define TARGET_PIN_RADIUS   12  // Circle diameter drawn at the active end of pins
 
@@ -59,20 +60,6 @@ enum ELECTRICAL_PINTYPE {
 
 
 /**
- * The component library pin object drawing shapes.
- */
-enum DrawPinShape {
-    NONE         = 0,
-    INVERT       = 1,
-    CLOCK        = 2,
-    LOWLEVEL_IN  = 4,
-    LOWLEVEL_OUT = 8,
-    CLOCK_FALL   = 0x10, /* this is common form for inverted clock in Eastern Block */
-    NONLOGIC     = 0x20
-};
-
-
-/**
  *  The component library pin object orientations.
  */
 enum DrawPinOrient {
@@ -94,7 +81,7 @@ class LIB_PIN : public LIB_ITEM
     wxPoint  m_position;     ///< Position of the pin.
     int      m_length;       ///< Length of the pin.
     int      m_orientation;  ///< Pin orientation (Up, Down, Left, Right)
-    int      m_shape;        ///< Bitwise ORed of pin shapes (see enum DrawPinShape)
+    GRAPHIC_PINSHAPE m_shape;        ///< Shape drawn around pin
     int      m_width;        ///< Line width of the pin.
     ELECTRICAL_PINTYPE m_type;  ///< Electrical type of the pin.  See enum ELECTRICAL_PINTYPE.
     int      m_attributes;   ///< Set bit 0 to indicate pin is invisible.
@@ -263,16 +250,16 @@ public:
 
     void Rotate();
 
-    int GetShape() const { return m_shape; }
+    GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
 
     /**
      * Set the shape of the pin to \a aShape.
      *
      * This will also update the draw style of the pins marked by EnableEditMode().
      *
-     * @param aShape - The draw shape of the pin.  See enum DrawPinShape.
+     * @param aShape - The draw shape of the pin.  See enum GRAPHIC_PINSHAPE.
      */
-    void SetShape( int aShape );
+    void SetShape( GRAPHIC_PINSHAPE aShape );
 
     /**
      * Get the electrical type of the pin.
@@ -479,38 +466,6 @@ public:
     static int GetOrientationCodeIndex( int aCode );
 
     /**
-     * Get a list of pin draw style names.
-     *
-     * @return  List of valid pin draw style names.
-     */
-    static wxArrayString GetStyleNames();
-
-    /**
-     * Get a list of pin styles bitmaps for menus and dialogs.
-     *
-     * @return  List of valid pin electrical type bitmaps symbols in .xpm format.
-     */
-    static const BITMAP_DEF* GetStyleSymbols();
-
-    /**
-     * Get the pin draw style code by index used to set the pin draw style.
-     *
-     * @param aIndex - The index of the pin draw style code to look up.
-     * @return  Pin draw style code if index is valid.  Returns NONE
-     *          style on index error.
-     */
-    static int GetStyleCode( int aIndex );
-
-    /**
-     * Get the index of the pin draw style code.
-     *
-     * @param aCode - The pin draw style code to look up.
-     * @return The index of the pin draw style code if found.  Otherwise,
-     *         return wxNOT_FOUND.
-     */
-    static int GetStyleCodeIndex( int aCode );
-
-    /**
      * Get a list of pin electrical type names.
      *
      * @return  List of valid pin electrical type names.
diff --git a/eeschema/pin_shape.cpp b/eeschema/pin_shape.cpp
new file mode 100644
index 0000000..f59dbb4
--- /dev/null
+++ b/eeschema/pin_shape.cpp
@@ -0,0 +1,104 @@
+/*
+ * 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( GRAPHIC_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( "?" );
+}
+
+
+BITMAP_DEF GetBitmap( GRAPHIC_PINSHAPE shape )
+{
+    switch( shape )
+    {
+    case PINSHAPE_LINE:
+        return pinshape_normal_xpm;
+
+    case PINSHAPE_INVERTED:
+        return pinshape_invert_xpm;
+
+    case PINSHAPE_CLOCK:
+        return pinshape_clock_normal_xpm;
+
+    case PINSHAPE_INVERTED_CLOCK:
+        return pinshape_clock_invert_xpm;
+
+    case PINSHAPE_INPUT_LOW:
+        return pinshape_active_low_input_xpm;
+
+    case PINSHAPE_CLOCK_LOW:
+        return pinshape_clock_active_low_xpm;
+
+    case PINSHAPE_OUTPUT_LOW:
+        return pinshape_active_low_output_xpm;
+
+    case PINSHAPE_FALLING_EDGE_CLOCK:
+        return pinshape_clock_fall_xpm;
+
+    case PINSHAPE_NONLOGIC:
+        return pinshape_nonlogic_xpm;
+    }
+
+    assert( !"Invalid pin shape" );
+    return 0;
+};
diff --git a/eeschema/pin_shape.h b/eeschema/pin_shape.h
new file mode 100644
index 0000000..25f11b9
--- /dev/null
+++ b/eeschema/pin_shape.h
@@ -0,0 +1,57 @@
+/*
+ * 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.h
+ * @brief Pin shape handling
+ */
+
+#ifndef _PIN_SHAPE_H_
+#define _PIN_SHAPE_H_
+
+#include <wx/string.h>
+#include <bitmaps.h>
+
+enum GRAPHIC_PINSHAPE
+{
+    PINSHAPE_LINE,
+    PINSHAPE_INVERTED,
+    PINSHAPE_CLOCK,
+    PINSHAPE_INVERTED_CLOCK,
+    PINSHAPE_INPUT_LOW,
+    PINSHAPE_CLOCK_LOW,
+    PINSHAPE_OUTPUT_LOW,
+    PINSHAPE_FALLING_EDGE_CLOCK,
+    PINSHAPE_NONLOGIC
+};
+
+enum
+{
+    PINSHAPE_COUNT = PINSHAPE_NONLOGIC + 1
+};
+
+// UI
+wxString    GetText( GRAPHIC_PINSHAPE shape );
+BITMAP_DEF  GetBitmap( GRAPHIC_PINSHAPE shape );
+
+#endif
diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp
index b54faf6..c8640bd 100644
--- a/eeschema/pinedit.cpp
+++ b/eeschema/pinedit.cpp
@@ -57,7 +57,7 @@ static wxPoint OldPos;
 static wxPoint PinPreviousPos;
 static ELECTRICAL_PINTYPE LastPinType   = PIN_INPUT;
 static int     LastPinOrient        = PIN_RIGHT;
-static int     LastPinShape         = NONE;
+static GRAPHIC_PINSHAPE LastPinShape = PINSHAPE_LINE;
 static bool    LastPinCommonConvert = false;
 static bool    LastPinCommonUnit    = false;
 static bool    LastPinVisible       = true;
@@ -104,8 +104,7 @@ void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event )
     wxString units = GetUnitsLabel( g_UserUnit );
     dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() );
     dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) );
-    dlg.SetStyleList( LIB_PIN::GetStyleNames(), LIB_PIN::GetStyleSymbols() );
-    dlg.SetStyle( LIB_PIN::GetStyleCodeIndex( pin->GetShape() ) );
+    dlg.SetStyle( pin->GetShape() );
     dlg.SetElectricalTypeList( LIB_PIN::GetElectricalTypeNames(),
                                LIB_PIN::GetElectricalTypeSymbols() );
     dlg.SetElectricalType( pin->GetType() );
@@ -147,7 +146,7 @@ void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event )
     LastPinNumSize = ValueFromString( g_UserUnit, dlg.GetPadNameTextSize() );
     LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() );
     LastPinLength = ValueFromString( g_UserUnit, dlg.GetLength() );
-    LastPinShape = LIB_PIN::GetStyleCode( dlg.GetStyle() );
+    LastPinShape = dlg.GetStyle();
     LastPinType = dlg.GetElectricalType();
     LastPinCommonConvert = dlg.GetAddToAllBodyStyles();
     LastPinCommonUnit = dlg.GetAddToAllParts();
diff --git a/eeschema/widgets/pin_shape_combobox.cpp b/eeschema/widgets/pin_shape_combobox.cpp
new file mode 100644
index 0000000..9bab9ff
--- /dev/null
+++ b/eeschema/widgets/pin_shape_combobox.cpp
@@ -0,0 +1,69 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2015 Simon Richter <Simon.Richter@xxxxxxxxxx>
+ *
+ * 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_combobox.cpp
+ * @brief ComboBox widget for pin shape
+ */
+
+#include "pin_shape_combobox.h"
+
+#include <lib_pin.h>
+
+PinShapeComboBox::PinShapeComboBox( wxWindow* parent,
+        wxWindowID id,
+        const wxString& value,
+        const wxPoint& pos,
+        const wxSize& size,
+        int n,
+        const wxString choices[],
+        long style,
+        const wxValidator& validator,
+        const wxString& name ) :
+    wxBitmapComboBox( parent, id, value, pos, size, n, choices, style, validator, name )
+{
+    for( unsigned ii = 0; ii < PINSHAPE_COUNT; ++ii )
+    {
+        GRAPHIC_PINSHAPE shape = static_cast<GRAPHIC_PINSHAPE>( ii );
+
+        wxString text = GetText( shape );
+        BITMAP_DEF bitmap = GetBitmap( shape );
+
+        if( bitmap == NULL )
+            Append( text );
+        else
+            Insert( text, KiBitmap( bitmap ), ii );
+    }
+}
+
+
+GRAPHIC_PINSHAPE PinShapeComboBox::GetSelection()
+{
+    return static_cast<GRAPHIC_PINSHAPE>( wxBitmapComboBox::GetSelection() );
+}
+
+
+void PinShapeComboBox::SetSelection( GRAPHIC_PINSHAPE aShape )
+{
+    wxBitmapComboBox::SetSelection( aShape );
+}
diff --git a/eeschema/widgets/pin_shape_combobox.h b/eeschema/widgets/pin_shape_combobox.h
new file mode 100644
index 0000000..659aa02
--- /dev/null
+++ b/eeschema/widgets/pin_shape_combobox.h
@@ -0,0 +1,51 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2015 Simon Richter <Simon.Richter@xxxxxxxxxx>
+ *
+ * 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_combobox.h
+ * @brief ComboBox widget for pin shape
+ */
+
+#include <wx/bmpcbox.h>
+
+#include <pin_shape.h>
+
+class PinShapeComboBox : public wxBitmapComboBox
+{
+public:
+    /// @todo C++11: replace with forwarder
+
+    PinShapeComboBox( wxWindow* parent,
+            wxWindowID id = wxID_ANY,
+            const wxString& value = wxEmptyString,
+            const wxPoint& pos = wxDefaultPosition,
+            const wxSize& size = wxDefaultSize,
+            int n = 0,
+            const wxString choices[] = NULL,
+            long style = 0,
+            const wxValidator& validator = wxDefaultValidator,
+            const wxString& name = wxBitmapComboBoxNameStr );
+
+    GRAPHIC_PINSHAPE    GetSelection();
+    void        SetSelection( GRAPHIC_PINSHAPE aShape );
+};

Follow ups

References