graphics/GraphicCommons.py
changeset 537 a31bf722aa82
parent 532 63e141705d19
child 550 cfa295862d55
--- a/graphics/GraphicCommons.py	Thu Apr 21 15:15:57 2011 +0200
+++ b/graphics/GraphicCommons.py	Thu Apr 21 16:06:33 2011 +0200
@@ -570,6 +570,18 @@
     def GetConnectorTranslation(self, element):
         return {}
     
+    def FindNearestConnector(self, position, connectors):
+        distances = []
+        for connector in connectors:
+            connector_pos = connector.GetRelPosition()
+            distances.append((sqrt((self.Pos.x + connector_pos.x - position.x) ** 2 +
+                                   (self.Pos.y + connector_pos.y - position.y) ** 2),
+                              connector))
+        distances.sort()
+        if len(distances) > 0:
+            return distances[0][1]
+        return None
+        
     def IsOfType(self, type, reference):
         return self.Parent.IsOfType(type, reference)