graphics/GraphicCommons.py
changeset 243 c5da8b706cde
parent 237 097e8ee006cb
child 249 d8425712acef
--- a/graphics/GraphicCommons.py	Wed Aug 27 16:55:16 2008 +0200
+++ b/graphics/GraphicCommons.py	Wed Aug 27 16:56:25 2008 +0200
@@ -1103,16 +1103,17 @@
             self.Negated = False
     
     # Tests if the point given is near from the end point of this connector
-    def TestPoint(self, pt, exclude = True):
+    def TestPoint(self, pt, direction = None, exclude = True):
         parent_pos = self.ParentBlock.GetPosition()
         if not (len(self.Wires) > 0 and self.OneConnected and exclude):
-            # Calculate a square around the end point of this connector
-            x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
-            y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
-            width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
-            height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
-            rect = wx.Rect(x, y, width, height)
-            return rect.InsideXY(pt.x, pt.y)
+            if direction is None or self.Direction == direction:
+                # Calculate a square around the end point of this connector
+                x = parent_pos[0] + self.Pos.x + self.Direction[0] * CONNECTOR_SIZE - ANCHOR_DISTANCE
+                y = parent_pos[1] + self.Pos.y + self.Direction[1] * CONNECTOR_SIZE - ANCHOR_DISTANCE
+                width = ANCHOR_DISTANCE * 2 + abs(self.Direction[0]) * CONNECTOR_SIZE
+                height = ANCHOR_DISTANCE * 2 + abs(self.Direction[1]) * CONNECTOR_SIZE
+                rect = wx.Rect(x, y, width, height)
+                return rect.InsideXY(pt.x, pt.y)
         return False
     
     # Draws the highlightment of this element if it is highlighted
@@ -1277,6 +1278,23 @@
             return computed_type
         return None
     
+    def GetConnectionDirection(self):
+        if self.StartConnected is None and self.EndConnected is None:
+            return None
+        elif self.StartConnected is not None and self.EndConnected is None:
+            return (-self.StartPoint[1][0], -self.StartPoint[1][1])
+        elif self.StartConnected is None and self.EndConnected is not None:
+            return self.EndPoint
+        elif self.Handle is not None:
+            handle_type, handle = self.Handle
+            # A point has been handled
+            if handle_type == HANDLE_POINT:
+                if handle == 0:
+                    return self.EndPoint
+                else:
+                    return (-self.StartPoint[1][0], -self.StartPoint[1][1])
+        return None
+    
     def GetOtherConnected(self, connector):
         if self.StartConnected == connector:
             return self.EndConnected
@@ -1998,7 +2016,7 @@
                 movey = round(float(self.Points[handle].y + movey) / float(scaling[1])) * scaling[1] - self.Points[handle].y
             # Try to connect point to a connector
             new_pos = wx.Point(self.Points[handle].x + movex, self.Points[handle].y + movey)
-            connector = self.Parent.FindBlockConnector(new_pos)
+            connector = self.Parent.FindBlockConnector(new_pos, self.GetConnectionDirection())
             if connector:
                 if handle == 0 and self.EndConnected != connector and connector.IsCompatible(self.GetEndConnectedType()):
                     connector.HighlightParentBlock(True)