graphics/SFC_Objects.py
changeset 80 c798a68c5560
parent 71 0578bc212c20
child 108 9aa1fdfb7cb2
--- a/graphics/SFC_Objects.py	Thu Aug 23 09:50:35 2007 +0200
+++ b/graphics/SFC_Objects.py	Mon Aug 27 17:37:50 2007 +0200
@@ -436,15 +436,17 @@
 class SFC_Transition(Graphic_Element):
     
     # Create a new transition
-    def __init__(self, parent, type = "reference", condition = None, id = None):
+    def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None):
         Graphic_Element.__init__(self, parent)
         self.Type = None
         self.Id = id
+        self.Priority = 0
         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
         # Create an input and output connector
         self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
         self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
         self.SetType(type, condition)
+        self.SetPriority(priority)
     
     # Destructor
     def __del__(self):
@@ -472,6 +474,14 @@
             else:
                 self.ConditionSize = dc.GetTextExtent("Transition")
     
+    # Refresh the size of text for name
+    def RefreshPrioritySize(self):
+        if self.Priority != "":
+            dc = wx.ClientDC(self.Parent)
+            self.PrioritySize = dc.GetTextExtent(str(self.Priority))
+        else:
+            self.PrioritySize = None
+
     # Delete this transition by calling the appropriate method
     def Delete(self):
         self.Parent.DeleteTransition(self)
@@ -486,18 +496,20 @@
     # Refresh the transition bounding box
     def RefreshBoundingBox(self):
         dc = wx.ClientDC(self.Parent)
+        bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1]
+        if self.Priority != 0:
+            bbx_y = self.Pos.y - self.PrioritySize[1] - 2
+            bbx_width = max(self.Size[0], self.PrioritySize[0])
+            bbx_height = self.Size[1] + self.PrioritySize[1] + 2
         if self.Type == "connection":
             bbx_x = self.Pos.x - CONNECTOR_SIZE
-            bbx_width = self.Size[0] + CONNECTOR_SIZE
-            bbx_y = self.Pos.y
-            bbx_height = self.Size[1]
+            bbx_width = bbx_width + CONNECTOR_SIZE
         else:
             text_width, text_height = self.ConditionSize
             # Calculate the bounding box size
-            bbx_x = self.Pos.x
-            bbx_width = self.Size[0] + 5 + text_width
-            bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2)
-            bbx_height = max(self.Size[1], text_height) - 5
+            bbx_width = max(bbx_width, self.Size[0] + 5 + text_width)
+            bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2))
+            bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2)
         self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
         
     # Returns the connector connected to input
@@ -601,6 +613,16 @@
     def GetType(self):
         return self.Type
 
+    # Changes the transition priority
+    def SetPriority(self, priority):
+        self.Priority = priority
+        self.RefreshPrioritySize()
+        self.RefreshBoundingBox()
+        
+    # Returns the transition type
+    def GetPriority(self):
+        return self.Priority
+
     # Returns the transition condition
     def GetCondition(self):
         if self.Type != "connection":
@@ -719,6 +741,10 @@
                 condition = "Transition"
             dc.DrawText(condition, self.Pos.x + self.Size[0] + 5,
                         self.Pos.y + (self.Size[1] - text_height) / 2)
+        # Draw priority number
+        if self.Priority != 0:
+            priority_width, priority_height = self.PrioritySize
+            dc.DrawText(str(self.Priority), self.Pos.x, self.Pos.y - self.PrioritySize[1] - 2)
         # Draw input and output connectors
         self.Input.Draw(dc)
         self.Output.Draw(dc)
@@ -815,6 +841,13 @@
                 self.Inputs.remove(connector)
                 self.MoveConnector(self.Inputs[0], 0)
     
+    # Remove the handled branch from the divergence
+    def RemoveHandledBranch(self):
+        handle_type, handle = self.Handle
+        if handle_type == HANDLE_CONNECTOR:
+            handle.UnConnect(delete=True)
+            self.RemoveBranch(handle)
+            
     # Return the number of branches for the divergence
     def GetBranchNumber(self):
         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: