graphics/SFC_Objects.py
changeset 64 dd6f693e46a1
parent 58 39cd981ff242
child 71 0578bc212c20
equal deleted inserted replaced
63:04a02b4b2a57 64:dd6f693e46a1
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 from wxPython.wx import *
       
    26 import wx
    25 import wx
    27 
    26 
    28 from GraphicCommons import *
    27 from GraphicCommons import *
    29 from plcopen.structures import *
    28 from plcopen.structures import *
    30 
    29 
    48     def __init__(self, parent, name, initial = False, id = None):
    47     def __init__(self, parent, name, initial = False, id = None):
    49         Graphic_Element.__init__(self, parent)
    48         Graphic_Element.__init__(self, parent)
    50         self.Name = name
    49         self.Name = name
    51         self.Initial = initial
    50         self.Initial = initial
    52         self.Id = id
    51         self.Id = id
    53         self.Size = wxSize(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
    52         self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1])
    54         # Create an input and output connector
    53         # Create an input and output connector
    55         if not self.Initial:
    54         if not self.Initial:
    56             self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)
    55             self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
    57         else:
    56         else:
    58             self.Input = None
    57             self.Input = None
    59         self.Output = None
    58         self.Output = None
    60         self.Action = None
    59         self.Action = None
    61     
    60     
    70         self.Parent.DeleteStep(self)
    69         self.Parent.DeleteStep(self)
    71     
    70     
    72     # Unconnect input and output
    71     # Unconnect input and output
    73     def Clean(self):
    72     def Clean(self):
    74         if self.Input:
    73         if self.Input:
    75             self.Input.UnConnect()
    74             self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    76         if self.Output:
    75         if self.Output:
    77             self.Output.UnConnect()
    76             self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    78         if self.Action:
    77         if self.Action:
    79             self.Action.UnConnect()
    78             self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
    80     
    79     
    81     # Add output connector to step
    80     # Add output connector to step
    82     def AddOutput(self):
    81     def AddOutput(self):
    83         if not self.Output:
    82         if not self.Output:
    84             self.Output = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, self.Size[1]), SOUTH)
    83             self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
    85             self.RefreshBoundingBox()
    84             self.RefreshBoundingBox()
    86     
    85     
    87     # Remove output connector from step
    86     # Remove output connector from step
    88     def RemoveOutput(self):
    87     def RemoveOutput(self):
    89         if self.Output:
    88         if self.Output:
    92             self.RefreshBoundingBox()
    91             self.RefreshBoundingBox()
    93     
    92     
    94     # Add action connector to step
    93     # Add action connector to step
    95     def AddAction(self):
    94     def AddAction(self):
    96         if not self.Action:
    95         if not self.Action:
    97             self.Action = Connector(self, "", "ANY", wxPoint(self.Size[0], self.Size[1] / 2), EAST)
    96             self.Action = Connector(self, "", "ANY", wx.Point(self.Size[0], self.Size[1] / 2), EAST)
    98             self.RefreshBoundingBox()
    97             self.RefreshBoundingBox()
    99     
    98     
   100     # Remove action connector from step
    99     # Remove action connector from step
   101     def RemoveAction(self):
   100     def RemoveAction(self):
   102         if self.Action:
   101         if self.Action:
   104             self.Action = None
   103             self.Action = None
   105             self.RefreshBoundingBox()
   104             self.RefreshBoundingBox()
   106     
   105     
   107     # Refresh the step bounding box
   106     # Refresh the step bounding box
   108     def RefreshBoundingBox(self):
   107     def RefreshBoundingBox(self):
   109         dc = wxClientDC(self.Parent)
   108         dc = wx.ClientDC(self.Parent)
   110         # Calculate the bounding box size
   109         # Calculate the bounding box size
   111         if self.Action:
   110         if self.Action:
   112             bbx_width = self.Size[0] + CONNECTOR_SIZE
   111             bbx_width = self.Size[0] + CONNECTOR_SIZE
   113         else:
   112         else:
   114             bbx_width = self.Size[0]
   113             bbx_width = self.Size[0]
   120         else:
   119         else:
   121             bbx_y = self.Pos.y - CONNECTOR_SIZE
   120             bbx_y = self.Pos.y - CONNECTOR_SIZE
   122             bbx_height = self.Size[1] + CONNECTOR_SIZE
   121             bbx_height = self.Size[1] + CONNECTOR_SIZE
   123             if self.Output:
   122             if self.Output:
   124                 bbx_height += CONNECTOR_SIZE
   123                 bbx_height += CONNECTOR_SIZE
   125         #self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1)
   124         #self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1)
   126         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   125         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   127         
   126         
   128     # Refresh the positions of the step connectors
   127     # Refresh the positions of the step connectors
   129     def RefreshConnectors(self):
   128     def RefreshConnectors(self):
   130         # Update input position if it exists
   129         # Update input position if it exists
   131         if self.Input:
   130         if self.Input:
   132             self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0))
   131             self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
   133         # Update output position
   132         # Update output position
   134         if self.Output:
   133         if self.Output:
   135             self.Output.SetPosition(wxPoint(self.Size[0] / 2, self.Size[1]))
   134             self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1]))
   136         # Update action position if it exists
   135         # Update action position if it exists
   137         if self.Action:
   136         if self.Action:
   138             self.Action.SetPosition(wxPoint(self.Size[0], self.Size[1] / 2))
   137             self.Action.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
   139         self.RefreshConnected()
   138         self.RefreshConnected()
   140     
   139     
   141     # Refresh the position of wires connected to step
   140     # Refresh the position of wires connected to step
   142     def RefreshConnected(self, exclude = []):
   141     def RefreshConnected(self, exclude = []):
   143         if self.Input:
   142         if self.Input:
   235             return max(0, action_block.GetLineNumber() - 1)
   234             return max(0, action_block.GetLineNumber() - 1)
   236         return 0
   235         return 0
   237     
   236     
   238     # Returns the step minimum size
   237     # Returns the step minimum size
   239     def GetMinSize(self):
   238     def GetMinSize(self):
   240         dc = wxClientDC(self.Parent)
   239         dc = wx.ClientDC(self.Parent)
   241         text_width, text_height = dc.GetTextExtent(self.Name)
   240         text_width, text_height = dc.GetTextExtent(self.Name)
   242         if self.Initial:
   241         if self.Initial:
   243             return text_width + 14, text_height + 14
   242             return text_width + 14, text_height + 14
   244         else:
   243         else:
   245             return text_width + 10, text_height + 10
   244             return text_width + 10, text_height + 10
   283             wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1]
   282             wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1]
   284             diffy = wire_size - output_pos.y + current_pos.y
   283             diffy = wire_size - output_pos.y + current_pos.y
   285             if diffy != 0:
   284             if diffy != 0:
   286                 if isinstance(output_block, SFC_Step):
   285                 if isinstance(output_block, SFC_Step):
   287                     output_block.MoveActionBlock((diffx, diffy))
   286                     output_block.MoveActionBlock((diffx, diffy))
   288                 wires[0][0].SetPoints([wxPoint(current_pos.x, current_pos.y + wire_size),
   287                 wires[0][0].SetPoints([wx.Point(current_pos.x, current_pos.y + wire_size),
   289                     wxPoint(current_pos.x, current_pos.y)])
   288                     wx.Point(current_pos.x, current_pos.y)])
   290                 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0:
   289                 if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0:
   291                     output_block.Move(diffx, diffy, self.Parent.Wires)
   290                     output_block.Move(diffx, diffy, self.Parent.Wires)
   292                     output_block.RefreshOutputPosition((diffx, diffy))
   291                     output_block.RefreshOutputPosition((diffx, diffy))
   293                 else:
   292                 else:
   294                     output_block.RefreshPosition()
   293                     output_block.RefreshPosition()
   392             elif self.Output:
   391             elif self.Output:
   393                 self.Output.RefreshWires()
   392                 self.Output.RefreshWires()
   394     
   393     
   395     # Draws step
   394     # Draws step
   396     def Draw(self, dc):
   395     def Draw(self, dc):
   397         dc.SetPen(wxBLACK_PEN)
   396         dc.SetPen(wx.BLACK_PEN)
   398         dc.SetBrush(wxWHITE_BRUSH)
   397         dc.SetBrush(wx.WHITE_BRUSH)
   399         # Draw two rectangles for representing the step
   398         # Draw two rectangles for representing the step
   400         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   399         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   401         if self.Initial:
   400         if self.Initial:
   402             dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3)
   401             dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3)
   403         # Draw step name
   402         # Draw step name
   422 """
   421 """
   423 
   422 
   424 class SFC_Transition(Graphic_Element):
   423 class SFC_Transition(Graphic_Element):
   425     
   424     
   426     # Create a new transition
   425     # Create a new transition
   427     def __init__(self, parent, type = "reference", condition = "", id = None):
   426     def __init__(self, parent, type = "reference", condition = None, id = None):
   428         Graphic_Element.__init__(self, parent)
   427         Graphic_Element.__init__(self, parent)
   429         self.Type = type
   428         self.Type = None
   430         self.Condition = condition
       
   431         self.Id = id
   429         self.Id = id
   432         self.Size = wxSize(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   430         self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1])
   433         # Create an input and output connector
   431         # Create an input and output connector
   434         self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)
   432         self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
   435         self.Output = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, self.Size[1]), SOUTH)
   433         self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)
       
   434         self.SetType(type, condition)
   436     
   435     
   437     # Destructor
   436     # Destructor
   438     def __del__(self):
   437     def __del__(self):
   439         self.Input = None
   438         self.Input = None
   440         self.Output = None
   439         self.Output = None
       
   440         if self.Type == "connection":
       
   441             self.Condition = None
   441     
   442     
   442     # Forbids to change the transition size
   443     # Forbids to change the transition size
   443     def SetSize(self, width, height):
   444     def SetSize(self, width, height):
   444         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   445         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   445             Graphic_Element.SetSize(self, width, height)
   446             Graphic_Element.SetSize(self, width, height)
   447     # Forbids to resize the transition
   448     # Forbids to resize the transition
   448     def Resize(self, x, y, width, height):
   449     def Resize(self, x, y, width, height):
   449         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   450         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
   450             Graphic_Element.Resize(self, x, y, width, height)
   451             Graphic_Element.Resize(self, x, y, width, height)
   451     
   452     
       
   453     # Refresh the size of text for name
       
   454     def RefreshConditionSize(self):
       
   455         if self.Type != "connection":
       
   456             dc = wx.ClientDC(self.Parent)
       
   457             if self.Condition != "":
       
   458                 self.ConditionSize = dc.GetTextExtent(self.Condition)
       
   459             else:
       
   460                 self.ConditionSize = dc.GetTextExtent("Transition")
       
   461     
   452     # Delete this transition by calling the appropriate method
   462     # Delete this transition by calling the appropriate method
   453     def Delete(self):
   463     def Delete(self):
   454         self.Parent.DeleteTransition(self)
   464         self.Parent.DeleteTransition(self)
   455     
   465     
   456     # Unconnect input and output
   466     # Unconnect input and output
   457     def Clean(self):
   467     def Clean(self):
   458         self.Input.UnConnect()
   468         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   459         self.Output.UnConnect()
   469         self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
       
   470         if self.Type == "connection":
       
   471             self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   460     
   472     
   461     # Refresh the transition bounding box
   473     # Refresh the transition bounding box
   462     def RefreshBoundingBox(self):
   474     def RefreshBoundingBox(self):
   463         dc = wxClientDC(self.Parent)
   475         dc = wx.ClientDC(self.Parent)
   464         if self.Condition != "":
   476         if self.Type == "connection":
   465             text_width, text_height = dc.GetTextExtent(self.Condition)
   477             bbx_x = self.Pos.x - CONNECTOR_SIZE
   466         else:
   478             bbx_width = self.Size[0] + CONNECTOR_SIZE
   467             text_width, text_height = dc.GetTextExtent("Transition")
   479             bbx_y = self.Pos.y
   468         # Calculate the bounding box size
   480             bbx_height = self.Size[1]
   469         bbx_width = self.Size[0] + 5 + text_width
   481         else:
   470         bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2)
   482             text_width, text_height = self.ConditionSize
   471         bbx_height = max(self.Size[1], text_height)
   483             # Calculate the bounding box size
   472         self.BoundingBox = wxRect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height - 4)
   484             bbx_x = self.Pos.x
       
   485             bbx_width = self.Size[0] + 5 + text_width
       
   486             bbx_y = self.Pos.y - max(0, (text_height - 5 - self.Size[1]) / 2)
       
   487             bbx_height = max(self.Size[1], text_height) - 5
       
   488         self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
   473         
   489         
   474     # Returns the connector connected to input
   490     # Returns the connector connected to input
   475     def GetPreviousConnector(self):
   491     def GetPreviousConnector(self):
   476         wires = self.Input.GetWires()
   492         wires = self.Input.GetWires()
   477         if len(wires) == 1:
   493         if len(wires) == 1:
   486         return None
   502         return None
   487     
   503     
   488     # Refresh the positions of the transition connectors
   504     # Refresh the positions of the transition connectors
   489     def RefreshConnectors(self):
   505     def RefreshConnectors(self):
   490         # Update input position
   506         # Update input position
   491         self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0))
   507         self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
   492         # Update output position
   508         # Update output position
   493         self.Output.SetPosition(wxPoint(self.Size[0] / 2, self.Size[1]))
   509         self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1]))
       
   510         if self.Type == "connection":
       
   511             self.Condition.SetPosition(wx.Point(0, self.Size[1] / 2))
   494         self.RefreshConnected()
   512         self.RefreshConnected()
   495     
   513     
   496     # Refresh the position of the wires connected to transition
   514     # Refresh the position of the wires connected to transition
   497     def RefreshConnected(self, exclude = []):
   515     def RefreshConnected(self, exclude = []):
   498         self.Input.MoveConnected(exclude)
   516         self.Input.MoveConnected(exclude)
   499         self.Output.MoveConnected(exclude)
   517         self.Output.MoveConnected(exclude)
       
   518         if self.Type == "connection":
       
   519             self.Condition.MoveConnected(exclude)
   500     
   520     
   501     # Returns the transition connector that starts with the point given if it exists 
   521     # Returns the transition connector that starts with the point given if it exists 
   502     def GetConnector(self, position, name = None):
   522     def GetConnector(self, position, name = None):
   503         # if a name is given
   523         # if a name is given
   504         if name:
   524         if name:
   505             # Test input and output connector
   525             # Test input and output connector
   506             if name == self.Input.GetName():
   526             if name == self.Input.GetName():
   507                 return self.Input
   527                 return self.Input
   508             if name == self.Output.GetName():
   528             if name == self.Output.GetName():
   509                 return self.Output
   529                 return self.Output
       
   530             if self.Type == "connection" and name == self.Condition.GetName():
       
   531                 return self.Condition
   510         # Test input connector
   532         # Test input connector
   511         input_pos = self.Input.GetRelPosition()
   533         input_pos = self.Input.GetRelPosition()
   512         if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   534         if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y:
   513             return self.Input
   535             return self.Input
   514         # Test output connector
   536         # Test output connector
   515         output_pos = self.Output.GetRelPosition()
   537         output_pos = self.Output.GetRelPosition()
   516         if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
   538         if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y:
   517             return self.Output
   539             return self.Output
       
   540         if self.Type == "connection":
       
   541             # Test condition connector
       
   542             condition_pos = self.Condition.GetRelPosition()
       
   543             if position.x == self.Pos.x + condition_pos.x and position.y == self.Pos.y + condition_pos.y:
       
   544                 return self.Condition
   518         return None
   545         return None
   519     
   546     
   520     # Returns input and output transition connectors
   547     # Returns input and output transition connectors
   521     def GetConnectors(self):
   548     def GetConnectors(self):
   522         return {"input":self.Input,"output":self.Output}
   549         connectors = {"input":self.Input,"output":self.Output}
       
   550         if self.Type == "connection":
       
   551             connectors["connection"] = self.Condition
       
   552         return connectors
   523     
   553     
   524     # Test if point given is on transition input or output connector
   554     # Test if point given is on transition input or output connector
   525     def TestConnector(self, pt, exclude=True):
   555     def TestConnector(self, pt, exclude=True):
   526         # Test input connector
   556         # Test input connector
   527         if self.Input.TestPoint(pt, exclude):
   557         if self.Input.TestPoint(pt, exclude):
   528             return self.Input
   558             return self.Input
   529         # Test output connector
   559         # Test output connector
   530         if self.Output.TestPoint(pt, exclude):
   560         if self.Output.TestPoint(pt, exclude):
   531             return self.Output
   561             return self.Output
       
   562         # Test condition connector
       
   563         if self.Type == "connection" and self.Condition.TestPoint(pt, exclude):
       
   564             return self.Condition
   532         return None
   565         return None
   533 
   566 
   534     # Changes the transition type
   567     # Changes the transition type
   535     def SetType(self, type):
   568     def SetType(self, type, condition = None):
   536         self.Type = type
   569         if self.Type != type:
       
   570             if self.Type == "connection":
       
   571                self.Condition.UnConnect() 
       
   572             self.Type = type
       
   573             if type == "connection":
       
   574                 self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST)
       
   575             else:
       
   576                 if condition == None:
       
   577                     condition = ""
       
   578                 self.Condition = condition
       
   579                 self.RefreshConditionSize()
       
   580         elif self.Type != "connection":
       
   581             if condition == None:
       
   582                 condition = ""
       
   583             self.Condition = condition
       
   584             self.RefreshConditionSize()
       
   585         self.RefreshBoundingBox()
   537         
   586         
   538     # Returns the transition type
   587     # Returns the transition type
   539     def GetType(self):
   588     def GetType(self):
   540         return self.Type
   589         return self.Type
   541 
   590 
   542     # Changes the transition condition
       
   543     def SetCondition(self, condition):
       
   544         self.Condition = condition
       
   545         self.RefreshBoundingBox()
       
   546 
       
   547     # Returns the transition condition
   591     # Returns the transition condition
   548     def GetCondition(self):
   592     def GetCondition(self):
   549         return self.Condition
   593         if self.Type != "connection":
       
   594             return self.Condition
       
   595         return None
   550         
   596         
   551     # Returns the transition minimum size
   597     # Returns the transition minimum size
   552     def GetMinSize(self):
   598     def GetMinSize(self):
   553         return SFC_TRANSITION_SIZE
   599         return SFC_TRANSITION_SIZE
   554     
   600     
   645             else:
   691             else:
   646                 self.Output.RefreshWires()
   692                 self.Output.RefreshWires()
   647     
   693     
   648     # Draws transition
   694     # Draws transition
   649     def Draw(self, dc):
   695     def Draw(self, dc):
   650         dc.SetPen(wxBLACK_PEN)
   696         dc.SetPen(wx.BLACK_PEN)
   651         dc.SetBrush(wxBLACK_BRUSH)
   697         dc.SetBrush(wx.BLACK_BRUSH)
   652         # Draw plain rectangle for representing the transition
   698         # Draw plain rectangle for representing the transition
   653         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   699         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   654         # Draw transition condition
   700         # Draw transition condition
   655         if self.Condition != "":
   701         if self.Type != "connection":
   656             text_width, text_height = dc.GetTextExtent(self.Condition)
   702             text_width, text_height = self.ConditionSize
   657             condition = self.Condition
   703             if self.Condition != "":
   658         else:
   704                 condition = self.Condition
   659             text_width, text_height = dc.GetTextExtent("Transition")
   705             else:
   660             condition = "Transition"
   706                 condition = "Transition"
   661         dc.DrawText(condition, self.Pos.x + self.Size[0] + 5,
   707             dc.DrawText(condition, self.Pos.x + self.Size[0] + 5,
   662                     self.Pos.y + (self.Size[1] - text_height) / 2)
   708                         self.Pos.y + (self.Size[1] - text_height) / 2)
   663         # Draw input and output connectors
   709         # Draw input and output connectors
   664         self.Input.Draw(dc)
   710         self.Input.Draw(dc)
   665         self.Output.Draw(dc)
   711         self.Output.Draw(dc)
       
   712         if self.Type == "connection":
       
   713             self.Condition.Draw(dc)
   666         Graphic_Element.Draw(self, dc)
   714         Graphic_Element.Draw(self, dc)
   667 
   715 
   668 #-------------------------------------------------------------------------------
   716 #-------------------------------------------------------------------------------
   669 #                Sequencial Function Chart Divergence and Convergence
   717 #                Sequencial Function Chart Divergence and Convergence
   670 #-------------------------------------------------------------------------------
   718 #-------------------------------------------------------------------------------
   682         self.Type = type
   730         self.Type = type
   683         self.Id = id
   731         self.Id = id
   684         self.RealConnectors = None
   732         self.RealConnectors = None
   685         number = max(2, number)
   733         number = max(2, number)
   686         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   734         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   687             self.Size = wxSize((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1)
   735             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 1)
   688         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   736         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   689             self.Size = wxSize((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3)
   737             self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3)
   690         # Create an input and output connector
   738         # Create an input and output connector
   691         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   739         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   692             self.Inputs = [Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)]
   740             self.Inputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)]
   693             self.Outputs = []
   741             self.Outputs = []
   694             for i in xrange(number):
   742             for i in xrange(number):
   695                 self.Outputs.append(Connector(self, "", "ANY", wxPoint(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
   743                 self.Outputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH))
   696         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   744         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   697             self.Inputs = []
   745             self.Inputs = []
   698             for i in xrange(number):
   746             for i in xrange(number):
   699                 self.Inputs.append(Connector(self, "", "ANY", wxPoint(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
   747                 self.Inputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH))
   700             self.Outputs = [Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, self.Size[1]), SOUTH)]
   748             self.Outputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)]
   701     
   749     
   702     # Destructor
   750     # Destructor
   703     def __del__(self):
   751     def __del__(self):
   704         self.Inputs = []
   752         self.Inputs = []
   705         self.Outputs = []
   753         self.Outputs = []
   718         return self.Type
   766         return self.Type
   719     
   767     
   720     # Unconnect input and output
   768     # Unconnect input and output
   721     def Clean(self):
   769     def Clean(self):
   722         for input in self.Inputs:
   770         for input in self.Inputs:
   723             input.UnConnect()
   771             input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   724         for output in self.Outputs:
   772         for output in self.Outputs:
   725             output.UnConnect()
   773             output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
   726     
   774     
   727     # Add a branch to the divergence
   775     # Add a branch to the divergence
   728     def AddBranch(self):
   776     def AddBranch(self):
   729         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   777         if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
   730             maxx = 0
   778             maxx = 0
   731             for output in self.Outputs:
   779             for output in self.Outputs:
   732                 pos = output.GetRelPosition()
   780                 pos = output.GetRelPosition()
   733                 maxx = max(maxx, pos.x)
   781                 maxx = max(maxx, pos.x)
   734             connector = Connector(self, "", "ANY", wxPoint(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
   782             connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)
   735             self.Outputs.append(connector)
   783             self.Outputs.append(connector)
   736             self.MoveConnector(connector, 0)
   784             self.MoveConnector(connector, 0)
   737         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   785         elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   738             maxx = 0
   786             maxx = 0
   739             for input in self.Inputs:
   787             for input in self.Inputs:
   740                 pos = input.GetRelPosition()
   788                 pos = input.GetRelPosition()
   741                 maxx = max(maxx, pos.x)
   789                 maxx = max(maxx, pos.x)
   742             connector = Connector(self, "", "ANY", wxPoint(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
   790             connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
   743             self.Inputs.append(connector)
   791             self.Inputs.append(connector)
   744             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
   792             self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
   745     
   793     
   746     # Remove a branch from the divergence
   794     # Remove a branch from the divergence
   747     def RemoveBranch(self, connector):
   795     def RemoveBranch(self, connector):
   767         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None
   815         return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, False) != None
   768     
   816     
   769     # Refresh the divergence bounding box
   817     # Refresh the divergence bounding box
   770     def RefreshBoundingBox(self):
   818     def RefreshBoundingBox(self):
   771         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   819         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   772             self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - 2, 
   820             self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - 2, 
   773                 self.Size[0] + 1, self.Size[1] + 5)
   821                 self.Size[0] + 1, self.Size[1] + 5)
   774         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   822         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
   775             self.BoundingBox = wxRect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, 
   823             self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2, 
   776                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5)
   824                 self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5)
   777     
   825     
   778     # Refresh the position of wires connected to divergence
   826     # Refresh the position of wires connected to divergence
   779     def RefreshConnected(self, exclude = []):
   827     def RefreshConnected(self, exclude = []):
   780         for input in self.Inputs:
   828         for input in self.Inputs:
   783             output.MoveConnected(exclude)
   831             output.MoveConnected(exclude)
   784     
   832     
   785     # Moves the divergence connector given
   833     # Moves the divergence connector given
   786     def MoveConnector(self, connector, movex):
   834     def MoveConnector(self, connector, movex):
   787         position = connector.GetRelPosition()
   835         position = connector.GetRelPosition()
   788         connector.SetPosition(wxPoint(position.x + movex, position.y))
   836         connector.SetPosition(wx.Point(position.x + movex, position.y))
   789         minx = self.Size[0]
   837         minx = self.Size[0]
   790         maxx = 0
   838         maxx = 0
   791         for input in self.Inputs:
   839         for input in self.Inputs:
   792             input_pos = input.GetRelPosition()
   840             input_pos = input.GetRelPosition()
   793             minx = min(minx, input_pos.x)
   841             minx = min(minx, input_pos.x)
   797             minx = min(minx, output_pos.x)
   845             minx = min(minx, output_pos.x)
   798             maxx = max(maxx, output_pos.x)
   846             maxx = max(maxx, output_pos.x)
   799         if minx != 0:
   847         if minx != 0:
   800             for input in self.Inputs:
   848             for input in self.Inputs:
   801                 input_pos = input.GetRelPosition()
   849                 input_pos = input.GetRelPosition()
   802                 input.SetPosition(wxPoint(input_pos.x - minx, input_pos.y))
   850                 input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y))
   803             for output in self.Outputs:
   851             for output in self.Outputs:
   804                 output_pos = output.GetRelPosition()
   852                 output_pos = output.GetRelPosition()
   805                 output.SetPosition(wxPoint(output_pos.x - minx, output_pos.y))
   853                 output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y))
   806         self.Pos.x += minx
   854         self.Pos.x += minx
   807         self.Size[0] = maxx - minx
   855         self.Size[0] = maxx - minx
   808         connector.MoveConnected()
   856         connector.MoveConnected()
   809         self.RefreshBoundingBox()
   857         self.RefreshBoundingBox()
   810     
   858     
   850     # Changes the divergence size
   898     # Changes the divergence size
   851     def SetSize(self, width, height):
   899     def SetSize(self, width, height):
   852         for i, input in enumerate(self.Inputs):
   900         for i, input in enumerate(self.Inputs):
   853             position = input.GetRelPosition()
   901             position = input.GetRelPosition()
   854             if self.RealConnectors:
   902             if self.RealConnectors:
   855                 input.SetPosition(wxPoint(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
   903                 input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0))
   856             else:
   904             else:
   857                 input.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0))
   905                 input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0))
   858             input.MoveConnected()
   906             input.MoveConnected()
   859         for i, output in enumerate(self.Outputs):
   907         for i, output in enumerate(self.Outputs):
   860             position = output.GetRelPosition()
   908             position = output.GetRelPosition()
   861             if self.RealConnectors:
   909             if self.RealConnectors:
   862                 output.SetPosition(wxPoint(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1]))
   910                 output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), self.Size[1]))
   863             else:
   911             else:
   864                 output.SetPosition(wxPoint(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1]))
   912                 output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), self.Size[1]))
   865             output.MoveConnected()
   913             output.MoveConnected()
   866         self.Size = wxSize(width, height)
   914         self.Size = wx.Size(width, height)
   867         self.RefreshBoundingBox()
   915         self.RefreshBoundingBox()
   868     
   916     
   869     # Returns the divergence minimum size
   917     # Returns the divergence minimum size
   870     def GetMinSize(self):
   918     def GetMinSize(self):
   871         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   919         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
   937         pos = GetScaledEventPosition(event, dc, scaling)
   985         pos = GetScaledEventPosition(event, dc, scaling)
   938         # Test if a connector have been handled
   986         # Test if a connector have been handled
   939         connector = self.TestConnector(pos, False)
   987         connector = self.TestConnector(pos, False)
   940         if connector:
   988         if connector:
   941             self.Handle = (HANDLE_CONNECTOR, connector)
   989             self.Handle = (HANDLE_CONNECTOR, connector)
   942             self.Parent.SetCursor(wxStockCursor(wxCURSOR_HAND))
   990             self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
   943             self.Selected = False
   991             self.Selected = False
   944             # Initializes the last position
   992             # Initializes the last position
   945             self.oldPos = GetScaledEventPosition(event, dc, scaling)
   993             self.oldPos = GetScaledEventPosition(event, dc, scaling)
   946         else:
   994         else:
   947             self.RealConnectors = {"Inputs":[],"Outputs":[]}
   995             self.RealConnectors = {"Inputs":[],"Outputs":[]}
  1019                 for output in self.Outputs:
  1067                 for output in self.Outputs:
  1020                     output.RefreshWires()
  1068                     output.RefreshWires()
  1021     
  1069     
  1022     # Draws divergence
  1070     # Draws divergence
  1023     def Draw(self, dc):
  1071     def Draw(self, dc):
  1024         dc.SetPen(wxBLACK_PEN)
  1072         dc.SetPen(wx.BLACK_PEN)
  1025         dc.SetBrush(wxBLACK_BRUSH)
  1073         dc.SetBrush(wx.BLACK_BRUSH)
  1026         # Draw plain rectangle for representing the divergence
  1074         # Draw plain rectangle for representing the divergence
  1027         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1075         if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
  1028             dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1076             dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1029         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1077         elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
  1030             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, 
  1078             dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, 
  1051     # Create a new jump
  1099     # Create a new jump
  1052     def __init__(self, parent, target, id = None):
  1100     def __init__(self, parent, target, id = None):
  1053         Graphic_Element.__init__(self, parent)
  1101         Graphic_Element.__init__(self, parent)
  1054         self.Target = target
  1102         self.Target = target
  1055         self.Id = id
  1103         self.Id = id
  1056         self.Size = wxSize(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1104         self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1])
  1057         # Create an input and output connector
  1105         # Create an input and output connector
  1058         self.Input = Connector(self, "", "ANY", wxPoint(self.Size[0] / 2, 0), NORTH)
  1106         self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)
  1059         
  1107         
  1060     # Destructor
  1108     # Destructor
  1061     def __del__(self):
  1109     def __del__(self):
  1062         self.Input = None
  1110         self.Input = None
  1063     
  1111     
  1075     def Delete(self):
  1123     def Delete(self):
  1076         self.Parent.DeleteJump(self)
  1124         self.Parent.DeleteJump(self)
  1077     
  1125     
  1078     # Unconnect input
  1126     # Unconnect input
  1079     def Clean(self):
  1127     def Clean(self):
  1080         self.Input.UnConnect()
  1128         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1081     
  1129     
  1082     # Refresh the jump bounding box
  1130     # Refresh the jump bounding box
  1083     def RefreshBoundingBox(self):
  1131     def RefreshBoundingBox(self):
  1084         dc = wxClientDC(self.Parent)
  1132         dc = wx.ClientDC(self.Parent)
  1085         text_width, text_height = dc.GetTextExtent(self.Target)
  1133         text_width, text_height = dc.GetTextExtent(self.Target)
  1086         # Calculate the bounding box size
  1134         # Calculate the bounding box size
  1087         bbx_width = self.Size[0] + 2 + text_width
  1135         bbx_width = self.Size[0] + 2 + text_width
  1088         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1136         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, 
  1089                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1137                 bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1)
  1090     
  1138     
  1091     # Returns the connector connected to input
  1139     # Returns the connector connected to input
  1092     def GetPreviousConnector(self):
  1140     def GetPreviousConnector(self):
  1093         wires = self.Input.GetWires()
  1141         wires = self.Input.GetWires()
  1095             return wires[0][0].EndConnected
  1143             return wires[0][0].EndConnected
  1096         return None
  1144         return None
  1097     
  1145     
  1098     # Refresh the element connectors position
  1146     # Refresh the element connectors position
  1099     def RefreshConnectors(self):
  1147     def RefreshConnectors(self):
  1100         self.Input.SetPosition(wxPoint(self.Size[0] / 2, 0))
  1148         self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
  1101         self.RefreshConnected()
  1149         self.RefreshConnected()
  1102     
  1150     
  1103     # Refresh the position of wires connected to jump
  1151     # Refresh the position of wires connected to jump
  1104     def RefreshConnected(self, exclude = []):
  1152     def RefreshConnected(self, exclude = []):
  1105         if self.Input:
  1153         if self.Input:
  1189             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1237             if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
  1190                 self.RefreshInputModel()
  1238                 self.RefreshInputModel()
  1191     
  1239     
  1192     # Draws divergence
  1240     # Draws divergence
  1193     def Draw(self, dc):
  1241     def Draw(self, dc):
  1194         dc.SetPen(wxBLACK_PEN)
  1242         dc.SetPen(wx.BLACK_PEN)
  1195         dc.SetBrush(wxBLACK_BRUSH)
  1243         dc.SetBrush(wx.BLACK_BRUSH)
  1196         # Draw plain rectangle for representing the divergence
  1244         # Draw plain rectangle for representing the divergence
  1197         dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])
  1245         dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])
  1198         points = [wxPoint(self.Pos.x, self.Pos.y),
  1246         points = [wx.Point(self.Pos.x, self.Pos.y),
  1199                   wxPoint(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3),
  1247                   wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3),
  1200                   wxPoint(self.Pos.x + self.Size[0], self.Pos.y),
  1248                   wx.Point(self.Pos.x + self.Size[0], self.Pos.y),
  1201                   wxPoint(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])]
  1249                   wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])]
  1202         dc.DrawPolygon(points)
  1250         dc.DrawPolygon(points)
  1203         text_width, text_height = dc.GetTextExtent(self.Target)
  1251         text_width, text_height = dc.GetTextExtent(self.Target)
  1204         dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2,
  1252         dc.DrawText(self.Target, self.Pos.x + self.Size[0] + 2,
  1205                     self.Pos.y + (self.Size[1] - text_height) / 2)
  1253                     self.Pos.y + (self.Size[1] - text_height) / 2)
  1206         # Draw input connector
  1254         # Draw input connector
  1221     
  1269     
  1222     # Create a new action block
  1270     # Create a new action block
  1223     def __init__(self, parent, actions = [], id = None):
  1271     def __init__(self, parent, actions = [], id = None):
  1224         Graphic_Element.__init__(self, parent)
  1272         Graphic_Element.__init__(self, parent)
  1225         self.Id = id
  1273         self.Id = id
  1226         self.Size = wxSize(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1274         self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1])
  1227         # Create an input and output connector
  1275         # Create an input and output connector
  1228         self.Input = Connector(self, "", "ANY", wxPoint(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
  1276         self.Input = Connector(self, "", "ANY", wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST)
  1229         self.SetActions(actions)
  1277         self.SetActions(actions)
  1230     
  1278     
  1231     # Destructor
  1279     # Destructor
  1232     def __del__(self):
  1280     def __del__(self):
  1233         self.Input = None
  1281         self.Input = None
  1254     def Delete(self):
  1302     def Delete(self):
  1255         self.Parent.DeleteActionBlock(self)
  1303         self.Parent.DeleteActionBlock(self)
  1256     
  1304     
  1257     # Unconnect input and output
  1305     # Unconnect input and output
  1258     def Clean(self):
  1306     def Clean(self):
  1259         self.Input.UnConnect()
  1307         self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE)
  1260         
  1308         
  1261     # Refresh the action block bounding box
  1309     # Refresh the action block bounding box
  1262     def RefreshBoundingBox(self):
  1310     def RefreshBoundingBox(self):
  1263         self.BoundingBox = wxRect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
  1311         self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0], self.Size[1])
  1264     
  1312     
  1265     # Refresh the position of wires connected to action block
  1313     # Refresh the position of wires connected to action block
  1266     def RefreshConnected(self, exclude = []):
  1314     def RefreshConnected(self, exclude = []):
  1267         self.Input.MoveConnected(exclude)
  1315         self.Input.MoveConnected(exclude)
  1268     
  1316     
  1277             return self.Input
  1325             return self.Input
  1278         return None
  1326         return None
  1279     
  1327     
  1280     # Changes the action block actions
  1328     # Changes the action block actions
  1281     def SetActions(self, actions):
  1329     def SetActions(self, actions):
  1282         dc = wxClientDC(self.Parent)
  1330         dc = wx.ClientDC(self.Parent)
  1283         self.Actions = actions
  1331         self.Actions = actions
  1284         self.ColSize = [0, 0, 0]
  1332         self.ColSize = [0, 0, 0]
  1285         for action in self.Actions:
  1333         for action in self.Actions:
  1286             width, height = dc.GetTextExtent(action["qualifier"])
  1334             width, height = dc.GetTextExtent(action["qualifier"])
  1287             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1335             self.ColSize[0] = max(self.ColSize[0], width + 10)
  1293             if "indicator" in action and action["indicator"] != "":
  1341             if "indicator" in action and action["indicator"] != "":
  1294                 width, height = dc.GetTextExtent(action["indicator"])
  1342                 width, height = dc.GetTextExtent(action["indicator"])
  1295                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1343                 self.ColSize[2] = max(self.ColSize[2], width + 10)
  1296         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1344         if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
  1297             line_size = self.GetLineSize()
  1345             line_size = self.GetLineSize()
  1298             self.Size = wxSize(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size)
  1346             self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size)
  1299         else:
  1347         else:
  1300             self.Size = wxSize(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1348             self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2],
  1301                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1349                 SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1])
  1302         self.RefreshBoundingBox()
  1350         self.RefreshBoundingBox()
  1303         if self.Input:
  1351         if self.Input:
  1304             wires = self.Input.GetWires()
  1352             wires = self.Input.GetWires()
  1305             if len(wires) == 1:
  1353             if len(wires) == 1:
  1341     def RefreshModel(self, move=True):
  1389     def RefreshModel(self, move=True):
  1342         self.Parent.RefreshActionBlockModel(self)
  1390         self.Parent.RefreshActionBlockModel(self)
  1343     
  1391     
  1344     # Draws divergence
  1392     # Draws divergence
  1345     def Draw(self, dc):
  1393     def Draw(self, dc):
  1346         dc.SetPen(wxBLACK_PEN)
  1394         dc.SetPen(wx.BLACK_PEN)
  1347         dc.SetBrush(wxWHITE_BRUSH)
  1395         dc.SetBrush(wx.WHITE_BRUSH)
  1348         colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]]
  1396         colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]]
  1349         # Draw plain rectangle for representing the action block
  1397         # Draw plain rectangle for representing the action block
  1350         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1398         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1351         dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, 
  1399         dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, 
  1352                 self.Pos.x + colsize[0], self.Pos.y + self.Size[1])
  1400                 self.Pos.x + colsize[0], self.Pos.y + self.Size[1])