graphics/SFC_Objects.py
changeset 1744 69dfdb26f600
parent 1743 c3c3d1318130
child 1754 63f4af6bf6d9
equal deleted inserted replaced
1743:c3c3d1318130 1744:69dfdb26f600
    44     """
    44     """
    45     Class that implements the graphic representation of a step
    45     Class that implements the graphic representation of a step
    46     """
    46     """
    47 
    47 
    48     # Create a new step
    48     # Create a new step
    49     def __init__(self, parent, name, initial = False, id = None):
    49     def __init__(self, parent, name, initial=False, id=None):
    50         Graphic_Element.__init__(self, parent)
    50         Graphic_Element.__init__(self, parent)
    51         DebugDataConsumer.__init__(self)
    51         DebugDataConsumer.__init__(self)
    52         self.SetName(name)
    52         self.SetName(name)
    53         self.Initial = initial
    53         self.Initial = initial
    54         self.Id = id
    54         self.Id = id
   103                 if self.Action is not None:
   103                 if self.Action is not None:
   104                     self.Action.SpreadCurrent(False)
   104                     self.Action.SpreadCurrent(False)
   105             self.PreviousSpreading = spreading
   105             self.PreviousSpreading = spreading
   106 
   106 
   107     # Make a clone of this SFC_Step
   107     # Make a clone of this SFC_Step
   108     def Clone(self, parent, id = None, name = "Step", pos = None):
   108     def Clone(self, parent, id=None, name="Step", pos=None):
   109         step = SFC_Step(parent, name, self.Initial, id)
   109         step = SFC_Step(parent, name, self.Initial, id)
   110         step.SetSize(self.Size[0], self.Size[1])
   110         step.SetSize(self.Size[0], self.Size[1])
   111         if pos is not None:
   111         if pos is not None:
   112             step.SetPosition(pos.x, pos.y)
   112             step.SetPosition(pos.x, pos.y)
   113         else:
   113         else:
   129         if self.Action is not None:
   129         if self.Action is not None:
   130             connectors[self.Action] = element.Action
   130             connectors[self.Action] = element.Action
   131         return connectors
   131         return connectors
   132 
   132 
   133     # Returns the RedrawRect
   133     # Returns the RedrawRect
   134     def GetRedrawRect(self, movex = 0, movey = 0):
   134     def GetRedrawRect(self, movex=0, movey=0):
   135         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   135         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   136         if self.Input:
   136         if self.Input:
   137             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   137             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   138         if self.Output:
   138         if self.Output:
   139             rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   139             rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   153         self.Parent.DeleteStep(self)
   153         self.Parent.DeleteStep(self)
   154 
   154 
   155     # Unconnect input and output
   155     # Unconnect input and output
   156     def Clean(self):
   156     def Clean(self):
   157         if self.Input:
   157         if self.Input:
   158             self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   158             self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   159         if self.Output:
   159         if self.Output:
   160             self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   160             self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   161         if self.Action:
   161         if self.Action:
   162             self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   162             self.Action.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   163 
   163 
   164     # Refresh the size of text for name
   164     # Refresh the size of text for name
   165     def RefreshNameSize(self):
   165     def RefreshNameSize(self):
   166         self.NameSize = self.Parent.GetTextExtent(self.Name)
   166         self.NameSize = self.Parent.GetTextExtent(self.Name)
   167 
   167 
   172             self.RefreshBoundingBox()
   172             self.RefreshBoundingBox()
   173 
   173 
   174     # Remove output connector from step
   174     # Remove output connector from step
   175     def RemoveInput(self):
   175     def RemoveInput(self):
   176         if self.Input:
   176         if self.Input:
   177             self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   177             self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   178             self.Input = None
   178             self.Input = None
   179             self.RefreshBoundingBox()
   179             self.RefreshBoundingBox()
   180 
   180 
   181     # Add output connector to step
   181     # Add output connector to step
   182     def AddOutput(self):
   182     def AddOutput(self):
   183         if not self.Output:
   183         if not self.Output:
   184             self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)
   184             self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)
   185             self.RefreshBoundingBox()
   185             self.RefreshBoundingBox()
   186 
   186 
   187     # Remove output connector from step
   187     # Remove output connector from step
   188     def RemoveOutput(self):
   188     def RemoveOutput(self):
   189         if self.Output:
   189         if self.Output:
   190             self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   190             self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   191             self.Output = None
   191             self.Output = None
   192             self.RefreshBoundingBox()
   192             self.RefreshBoundingBox()
   193 
   193 
   194     # Add action connector to step
   194     # Add action connector to step
   195     def AddAction(self):
   195     def AddAction(self):
   196         if not self.Action:
   196         if not self.Action:
   197             self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone = True)
   197             self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone=True)
   198             self.RefreshBoundingBox()
   198             self.RefreshBoundingBox()
   199 
   199 
   200     # Remove action connector from step
   200     # Remove action connector from step
   201     def RemoveAction(self):
   201     def RemoveAction(self):
   202         if self.Action:
   202         if self.Action:
   203             self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   203             self.Action.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   204             self.Action = None
   204             self.Action = None
   205             self.RefreshBoundingBox()
   205             self.RefreshBoundingBox()
   206 
   206 
   207     # Refresh the step bounding box
   207     # Refresh the step bounding box
   208     def RefreshBoundingBox(self):
   208     def RefreshBoundingBox(self):
   242         if self.Action:
   242         if self.Action:
   243             self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos))
   243             self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos))
   244         self.RefreshConnected()
   244         self.RefreshConnected()
   245 
   245 
   246     # Refresh the position of wires connected to step
   246     # Refresh the position of wires connected to step
   247     def RefreshConnected(self, exclude = []):
   247     def RefreshConnected(self, exclude=[]):
   248         if self.Input:
   248         if self.Input:
   249             self.Input.MoveConnected(exclude)
   249             self.Input.MoveConnected(exclude)
   250         if self.Output:
   250         if self.Output:
   251             self.Output.MoveConnected(exclude)
   251             self.Output.MoveConnected(exclude)
   252         if self.Action:
   252         if self.Action:
   253             self.Action.MoveConnected(exclude)
   253             self.Action.MoveConnected(exclude)
   254 
   254 
   255     # Returns the step connector that starts with the point given if it exists
   255     # Returns the step connector that starts with the point given if it exists
   256     def GetConnector(self, position, name = None):
   256     def GetConnector(self, position, name=None):
   257         # if a name is given
   257         # if a name is given
   258         if name is not None:
   258         if name is not None:
   259             # Test input, output and action connector if they exists
   259             # Test input, output and action connector if they exists
   260             #if self.Input and name == self.Input.GetName():
   260             #if self.Input and name == self.Input.GetName():
   261             #    return self.Input
   261             #    return self.Input
   287         if self.Output:
   287         if self.Output:
   288             connectors["outputs"].append(self.Output)
   288             connectors["outputs"].append(self.Output)
   289         return connectors
   289         return connectors
   290 
   290 
   291     # Test if point given is on step input or output connector
   291     # Test if point given is on step input or output connector
   292     def TestConnector(self, pt, direction = None, exclude=True):
   292     def TestConnector(self, pt, direction=None, exclude=True):
   293         # Test input connector if it exists
   293         # Test input connector if it exists
   294         if self.Input and self.Input.TestPoint(pt, direction, exclude):
   294         if self.Input and self.Input.TestPoint(pt, direction, exclude):
   295             return self.Input
   295             return self.Input
   296         # Test output connector
   296         # Test output connector
   297         if self.Output and self.Output.TestPoint(pt, direction, exclude):
   297         if self.Output and self.Output.TestPoint(pt, direction, exclude):
   383                         input_block.MoveActionBlock((diffx, 0))
   383                         input_block.MoveActionBlock((diffx, 0))
   384                     input_block.Move(diffx, 0)
   384                     input_block.Move(diffx, 0)
   385                     input_block.RefreshInputPosition()
   385                     input_block.RefreshInputPosition()
   386 
   386 
   387     # Align output element with this step
   387     # Align output element with this step
   388     def RefreshOutputPosition(self, move = None):
   388     def RefreshOutputPosition(self, move=None):
   389         if self.Output:
   389         if self.Output:
   390             wires = self.Output.GetWires()
   390             wires = self.Output.GetWires()
   391             if len(wires) != 1:
   391             if len(wires) != 1:
   392                 return
   392                 return
   393             current_pos = self.Output.GetPosition(False)
   393             current_pos = self.Output.GetPosition(False)
   577     """
   577     """
   578     Class that implements the graphic representation of a transition
   578     Class that implements the graphic representation of a transition
   579     """
   579     """
   580 
   580 
   581     # Create a new transition
   581     # Create a new transition
   582     def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None):
   582     def __init__(self, parent, type="reference", condition=None, priority=0, id=None):
   583         Graphic_Element.__init__(self, parent)
   583         Graphic_Element.__init__(self, parent)
   584         DebugDataConsumer.__init__(self)
   584         DebugDataConsumer.__init__(self)
   585         self.Type = None
   585         self.Type = None
   586         self.Id = id
   586         self.Id = id
   587         self.Priority = 0
   587         self.Priority = 0
   588         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   588         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   589         # Create an input and output connector
   589         # Create an input and output connector
   590         self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
   590         self.Input  = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0),            NORTH, onlyone=True)
   591         self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)
   591         self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)
   592         self.SetType(type, condition)
   592         self.SetType(type, condition)
   593         self.SetPriority(priority)
   593         self.SetPriority(priority)
   594         self.Highlights = {}
   594         self.Highlights = {}
   595         self.PreviousValue = None
   595         self.PreviousValue = None
   596         self.PreviousSpreading = False
   596         self.PreviousSpreading = False
   630             elif not spreading and self.PreviousSpreading:
   630             elif not spreading and self.PreviousSpreading:
   631                 self.Output.SpreadCurrent(False)
   631                 self.Output.SpreadCurrent(False)
   632             self.PreviousSpreading = spreading
   632             self.PreviousSpreading = spreading
   633 
   633 
   634     # Make a clone of this SFC_Transition
   634     # Make a clone of this SFC_Transition
   635     def Clone(self, parent, id = None, pos = None):
   635     def Clone(self, parent, id=None, pos=None):
   636         transition = SFC_Transition(parent, self.Type, self.Condition, self.Priority, id)
   636         transition = SFC_Transition(parent, self.Type, self.Condition, self.Priority, id)
   637         transition.SetSize(self.Size[0], self.Size[1])
   637         transition.SetSize(self.Size[0], self.Size[1])
   638         if pos is not None:
   638         if pos is not None:
   639             transition.SetPosition(pos.x, pos.y)
   639             transition.SetPosition(pos.x, pos.y)
   640         else:
   640         else:
   650         if self.Type == "connection" and self.Condition is not None:
   650         if self.Type == "connection" and self.Condition is not None:
   651             connectors[self.Condition] = element.Condition
   651             connectors[self.Condition] = element.Condition
   652         return connectors
   652         return connectors
   653 
   653 
   654     # Returns the RedrawRect
   654     # Returns the RedrawRect
   655     def GetRedrawRect(self, movex = 0, movey = 0):
   655     def GetRedrawRect(self, movex=0, movey=0):
   656         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   656         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   657         if self.Input:
   657         if self.Input:
   658             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   658             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
   659         if self.Output:
   659         if self.Output:
   660             rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   660             rect = rect.Union(self.Output.GetRedrawRect(movex, movey))
   696     def Delete(self):
   696     def Delete(self):
   697         self.Parent.DeleteTransition(self)
   697         self.Parent.DeleteTransition(self)
   698 
   698 
   699     # Unconnect input and output
   699     # Unconnect input and output
   700     def Clean(self):
   700     def Clean(self):
   701         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   701         self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   702         self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   702         self.Output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   703         if self.Type == "connection":
   703         if self.Type == "connection":
   704             self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   704             self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   705 
   705 
   706     # Returns if the point given is in the bounding box
   706     # Returns if the point given is in the bounding box
   707     def HitTest(self, pt, connectors=True):
   707     def HitTest(self, pt, connectors=True):
   708         if self.Type != "connection":
   708         if self.Type != "connection":
   709             # Calculate the bounding box of the condition outside the transition
   709             # Calculate the bounding box of the condition outside the transition
   764         if self.Type == "connection":
   764         if self.Type == "connection":
   765             self.Condition.SetPosition(wx.Point(0, vertical_pos))
   765             self.Condition.SetPosition(wx.Point(0, vertical_pos))
   766         self.RefreshConnected()
   766         self.RefreshConnected()
   767 
   767 
   768     # Refresh the position of the wires connected to transition
   768     # Refresh the position of the wires connected to transition
   769     def RefreshConnected(self, exclude = []):
   769     def RefreshConnected(self, exclude=[]):
   770         self.Input.MoveConnected(exclude)
   770         self.Input.MoveConnected(exclude)
   771         self.Output.MoveConnected(exclude)
   771         self.Output.MoveConnected(exclude)
   772         if self.Type == "connection":
   772         if self.Type == "connection":
   773             self.Condition.MoveConnected(exclude)
   773             self.Condition.MoveConnected(exclude)
   774 
   774 
   775     # Returns the transition connector that starts with the point given if it exists
   775     # Returns the transition connector that starts with the point given if it exists
   776     def GetConnector(self, position, name = None):
   776     def GetConnector(self, position, name=None):
   777         # if a name is given
   777         # if a name is given
   778         if name is not None:
   778         if name is not None:
   779             # Test input and output connector
   779             # Test input and output connector
   780             #if name == self.Input.GetName():
   780             #if name == self.Input.GetName():
   781             #    return self.Input
   781             #    return self.Input
   797     # Returns input and output transition connectors
   797     # Returns input and output transition connectors
   798     def GetConnectors(self):
   798     def GetConnectors(self):
   799         return {"inputs": [self.Input], "outputs": [self.Output]}
   799         return {"inputs": [self.Input], "outputs": [self.Output]}
   800 
   800 
   801     # Test if point given is on transition input or output connector
   801     # Test if point given is on transition input or output connector
   802     def TestConnector(self, pt, direction = None, exclude=True):
   802     def TestConnector(self, pt, direction=None, exclude=True):
   803         # Test input connector
   803         # Test input connector
   804         if self.Input.TestPoint(pt, direction, exclude):
   804         if self.Input.TestPoint(pt, direction, exclude):
   805             return self.Input
   805             return self.Input
   806         # Test output connector
   806         # Test output connector
   807         if self.Output.TestPoint(pt, direction, exclude):
   807         if self.Output.TestPoint(pt, direction, exclude):
   810         if self.Type == "connection" and self.Condition.TestPoint(pt, direction, exclude):
   810         if self.Type == "connection" and self.Condition.TestPoint(pt, direction, exclude):
   811             return self.Condition
   811             return self.Condition
   812         return None
   812         return None
   813 
   813 
   814     # Changes the transition type
   814     # Changes the transition type
   815     def SetType(self, type, condition = None):
   815     def SetType(self, type, condition=None):
   816         if self.Type != type:
   816         if self.Type != type:
   817             if self.Type == "connection":
   817             if self.Type == "connection":
   818                self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   818                self.Condition.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   819             self.Type = type
   819             self.Type = type
   820             if type == "connection":
   820             if type == "connection":
   821                 self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST)
   821                 self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST)
   822             else:
   822             else:
   823                 if condition is None:
   823                 if condition is None:
   871                     input_block.MoveActionBlock((diffx, 0))
   871                     input_block.MoveActionBlock((diffx, 0))
   872                 input_block.Move(diffx, 0)
   872                 input_block.Move(diffx, 0)
   873                 input_block.RefreshInputPosition()
   873                 input_block.RefreshInputPosition()
   874 
   874 
   875     # Align output element with this step
   875     # Align output element with this step
   876     def RefreshOutputPosition(self, move = None):
   876     def RefreshOutputPosition(self, move=None):
   877         wires = self.Output.GetWires()
   877         wires = self.Output.GetWires()
   878         if len(wires) != 1:
   878         if len(wires) != 1:
   879             return
   879             return
   880         current_pos = self.Output.GetPosition(False)
   880         current_pos = self.Output.GetPosition(False)
   881         output = wires[0][0].GetOtherConnected(self.Output)
   881         output = wires[0][0].GetOtherConnected(self.Output)
   918             self.Move(movex, 0)
   918             self.Move(movex, 0)
   919             self.RefreshInputPosition()
   919             self.RefreshInputPosition()
   920             self.RefreshOutputPosition()
   920             self.RefreshOutputPosition()
   921             return movex, 0
   921             return movex, 0
   922         else:
   922         else:
   923             return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac = 2, height_fac = 2)
   923             return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac=2, height_fac=2)
   924 
   924 
   925     # Refresh input element model
   925     # Refresh input element model
   926     def RefreshInputModel(self):
   926     def RefreshInputModel(self):
   927         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   927         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
   928             input = self.GetPreviousConnector()
   928             input = self.GetPreviousConnector()
  1047     Class that implements the graphic representation of a divergence or convergence,
  1047     Class that implements the graphic representation of a divergence or convergence,
  1048     selection or simultaneous
  1048     selection or simultaneous
  1049     """
  1049     """
  1050 
  1050 
  1051     # Create a new divergence
  1051     # Create a new divergence
  1052     def __init__(self, parent, type, number = 2, id = None):
  1052     def __init__(self, parent, type, number=2, id=None):
  1053         Graphic_Element.__init__(self, parent)
  1053         Graphic_Element.__init__(self, parent)
  1054         self.Type = type
  1054         self.Type = type
  1055         self.Id = id
  1055         self.Id = id
  1056         self.RealConnectors = None
  1056         self.RealConnectors = None
  1057         number = max(2, number)
  1057         number = max(2, number)
  1058         self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
  1058         self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1])
  1059         # Create an input and output connector
  1059         # Create an input and output connector
  1060         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1060         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1061             self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)]
  1061             self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)]
  1062             self.Outputs = []
  1062             self.Outputs = []
  1063             for i in xrange(number):
  1063             for i in xrange(number):
  1064                 self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True))
  1064                 self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True))
  1065         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1065         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1066             self.Inputs = []
  1066             self.Inputs = []
  1067             for i in xrange(number):
  1067             for i in xrange(number):
  1068                 self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True))
  1068                 self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True))
  1069             self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)]
  1069             self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone=True)]
  1070         self.Value = None
  1070         self.Value = None
  1071         self.PreviousValue = None
  1071         self.PreviousValue = None
  1072 
  1072 
  1073     def Flush(self):
  1073     def Flush(self):
  1074         for input in self.Inputs:
  1074         for input in self.Inputs:
  1103                     self.Parent.ElementNeedRefresh(self)
  1103                     self.Parent.ElementNeedRefresh(self)
  1104                 for output in self.Outputs:
  1104                 for output in self.Outputs:
  1105                     output.SpreadCurrent(False)
  1105                     output.SpreadCurrent(False)
  1106 
  1106 
  1107     # Make a clone of this SFC_Divergence
  1107     # Make a clone of this SFC_Divergence
  1108     def Clone(self, parent, id = None, pos = None):
  1108     def Clone(self, parent, id=None, pos=None):
  1109         divergence = SFC_Divergence(parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id)
  1109         divergence = SFC_Divergence(parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id)
  1110         divergence.SetSize(self.Size[0], self.Size[1])
  1110         divergence.SetSize(self.Size[0], self.Size[1])
  1111         if pos is not None:
  1111         if pos is not None:
  1112             divergence.SetPosition(pos.x, pos.y)
  1112             divergence.SetPosition(pos.x, pos.y)
  1113         else:
  1113         else:
  1118 
  1118 
  1119     def GetConnectorTranslation(self, element):
  1119     def GetConnectorTranslation(self, element):
  1120         return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))
  1120         return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))
  1121 
  1121 
  1122     # Returns the RedrawRect
  1122     # Returns the RedrawRect
  1123     def GetRedrawRect(self, movex = 0, movey = 0):
  1123     def GetRedrawRect(self, movex=0, movey=0):
  1124         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1124         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1125         if movex != 0 or movey != 0:
  1125         if movex != 0 or movey != 0:
  1126             for input in self.Inputs:
  1126             for input in self.Inputs:
  1127                 if input.IsConnected():
  1127                 if input.IsConnected():
  1128                     rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
  1128                     rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
  1145         return self.Type
  1145         return self.Type
  1146 
  1146 
  1147     # Unconnect input and output
  1147     # Unconnect input and output
  1148     def Clean(self):
  1148     def Clean(self):
  1149         for input in self.Inputs:
  1149         for input in self.Inputs:
  1150             input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1150             input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1151         for output in self.Outputs:
  1151         for output in self.Outputs:
  1152             output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1152             output.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1153 
  1153 
  1154     # Add a branch to the divergence
  1154     # Add a branch to the divergence
  1155     def AddBranch(self):
  1155     def AddBranch(self):
  1156         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1156         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
  1157             maxx = 0
  1157             maxx = 0
  1158             for output in self.Outputs:
  1158             for output in self.Outputs:
  1159                 pos = output.GetRelPosition()
  1159                 pos = output.GetRelPosition()
  1160                 maxx = max(maxx, pos.x)
  1160                 maxx = max(maxx, pos.x)
  1161             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True)
  1161             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone=True)
  1162             self.Outputs.append(connector)
  1162             self.Outputs.append(connector)
  1163             self.MoveConnector(connector, 0)
  1163             self.MoveConnector(connector, 0)
  1164         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1164         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1165             maxx = 0
  1165             maxx = 0
  1166             for input in self.Inputs:
  1166             for input in self.Inputs:
  1167                 pos = input.GetRelPosition()
  1167                 pos = input.GetRelPosition()
  1168                 maxx = max(maxx, pos.x)
  1168                 maxx = max(maxx, pos.x)
  1169             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True)
  1169             connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone=True)
  1170             self.Inputs.append(connector)
  1170             self.Inputs.append(connector)
  1171             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
  1171             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
  1172 
  1172 
  1173     # Remove a branch from the divergence
  1173     # Remove a branch from the divergence
  1174     def RemoveBranch(self, connector):
  1174     def RemoveBranch(self, connector):
  1207         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1207         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1208             self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y,
  1208             self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y,
  1209                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1)
  1209                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1)
  1210 
  1210 
  1211     # Refresh the position of wires connected to divergence
  1211     # Refresh the position of wires connected to divergence
  1212     def RefreshConnected(self, exclude = []):
  1212     def RefreshConnected(self, exclude=[]):
  1213         for input in self.Inputs:
  1213         for input in self.Inputs:
  1214             input.MoveConnected(exclude)
  1214             input.MoveConnected(exclude)
  1215         for output in self.Outputs:
  1215         for output in self.Outputs:
  1216             output.MoveConnected(exclude)
  1216             output.MoveConnected(exclude)
  1217 
  1217 
  1242         self.Size[0] = maxx - minx
  1242         self.Size[0] = maxx - minx
  1243         connector.MoveConnected()
  1243         connector.MoveConnected()
  1244         self.RefreshBoundingBox()
  1244         self.RefreshBoundingBox()
  1245 
  1245 
  1246     # Returns the divergence connector that starts with the point given if it exists
  1246     # Returns the divergence connector that starts with the point given if it exists
  1247     def GetConnector(self, position, name = None):
  1247     def GetConnector(self, position, name=None):
  1248         # if a name is given
  1248         # if a name is given
  1249         if name is not None:
  1249         if name is not None:
  1250             # Test each input and output connector
  1250             # Test each input and output connector
  1251             #for input in self.Inputs:
  1251             #for input in self.Inputs:
  1252             #    if name == input.GetName():
  1252             #    if name == input.GetName():
  1259     # Returns input and output divergence connectors
  1259     # Returns input and output divergence connectors
  1260     def GetConnectors(self):
  1260     def GetConnectors(self):
  1261         return {"inputs": self.Inputs, "outputs": self.Outputs}
  1261         return {"inputs": self.Inputs, "outputs": self.Outputs}
  1262 
  1262 
  1263     # Test if point given is on divergence input or output connector
  1263     # Test if point given is on divergence input or output connector
  1264     def TestConnector(self, pt, direction = None, exclude=True):
  1264     def TestConnector(self, pt, direction=None, exclude=True):
  1265         # Test input connector
  1265         # Test input connector
  1266         for input in self.Inputs:
  1266         for input in self.Inputs:
  1267             if input.TestPoint(pt, direction, exclude):
  1267             if input.TestPoint(pt, direction, exclude):
  1268                 return input
  1268                 return input
  1269         # Test output connector
  1269         # Test output connector
  1341             self.RefreshOutputPosition((0, diffy))
  1341             self.RefreshOutputPosition((0, diffy))
  1342         for input in self.Inputs:
  1342         for input in self.Inputs:
  1343             input.MoveConnected()
  1343             input.MoveConnected()
  1344 
  1344 
  1345     # Align output element with this divergence
  1345     # Align output element with this divergence
  1346     def RefreshOutputPosition(self, move = None):
  1346     def RefreshOutputPosition(self, move=None):
  1347         if move:
  1347         if move:
  1348             for output_connector in self.Outputs:
  1348             for output_connector in self.Outputs:
  1349                 wires = output_connector.GetWires()
  1349                 wires = output_connector.GetWires()
  1350                 if len(wires) != 1:
  1350                 if len(wires) != 1:
  1351                     return
  1351                     return
  1507     """
  1507     """
  1508     Class that implements the graphic representation of a jump to step
  1508     Class that implements the graphic representation of a jump to step
  1509     """
  1509     """
  1510 
  1510 
  1511     # Create a new jump
  1511     # Create a new jump
  1512     def __init__(self, parent, target, id = None):
  1512     def __init__(self, parent, target, id=None):
  1513         Graphic_Element.__init__(self, parent)
  1513         Graphic_Element.__init__(self, parent)
  1514         self.SetTarget(target)
  1514         self.SetTarget(target)
  1515         self.Id = id
  1515         self.Id = id
  1516         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1516         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1517         self.Highlights = []
  1517         self.Highlights = []
  1518         # Create an input and output connector
  1518         # Create an input and output connector
  1519         self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
  1519         self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone=True)
  1520         self.Value = None
  1520         self.Value = None
  1521         self.PreviousValue = None
  1521         self.PreviousValue = None
  1522 
  1522 
  1523     def Flush(self):
  1523     def Flush(self):
  1524         if self.Input is not None:
  1524         if self.Input is not None:
  1531             self.Value = self.Input.ReceivingCurrent()
  1531             self.Value = self.Input.ReceivingCurrent()
  1532             if self.Value != self.PreviousValue and self.Visible:
  1532             if self.Value != self.PreviousValue and self.Visible:
  1533                 self.Parent.ElementNeedRefresh(self)
  1533                 self.Parent.ElementNeedRefresh(self)
  1534 
  1534 
  1535     # Make a clone of this SFC_Jump
  1535     # Make a clone of this SFC_Jump
  1536     def Clone(self, parent, id = None, pos = None):
  1536     def Clone(self, parent, id=None, pos=None):
  1537         jump = SFC_Jump(parent, self.Target, id)
  1537         jump = SFC_Jump(parent, self.Target, id)
  1538         jump.SetSize(self.Size[0], self.Size[1])
  1538         jump.SetSize(self.Size[0], self.Size[1])
  1539         if pos is not None:
  1539         if pos is not None:
  1540             jump.SetPosition(pos.x, pos.y)
  1540             jump.SetPosition(pos.x, pos.y)
  1541         else:
  1541         else:
  1545 
  1545 
  1546     def GetConnectorTranslation(self, element):
  1546     def GetConnectorTranslation(self, element):
  1547         return {self.Input: element.Input}
  1547         return {self.Input: element.Input}
  1548 
  1548 
  1549     # Returns the RedrawRect
  1549     # Returns the RedrawRect
  1550     def GetRedrawRect(self, movex = 0, movey = 0):
  1550     def GetRedrawRect(self, movex=0, movey=0):
  1551         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1551         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1552         if self.Input:
  1552         if self.Input:
  1553             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
  1553             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
  1554         if movex != 0 or movey != 0:
  1554         if movex != 0 or movey != 0:
  1555             if self.Input.IsConnected():
  1555             if self.Input.IsConnected():
  1570     def Delete(self):
  1570     def Delete(self):
  1571         self.Parent.DeleteJump(self)
  1571         self.Parent.DeleteJump(self)
  1572 
  1572 
  1573     # Unconnect input
  1573     # Unconnect input
  1574     def Clean(self):
  1574     def Clean(self):
  1575         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1575         self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1576 
  1576 
  1577     # Refresh the size of text for target
  1577     # Refresh the size of text for target
  1578     def RefreshTargetSize(self):
  1578     def RefreshTargetSize(self):
  1579         self.TargetSize = self.Parent.GetTextExtent(self.Target)
  1579         self.TargetSize = self.Parent.GetTextExtent(self.Target)
  1580 
  1580 
  1611             horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
  1611             horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
  1612         self.Input.SetPosition(wx.Point(horizontal_pos, 0))
  1612         self.Input.SetPosition(wx.Point(horizontal_pos, 0))
  1613         self.RefreshConnected()
  1613         self.RefreshConnected()
  1614 
  1614 
  1615     # Refresh the position of wires connected to jump
  1615     # Refresh the position of wires connected to jump
  1616     def RefreshConnected(self, exclude = []):
  1616     def RefreshConnected(self, exclude=[]):
  1617         if self.Input:
  1617         if self.Input:
  1618             self.Input.MoveConnected(exclude)
  1618             self.Input.MoveConnected(exclude)
  1619 
  1619 
  1620     # Returns input jump connector
  1620     # Returns input jump connector
  1621     def GetConnector(self, position = None, name = None):
  1621     def GetConnector(self, position=None, name=None):
  1622         return self.Input
  1622         return self.Input
  1623 
  1623 
  1624     # Returns all the jump connectors
  1624     # Returns all the jump connectors
  1625     def GetConnectors(self):
  1625     def GetConnectors(self):
  1626         return {"inputs": [self.Input], "outputs": []}
  1626         return {"inputs": [self.Input], "outputs": []}
  1627 
  1627 
  1628     # Test if point given is on jump input connector
  1628     # Test if point given is on jump input connector
  1629     def TestConnector(self, pt, direction = None, exclude = True):
  1629     def TestConnector(self, pt, direction=None, exclude=True):
  1630         # Test input connector
  1630         # Test input connector
  1631         if self.Input and self.Input.TestPoint(pt, direction, exclude):
  1631         if self.Input and self.Input.TestPoint(pt, direction, exclude):
  1632             return self.Input
  1632             return self.Input
  1633         return None
  1633         return None
  1634 
  1634 
  1662                         input_block.MoveActionBlock((diffx, 0))
  1662                         input_block.MoveActionBlock((diffx, 0))
  1663                     input_block.Move(diffx, 0)
  1663                     input_block.Move(diffx, 0)
  1664                     input_block.RefreshInputPosition()
  1664                     input_block.RefreshInputPosition()
  1665 
  1665 
  1666     # Can't align output element, because there is no output
  1666     # Can't align output element, because there is no output
  1667     def RefreshOutputPosition(self, move = None):
  1667     def RefreshOutputPosition(self, move=None):
  1668         pass
  1668         pass
  1669 
  1669 
  1670     # Method called when a LeftDClick event have been generated
  1670     # Method called when a LeftDClick event have been generated
  1671     def OnLeftDClick(self, event, dc, scaling):
  1671     def OnLeftDClick(self, event, dc, scaling):
  1672         # Edit the jump properties
  1672         # Edit the jump properties
  1685                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
  1685                 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
  1686             self.Move(movex, 0)
  1686             self.Move(movex, 0)
  1687             self.RefreshInputPosition()
  1687             self.RefreshInputPosition()
  1688             return movex, 0
  1688             return movex, 0
  1689         else:
  1689         else:
  1690             return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac = 2)
  1690             return Graphic_Element.ProcessDragging(self, movex, movey, event, scaling, width_fac=2)
  1691 
  1691 
  1692     # Refresh input element model
  1692     # Refresh input element model
  1693     def RefreshInputModel(self):
  1693     def RefreshInputModel(self):
  1694         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1694         if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1695             input = self.GetPreviousConnector()
  1695             input = self.GetPreviousConnector()
  1783     """
  1783     """
  1784     Class that implements the graphic representation of an action block
  1784     Class that implements the graphic representation of an action block
  1785     """
  1785     """
  1786 
  1786 
  1787     # Create a new action block
  1787     # Create a new action block
  1788     def __init__(self, parent, actions = [], id = None):
  1788     def __init__(self, parent, actions=[], id=None):
  1789         Graphic_Element.__init__(self, parent)
  1789         Graphic_Element.__init__(self, parent)
  1790         self.Id = id
  1790         self.Id = id
  1791         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1791         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1792         self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1792         self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1793         self.Highlights = {}
  1793         self.Highlights = {}
  1794         # Create an input and output connector
  1794         # Create an input and output connector
  1795         self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True)
  1795         self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone=True)
  1796         self.SetActions(actions)
  1796         self.SetActions(actions)
  1797         self.Value = None
  1797         self.Value = None
  1798         self.PreviousValue = None
  1798         self.PreviousValue = None
  1799 
  1799 
  1800     def Flush(self):
  1800     def Flush(self):
  1808             self.Value = self.Input.ReceivingCurrent()
  1808             self.Value = self.Input.ReceivingCurrent()
  1809             if self.Value != self.PreviousValue and self.Visible:
  1809             if self.Value != self.PreviousValue and self.Visible:
  1810                 self.Parent.ElementNeedRefresh(self)
  1810                 self.Parent.ElementNeedRefresh(self)
  1811 
  1811 
  1812     # Make a clone of this SFC_ActionBlock
  1812     # Make a clone of this SFC_ActionBlock
  1813     def Clone(self, parent, id = None, pos = None):
  1813     def Clone(self, parent, id=None, pos=None):
  1814         actions = [action.copy() for action in self.Actions]
  1814         actions = [action.copy() for action in self.Actions]
  1815         action_block = SFC_ActionBlock(parent, actions, id)
  1815         action_block = SFC_ActionBlock(parent, actions, id)
  1816         action_block.SetSize(self.Size[0], self.Size[1])
  1816         action_block.SetSize(self.Size[0], self.Size[1])
  1817         if pos is not None:
  1817         if pos is not None:
  1818             action_block.SetPosition(pos.x, pos.y)
  1818             action_block.SetPosition(pos.x, pos.y)
  1823 
  1823 
  1824     def GetConnectorTranslation(self, element):
  1824     def GetConnectorTranslation(self, element):
  1825         return {self.Input: element.Input}
  1825         return {self.Input: element.Input}
  1826 
  1826 
  1827     # Returns the RedrawRect
  1827     # Returns the RedrawRect
  1828     def GetRedrawRect(self, movex = 0, movey = 0):
  1828     def GetRedrawRect(self, movex=0, movey=0):
  1829         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1829         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
  1830         if self.Input:
  1830         if self.Input:
  1831             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
  1831             rect = rect.Union(self.Input.GetRedrawRect(movex, movey))
  1832         if movex != 0 or movey != 0:
  1832         if movex != 0 or movey != 0:
  1833             if self.Input.IsConnected():
  1833             if self.Input.IsConnected():
  1856     def Delete(self):
  1856     def Delete(self):
  1857         self.Parent.DeleteActionBlock(self)
  1857         self.Parent.DeleteActionBlock(self)
  1858 
  1858 
  1859     # Unconnect input and output
  1859     # Unconnect input and output
  1860     def Clean(self):
  1860     def Clean(self):
  1861         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1861         self.Input.UnConnect(delete=self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1862 
  1862 
  1863     # Refresh the action block bounding box
  1863     # Refresh the action block bounding box
  1864     def RefreshBoundingBox(self):
  1864     def RefreshBoundingBox(self):
  1865         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1865         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1866 
  1866 
  1867     # Refresh the position of wires connected to action block
  1867     # Refresh the position of wires connected to action block
  1868     def RefreshConnected(self, exclude = []):
  1868     def RefreshConnected(self, exclude=[]):
  1869         self.Input.MoveConnected(exclude)
  1869         self.Input.MoveConnected(exclude)
  1870 
  1870 
  1871     # Returns input action block connector
  1871     # Returns input action block connector
  1872     def GetConnector(self, position = None, name = None):
  1872     def GetConnector(self, position=None, name=None):
  1873         return self.Input
  1873         return self.Input
  1874 
  1874 
  1875     # Returns all the action block connectors
  1875     # Returns all the action block connectors
  1876     def GetConnectors(self):
  1876     def GetConnectors(self):
  1877         return {"inputs": [self.Input], "outputs": []}
  1877         return {"inputs": [self.Input], "outputs": []}
  1878 
  1878 
  1879     # Test if point given is on action block input connector
  1879     # Test if point given is on action block input connector
  1880     def TestConnector(self, pt, direction = None, exclude = True):
  1880     def TestConnector(self, pt, direction=None, exclude=True):
  1881         # Test input connector
  1881         # Test input connector
  1882         if self.Input.TestPoint(pt, direction, exclude):
  1882         if self.Input.TestPoint(pt, direction, exclude):
  1883             return self.Input
  1883             return self.Input
  1884         return None
  1884         return None
  1885 
  1885