graphics/SFC_Objects.py
changeset 144 b67a5de5a24a
parent 140 06d28f03f6f4
child 145 4fb225afddf4
--- a/graphics/SFC_Objects.py	Fri Jan 04 17:47:58 2008 +0100
+++ b/graphics/SFC_Objects.py	Fri Jan 04 17:49:17 2008 +0100
@@ -65,16 +65,37 @@
         self.Action = None
     
     # Make a clone of this SFC_Step
-    def Clone(self, id = None, pos = None):
-        step = SFC_Step(self.Parent, self.Type, self.Name, id)
+    def Clone(self, id = None, name = "Step", pos = None):
+        step = SFC_Step(self.Parent, name, self.Initial, id)
         step.SetSize(self.Size[0], self.Size[1])
         if pos is not None:
             step.SetPosition(pos.x, pos.y)
-        step.Input = self.Input.Clone(step)
-        step.Output = self.Output.Clone(step)
-        step.Action = self.Action.Clone(step)
+        if self.Input:
+            step.Input = self.Input.Clone(step)
+        if self.Output:
+            step.Output = self.Output.Clone(step)
+        if self.Action:
+            step.Action = self.Action.Clone(step)
         return step
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        if self.Input:
+            rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        if self.Output:
+            rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
+        if self.Action:
+            rect = rect.Union(self.Action.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input and self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+            if self.Output and self.Output.IsConnected():
+                rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
+            if self.Action and self.Action.IsConnected():
+                rect = rect.Union(self.Action.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Delete this step by calling the appropriate method
     def Delete(self):
         self.Parent.DeleteStep(self)
@@ -428,6 +449,7 @@
     
     # Draws step
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.WHITE_BRUSH)
         # Draw two rectangles for representing the step
@@ -445,7 +467,6 @@
             self.Output.Draw(dc)
         if self.Action:
             self.Action.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -488,6 +509,18 @@
         transition.Output = self.Output.Clone(transition)
         return transition
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+            if self.Output.IsConnected():
+                rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to change the transition size
     def SetSize(self, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -763,6 +796,7 @@
     
     # Draws transition
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw plain rectangle for representing the transition
@@ -785,7 +819,6 @@
         self.Output.Draw(dc)
         if self.Type == "connection":
             self.Condition.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -837,6 +870,18 @@
         divergence.Outputs = [output.Clone(divergence) for output in self.Outputs]
         return divergence
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        if movex != 0 or movey != 0:
+            for input in self.Inputs:
+                if input.IsConnected():
+                    rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
+            for output in self.Outputs:
+                if output.IsConnected():
+                    rect = rect.Union(output.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to resize the divergence
     def Resize(self, x, y, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -1172,19 +1217,21 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        if self.Highlighted:
-            dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
-            dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
-            # Draw two rectangles for representing the contact
-            posx = self.Pos.x - 2
-            width = self.Size[0] + 5
-            if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
-                posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA
-                width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2
-            dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5)
+        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+        dc.SetLogicalFunction(wx.AND)
+        # Draw two rectangles for representing the contact
+        posx = self.Pos.x - 2
+        width = self.Size[0] + 5
+        if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
+            posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA
+            width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2
+        dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5)
+        dc.SetLogicalFunction(wx.COPY)
         
     # Draws divergence
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw plain rectangle for representing the divergence
@@ -1200,7 +1247,6 @@
             input.Draw(dc)
         for output in self.Outputs:
             output.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -1235,6 +1281,15 @@
         jump.Input = self.Input.Clone(jump)
         return jump
     
+    # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+        return rect
+    
     # Forbids to change the jump size
     def SetSize(self, width, height):
         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
@@ -1367,16 +1422,18 @@
     
     # Draws the highlightment of this element if it is highlighted
     def DrawHighlightment(self, dc):
-        if self.Highlighted:
-            dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
-            dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
-            points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2),
-                      wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2),
-                      wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)]
-            dc.DrawPolygon(points)
+        dc.SetPen(wx.Pen(HIGHLIGHTCOLOR))
+        dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
+        dc.SetLogicalFunction(wx.AND)
+        points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2),
+                  wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2),
+                  wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)]
+        dc.DrawPolygon(points)
+        dc.SetLogicalFunction(wx.COPY)
     
     # Draws divergence
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.BLACK_BRUSH)
         # Draw plain rectangle for representing the divergence
@@ -1392,7 +1449,6 @@
         # Draw input connector
         if self.Input:
             self.Input.Draw(dc)
-        Graphic_Element.Draw(self, dc)
         
 
 #-------------------------------------------------------------------------------
@@ -1427,7 +1483,16 @@
         if pos is not None:
             action_block.SetPosition(pos.x, pos.y)
         action_block.Input = self.Input.Clone(action_block)
-        return jump
+        return action_block
+    
+        # Returns the RedrawRect
+    def GetRedrawRect(self, movex = 0, movey = 0):
+        rect = Graphic_Element.GetRedrawRect(self, movex, movey)
+        rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
+        if movex != 0 or movey != 0:
+            if self.Input.IsConnected():
+                rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
+        return rect
     
     # Returns the number of action lines
     def GetLineNumber(self):
@@ -1457,7 +1522,7 @@
         
     # Refresh the action block bounding box
     def RefreshBoundingBox(self):
-        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
+        self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
     
     # Refresh the position of wires connected to action block
     def RefreshConnected(self, exclude = []):
@@ -1557,6 +1622,7 @@
     
     # Draws divergence
     def Draw(self, dc):
+        Graphic_Element.Draw(self, dc)
         dc.SetPen(wx.BLACK_PEN)
         dc.SetBrush(wx.WHITE_BRUSH)
         colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]]
@@ -1590,5 +1656,4 @@
                         self.Pos.y + i * line_size + (line_size - text_height) / 2)
         # Draw input connector
         self.Input.Draw(dc)
-        Graphic_Element.Draw(self, dc)