graphics/FBD_Objects.py
changeset 659 46c3d5410888
parent 653 71b57ed5223b
child 664 02e8c6e882af
--- a/graphics/FBD_Objects.py	Tue Mar 27 23:50:19 2012 +0200
+++ b/graphics/FBD_Objects.py	Tue Mar 27 23:55:10 2012 +0200
@@ -113,24 +113,42 @@
     def RefreshExecutionOrderSize(self):
         self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
     
-    # Refresh the block bounding box
-    def RefreshBoundingBox(self):
+    # Returns if the point given is in the bounding box
+    def HitTest(self, pt, connectors=True):
+        if self.Name != "":
+            test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y)
+        else:
+            test_text = False
+        test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y)
+        return test_text or test_block
+    
+    # Returns the bounding box of the name outside the block
+    def GetTextBoundingBox(self):
         # Calculate the size of the name outside the block
         text_width, text_height = self.NameSize
-        # Calculate the bounding box size
-        bbx_x = self.Pos.x - max(min(1, len(self.Inputs)) * CONNECTOR_SIZE, (text_width - self.Size[0]) / 2)
-        bbx_width = max(self.Size[0] + 1 + (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE, text_width)
-        if self.Name != "":
-            bbx_y = self.Pos.y - (text_height + 2)
-            bbx_height = self.Size[1] + (text_height + 2)
-        else:
-            bbx_y = self.Pos.y
-            bbx_height = self.Size[1]
+        return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2,
+                       self.Pos.y - (text_height + 2),
+                       text_width,
+                       text_height)
+    
+    # Returns the bounding box of function block without name outside
+    def GetBlockBoundingBox(self, connectors=True):
+        bbx_x, bbx_y = self.Pos.x, self.Pos.y
+        bbx_width, bbx_height = self.Size
+        if connectors:
+            bbx_x -= min(1, len(self.Inputs)) * CONNECTOR_SIZE
+            bbx_width += (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE
         if self.ExecutionOrder != 0:
             bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
             bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
-        self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
+        return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
+    
+    # Refresh the block bounding box
+    def RefreshBoundingBox(self):
+        self.BoundingBox = self.GetBlockBoundingBox()
+        if self.Name != "":
+            self.BoundingBox.Union(self.GetTextBoundingBox())
     
     # Refresh the positions of the block connectors
     def RefreshConnectors(self):