graphics/FBD_Objects.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1847 6198190bc121
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    25 import wx
    25 import wx
    26 
    26 
    27 from graphics.GraphicCommons import *
    27 from graphics.GraphicCommons import *
    28 from plcopen.structures import *
    28 from plcopen.structures import *
    29 
    29 
    30 #-------------------------------------------------------------------------------
    30 
       
    31 # -------------------------------------------------------------------------------
    31 #                         Function Block Diagram Block
    32 #                         Function Block Diagram Block
    32 #-------------------------------------------------------------------------------
    33 # -------------------------------------------------------------------------------
    33 
    34 
    34 """
       
    35 Class that implements the graphic representation of a function block
       
    36 """
       
    37 
    35 
    38 def TestConnectorName(name, block_type):
    36 def TestConnectorName(name, block_type):
    39     return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2")
    37     return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2")
    40 
    38 
       
    39 
    41 class FBD_Block(Graphic_Element):
    40 class FBD_Block(Graphic_Element):
    42     
    41     """
       
    42     Class that implements the graphic representation of a function block
       
    43     """
       
    44 
    43     # Create a new block
    45     # Create a new block
    44     def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0):
    46     def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors={}, executionControl=False, executionOrder=0):
    45         Graphic_Element.__init__(self, parent)
    47         Graphic_Element.__init__(self, parent)
    46         self.Type = None
    48         self.Type = None
    47         self.Description = None
    49         self.Description = None
    48         self.Extension = None
    50         self.Extension = None
    49         self.ExecutionControl = False
    51         self.ExecutionControl = False
    54         self.Outputs = []
    56         self.Outputs = []
    55         self.Colour = wx.BLACK
    57         self.Colour = wx.BLACK
    56         self.Pen = MiterPen(wx.BLACK)
    58         self.Pen = MiterPen(wx.BLACK)
    57         self.SetType(type, extension, inputs, connectors, executionControl)
    59         self.SetType(type, extension, inputs, connectors, executionControl)
    58         self.Highlights = {}
    60         self.Highlights = {}
    59     
    61 
    60     # Make a clone of this FBD_Block
    62     # Make a clone of this FBD_Block
    61     def Clone(self, parent, id = None, name = "", pos = None):
    63     def Clone(self, parent, id=None, name="", pos=None):
    62         if self.Name != "" and name == "":
    64         if self.Name != "" and name == "":
    63             name = self.Name
    65             name = self.Name
    64         block = FBD_Block(parent, self.Type, name, id, self.Extension)
    66         block = FBD_Block(parent, self.Type, name, id, self.Extension)
    65         block.SetSize(self.Size[0], self.Size[1])
    67         block.SetSize(self.Size[0], self.Size[1])
    66         if pos is not None:
    68         if pos is not None:
    68         else:
    70         else:
    69             block.SetPosition(self.Pos.x, self.Pos.y)
    71             block.SetPosition(self.Pos.x, self.Pos.y)
    70         block.Inputs = [input.Clone(block) for input in self.Inputs]
    72         block.Inputs = [input.Clone(block) for input in self.Inputs]
    71         block.Outputs = [output.Clone(block) for output in self.Outputs]
    73         block.Outputs = [output.Clone(block) for output in self.Outputs]
    72         return block
    74         return block
    73     
    75 
    74     def GetConnectorTranslation(self, element):
    76     def GetConnectorTranslation(self, element):
    75         return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))
    77         return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs))
    76     
    78 
    77     def Flush(self):
    79     def Flush(self):
    78         for input in self.Inputs:
    80         for input in self.Inputs:
    79             input.Flush()
    81             input.Flush()
    80         self.Inputs = []
    82         self.Inputs = []
    81         for output in self.Outputs:
    83         for output in self.Outputs:
    82             output.Flush()
    84             output.Flush()
    83         self.Outputs = []
    85         self.Outputs = []
    84     
    86 
    85     # Returns the RedrawRect
    87     # Returns the RedrawRect
    86     def GetRedrawRect(self, movex = 0, movey = 0):
    88     def GetRedrawRect(self, movex=0, movey=0):
    87         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
    89         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
    88         if movex != 0 or movey != 0:
    90         if movex != 0 or movey != 0:
    89             for input in self.Inputs:
    91             for input in self.Inputs:
    90                 if input.IsConnected():
    92                 if input.IsConnected():
    91                     rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
    93                     rect = rect.Union(input.GetConnectedRedrawRect(movex, movey))
    92             for output in self.Outputs:
    94             for output in self.Outputs:
    93                 if output.IsConnected():
    95                 if output.IsConnected():
    94                     rect = rect.Union(output.GetConnectedRedrawRect(movex, movey))
    96                     rect = rect.Union(output.GetConnectedRedrawRect(movex, movey))
    95         return rect
    97         return rect
    96     
    98 
    97     # Delete this block by calling the appropriate method
    99     # Delete this block by calling the appropriate method
    98     def Delete(self):
   100     def Delete(self):
    99         self.Parent.DeleteBlock(self)
   101         self.Parent.DeleteBlock(self)
   100     
   102 
   101     # Unconnect all inputs and outputs
   103     # Unconnect all inputs and outputs
   102     def Clean(self):
   104     def Clean(self):
   103         for input in self.Inputs:
   105         for input in self.Inputs:
   104             input.UnConnect(delete = True)
   106             input.UnConnect(delete=True)
   105         for output in self.Outputs:
   107         for output in self.Outputs:
   106             output.UnConnect(delete = True)
   108             output.UnConnect(delete=True)
   107     
   109 
   108     # Refresh the size of text for name
   110     # Refresh the size of text for name
   109     def RefreshNameSize(self):
   111     def RefreshNameSize(self):
   110         self.NameSize = self.Parent.GetTextExtent(self.Name)
   112         self.NameSize = self.Parent.GetTextExtent(self.Name)
   111     
   113 
   112     # Refresh the size of text for execution order
   114     # Refresh the size of text for execution order
   113     def RefreshExecutionOrderSize(self):
   115     def RefreshExecutionOrderSize(self):
   114         self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
   116         self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
   115     
   117 
   116     # Returns if the point given is in the bounding box
   118     # Returns if the point given is in the bounding box
   117     def HitTest(self, pt, connectors=True):
   119     def HitTest(self, pt, connectors=True):
   118         if self.Name != "":
   120         if self.Name != "":
   119             test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y)
   121             test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y)
   120         else:
   122         else:
   121             test_text = False
   123             test_text = False
   122         test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y)
   124         test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y)
   123         return test_text or test_block
   125         return test_text or test_block
   124     
   126 
   125     # Returns the bounding box of the name outside the block
   127     # Returns the bounding box of the name outside the block
   126     def GetTextBoundingBox(self):
   128     def GetTextBoundingBox(self):
   127         # Calculate the size of the name outside the block
   129         # Calculate the size of the name outside the block
   128         text_width, text_height = self.NameSize
   130         text_width, text_height = self.NameSize
   129         return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2,
   131         return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2,
   130                        self.Pos.y - (text_height + 2),
   132                        self.Pos.y - (text_height + 2),
   131                        text_width,
   133                        text_width,
   132                        text_height)
   134                        text_height)
   133     
   135 
   134     # Returns the bounding box of function block without name outside
   136     # Returns the bounding box of function block without name outside
   135     def GetBlockBoundingBox(self, connectors=True):
   137     def GetBlockBoundingBox(self, connectors=True):
   136         bbx_x, bbx_y = self.Pos.x, self.Pos.y
   138         bbx_x, bbx_y = self.Pos.x, self.Pos.y
   137         bbx_width, bbx_height = self.Size
   139         bbx_width, bbx_height = self.Size
   138         if connectors:
   140         if connectors:
   141         if self.ExecutionOrder != 0:
   143         if self.ExecutionOrder != 0:
   142             bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
   144             bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
   143             bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
   145             bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
   144             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   146             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   145         return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
   147         return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1)
   146     
   148 
   147     # Refresh the block bounding box
   149     # Refresh the block bounding box
   148     def RefreshBoundingBox(self):
   150     def RefreshBoundingBox(self):
   149         self.BoundingBox = self.GetBlockBoundingBox()
   151         self.BoundingBox = self.GetBlockBoundingBox()
   150         if self.Name != "":
   152         if self.Name != "":
   151             self.BoundingBox.Union(self.GetTextBoundingBox())
   153             self.BoundingBox.Union(self.GetTextBoundingBox())
   152     
   154 
   153     # Refresh the positions of the block connectors
   155     # Refresh the positions of the block connectors
   154     def RefreshConnectors(self):
   156     def RefreshConnectors(self):
   155         scaling = self.Parent.GetScaling()
   157         scaling = self.Parent.GetScaling()
   156         # Calculate the size for the connector lines
   158         # Calculate the size for the connector lines
   157         lines = max(len(self.Inputs), len(self.Outputs))
   159         lines = max(len(self.Inputs), len(self.Outputs))
   168                     self.Inputs[i].SetPosition(wx.Point(0, ypos))
   170                     self.Inputs[i].SetPosition(wx.Point(0, ypos))
   169                 if i < len(self.Outputs):
   171                 if i < len(self.Outputs):
   170                     self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
   172                     self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos))
   171                 position += linesize
   173                 position += linesize
   172         self.RefreshConnected()
   174         self.RefreshConnected()
   173     
   175 
   174     # Refresh the positions of wires connected to inputs and outputs
   176     # Refresh the positions of wires connected to inputs and outputs
   175     def RefreshConnected(self, exclude = []):
   177     def RefreshConnected(self, exclude=[]):
   176         for input in self.Inputs:
   178         for input in self.Inputs:
   177             input.MoveConnected(exclude)
   179             input.MoveConnected(exclude)
   178         for output in self.Outputs:
   180         for output in self.Outputs:
   179             output.MoveConnected(exclude)
   181             output.MoveConnected(exclude)
   180     
   182 
   181     # Returns the block connector that starts with the point given if it exists 
   183     # Returns the block connector that starts with the point given if it exists
   182     def GetConnector(self, position, output_name = None, input_name = None):
   184     def GetConnector(self, position, output_name=None, input_name=None):
   183         if input_name is not None:
   185         if input_name is not None:
   184             # Test each input connector
   186             # Test each input connector
   185             for input in self.Inputs:
   187             for input in self.Inputs:
   186                 if input_name == input.GetName():
   188                 if input_name == input.GetName():
   187                     return input
   189                     return input
   191                 if output_name == output.GetName():
   193                 if output_name == output.GetName():
   192                     return output
   194                     return output
   193         if input_name is None and output_name is None:
   195         if input_name is None and output_name is None:
   194             return self.FindNearestConnector(position, self.Inputs + self.Outputs)
   196             return self.FindNearestConnector(position, self.Inputs + self.Outputs)
   195         return None
   197         return None
   196         
   198 
   197     def GetInputTypes(self):
   199     def GetInputTypes(self):
   198         return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"])
   200         return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"])
   199     
   201 
   200     def SetOutputValues(self, values):
   202     def SetOutputValues(self, values):
   201         for output in self.Outputs:
   203         for output in self.Outputs:
   202             output.SetValue(values.get(ouput.getName(), None))
   204             output.SetValue(values.get(ouput.getName(), None))
   203     
   205 
   204     def GetConnectionResultType(self, connector, connectortype):
   206     def GetConnectionResultType(self, connector, connectortype):
   205         if not TestConnectorName(connector.GetName(), self.Type):
   207         if not TestConnectorName(connector.GetName(), self.Type):
   206             return connectortype
   208             return connectortype
   207         resulttype = connectortype
   209         resulttype = connectortype
   208         for input in self.Inputs:
   210         for input in self.Inputs:
   214             if output != connector and output.GetType(True) == "ANY" and TestConnectorName(output.GetName(), self.Type):
   216             if output != connector and output.GetType(True) == "ANY" and TestConnectorName(output.GetName(), self.Type):
   215                 outputtype = output.GetConnectedType()
   217                 outputtype = output.GetConnectedType()
   216                 if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype):
   218                 if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype):
   217                     resulttype = outputtype
   219                     resulttype = outputtype
   218         return resulttype
   220         return resulttype
   219         
   221 
   220     # Returns all the block connectors
   222     # Returns all the block connectors
   221     def GetConnectors(self):
   223     def GetConnectors(self):
   222         return {"inputs" : self.Inputs, "outputs" : self.Outputs}
   224         return {"inputs": self.Inputs, "outputs": self.Outputs}
   223     
   225 
   224     # Test if point given is on one of the block connectors
   226     # Test if point given is on one of the block connectors
   225     def TestConnector(self, pt, direction = None, exclude = True):
   227     def TestConnector(self, pt, direction=None, exclude=True):
   226         # Test each input connector
   228         # Test each input connector
   227         for input in self.Inputs:
   229         for input in self.Inputs:
   228             if input.TestPoint(pt, direction, exclude):
   230             if input.TestPoint(pt, direction, exclude):
   229                 return input
   231                 return input
   230         # Test each output connector
   232         # Test each output connector
   231         for output in self.Outputs:
   233         for output in self.Outputs:
   232             if output.TestPoint(pt, direction, exclude):
   234             if output.TestPoint(pt, direction, exclude):
   233                 return output
   235                 return output
   234         return None
   236         return None
   235     
   237 
   236     # Changes the block type
   238     # Changes the block type
   237     def SetType(self, type, extension, inputs = None, connectors = {}, executionControl = False):
   239     def SetType(self, type, extension, inputs=None, connectors={}, executionControl=False):
   238         if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: 
   240         if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl:
   239             if type != self.Type:
   241             if type != self.Type:
   240                 self.Type = type
   242                 self.Type = type
   241                 self.TypeSize = self.Parent.GetTextExtent(self.Type)
   243                 self.TypeSize = self.Parent.GetTextExtent(self.Type)
   242             self.Extension = extension
   244             self.Extension = extension
   243             self.ExecutionControl = executionControl
   245             self.ExecutionControl = executionControl
   250                 outputs = [output for output in blocktype["outputs"]]
   252                 outputs = [output for output in blocktype["outputs"]]
   251                 if blocktype["extensible"]:
   253                 if blocktype["extensible"]:
   252                     start = int(inputs[-1][0].replace("IN", ""))
   254                     start = int(inputs[-1][0].replace("IN", ""))
   253                     for i in xrange(self.Extension - len(blocktype["inputs"])):
   255                     for i in xrange(self.Extension - len(blocktype["inputs"])):
   254                         start += 1
   256                         start += 1
   255                         inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2]))
   257                         inputs.append(("IN%d" % start, inputs[-1][1], inputs[-1][2]))
   256                 comment = blocktype["comment"]
   258                 comment = blocktype["comment"]
   257                 self.Description = _(comment) + blocktype.get("usage", "")
   259                 self.Description = _(comment) + blocktype.get("usage", "")
   258             else:
   260             else:
   259                 self.Colour = wx.RED
   261                 self.Colour = wx.RED
   260                 inputs = connectors.get("inputs", [])
   262                 inputs = connectors.get("inputs", [])
   261                 outputs = connectors.get("outputs", [])
   263                 outputs = connectors.get("outputs", [])
   262                 self.Description = None
   264                 self.Description = None
   263             if self.ExecutionControl:
   265             if self.ExecutionControl:
   264                 inputs.insert(0, ("EN","BOOL","none"))
   266                 inputs.insert(0,  ("EN",   "BOOL", "none"))
   265                 outputs.insert(0, ("ENO","BOOL","none"))
   267                 outputs.insert(0, ("ENO",  "BOOL", "none"))
   266             self.Pen = MiterPen(self.Colour)
   268             self.Pen = MiterPen(self.Colour)
   267             
   269 
   268             # Extract the inputs properties and create or modify the corresponding connector
   270             # Extract the inputs properties and create or modify the corresponding connector
   269             input_connectors = []
   271             input_connectors = []
   270             for input_name, input_type, input_modifier in inputs:
   272             for input_name, input_type, input_modifier in inputs:
   271                 connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True)
   273                 connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone=True)
   272                 if input_modifier == "negated":
   274                 if input_modifier == "negated":
   273                     connector.SetNegated(True)
   275                     connector.SetNegated(True)
   274                 elif input_modifier != "none":
   276                 elif input_modifier != "none":
   275                     connector.SetEdge(input_modifier)
   277                     connector.SetEdge(input_modifier)
   276                 for input in self.Inputs:
   278                 for input in self.Inputs:
   280                         for wire in wires:
   282                         for wire in wires:
   281                             connector.Connect(wire)
   283                             connector.Connect(wire)
   282                         break
   284                         break
   283                 input_connectors.append(connector)
   285                 input_connectors.append(connector)
   284             for input in self.Inputs:
   286             for input in self.Inputs:
   285                 input.UnConnect(delete = True)
   287                 input.UnConnect(delete=True)
   286             self.Inputs = input_connectors
   288             self.Inputs = input_connectors
   287             
   289 
   288             # Extract the outputs properties and create or modify the corresponding connector
   290             # Extract the outputs properties and create or modify the corresponding connector
   289             output_connectors = []
   291             output_connectors = []
   290             for output_name, output_type, output_modifier in outputs:
   292             for output_name, output_type, output_modifier in outputs:
   291                 connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST)
   293                 connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST)
   292                 if output_modifier == "negated":
   294                 if output_modifier == "negated":
   300                         for wire in wires:
   302                         for wire in wires:
   301                             connector.Connect(wire)
   303                             connector.Connect(wire)
   302                         break
   304                         break
   303                 output_connectors.append(connector)
   305                 output_connectors.append(connector)
   304             for output in self.Outputs:
   306             for output in self.Outputs:
   305                 output.UnConnect(delete = True)
   307                 output.UnConnect(delete=True)
   306             self.Outputs = output_connectors
   308             self.Outputs = output_connectors
   307                 
   309 
   308             self.RefreshMinSize()
   310             self.RefreshMinSize()
   309             self.RefreshConnectors()
   311             self.RefreshConnectors()
   310             for output in self.Outputs:
   312             for output in self.Outputs:
   311                 output.RefreshWires()
   313                 output.RefreshWires()
   312             self.RefreshBoundingBox()
   314             self.RefreshBoundingBox()
   313     
   315 
   314     # Returns the block type
   316     # Returns the block type
   315     def GetType(self):
   317     def GetType(self):
   316         return self.Type
   318         return self.Type
   317     
   319 
   318     # Changes the block name
   320     # Changes the block name
   319     def SetName(self, name):
   321     def SetName(self, name):
   320         self.Name = name
   322         self.Name = name
   321         self.RefreshNameSize()
   323         self.RefreshNameSize()
   322     
   324 
   323     # Returs the block name
   325     # Returs the block name
   324     def GetName(self):
   326     def GetName(self):
   325         return self.Name
   327         return self.Name
   326     
   328 
   327     # Changes the extension name
   329     # Changes the extension name
   328     def SetExtension(self, extension):
   330     def SetExtension(self, extension):
   329         self.Extension = extension
   331         self.Extension = extension
   330     
   332 
   331     # Returs the extension name
   333     # Returs the extension name
   332     def GetExtension(self):
   334     def GetExtension(self):
   333         return self.Extension
   335         return self.Extension
   334     
   336 
   335     # Changes the execution order
   337     # Changes the execution order
   336     def SetExecutionOrder(self, executionOrder):
   338     def SetExecutionOrder(self, executionOrder):
   337         self.ExecutionOrder = executionOrder
   339         self.ExecutionOrder = executionOrder
   338         self.RefreshExecutionOrderSize()
   340         self.RefreshExecutionOrderSize()
   339     
   341 
   340     # Returs the execution order
   342     # Returs the execution order
   341     def GetExecutionOrder(self):
   343     def GetExecutionOrder(self):
   342         return self.ExecutionOrder
   344         return self.ExecutionOrder
   343     
   345 
   344     # Returs the execution order
   346     # Returs the execution order
   345     def GetExecutionControl(self):
   347     def GetExecutionControl(self):
   346         return self.ExecutionControl
   348         return self.ExecutionControl
   347     
   349 
   348     # Refresh the block minimum size
   350     # Refresh the block minimum size
   349     def RefreshMinSize(self):
   351     def RefreshMinSize(self):
   350         # Calculate the inputs maximum width
   352         # Calculate the inputs maximum width
   351         max_input = 0
   353         max_input = 0
   352         for input in self.Inputs:
   354         for input in self.Inputs:
   358             w, h = output.GetNameSize()
   360             w, h = output.GetNameSize()
   359             max_output = max(max_output, w)
   361             max_output = max(max_output, w)
   360         width = max(self.TypeSize[0] + 10, max_input + max_output + 15)
   362         width = max(self.TypeSize[0] + 10, max_input + max_output + 15)
   361         height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE
   363         height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE
   362         self.MinSize = width, height
   364         self.MinSize = width, height
   363     
   365 
   364     # Returns the block minimum size
   366     # Returns the block minimum size
   365     def GetMinSize(self):
   367     def GetMinSize(self):
   366         return self.MinSize
   368         return self.MinSize
   367     
   369 
   368     # Changes the negated property of the connector handled
   370     # Changes the negated property of the connector handled
   369     def SetConnectorNegated(self, negated):
   371     def SetConnectorNegated(self, negated):
   370         handle_type, handle = self.Handle
   372         handle_type, handle = self.Handle
   371         if handle_type == HANDLE_CONNECTOR:
   373         if handle_type == HANDLE_CONNECTOR:
   372             handle.SetNegated(negated)
   374             handle.SetNegated(negated)
   373             self.RefreshModel(False)
   375             self.RefreshModel(False)
   374     
   376 
   375     # Changes the edge property of the connector handled
   377     # Changes the edge property of the connector handled
   376     def SetConnectorEdge(self, edge):
   378     def SetConnectorEdge(self, edge):
   377         handle_type, handle = self.Handle
   379         handle_type, handle = self.Handle
   378         if handle_type == HANDLE_CONNECTOR:
   380         if handle_type == HANDLE_CONNECTOR:
   379             handle.SetEdge(edge)
   381             handle.SetEdge(edge)
   380             self.RefreshModel(False)
   382             self.RefreshModel(False)
   381     
   383 
   382 ##    # Method called when a Motion event have been generated
   384 #    # Method called when a Motion event have been generated
   383 ##    def OnMotion(self, event, dc, scaling):
   385 #    def OnMotion(self, event, dc, scaling):
   384 ##        if not event.Dragging():
   386 #        if not event.Dragging():
   385 ##            pos = event.GetLogicalPosition(dc)
   387 #            pos = event.GetLogicalPosition(dc)
   386 ##            for input in self.Inputs:
   388 #            for input in self.Inputs:
   387 ##                rect = input.GetRedrawRect()
   389 #                rect = input.GetRedrawRect()
   388 ##                if rect.InsideXY(pos.x, pos.y):
   390 #                if rect.InsideXY(pos.x, pos.y):
   389 ##                    print "Find input"
   391 #                    print "Find input"
   390 ##                    tip = wx.TipWindow(self.Parent, "Test")
   392 #                    tip = wx.TipWindow(self.Parent, "Test")
   391 ##                    tip.SetBoundingRect(rect)
   393 #                    tip.SetBoundingRect(rect)
   392 ##        return Graphic_Element.OnMotion(self, event, dc, scaling)
   394 #        return Graphic_Element.OnMotion(self, event, dc, scaling)
   393     
   395 
   394     # Method called when a LeftDClick event have been generated
   396     # Method called when a LeftDClick event have been generated
   395     def OnLeftDClick(self, event, dc, scaling):
   397     def OnLeftDClick(self, event, dc, scaling):
   396         # Edit the block properties
   398         # Edit the block properties
   397         self.Parent.EditBlockContent(self)
   399         self.Parent.EditBlockContent(self)
   398     
   400 
   399     # Method called when a RightUp event have been generated
   401     # Method called when a RightUp event have been generated
   400     def OnRightUp(self, event, dc, scaling):
   402     def OnRightUp(self, event, dc, scaling):
   401         pos = GetScaledEventPosition(event, dc, scaling)
   403         pos = GetScaledEventPosition(event, dc, scaling)
   402         # Popup the menu with special items for a block and a connector if one is handled
   404         # Popup the menu with special items for a block and a connector if one is handled
   403         connector = self.TestConnector(pos, exclude=False)
   405         connector = self.TestConnector(pos, exclude=False)
   404         if connector:
   406         if connector:
   405             self.Handle = (HANDLE_CONNECTOR, connector)
   407             self.Handle = (HANDLE_CONNECTOR, connector)
   406             self.Parent.PopupBlockMenu(connector)
   408             self.Parent.PopupBlockMenu(connector)
   407         else:
   409         else:
   408             self.Parent.PopupBlockMenu()
   410             self.Parent.PopupBlockMenu()
   409     
   411 
   410     # Refreshes the block model
   412     # Refreshes the block model
   411     def RefreshModel(self, move=True):
   413     def RefreshModel(self, move=True):
   412         self.Parent.RefreshBlockModel(self)
   414         self.Parent.RefreshBlockModel(self)
   413         # If block has moved, refresh the model of wires connected to outputs
   415         # If block has moved, refresh the model of wires connected to outputs
   414         if move:
   416         if move:
   415             for output in self.Outputs:
   417             for output in self.Outputs:
   416                 output.RefreshWires()
   418                 output.RefreshWires()
   417     
   419 
   418     def GetToolTipValue(self):
   420     def GetToolTipValue(self):
   419         return self.Description
   421         return self.Description
   420     
   422 
   421     # Adds an highlight to the block
   423     # Adds an highlight to the block
   422     def AddHighlight(self, infos, start, end ,highlight_type):
   424     def AddHighlight(self, infos, start, end, highlight_type):
   423         if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0:
   425         if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0:
   424             highlights = self.Highlights.setdefault(infos[0], [])
   426             highlights = self.Highlights.setdefault(infos[0], [])
   425             AddHighlight(highlights, (start, end, highlight_type))
   427             AddHighlight(highlights, (start, end, highlight_type))
   426         elif infos[0] == "input" and infos[1] < len(self.Inputs):
   428         elif infos[0] == "input" and infos[1] < len(self.Inputs):
   427             self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
   429             self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
   428         elif infos[0] == "output" and infos[1] < len(self.Outputs):
   430         elif infos[0] == "output" and infos[1] < len(self.Outputs):
   429             self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
   431             self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type)
   430     
   432 
   431     # Removes an highlight from the block
   433     # Removes an highlight from the block
   432     def RemoveHighlight(self, infos, start, end, highlight_type):
   434     def RemoveHighlight(self, infos, start, end, highlight_type):
   433         if infos[0] in ["type", "name"]:
   435         if infos[0] in ["type", "name"]:
   434             highlights = self.Highlights.get(infos[0], [])
   436             highlights = self.Highlights.get(infos[0], [])
   435             if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
   437             if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0:
   436                 self.Highlights.pop(infos[0])
   438                 self.Highlights.pop(infos[0])
   437         elif infos[0] == "input" and infos[1] < len(self.Inputs):
   439         elif infos[0] == "input" and infos[1] < len(self.Inputs):
   438             self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
   440             self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
   439         elif infos[0] == "output" and infos[1] < len(self.Outputs):
   441         elif infos[0] == "output" and infos[1] < len(self.Outputs):
   440             self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
   442             self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type)
   441             
   443 
   442     # Removes all the highlights of one particular type from the block
   444     # Removes all the highlights of one particular type from the block
   443     def ClearHighlight(self, highlight_type=None):
   445     def ClearHighlight(self, highlight_type=None):
   444         if highlight_type is None:
   446         if highlight_type is None:
   445             self.Highlights = {}
   447             self.Highlights = {}
   446         else:
   448         else:
   451                     self.Highlights.pop(name)
   453                     self.Highlights.pop(name)
   452         for input in self.Inputs:
   454         for input in self.Inputs:
   453             input.ClearHighlights(highlight_type)
   455             input.ClearHighlights(highlight_type)
   454         for output in self.Outputs:
   456         for output in self.Outputs:
   455             output.ClearHighlights(highlight_type)
   457             output.ClearHighlights(highlight_type)
   456     
   458 
   457     # Draws block
   459     # Draws block
   458     def Draw(self, dc):
   460     def Draw(self, dc):
   459         Graphic_Element.Draw(self, dc)
   461         Graphic_Element.Draw(self, dc)
   460         dc.SetPen(self.Pen)
   462         dc.SetPen(self.Pen)
   461         dc.SetBrush(wx.WHITE_BRUSH)
   463         dc.SetBrush(wx.WHITE_BRUSH)
   462         dc.SetTextForeground(self.Colour)
   464         dc.SetTextForeground(self.Colour)
   463         
   465 
   464         if getattr(dc, "printing", False):
   466         if getattr(dc, "printing", False):
   465             name_size = dc.GetTextExtent(self.Name)
   467             name_size = dc.GetTextExtent(self.Name)
   466             type_size = dc.GetTextExtent(self.Type)
   468             type_size = dc.GetTextExtent(self.Type)
   467             executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
   469             executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
   468         else:
   470         else:
   469             name_size = self.NameSize
   471             name_size = self.NameSize
   470             type_size = self.TypeSize
   472             type_size = self.TypeSize
   471             executionorder_size = self.ExecutionOrderSize
   473             executionorder_size = self.ExecutionOrderSize
   472             
   474 
   473         # Draw a rectangle with the block size
   475         # Draw a rectangle with the block size
   474         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   476         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   475         # Draw block name and block type
   477         # Draw block name and block type
   476         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   478         name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   477                     self.Pos.y - (name_size[1] + 2))
   479                     self.Pos.y - (name_size[1] + 2))
   485         for output in self.Outputs:
   487         for output in self.Outputs:
   486             output.Draw(dc)
   488             output.Draw(dc)
   487         if self.ExecutionOrder != 0:
   489         if self.ExecutionOrder != 0:
   488             # Draw block execution order
   490             # Draw block execution order
   489             dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
   491             dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
   490                     self.Pos.y + self.Size[1] + 2)
   492                         self.Pos.y + self.Size[1] + 2)
   491         
   493 
   492         if not getattr(dc, "printing", False):
   494         if not getattr(dc, "printing", False):
   493             DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1])
   495             DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1])
   494             DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1])
   496             DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1])
   495         
   497 
   496 
   498 
   497 #-------------------------------------------------------------------------------
   499 # -------------------------------------------------------------------------------
   498 #                        Function Block Diagram Variable
   500 #                        Function Block Diagram Variable
   499 #-------------------------------------------------------------------------------
   501 # -------------------------------------------------------------------------------
   500 
   502 
   501 """
       
   502 Class that implements the graphic representation of a variable
       
   503 """
       
   504 
   503 
   505 class FBD_Variable(Graphic_Element):
   504 class FBD_Variable(Graphic_Element):
       
   505     """
       
   506     Class that implements the graphic representation of a variable
       
   507     """
   506 
   508 
   507     # Create a new variable
   509     # Create a new variable
   508     def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0):
   510     def __init__(self, parent, type, name, value_type, id=None, executionOrder=0):
   509         Graphic_Element.__init__(self, parent)
   511         Graphic_Element.__init__(self, parent)
   510         self.Type = None
   512         self.Type = None
   511         self.ValueType = None
   513         self.ValueType = None
   512         self.Id = id
   514         self.Id = id
   513         self.SetName(name)
   515         self.SetName(name)
   514         self.SetExecutionOrder(executionOrder)
   516         self.SetExecutionOrder(executionOrder)
   515         self.Input = None
   517         self.Input = None
   516         self.Output = None
   518         self.Output = None
   517         self.SetType(type, value_type)
   519         self.SetType(type, value_type)
   518         self.Highlights = []
   520         self.Highlights = []
   519     
   521 
   520     # Make a clone of this FBD_Variable
   522     # Make a clone of this FBD_Variable
   521     def Clone(self, parent, id = None, pos = None):
   523     def Clone(self, parent, id=None, pos=None):
   522         variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id)
   524         variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id)
   523         variable.SetSize(self.Size[0], self.Size[1])
   525         variable.SetSize(self.Size[0], self.Size[1])
   524         if pos is not None:
   526         if pos is not None:
   525             variable.SetPosition(pos.x, pos.y)
   527             variable.SetPosition(pos.x, pos.y)
   526         else:
   528         else:
   528         if self.Input:
   530         if self.Input:
   529             variable.Input = self.Input.Clone(variable)
   531             variable.Input = self.Input.Clone(variable)
   530         if self.Output:
   532         if self.Output:
   531             variable.Output = self.Output.Clone(variable)
   533             variable.Output = self.Output.Clone(variable)
   532         return variable
   534         return variable
   533     
   535 
   534     def GetConnectorTranslation(self, element):
   536     def GetConnectorTranslation(self, element):
   535         connectors = {}
   537         connectors = {}
   536         if self.Input is not None:
   538         if self.Input is not None:
   537             connectors[self.Input] = element.Input
   539             connectors[self.Input] = element.Input
   538         if self.Output is not None:
   540         if self.Output is not None:
   539             connectors[self.Output] = element.Output
   541             connectors[self.Output] = element.Output
   540         return connectors
   542         return connectors
   541     
   543 
   542     def Flush(self):
   544     def Flush(self):
   543         if self.Input is not None:
   545         if self.Input is not None:
   544             self.Input.Flush()
   546             self.Input.Flush()
   545             self.Input = None
   547             self.Input = None
   546         if self.Output is not None:
   548         if self.Output is not None:
   547             self.Output.Flush()
   549             self.Output.Flush()
   548             self.Output = None
   550             self.Output = None
   549     
   551 
   550     # Returns the RedrawRect
   552     # Returns the RedrawRect
   551     def GetRedrawRect(self, movex = 0, movey = 0):
   553     def GetRedrawRect(self, movex=0, movey=0):
   552         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   554         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   553         if movex != 0 or movey != 0:
   555         if movex != 0 or movey != 0:
   554             if self.Input and self.Input.IsConnected():
   556             if self.Input and self.Input.IsConnected():
   555                 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
   557                 rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey))
   556             if self.Output and self.Output.IsConnected():
   558             if self.Output and self.Output.IsConnected():
   557                 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
   559                 rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey))
   558         return rect
   560         return rect
   559     
   561 
   560     # Unconnect connector
   562     # Unconnect connector
   561     def Clean(self):
   563     def Clean(self):
   562         if self.Input:
   564         if self.Input:
   563             self.Input.UnConnect(delete = True)
   565             self.Input.UnConnect(delete=True)
   564         if self.Output:
   566         if self.Output:
   565             self.Output.UnConnect(delete = True)
   567             self.Output.UnConnect(delete=True)
   566     
   568 
   567     # Delete this variable by calling the appropriate method
   569     # Delete this variable by calling the appropriate method
   568     def Delete(self):
   570     def Delete(self):
   569         self.Parent.DeleteVariable(self)
   571         self.Parent.DeleteVariable(self)
   570     
   572 
   571     # Refresh the size of text for name
   573     # Refresh the size of text for name
   572     def RefreshNameSize(self):
   574     def RefreshNameSize(self):
   573         self.NameSize = self.Parent.GetTextExtent(self.Name)
   575         self.NameSize = self.Parent.GetTextExtent(self.Name)
   574     
   576 
   575     # Refresh the size of text for execution order
   577     # Refresh the size of text for execution order
   576     def RefreshExecutionOrderSize(self):
   578     def RefreshExecutionOrderSize(self):
   577         self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
   579         self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder))
   578     
   580 
   579     # Refresh the variable bounding box
   581     # Refresh the variable bounding box
   580     def RefreshBoundingBox(self):
   582     def RefreshBoundingBox(self):
   581         if self.Type in (OUTPUT, INOUT):
   583         if self.Type in (OUTPUT, INOUT):
   582             bbx_x = self.Pos.x - CONNECTOR_SIZE
   584             bbx_x = self.Pos.x - CONNECTOR_SIZE
   583         else:
   585         else:
   592         if self.ExecutionOrder != 0:
   594         if self.ExecutionOrder != 0:
   593             bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
   595             bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0])
   594             bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
   596             bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0])
   595             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   597             bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2)
   596         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
   598         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1)
   597     
   599 
   598     # Refresh the position of the variable connector
   600     # Refresh the position of the variable connector
   599     def RefreshConnectors(self):
   601     def RefreshConnectors(self):
   600         scaling = self.Parent.GetScaling()
   602         scaling = self.Parent.GetScaling()
   601         if scaling is not None:
   603         if scaling is not None:
   602             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   604             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   605         if self.Input:
   607         if self.Input:
   606             self.Input.SetPosition(wx.Point(0, position))
   608             self.Input.SetPosition(wx.Point(0, position))
   607         if self.Output:
   609         if self.Output:
   608             self.Output.SetPosition(wx.Point(self.Size[0], position))
   610             self.Output.SetPosition(wx.Point(self.Size[0], position))
   609         self.RefreshConnected()
   611         self.RefreshConnected()
   610     
   612 
   611     # Refresh the position of wires connected to connector
   613     # Refresh the position of wires connected to connector
   612     def RefreshConnected(self, exclude = []):
   614     def RefreshConnected(self, exclude=[]):
   613         if self.Input:
   615         if self.Input:
   614             self.Input.MoveConnected(exclude)
   616             self.Input.MoveConnected(exclude)
   615         if self.Output:
   617         if self.Output:
   616             self.Output.MoveConnected(exclude)
   618             self.Output.MoveConnected(exclude)
   617         
   619 
   618     # Test if point given is on the variable connector
   620     # Test if point given is on the variable connector
   619     def TestConnector(self, pt, direction = None, exclude=True):
   621     def TestConnector(self, pt, direction=None, exclude=True):
   620         if self.Input and self.Input.TestPoint(pt, direction, exclude):
   622         if self.Input and self.Input.TestPoint(pt, direction, exclude):
   621             return self.Input
   623             return self.Input
   622         if self.Output and self.Output.TestPoint(pt, direction, exclude):
   624         if self.Output and self.Output.TestPoint(pt, direction, exclude):
   623             return self.Output
   625             return self.Output
   624         return None
   626         return None
   625     
   627 
   626     # Returns the block connector that starts with the point given if it exists 
   628     # Returns the block connector that starts with the point given if it exists
   627     def GetConnector(self, position, name = None):
   629     def GetConnector(self, position, name=None):
   628         # if a name is given
   630         # if a name is given
   629         if name is not None:
   631         if name is not None:
   630             # Test input and output connector if they exists
   632             # Test input and output connector if they exists
   631             #if self.Input and name == self.Input.GetName():
   633             # if self.Input and name == self.Input.GetName():
   632             #    return self.Input
   634             #    return self.Input
   633             if self.Output and name == self.Output.GetName():
   635             if self.Output and name == self.Output.GetName():
   634                 return self.Output
   636                 return self.Output
   635         connectors = []
   637         connectors = []
   636         # Test input connector if it exists
   638         # Test input connector if it exists
   638             connectors.append(self.Input)
   640             connectors.append(self.Input)
   639         # Test output connector if it exists
   641         # Test output connector if it exists
   640         if self.Output:
   642         if self.Output:
   641             connectors.append(self.Output)
   643             connectors.append(self.Output)
   642         return self.FindNearestConnector(position, connectors)
   644         return self.FindNearestConnector(position, connectors)
   643     
   645 
   644     # Returns all the block connectors 
   646     # Returns all the block connectors
   645     def GetConnectors(self):
   647     def GetConnectors(self):
   646         connectors = {"inputs": [], "outputs": []}
   648         connectors = {"inputs": [], "outputs": []}
   647         if self.Input:
   649         if self.Input:
   648             connectors["inputs"].append(self.Input)
   650             connectors["inputs"].append(self.Input)
   649         if self.Output:
   651         if self.Output:
   650             connectors["outputs"].append(self.Output)
   652             connectors["outputs"].append(self.Output)
   651         return connectors
   653         return connectors
   652     
   654 
   653     # Changes the negated property of the variable connector if handled
   655     # Changes the negated property of the variable connector if handled
   654     def SetConnectorNegated(self, negated):
   656     def SetConnectorNegated(self, negated):
   655         handle_type, handle = self.Handle
   657         handle_type, handle = self.Handle
   656         if handle_type == HANDLE_CONNECTOR:
   658         if handle_type == HANDLE_CONNECTOR:
   657             handle.SetNegated(negated)
   659             handle.SetNegated(negated)
   658             self.RefreshModel(False)
   660             self.RefreshModel(False)
   659     
   661 
   660     # Changes the variable type
   662     # Changes the variable type
   661     def SetType(self, type, value_type):
   663     def SetType(self, type, value_type):
   662         if type != self.Type:
   664         if type != self.Type:
   663             self.Type = type
   665             self.Type = type
   664             # Create an input or output connector according to variable type
   666             # Create an input or output connector according to variable type
   665             if self.Type != INPUT:
   667             if self.Type != INPUT:
   666                 if self.Input is None:
   668                 if self.Input is None:
   667                     self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True)
   669                     self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone=True)
   668             elif self.Input:
   670             elif self.Input:
   669                 self.Input.UnConnect(delete = True)
   671                 self.Input.UnConnect(delete=True)
   670                 self.Input = None
   672                 self.Input = None
   671             if self.Type != OUTPUT:
   673             if self.Type != OUTPUT:
   672                 if self.Output is None:
   674                 if self.Output is None:
   673                     self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST)
   675                     self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST)
   674             elif self.Output:
   676             elif self.Output:
   675                 self.Output.UnConnect(delete = True)
   677                 self.Output.UnConnect(delete=True)
   676                 self.Output = None
   678                 self.Output = None
   677             self.RefreshConnectors()
   679             self.RefreshConnectors()
   678             self.RefreshBoundingBox()
   680             self.RefreshBoundingBox()
   679         elif value_type != self.ValueType:
   681         elif value_type != self.ValueType:
   680             if self.Input:
   682             if self.Input:
   681                 self.Input.SetType(value_type)
   683                 self.Input.SetType(value_type)
   682             if self.Output:
   684             if self.Output:
   683                 self.Output.SetType(value_type)            
   685                 self.Output.SetType(value_type)
   684         
   686 
   685     # Returns the variable type
   687     # Returns the variable type
   686     def GetType(self):
   688     def GetType(self):
   687         return self.Type
   689         return self.Type
   688     
   690 
   689     # Returns the variable value type
   691     # Returns the variable value type
   690     def GetValueType(self):
   692     def GetValueType(self):
   691         return self.ValueType
   693         return self.ValueType
   692     
   694 
   693     # Changes the variable name
   695     # Changes the variable name
   694     def SetName(self, name):
   696     def SetName(self, name):
   695         self.Name = name
   697         self.Name = name
   696         self.RefreshNameSize()
   698         self.RefreshNameSize()
   697     
   699 
   698     # Returns the variable name
   700     # Returns the variable name
   699     def GetName(self):
   701     def GetName(self):
   700         return self.Name
   702         return self.Name
   701     
   703 
   702     # Changes the execution order
   704     # Changes the execution order
   703     def SetExecutionOrder(self, executionOrder):
   705     def SetExecutionOrder(self, executionOrder):
   704         self.ExecutionOrder = executionOrder
   706         self.ExecutionOrder = executionOrder
   705         self.RefreshExecutionOrderSize()
   707         self.RefreshExecutionOrderSize()
   706     
   708 
   707     # Returs the execution order
   709     # Returs the execution order
   708     def GetExecutionOrder(self):
   710     def GetExecutionOrder(self):
   709         return self.ExecutionOrder
   711         return self.ExecutionOrder
   710     
   712 
   711     # Returns the variable minimum size
   713     # Returns the variable minimum size
   712     def GetMinSize(self):
   714     def GetMinSize(self):
   713         return self.NameSize[0] + 10, self.NameSize[1] + 10
   715         return self.NameSize[0] + 10, self.NameSize[1] + 10
   714     
   716 
   715     # Set size of the variable to the minimum size
   717     # Set size of the variable to the minimum size
   716     def SetBestSize(self, scaling):
   718     def SetBestSize(self, scaling):
   717         if self.Type == INPUT:
   719         if self.Type == INPUT:
   718             return Graphic_Element.SetBestSize(self, scaling, x_factor=1.)
   720             return Graphic_Element.SetBestSize(self, scaling, x_factor=1.)
   719         elif self.Type == OUTPUT:
   721         elif self.Type == OUTPUT:
   720             return Graphic_Element.SetBestSize(self, scaling, x_factor=0.)
   722             return Graphic_Element.SetBestSize(self, scaling, x_factor=0.)
   721         else:
   723         else:
   722             return Graphic_Element.SetBestSize(self, scaling)
   724             return Graphic_Element.SetBestSize(self, scaling)
   723     
   725 
   724     # Method called when a LeftDClick event have been generated
   726     # Method called when a LeftDClick event have been generated
   725     def OnLeftDClick(self, event, dc, scaling):
   727     def OnLeftDClick(self, event, dc, scaling):
   726         if event.ControlDown():
   728         if event.ControlDown():
   727             # Change variable type 
   729             # Change variable type
   728             types = [INPUT, OUTPUT, INOUT]
   730             types = [INPUT, OUTPUT, INOUT]
   729             self.Parent.ChangeVariableType(self,
   731             self.Parent.ChangeVariableType(
   730                 types[(types.index(self.Type) + 1) % len(types)])
   732                 self, types[(types.index(self.Type) + 1) % len(types)])
   731         else:
   733         else:
   732             # Edit the variable properties
   734             # Edit the variable properties
   733             self.Parent.EditVariableContent(self)
   735             self.Parent.EditVariableContent(self)
   734     
   736 
   735     # Method called when a RightUp event have been generated
   737     # Method called when a RightUp event have been generated
   736     def OnRightUp(self, event, dc, scaling):
   738     def OnRightUp(self, event, dc, scaling):
   737         self.Parent.PopupVariableMenu()
   739         self.Parent.PopupVariableMenu()
   738     
   740 
   739     # Refreshes the variable model
   741     # Refreshes the variable model
   740     def RefreshModel(self, move=True):
   742     def RefreshModel(self, move=True):
   741         self.Parent.RefreshVariableModel(self)
   743         self.Parent.RefreshVariableModel(self)
   742         # If variable has moved and variable is not of type OUTPUT, refresh the model
   744         # If variable has moved and variable is not of type OUTPUT, refresh the model
   743         # of wires connected to output connector
   745         # of wires connected to output connector
   744         if move and self.Type != OUTPUT:
   746         if move and self.Type != OUTPUT:
   745             if self.Output:
   747             if self.Output:
   746                 self.Output.RefreshWires()
   748                 self.Output.RefreshWires()
   747     
   749 
   748     # Adds an highlight to the variable
   750     # Adds an highlight to the variable
   749     def AddHighlight(self, infos, start, end, highlight_type):
   751     def AddHighlight(self, infos, start, end, highlight_type):
   750         if infos[0] == "expression" and start[0] == 0 and end[0] == 0:
   752         if infos[0] == "expression" and start[0] == 0 and end[0] == 0:
   751             AddHighlight(self.Highlights, (start, end, highlight_type))
   753             AddHighlight(self.Highlights, (start, end, highlight_type))
   752     
   754 
   753     # Removes an highlight from the variable
   755     # Removes an highlight from the variable
   754     def RemoveHighlight(self, infos, start, end, highlight_type):
   756     def RemoveHighlight(self, infos, start, end, highlight_type):
   755         if infos[0] == "expression":
   757         if infos[0] == "expression":
   756             RemoveHighlight(self.Highlights, (start, end, highlight_type))
   758             RemoveHighlight(self.Highlights, (start, end, highlight_type))
   757     
   759 
   758     # Removes all the highlights of one particular type from the variable
   760     # Removes all the highlights of one particular type from the variable
   759     def ClearHighlight(self, highlight_type=None):
   761     def ClearHighlight(self, highlight_type=None):
   760         ClearHighlights(self.Highlights, highlight_type)
   762         ClearHighlights(self.Highlights, highlight_type)
   761     
   763 
   762     # Draws variable
   764     # Draws variable
   763     def Draw(self, dc):
   765     def Draw(self, dc):
   764         Graphic_Element.Draw(self, dc)
   766         Graphic_Element.Draw(self, dc)
   765         dc.SetPen(MiterPen(wx.BLACK))
   767         dc.SetPen(MiterPen(wx.BLACK))
   766         dc.SetBrush(wx.WHITE_BRUSH)
   768         dc.SetBrush(wx.WHITE_BRUSH)
   767         
   769 
   768         if getattr(dc, "printing", False):
   770         if getattr(dc, "printing", False):
   769             name_size = dc.GetTextExtent(self.Name)
   771             name_size = dc.GetTextExtent(self.Name)
   770             executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
   772             executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder))
   771         else:
   773         else:
   772             name_size = self.NameSize
   774             name_size = self.NameSize
   773             executionorder_size = self.ExecutionOrderSize
   775             executionorder_size = self.ExecutionOrderSize
   774         
   776 
   775         text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, 
   777         text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
   776                     self.Pos.y + (self.Size[1] - name_size[1]) / 2)
   778                     self.Pos.y + (self.Size[1] - name_size[1]) / 2)
   777         # Draw a rectangle with the variable size
   779         # Draw a rectangle with the variable size
   778         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   780         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
   779         # Draw variable name
   781         # Draw variable name
   780         dc.DrawText(self.Name, text_pos[0], text_pos[1])
   782         dc.DrawText(self.Name, text_pos[0], text_pos[1])
   781         # Draw connectors
   783         # Draw connectors
   782         if self.Input:
   784         if self.Input:
   783             self.Input.Draw(dc)
   785             self.Input.Draw(dc)
   784         if self.Output:    
   786         if self.Output:
   785             self.Output.Draw(dc)
   787             self.Output.Draw(dc)
   786         if self.ExecutionOrder != 0:
   788         if self.ExecutionOrder != 0:
   787             # Draw variable execution order
   789             # Draw variable execution order
   788             dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
   790             dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0],
   789                     self.Pos.y + self.Size[1] + 2)
   791                         self.Pos.y + self.Size[1] + 2)
   790         if not getattr(dc, "printing", False):
   792         if not getattr(dc, "printing", False):
   791             DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
   793             DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
   792             
   794 
   793 #-------------------------------------------------------------------------------
   795 
       
   796 # -------------------------------------------------------------------------------
   794 #                        Function Block Diagram Connector
   797 #                        Function Block Diagram Connector
   795 #-------------------------------------------------------------------------------
   798 # -------------------------------------------------------------------------------
   796 
   799 
   797 """
       
   798 Class that implements the graphic representation of a connection
       
   799 """
       
   800 
   800 
   801 class FBD_Connector(Graphic_Element):
   801 class FBD_Connector(Graphic_Element):
       
   802     """
       
   803     Class that implements the graphic representation of a connection
       
   804     """
   802 
   805 
   803     # Create a new connection
   806     # Create a new connection
   804     def __init__(self, parent, type, name, id = None):
   807     def __init__(self, parent, type, name, id=None):
   805         Graphic_Element.__init__(self, parent)
   808         Graphic_Element.__init__(self, parent)
   806         self.Type = type
   809         self.Type = type
   807         self.Id = id
   810         self.Id = id
   808         self.SetName(name)
   811         self.SetName(name)
   809         self.Pos = wx.Point(0, 0)
   812         self.Pos = wx.Point(0, 0)
   810         self.Size = wx.Size(0, 0)
   813         self.Size = wx.Size(0, 0)
   811         self.Highlights = []
   814         self.Highlights = []
   812         # Create an input or output connector according to connection type
   815         # Create an input or output connector according to connection type
   813         if self.Type == CONNECTOR:
   816         if self.Type == CONNECTOR:
   814             self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True)
   817             self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True)
   815         else:
   818         else:
   816             self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
   819             self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
   817         self.RefreshConnectors()
   820         self.RefreshConnectors()
   818         self.RefreshNameSize()
   821         self.RefreshNameSize()
   819     
   822 
   820     def Flush(self):
   823     def Flush(self):
   821         if self.Connector:
   824         if self.Connector:
   822             self.Connector.Flush()
   825             self.Connector.Flush()
   823             self.Connector = None
   826             self.Connector = None
   824     
   827 
   825     # Returns the RedrawRect
   828     # Returns the RedrawRect
   826     def GetRedrawRect(self, movex = 0, movey = 0):
   829     def GetRedrawRect(self, movex=0, movey=0):
   827         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   830         rect = Graphic_Element.GetRedrawRect(self, movex, movey)
   828         if movex != 0 or movey != 0:
   831         if movex != 0 or movey != 0:
   829             if self.Connector and self.Connector.IsConnected():
   832             if self.Connector and self.Connector.IsConnected():
   830                 rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey))
   833                 rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey))
   831         return rect
   834         return rect
   832     
   835 
   833     # Make a clone of this FBD_Connector
   836     # Make a clone of this FBD_Connector
   834     def Clone(self, parent, id = None, pos = None):
   837     def Clone(self, parent, id=None, pos=None):
   835         connection = FBD_Connector(parent, self.Type, self.Name, id)
   838         connection = FBD_Connector(parent, self.Type, self.Name, id)
   836         connection.SetSize(self.Size[0], self.Size[1])
   839         connection.SetSize(self.Size[0], self.Size[1])
   837         if pos is not None:
   840         if pos is not None:
   838             connection.SetPosition(pos.x, pos.y)
   841             connection.SetPosition(pos.x, pos.y)
   839         else:
   842         else:
   840             connection.SetPosition(self.Pos.x, self.Pos.y)
   843             connection.SetPosition(self.Pos.x, self.Pos.y)
   841         connection.Connector = self.Connector.Clone(connection)
   844         connection.Connector = self.Connector.Clone(connection)
   842         return connection
   845         return connection
   843     
   846 
   844     def GetConnectorTranslation(self, element):
   847     def GetConnectorTranslation(self, element):
   845         return {self.Connector : element.Connector}
   848         return {self.Connector: element.Connector}
   846 
   849 
   847     # Unconnect connector
   850     # Unconnect connector
   848     def Clean(self):
   851     def Clean(self):
   849         if self.Connector:
   852         if self.Connector:
   850             self.Connector.UnConnect(delete = True)
   853             self.Connector.UnConnect(delete=True)
   851     
   854 
   852     # Delete this connection by calling the appropriate method
   855     # Delete this connection by calling the appropriate method
   853     def Delete(self):
   856     def Delete(self):
   854         self.Parent.DeleteConnection(self)
   857         self.Parent.DeleteConnection(self)
   855     
   858 
   856     # Refresh the size of text for name
   859     # Refresh the size of text for name
   857     def RefreshNameSize(self):
   860     def RefreshNameSize(self):
   858         self.NameSize = self.Parent.GetTextExtent(self.Name)
   861         self.NameSize = self.Parent.GetTextExtent(self.Name)
   859     
   862 
   860     # Refresh the connection bounding box
   863     # Refresh the connection bounding box
   861     def RefreshBoundingBox(self):
   864     def RefreshBoundingBox(self):
   862         if self.Type == CONNECTOR:
   865         if self.Type == CONNECTOR:
   863             bbx_x = self.Pos.x - CONNECTOR_SIZE
   866             bbx_x = self.Pos.x - CONNECTOR_SIZE
   864         else:
   867         else:
   865             bbx_x = self.Pos.x
   868             bbx_x = self.Pos.x
   866         bbx_width = self.Size[0] + CONNECTOR_SIZE
   869         bbx_width = self.Size[0] + CONNECTOR_SIZE
   867         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
   870         self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1])
   868     
   871 
   869     # Refresh the position of the connection connector
   872     # Refresh the position of the connection connector
   870     def RefreshConnectors(self):
   873     def RefreshConnectors(self):
   871         scaling = self.Parent.GetScaling()
   874         scaling = self.Parent.GetScaling()
   872         if scaling is not None:
   875         if scaling is not None:
   873             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   876             position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y
   876         if self.Type == CONNECTOR:
   879         if self.Type == CONNECTOR:
   877             self.Connector.SetPosition(wx.Point(0, position))
   880             self.Connector.SetPosition(wx.Point(0, position))
   878         else:
   881         else:
   879             self.Connector.SetPosition(wx.Point(self.Size[0], position))
   882             self.Connector.SetPosition(wx.Point(self.Size[0], position))
   880         self.RefreshConnected()
   883         self.RefreshConnected()
   881     
   884 
   882     # Refresh the position of wires connected to connector
   885     # Refresh the position of wires connected to connector
   883     def RefreshConnected(self, exclude = []):
   886     def RefreshConnected(self, exclude=[]):
   884         if self.Connector:
   887         if self.Connector:
   885             self.Connector.MoveConnected(exclude)
   888             self.Connector.MoveConnected(exclude)
   886     
   889 
   887     # Test if point given is on the connection connector
   890     # Test if point given is on the connection connector
   888     def TestConnector(self, pt, direction = None, exclude=True):
   891     def TestConnector(self, pt, direction=None, exclude=True):
   889         if self.Connector and self.Connector.TestPoint(pt, direction, exclude):
   892         if self.Connector and self.Connector.TestPoint(pt, direction, exclude):
   890             return self.Connector
   893             return self.Connector
   891         return None
   894         return None
   892     
   895 
   893     # Returns the connection connector
   896     # Returns the connection connector
   894     def GetConnector(self, position = None, name = None):
   897     def GetConnector(self, position=None, name=None):
   895         return self.Connector
   898         return self.Connector
   896     
   899 
   897         # Returns all the block connectors 
   900         # Returns all the block connectors
   898     def GetConnectors(self):
   901     def GetConnectors(self):
   899         connectors = {"inputs": [], "outputs": []}
   902         connectors = {"inputs": [], "outputs": []}
   900         if self.Type == CONNECTOR:
   903         if self.Type == CONNECTOR:
   901             connectors["inputs"].append(self.Connector)
   904             connectors["inputs"].append(self.Connector)
   902         else:
   905         else:
   916         if type != self.Type:
   919         if type != self.Type:
   917             self.Type = type
   920             self.Type = type
   918             self.Clean()
   921             self.Clean()
   919             # Create an input or output connector according to connection type
   922             # Create an input or output connector according to connection type
   920             if self.Type == CONNECTOR:
   923             if self.Type == CONNECTOR:
   921                 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True)
   924                 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True)
   922             else:
   925             else:
   923                 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
   926                 self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST)
   924             self.RefreshConnectors()
   927             self.RefreshConnectors()
   925             self.RefreshBoundingBox()
   928             self.RefreshBoundingBox()
   926     
   929 
   927     # Returns the connection type
   930     # Returns the connection type
   928     def GetType(self):
   931     def GetType(self):
   929         return self.Type
   932         return self.Type
   930     
   933 
   931     def GetConnectionResultType(self, connector, connectortype):
   934     def GetConnectionResultType(self, connector, connectortype):
   932         if self.Type == CONTINUATION:
   935         if self.Type == CONTINUATION:
   933             connector = self.Parent.GetConnectorByName(self.Name)
   936             connector = self.Parent.GetConnectorByName(self.Name)
   934             if connector is not None:
   937             if connector is not None:
   935                 return connector.Connector.GetConnectedType()
   938                 return connector.Connector.GetConnectedType()
   936         return connectortype
   939         return connectortype
   937     
   940 
   938     # Changes the connection name
   941     # Changes the connection name
   939     def SetName(self, name):
   942     def SetName(self, name):
   940         self.Name = name
   943         self.Name = name
   941         self.RefreshNameSize()
   944         self.RefreshNameSize()
   942         
   945 
   943     # Returns the connection name
   946     # Returns the connection name
   944     def GetName(self):
   947     def GetName(self):
   945         return self.Name
   948         return self.Name
   946     
   949 
   947     # Set size of the variable to the minimum size
   950     # Set size of the variable to the minimum size
   948     def SetBestSize(self, scaling):
   951     def SetBestSize(self, scaling):
   949         if self.Type == CONTINUATION:
   952         if self.Type == CONTINUATION:
   950             return Graphic_Element.SetBestSize(self, scaling, x_factor=1.)
   953             return Graphic_Element.SetBestSize(self, scaling, x_factor=1.)
   951         else:
   954         else:
   952             return Graphic_Element.SetBestSize(self, scaling, x_factor=0.)
   955             return Graphic_Element.SetBestSize(self, scaling, x_factor=0.)
   953     
   956 
   954     # Returns the connection minimum size
   957     # Returns the connection minimum size
   955     def GetMinSize(self):
   958     def GetMinSize(self):
   956         text_width, text_height = self.NameSize
   959         text_width, text_height = self.NameSize
   957         if text_height % 2 == 1:
   960         if text_height % 2 == 1:
   958             text_height += 1
   961             text_height += 1
   959         return text_width + text_height + 20, text_height + 10
   962         return text_width + text_height + 20, text_height + 10
   960     
   963 
   961     # Method called when a LeftDClick event have been generated
   964     # Method called when a LeftDClick event have been generated
   962     def OnLeftDClick(self, event, dc, scaling):
   965     def OnLeftDClick(self, event, dc, scaling):
   963         if event.ControlDown():
   966         if event.ControlDown():
   964             # Change connection type 
   967             # Change connection type
   965             if self.Type == CONNECTOR:
   968             if self.Type == CONNECTOR:
   966                 self.Parent.ChangeConnectionType(self, CONTINUATION)
   969                 self.Parent.ChangeConnectionType(self, CONTINUATION)
   967             else:
   970             else:
   968                 self.Parent.ChangeConnectionType(self, CONNECTOR)
   971                 self.Parent.ChangeConnectionType(self, CONNECTOR)
   969         else:
   972         else:
   970             # Edit the connection properties
   973             # Edit the connection properties
   971             self.Parent.EditConnectionContent(self)
   974             self.Parent.EditConnectionContent(self)
   972     
   975 
   973     # Method called when a RightUp event have been generated
   976     # Method called when a RightUp event have been generated
   974     def OnRightUp(self, event, dc, scaling):
   977     def OnRightUp(self, event, dc, scaling):
   975         # Popup the default menu
   978         # Popup the default menu
   976         self.Parent.PopupConnectionMenu()
   979         self.Parent.PopupConnectionMenu()
   977     
   980 
   978     # Refreshes the connection model
   981     # Refreshes the connection model
   979     def RefreshModel(self, move=True):
   982     def RefreshModel(self, move=True):
   980         self.Parent.RefreshConnectionModel(self)
   983         self.Parent.RefreshConnectionModel(self)
   981         # If connection has moved and connection is of type CONTINUATION, refresh
   984         # If connection has moved and connection is of type CONTINUATION, refresh
   982         # the model of wires connected to connector
   985         # the model of wires connected to connector
   983         if move and self.Type == CONTINUATION:
   986         if move and self.Type == CONTINUATION:
   984             if self.Connector:
   987             if self.Connector:
   985                 self.Connector.RefreshWires()
   988                 self.Connector.RefreshWires()
   986     
   989 
   987     # Adds an highlight to the connection
   990     # Adds an highlight to the connection
   988     def AddHighlight(self, infos, start, end, highlight_type):
   991     def AddHighlight(self, infos, start, end, highlight_type):
   989         if infos[0] == "name" and start[0] == 0 and end[0] == 0:
   992         if infos[0] == "name" and start[0] == 0 and end[0] == 0:
   990             AddHighlight(self.Highlights, (start, end, highlight_type))
   993             AddHighlight(self.Highlights, (start, end, highlight_type))
   991     
   994 
   992     # Removes an highlight from the connection
   995     # Removes an highlight from the connection
   993     def RemoveHighlight(self, infos, start, end, highlight_type):
   996     def RemoveHighlight(self, infos, start, end, highlight_type):
   994         if infos[0] == "name":
   997         if infos[0] == "name":
   995             RemoveHighlight(self.Highlights, (start, end, highlight_type))
   998             RemoveHighlight(self.Highlights, (start, end, highlight_type))
   996     
   999 
   997     # Removes all the highlights of one particular type from the connection
  1000     # Removes all the highlights of one particular type from the connection
   998     def ClearHighlight(self, highlight_type=None):
  1001     def ClearHighlight(self, highlight_type=None):
   999         ClearHighlights(self.Highlights, highlight_type)
  1002         ClearHighlights(self.Highlights, highlight_type)
  1000     
  1003 
  1001     # Draws connection
  1004     # Draws connection
  1002     def Draw(self, dc):
  1005     def Draw(self, dc):
  1003         Graphic_Element.Draw(self, dc)
  1006         Graphic_Element.Draw(self, dc)
  1004         dc.SetPen(MiterPen(wx.BLACK))
  1007         dc.SetPen(MiterPen(wx.BLACK))
  1005         dc.SetBrush(wx.WHITE_BRUSH)
  1008         dc.SetBrush(wx.WHITE_BRUSH)
  1006         
  1009 
  1007         if getattr(dc, "printing", False):
  1010         if getattr(dc, "printing", False):
  1008             name_size = dc.GetTextExtent(self.Name)
  1011             name_size = dc.GetTextExtent(self.Name)
  1009         else:
  1012         else:
  1010             name_size = self.NameSize
  1013             name_size = self.NameSize
  1011         
  1014 
  1012         # Draw a rectangle with the connection size with arrows inside
  1015         # Draw a rectangle with the connection size with arrows inside
  1013         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1016         dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1)
  1014         arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2)
  1017         arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2)
  1015         dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, 
  1018         dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize,
  1016                 self.Pos.y + self.Size[1] / 2)
  1019                     self.Pos.y + self.Size[1] / 2)
  1017         dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, 
  1020         dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2,
  1018                 self.Pos.x, self.Pos.y + self.Size[1])
  1021                     self.Pos.x, self.Pos.y + self.Size[1])
  1019         dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, 
  1022         dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y,
  1020                 self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
  1023                     self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2)
  1021         dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, 
  1024         dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2,
  1022                 self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
  1025                     self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1])
  1023         # Draw connection name
  1026         # Draw connection name
  1024         text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, 
  1027         text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2,
  1025                     self.Pos.y + (self.Size[1] - name_size[1]) / 2)
  1028                     self.Pos.y + (self.Size[1] - name_size[1]) / 2)
  1026         dc.DrawText(self.Name, text_pos[0], text_pos[1])
  1029         dc.DrawText(self.Name, text_pos[0], text_pos[1])
  1027         # Draw connector
  1030         # Draw connector
  1028         if self.Connector:
  1031         if self.Connector:
  1029             self.Connector.Draw(dc)
  1032             self.Connector.Draw(dc)
  1030         
  1033 
  1031         if not getattr(dc, "printing", False):
  1034         if not getattr(dc, "printing", False):
  1032             DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
  1035             DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1])
  1033