From db8efe512c04c94bb194991800c777a8c736f701 Mon Sep 17 00:00:00 2001
From: mehtank <mehtank@ucla.edu>
Date: Fri, 9 Sep 2022 05:41:54 +0000
Subject: [PATCH] Connect edge lists in reverse order to allow more universal
 connectivity

---
 rocolib/api/ports/EdgePort.py     |  9 ++++++---
 rocolib/builders/ESPSegBuilder.py | 12 ++++++------
 rocolib/library/ESPSeg.yaml       | 12 ++++++------
 rocolib/library/SimpleRectBeam.py |  4 ++--
 4 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/rocolib/api/ports/EdgePort.py b/rocolib/api/ports/EdgePort.py
index 60c2c44..03a6855 100644
--- a/rocolib/api/ports/EdgePort.py
+++ b/rocolib/api/ports/EdgePort.py
@@ -37,18 +37,21 @@ class EdgePort(Port):
     if isinstance(toPort, EdgePort):
       label1 = self.getEdges()
       label2 = toPort.getEdges()
+
+      numedges = len(label1)
+
       # XXX associate ports with specific composables so this isn't necessary
-      for i in range(len(label1)):
+      for i in range(numedges):
         if label1[i] not in (e.name for e in graph.edges):
           return
         if label2[i] not in (e.name for e in graph.edges):
           return
 
-      for i in range(len(label1)):
+      for i in range(numedges):
         newargs = {}
         for key, value in kwargs.items():
           if isinstance(value, (list, tuple)):
             newargs[key] = value[i]
           else:
             newargs[key] = value
-        graph.mergeEdge(label1[i], label2[i], **newargs)
+        graph.mergeEdge(label1[i], label2[numedges-i-1], **newargs)
diff --git a/rocolib/builders/ESPSegBuilder.py b/rocolib/builders/ESPSegBuilder.py
index d545bef..6ba94f4 100644
--- a/rocolib/builders/ESPSegBuilder.py
+++ b/rocolib/builders/ESPSegBuilder.py
@@ -43,10 +43,10 @@ c.addConstConstraint(("right","flip"), True)
 
 # connections
 c.addConnection(("brain", "topedge0"),
-                ("right", "botedge0"),
+                ("right", "topedge0"),
                 angle=-90)
 c.addConnection(("brain", "botedge0"),
-                ("left", "topedge0"),
+                ("left", "botedge0"),
                 angle=-90)
 
 # Sheath
@@ -65,7 +65,7 @@ c.addConstraint(("sheathsplit","botlength"), ("driveservo", "width"),
           x[1] - 2*getDim(x[0],'motorheight'), \
           getDim(x[0],'motorheight'))")
 
-c.addConnection(("left", "botedge1"),
+c.addConnection(("left", "topedge1"),
                 ("sheathsplit", "botedge2"),
                 angle=180)
 
@@ -76,7 +76,7 @@ c.addConnection(("right", "botedge1"),
 '''
 
 c.addConnection(("sheathsplit", "topedge0"),
-                ("sheath", "topedge1"))
+                ("sheath", "botedge1"))
 
 # Tail
 c.addSubcomponent("tail", "Tail", inherit=("flapwidth", "tailwidth"), prefix=None)
@@ -85,14 +85,14 @@ c.addConstraint(("tail","height"), *depthfn(["height"], "%s/2.+x[2]"))
 c.addConstraint(("tail","depth"), *depthfn(["battery"], "%s+x[2]"))
 
 c.addConnection(("tail", "topedge"),
-                ("sheath", "botedge1"),
+                ("sheath", "topedge1"),
                 angle=90)
 
 c.addSubcomponent("tailsplit", "SplitEdge")
 c.addConstraint(("tailsplit","toplength"), "width", "(x,)")
 c.addConstraint(("tailsplit","botlength"), ("width", "flapwidth"), "(x[0]*(1-x[1])/2., x[0]*x[1], x[0]*(1-x[1])/2.)")
 
-c.addConnection(("sheath", "botedge3"),
+c.addConnection(("sheath", "topedge3"),
                 ("tailsplit", "topedge0"))
 
 c.addConnection(("tail", "flapedge"),
diff --git a/rocolib/library/ESPSeg.yaml b/rocolib/library/ESPSeg.yaml
index 0c84eb9..77254a2 100644
--- a/rocolib/library/ESPSeg.yaml
+++ b/rocolib/library/ESPSeg.yaml
@@ -3,17 +3,17 @@ connections:
   - - brain
     - topedge0
   - - right
-    - botedge0
+    - topedge0
   - angle: -90
   connection1:
   - - brain
     - botedge0
   - - left
-    - topedge0
+    - botedge0
   - angle: -90
   connection2:
   - - left
-    - botedge1
+    - topedge1
   - - sheathsplit
     - botedge2
   - angle: 180
@@ -21,17 +21,17 @@ connections:
   - - sheathsplit
     - topedge0
   - - sheath
-    - topedge1
+    - botedge1
   - {}
   connection4:
   - - tail
     - topedge
   - - sheath
-    - botedge1
+    - topedge1
   - angle: 90
   connection5:
   - - sheath
-    - botedge3
+    - topedge3
   - - tailsplit
     - topedge0
   - {}
diff --git a/rocolib/library/SimpleRectBeam.py b/rocolib/library/SimpleRectBeam.py
index 841762a..46b14c2 100644
--- a/rocolib/library/SimpleRectBeam.py
+++ b/rocolib/library/SimpleRectBeam.py
@@ -10,8 +10,8 @@ class SimpleRectBeam(FoldedComponent):
     self.addParameter("addTabs", True, valueType="bool")
 
     for i in range(4):
-      self.addEdgeInterface("topedge%d" % i, "r%d.e0" % i, ["width", "depth"][i % 2])
-      self.addEdgeInterface("botedge%d" % i, "r%d.e2" % i, ["width", "depth"][i % 2])
+      self.addEdgeInterface("topedge%d" % i, "r%d.e2" % i, ["width", "depth"][i % 2])
+      self.addEdgeInterface("botedge%d" % i, "r%d.e0" % i, ["width", "depth"][i % 2])
       self.addFaceInterface("face%d" % i, "r%d" % i)
     self.addEdgeInterface("slotedge", "r3.e1", "length")
     self.addEdgeInterface("tabedge", "r0.e3", "length")
-- 
GitLab