kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #23197
[PATCH 10/19] ElectricPinType: Use enum rather than int where possible
---
eeschema/class_netlist_object.cpp | 6 +++---
eeschema/class_netlist_object.h | 8 ++++++--
eeschema/dialogs/dialog_lib_edit_pin.cpp | 2 +-
eeschema/dialogs/dialog_lib_edit_pin.h | 6 +++---
eeschema/erc.cpp | 10 +++++-----
eeschema/lib_pin.cpp | 26 +++++++++++-------------
eeschema/lib_pin.h | 34 ++++++++++++++++----------------
eeschema/pinedit.cpp | 16 +++++++--------
eeschema/sch_component.cpp | 2 +-
eeschema/sch_sheet.cpp | 2 +-
10 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/eeschema/class_netlist_object.cpp b/eeschema/class_netlist_object.cpp
index a7fe36a..441b2da 100644
--- a/eeschema/class_netlist_object.cpp
+++ b/eeschema/class_netlist_object.cpp
@@ -200,14 +200,14 @@ NETLIST_OBJECT::~NETLIST_OBJECT()
}
-int NETLIST_OBJECT::GetElectricalType() const
+ElectricPinType NETLIST_OBJECT::GetElectricalType() const
{
if( m_Type == NET_PIN )
- return m_ElectricalType;
+ return m_ElectricalType.pin;
if( IsLabelType() )
{
- switch( m_ElectricalType )
+ switch( m_ElectricalType.label )
{
case NET_INPUT:
return PIN_INPUT;
diff --git a/eeschema/class_netlist_object.h b/eeschema/class_netlist_object.h
index 7c9e987..dddd573 100644
--- a/eeschema/class_netlist_object.h
+++ b/eeschema/class_netlist_object.h
@@ -104,7 +104,11 @@ public:
int m_Flag; /* flag used in calculations */
SCH_SHEET_PATH m_SheetPath; // the sheet path which contains this item
SCH_SHEET_PATH m_SheetPathInclude; // sheet path which contains the hierarchical label
- int m_ElectricalType; /* Has meaning only for Pins and
+ union
+ {
+ ElectricPinType pin;
+ int label;
+ } m_ElectricalType; /* Has meaning only for Pins and
* hierarchical pins: electrical type */
int m_BusNetCode; /* Used for BUS connections */
int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member
@@ -161,7 +165,7 @@ public:
return m_ConnectionType;
}
- int GetElectricalType() const;
+ ElectricPinType GetElectricalType() const;
/**
* Set m_netNameCandidate to a connected item which will
diff --git a/eeschema/dialogs/dialog_lib_edit_pin.cpp b/eeschema/dialogs/dialog_lib_edit_pin.cpp
index e626325..ae12e34 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin.cpp
+++ b/eeschema/dialogs/dialog_lib_edit_pin.cpp
@@ -134,7 +134,7 @@ void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event )
int pinOrient = LIB_PIN::GetOrientationCode( GetOrientation() );
int pinLength = ValueFromString( g_UserUnit, GetLength() );
PinShape pinShape = GetStyle();
- int pinType = GetElectricalType();
+ ElectricPinType pinType = GetElectricalType();
m_dummyPin->SetName( GetPinName() );
m_dummyPin->SetNameTextSize( pinNameSize );
diff --git a/eeschema/dialogs/dialog_lib_edit_pin.h b/eeschema/dialogs/dialog_lib_edit_pin.h
index 3b4e363..0ffdcd8 100644
--- a/eeschema/dialogs/dialog_lib_edit_pin.h
+++ b/eeschema/dialogs/dialog_lib_edit_pin.h
@@ -61,13 +61,13 @@ public:
int GetOrientation( void ) { return m_choiceOrientation->GetSelection(); }
void SetElectricalTypeList( const wxArrayString& list, const BITMAP_DEF* aBitmaps );
- void SetElectricalType( int type )
+ void SetElectricalType( ElectricPinType type )
{
m_choiceElectricalType->SetSelection( type );
}
- int GetElectricalType( void )
+ ElectricPinType GetElectricalType( void )
{
- return m_choiceElectricalType->GetSelection();
+ return static_cast<ElectricPinType>( m_choiceElectricalType->GetSelection() );
}
void SetStyle( PinShape style ) { m_choiceStyle->SetSelection( style ); }
diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp
index f714c5b..a7f1b58 100644
--- a/eeschema/erc.cpp
+++ b/eeschema/erc.cpp
@@ -228,9 +228,9 @@ int TestDuplicateSheetNames( bool aCreateMarker )
void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
int aMinConn, int aDiag )
{
- SCH_MARKER* marker = NULL;
- SCH_SCREEN* screen;
- int ii, jj;
+ SCH_MARKER* marker = NULL;
+ SCH_SCREEN* screen;
+ ElectricPinType ii, jj;
if( aDiag == OK )
return;
@@ -374,11 +374,11 @@ void TestOthersItems( NETLIST_OBJECT_LIST* aList,
int* aMinConnexion )
{
unsigned netItemTst = aNetStart;
- int jj;
+ ElectricPinType jj;
int erc = OK;
/* Analysis of the table of connections. */
- int ref_elect_type = aList->GetItem( aNetItemRef )->GetElectricalType();
+ ElectricPinType ref_elect_type = aList->GetItem( aNetItemRef )->GetElectricalType();
int local_minconn = NOC;
if( ref_elect_type == PIN_NC )
diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index 0115a42..ed6d4e4 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -90,8 +90,10 @@ static const BITMAP_DEF iconsPinsElectricalType[] =
#define PIN_ELECTRICAL_TYPE_CNT DIM( iconsPinsElectricalType )
-const wxString LIB_PIN::GetCanonicalElectricalTypeName( unsigned aType )
+const wxString LIB_PIN::GetCanonicalElectricalTypeName( ElectricPinType aType )
{
+ assert( aType >= 0 && aType < PIN_NMAX );
+
// These strings are the canonical name of the electrictal type
// Not translated, no space in name, only ASCII chars.
// to use when the string name must be known and well defined
@@ -108,12 +110,11 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( unsigned aType )
wxT( "power_out" ),
wxT( "openCol" ),
wxT( "openEm" ),
- wxT( "NotConnected" ),
- wxT( "???" )
+ wxT( "NotConnected" )
};
if( aType > PIN_NMAX )
- aType = PIN_NMAX;
+ return wxT( "???" );
return msgPinElectricType[ aType ];
}
@@ -144,7 +145,7 @@ static const wxString getPinOrientationName( unsigned aPinOrientationCode )
return pin_orientation_names[ aPinOrientationCode ];
}
-const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType )
+const wxString LIB_PIN::GetElectricalTypeName( ElectricPinType aPinsElectricalType )
{
const wxString pin_electrical_type_names[] =
{ // Keep these translated strings not static
@@ -158,12 +159,11 @@ const wxString LIB_PIN::GetElectricalTypeName( unsigned aPinsElectricalType )
_( "Power output" ),
_( "Open collector" ),
_( "Open emitter" ),
- _( "Not connected" ),
- wxT( "???" )
+ _( "Not connected" )
};
if( aPinsElectricalType > PIN_ELECTRICAL_TYPE_CNT )
- aPinsElectricalType = PIN_ELECTRICAL_TYPE_CNT;
+ return wxT( "???" );
return pin_electrical_type_names[ aPinsElectricalType ];
}
@@ -352,13 +352,9 @@ void LIB_PIN::SetShape( PinShape aShape )
}
-void LIB_PIN::SetType( int aType )
+void LIB_PIN::SetType( ElectricPinType aType )
{
- if( aType < 0 )
- aType = 0;
-
- if( aType >= (int)PIN_ELECTRICAL_TYPE_CNT )
- aType = PIN_ELECTRICAL_TYPE_CNT - 1;
+ assert( aType >= 0 && aType < PIN_NMAX );
if( m_type != aType )
{
@@ -2222,7 +2218,7 @@ wxArrayString LIB_PIN::GetElectricalTypeNames( void )
wxArrayString tmp;
for( unsigned ii = 0; ii < PIN_ELECTRICAL_TYPE_CNT; ii++ )
- tmp.Add( LIB_PIN::GetElectricalTypeName( ii ) );
+ tmp.Add( LIB_PIN::GetElectricalTypeName( static_cast<ElectricPinType>( ii ) ) );
return tmp;
}
diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h
index a5d9675..bfd1f92 100644
--- a/eeschema/lib_pin.h
+++ b/eeschema/lib_pin.h
@@ -60,19 +60,19 @@ enum LibPinDrawFlags {
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)
- PinShape m_shape; ///< Shape drawn around pin
- int m_width; ///< Line width of the pin.
- int m_type; ///< Electrical type of the pin. See enum ElectricPinType.
- int m_attributes; ///< Set bit 0 to indicate pin is invisible.
- wxString m_name;
- long m_number; ///< Pin number defined as 4 ASCII characters like "12", "anod",
- ///< "G6", or "12". It is stored as "12\0\0" and does not
- ///< depend on endian type.
- int m_numTextSize;
- int m_nameTextSize; ///< Pin num and Pin name sizes
+ wxPoint m_position; ///< Position of the pin.
+ int m_length; ///< Length of the pin.
+ int m_orientation; ///< Pin orientation (Up, Down, Left, Right)
+ PinShape m_shape; ///< Shape drawn around pin
+ int m_width; ///< Line width of the pin.
+ ElectricPinType m_type; ///< Electrical type of the pin. See enum ElectricPinType.
+ int m_attributes; ///< Set bit 0 to indicate pin is invisible.
+ wxString m_name;
+ long m_number; ///< Pin number defined as 4 ASCII characters like "12", "anod",
+ ///< "G6", or "12". It is stored as "12\0\0" and does not
+ ///< depend on endian type.
+ int m_numTextSize;
+ int m_nameTextSize; ///< Pin num and Pin name sizes
/**
* Draw a pin, with or without the pin texts
@@ -248,7 +248,7 @@ public:
*
* @return The electrical type of the pin (see enun ElectricPinType for values).
*/
- int GetType() const { return m_type; }
+ ElectricPinType GetType() const { return m_type; }
/**
* return a string giving the electrical type of a pin.
@@ -256,7 +256,7 @@ public:
* @param aType is the electrical type (see enum ElectricPinType )
* @return The electrical name for a pin type (see enun MsgPinElectricType for names).
*/
- static const wxString GetCanonicalElectricalTypeName( unsigned aType );
+ static const wxString GetCanonicalElectricalTypeName( ElectricPinType aType );
/**
* return a string giving the electrical type of the pin.
@@ -273,7 +273,7 @@ public:
* @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( unsigned aType );
+ static const wxString GetElectricalTypeName( ElectricPinType aType );
/**
* return a translated string for messages giving the electrical type of the pin.
@@ -292,7 +292,7 @@ public:
*
* @param aType - The electrical type of the pin(see enun ElectricPinType for values).
*/
- void SetType( int aType );
+ void SetType( ElectricPinType aType );
/**
* Set the pin length.
diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp
index fc5b71a..dd31c93 100644
--- a/eeschema/pinedit.cpp
+++ b/eeschema/pinedit.cpp
@@ -53,14 +53,14 @@ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC );
static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon, bool aErase );
-static wxPoint OldPos;
-static wxPoint PinPreviousPos;
-static int LastPinType = PIN_INPUT;
-static int LastPinOrient = PIN_RIGHT;
-static PinShape LastPinShape = PINSHAPE_LINE;
-static bool LastPinCommonConvert = false;
-static bool LastPinCommonUnit = false;
-static bool LastPinVisible = true;
+static wxPoint OldPos;
+static wxPoint PinPreviousPos;
+static ElectricPinType LastPinType = PIN_INPUT;
+static int LastPinOrient = PIN_RIGHT;
+static PinShape LastPinShape = PINSHAPE_LINE;
+static bool LastPinCommonConvert = false;
+static bool LastPinCommonUnit = false;
+static bool LastPinVisible = true;
// The -1 is a non-valid value to trigger delayed initialization
static int LastPinLength = -1;
diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp
index aaed3f3..061034a 100644
--- a/eeschema/sch_component.cpp
+++ b/eeschema/sch_component.cpp
@@ -1900,7 +1900,7 @@ void SCH_COMPONENT::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
item->m_SheetPath = *aSheetPath;
item->m_Type = NET_PIN;
item->m_Link = (SCH_ITEM*) this;
- item->m_ElectricalType = pin->GetType();
+ item->m_ElectricalType.pin = pin->GetType();
item->m_PinNum = pin->GetNumber();
item->m_Label = pin->GetName();
item->m_Start = item->m_End = pos;
diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp
index e1ec949..37c3657 100644
--- a/eeschema/sch_sheet.cpp
+++ b/eeschema/sch_sheet.cpp
@@ -1092,7 +1092,7 @@ void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
item->m_Comp = &m_pins[i];
item->m_Link = this;
item->m_Type = NET_SHEETLABEL;
- item->m_ElectricalType = m_pins[i].GetShape();
+ item->m_ElectricalType.label = m_pins[i].GetShape();
item->m_Label = m_pins[i].GetText();
item->m_Start = item->m_End = m_pins[i].GetPosition();
aNetListItems.push_back( item );
Follow ups
References
-
[PATCH 00/19] Pin shape and type refactoring
From: Simon Richter, 2016-02-17
-
[PATCH 01/19] Replace DrawPinShape enum with PinShape
From: Simon Richter, 2016-02-17
-
[PATCH 02/19] PinShapeComboBox: Introduce widget
From: Simon Richter, 2016-02-17
-
[PATCH 03/19] PinShapeComboBox: Fully initialize in c'tor
From: Simon Richter, 2016-02-17
-
[PATCH 04/19] PinShapeComboBox: typesafe Get/Set
From: Simon Richter, 2016-02-17
-
[PATCH 05/19] PinShape: move enum to own header
From: Simon Richter, 2016-02-17
-
[PATCH 06/19] PinShape: move text lookup
From: Simon Richter, 2016-02-17
-
[PATCH 07/19] PinShape: drop list interfaces
From: Simon Richter, 2016-02-17
-
[PATCH 08/19] PinShape: move bitmap lookup
From: Simon Richter, 2016-02-17
-
[PATCH 09/19] ElectricPinType: move definition to pin_type.h
From: Simon Richter, 2016-02-17