etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor etisserant@0: #based on the plcopen standard. etisserant@0: # lbessard@58: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@5: #modify it under the terms of the GNU General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@58: #General Public License for more details. etisserant@0: # etisserant@5: #You should have received a copy of the GNU General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: import wx etisserant@0: etisserant@0: from GraphicCommons import * etisserant@0: from plcopen.structures import * etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Function Block Diagram Block etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a function block etisserant@0: """ etisserant@0: laurent@653: def TestConnectorName(name, block_type): laurent@653: return name in ["OUT", "MN", "MX"] or name.startswith("IN") and (block_type, name) != ("EXPT", "IN2") laurent@653: etisserant@0: class FBD_Block(Graphic_Element): etisserant@0: etisserant@0: # Create a new block lbessard@269: def __init__(self, parent, type, name, id = None, extension = 0, inputs = None, connectors = {}, executionControl = False, executionOrder = 0): etisserant@0: Graphic_Element.__init__(self, parent) lbessard@3: self.Type = None laurent@625: self.Description = None lbessard@27: self.Extension = None lbessard@269: self.ExecutionControl = False etisserant@0: self.Id = id lbessard@118: self.SetName(name) lbessard@118: self.SetExecutionOrder(executionOrder) lbessard@2: self.Inputs = [] lbessard@2: self.Outputs = [] lbessard@90: self.Colour = wx.BLACK laurent@563: self.Pen = MiterPen(wx.BLACK) lbessard@269: self.SetType(type, extension, inputs, connectors, executionControl) laurent@566: self.Highlights = {} etisserant@0: lbessard@112: # Make a clone of this FBD_Block lbessard@162: def Clone(self, parent, id = None, name = "", pos = None): lbessard@144: if self.Name != "" and name == "": lbessard@144: name = self.Name lbessard@162: block = FBD_Block(parent, self.Type, name, id, self.Extension) lbessard@112: block.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: block.SetPosition(pos.x, pos.y) lbessard@283: else: lbessard@283: block.SetPosition(self.Pos.x, self.Pos.y) lbessard@112: block.Inputs = [input.Clone(block) for input in self.Inputs] lbessard@112: block.Outputs = [output.Clone(block) for output in self.Outputs] lbessard@112: return block lbessard@112: lbessard@283: def GetConnectorTranslation(self, element): lbessard@283: return dict(zip(self.Inputs + self.Outputs, element.Inputs + element.Outputs)) lbessard@283: lbessard@249: def Flush(self): lbessard@249: for input in self.Inputs: lbessard@249: input.Flush() etisserant@0: self.Inputs = [] lbessard@249: for output in self.Outputs: lbessard@249: output.Flush() etisserant@0: self.Outputs = [] etisserant@0: lbessard@144: # Returns the RedrawRect lbessard@144: def GetRedrawRect(self, movex = 0, movey = 0): lbessard@144: rect = Graphic_Element.GetRedrawRect(self, movex, movey) lbessard@144: if movex != 0 or movey != 0: lbessard@144: for input in self.Inputs: lbessard@144: if input.IsConnected(): lbessard@144: rect = rect.Union(input.GetConnectedRedrawRect(movex, movey)) lbessard@144: for output in self.Outputs: lbessard@144: if output.IsConnected(): lbessard@144: rect = rect.Union(output.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: etisserant@0: # Delete this block by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteBlock(self) etisserant@0: etisserant@0: # Unconnect all inputs and outputs etisserant@0: def Clean(self): etisserant@0: for input in self.Inputs: lbessard@2: input.UnConnect(delete = True) lbessard@2: for output in self.Outputs: lbessard@2: output.UnConnect(delete = True) etisserant@0: lbessard@42: # Refresh the size of text for name lbessard@42: def RefreshNameSize(self): lbessard@165: self.NameSize = self.Parent.GetTextExtent(self.Name) lbessard@42: lbessard@118: # Refresh the size of text for execution order lbessard@118: def RefreshExecutionOrderSize(self): lbessard@165: self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) lbessard@118: laurent@659: # Returns if the point given is in the bounding box laurent@659: def HitTest(self, pt, connectors=True): laurent@659: if self.Name != "": laurent@659: test_text = self.GetTextBoundingBox().InsideXY(pt.x, pt.y) laurent@659: else: laurent@659: test_text = False laurent@659: test_block = self.GetBlockBoundingBox(connectors).InsideXY(pt.x, pt.y) laurent@659: return test_text or test_block laurent@659: laurent@659: # Returns the bounding box of the name outside the block laurent@659: def GetTextBoundingBox(self): etisserant@0: # Calculate the size of the name outside the block lbessard@42: text_width, text_height = self.NameSize laurent@659: return wx.Rect(self.Pos.x + (self.Size[0] - text_width) / 2, laurent@659: self.Pos.y - (text_height + 2), laurent@659: text_width, laurent@659: text_height) laurent@659: laurent@659: # Returns the bounding box of function block without name outside laurent@659: def GetBlockBoundingBox(self, connectors=True): laurent@659: bbx_x, bbx_y = self.Pos.x, self.Pos.y laurent@659: bbx_width, bbx_height = self.Size laurent@659: if connectors: laurent@659: bbx_x -= min(1, len(self.Inputs)) * CONNECTOR_SIZE laurent@659: bbx_width += (min(1, len(self.Inputs)) + min(1, len(self.Outputs))) * CONNECTOR_SIZE lbessard@118: if self.ExecutionOrder != 0: lbessard@118: bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) lbessard@118: bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) lbessard@118: bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) laurent@659: return wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) laurent@659: laurent@659: # Refresh the block bounding box laurent@659: def RefreshBoundingBox(self): laurent@659: self.BoundingBox = self.GetBlockBoundingBox() laurent@659: if self.Name != "": laurent@659: self.BoundingBox.Union(self.GetTextBoundingBox()) etisserant@0: etisserant@0: # Refresh the positions of the block connectors etisserant@0: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() etisserant@0: # Calculate the size for the connector lines etisserant@0: lines = max(len(self.Inputs), len(self.Outputs)) lbessard@103: if lines > 0: lbessard@103: linesize = max((self.Size[1] - BLOCK_LINE_SIZE) / lines, BLOCK_LINE_SIZE) lbessard@145: # Update inputs and outputs positions lbessard@103: position = BLOCK_LINE_SIZE + linesize / 2 lbessard@145: for i in xrange(lines): lbessard@145: if scaling is not None: Laurent@717: ypos = round_scaling(self.Pos.y + position, scaling[1]) - self.Pos.y lbessard@145: else: lbessard@145: ypos = position lbessard@145: if i < len(self.Inputs): lbessard@145: self.Inputs[i].SetPosition(wx.Point(0, ypos)) lbessard@145: if i < len(self.Outputs): lbessard@145: self.Outputs[i].SetPosition(wx.Point(self.Size[0], ypos)) lbessard@103: position += linesize etisserant@0: self.RefreshConnected() etisserant@0: etisserant@0: # Refresh the positions of wires connected to inputs and outputs etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: for input in self.Inputs: etisserant@0: input.MoveConnected(exclude) etisserant@0: for output in self.Outputs: etisserant@0: output.MoveConnected(exclude) etisserant@0: etisserant@0: # Returns the block connector that starts with the point given if it exists lbessard@27: def GetConnector(self, position, name = None): lbessard@27: # if a name is given laurent@633: if name is not None: lbessard@27: # Test each input and output connector laurent@633: #for input in self.Inputs: laurent@633: # if name == input.GetName(): laurent@633: # return input lbessard@27: for output in self.Outputs: lbessard@27: if name == output.GetName(): lbessard@27: return output laurent@537: return self.FindNearestConnector(position, self.Inputs + self.Outputs) laurent@537: lbessard@28: def GetInputTypes(self): lbessard@269: return tuple([input.GetType(True) for input in self.Inputs if input.GetName() != "EN"]) lbessard@28: lbessard@102: def SetOutputValues(self, values): lbessard@102: for output in self.Outputs: lbessard@102: output.SetValue(values.get(ouput.getName(), None)) lbessard@102: lbessard@102: def GetConnectionResultType(self, connector, connectortype): laurent@653: if not TestConnectorName(connector.GetName(), self.Type): laurent@653: return connectortype lbessard@102: resulttype = connectortype lbessard@99: for input in self.Inputs: laurent@664: if input != connector and input.GetType(True) == "ANY" and TestConnectorName(input.GetName(), self.Type): lbessard@99: inputtype = input.GetConnectedType() lbessard@231: if resulttype is None or inputtype is not None and self.IsOfType(inputtype, resulttype): lbessard@99: resulttype = inputtype lbessard@99: for output in self.Outputs: laurent@664: if output != connector and output.GetType(True) == "ANY" and TestConnectorName(output.GetName(), self.Type): lbessard@99: outputtype = output.GetConnectedType() lbessard@231: if resulttype is None or outputtype is not None and self.IsOfType(outputtype, resulttype): lbessard@99: resulttype = outputtype laurent@653: return resulttype laurent@653: lbessard@145: # Returns all the block connectors etisserant@0: def GetConnectors(self): etisserant@0: return {"inputs" : self.Inputs, "outputs" : self.Outputs} etisserant@0: etisserant@0: # Test if point given is on one of the block connectors lbessard@243: def TestConnector(self, pt, direction = None, exclude = True): etisserant@0: # Test each input connector etisserant@0: for input in self.Inputs: lbessard@243: if input.TestPoint(pt, direction, exclude): etisserant@0: return input etisserant@0: # Test each output connector etisserant@0: for output in self.Outputs: lbessard@243: if output.TestPoint(pt, direction, exclude): etisserant@0: return output etisserant@0: return None etisserant@0: lbessard@2: # Changes the block type lbessard@269: def SetType(self, type, extension, inputs = None, connectors = {}, executionControl = False): lbessard@269: if type != self.Type or self.Extension != extension or executionControl != self.ExecutionControl: lbessard@42: if type != self.Type: lbessard@42: self.Type = type lbessard@165: self.TypeSize = self.Parent.GetTextExtent(self.Type) lbessard@27: self.Extension = extension lbessard@269: self.ExecutionControl = executionControl lbessard@3: # Find the block definition from type given and create the corresponding lbessard@3: # inputs and outputs lbessard@231: blocktype = self.Parent.GetBlockType(type, inputs) lbessard@3: if blocktype: lbessard@90: self.Colour = wx.BLACK lbessard@3: inputs = [input for input in blocktype["inputs"]] lbessard@3: outputs = [output for output in blocktype["outputs"]] lbessard@3: if blocktype["extensible"]: lbessard@3: start = int(inputs[-1][0].replace("IN", "")) lbessard@3: for i in xrange(self.Extension - len(blocktype["inputs"])): lbessard@3: start += 1 lbessard@27: inputs.append(("IN%d"%start, inputs[-1][1], inputs[-1][2])) laurent@625: comment = blocktype["comment"] laurent@625: self.Description = _(comment) + blocktype.get("usage", "") lbessard@16: else: lbessard@90: self.Colour = wx.RED laurent@379: inputs = connectors.get("inputs", []) laurent@379: outputs = connectors.get("outputs", []) laurent@625: self.Description = None lbessard@269: if self.ExecutionControl: lbessard@269: inputs.insert(0, ("EN","BOOL","none")) lbessard@269: outputs.insert(0, ("ENO","BOOL","none")) laurent@563: self.Pen = MiterPen(self.Colour) laurent@679: laurent@679: # Extract the inputs properties and create or modify the corresponding connector laurent@687: idx = 0 laurent@679: for idx, (input_name, input_type, input_modifier) in enumerate(inputs): laurent@679: if idx < len(self.Inputs): laurent@679: connector = self.Inputs[idx] laurent@679: connector.SetName(input_name) laurent@679: connector.SetType(input_type) laurent@679: else: laurent@679: connector = Connector(self, input_name, input_type, wx.Point(0, 0), WEST, onlyone = True) laurent@679: self.Inputs.append(connector) lbessard@3: if input_modifier == "negated": lbessard@3: connector.SetNegated(True) lbessard@3: elif input_modifier != "none": lbessard@3: connector.SetEdge(input_modifier) laurent@679: for i in xrange(idx + 1, len(self.Inputs)): laurent@679: self.Inputs[i].UnConnect(delete = True) laurent@679: self.Inputs = self.Inputs[:idx + 1] laurent@679: laurent@679: # Extract the outputs properties and create or modify the corresponding connector laurent@687: idx = 0 laurent@679: for idx, (output_name, output_type, output_modifier) in enumerate(outputs): laurent@679: if idx < len(self.Outputs): laurent@679: connector = self.Outputs[idx] laurent@679: connector.SetName(output_name) laurent@679: connector.SetType(output_type) laurent@679: else: laurent@679: connector = Connector(self, output_name, output_type, wx.Point(0, 0), EAST) laurent@679: self.Outputs.append(connector) lbessard@3: if output_modifier == "negated": lbessard@3: connector.SetNegated(True) lbessard@3: elif output_modifier != "none": lbessard@3: connector.SetEdge(output_modifier) laurent@679: for i in xrange(idx + 1, len(self.Outputs)): laurent@679: self.Outputs[i].UnConnect(delete = True) laurent@679: self.Outputs = self.Outputs[:idx + 1] laurent@679: lbessard@42: self.RefreshMinSize() lbessard@3: self.RefreshConnectors() lbessard@3: self.RefreshBoundingBox() lbessard@2: etisserant@0: # Returns the block type etisserant@0: def GetType(self): etisserant@0: return self.Type etisserant@0: etisserant@0: # Changes the block name etisserant@0: def SetName(self, name): etisserant@0: self.Name = name lbessard@42: self.RefreshNameSize() etisserant@0: etisserant@0: # Returs the block name etisserant@0: def GetName(self): etisserant@0: return self.Name etisserant@0: lbessard@2: # Changes the extension name lbessard@2: def SetExtension(self, extension): lbessard@2: self.Extension = extension lbessard@2: lbessard@2: # Returs the extension name lbessard@2: def GetExtension(self): lbessard@2: return self.Extension lbessard@2: lbessard@118: # Changes the execution order lbessard@118: def SetExecutionOrder(self, executionOrder): lbessard@118: self.ExecutionOrder = executionOrder lbessard@118: self.RefreshExecutionOrderSize() lbessard@118: lbessard@118: # Returs the execution order lbessard@118: def GetExecutionOrder(self): lbessard@118: return self.ExecutionOrder lbessard@118: lbessard@269: # Returs the execution order lbessard@269: def GetExecutionControl(self): lbessard@269: return self.ExecutionControl lbessard@269: lbessard@42: # Refresh the block minimum size lbessard@42: def RefreshMinSize(self): etisserant@0: # Calculate the inputs maximum width etisserant@0: max_input = 0 etisserant@0: for input in self.Inputs: lbessard@42: w, h = input.GetNameSize() etisserant@0: max_input = max(max_input, w) etisserant@0: # Calculate the outputs maximum width etisserant@0: max_output = 0 etisserant@0: for output in self.Outputs: lbessard@42: w, h = output.GetNameSize() etisserant@0: max_output = max(max_output, w) lbessard@42: width = max(self.TypeSize[0] + 10, max_input + max_output + 15) etisserant@0: height = (max(len(self.Inputs), len(self.Outputs)) + 1) * BLOCK_LINE_SIZE lbessard@42: self.MinSize = width, height lbessard@42: lbessard@42: # Returns the block minimum size lbessard@42: def GetMinSize(self): lbessard@42: return self.MinSize etisserant@0: etisserant@0: # Changes the negated property of the connector handled etisserant@0: def SetConnectorNegated(self, negated): etisserant@0: handle_type, handle = self.Handle etisserant@0: if handle_type == HANDLE_CONNECTOR: etisserant@0: handle.SetNegated(negated) etisserant@0: self.RefreshModel(False) etisserant@0: etisserant@0: # Changes the edge property of the connector handled etisserant@0: def SetConnectorEdge(self, edge): etisserant@0: handle_type, handle = self.Handle etisserant@0: if handle_type == HANDLE_CONNECTOR: etisserant@0: handle.SetEdge(edge) etisserant@0: self.RefreshModel(False) etisserant@0: lbessard@287: ## # Method called when a Motion event have been generated lbessard@287: ## def OnMotion(self, event, dc, scaling): lbessard@287: ## if not event.Dragging(): lbessard@287: ## pos = event.GetLogicalPosition(dc) lbessard@287: ## for input in self.Inputs: lbessard@287: ## rect = input.GetRedrawRect() lbessard@287: ## if rect.InsideXY(pos.x, pos.y): lbessard@287: ## print "Find input" lbessard@287: ## tip = wx.TipWindow(self.Parent, "Test") lbessard@287: ## tip.SetBoundingRect(rect) lbessard@287: ## return Graphic_Element.OnMotion(self, event, dc, scaling) lbessard@287: lbessard@2: # Method called when a LeftDClick event have been generated lbessard@27: def OnLeftDClick(self, event, dc, scaling): lbessard@3: # Edit the block properties lbessard@2: self.Parent.EditBlockContent(self) lbessard@2: etisserant@0: # Method called when a RightUp event have been generated lbessard@27: def OnRightUp(self, event, dc, scaling): lbessard@27: pos = GetScaledEventPosition(event, dc, scaling) etisserant@0: # Popup the menu with special items for a block and a connector if one is handled lbessard@243: connector = self.TestConnector(pos, exclude=False) etisserant@0: if connector: etisserant@0: self.Handle = (HANDLE_CONNECTOR, connector) etisserant@0: self.Parent.PopupBlockMenu(connector) etisserant@0: else: etisserant@0: self.Parent.PopupBlockMenu() etisserant@0: etisserant@0: # Refreshes the block model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshBlockModel(self) etisserant@0: # If block has moved, refresh the model of wires connected to outputs etisserant@0: if move: etisserant@0: for output in self.Outputs: etisserant@0: output.RefreshWires() etisserant@0: laurent@625: def GetToolTipValue(self): laurent@625: return self.Description laurent@625: laurent@566: # Adds an highlight to the block laurent@566: def AddHighlight(self, infos, start, end ,highlight_type): lbessard@231: if infos[0] in ["type", "name"] and start[0] == 0 and end[0] == 0: laurent@566: highlights = self.Highlights.setdefault(infos[0], []) laurent@566: AddHighlight(highlights, (start, end, highlight_type)) lbessard@231: elif infos[0] == "input" and infos[1] < len(self.Inputs): laurent@566: self.Inputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) lbessard@231: elif infos[0] == "output" and infos[1] < len(self.Outputs): laurent@566: self.Outputs[infos[1]].AddHighlight(infos[2:], start, end, highlight_type) laurent@566: laurent@566: # Removes an highlight from the block laurent@566: def RemoveHighlight(self, infos, start, end, highlight_type): laurent@566: if infos[0] in ["type", "name"]: laurent@566: highlights = self.Highlights.get(infos[0], []) laurent@566: if RemoveHighlight(highlights, (start, end, highlight_type)) and len(highlights) == 0: laurent@566: self.Highlights.pop(infos[0]) laurent@566: elif infos[0] == "input" and infos[1] < len(self.Inputs): laurent@566: self.Inputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) laurent@566: elif infos[0] == "output" and infos[1] < len(self.Outputs): laurent@566: self.Outputs[infos[1]].RemoveHighlight(infos[2:], start, end, highlight_type) laurent@566: laurent@566: # Removes all the highlights of one particular type from the block laurent@566: def ClearHighlight(self, highlight_type=None): laurent@566: if highlight_type is None: laurent@566: self.Highlights = {} laurent@566: else: laurent@566: highlight_items = self.Highlights.items() laurent@566: for name, highlights in highlight_items: laurent@566: highlights = ClearHighlights(highlights, highlight_type) laurent@566: if len(highlights) == 0: laurent@566: self.Highlights.pop(name) laurent@566: for input in self.Inputs: laurent@566: input.ClearHighlights(highlight_type) laurent@566: for output in self.Outputs: laurent@566: output.ClearHighlights(highlight_type) lbessard@231: etisserant@0: # Draws block etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@90: dc.SetPen(self.Pen) lbessard@64: dc.SetBrush(wx.WHITE_BRUSH) lbessard@90: dc.SetTextForeground(self.Colour) lbessard@213: lbessard@213: if getattr(dc, "printing", False): lbessard@213: name_size = dc.GetTextExtent(self.Name) lbessard@213: type_size = dc.GetTextExtent(self.Type) lbessard@213: executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) lbessard@213: else: lbessard@213: name_size = self.NameSize lbessard@213: type_size = self.TypeSize lbessard@213: executionorder_size = self.ExecutionOrderSize lbessard@213: etisserant@0: # Draw a rectangle with the block size etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: # Draw block name and block type lbessard@231: name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, lbessard@231: self.Pos.y - (name_size[1] + 2)) lbessard@231: type_pos = (self.Pos.x + (self.Size[0] - type_size[0]) / 2, lbessard@231: self.Pos.y + 5) lbessard@231: dc.DrawText(self.Name, name_pos[0], name_pos[1]) lbessard@231: dc.DrawText(self.Type, type_pos[0], type_pos[1]) etisserant@0: # Draw inputs and outputs connectors etisserant@0: for input in self.Inputs: etisserant@0: input.Draw(dc) etisserant@0: for output in self.Outputs: etisserant@0: output.Draw(dc) lbessard@118: if self.ExecutionOrder != 0: lbessard@118: # Draw block execution order lbessard@213: dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], lbessard@118: self.Pos.y + self.Size[1] + 2) laurent@566: laurent@566: if not getattr(dc, "printing", False): laurent@566: DrawHighlightedText(dc, self.Name, self.Highlights.get("name", []), name_pos[0], name_pos[1]) laurent@566: DrawHighlightedText(dc, self.Type, self.Highlights.get("type", []), type_pos[0], type_pos[1]) lbessard@140: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Function Block Diagram Variable etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a variable etisserant@0: """ etisserant@0: etisserant@0: class FBD_Variable(Graphic_Element): etisserant@0: etisserant@0: # Create a new variable lbessard@118: def __init__(self, parent, type, name, value_type, id = None, executionOrder = 0): etisserant@0: Graphic_Element.__init__(self, parent) lbessard@3: self.Type = None lbessard@3: self.ValueType = None etisserant@0: self.Id = id lbessard@118: self.SetName(name) lbessard@118: self.SetExecutionOrder(executionOrder) etisserant@0: self.Input = None etisserant@0: self.Output = None lbessard@3: self.SetType(type, value_type) laurent@566: self.Highlights = [] etisserant@0: lbessard@112: # Make a clone of this FBD_Variable lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@162: variable = FBD_Variable(parent, self.Type, self.Name, self.ValueType, id) lbessard@112: variable.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: variable.SetPosition(pos.x, pos.y) lbessard@283: else: lbessard@283: variable.SetPosition(self.Pos.x, self.Pos.y) lbessard@144: if self.Input: lbessard@144: variable.Input = self.Input.Clone(variable) lbessard@144: if self.Output: lbessard@144: variable.Output = self.Output.Clone(variable) lbessard@112: return variable lbessard@112: lbessard@283: def GetConnectorTranslation(self, element): lbessard@283: connectors = {} lbessard@283: if self.Input is not None: lbessard@287: connectors[self.Input] = element.Input lbessard@283: if self.Output is not None: lbessard@283: connectors[self.Output] = element.Output lbessard@283: return connectors lbessard@283: lbessard@249: def Flush(self): lbessard@249: if self.Input is not None: lbessard@249: self.Input.Flush() lbessard@249: self.Input = None lbessard@249: if self.Output is not None: lbessard@249: self.Output.Flush() lbessard@249: self.Output = None etisserant@0: lbessard@144: # Returns the RedrawRect lbessard@144: def GetRedrawRect(self, movex = 0, movey = 0): lbessard@144: rect = Graphic_Element.GetRedrawRect(self, movex, movey) lbessard@144: if movex != 0 or movey != 0: lbessard@144: if self.Input and self.Input.IsConnected(): lbessard@144: rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) lbessard@144: if self.Output and self.Output.IsConnected(): lbessard@144: rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: etisserant@0: # Unconnect connector etisserant@0: def Clean(self): etisserant@0: if self.Input: lbessard@3: self.Input.UnConnect(delete = True) etisserant@0: if self.Output: lbessard@3: self.Output.UnConnect(delete = True) etisserant@0: etisserant@0: # Delete this variable by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteVariable(self) etisserant@0: lbessard@42: # Refresh the size of text for name lbessard@42: def RefreshNameSize(self): lbessard@165: self.NameSize = self.Parent.GetTextExtent(self.Name) lbessard@42: lbessard@118: # Refresh the size of text for execution order lbessard@118: def RefreshExecutionOrderSize(self): lbessard@165: self.ExecutionOrderSize = self.Parent.GetTextExtent(str(self.ExecutionOrder)) lbessard@118: etisserant@0: # Refresh the variable bounding box etisserant@0: def RefreshBoundingBox(self): etisserant@0: if self.Type in (OUTPUT, INOUT): etisserant@0: bbx_x = self.Pos.x - CONNECTOR_SIZE etisserant@0: else: etisserant@0: bbx_x = self.Pos.x etisserant@0: if self.Type == INOUT: etisserant@0: bbx_width = self.Size[0] + 2 * CONNECTOR_SIZE etisserant@0: else: etisserant@0: bbx_width = self.Size[0] + CONNECTOR_SIZE laurent@533: bbx_x = min(bbx_x, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2) laurent@533: bbx_width = max(bbx_width, self.NameSize[0]) lbessard@118: bbx_height = self.Size[1] lbessard@118: if self.ExecutionOrder != 0: lbessard@118: bbx_x = min(bbx_x, self.Pos.x + self.Size[0] - self.ExecutionOrderSize[0]) lbessard@118: bbx_width = max(bbx_width, bbx_width + self.Pos.x + self.ExecutionOrderSize[0] - bbx_x - self.Size[0]) lbessard@118: bbx_height = bbx_height + (self.ExecutionOrderSize[1] + 2) lbessard@118: self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width + 1, bbx_height + 1) etisserant@0: etisserant@0: # Refresh the position of the variable connector etisserant@0: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: if scaling is not None: Laurent@717: position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y lbessard@145: else: lbessard@145: position = self.Size[1] / 2 etisserant@0: if self.Input: lbessard@145: self.Input.SetPosition(wx.Point(0, position)) etisserant@0: if self.Output: lbessard@145: self.Output.SetPosition(wx.Point(self.Size[0], position)) lbessard@28: self.RefreshConnected() etisserant@0: etisserant@0: # Refresh the position of wires connected to connector etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: if self.Input: etisserant@0: self.Input.MoveConnected(exclude) etisserant@0: if self.Output: etisserant@0: self.Output.MoveConnected(exclude) etisserant@0: etisserant@0: # Test if point given is on the variable connector lbessard@243: def TestConnector(self, pt, direction = None, exclude=True): lbessard@243: if self.Input and self.Input.TestPoint(pt, direction, exclude): etisserant@0: return self.Input lbessard@243: if self.Output and self.Output.TestPoint(pt, direction, exclude): etisserant@0: return self.Output etisserant@0: return None etisserant@0: etisserant@0: # Returns the block connector that starts with the point given if it exists lbessard@27: def GetConnector(self, position, name = None): lbessard@27: # if a name is given laurent@633: if name is not None: lbessard@27: # Test input and output connector if they exists laurent@633: #if self.Input and name == self.Input.GetName(): laurent@633: # return self.Input lbessard@27: if self.Output and name == self.Output.GetName(): lbessard@27: return self.Output laurent@537: connectors = [] etisserant@0: # Test input connector if it exists etisserant@0: if self.Input: laurent@537: connectors.append(self.Input) etisserant@0: # Test output connector if it exists etisserant@0: if self.Output: laurent@537: connectors.append(self.Output) laurent@537: return self.FindNearestConnector(position, connectors) etisserant@0: etisserant@0: # Returns all the block connectors etisserant@0: def GetConnectors(self): laurent@383: connectors = {"inputs": [], "outputs": []} laurent@383: if self.Input: laurent@383: connectors["inputs"].append(self.Input) laurent@383: if self.Output: laurent@383: connectors["outputs"].append(self.Output) laurent@383: return connectors etisserant@0: etisserant@0: # Changes the negated property of the variable connector if handled etisserant@0: def SetConnectorNegated(self, negated): etisserant@0: handle_type, handle = self.Handle etisserant@0: if handle_type == HANDLE_CONNECTOR: etisserant@0: handle.SetNegated(negated) etisserant@0: self.RefreshModel(False) etisserant@0: lbessard@3: # Changes the variable type lbessard@3: def SetType(self, type, value_type): lbessard@32: if type != self.Type: lbessard@3: self.Type = type lbessard@3: self.Clean() lbessard@3: self.Input = None lbessard@3: self.Output = None lbessard@3: # Create an input or output connector according to variable type lbessard@3: if self.Type != INPUT: lbessard@64: self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True) lbessard@3: if self.Type != OUTPUT: lbessard@64: self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) lbessard@3: self.RefreshConnectors() lbessard@32: elif value_type != self.ValueType: lbessard@32: if self.Input: lbessard@32: self.Input.SetType(value_type) lbessard@32: if self.Output: lbessard@32: self.Output.SetType(value_type) lbessard@32: self.RefreshConnectors() lbessard@3: etisserant@0: # Returns the variable type etisserant@0: def GetType(self): etisserant@0: return self.Type etisserant@0: etisserant@0: # Changes the variable name etisserant@0: def SetName(self, name): etisserant@0: self.Name = name lbessard@42: self.RefreshNameSize() etisserant@0: etisserant@0: # Returns the variable name etisserant@0: def GetName(self): etisserant@0: return self.Name etisserant@0: lbessard@118: # Changes the execution order lbessard@118: def SetExecutionOrder(self, executionOrder): lbessard@118: self.ExecutionOrder = executionOrder lbessard@118: self.RefreshExecutionOrderSize() lbessard@118: lbessard@118: # Returs the execution order lbessard@118: def GetExecutionOrder(self): lbessard@118: return self.ExecutionOrder lbessard@118: Laurent@717: # Changes the element size Laurent@717: def SetSize(self, width, height): Laurent@717: scaling = self.Parent.GetScaling() Laurent@717: min_width, min_height = self.GetMinSize() Laurent@717: if width < min_width: Laurent@717: if self.Type == INPUT: Laurent@717: posx = max(0, self.Pos.x + width - min_width) Laurent@717: if scaling is not None: Laurent@717: posx = round_scaling(posx, scaling[0]) Laurent@717: self.Pos.x = posx Laurent@717: elif self.Type == OUTPUT: Laurent@721: posx = max(0, self.Pos.x + (width - min_width) / 2) Laurent@717: if scaling is not None: Laurent@717: posx = round_scaling(posx, scaling[0]) Laurent@717: self.Pos.x = posx Laurent@717: width = min_width Laurent@717: if scaling is not None: Laurent@717: width = round_scaling(width, scaling[0], 1) Laurent@717: if height < min_height: Laurent@717: posy = max(0, self.Pos.y + (height - min_height) / 2) Laurent@717: if scaling is not None: Laurent@717: posy = round_scaling(posy, scaling[1]) Laurent@717: self.Pos.y = posy Laurent@717: height = min_height Laurent@717: if scaling is not None: Laurent@717: height = round_scaling(height, scaling[1], 1) Laurent@717: Graphic_Element.SetSize(self, width, height) Laurent@717: etisserant@0: # Returns the variable minimum size etisserant@0: def GetMinSize(self): lbessard@42: return self.NameSize[0] + 10, self.NameSize[1] + 10 etisserant@0: lbessard@3: # Method called when a LeftDClick event have been generated lbessard@27: def OnLeftDClick(self, event, dc, scaling): lbessard@3: # Edit the variable properties lbessard@3: self.Parent.EditVariableContent(self) lbessard@3: etisserant@0: # Method called when a RightUp event have been generated lbessard@27: def OnRightUp(self, event, dc, scaling): lbessard@102: self.Parent.PopupDefaultMenu() etisserant@0: etisserant@0: # Refreshes the variable model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshVariableModel(self) etisserant@0: # If variable has moved and variable is not of type OUTPUT, refresh the model etisserant@0: # of wires connected to output connector etisserant@0: if move and self.Type != OUTPUT: etisserant@0: if self.Output: etisserant@0: self.Output.RefreshWires() etisserant@0: laurent@566: # Adds an highlight to the variable laurent@566: def AddHighlight(self, infos, start, end, highlight_type): lbessard@231: if infos[0] == "expression" and start[0] == 0 and end[0] == 0: laurent@566: AddHighlight(self.Highlights, (start, end, highlight_type)) laurent@566: laurent@566: # Removes an highlight from the variable laurent@566: def RemoveHighlight(self, infos, start, end, highlight_type): laurent@566: if infos[0] == "expression": laurent@566: RemoveHighlight(self.Highlights, (start, end, highlight_type)) laurent@566: laurent@566: # Removes all the highlights of one particular type from the variable laurent@566: def ClearHighlight(self, highlight_type=None): laurent@566: ClearHighlights(self.Highlights, highlight_type) lbessard@231: etisserant@0: # Draws variable etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) laurent@563: dc.SetPen(MiterPen(wx.BLACK)) lbessard@64: dc.SetBrush(wx.WHITE_BRUSH) lbessard@213: lbessard@213: if getattr(dc, "printing", False): lbessard@213: name_size = dc.GetTextExtent(self.Name) lbessard@213: executionorder_size = dc.GetTextExtent(str(self.ExecutionOrder)) lbessard@213: else: lbessard@213: name_size = self.NameSize lbessard@213: executionorder_size = self.ExecutionOrderSize lbessard@213: lbessard@231: text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, lbessard@231: self.Pos.y + (self.Size[1] - name_size[1]) / 2) etisserant@0: # Draw a rectangle with the variable size etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: # Draw variable name lbessard@231: dc.DrawText(self.Name, text_pos[0], text_pos[1]) etisserant@0: # Draw connectors etisserant@0: if self.Input: etisserant@0: self.Input.Draw(dc) etisserant@0: if self.Output: etisserant@0: self.Output.Draw(dc) lbessard@118: if self.ExecutionOrder != 0: lbessard@118: # Draw variable execution order lbessard@213: dc.DrawText(str(self.ExecutionOrder), self.Pos.x + self.Size[0] - executionorder_size[0], lbessard@118: self.Pos.y + self.Size[1] + 2) laurent@566: if not getattr(dc, "printing", False): laurent@566: DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) laurent@566: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Function Block Diagram Connector etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a connection etisserant@0: """ etisserant@0: etisserant@0: class FBD_Connector(Graphic_Element): etisserant@0: etisserant@0: # Create a new connection etisserant@0: def __init__(self, parent, type, name, id = None): etisserant@0: Graphic_Element.__init__(self, parent) etisserant@0: self.Type = type etisserant@0: self.Id = id lbessard@118: self.SetName(name) lbessard@64: self.Pos = wx.Point(0, 0) lbessard@64: self.Size = wx.Size(0, 0) laurent@566: self.Highlights = [] etisserant@0: # Create an input or output connector according to connection type etisserant@0: if self.Type == CONNECTOR: lbessard@64: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) lbessard@64: else: lbessard@64: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) etisserant@0: self.RefreshConnectors() lbessard@42: self.RefreshNameSize() etisserant@0: lbessard@249: def Flush(self): lbessard@249: if self.Connector: lbessard@249: self.Connector.Flush() lbessard@249: self.Connector = None etisserant@0: lbessard@144: # Returns the RedrawRect lbessard@144: def GetRedrawRect(self, movex = 0, movey = 0): lbessard@144: rect = Graphic_Element.GetRedrawRect(self, movex, movey) lbessard@144: if movex != 0 or movey != 0: lbessard@144: if self.Connector and self.Connector.IsConnected(): lbessard@144: rect = rect.Union(self.Connector.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: lbessard@112: # Make a clone of this FBD_Connector lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@162: connection = FBD_Connector(parent, self.Type, self.Name, id) lbessard@112: connection.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: connection.SetPosition(pos.x, pos.y) lbessard@283: else: lbessard@283: connection.SetPosition(self.Pos.x, self.Pos.y) lbessard@112: connection.Connector = self.Connector.Clone(connection) lbessard@112: return connection lbessard@112: lbessard@283: def GetConnectorTranslation(self, element): lbessard@283: return {self.Connector : element.Connector} lbessard@283: etisserant@0: # Unconnect connector etisserant@0: def Clean(self): etisserant@0: if self.Connector: lbessard@28: self.Connector.UnConnect(delete = True) etisserant@0: etisserant@0: # Delete this connection by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteConnection(self) etisserant@0: lbessard@42: # Refresh the size of text for name lbessard@42: def RefreshNameSize(self): lbessard@165: self.NameSize = self.Parent.GetTextExtent(self.Name) lbessard@42: etisserant@0: # Refresh the connection bounding box etisserant@0: def RefreshBoundingBox(self): etisserant@0: if self.Type == CONNECTOR: etisserant@0: bbx_x = self.Pos.x - CONNECTOR_SIZE etisserant@0: else: etisserant@0: bbx_x = self.Pos.x etisserant@0: bbx_width = self.Size[0] + CONNECTOR_SIZE lbessard@64: self.BoundingBox = wx.Rect(bbx_x, self.Pos.y, bbx_width, self.Size[1]) etisserant@0: etisserant@0: # Refresh the position of the connection connector etisserant@0: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: if scaling is not None: Laurent@717: position = round_scaling(self.Pos.y + self.Size[1] / 2, scaling[1]) - self.Pos.y lbessard@145: else: lbessard@145: position = self.Size[1] / 2 etisserant@0: if self.Type == CONNECTOR: lbessard@145: self.Connector.SetPosition(wx.Point(0, position)) lbessard@145: else: lbessard@145: self.Connector.SetPosition(wx.Point(self.Size[0], position)) lbessard@28: self.RefreshConnected() etisserant@0: etisserant@0: # Refresh the position of wires connected to connector etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: if self.Connector: etisserant@0: self.Connector.MoveConnected(exclude) etisserant@0: etisserant@0: # Test if point given is on the connection connector lbessard@243: def TestConnector(self, pt, direction = None, exclude=True): lbessard@243: if self.Connector and self.Connector.TestPoint(pt, direction, exclude): etisserant@0: return self.Connector etisserant@0: return None etisserant@0: etisserant@0: # Returns the connection connector lbessard@27: def GetConnector(self, position = None, name = None): etisserant@0: return self.Connector etisserant@0: laurent@383: # Returns all the block connectors laurent@383: def GetConnectors(self): laurent@383: connectors = {"inputs": [], "outputs": []} laurent@383: if self.Type == CONNECTOR: laurent@383: connectors["inputs"].append(self.Connector) laurent@383: else: laurent@383: connectors["outputs"].append(self.Connector) laurent@383: return connectors laurent@383: lbessard@28: # Changes the variable type lbessard@28: def SetType(self, type): lbessard@28: if type != self.Type: lbessard@28: self.Type = type lbessard@28: self.Clean() lbessard@28: # Create an input or output connector according to connection type lbessard@28: if self.Type == CONNECTOR: lbessard@64: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), WEST, onlyone = True) lbessard@28: else: lbessard@64: self.Connector = Connector(self, "", "ANY", wx.Point(0, 0), EAST) lbessard@28: self.RefreshConnectors() lbessard@28: etisserant@0: # Returns the connection type etisserant@0: def GetType(self): etisserant@0: return self.Type etisserant@0: lbessard@145: def GetConnectionResultType(self, connector, connectortype): laurent@388: if self.Type == CONTINUATION: laurent@388: connector = self.Parent.GetConnectorByName(self.Name) laurent@388: if connector is not None: laurent@388: return connector.Connector.GetConnectedType() lbessard@145: return connectortype lbessard@145: etisserant@0: # Changes the connection name etisserant@0: def SetName(self, name): etisserant@0: self.Name = name lbessard@42: self.RefreshNameSize() etisserant@0: etisserant@0: # Returns the connection name etisserant@0: def GetName(self): etisserant@0: return self.Name etisserant@0: Laurent@717: # Changes the element size Laurent@717: def SetSize(self, width, height): Laurent@717: scaling = self.Parent.GetScaling() Laurent@717: min_width, min_height = self.GetMinSize() Laurent@717: if width < min_width: Laurent@717: if self.Type == CONTINUATION: Laurent@717: posx = max(0, self.Pos.x + width - min_width) Laurent@717: if scaling is not None: Laurent@717: posx = round_scaling(posx, scaling[0]) Laurent@717: self.Pos.x = posx Laurent@717: width = min_width Laurent@717: if scaling is not None: Laurent@717: width = round_scaling(width, scaling[0], 1) Laurent@717: if height < min_height: Laurent@717: posy = max(0, self.Pos.y + (height - min_height) / 2) Laurent@717: if scaling is not None: Laurent@717: posy = round_scaling(posy, scaling[1]) Laurent@717: self.Pos.y = posy Laurent@717: height = min_height Laurent@717: if scaling is not None: Laurent@717: height = round_scaling(height, scaling[1], 1) Laurent@717: Graphic_Element.SetSize(self, width, height) Laurent@717: etisserant@0: # Returns the connection minimum size etisserant@0: def GetMinSize(self): lbessard@42: text_width, text_height = self.NameSize etisserant@0: if text_height % 2 == 1: etisserant@0: text_height += 1 etisserant@0: return text_width + text_height + 20, text_height + 10 etisserant@0: lbessard@28: # Method called when a LeftDClick event have been generated lbessard@28: def OnLeftDClick(self, event, dc, scaling): lbessard@28: # Edit the connection properties lbessard@28: self.Parent.EditConnectionContent(self) lbessard@28: etisserant@0: # Method called when a RightUp event have been generated lbessard@27: def OnRightUp(self, event, dc, scaling): etisserant@0: # Popup the default menu etisserant@0: self.Parent.PopupDefaultMenu() etisserant@0: etisserant@0: # Refreshes the connection model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshConnectionModel(self) etisserant@0: # If connection has moved and connection is of type CONTINUATION, refresh etisserant@0: # the model of wires connected to connector etisserant@0: if move and self.Type == CONTINUATION: etisserant@0: if self.Connector: etisserant@0: self.Connector.RefreshWires() etisserant@0: laurent@566: # Adds an highlight to the connection laurent@566: def AddHighlight(self, infos, start, end, highlight_type): laurent@566: if infos[0] == "name" and start[0] == 0 and end[0] == 0: laurent@566: AddHighlight(self.Highlights, (start, end, highlight_type)) laurent@566: laurent@566: # Removes an highlight from the connection laurent@566: def RemoveHighlight(self, infos, start, end, highlight_type): laurent@566: if infos[0] == "name": laurent@566: RemoveHighlight(self.Highlights, (start, end, highlight_type)) laurent@566: laurent@566: # Removes all the highlights of one particular type from the connection laurent@566: def ClearHighlight(self, highlight_type=None): laurent@566: ClearHighlights(self.Highlights, highlight_type) laurent@566: etisserant@0: # Draws connection etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) laurent@563: dc.SetPen(MiterPen(wx.BLACK)) lbessard@64: dc.SetBrush(wx.WHITE_BRUSH) lbessard@213: lbessard@213: if getattr(dc, "printing", False): lbessard@213: name_size = dc.GetTextExtent(self.Name) lbessard@213: else: lbessard@213: name_size = self.NameSize lbessard@213: laurent@379: # Draw a rectangle with the connection size with arrows inside etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) lbessard@213: arrowsize = min(self.Size[1] / 2, (self.Size[0] - name_size[0] - 10) / 2) etisserant@0: dc.DrawLine(self.Pos.x, self.Pos.y, self.Pos.x + arrowsize, etisserant@0: self.Pos.y + self.Size[1] / 2) etisserant@0: dc.DrawLine(self.Pos.x + arrowsize, self.Pos.y + self.Size[1] / 2, etisserant@0: self.Pos.x, self.Pos.y + self.Size[1]) etisserant@0: dc.DrawLine(self.Pos.x + self.Size[0] - arrowsize, self.Pos.y, etisserant@0: self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2) etisserant@0: dc.DrawLine(self.Pos.x + self.Size[0], self.Pos.y + self.Size[1] / 2, etisserant@0: self.Pos.x + self.Size[0] - arrowsize, self.Pos.y + self.Size[1]) lbessard@118: # Draw connection name laurent@566: text_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, laurent@566: self.Pos.y + (self.Size[1] - name_size[1]) / 2) laurent@566: dc.DrawText(self.Name, text_pos[0], text_pos[1]) etisserant@0: # Draw connector etisserant@0: if self.Connector: etisserant@0: self.Connector.Draw(dc) lbessard@140: laurent@566: if not getattr(dc, "printing", False): laurent@566: DrawHighlightedText(dc, self.Name, self.Highlights, text_pos[0], text_pos[1]) laurent@566: