graphics/SFC_Objects.py
changeset 108 9aa1fdfb7cb2
parent 80 c798a68c5560
child 110 29b6b70e1721
--- a/graphics/SFC_Objects.py	Fri Oct 05 18:11:51 2007 +0200
+++ b/graphics/SFC_Objects.py	Wed Oct 17 17:50:27 2007 +0200
@@ -52,7 +52,7 @@
         self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
         # Create an input and output connector
         if not self.Initial:
-            self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
+            self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
         else:
             self.Input = None
         self.Output = None
@@ -80,7 +80,7 @@
     # Add output connector to step
     def AddInput(self):
         if not self.Input:
-            self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
+            self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
             self.RefreshBoundingBox()
     
     # Remove output connector from step
@@ -93,7 +93,7 @@
     # Add output connector to step
     def AddOutput(self):
         if not self.Output:
-            self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
+            self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
             self.RefreshBoundingBox()
     
     # Remove output connector from step
@@ -106,7 +106,7 @@
     # Add action connector to step
     def AddAction(self):
         if not self.Action:
-            self.Action = Connector(self, "", "ANY", wx.Point(self.Size[0], self.Size[1] / 2), EAST)
+            self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST)
             self.RefreshBoundingBox()
     
     # Remove action connector from step
@@ -199,6 +199,9 @@
         # Test output connector
         if self.Output and self.Output.TestPoint(pt, exclude):
             return self.Output
+        # Test action connector
+        if self.Action and self.Action.TestPoint(pt, exclude):
+            return self.Action
         return None
 
     # Changes the step name
@@ -262,7 +265,10 @@
         diffy = height - self.Size.GetHeight()
         self.Move(diffx, 0)
         Graphic_Element.SetSize(self, width, height)
-        self.RefreshOutputPosition((0, diffy))
+        if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+            self.RefreshConnected()
+        else:
+            self.RefreshOutputPosition((0, diffy))
     
     # Align input element with this step
     def RefreshInputPosition(self):
@@ -443,8 +449,8 @@
         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.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
+        self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
         self.SetType(type, condition)
         self.SetPriority(priority)
     
@@ -776,15 +782,15 @@
             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3)
         # Create an input and output connector
         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
-            self.Inputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)]
+            self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)]
             self.Outputs = []
             for i in xrange(number):
-                self.Outputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
+                self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
             self.Inputs = []
             for i in xrange(number):
-                self.Inputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
-            self.Outputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)]
+                self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
+            self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)]
     
     # Destructor
     def __del__(self):
@@ -818,7 +824,7 @@
             for output in self.Outputs:
                 pos = output.GetRelPosition()
                 maxx = max(maxx, pos.x)
-            connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
+            connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
             self.Outputs.append(connector)
             self.MoveConnector(connector, 0)
         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
@@ -826,7 +832,7 @@
             for input in self.Inputs:
                 pos = input.GetRelPosition()
                 maxx = max(maxx, pos.x)
-            connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
+            connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
             self.Inputs.append(connector)
             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
     
@@ -1149,7 +1155,7 @@
         self.Id = id
         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
         # Create an input and output connector
-        self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
+        self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
         
     # Destructor
     def __del__(self):
@@ -1318,8 +1324,9 @@
         Graphic_Element.__init__(self, parent)
         self.Id = id
         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
+        self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
         # Create an input and output connector
-        self.Input = Connector(self, "", "ANY", wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
+        self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
         self.SetActions(actions)
     
     # Destructor
@@ -1331,7 +1338,7 @@
         return len(self.Actions)
     
     def GetLineSize(self):
-        if len(self.Actions) > 1:
+        if len(self.Actions) > 0:
             return self.Size[1] / len(self.Actions)
         else:
             return SFC_ACTION_MIN_SIZE[1]
@@ -1376,30 +1383,40 @@
         dc = wx.ClientDC(self.Parent)
         self.Actions = actions
         self.ColSize = [0, 0, 0]
+        min_height = 0
         for action in self.Actions:
             width, height = dc.GetTextExtent(action["qualifier"])
             self.ColSize[0] = max(self.ColSize[0], width + 10)
+            row_height = height
             if "duration" in action:
                 width, height = dc.GetTextExtent(action["duration"])
+                row_height = max(row_height, height)
                 self.ColSize[0] = max(self.ColSize[0], width + 10)
             width, height = dc.GetTextExtent(action["value"])
+            row_height = max(row_height, height)
             self.ColSize[1] = max(self.ColSize[1], width + 10)
             if "indicator" in action and action["indicator"] != "":
                 width, height = dc.GetTextExtent(action["indicator"])
+                row_height = max(row_height, height)
                 self.ColSize[2] = max(self.ColSize[2], width + 10)
+            min_height += row_height + 5
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
-            line_size = self.GetLineSize()
-            self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size)
+            self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1]))
+            self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
+                SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height)
+            self.RefreshBoundingBox()
         else:
             self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
-        self.RefreshBoundingBox()
-        if self.Input:
-            wires = self.Input.GetWires()
-            if len(wires) == 1:
-                input_block = wires[0][0].EndConnected.GetParentBlock()
-                input_block.RefreshOutputPosition()
-                input_block.RefreshOutputModel(True)
+            self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
+                SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
+            self.RefreshBoundingBox()
+            if self.Input:
+                wires = self.Input.GetWires()
+                if len(wires) == 1:
+                    input_block = wires[0][0].EndConnected.GetParentBlock()
+                    input_block.RefreshOutputPosition()
+                    input_block.RefreshOutputModel(True)
     
     # Returns the action block actions
     def GetActions(self):
@@ -1407,8 +1424,7 @@
     
     # Returns the action block minimum size
     def GetMinSize(self):
-        return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
-            SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]
+        return self.MinSize
     
     # Method called when a LeftDClick event have been generated
     def OnLeftDClick(self, event, dc, scaling):