← Back to team overview

kicad-developers team mailing list archive

[PATCH 05/27] Separate ElectricPinType and TypeSheetLabel

 

These enums are silently treated as equivalent in the ERC, because the
values are casted to integers. This works for the most part, because the
values are similar, but this is in no way enforced, and there is a small
inconsistency (NET_UNSPECIFIED vs PIN_PASSIVE).

This turns the storage into a discriminated union, and provides an accessor
method that checks that a meaningful value can be returned and returns an
ElectricPinType in any case.
---
 eeschema/class_netlist_object.cpp | 37 +++++++++++++++++++++++++++++++++++--
 eeschema/class_netlist_object.h   |  3 +++
 eeschema/erc.cpp                  |  8 ++++----
 3 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/eeschema/class_netlist_object.cpp b/eeschema/class_netlist_object.cpp
index 3a99199..5469e75 100644
--- a/eeschema/class_netlist_object.cpp
+++ b/eeschema/class_netlist_object.cpp
@@ -173,8 +173,6 @@ NETLIST_OBJECT::NETLIST_OBJECT()
                                      * contains this pin
                                      */
     m_Flag = 0;                     /* flag used in calculations */
-    m_ElectricalType = 0;           /* Has meaning only for Pins and hierarchical pins: electrical
-                                     * type */
     m_netCode    = 0;               /* net code for all items except BUS labels because a BUS
                                      * label has as many net codes as bus members
                                      */
@@ -201,6 +199,41 @@ NETLIST_OBJECT::~NETLIST_OBJECT()
 {
 }
 
+
+int NETLIST_OBJECT::GetElectricalType() const
+{
+    if( m_Type == NET_PIN )
+        return m_ElectricalType;
+
+    if( IsLabelType() )
+    {
+        switch( m_ElectricalType )
+        {
+        case NET_INPUT:
+            return PIN_INPUT;
+
+        case NET_OUTPUT:
+            return PIN_OUTPUT;
+
+        case NET_BIDI:
+            return PIN_BIDI;
+
+        case NET_TRISTATE:
+            return PIN_TRISTATE;
+
+        case NET_UNSPECIFIED:
+            return PIN_UNSPECIFIED;
+        }
+
+        assert( ! "Invalid net type" );
+    }
+
+    assert( ! "No electrical type mapping defined for netlist object type" );
+
+    return PIN_NC;
+}
+
+
 // return true if the object is a label of any type
 bool NETLIST_OBJECT::IsLabelType() const
 {
diff --git a/eeschema/class_netlist_object.h b/eeschema/class_netlist_object.h
index cd3ff48..fb18cd0 100644
--- a/eeschema/class_netlist_object.h
+++ b/eeschema/class_netlist_object.h
@@ -33,6 +33,7 @@
 
 
 #include <sch_sheet_path.h>
+#include <sch_text.h>
 #include <lib_pin.h>      // LIB_PIN::PinStringNum( m_PinNum )
 
 class NETLIST_OBJECT_LIST;
@@ -159,6 +160,8 @@ public:
         return m_ConnectionType;
     }
 
+    int GetElectricalType() const;
+
     /**
      * Set m_netNameCandidate to a connected item which will
      * be used to calcule the net name of the item
diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp
index c93a9b1..0572887 100644
--- a/eeschema/erc.cpp
+++ b/eeschema/erc.cpp
@@ -264,7 +264,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
         return;
     }
 
-    ii = aNetItemRef->m_ElectricalType;
+    ii = aNetItemRef->GetElectricalType();
 
     wxString string_pinnum, cmp_ref;
     char     ascii_buf[5];
@@ -322,7 +322,7 @@ void Diagnose( NETLIST_OBJECT* aNetItemRef, NETLIST_OBJECT* aNetItemTst,
 
     if( aNetItemTst )         /* Error between 2 pins */
     {
-        jj = aNetItemTst->m_ElectricalType;
+        jj = aNetItemTst->GetElectricalType();
         int errortype = ERCE_PIN_TO_PIN_WARNING;
 
         if( aDiag == ERR )
@@ -363,7 +363,7 @@ void TestOthersItems( NETLIST_OBJECT_LIST* aList,
     int erc = OK;
 
     /* Analysis of the table of connections. */
-    int ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalType;
+    int ref_elect_type = aList->GetItem( aNetItemRef )->GetElectricalType();
     int local_minconn = NOC;
 
     if( ref_elect_type == PIN_NC )
@@ -461,7 +461,7 @@ void TestOthersItems( NETLIST_OBJECT_LIST* aList,
             break;
 
         case NET_PIN:
-            jj = aList->GetItem( netItemTst )->m_ElectricalType;
+            jj = aList->GetItem( netItemTst )->GetElectricalType();
             local_minconn = std::max( MinimalReq[ref_elect_type][jj], local_minconn );
 
             if( netItemTst <= aNetItemRef )

Follow ups

References