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: def GetWireSize(block): etisserant@0: if isinstance(block, SFC_Step): etisserant@0: return SFC_WIRE_MIN_SIZE + block.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] etisserant@0: else: etisserant@0: return SFC_WIRE_MIN_SIZE etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Sequencial Function Chart Step etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a step etisserant@0: """ etisserant@0: etisserant@0: class SFC_Step(Graphic_Element): etisserant@0: etisserant@0: # Create a new step etisserant@0: def __init__(self, parent, name, initial = False, id = None): etisserant@0: Graphic_Element.__init__(self, parent) lbessard@213: self.SetName(name) etisserant@0: self.Initial = initial etisserant@0: self.Id = id lbessard@231: self.Error = None lbessard@64: self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) etisserant@0: # Create an input and output connector etisserant@0: if not self.Initial: lbessard@108: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) etisserant@0: else: etisserant@0: self.Input = None etisserant@0: self.Output = None etisserant@0: self.Action = None lbessard@253: self.Value = None lbessard@253: self.PreviousValue = None lbessard@253: self.PreviousSpreading = False etisserant@0: 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 lbessard@249: if self.Output is not None: lbessard@249: self.Action.Flush() lbessard@249: self.Action = None etisserant@0: lbessard@253: def SetValue(self, value): lbessard@253: self.PreviousValue = self.Value lbessard@253: self.Value = value lbessard@253: if self.Value != self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: self.SpreadCurrent() lbessard@253: lbessard@253: def SpreadCurrent(self): lbessard@253: if self.Parent.Debug: lbessard@253: spreading = self.Value lbessard@253: if spreading and not self.PreviousSpreading: lbessard@253: self.Output.SpreadCurrent(True) lbessard@253: if self.Action is not None: lbessard@253: self.Action.SpreadCurrent(True) lbessard@253: elif not spreading and self.PreviousSpreading: lbessard@253: self.Output.SpreadCurrent(False) lbessard@253: if self.Action is not None: lbessard@253: self.Action.SpreadCurrent(False) lbessard@253: self.PreviousSpreading = spreading lbessard@253: lbessard@112: # Make a clone of this SFC_Step lbessard@162: def Clone(self, parent, id = None, name = "Step", pos = None): lbessard@162: step = SFC_Step(parent, name, self.Initial, id) lbessard@112: step.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: step.SetPosition(pos.x, pos.y) lbessard@144: if self.Input: lbessard@144: step.Input = self.Input.Clone(step) lbessard@144: if self.Output: lbessard@144: step.Output = self.Output.Clone(step) lbessard@144: if self.Action: lbessard@144: step.Action = self.Action.Clone(step) lbessard@112: return step lbessard@112: 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 self.Input: lbessard@144: rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) lbessard@144: if self.Output: lbessard@144: rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) lbessard@144: if self.Action: lbessard@144: rect = rect.Union(self.Action.GetRedrawRect(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: if self.Action and self.Action.IsConnected(): lbessard@144: rect = rect.Union(self.Action.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: etisserant@0: # Delete this step by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteStep(self) etisserant@0: etisserant@0: # Unconnect input and output etisserant@0: def Clean(self): etisserant@0: if self.Input: lbessard@64: self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: if self.Output: lbessard@64: self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: if self.Action: lbessard@64: self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: lbessard@213: # Refresh the size of text for name lbessard@213: def RefreshNameSize(self): lbessard@213: self.NameSize = self.Parent.GetTextExtent(self.Name) lbessard@213: etisserant@0: # Add output connector to step lbessard@71: def AddInput(self): lbessard@71: if not self.Input: lbessard@108: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) lbessard@71: self.RefreshBoundingBox() lbessard@71: lbessard@71: # Remove output connector from step lbessard@71: def RemoveInput(self): lbessard@71: if self.Input: lbessard@154: self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) lbessard@71: self.Input = None lbessard@71: self.RefreshBoundingBox() lbessard@71: lbessard@71: # Add output connector to step etisserant@0: def AddOutput(self): etisserant@0: if not self.Output: lbessard@145: self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Remove output connector from step etisserant@0: def RemoveOutput(self): etisserant@0: if self.Output: lbessard@154: self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: self.Output = None etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Add action connector to step etisserant@0: def AddAction(self): etisserant@0: if not self.Action: lbessard@145: self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST, onlyone = True) etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Remove action connector from step etisserant@0: def RemoveAction(self): etisserant@0: if self.Action: lbessard@154: self.Action.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: self.Action = None etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Refresh the step bounding box etisserant@0: def RefreshBoundingBox(self): etisserant@0: # Calculate the bounding box size etisserant@0: if self.Action: etisserant@0: bbx_width = self.Size[0] + CONNECTOR_SIZE etisserant@0: else: etisserant@0: bbx_width = self.Size[0] etisserant@0: if self.Initial: etisserant@0: bbx_y = self.Pos.y etisserant@0: bbx_height = self.Size[1] etisserant@0: if self.Output: etisserant@0: bbx_height += CONNECTOR_SIZE etisserant@0: else: etisserant@0: bbx_y = self.Pos.y - CONNECTOR_SIZE etisserant@0: bbx_height = self.Size[1] + CONNECTOR_SIZE etisserant@0: if self.Output: etisserant@0: bbx_height += CONNECTOR_SIZE lbessard@64: #self.BoundingBox = wx.Rect(self.Pos.x, bbx_y, bbx_width + 1, bbx_height + 1) lbessard@64: self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: etisserant@0: # Refresh the positions of the step connectors etisserant@0: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: horizontal_pos = self.Size[0] / 2 lbessard@145: vertical_pos = self.Size[1] / 2 lbessard@145: if scaling is not None: lbessard@145: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@145: vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y etisserant@0: # Update input position if it exists etisserant@0: if self.Input: lbessard@145: self.Input.SetPosition(wx.Point(horizontal_pos, 0)) etisserant@0: # Update output position etisserant@0: if self.Output: lbessard@145: self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) etisserant@0: # Update action position if it exists etisserant@0: if self.Action: lbessard@145: self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos)) etisserant@0: self.RefreshConnected() etisserant@0: etisserant@0: # Refresh the position of wires connected to step 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: if self.Action: etisserant@0: self.Action.MoveConnected(exclude) etisserant@0: etisserant@0: # Returns the step 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 lbessard@27: if name: lbessard@27: # Test input, output and action connector if they exists lbessard@27: if self.Input and name == self.Input.GetName(): lbessard@27: return self.Input lbessard@27: if self.Output and name == self.Output.GetName(): lbessard@27: return self.Output lbessard@27: if self.Action and name == self.Action.GetName(): lbessard@27: return self.Action etisserant@0: # Test input connector if it exists etisserant@0: if self.Input: etisserant@0: input_pos = self.Input.GetRelPosition() etisserant@0: if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: etisserant@0: return self.Input etisserant@0: # Test output connector if it exists etisserant@0: if self.Output: etisserant@0: output_pos = self.Output.GetRelPosition() etisserant@0: if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: etisserant@0: return self.Output etisserant@0: # Test action connector if it exists etisserant@0: if self.Action: etisserant@0: action_pos = self.Action.GetRelPosition() etisserant@0: if position.x == self.Pos.x + action_pos.x and position.y == self.Pos.y + action_pos.y: etisserant@0: return self.Action etisserant@0: return None etisserant@0: etisserant@0: # Returns input and output step connectors etisserant@0: def GetConnectors(self): etisserant@0: return {"input":self.Input,"output":self.Output,"action":self.Action} etisserant@0: etisserant@0: # Test if point given is on step input or output connector lbessard@243: def TestConnector(self, pt, direction = None, exclude=True): etisserant@0: # Test input connector if it exists lbessard@243: if self.Input and self.Input.TestPoint(pt, direction, exclude): etisserant@0: return self.Input etisserant@0: # Test output connector lbessard@243: if self.Output and self.Output.TestPoint(pt, direction, exclude): etisserant@0: return self.Output lbessard@108: # Test action connector lbessard@243: if self.Action and self.Action.TestPoint(pt, direction, exclude): lbessard@108: return self.Action etisserant@0: return None etisserant@0: etisserant@0: # Changes the step name etisserant@0: def SetName(self, name): etisserant@0: self.Name = name lbessard@213: self.RefreshNameSize() etisserant@0: etisserant@0: # Returns the step name etisserant@0: def GetName(self): etisserant@0: return self.Name etisserant@0: etisserant@0: # Returns the step initial property etisserant@0: def GetInitial(self): etisserant@0: return self.Initial etisserant@0: etisserant@0: # Returns the connector connected to input etisserant@0: def GetPreviousConnector(self): etisserant@0: if self.Input: etisserant@0: wires = self.Input.GetWires() etisserant@0: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Input) etisserant@0: return None etisserant@0: etisserant@0: # Returns the connector connected to output etisserant@0: def GetNextConnector(self): etisserant@0: if self.Output: etisserant@0: wires = self.Output.GetWires() etisserant@0: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Output) etisserant@0: return None etisserant@0: etisserant@0: # Returns the connector connected to action etisserant@0: def GetActionConnector(self): etisserant@0: if self.Action: etisserant@0: wires = self.Action.GetWires() etisserant@0: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Action) etisserant@0: return None etisserant@0: etisserant@0: # Returns the number of action line etisserant@0: def GetActionExtraLineNumber(self): etisserant@0: if self.Action: etisserant@0: wires = self.Action.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return 0 lbessard@145: action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() etisserant@0: return max(0, action_block.GetLineNumber() - 1) etisserant@0: return 0 etisserant@0: etisserant@0: # Returns the step minimum size etisserant@0: def GetMinSize(self): lbessard@165: text_width, text_height = self.Parent.GetTextExtent(self.Name) etisserant@0: if self.Initial: etisserant@0: return text_width + 14, text_height + 14 etisserant@0: else: etisserant@0: return text_width + 10, text_height + 10 etisserant@0: etisserant@0: # Updates the step size etisserant@0: def UpdateSize(self, width, height): etisserant@0: diffx = self.Size.GetWidth() / 2 - width / 2 etisserant@0: diffy = height - self.Size.GetHeight() etisserant@0: self.Move(diffx, 0) etisserant@0: Graphic_Element.SetSize(self, width, height) lbessard@108: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@108: self.RefreshConnected() lbessard@108: else: lbessard@108: self.RefreshOutputPosition((0, diffy)) etisserant@0: etisserant@0: # Align input element with this step etisserant@0: def RefreshInputPosition(self): etisserant@0: if self.Input: etisserant@0: current_pos = self.Input.GetPosition(False) etisserant@0: input = self.GetPreviousConnector() etisserant@0: if input: etisserant@0: input_pos = input.GetPosition(False) etisserant@0: diffx = current_pos.x - input_pos.x etisserant@0: input_block = input.GetParentBlock() etisserant@0: if isinstance(input_block, SFC_Divergence): etisserant@0: input_block.MoveConnector(input, diffx) etisserant@0: else: etisserant@0: if isinstance(input_block, SFC_Step): etisserant@0: input_block.MoveActionBlock((diffx, 0)) etisserant@0: input_block.Move(diffx, 0) etisserant@0: input_block.RefreshInputPosition() etisserant@0: etisserant@0: # Align output element with this step etisserant@0: def RefreshOutputPosition(self, move = None): etisserant@0: if self.Output: etisserant@0: wires = self.Output.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: current_pos = self.Output.GetPosition(False) lbessard@145: output = wires[0][0].GetOtherConnected(self.Output) etisserant@0: output_pos = output.GetPosition(False) etisserant@0: diffx = current_pos.x - output_pos.x etisserant@0: output_block = output.GetParentBlock() etisserant@0: wire_size = SFC_WIRE_MIN_SIZE + self.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] etisserant@0: diffy = wire_size - output_pos.y + current_pos.y etisserant@0: if diffy != 0: etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock((diffx, diffy)) lbessard@64: wires[0][0].SetPoints([wx.Point(current_pos.x, current_pos.y + wire_size), lbessard@64: wx.Point(current_pos.x, current_pos.y)]) etisserant@0: if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: etisserant@0: output_block.Move(diffx, diffy, self.Parent.Wires) etisserant@0: output_block.RefreshOutputPosition((diffx, diffy)) etisserant@0: else: etisserant@0: output_block.RefreshPosition() etisserant@0: elif move: etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock(move) etisserant@0: wires[0][0].Move(move[0], move[1], True) etisserant@0: if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: etisserant@0: output_block.Move(move[0], move[1], self.Parent.Wires) etisserant@0: output_block.RefreshOutputPosition(move) etisserant@0: else: etisserant@0: output_block.RefreshPosition() etisserant@0: elif isinstance(output_block, SFC_Divergence): etisserant@0: output_block.MoveConnector(output, diffx) etisserant@0: else: etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock((diffx, 0)) etisserant@0: output_block.Move(diffx, 0) etisserant@0: output_block.RefreshOutputPosition() etisserant@0: etisserant@0: # Refresh action element with this step etisserant@0: def MoveActionBlock(self, move): etisserant@0: if self.Action: etisserant@0: wires = self.Action.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return lbessard@145: action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock() etisserant@0: action_block.Move(move[0], move[1], self.Parent.Wires) etisserant@0: wires[0][0].Move(move[0], move[1], True) etisserant@0: etisserant@0: # Resize the divergence from position and size given etisserant@0: def Resize(self, x, y, width, height): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.UpdateSize(width, height) lbessard@27: else: lbessard@27: Graphic_Element.Resize(self, x, y, width, height) etisserant@0: etisserant@0: # Method called when a LeftDClick event have been generated lbessard@42: def OnLeftDClick(self, event, dc, scaling): etisserant@0: # Edit the step properties etisserant@0: self.Parent.EditStepContent(self) etisserant@0: etisserant@0: # Method called when a RightUp event have been generated lbessard@27: def OnRightUp(self, event, dc, scaling): etisserant@0: # Popup the menu with special items for a step etisserant@0: self.Parent.PopupDefaultMenu() etisserant@0: etisserant@0: # Refreshes the step state according to move defined and handle selected lbessard@165: def ProcessDragging(self, movex, movey, centered, scaling): etisserant@0: handle_type, handle = self.Handle etisserant@0: if handle_type == HANDLE_MOVE: lbessard@138: movex = max(-self.BoundingBox.x, movex) lbessard@138: movey = max(-self.BoundingBox.y, movey) lbessard@145: if scaling is not None: lbessard@145: movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@145: movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y etisserant@0: action_block = None lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: self.Move(movex, movey) lbessard@27: self.RefreshConnected() lbessard@138: return movex, movey lbessard@27: elif self.Initial: etisserant@0: self.MoveActionBlock((movex, movey)) etisserant@0: self.Move(movex, movey, self.Parent.Wires) etisserant@0: self.RefreshOutputPosition((movex, movey)) lbessard@138: return movex, movey etisserant@0: else: etisserant@0: self.MoveActionBlock((movex, 0)) etisserant@0: self.Move(movex, 0) etisserant@0: self.RefreshInputPosition() etisserant@0: self.RefreshOutputPosition() lbessard@138: return movex, 0 lbessard@110: else: lbessard@165: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) etisserant@0: etisserant@0: # Refresh input element model etisserant@0: def RefreshInputModel(self): etisserant@0: if self.Input: etisserant@0: input = self.GetPreviousConnector() etisserant@0: if input: etisserant@0: input_block = input.GetParentBlock() etisserant@0: input_block.RefreshModel(False) etisserant@0: if not isinstance(input_block, SFC_Divergence): etisserant@0: input_block.RefreshInputModel() etisserant@0: etisserant@0: # Refresh output element model etisserant@0: def RefreshOutputModel(self, move=False): etisserant@0: if self.Output: etisserant@0: output = self.GetNextConnector() etisserant@0: if output: etisserant@0: output_block = output.GetParentBlock() etisserant@0: output_block.RefreshModel(False) etisserant@0: if not isinstance(output_block, SFC_Divergence) or move: etisserant@0: output_block.RefreshOutputModel(move) etisserant@0: etisserant@0: # Refreshes the step model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshStepModel(self) etisserant@0: if self.Action: etisserant@0: action = self.GetActionConnector() etisserant@0: if action: etisserant@0: action_block = action.GetParentBlock() etisserant@0: action_block.RefreshModel(False) etisserant@0: # If step has moved, refresh the model of wires connected to output etisserant@0: if move: lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.RefreshInputModel() lbessard@27: self.RefreshOutputModel(self.Initial) lbessard@27: elif self.Output: lbessard@27: self.Output.RefreshWires() etisserant@0: lbessard@231: def AddError(self, infos, start, end): lbessard@231: if infos[0] == "name" and start[0] == 0 and end[0] == 0: lbessard@231: self.Error = (start[1], end[1]) lbessard@231: etisserant@0: # Draws step etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@253: if self.Value: lbessard@253: dc.SetPen(wx.GREEN_PEN) lbessard@253: else: lbessard@253: dc.SetPen(wx.BLACK_PEN) 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: etisserant@0: # Draw two rectangles for representing the step etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: if self.Initial: etisserant@0: dc.DrawRectangle(self.Pos.x + 2, self.Pos.y + 2, self.Size[0] - 3, self.Size[1] - 3) etisserant@0: # Draw step name lbessard@231: name_pos = (self.Pos.x + (self.Size[0] - name_size[0]) / 2, lbessard@213: self.Pos.y + (self.Size[1] - name_size[1]) / 2) lbessard@231: dc.DrawText(self.Name, name_pos[0], name_pos[1]) etisserant@0: # Draw input and output connectors etisserant@0: if self.Input: etisserant@0: self.Input.Draw(dc) etisserant@0: if self.Output: etisserant@0: self.Output.Draw(dc) etisserant@0: if self.Action: etisserant@0: self.Action.Draw(dc) lbessard@231: if self.Error is not None: lbessard@231: HighlightErrorZone(dc, name_pos[0], name_pos[1], name_size[0], name_size[1]) lbessard@140: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Sequencial Function Chart Transition etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a transition etisserant@0: """ etisserant@0: etisserant@0: class SFC_Transition(Graphic_Element): etisserant@0: etisserant@0: # Create a new transition lbessard@80: def __init__(self, parent, type = "reference", condition = None, priority = 0, id = None): etisserant@0: Graphic_Element.__init__(self, parent) lbessard@64: self.Type = None etisserant@0: self.Id = id lbessard@80: self.Priority = 0 lbessard@64: self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) etisserant@0: # Create an input and output connector lbessard@145: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) lbessard@145: self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True) lbessard@64: self.SetType(type, condition) lbessard@80: self.SetPriority(priority) lbessard@231: self.Errors = {} lbessard@253: self.Value = None lbessard@253: self.PreviousValue = None lbessard@253: self.PreviousSpreading = False etisserant@0: 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 lbessard@249: if self.Type == "connection" and self.Condition is not None: lbessard@249: self.Condition.Flush() lbessard@64: self.Condition = None etisserant@0: lbessard@253: def SetValue(self, value): lbessard@253: self.PreviousValue = self.Value lbessard@253: self.Value = value lbessard@253: if self.Value != self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: self.SpreadCurrent() lbessard@253: lbessard@253: def SpreadCurrent(self): lbessard@253: if self.Parent.Debug: lbessard@253: if self.Value is None: lbessard@253: self.Value = False lbessard@253: spreading = self.Input.ReceivingCurrent() & self.Value lbessard@253: if spreading and not self.PreviousSpreading: lbessard@253: self.Output.SpreadCurrent(True) lbessard@253: elif not spreading and self.PreviousSpreading: lbessard@253: self.Output.SpreadCurrent(False) lbessard@253: self.PreviousSpreading = spreading lbessard@253: lbessard@112: # Make a clone of this SFC_Transition lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@162: transition = SFC_Transition(parent, self.Type, self.Condition, self.Priority, id) lbessard@112: transition.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: transition.SetPosition(pos.x, pos.y) lbessard@112: transition.Input = self.Input.Clone(transition) lbessard@112: transition.Output = self.Output.Clone(transition) lbessard@172: if self.Type == "connection": lbessard@172: transition.Condition = self.Condition.Clone(transition) lbessard@112: return transition lbessard@112: 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: rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) lbessard@144: rect = rect.Union(self.Output.GetRedrawRect(movex, movey)) lbessard@144: if movex != 0 or movey != 0: lbessard@144: if self.Input.IsConnected(): lbessard@144: rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) lbessard@144: if self.Output.IsConnected(): lbessard@144: rect = rect.Union(self.Output.GetConnectedRedrawRect(movex, movey)) etisserant@175: if self.Type == "connection" and self.Condition.IsConnected(): lbessard@172: rect = rect.Union(self.Condition.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: etisserant@0: # Forbids to change the transition size etisserant@0: def SetSize(self, width, height): lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: Graphic_Element.SetSize(self, width, height) etisserant@0: etisserant@0: # Forbids to resize the transition etisserant@0: def Resize(self, x, y, width, height): lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: Graphic_Element.Resize(self, x, y, width, height) etisserant@0: lbessard@64: # Refresh the size of text for name lbessard@64: def RefreshConditionSize(self): lbessard@64: if self.Type != "connection": lbessard@64: if self.Condition != "": lbessard@165: self.ConditionSize = self.Parent.GetTextExtent(self.Condition) lbessard@64: else: lbessard@165: self.ConditionSize = self.Parent.GetTextExtent("Transition") lbessard@64: lbessard@80: # Refresh the size of text for name lbessard@80: def RefreshPrioritySize(self): lbessard@80: if self.Priority != "": lbessard@165: self.PrioritySize = self.Parent.GetTextExtent(str(self.Priority)) lbessard@80: else: lbessard@80: self.PrioritySize = None lbessard@80: etisserant@0: # Delete this transition by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteTransition(self) etisserant@0: etisserant@0: # Unconnect input and output etisserant@0: def Clean(self): lbessard@64: self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) lbessard@64: self.Output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) lbessard@64: if self.Type == "connection": lbessard@64: self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: etisserant@0: # Refresh the transition bounding box etisserant@0: def RefreshBoundingBox(self): lbessard@80: bbx_x, bbx_y, bbx_width, bbx_height = self.Pos.x, self.Pos.y, self.Size[0], self.Size[1] lbessard@80: if self.Priority != 0: lbessard@80: bbx_y = self.Pos.y - self.PrioritySize[1] - 2 lbessard@80: bbx_width = max(self.Size[0], self.PrioritySize[0]) lbessard@80: bbx_height = self.Size[1] + self.PrioritySize[1] + 2 lbessard@64: if self.Type == "connection": lbessard@64: bbx_x = self.Pos.x - CONNECTOR_SIZE lbessard@80: bbx_width = bbx_width + CONNECTOR_SIZE lbessard@64: else: lbessard@64: text_width, text_height = self.ConditionSize lbessard@64: # Calculate the bounding box size lbessard@80: bbx_width = max(bbx_width, self.Size[0] + 5 + text_width) lbessard@80: bbx_y = min(bbx_y, self.Pos.y - max(0, (text_height - self.Size[1]) / 2)) lbessard@80: bbx_height = max(bbx_height, self.Pos.y - bbx_y + (self.Size[1] + text_height) / 2) lbessard@64: self.BoundingBox = wx.Rect(bbx_x, bbx_y, bbx_width + 1, bbx_height + 1) etisserant@0: etisserant@0: # Returns the connector connected to input etisserant@0: def GetPreviousConnector(self): etisserant@0: wires = self.Input.GetWires() etisserant@0: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Input) etisserant@0: return None etisserant@0: etisserant@0: # Returns the connector connected to output etisserant@0: def GetNextConnector(self): etisserant@0: wires = self.Output.GetWires() etisserant@0: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Output) etisserant@0: return None etisserant@0: etisserant@0: # Refresh the positions of the transition connectors etisserant@0: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: horizontal_pos = self.Size[0] / 2 lbessard@145: vertical_pos = self.Size[1] / 2 lbessard@145: if scaling is not None: lbessard@145: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@145: vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y etisserant@0: # Update input position lbessard@145: self.Input.SetPosition(wx.Point(horizontal_pos, 0)) etisserant@0: # Update output position lbessard@145: self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1])) lbessard@64: if self.Type == "connection": lbessard@145: self.Condition.SetPosition(wx.Point(0, vertical_pos)) etisserant@0: self.RefreshConnected() etisserant@0: etisserant@0: # Refresh the position of the wires connected to transition etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: self.Input.MoveConnected(exclude) etisserant@0: self.Output.MoveConnected(exclude) lbessard@64: if self.Type == "connection": lbessard@64: self.Condition.MoveConnected(exclude) etisserant@0: etisserant@0: # Returns the transition 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 lbessard@27: if name: lbessard@27: # Test input and output connector lbessard@27: if name == self.Input.GetName(): lbessard@27: return self.Input lbessard@27: if name == self.Output.GetName(): lbessard@27: return self.Output lbessard@64: if self.Type == "connection" and name == self.Condition.GetName(): lbessard@64: return self.Condition etisserant@0: # Test input connector etisserant@0: input_pos = self.Input.GetRelPosition() etisserant@0: if position.x == self.Pos.x + input_pos.x and position.y == self.Pos.y + input_pos.y: etisserant@0: return self.Input etisserant@0: # Test output connector etisserant@0: output_pos = self.Output.GetRelPosition() etisserant@0: if position.x == self.Pos.x + output_pos.x and position.y == self.Pos.y + output_pos.y: etisserant@0: return self.Output lbessard@64: if self.Type == "connection": lbessard@64: # Test condition connector lbessard@64: condition_pos = self.Condition.GetRelPosition() lbessard@64: if position.x == self.Pos.x + condition_pos.x and position.y == self.Pos.y + condition_pos.y: lbessard@64: return self.Condition etisserant@0: return None etisserant@0: etisserant@0: # Returns input and output transition connectors etisserant@0: def GetConnectors(self): lbessard@64: connectors = {"input":self.Input,"output":self.Output} lbessard@64: if self.Type == "connection": lbessard@64: connectors["connection"] = self.Condition lbessard@64: return connectors etisserant@0: etisserant@0: # Test if point given is on transition input or output connector lbessard@243: def TestConnector(self, pt, direction = None, exclude=True): etisserant@0: # Test input connector lbessard@243: if self.Input.TestPoint(pt, direction, exclude): etisserant@0: return self.Input etisserant@0: # Test output connector lbessard@243: if self.Output.TestPoint(pt, direction, exclude): etisserant@0: return self.Output lbessard@64: # Test condition connector lbessard@243: if self.Type == "connection" and self.Condition.TestPoint(pt, direction, exclude): lbessard@64: return self.Condition etisserant@0: return None etisserant@0: etisserant@0: # Changes the transition type lbessard@64: def SetType(self, type, condition = None): lbessard@64: if self.Type != type: lbessard@64: if self.Type == "connection": lbessard@154: self.Condition.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) lbessard@64: self.Type = type lbessard@64: if type == "connection": lbessard@64: self.Condition = Connector(self, "", "BOOL", wx.Point(0, self.Size[1] / 2), WEST) lbessard@64: else: lbessard@64: if condition == None: lbessard@64: condition = "" lbessard@64: self.Condition = condition lbessard@64: self.RefreshConditionSize() lbessard@64: elif self.Type != "connection": lbessard@64: if condition == None: lbessard@64: condition = "" lbessard@64: self.Condition = condition lbessard@64: self.RefreshConditionSize() lbessard@64: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Returns the transition type etisserant@0: def GetType(self): etisserant@0: return self.Type etisserant@0: lbessard@80: # Changes the transition priority lbessard@80: def SetPriority(self, priority): lbessard@80: self.Priority = priority lbessard@80: self.RefreshPrioritySize() lbessard@80: self.RefreshBoundingBox() lbessard@80: lbessard@80: # Returns the transition type lbessard@80: def GetPriority(self): lbessard@80: return self.Priority lbessard@80: etisserant@0: # Returns the transition condition etisserant@0: def GetCondition(self): lbessard@64: if self.Type != "connection": lbessard@64: return self.Condition lbessard@64: return None etisserant@0: etisserant@0: # Returns the transition minimum size etisserant@0: def GetMinSize(self): etisserant@0: return SFC_TRANSITION_SIZE etisserant@0: etisserant@0: # Align input element with this step etisserant@0: def RefreshInputPosition(self): etisserant@0: wires = self.Input.GetWires() etisserant@0: current_pos = self.Input.GetPosition(False) etisserant@0: input = self.GetPreviousConnector() etisserant@0: if input: etisserant@0: input_pos = input.GetPosition(False) etisserant@0: diffx = current_pos.x - input_pos.x etisserant@0: input_block = input.GetParentBlock() etisserant@0: if isinstance(input_block, SFC_Divergence): etisserant@0: input_block.MoveConnector(input, diffx) etisserant@0: else: etisserant@0: if isinstance(input_block, SFC_Step): etisserant@0: input_block.MoveActionBlock((diffx, 0)) etisserant@0: input_block.Move(diffx, 0) etisserant@0: input_block.RefreshInputPosition() etisserant@0: etisserant@0: # Align output element with this step etisserant@0: def RefreshOutputPosition(self, move = None): etisserant@0: wires = self.Output.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: current_pos = self.Output.GetPosition(False) lbessard@145: output = wires[0][0].GetOtherConnected(self.Output) etisserant@0: output_pos = output.GetPosition(False) etisserant@0: diffx = current_pos.x - output_pos.x etisserant@0: output_block = output.GetParentBlock() etisserant@0: if move: etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock(move) etisserant@0: wires[0][0].Move(move[0], move[1], True) etisserant@0: if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: etisserant@0: output_block.Move(move[0], move[1], self.Parent.Wires) etisserant@0: output_block.RefreshOutputPosition(move) etisserant@0: else: etisserant@0: output_block.RefreshPosition() etisserant@0: elif isinstance(output_block, SFC_Divergence): etisserant@0: output_block.MoveConnector(output, diffx) etisserant@0: else: etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock((diffx, 0)) etisserant@0: output_block.Move(diffx, 0) etisserant@0: output_block.RefreshOutputPosition() lbessard@27: etisserant@0: # Method called when a LeftDClick event have been generated lbessard@27: def OnLeftDClick(self, event, dc, scaling): etisserant@0: # Edit the transition properties etisserant@0: self.Parent.EditTransitionContent(self) etisserant@0: etisserant@0: # Method called when a RightUp event have been generated lbessard@27: def OnRightUp(self, event, dc, scaling): etisserant@0: # Popup the menu with special items for a step etisserant@0: self.Parent.PopupDefaultMenu() etisserant@0: etisserant@0: # Refreshes the transition state according to move defined and handle selected lbessard@165: def ProcessDragging(self, movex, movey, centered, scaling): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@138: movex = max(-self.BoundingBox.x, movex) lbessard@145: if scaling is not None: lbessard@145: movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@27: self.Move(movex, 0) lbessard@27: self.RefreshInputPosition() lbessard@27: self.RefreshOutputPosition() lbessard@138: return movex, 0 lbessard@110: else: etisserant@175: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling, width_fac = 2, height_fac = 2) etisserant@0: etisserant@0: # Refresh input element model etisserant@0: def RefreshInputModel(self): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: input = self.GetPreviousConnector() lbessard@27: if input: lbessard@27: input_block = input.GetParentBlock() lbessard@27: input_block.RefreshModel(False) lbessard@27: if not isinstance(input_block, SFC_Divergence): lbessard@27: input_block.RefreshInputModel() etisserant@0: etisserant@0: # Refresh output element model etisserant@0: def RefreshOutputModel(self, move=False): etisserant@0: output = self.GetNextConnector() etisserant@0: if output: etisserant@0: output_block = output.GetParentBlock() etisserant@0: output_block.RefreshModel(False) etisserant@0: if not isinstance(output_block, SFC_Divergence) or move: etisserant@0: output_block.RefreshOutputModel(move) etisserant@0: etisserant@0: # Refreshes the transition model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshTransitionModel(self) etisserant@0: # If transition has moved, refresh the model of wires connected to output etisserant@0: if move: lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.RefreshInputModel() lbessard@27: self.RefreshOutputModel() lbessard@27: else: lbessard@27: self.Output.RefreshWires() etisserant@0: lbessard@231: def AddError(self, infos, start, end): lbessard@231: if infos[0] == "priority" and start[0] == 0 and start[1] == 0: lbessard@231: self.Errors[infos[0]] = (start[1], end[1]) lbessard@231: elif infos[0] == "inline": lbessard@231: if infos[0] not in self.Errors: lbessard@231: self.Errors[infos[0]] = [] lbessard@231: self.Errors[infos[0]].append((start[1], end[1])) lbessard@231: else: lbessard@231: pass lbessard@231: etisserant@0: # Draws transition etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@253: if self.Value: lbessard@253: dc.SetPen(wx.GREEN_PEN) lbessard@253: dc.SetBrush(wx.GREEN_BRUSH) lbessard@253: else: lbessard@253: dc.SetPen(wx.BLACK_PEN) lbessard@253: dc.SetBrush(wx.BLACK_BRUSH) lbessard@213: lbessard@213: if getattr(dc, "printing", False): lbessard@213: if self.Type != "connection": lbessard@213: condition_size = dc.GetTextExtent(self.Condition) lbessard@213: if self.Priority != 0: lbessard@213: priority_size = dc.GetTextExtent(str(self.Priority)) lbessard@213: else: lbessard@213: if self.Type != "connection": lbessard@213: condition_size = self.ConditionSize lbessard@213: if self.Priority != 0: lbessard@213: priority_size = self.PrioritySize lbessard@213: etisserant@0: # Draw plain rectangle for representing the transition etisserant@175: dc.DrawRectangle(self.Pos.x, etisserant@175: self.Pos.y + (self.Size[1] - SFC_TRANSITION_SIZE[1])/2, etisserant@175: self.Size[0] + 1, etisserant@175: SFC_TRANSITION_SIZE[1] + 1) etisserant@175: vertical_line_x = self.Input.GetPosition()[0] lbessard@199: dc.DrawLine(vertical_line_x, self.Pos.y, vertical_line_x, self.Pos.y + self.Size[1] + 1) etisserant@0: # Draw transition condition lbessard@64: if self.Type != "connection": lbessard@64: if self.Condition != "": lbessard@64: condition = self.Condition lbessard@64: else: lbessard@64: condition = "Transition" lbessard@231: condition_pos = (self.Pos.x + self.Size[0] + 5, lbessard@231: self.Pos.y + (self.Size[1] - condition_size[1]) / 2) lbessard@231: dc.DrawText(condition, condition_pos[0], condition_pos[1]) lbessard@80: # Draw priority number lbessard@80: if self.Priority != 0: lbessard@231: priority_pos = (self.Pos.x, self.Pos.y - priority_size[1] - 2) lbessard@231: dc.DrawText(str(self.Priority), priority_pos[0], priority_pos[1]) etisserant@0: # Draw input and output connectors etisserant@0: self.Input.Draw(dc) etisserant@0: self.Output.Draw(dc) lbessard@64: if self.Type == "connection": lbessard@64: self.Condition.Draw(dc) lbessard@231: if "priority" in self.Errors: lbessard@231: HighlightErrorZone(dc, priority_pos[0], priority_pos[1], priority_size[0], priority_size[1]) lbessard@231: if "inline" in self.Errors: lbessard@231: for start, end in self.Errors["inline"]: lbessard@231: offset = dc.GetTextExtent(self.Condition[:start]) lbessard@231: size = dc.GetTextExtent(self.Condition[start:end + 1]) lbessard@231: HighlightErrorZone(dc, condition_pos[0] + offset[0], condition_pos[1], size[0], size[1]) lbessard@231: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Sequencial Function Chart Divergence and Convergence etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a divergence or convergence, etisserant@0: selection or simultaneous etisserant@0: """ etisserant@0: etisserant@0: class SFC_Divergence(Graphic_Element): etisserant@0: etisserant@0: # Create a new divergence etisserant@0: def __init__(self, parent, type, number = 2, id = None): etisserant@0: Graphic_Element.__init__(self, parent) etisserant@0: self.Type = type etisserant@0: self.Id = id etisserant@0: self.RealConnectors = None etisserant@0: number = max(2, number) etisserant@175: self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, self.GetMinSize()[1]) etisserant@0: # Create an input and output connector etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: lbessard@145: self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)] etisserant@0: self.Outputs = [] etisserant@0: for i in xrange(number): lbessard@145: self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True)) etisserant@0: elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: self.Inputs = [] etisserant@0: for i in xrange(number): lbessard@145: self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True)) lbessard@145: self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)] lbessard@253: self.Value = None lbessard@253: self.PreviousValue = None etisserant@0: 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@253: def SpreadCurrent(self): lbessard@253: if self.Parent.Debug: lbessard@253: self.PreviousValue = self.Value lbessard@253: if self.Type == SELECTION_CONVERGENCE: lbessard@253: self.Value = False lbessard@253: for input in self.Inputs: lbessard@253: self.Value |= input.ReceivingCurrent() lbessard@253: elif self.Type == SIMULTANEOUS_CONVERGENCE: lbessard@253: self.Value = True lbessard@253: for input in self.Inputs: lbessard@253: self.Value &= input.ReceivingCurrent() lbessard@253: elif self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: lbessard@253: self.Value = self.Inputs[0].ReceivingCurrent() lbessard@253: else: lbessard@253: self.Value = False lbessard@253: if self.Value and not self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: for output in self.Outputs: lbessard@253: output.SpreadCurrent(True) lbessard@253: elif not self.Value and self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: for output in self.Outputs: lbessard@253: output.SpreadCurrent(False) lbessard@253: lbessard@112: # Make a clone of this SFC_Divergence lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@162: divergence = SFC_Divergence(parent, self.Type, max(len(self.Inputs), len(self.Outputs)), id) lbessard@112: divergence.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: divergence.SetPosition(pos.x, pos.y) lbessard@112: divergence.Inputs = [input.Clone(divergence) for input in self.Inputs] lbessard@112: divergence.Outputs = [output.Clone(divergence) for output in self.Outputs] lbessard@112: return divergence lbessard@112: 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: # Forbids to resize the divergence etisserant@0: def Resize(self, x, y, width, height): lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: etisserant@175: Graphic_Element.Resize(self, x, 0, width, self.GetMinSize()[1]) etisserant@0: etisserant@0: # Delete this divergence by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteDivergence(self) etisserant@0: etisserant@0: # Returns the divergence type etisserant@0: def GetType(self): etisserant@0: return self.Type etisserant@0: etisserant@0: # Unconnect input and output etisserant@0: def Clean(self): etisserant@0: for input in self.Inputs: lbessard@64: input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: for output in self.Outputs: lbessard@64: output.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: etisserant@0: # Add a branch to the divergence etisserant@0: def AddBranch(self): etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: etisserant@0: maxx = 0 etisserant@0: for output in self.Outputs: etisserant@0: pos = output.GetRelPosition() etisserant@0: maxx = max(maxx, pos.x) lbessard@145: connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH, onlyone = True) etisserant@0: self.Outputs.append(connector) etisserant@0: self.MoveConnector(connector, 0) etisserant@0: elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: maxx = 0 etisserant@0: for input in self.Inputs: etisserant@0: pos = input.GetRelPosition() etisserant@0: maxx = max(maxx, pos.x) lbessard@145: connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True) etisserant@0: self.Inputs.append(connector) etisserant@0: self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) etisserant@0: etisserant@0: # Remove a branch from the divergence etisserant@0: def RemoveBranch(self, connector): etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: lbessard@110: if connector in self.Outputs and len(self.Outputs) > 2: etisserant@0: self.Outputs.remove(connector) etisserant@0: self.MoveConnector(self.Outputs[0], 0) etisserant@0: elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: lbessard@110: if connector in self.Inputs and len(self.Inputs) > 2: etisserant@0: self.Inputs.remove(connector) etisserant@0: self.MoveConnector(self.Inputs[0], 0) etisserant@0: lbessard@80: # Remove the handled branch from the divergence lbessard@80: def RemoveHandledBranch(self): lbessard@80: handle_type, handle = self.Handle lbessard@80: if handle_type == HANDLE_CONNECTOR: lbessard@80: handle.UnConnect(delete=True) lbessard@80: self.RemoveBranch(handle) lbessard@80: etisserant@0: # Return the number of branches for the divergence etisserant@0: def GetBranchNumber(self): etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: etisserant@0: return len(self.Outputs) etisserant@0: elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: return len(self.Inputs) etisserant@0: etisserant@0: # Returns if the point given is in the bounding box etisserant@0: def HitTest(self, pt): etisserant@0: rect = self.BoundingBox lbessard@243: return rect.InsideXY(pt.x, pt.y) or self.TestConnector(pt, exclude=False) != None etisserant@0: etisserant@0: # Refresh the divergence bounding box etisserant@0: def RefreshBoundingBox(self): etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: lbessard@145: self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, lbessard@145: self.Size[0] + 1, self.Size[1] + 1) etisserant@0: elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: lbessard@145: self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, lbessard@145: self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1) etisserant@0: etisserant@0: # Refresh the position of wires connected to divergence 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: # Moves the divergence connector given etisserant@0: def MoveConnector(self, connector, movex): etisserant@0: position = connector.GetRelPosition() lbessard@64: connector.SetPosition(wx.Point(position.x + movex, position.y)) etisserant@0: minx = self.Size[0] etisserant@0: maxx = 0 etisserant@0: for input in self.Inputs: etisserant@0: input_pos = input.GetRelPosition() etisserant@0: minx = min(minx, input_pos.x) etisserant@0: maxx = max(maxx, input_pos.x) etisserant@0: for output in self.Outputs: etisserant@0: output_pos = output.GetRelPosition() etisserant@0: minx = min(minx, output_pos.x) etisserant@0: maxx = max(maxx, output_pos.x) etisserant@0: if minx != 0: etisserant@0: for input in self.Inputs: etisserant@0: input_pos = input.GetRelPosition() lbessard@64: input.SetPosition(wx.Point(input_pos.x - minx, input_pos.y)) etisserant@0: for output in self.Outputs: etisserant@0: output_pos = output.GetRelPosition() lbessard@64: output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y)) lbessard@110: self.Inputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) lbessard@110: self.Outputs.sort(lambda x, y: x.Pos.x.__cmp__(y.Pos.x)) etisserant@0: self.Pos.x += minx etisserant@0: self.Size[0] = maxx - minx etisserant@0: connector.MoveConnected() etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Returns the divergence 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 lbessard@27: if name: lbessard@27: # Test each input and output connector lbessard@27: for input in self.Inputs: lbessard@27: if name == input.GetName(): lbessard@27: return input lbessard@27: for output in self.Outputs: lbessard@27: if name == output.GetName(): lbessard@27: return output etisserant@0: # Test input connector etisserant@0: for input in self.Inputs: etisserant@0: input_pos = input.GetPosition(False) etisserant@0: if position.x == input_pos.x and position.y == input_pos.y: etisserant@0: return input etisserant@0: # Test output connector etisserant@0: for output in self.Outputs: etisserant@0: output_pos = output.GetPosition(False) etisserant@0: if position.x == output_pos.x and position.y == output_pos.y: etisserant@0: return output etisserant@0: return None etisserant@0: etisserant@0: # Returns input and output divergence 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 divergence input or output connector lbessard@243: def TestConnector(self, pt, direction = None, exclude=True): etisserant@0: # Test input connector etisserant@0: for input in self.Inputs: lbessard@243: if input.TestPoint(pt, direction, exclude): etisserant@0: return input etisserant@0: # Test 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: etisserant@0: # Changes the divergence size etisserant@0: def SetSize(self, width, height): lbessard@199: height = self.GetMinSize()[1] etisserant@0: for i, input in enumerate(self.Inputs): etisserant@0: position = input.GetRelPosition() etisserant@0: if self.RealConnectors: lbessard@64: input.SetPosition(wx.Point(int(round(self.RealConnectors["Inputs"][i] * width)), 0)) etisserant@0: else: lbessard@64: input.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), 0)) etisserant@0: input.MoveConnected() etisserant@0: for i, output in enumerate(self.Outputs): etisserant@0: position = output.GetRelPosition() etisserant@0: if self.RealConnectors: lbessard@146: output.SetPosition(wx.Point(int(round(self.RealConnectors["Outputs"][i] * width)), height)) etisserant@0: else: lbessard@146: output.SetPosition(wx.Point(int(round(float(position.x)*float(width)/float(self.Size[0]))), height)) etisserant@0: output.MoveConnected() lbessard@64: self.Size = wx.Size(width, height) etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Returns the divergence minimum size lbessard@110: def GetMinSize(self, default=False): lbessard@110: width = 0 lbessard@110: if default: lbessard@110: if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: lbessard@110: width = (len(self.Outputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL lbessard@110: elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: lbessard@110: width = (len(self.Inputs) - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL lbessard@27: if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: lbessard@110: return width, 1 lbessard@27: elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: lbessard@110: return width, 3 lbessard@27: return 0, 0 etisserant@0: etisserant@0: # Refresh the position of the block connected to connector etisserant@0: def RefreshConnectedPosition(self, connector): etisserant@0: wires = connector.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: current_pos = connector.GetPosition(False) lbessard@145: next = wires[0][0].GetOtherConnected(connector) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: diffx = current_pos.x - next_pos.x etisserant@0: next_block = next.GetParentBlock() etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.MoveConnector(next, diffx) etisserant@0: else: etisserant@0: next_block.Move(diffx, 0) etisserant@0: if connector in self.Inputs: etisserant@0: next_block.RefreshInputPosition() etisserant@0: else: etisserant@0: next_block.RefreshOutputPosition() lbessard@27: etisserant@0: # Refresh the position of this divergence etisserant@0: def RefreshPosition(self): etisserant@0: y = 0 etisserant@0: for input in self.Inputs: etisserant@0: wires = input.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return lbessard@145: previous = wires[0][0].GetOtherConnected(input) etisserant@0: previous_pos = previous.GetPosition(False) etisserant@0: y = max(y, previous_pos.y + GetWireSize(previous.GetParentBlock())) etisserant@0: diffy = y - self.Pos.y etisserant@0: if diffy != 0: etisserant@0: self.Move(0, diffy, self.Parent.Wires) etisserant@0: self.RefreshOutputPosition((0, diffy)) etisserant@0: for input in self.Inputs: etisserant@0: input.MoveConnected() etisserant@0: etisserant@0: # Align output element with this divergence etisserant@0: def RefreshOutputPosition(self, move = None): etisserant@0: if move: etisserant@0: for output_connector in self.Outputs: etisserant@0: wires = output_connector.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: current_pos = output_connector.GetPosition(False) lbessard@145: output = wires[0][0].GetOtherConnected(self.Output) etisserant@0: output_pos = output.GetPosition(False) etisserant@0: diffx = current_pos.x - output_pos.x etisserant@0: output_block = output.GetParentBlock() etisserant@0: if isinstance(output_block, SFC_Step): etisserant@0: output_block.MoveActionBlock(move) etisserant@0: wires[0][0].Move(move[0], move[1], True) etisserant@0: if not isinstance(output_block, SFC_Divergence) or output_block.GetConnectors()["inputs"].index(output) == 0: etisserant@0: output_block.Move(move[0], move[1], self.Parent.Wires) etisserant@0: output_block.RefreshOutputPosition(move) etisserant@0: etisserant@0: # Method called when a LeftDown event have been generated lbessard@27: def OnLeftDown(self, event, dc, scaling): lbessard@145: self.RealConnectors = {"Inputs":[],"Outputs":[]} lbessard@145: for input in self.Inputs: lbessard@145: position = input.GetRelPosition() lbessard@145: self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) lbessard@145: for output in self.Outputs: lbessard@145: position = output.GetRelPosition() lbessard@145: self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) lbessard@145: Graphic_Element.OnLeftDown(self, event, dc, scaling) lbessard@145: lbessard@145: # Method called when a LeftUp event have been generated lbessard@145: def OnLeftUp(self, event, dc, scaling): lbessard@145: Graphic_Element.OnLeftUp(self, event, dc, scaling) lbessard@145: self.RealConnectors = None lbessard@145: lbessard@145: # Method called when a RightDown event have been generated lbessard@145: def OnRightDown(self, event, dc, scaling): lbessard@27: pos = GetScaledEventPosition(event, dc, scaling) etisserant@0: # Test if a connector have been handled lbessard@243: connector = self.TestConnector(pos, exclude=False) etisserant@0: if connector: etisserant@0: self.Handle = (HANDLE_CONNECTOR, connector) lbessard@64: self.Parent.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) etisserant@0: self.Selected = False etisserant@0: # Initializes the last position lbessard@27: self.oldPos = GetScaledEventPosition(event, dc, scaling) etisserant@0: else: lbessard@145: Graphic_Element.OnRightDown(self, event, dc, scaling) lbessard@145: lbessard@145: # Method called when a RightUp event have been generated lbessard@145: def OnRightUp(self, event, dc, scaling): etisserant@0: handle_type, handle = self.Handle lbessard@204: if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos: etisserant@0: wires = handle.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return lbessard@145: block = wires[0][0].GetOtherConnected(handle).GetParentBlock() etisserant@0: block.RefreshModel(False) etisserant@0: if not isinstance(block, SFC_Divergence): etisserant@0: if handle in self.Inputs: etisserant@0: block.RefreshInputModel() etisserant@0: else: etisserant@0: block.RefreshOutputModel() lbessard@145: Graphic_Element.OnRightUp(self, event, dc, scaling) lbessard@145: else: lbessard@145: pos = GetScaledEventPosition(event, dc, scaling) lbessard@145: # Popup the menu with special items for a block and a connector if one is handled lbessard@243: connector = self.TestConnector(pos, exclude=False) lbessard@145: if connector: lbessard@145: self.Handle = (HANDLE_CONNECTOR, connector) lbessard@145: self.Parent.PopupDivergenceMenu(True) lbessard@145: else: lbessard@145: # Popup the divergence menu without delete branch lbessard@145: self.Parent.PopupDivergenceMenu(False) etisserant@0: etisserant@0: # Refreshes the divergence state according to move defined and handle selected lbessard@165: def ProcessDragging(self, movex, movey, centered, scaling): etisserant@0: handle_type, handle = self.Handle etisserant@0: # A connector has been handled etisserant@0: if handle_type == HANDLE_CONNECTOR: lbessard@138: movex = max(-self.BoundingBox.x, movex) lbessard@145: if scaling is not None: lbessard@145: movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x etisserant@0: self.MoveConnector(handle, movex) lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.RefreshConnectedPosition(handle) lbessard@138: return movex, 0 lbessard@27: elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@165: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) lbessard@138: return 0, 0 etisserant@0: etisserant@0: # Refresh output element model etisserant@0: def RefreshOutputModel(self, move=False): lbessard@27: if move and self.Parent.GetDrawingMode() != FREEDRAWING_MODE: etisserant@0: for output in self.Outputs: etisserant@0: wires = output.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return lbessard@145: output_block = wires[0][0].GetOtherConnected(output).GetParentBlock() etisserant@0: output_block.RefreshModel(False) etisserant@0: if not isinstance(output_block, SFC_Divergence) or move: etisserant@0: output_block.RefreshOutputModel(move) etisserant@0: etisserant@0: # Refreshes the divergence model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshDivergenceModel(self) etisserant@0: # If divergence has moved, refresh the model of wires connected to outputs etisserant@0: if move: lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.RefreshOutputModel() lbessard@27: else: lbessard@27: for output in self.Outputs: lbessard@27: output.RefreshWires() etisserant@0: lbessard@140: # Draws the highlightment of this element if it is highlighted lbessard@140: def DrawHighlightment(self, dc): lbessard@144: dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) lbessard@144: dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) lbessard@144: dc.SetLogicalFunction(wx.AND) lbessard@144: # Draw two rectangles for representing the contact lbessard@144: posx = self.Pos.x - 2 lbessard@144: width = self.Size[0] + 5 lbessard@144: if self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: lbessard@144: posx -= SFC_SIMULTANEOUS_SEQUENCE_EXTRA lbessard@144: width += SFC_SIMULTANEOUS_SEQUENCE_EXTRA * 2 lbessard@144: dc.DrawRectangle(posx, self.Pos.y - 2, width, self.Size[1] + 5) lbessard@144: dc.SetLogicalFunction(wx.COPY) lbessard@140: etisserant@0: # Draws divergence etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@253: if self.Value: lbessard@253: dc.SetPen(wx.GREEN_PEN) lbessard@253: dc.SetBrush(wx.GREEN_BRUSH) lbessard@253: else: lbessard@253: dc.SetPen(wx.BLACK_PEN) lbessard@253: dc.SetBrush(wx.BLACK_BRUSH) etisserant@0: # Draw plain rectangle for representing the divergence etisserant@0: if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y, etisserant@0: self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y) lbessard@27: dc.DrawLine(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y + self.Size[1], lbessard@27: self.Pos.x + self.Size[0] + SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Pos.y + self.Size[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@140: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Sequencial Function Chart Jump to Step etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of a jump to step etisserant@0: """ etisserant@0: etisserant@0: class SFC_Jump(Graphic_Element): etisserant@0: etisserant@0: # Create a new jump etisserant@0: def __init__(self, parent, target, id = None): etisserant@0: Graphic_Element.__init__(self, parent) lbessard@213: self.SetTarget(target) etisserant@0: self.Id = id lbessard@64: self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) lbessard@231: self.Errors = {} etisserant@0: # Create an input and output connector lbessard@145: self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True) lbessard@253: self.Value = None lbessard@253: self.PreviousValue = None etisserant@0: lbessard@249: def Flush(self): lbessard@249: if self.Input is not None: lbessard@249: self.Input.Flush() lbessard@249: self.Input = None etisserant@0: lbessard@253: def SpreadCurrent(self): lbessard@253: if self.Parent.Debug: lbessard@253: self.PreviousValue = self.Value lbessard@253: self.Value = self.Input.ReceivingCurrent() lbessard@253: if self.Value != self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: lbessard@112: # Make a clone of this SFC_Jump lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@162: jump = SFC_Jump(parent, self.Target, id) lbessard@112: jump.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: jump.SetPosition(pos.x, pos.y) lbessard@112: jump.Input = self.Input.Clone(jump) lbessard@112: return jump lbessard@112: 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: rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) lbessard@144: if movex != 0 or movey != 0: lbessard@144: if self.Input.IsConnected(): lbessard@144: rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@144: etisserant@0: # Forbids to change the jump size etisserant@0: def SetSize(self, width, height): lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: Graphic_Element.SetSize(self, width, height) etisserant@0: etisserant@0: # Forbids to resize jump etisserant@0: def Resize(self, x, y, width, height): lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@27: Graphic_Element.Resize(self, x, y, width, height) etisserant@0: etisserant@0: # Delete this jump by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteJump(self) etisserant@0: etisserant@0: # Unconnect input etisserant@0: def Clean(self): lbessard@64: self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: lbessard@213: # Refresh the size of text for target lbessard@213: def RefreshTargetSize(self): lbessard@213: self.TargetSize = self.Parent.GetTextExtent(self.Target) lbessard@213: etisserant@0: # Refresh the jump bounding box etisserant@0: def RefreshBoundingBox(self): lbessard@165: text_width, text_height = self.Parent.GetTextExtent(self.Target) etisserant@0: # Calculate the bounding box size etisserant@0: bbx_width = self.Size[0] + 2 + text_width lbessard@64: self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - CONNECTOR_SIZE, etisserant@0: bbx_width + 1, self.Size[1] + CONNECTOR_SIZE + 1) etisserant@0: etisserant@0: # Returns the connector connected to input etisserant@0: def GetPreviousConnector(self): lbessard@27: wires = self.Input.GetWires() lbessard@27: if len(wires) == 1: lbessard@145: return wires[0][0].GetOtherConnected(self.Input) etisserant@0: return None etisserant@0: lbessard@27: # Refresh the element connectors position lbessard@27: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: horizontal_pos = self.Size[0] / 2 lbessard@145: if scaling is not None: lbessard@145: horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@145: self.Input.SetPosition(wx.Point(horizontal_pos, 0)) lbessard@27: self.RefreshConnected() lbessard@27: etisserant@0: # Refresh the position of wires connected to jump etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: if self.Input: etisserant@0: self.Input.MoveConnected(exclude) etisserant@0: etisserant@0: # Returns input jump connector lbessard@27: def GetConnector(self, position = None, name = None): etisserant@0: return self.Input etisserant@0: etisserant@0: # Test if point given is on jump input connector lbessard@243: def TestConnector(self, pt, direction = None, exclude = True): etisserant@0: # Test input connector lbessard@243: if self.Input and self.Input.TestPoint(pt, direction, exclude): etisserant@0: return self.Input etisserant@0: return None etisserant@0: etisserant@0: # Changes the jump target etisserant@0: def SetTarget(self, target): etisserant@0: self.Target = target lbessard@213: self.RefreshTargetSize() etisserant@0: self.RefreshBoundingBox() etisserant@0: etisserant@0: # Returns the jump target etisserant@0: def GetTarget(self): etisserant@0: return self.Target etisserant@0: etisserant@0: # Returns the jump minimum size etisserant@0: def GetMinSize(self): etisserant@0: return SFC_JUMP_SIZE etisserant@0: etisserant@0: # Align input element with this jump etisserant@0: def RefreshInputPosition(self): etisserant@0: if self.Input: etisserant@0: current_pos = self.Input.GetPosition(False) etisserant@0: input = self.GetPreviousConnector() etisserant@0: if input: etisserant@0: input_pos = input.GetPosition(False) etisserant@0: diffx = current_pos.x - input_pos.x etisserant@0: input_block = input.GetParentBlock() etisserant@0: if isinstance(input_block, SFC_Divergence): etisserant@0: input_block.MoveConnector(input, diffx) etisserant@0: else: etisserant@0: if isinstance(input_block, SFC_Step): etisserant@0: input_block.MoveActionBlock((diffx, 0)) etisserant@0: input_block.Move(diffx, 0) etisserant@0: input_block.RefreshInputPosition() etisserant@0: etisserant@0: # Can't align output element, because there is no output etisserant@0: def RefreshOutputPosition(self, move = None): etisserant@0: pass etisserant@0: etisserant@0: # Method called when a LeftDClick event have been generated lbessard@27: def OnLeftDClick(self, event, dc, scaling): etisserant@0: # Edit the jump properties etisserant@0: self.Parent.EditJumpContent(self) etisserant@0: 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 jump state according to move defined and handle selected lbessard@165: def ProcessDragging(self, movex, movey, centered, scaling): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@138: movex = max(-self.BoundingBox.x, movex) lbessard@145: if scaling is not None: lbessard@145: movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@27: self.Move(movex, 0) lbessard@27: self.RefreshInputPosition() lbessard@138: return movex, 0 lbessard@110: else: etisserant@175: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling, width_fac = 2) etisserant@0: etisserant@0: # Refresh input element model etisserant@0: def RefreshInputModel(self): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: input = self.GetPreviousConnector() lbessard@27: if input: lbessard@27: input_block = input.GetParentBlock() lbessard@27: input_block.RefreshModel(False) lbessard@27: if not isinstance(input_block, SFC_Divergence): lbessard@27: input_block.RefreshInputModel() etisserant@0: etisserant@0: # Refresh output element model etisserant@0: def RefreshOutputModel(self, move=False): etisserant@0: pass etisserant@0: etisserant@0: # Refreshes the jump model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshJumpModel(self) etisserant@0: if move: lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: self.RefreshInputModel() etisserant@0: lbessard@231: def AddError(self, infos, start, end): lbessard@231: if infos[0] == "target" and start[0] == 0 and end[0] == 0: lbessard@231: self.Errors[infos[0]] = (start[1], end[1]) lbessard@231: lbessard@140: # Draws the highlightment of this element if it is highlighted lbessard@140: def DrawHighlightment(self, dc): lbessard@144: dc.SetPen(wx.Pen(HIGHLIGHTCOLOR)) lbessard@144: dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR)) lbessard@144: dc.SetLogicalFunction(wx.AND) lbessard@144: points = [wx.Point(self.Pos.x - 3, self.Pos.y - 2), lbessard@144: wx.Point(self.Pos.x + self.Size[0] + 4, self.Pos.y - 2), lbessard@144: wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] + 4)] lbessard@144: dc.DrawPolygon(points) lbessard@144: dc.SetLogicalFunction(wx.COPY) lbessard@140: etisserant@0: # Draws divergence etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@253: if self.Value: lbessard@253: dc.SetPen(wx.GREEN_PEN) lbessard@253: dc.SetBrush(wx.GREEN_BRUSH) lbessard@253: else: lbessard@253: dc.SetPen(wx.BLACK_PEN) lbessard@253: dc.SetBrush(wx.BLACK_BRUSH) lbessard@213: lbessard@213: if getattr(dc, "printing", False): lbessard@213: target_size = dc.GetTextExtent(self.Target) lbessard@213: else: lbessard@213: target_size = self.TargetSize lbessard@213: etisserant@0: # Draw plain rectangle for representing the divergence etisserant@0: dc.DrawLine(self.Pos.x + self.Size[0] / 2, self.Pos.y, self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1]) lbessard@64: points = [wx.Point(self.Pos.x, self.Pos.y), lbessard@64: wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1] / 3), lbessard@64: wx.Point(self.Pos.x + self.Size[0], self.Pos.y), lbessard@64: wx.Point(self.Pos.x + self.Size[0] / 2, self.Pos.y + self.Size[1])] etisserant@0: dc.DrawPolygon(points) lbessard@231: target_pos = (self.Pos.x + self.Size[0] + 2, lbessard@231: self.Pos.y + (self.Size[1] - target_size[1]) / 2) lbessard@231: dc.DrawText(self.Target, target_pos[0], target_pos[1]) etisserant@0: # Draw input connector etisserant@0: if self.Input: etisserant@0: self.Input.Draw(dc) lbessard@231: if "target" in self.Errors: lbessard@231: HighlightErrorZone(dc, target_pos[0], target_pos[1], target_size[0], target_size[1]) lbessard@140: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Sequencial Function Chart Action Block etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: """ etisserant@0: Class that implements the graphic representation of an action block etisserant@0: """ etisserant@0: etisserant@0: class SFC_ActionBlock(Graphic_Element): etisserant@0: etisserant@0: # Create a new action block etisserant@0: def __init__(self, parent, actions = [], id = None): etisserant@0: Graphic_Element.__init__(self, parent) etisserant@0: self.Id = id lbessard@64: self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) lbessard@108: self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) lbessard@231: self.Errors = {} etisserant@0: # Create an input and output connector lbessard@145: self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST, onlyone = True) etisserant@0: self.SetActions(actions) lbessard@253: self.Value = None lbessard@253: self.PreviousValue = None etisserant@0: lbessard@249: def Flush(self): lbessard@249: if self.Input is not None: lbessard@249: self.Input.Flush() lbessard@249: self.Input = None etisserant@0: lbessard@253: def SpreadCurrent(self): lbessard@253: if self.Parent.Debug: lbessard@253: self.PreviousValue = self.Value lbessard@253: self.Value = self.Input.ReceivingCurrent() lbessard@253: if self.Value != self.PreviousValue: lbessard@253: self.Refresh() lbessard@253: lbessard@112: # Make a clone of this SFC_ActionBlock lbessard@162: def Clone(self, parent, id = None, pos = None): lbessard@112: actions = [action.copy() for action in self.Actions] lbessard@162: action_block = SFC_ActionBlock(parent, actions, id) lbessard@112: action_block.SetSize(self.Size[0], self.Size[1]) lbessard@112: if pos is not None: lbessard@112: action_block.SetPosition(pos.x, pos.y) lbessard@112: action_block.Input = self.Input.Clone(action_block) lbessard@144: return action_block lbessard@144: 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: rect = rect.Union(self.Input.GetRedrawRect(movex, movey)) lbessard@144: if movex != 0 or movey != 0: lbessard@144: if self.Input.IsConnected(): lbessard@144: rect = rect.Union(self.Input.GetConnectedRedrawRect(movex, movey)) lbessard@144: return rect lbessard@112: etisserant@0: # Returns the number of action lines etisserant@0: def GetLineNumber(self): etisserant@0: return len(self.Actions) etisserant@0: lbessard@27: def GetLineSize(self): lbessard@108: if len(self.Actions) > 0: lbessard@27: return self.Size[1] / len(self.Actions) lbessard@27: else: lbessard@27: return SFC_ACTION_MIN_SIZE[1] lbessard@27: etisserant@0: # Forbids to resize the action block etisserant@0: def Resize(self, x, y, width, height): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: if x == 0: lbessard@27: self.SetSize(width, self.Size[1]) lbessard@27: else: lbessard@27: Graphic_Element.Resize(self, x, y, width, height) etisserant@0: etisserant@0: # Delete this action block by calling the appropriate method etisserant@0: def Delete(self): etisserant@0: self.Parent.DeleteActionBlock(self) etisserant@0: etisserant@0: # Unconnect input and output etisserant@0: def Clean(self): lbessard@64: self.Input.UnConnect(delete = self.Parent.GetDrawingMode() == FREEDRAWING_MODE) etisserant@0: etisserant@0: # Refresh the action block bounding box etisserant@0: def RefreshBoundingBox(self): lbessard@144: self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: etisserant@0: # Refresh the position of wires connected to action block etisserant@0: def RefreshConnected(self, exclude = []): etisserant@0: self.Input.MoveConnected(exclude) etisserant@0: etisserant@0: # Returns input action block connector lbessard@27: def GetConnector(self, position = None, name = None): etisserant@0: return self.Input etisserant@0: etisserant@0: # Test if point given is on action block input connector lbessard@243: def TestConnector(self, pt, direction = None, exclude = True): etisserant@0: # Test input connector lbessard@243: if self.Input.TestPoint(pt, direction, exclude): etisserant@0: return self.Input etisserant@0: return None etisserant@0: lbessard@145: # Refresh the element connectors position lbessard@145: def RefreshConnectors(self): lbessard@145: scaling = self.Parent.GetScaling() lbessard@145: vertical_pos = SFC_ACTION_MIN_SIZE[1] / 2 lbessard@145: if scaling is not None: lbessard@145: vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y lbessard@145: self.Input.SetPosition(wx.Point(0, vertical_pos)) lbessard@145: self.RefreshConnected() lbessard@145: etisserant@0: # Changes the action block actions etisserant@0: def SetActions(self, actions): etisserant@0: self.Actions = actions etisserant@0: self.ColSize = [0, 0, 0] lbessard@108: min_height = 0 etisserant@0: for action in self.Actions: lbessard@165: width, height = self.Parent.GetTextExtent(action["qualifier"]) etisserant@0: self.ColSize[0] = max(self.ColSize[0], width + 10) lbessard@108: row_height = height etisserant@0: if "duration" in action: lbessard@165: width, height = self.Parent.GetTextExtent(action["duration"]) lbessard@108: row_height = max(row_height, height) etisserant@0: self.ColSize[0] = max(self.ColSize[0], width + 10) lbessard@165: width, height = self.Parent.GetTextExtent(action["value"]) lbessard@108: row_height = max(row_height, height) etisserant@0: self.ColSize[1] = max(self.ColSize[1], width + 10) etisserant@0: if "indicator" in action and action["indicator"] != "": lbessard@165: width, height = self.Parent.GetTextExtent(action["indicator"]) lbessard@108: row_height = max(row_height, height) etisserant@0: self.ColSize[2] = max(self.ColSize[2], width + 10) lbessard@108: min_height += row_height + 5 lbessard@27: if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: lbessard@108: self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1])) lbessard@108: self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], lbessard@108: SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height) lbessard@108: self.RefreshBoundingBox() lbessard@64: else: lbessard@64: self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], lbessard@27: SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) lbessard@108: self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], lbessard@108: SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] lbessard@108: self.RefreshBoundingBox() lbessard@108: if self.Input: lbessard@108: wires = self.Input.GetWires() lbessard@108: if len(wires) == 1: lbessard@145: input_block = wires[0][0].GetOtherConnected(self.Input).GetParentBlock() lbessard@108: input_block.RefreshOutputPosition() lbessard@108: input_block.RefreshOutputModel(True) etisserant@0: etisserant@0: # Returns the action block actions etisserant@0: def GetActions(self): etisserant@0: return self.Actions etisserant@0: etisserant@0: # Returns the action block minimum size etisserant@0: def GetMinSize(self): lbessard@108: return self.MinSize etisserant@0: etisserant@0: # Method called when a LeftDClick event have been generated lbessard@27: def OnLeftDClick(self, event, dc, scaling): etisserant@0: # Edit the action block properties etisserant@0: self.Parent.EditActionBlockContent(self) etisserant@0: lbessard@127: # Method called when a RightUp event have been generated lbessard@127: def OnRightUp(self, event, dc, scaling): lbessard@127: # Popup the default menu lbessard@127: self.Parent.PopupDefaultMenu() lbessard@127: etisserant@0: # Refreshes the action block state according to move defined and handle selected lbessard@165: def ProcessDragging(self, movex, movey, centered, scaling): lbessard@27: if self.Parent.GetDrawingMode() != FREEDRAWING_MODE: lbessard@27: handle_type, handle = self.Handle lbessard@27: if handle_type == HANDLE_MOVE: lbessard@138: movex = max(-self.BoundingBox.x, movex) lbessard@145: if scaling is not None: lbessard@145: movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x lbessard@27: wires = self.Input.GetWires() lbessard@27: if len(wires) == 1: lbessard@145: input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False) lbessard@27: if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE: lbessard@27: self.Move(movex, 0) lbessard@138: return movex, 0 lbessard@138: return 0, 0 lbessard@27: else: lbessard@165: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) lbessard@165: else: lbessard@165: return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) lbessard@27: etisserant@0: etisserant@0: # Refreshes the action block model etisserant@0: def RefreshModel(self, move=True): etisserant@0: self.Parent.RefreshActionBlockModel(self) etisserant@0: lbessard@231: def AddError(self, infos, start, end): lbessard@231: if infos[0] == "action" and infos[1] < len(self.Actions): lbessard@231: if infos[1] not in self.Errors: lbessard@231: self.Errors[infos[1]] = {} lbessard@231: if infos[2] == "inline": lbessard@231: if infos[2] not in self.Errors[infos[1]]: lbessard@231: self.Errors[infos[1]][infos[2]] = [] lbessard@231: self.Errors[infos[1]][infos[2]].append((start[1], end[1])) lbessard@231: else: lbessard@231: self.Errors[infos[1]][infos[2]] = (start[1], end[1]) lbessard@231: etisserant@0: # Draws divergence etisserant@0: def Draw(self, dc): lbessard@144: Graphic_Element.Draw(self, dc) lbessard@253: if self.Value: lbessard@253: dc.SetPen(wx.GREEN_PEN) lbessard@253: else: lbessard@253: dc.SetPen(wx.BLACK_PEN) lbessard@64: dc.SetBrush(wx.WHITE_BRUSH) etisserant@0: colsize = [self.ColSize[0], self.Size[0] - self.ColSize[0] - self.ColSize[2], self.ColSize[2]] etisserant@0: # Draw plain rectangle for representing the action block etisserant@0: dc.DrawRectangle(self.Pos.x, self.Pos.y, self.Size[0] + 1, self.Size[1] + 1) etisserant@0: dc.DrawLine(self.Pos.x + colsize[0], self.Pos.y, etisserant@0: self.Pos.x + colsize[0], self.Pos.y + self.Size[1]) etisserant@0: dc.DrawLine(self.Pos.x + colsize[0] + colsize[1], self.Pos.y, etisserant@0: self.Pos.x + colsize[0] + colsize[1], self.Pos.y + self.Size[1]) lbessard@27: line_size = self.GetLineSize() etisserant@0: for i, action in enumerate(self.Actions): etisserant@0: if i != 0: lbessard@27: dc.DrawLine(self.Pos.x, self.Pos.y + i * line_size, lbessard@27: self.Pos.x + self.Size[0], self.Pos.y + i * line_size) lbessard@231: qualifier_size = dc.GetTextExtent(action["qualifier"]) etisserant@0: if "duration" in action: lbessard@231: qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, lbessard@231: self.Pos.y + i * line_size + line_size / 2 - qualifier_size[1]) lbessard@231: duration_size = dc.GetTextExtent(action["duration"]) lbessard@231: duration_pos = (self.Pos.x + (colsize[0] - duration_size[0]) / 2, lbessard@231: self.Pos.y + i * line_size + line_size / 2) lbessard@231: dc.DrawText(action["duration"], duration_pos[0], duration_pos[1]) etisserant@0: else: lbessard@231: qualifier_pos = (self.Pos.x + (colsize[0] - qualifier_size[0]) / 2, lbessard@231: self.Pos.y + i * line_size + (line_size - qualifier_size[1]) / 2) lbessard@231: dc.DrawText(action["qualifier"], qualifier_pos[0], qualifier_pos[1]) lbessard@231: content_size = dc.GetTextExtent(action["value"]) lbessard@231: content_pos = (self.Pos.x + colsize[0] + (colsize[1] - content_size[0]) / 2, lbessard@231: self.Pos.y + i * line_size + (line_size - content_size[1]) / 2) lbessard@231: dc.DrawText(action["value"], content_pos[0], content_pos[1]) etisserant@0: if "indicator" in action: lbessard@231: indicator_size = dc.GetTextExtent(action["indicator"]) lbessard@231: indicator_pos = (self.Pos.x + colsize[0] + colsize[1] + (colsize[2] - indicator_size[0]) / 2, lbessard@231: self.Pos.y + i * line_size + (line_size - indicator_size[1]) / 2) lbessard@231: dc.DrawText(action["indicator"], indicator_pos[0], indicator_pos[1]) lbessard@231: if i in self.Errors: lbessard@231: if "duration" in self.Errors[i] and "duration" in action: lbessard@231: HighlightErrorZone(dc, duration_pos[0], duration_pos[1], duration_size[0], duration_size[1]) lbessard@231: if "qualifier" in self.Errors[i]: lbessard@231: HighlightErrorZone(dc, qualifier_pos[0], qualifier_pos[1], qualifier_size[0], qualifier_size[1]) lbessard@231: if "reference" in self.Errors[i]: lbessard@231: HighlightErrorZone(dc, content_pos[0], content_pos[1], content_size[0], content_size[1]) lbessard@231: elif "inline" in self.Errors[i]: lbessard@231: for start, end in self.Errors[i]["inline"]: lbessard@231: offset = dc.GetTextExtent(action["value"][:start]) lbessard@231: size = dc.GetTextExtent(action["value"][start:end + 1]) lbessard@231: HighlightErrorZone(dc, content_pos[0] + offset[0], content_pos[1], size[0], size[1]) lbessard@231: if "indicator" in self.Errors[i]: lbessard@231: HighlightErrorZone(dc, indicator_pos[0], indicator_pos[1], indicator_size[0], indicator_size[1]) etisserant@0: # Draw input connector etisserant@0: self.Input.Draw(dc) lbessard@140: