diff -r 31e63e25b4cc -r 64beb9e9c749 graphics/FBD_Objects.py --- a/graphics/FBD_Objects.py Mon Aug 21 20:17:19 2017 +0000 +++ b/graphics/FBD_Objects.py Mon Aug 21 23:22:58 2017 +0300 @@ -27,21 +27,23 @@ from graphics.GraphicCommons import * from plcopen.structures import * -#------------------------------------------------------------------------------- + +# ------------------------------------------------------------------------------- # Function Block Diagram Block -#------------------------------------------------------------------------------- - -""" -Class that implements the graphic representation of a function block -""" +# ------------------------------------------------------------------------------- + def TestConnectorName(name, block_type): return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2") + class FBD_Block(Graphic_Element): - + """ + Class that implements the graphic representation of a function block + """ + # Create a new block - def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): + def __init__(self, parent, type, name, id=None, extension=0, inputs=None, connectors={}, executionControl=False, executionOrder=0): Graphic_Element.__init__(self, parent) self.Type = None self.Description = None @@ -56,9 +58,9 @@ self.Pen = MiterPen(wx.BLACK) self.SetType(type, extension, inputs, connectors, executionControl) self.Highlights = {} - + # Make a clone of this FBD_Block - def Clone(self, parent, id = None, name = "", pos = None): + def Clone(self, parent, id=None, name="", pos=None): if self.Name != "" and name == "": name = self.Name block = FBD_Block(parent, self.Type, name, id, self.Extension) @@ -70,10 +72,10 @@ block.Inputs = [input.Clone(block) for input in self.Inputs] block.Outputs = [output.Clone(block) for output in self.Outputs] return block - + def GetConnectorTranslation(self, element): return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs)) - + def Flush(self): for input in self.Inputs: input.Flush() @@ -81,9 +83,9 @@ for output in self.Outputs: output.Flush() self.Outputs = [] - + # Returns the RedrawRect - def GetRedrawRect(self, movex = 0, movey = 0): + def GetRedrawRect(self, movex=0, movey=0): rect = Graphic_Element.GetRedrawRect(self, movex, movey) if movex != 0 or movey != 0: for input in self.Inputs: @@ -93,26 +95,26 @@ if output.IsConnected(): rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) return rect - + # Delete this block by calling the appropriate method def Delete(self): self.Parent.DeleteBlock(self) - + # Unconnect all inputs and outputs def Clean(self): for input in self.Inputs: - input.UnConnect(delete = True) + input.UnConnect(delete=True) for output in self.Outputs: - output.UnConnect(delete = True) - + output.UnConnect(delete=True) + # Refresh the size of text for name def RefreshNameSize(self): self.NameSize = self.Parent.GetTextExtent(self.Name) - + # Refresh the size of text for execution order def RefreshExecutionOrderSize(self): self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) - + # Returns if the point given is in the bounding box def HitTest(self, pt, connectors=True): if self.Name != "": @@ -121,7 +123,7 @@ test_text = False test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y) return test_text or test_block - + # Returns the bounding box of the name outside the block def GetTextBoundingBox(self): # Calculate the size of the name outside the block @@ -130,7 +132,7 @@ self.Pos.y - (text_height + 2), text_width, text_height) - + # Returns the bounding box of function block without name outside def GetBlockBoundingBox(self, connectors=True): bbx_x, bbx_y = self.Pos.x, self.Pos.y @@ -143,13 +145,13 @@ bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) - + # Refresh the block bounding box def RefreshBoundingBox(self): self.BoundingBox = self.GetBlockBoundingBox() if self.Name != "": self.BoundingBox.Union(self.GetTextBoundingBox()) - + # Refresh the positions of the block connectors def RefreshConnectors(self): scaling = self.Parent.GetScaling() @@ -170,16 +172,16 @@ self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos)) position += linesize self.RefreshConnected() - + # Refresh the positions of wires connected to inputs and outputs - def RefreshConnected(self, exclude = []): + def RefreshConnected(self, exclude=[]): for input in self.Inputs: input.MoveConnected(exclude) for output in self.Outputs: output.MoveConnected(exclude) - - # Returns the block connector that starts with the point given if it exists - def GetConnector(self, position, output_name = None, input_name = None): + + # Returns the block connector that starts with the point given if it exists + def GetConnector(self, position, output_name=None, input_name=None): if input_name is not None: # Test each input connector for input in self.Inputs: @@ -193,14 +195,14 @@ if input_name is None and output_name is None: return self.FindNearestConnector(position, self.Inputs + self.Outputs) return None - + def GetInputTypes(self): return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"]) - + def SetOutputValues(self, values): for output in self.Outputs: output.SetValue(values.get(ouput.getName(), None)) - + def GetConnectionResultType(self, connector, connectortype): if not TestConnectorName(connector.GetName(), self.Type): return connectortype @@ -216,13 +218,13 @@ if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): resulttype = outputtype return resulttype - + # Returns all the block connectors def GetConnectors(self): - return {"inputs" : self.Inputs, "outputs" : self.Outputs} - + return {"inputs": self.Inputs, "outputs": self.Outputs} + # Test if point given is on one of the block connectors - def TestConnector(self, pt, direction = None, exclude = True): + def TestConnector(self, pt, direction=None, exclude=True): # Test each input connector for input in self.Inputs: if input.TestPoint(pt, direction, exclude): @@ -232,10 +234,10 @@ if output.TestPoint(pt, direction, exclude): return output return None - + # Changes the block type - def SetType(self, type, extension, inputs = None, connectors = {}, executionControl = False): - if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: + def SetType(self, type, extension, inputs=None, connectors={}, executionControl=False): + if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: if type != self.Type: self.Type = type self.TypeSize = self.Parent.GetTextExtent(self.Type) @@ -252,7 +254,7 @@ start = int(inputs[-1][0].replace("IN", "")) for i in xrange(self.Extension - len(blocktype["inputs"])): start += 1 - inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) + inputs.append(("IN%d" % start, inputs[-1][1], inputs[-1][2])) comment = blocktype["comment"] self.Description = _(comment) + blocktype.get("usage", "") else: @@ -261,14 +263,14 @@ outputs = connectors.get("outputs", []) self.Description = None if self.ExecutionControl: - inputs.insert(0, ("EN","BOOL","none")) - outputs.insert(0, ("ENO","BOOL","none")) + inputs.insert(0, ("EN", "BOOL", "none")) + outputs.insert(0, ("ENO", "BOOL", "none")) self.Pen = MiterPen(self.Colour) - + # Extract the inputs properties and create or modify the corresponding connector input_connectors = [] for input_name, input_type, input_modifier in inputs: - connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True) + connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone=True) if input_modifier == "negated": connector.SetNegated(True) elif input_modifier != "none": @@ -282,9 +284,9 @@ break input_connectors.append(connector) for input in self.Inputs: - input.UnConnect(delete = True) + input.UnConnect(delete=True) self.Inputs = input_connectors - + # Extract the outputs properties and create or modify the corresponding connector output_connectors = [] for output_name, output_type, output_modifier in outputs: @@ -302,49 +304,49 @@ break output_connectors.append(connector) for output in self.Outputs: - output.UnConnect(delete = True) + output.UnConnect(delete=True) self.Outputs = output_connectors - + self.RefreshMinSize() self.RefreshConnectors() for output in self.Outputs: output.RefreshWires() self.RefreshBoundingBox() - + # Returns the block type def GetType(self): return self.Type - + # Changes the block name def SetName(self, name): self.Name = name self.RefreshNameSize() - + # Returs the block name def GetName(self): return self.Name - + # Changes the extension name def SetExtension(self, extension): self.Extension = extension - + # Returs the extension name def GetExtension(self): return self.Extension - + # Changes the execution order def SetExecutionOrder(self, executionOrder): self.ExecutionOrder = executionOrder self.RefreshExecutionOrderSize() - + # Returs the execution order def GetExecutionOrder(self): return self.ExecutionOrder - + # Returs the execution order def GetExecutionControl(self): return self.ExecutionControl - + # Refresh the block minimum size def RefreshMinSize(self): # Calculate the inputs maximum width @@ -360,42 +362,42 @@ width = max(self.TypeSize[0] + 10, max_input + max_output + 15) height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE self.MinSize = width, height - + # Returns the block minimum size def GetMinSize(self): return self.MinSize - + # Changes the negated property of the connector handled def SetConnectorNegated(self, negated): handle_type, handle = self.Handle if handle_type == HANDLE_CONNECTOR: handle.SetNegated(negated) self.RefreshModel(False) - + # Changes the edge property of the connector handled def SetConnectorEdge(self, edge): handle_type, handle = self.Handle if handle_type == HANDLE_CONNECTOR: handle.SetEdge(edge) self.RefreshModel(False) - -## # Method called when a Motion event have been generated -## def OnMotion(self, event, dc, scaling): -## if not event.Dragging(): -## pos = event.GetLogicalPosition(dc) -## for input in self.Inputs: -## rect = input.GetRedrawRect() -## if rect.InsideXY(pos.x, pos.y): -## print "Find input" -## tip = wx.TipWindow(self.Parent, "Test") -## tip.SetBoundingRect(rect) -## return Graphic_Element.OnMotion(self, event, dc, scaling) - + +# # Method called when a Motion event have been generated +# def OnMotion(self, event, dc, scaling): +# if not event.Dragging(): +# pos = event.GetLogicalPosition(dc) +# for input in self.Inputs: +# rect = input.GetRedrawRect() +# if rect.InsideXY(pos.x, pos.y): +# print "Find input" +# tip = wx.TipWindow(self.Parent, "Test") +# tip.SetBoundingRect(rect) +# return Graphic_Element.OnMotion(self, event, dc, scaling) + # Method called when a LeftDClick event have been generated def OnLeftDClick(self, event, dc, scaling): # Edit the block properties self.Parent.EditBlockContent(self) - + # Method called when a RightUp event have been generated def OnRightUp(self, event, dc, scaling): pos = GetScaledEventPosition(event, dc, scaling) @@ -406,7 +408,7 @@ self.Parent.PopupBlockMenu(connector) else: self.Parent.PopupBlockMenu() - + # Refreshes the block model def RefreshModel(self, move=True): self.Parent.RefreshBlockModel(self) @@ -414,12 +416,12 @@ if move: for output in self.Outputs: output.RefreshWires() - + def GetToolTipValue(self): return self.Description - + # Adds an highlight to the block - def AddHighlight(self, infos, start, end ,highlight_type): + def AddHighlight(self, infos, start, end, highlight_type): if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: highlights = self.Highlights.setdefault(infos[0], []) AddHighlight(highlights, (start, end, highlight_type)) @@ -427,7 +429,7 @@ self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) elif infos[0] == "output" and infos[1] < len(self.Outputs): self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) - + # Removes an highlight from the block def RemoveHighlight(self, infos, start, end, highlight_type): if infos[0] in ["type", "name"]: @@ -438,7 +440,7 @@ self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) elif infos[0] == "output" and infos[1] < len(self.Outputs): self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) - + # Removes all the highlights of one particular type from the block def ClearHighlight(self, highlight_type=None): if highlight_type is None: @@ -453,14 +455,14 @@ input.ClearHighlights(highlight_type) for output in self.Outputs: output.ClearHighlights(highlight_type) - + # Draws block def Draw(self, dc): Graphic_Element.Draw(self, dc) dc.SetPen(self.Pen) dc.SetBrush(wx.WHITE_BRUSH) dc.SetTextForeground(self.Colour) - + if getattr(dc, "printing", False): name_size = dc.GetTextExtent(self.Name) type_size = dc.GetTextExtent(self.Type) @@ -469,7 +471,7 @@ name_size = self.NameSize type_size = self.TypeSize executionorder_size = self.ExecutionOrderSize - + # Draw a rectangle with the block size dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) # Draw block name and block type @@ -487,25 +489,25 @@ if self.ExecutionOrder != 0: # Draw block execution order dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], - self.Pos.y + self.Size[1] + 2) - + self.Pos.y + self.Size[1] + 2) + if not getattr(dc, "printing", False): DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1]) DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1]) - - -#------------------------------------------------------------------------------- + + +# ------------------------------------------------------------------------------- # Function Block Diagram Variable -#------------------------------------------------------------------------------- - -""" -Class that implements the graphic representation of a variable -""" +# ------------------------------------------------------------------------------- + class FBD_Variable(Graphic_Element): + """ + Class that implements the graphic representation of a variable + """ # Create a new variable - def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0): + def __init__(self, parent, type, name, value_type, id=None, executionOrder=0): Graphic_Element.__init__(self, parent) self.Type = None self.ValueType = None @@ -516,9 +518,9 @@ self.Output = None self.SetType(type, value_type) self.Highlights = [] - + # Make a clone of this FBD_Variable - def Clone(self, parent, id = None, pos = None): + def Clone(self, parent, id=None, pos=None): variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) variable.SetSize(self.Size[0], self.Size[1]) if pos is not None: @@ -530,7 +532,7 @@ if self.Output: variable.Output = self.Output.Clone(variable) return variable - + def GetConnectorTranslation(self, element): connectors = {} if self.Input is not None: @@ -538,7 +540,7 @@ if self.Output is not None: connectors[self.Output] = element.Output return connectors - + def Flush(self): if self.Input is not None: self.Input.Flush() @@ -546,9 +548,9 @@ if self.Output is not None: self.Output.Flush() self.Output = None - + # Returns the RedrawRect - def GetRedrawRect(self, movex = 0, movey = 0): + def GetRedrawRect(self, movex=0, movey=0): rect = Graphic_Element.GetRedrawRect(self, movex, movey) if movex != 0 or movey != 0: if self.Input and self.Input.IsConnected(): @@ -556,26 +558,26 @@ if self.Output and self.Output.IsConnected(): rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) return rect - + # Unconnect connector def Clean(self): if self.Input: - self.Input.UnConnect(delete = True) + self.Input.UnConnect(delete=True) if self.Output: - self.Output.UnConnect(delete = True) - + self.Output.UnConnect(delete=True) + # Delete this variable by calling the appropriate method def Delete(self): self.Parent.DeleteVariable(self) - + # Refresh the size of text for name def RefreshNameSize(self): self.NameSize = self.Parent.GetTextExtent(self.Name) - + # Refresh the size of text for execution order def RefreshExecutionOrderSize(self): self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) - + # Refresh the variable bounding box def RefreshBoundingBox(self): if self.Type in (OUTPUT, INOUT): @@ -594,7 +596,7 @@ bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1) - + # Refresh the position of the variable connector def RefreshConnectors(self): scaling = self.Parent.GetScaling() @@ -607,28 +609,28 @@ if self.Output: self.Output.SetPosition(wx.Point(self.Size[0], position)) self.RefreshConnected() - + # Refresh the position of wires connected to connector - def RefreshConnected(self, exclude = []): + def RefreshConnected(self, exclude=[]): if self.Input: self.Input.MoveConnected(exclude) if self.Output: self.Output.MoveConnected(exclude) - + # Test if point given is on the variable connector - def TestConnector(self, pt, direction = None, exclude=True): + def TestConnector(self, pt, direction=None, exclude=True): if self.Input and self.Input.TestPoint(pt, direction, exclude): return self.Input if self.Output and self.Output.TestPoint(pt, direction, exclude): return self.Output return None - - # Returns the block connector that starts with the point given if it exists - def GetConnector(self, position, name = None): + + # Returns the block connector that starts with the point given if it exists + def GetConnector(self, position, name=None): # if a name is given if name is not None: # Test input and output connector if they exists - #if self.Input and name == self.Input.GetName(): + # if self.Input and name == self.Input.GetName(): # return self.Input if self.Output and name == self.Output.GetName(): return self.Output @@ -640,8 +642,8 @@ if self.Output: connectors.append(self.Output) return self.FindNearestConnector(position, connectors) - - # Returns all the block connectors + + # Returns all the block connectors def GetConnectors(self): connectors = {"inputs": [], "outputs": []} if self.Input: @@ -649,14 +651,14 @@ if self.Output: connectors["outputs"].append(self.Output) return connectors - + # Changes the negated property of the variable connector if handled def SetConnectorNegated(self, negated): handle_type, handle = self.Handle if handle_type == HANDLE_CONNECTOR: handle.SetNegated(negated) self.RefreshModel(False) - + # Changes the variable type def SetType(self, type, value_type): if type != self.Type: @@ -664,15 +666,15 @@ # Create an input or output connector according to variable type if self.Type != INPUT: if self.Input is None: - self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True) + self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone=True) elif self.Input: - self.Input.UnConnect(delete = True) + self.Input.UnConnect(delete=True) self.Input = None if self.Type != OUTPUT: if self.Output is None: self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) elif self.Output: - self.Output.UnConnect(delete = True) + self.Output.UnConnect(delete=True) self.Output = None self.RefreshConnectors() self.RefreshBoundingBox() @@ -680,38 +682,38 @@ if self.Input: self.Input.SetType(value_type) if self.Output: - self.Output.SetType(value_type) - + self.Output.SetType(value_type) + # Returns the variable type def GetType(self): return self.Type - + # Returns the variable value type def GetValueType(self): return self.ValueType - + # Changes the variable name def SetName(self, name): self.Name = name self.RefreshNameSize() - + # Returns the variable name def GetName(self): return self.Name - + # Changes the execution order def SetExecutionOrder(self, executionOrder): self.ExecutionOrder = executionOrder self.RefreshExecutionOrderSize() - + # Returs the execution order def GetExecutionOrder(self): return self.ExecutionOrder - + # Returns the variable minimum size def GetMinSize(self): return self.NameSize[0] + 10, self.NameSize[1] + 10 - + # Set size of the variable to the minimum size def SetBestSize(self, scaling): if self.Type == INPUT: @@ -720,22 +722,22 @@ return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) else: return Graphic_Element.SetBestSize(self, scaling) - + # Method called when a LeftDClick event have been generated def OnLeftDClick(self, event, dc, scaling): if event.ControlDown(): - # Change variable type + # Change variable type types = [INPUT, OUTPUT, INOUT] - self.Parent.ChangeVariableType(self, - types[(types.index(self.Type) + 1) % len(types)]) + self.Parent.ChangeVariableType( + self, types[(types.index(self.Type) + 1) % len(types)]) else: # Edit the variable properties self.Parent.EditVariableContent(self) - + # Method called when a RightUp event have been generated def OnRightUp(self, event, dc, scaling): self.Parent.PopupVariableMenu() - + # Refreshes the variable model def RefreshModel(self, move=True): self.Parent.RefreshVariableModel(self) @@ -744,35 +746,35 @@ if move and self.Type != OUTPUT: if self.Output: self.Output.RefreshWires() - + # Adds an highlight to the variable def AddHighlight(self, infos, start, end, highlight_type): if infos[0] == "expression" and start[0] == 0 and end[0] == 0: AddHighlight(self.Highlights, (start, end, highlight_type)) - + # Removes an highlight from the variable def RemoveHighlight(self, infos, start, end, highlight_type): if infos[0] == "expression": RemoveHighlight(self.Highlights, (start, end, highlight_type)) - + # Removes all the highlights of one particular type from the variable def ClearHighlight(self, highlight_type=None): ClearHighlights(self.Highlights, highlight_type) - + # Draws variable def Draw(self, dc): Graphic_Element.Draw(self, dc) dc.SetPen(MiterPen(wx.BLACK)) dc.SetBrush(wx.WHITE_BRUSH) - + if getattr(dc, "printing", False): name_size = dc.GetTextExtent(self.Name) executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) else: name_size = self.NameSize executionorder_size = self.ExecutionOrderSize - - text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, + + text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, self.Pos.y + (self.Size[1] - name_size[1]) / 2) # Draw a rectangle with the variable size dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) @@ -781,27 +783,28 @@ # Draw connectors if self.Input: self.Input.Draw(dc) - if self.Output: + if self.Output: self.Output.Draw(dc) if self.ExecutionOrder != 0: # Draw variable execution order dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], - self.Pos.y + self.Size[1] + 2) + self.Pos.y + self.Size[1] + 2) if not getattr(dc, "printing", False): DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) - -#------------------------------------------------------------------------------- + + +# ------------------------------------------------------------------------------- # Function Block Diagram Connector -#------------------------------------------------------------------------------- - -""" -Class that implements the graphic representation of a connection -""" +# ------------------------------------------------------------------------------- + class FBD_Connector(Graphic_Element): + """ + Class that implements the graphic representation of a connection + """ # Create a new connection - def __init__(self, parent, type, name, id = None): + def __init__(self, parent, type, name, id=None): Graphic_Element.__init__(self, parent) self.Type = type self.Id = id @@ -811,27 +814,27 @@ self.Highlights = [] # Create an input or output connector according to connection type if self.Type == CONNECTOR: - self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) + self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) else: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) self.RefreshConnectors() self.RefreshNameSize() - + def Flush(self): if self.Connector: self.Connector.Flush() self.Connector = None - + # Returns the RedrawRect - def GetRedrawRect(self, movex = 0, movey = 0): + def GetRedrawRect(self, movex=0, movey=0): rect = Graphic_Element.GetRedrawRect(self, movex, movey) if movex != 0 or movey != 0: if self.Connector and self.Connector.IsConnected(): rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) return rect - + # Make a clone of this FBD_Connector - def Clone(self, parent, id = None, pos = None): + def Clone(self, parent, id=None, pos=None): connection = FBD_Connector(parent, self.Type, self.Name, id) connection.SetSize(self.Size[0], self.Size[1]) if pos is not None: @@ -840,23 +843,23 @@ connection.SetPosition(self.Pos.x, self.Pos.y) connection.Connector = self.Connector.Clone(connection) return connection - + def GetConnectorTranslation(self, element): - return {self.Connector : element.Connector} + return {self.Connector: element.Connector} # Unconnect connector def Clean(self): if self.Connector: - self.Connector.UnConnect(delete = True) - + self.Connector.UnConnect(delete=True) + # Delete this connection by calling the appropriate method def Delete(self): self.Parent.DeleteConnection(self) - + # Refresh the size of text for name def RefreshNameSize(self): self.NameSize = self.Parent.GetTextExtent(self.Name) - + # Refresh the connection bounding box def RefreshBoundingBox(self): if self.Type == CONNECTOR: @@ -865,7 +868,7 @@ bbx_x = self.Pos.x bbx_width = self.Size[0] + CONNECTOR_SIZE self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) - + # Refresh the position of the connection connector def RefreshConnectors(self): scaling = self.Parent.GetScaling() @@ -878,23 +881,23 @@ else: self.Connector.SetPosition(wx.Point(self.Size[0], position)) self.RefreshConnected() - + # Refresh the position of wires connected to connector - def RefreshConnected(self, exclude = []): + def RefreshConnected(self, exclude=[]): if self.Connector: self.Connector.MoveConnected(exclude) - + # Test if point given is on the connection connector - def TestConnector(self, pt, direction = None, exclude=True): + def TestConnector(self, pt, direction=None, exclude=True): if self.Connector and self.Connector.TestPoint(pt, direction, exclude): return self.Connector return None - + # Returns the connection connector - def GetConnector(self, position = None, name = None): + def GetConnector(self, position=None, name=None): return self.Connector - - # Returns all the block connectors + + # Returns all the block connectors def GetConnectors(self): connectors = {"inputs": [], "outputs": []} if self.Type == CONNECTOR: @@ -918,50 +921,50 @@ self.Clean() # Create an input or output connector according to connection type if self.Type == CONNECTOR: - self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) + self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone=True) else: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) self.RefreshConnectors() self.RefreshBoundingBox() - + # Returns the connection type def GetType(self): return self.Type - + def GetConnectionResultType(self, connector, connectortype): if self.Type == CONTINUATION: connector = self.Parent.GetConnectorByName(self.Name) if connector is not None: return connector.Connector.GetConnectedType() return connectortype - + # Changes the connection name def SetName(self, name): self.Name = name self.RefreshNameSize() - + # Returns the connection name def GetName(self): return self.Name - + # Set size of the variable to the minimum size def SetBestSize(self, scaling): if self.Type == CONTINUATION: return Graphic_Element.SetBestSize(self, scaling, x_factor=1.) else: return Graphic_Element.SetBestSize(self, scaling, x_factor=0.) - + # Returns the connection minimum size def GetMinSize(self): text_width, text_height = self.NameSize if text_height % 2 == 1: text_height += 1 return text_width + text_height + 20, text_height + 10 - + # Method called when a LeftDClick event have been generated def OnLeftDClick(self, event, dc, scaling): if event.ControlDown(): - # Change connection type + # Change connection type if self.Type == CONNECTOR: self.Parent.ChangeConnectionType(self, CONTINUATION) else: @@ -969,12 +972,12 @@ else: # Edit the connection properties self.Parent.EditConnectionContent(self) - + # Method called when a RightUp event have been generated def OnRightUp(self, event, dc, scaling): # Popup the default menu self.Parent.PopupConnectionMenu() - + # Refreshes the connection model def RefreshModel(self, move=True): self.Parent.RefreshConnectionModel(self) @@ -983,51 +986,50 @@ if move and self.Type == CONTINUATION: if self.Connector: self.Connector.RefreshWires() - + # Adds an highlight to the connection def AddHighlight(self, infos, start, end, highlight_type): if infos[0] == "name" and start[0] == 0 and end[0] == 0: AddHighlight(self.Highlights, (start, end, highlight_type)) - + # Removes an highlight from the connection def RemoveHighlight(self, infos, start, end, highlight_type): if infos[0] == "name": RemoveHighlight(self.Highlights, (start, end, highlight_type)) - + # Removes all the highlights of one particular type from the connection def ClearHighlight(self, highlight_type=None): ClearHighlights(self.Highlights, highlight_type) - + # Draws connection def Draw(self, dc): Graphic_Element.Draw(self, dc) dc.SetPen(MiterPen(wx.BLACK)) dc.SetBrush(wx.WHITE_BRUSH) - + if getattr(dc, "printing", False): name_size = dc.GetTextExtent(self.Name) else: name_size = self.NameSize - + # Draw a rectangle with the connection size with arrows inside dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) - dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, - self.Pos.y + self.Size[1] / 2) - dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, - self.Pos.x, self.Pos.y + self.Size[1]) - dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, - self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) - dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, - self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) + dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, + self.Pos.y + self.Size[1] / 2) + dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, + self.Pos.x, self.Pos.y + self.Size[1]) + dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, + self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) + dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, + self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) # Draw connection name - text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, + text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, self.Pos.y + (self.Size[1] - name_size[1]) / 2) dc.DrawText(self.Name, text_pos[0], text_pos[1]) # Draw connector if self.Connector: self.Connector.Draw(dc) - + if not getattr(dc, "printing", False): DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) -