Merged workaround for loading bug happening after automatic resize of function blocks. It appears that some code in GraphicCommons.py loop endlessly when wires coordinate do not align with x or y axis. Those erroneous coordinate are now filtered out when loaded in the view.
authorEdouard Tisserant
Tue, 18 Jun 2019 14:09:23 +0200
changeset 2618 4eca95f91cba
parent 2614 6b4061f6ced6 (current diff)
parent 2617 93ad3db5f9df (diff)
child 2619 b1ebe2803285
Merged workaround for loading bug happening after automatic resize of function blocks. It appears that some code in GraphicCommons.py loop endlessly when wires coordinate do not align with x or y axis. Those erroneous coordinate are now filtered out when loaded in the view.
--- a/graphics/GraphicCommons.py	Thu Jun 13 15:49:48 2019 +0200
+++ b/graphics/GraphicCommons.py	Tue Jun 18 14:09:23 2019 +0200
@@ -1964,9 +1964,23 @@
         return None
 
     # Define the wire points
-    def SetPoints(self, points, verify=True):
+    def SetPoints(self, points, merge_segments=True):
         if len(points) > 1:
-            self.Points = [wx.Point(x, y) for x, y in points]
+
+            # filter duplicates, add corner to diagonals
+            self.Points = []
+            lx,ly = None,None
+            for x, y in points:
+                ex, ey = lx == x, ly == y
+                if ex and ey:
+                    # duplicate
+                    continue
+                if (lx,ly) != (None,None) and not ex and not ey:
+                    # diagonal
+                    self.Points.append(wx.Point(lx, y))
+                self.Points.append(wx.Point(x, y))
+                lx,ly = x,y
+
             # Calculate the start and end directions
             self.StartPoint = [None, vector(self.Points[0], self.Points[1])]
             self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])]
@@ -1980,22 +1994,33 @@
             # Calculate the segments directions
             self.Segments = []
             i = 0
-            while i < len(self.Points) - 1:
-                if verify and 0 < i < len(self.Points) - 2 and \
-                   self.Points[i] == self.Points[i + 1] and \
-                   self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]):
-                    for dummy in xrange(2):
-                        self.Points.pop(i)
-                else:
-                    segment = vector(self.Points[i], self.Points[i + 1])
-                    if is_null_vector(segment) and i > 0:
-                        segment = (self.Segments[-1][1], self.Segments[-1][0])
-                    if i < len(self.Points) - 2:
-                        next = vector(self.Points[i + 1], self.Points[i + 2])
-                        if next == segment or is_null_vector(add_vectors(segment, next)):
-                            self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y))
-                    self.Segments.append(segment)
-                    i += 1
+            while True:
+                l = len(self.Points)
+                if i > l - 2:
+                    break
+
+                segment = vector(self.Points[i], self.Points[i + 1])
+
+                # merge segment if requested
+                if merge_segments and 0 < i and \
+                   self.Segments[-1] == segment:
+                    self.Points.pop(i)
+                    # Rollback
+                    self.Segments.pop()
+                    i -= 1
+                    continue
+
+                # remove corner when two segments are in opposite direction
+                if i < l - 2:
+                    next = vector(self.Points[i + 1], self.Points[i + 2])
+                    if is_null_vector(add_vectors(segment, next)):
+                        self.Points.pop(i+1)
+                        continue
+
+                self.Segments.append(segment)
+
+                i += 1
+
             self.RefreshBoundingBox()
             self.RefreshRealPoints()