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: # etisserant@0: #Copyright (C): 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@0: #modify it under the terms of the GNU Lesser 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 etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser 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: from wxPython.wx import * etisserant@0: from wxPython.grid import * etisserant@0: import wx etisserant@0: from types import * etisserant@0: etisserant@0: from plcopen.structures import * etisserant@0: from graphics.GraphicCommons import * etisserant@0: from graphics.SFC_Objects import * etisserant@0: from Viewer import * etisserant@0: etisserant@0: class SFC_Viewer(Viewer): etisserant@0: etisserant@0: def __init__(self, parent, window, controler): etisserant@0: Viewer.__init__(self, parent, window, controler) etisserant@0: etisserant@0: def ConnectConnectors(self, start, end): etisserant@0: startpoint = [start.GetPosition(False), start.GetDirection()] etisserant@0: endpoint = [end.GetPosition(False), end.GetDirection()] etisserant@0: wire = Wire(self, startpoint, endpoint) etisserant@0: self.Wires.append(wire) etisserant@0: self.Elements.append(wire) etisserant@0: start.Connect((wire, 0), False) etisserant@0: end.Connect((wire, -1), False) etisserant@0: wire.ConnectStartPoint(None, start) etisserant@0: wire.ConnectEndPoint(None, end) etisserant@0: return wire etisserant@0: etisserant@0: def CreateTransition(self, connector, next = None): etisserant@0: previous = connector.GetParentBlock() etisserant@0: id = self.GetNewId() etisserant@0: transition = SFC_Transition(self, "reference", "", id) etisserant@0: pos = connector.GetPosition(False) etisserant@0: transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: wire = self.ConnectConnectors(transition_connectors["input"], connector) etisserant@0: if isinstance(previous, SFC_Divergence): etisserant@0: previous.RefreshConnectedPosition(connector) etisserant@0: else: etisserant@0: previous.RefreshOutputPosition() etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)]) etisserant@0: self.Blocks.append(transition) etisserant@0: self.Elements.append(transition) etisserant@0: self.Controler.AddCurrentElementEditingTransition(id) etisserant@0: self.RefreshTransitionModel(transition) etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, transition_connectors["output"]) etisserant@0: pos = transition_connectors["output"].GetPosition(False) etisserant@0: next_block = next.GetParentBlock() etisserant@0: next_pos = next.GetPosition(False) etisserant@0: transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.RefreshPosition() etisserant@0: next_block.RefreshModel() etisserant@0: return transition etisserant@0: etisserant@0: def RemoveTransition(self, transition): etisserant@0: connectors = transition.GetConnectors() etisserant@0: input_wires = connectors["input"].GetWires() etisserant@0: if len(input_wires) != 1: etisserant@0: return etisserant@0: input_wire = input_wires[0][0] etisserant@0: previous = input_wire.EndConnected etisserant@0: input_wire.Clean() etisserant@0: self.Wires.remove(input_wire) etisserant@0: self.Elements.remove(input_wire) etisserant@0: output_wires = connectors["output"].GetWires() etisserant@0: if len(output_wires) != 1: etisserant@0: return etisserant@0: output_wire = output_wires[0][0] etisserant@0: next = output_wire.StartConnected etisserant@0: output_wire.Clean() etisserant@0: self.Wires.remove(output_wire) etisserant@0: self.Elements.remove(output_wire) etisserant@0: transition.Clean() etisserant@0: self.Blocks.remove(transition) etisserant@0: self.Elements.remove(transition) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(transition.GetId()) etisserant@0: wire = self.ConnectConnectors(next, previous) etisserant@0: return wire etisserant@0: etisserant@0: def CreateStep(self, name, connector, next = None): etisserant@0: previous = connector.GetParentBlock() etisserant@0: id = self.GetNewId() etisserant@0: step = SFC_Step(self, name, False, id) etisserant@0: if next: etisserant@0: step.AddOutput() etisserant@0: min_width, min_height = step.GetMinSize() etisserant@0: pos = connector.GetPosition(False) etisserant@0: step.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) etisserant@0: step.SetSize(min_width, min_height) etisserant@0: step_connectors = step.GetConnectors() etisserant@0: wire = self.ConnectConnectors(step_connectors["input"], connector) etisserant@0: if isinstance(previous, SFC_Divergence): etisserant@0: previous.RefreshConnectedPosition(connector) etisserant@0: else: etisserant@0: previous.RefreshOutputPosition() etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + GetWireSize(previous)), wxPoint(pos.x, pos.y)]) etisserant@0: self.Blocks.append(step) etisserant@0: self.Elements.append(step) etisserant@0: self.Controler.AddCurrentElementEditingStep(id) etisserant@0: self.RefreshStepModel(step) etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, step_connectors["output"]) etisserant@0: pos = step_connectors["output"].GetPosition(False) etisserant@0: next_block = next.GetParentBlock() etisserant@0: next_pos = next.GetPosition(False) etisserant@0: step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.RefreshPosition() etisserant@0: next_block.RefreshModel() etisserant@0: return step etisserant@0: etisserant@0: def RemoveStep(self, step): etisserant@0: connectors = step.GetConnectors() etisserant@0: if connectors["input"]: etisserant@0: input_wires = connectors["input"].GetWires() etisserant@0: if len(input_wires) != 1: etisserant@0: return etisserant@0: input_wire = input_wires[0][0] etisserant@0: previous = input_wire.EndConnected etisserant@0: input_wire.Clean() etisserant@0: self.Wires.remove(input_wire) etisserant@0: self.Elements.remove(input_wire) etisserant@0: else: etisserant@0: previous = None etisserant@0: if connectors["output"]: etisserant@0: output_wires = connectors["output"].GetWires() etisserant@0: if len(output_wires) != 1: etisserant@0: return etisserant@0: output_wire = output_wires[0][0] etisserant@0: next = output_wire.StartConnected etisserant@0: output_wire.Clean() etisserant@0: self.Wires.remove(output_wire) etisserant@0: self.Elements.remove(output_wire) etisserant@0: else: etisserant@0: next = None etisserant@0: action = step.GetActionConnector() etisserant@0: if action: etisserant@0: self.DeleteActionBlock(action.GetParentBlock()) etisserant@0: step.Clean() etisserant@0: self.Blocks.remove(step) etisserant@0: self.Elements.remove(step) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(step.GetId()) etisserant@0: if next and previous: etisserant@0: wire = self.ConnectConnectors(next, previous) etisserant@0: return wire etisserant@0: else: etisserant@0: return None etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Mouse event functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnViewerLeftDown(self, event): etisserant@0: if self.Mode == MODE_SELECTION: etisserant@0: pos = event.GetPosition() etisserant@0: if event.ControlDown(): etisserant@0: element = self.FindElement(pos, True) etisserant@0: if element and element not in self.Wires: etisserant@0: if isinstance(self.SelectedElement, Graphic_Group): etisserant@0: self.SelectedElement.SelectElement(element) etisserant@0: else: etisserant@0: group = Graphic_Group(self) etisserant@0: self.SelectedElement.SetSelected(False) etisserant@0: group.SelectElement(self.SelectedElement) etisserant@0: group.SelectElement(element) etisserant@0: self.SelectedElement = group etisserant@0: elements = self.SelectedElement.GetElements() etisserant@0: if len(elements) == 0: etisserant@0: self.SelectedElement = element etisserant@0: elif len(elements) == 1: etisserant@0: self.SelectedElement = elements[0] etisserant@0: else: etisserant@0: element = self.FindElement(pos) etisserant@0: if self.SelectedElement and self.SelectedElement != element: etisserant@0: if self.SelectedElement in self.Wires: etisserant@0: self.SelectedElement.SetSelectedSegment(None) etisserant@0: else: etisserant@0: self.SelectedElement.SetSelected(False) etisserant@0: self.SelectedElement = None etisserant@0: self.Refresh() etisserant@0: if element: etisserant@0: self.SelectedElement = element etisserant@0: self.SelectedElement.OnLeftDown(event, self.Scaling) etisserant@0: self.Refresh() etisserant@0: else: etisserant@0: self.rubberBand.Reset() etisserant@0: self.rubberBand.OnLeftDown(event, self.Scaling) etisserant@0: elif self.Mode == MODE_COMMENT: etisserant@0: self.rubberBand.Reset() etisserant@0: self.rubberBand.OnLeftDown(event, self.Scaling) etisserant@0: elif self.Mode == MODE_WIRE: etisserant@0: pos = GetScaledEventPosition(event, self.Scaling) etisserant@0: wire = Wire(self, [wxPoint(pos.x, pos.y), SOUTH], [wxPoint(pos.x, pos.y), NORTH]) etisserant@0: wire.oldPos = pos etisserant@0: wire.Handle = (HANDLE_POINT, 0) etisserant@0: wire.ProcessDragging(0, 0) etisserant@0: wire.Handle = (HANDLE_POINT, 1) etisserant@0: self.Wires.append(wire) etisserant@0: self.Elements.append(wire) etisserant@0: if self.SelectedElement: etisserant@0: self.SelectedElement.SetSelected(False) etisserant@0: self.SelectedElement = wire etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnViewerLeftUp(self, event): etisserant@0: if self.rubberBand.IsShown(): etisserant@0: if self.Mode == MODE_SELECTION: etisserant@0: elements = self.SearchElements(self.rubberBand.GetCurrentExtent()) etisserant@0: self.rubberBand.OnLeftUp(event, self.Scaling) etisserant@0: if len(elements) > 0: etisserant@0: self.SelectedElement = Graphic_Group(self) etisserant@0: self.SelectedElement.SetElements(elements) etisserant@0: self.SelectedElement.SetSelected(True) etisserant@0: self.Refresh() etisserant@0: elif self.Mode == MODE_COMMENT: etisserant@0: bbox = self.rubberBand.GetCurrentExtent() etisserant@0: self.rubberBand.OnLeftUp(event, self.Scaling) etisserant@0: wxCallAfter(self.AddComment, bbox) etisserant@0: elif self.Mode == MODE_INITIAL_STEP: etisserant@0: wxCallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.Scaling)) etisserant@0: elif self.Mode == MODE_SELECTION and self.SelectedElement: etisserant@0: if self.SelectedElement in self.Wires: etisserant@0: self.SelectedElement.SetSelectedSegment(0) etisserant@0: else: etisserant@0: self.SelectedElement.OnLeftUp(event, self.Scaling) etisserant@0: wxCallAfter(self.SetCursor, wxNullCursor) etisserant@0: self.ReleaseMouse() etisserant@0: self.Refresh() etisserant@0: elif self.Mode == MODE_WIRE and self.SelectedElement: etisserant@0: self.SelectedElement.ResetPoints() etisserant@0: self.SelectedElement.OnMotion(event, self.Scaling) etisserant@0: self.SelectedElement.GeneratePoints() etisserant@0: self.SelectedElement.RefreshModel() etisserant@0: self.SelectedElement.SetSelected(True) etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnViewerRightUp(self, event): etisserant@0: pos = event.GetPosition() etisserant@0: element = self.FindElement(pos) etisserant@0: if element: etisserant@0: if self.SelectedElement and self.SelectedElement != element: etisserant@0: self.SelectedElement.SetSelected(False) etisserant@0: self.SelectedElement = element etisserant@0: if self.SelectedElement in self.Wires: etisserant@0: self.SelectedElement.SetSelectedSegment(0) etisserant@0: else: etisserant@0: self.SelectedElement.SetSelected(True) etisserant@0: self.SelectedElement.OnRightUp(event, self.Scaling) etisserant@0: wxCallAfter(self.SetCursor, wxNullCursor) etisserant@0: self.ReleaseMouse() etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnViewerLeftDClick(self, event): etisserant@0: if self.Mode == MODE_SELECTION and self.SelectedElement: etisserant@0: self.SelectedElement.OnLeftDClick(event, self.Scaling) etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnViewerMotion(self, event): etisserant@0: if self.rubberBand.IsShown(): etisserant@0: self.rubberBand.OnMotion(event, self.Scaling) etisserant@0: elif self.Mode == MODE_SELECTION and self.SelectedElement: etisserant@0: if self.SelectedElement not in self.Wires: etisserant@0: self.SelectedElement.OnMotion(event, self.Scaling) etisserant@0: self.Refresh() etisserant@0: elif self.Mode == MODE_WIRE and self.SelectedElement: etisserant@0: self.SelectedElement.ResetPoints() etisserant@0: self.SelectedElement.OnMotion(event, self.Scaling) etisserant@0: self.SelectedElement.GeneratePoints() etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Keyboard event functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnChar(self, event): etisserant@0: keycode = event.GetKeyCode() etisserant@0: if self.Scaling: etisserant@0: scaling = self.Scaling etisserant@0: else: etisserant@0: scaling = (8, 8) etisserant@0: if keycode == WXK_DELETE and self.SelectedElement: etisserant@0: self.SelectedElement.Delete() etisserant@0: self.SelectedElement = None etisserant@0: elif keycode == WXK_LEFT and self.SelectedElement: etisserant@0: self.SelectedElement.Move(-scaling[0], 0) etisserant@0: elif keycode == WXK_RIGHT and self.SelectedElement: etisserant@0: self.SelectedElement.Move(scaling[0], 0) etisserant@0: elif keycode == WXK_UP and self.SelectedElement: etisserant@0: self.SelectedElement.Move(0, -scaling[1]) etisserant@0: elif keycode == WXK_DOWN and self.SelectedElement: etisserant@0: self.SelectedElement.Move(0, scaling[1]) etisserant@0: self.Refresh() etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Adding element functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def AddInitialStep(self, pos): etisserant@0: dialog = wxTextEntryDialog(self.Parent, "Add a new initial step", "Please enter step name", "", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: id = self.GetNewId() etisserant@0: name = dialog.GetValue() etisserant@0: step = SFC_Step(self, name, True, id) etisserant@0: min_width, min_height = step.GetMinSize() etisserant@0: step.SetPosition(pos.x, pos.y) etisserant@0: width, height = step.GetSize() etisserant@0: step.SetSize(max(min_width, width), max(min_height, height)) etisserant@0: self.Blocks.append(step) etisserant@0: self.Elements.append(step) etisserant@0: self.Controler.AddCurrentElementEditingStep(id) etisserant@0: self.RefreshStepModel(step) etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def AddStep(self): etisserant@0: if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step): etisserant@0: dialog = wxTextEntryDialog(self.Parent, "Add a new step", "Please enter step name", "", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: name = dialog.GetValue() etisserant@0: if self.SelectedElement in self.Wires: etisserant@0: self.SelectedElement.SetSelectedSegment(None) etisserant@0: previous = self.SelectedElement.EndConnected etisserant@0: next = self.SelectedElement.StartConnected etisserant@0: self.SelectedElement.Clean() etisserant@0: self.Wires.remove(self.SelectedElement) etisserant@0: self.Elements.remove(self.SelectedElement) etisserant@0: else: etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: if connectors["output"]: etisserant@0: previous = connectors["output"] etisserant@0: wires = previous.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: next = wire.StartConnected etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: else: etisserant@0: self.SelectedElement.AddOutput() etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: self.RefreshStepModel(self.SelectedElement) etisserant@0: previous = connectors["output"] etisserant@0: next = None etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]: etisserant@0: transition = self.CreateTransition(previous) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: step = self.CreateStep(name, transition_connectors["output"], next) etisserant@0: else: etisserant@0: step = self.CreateStep(name, previous) etisserant@0: step.AddOutput() etisserant@0: step.RefreshModel() etisserant@0: step_connectors = step.GetConnectors() etisserant@0: transition = self.CreateTransition(step_connectors["output"], next) etisserant@0: if self.SelectedElement in self.Wires: etisserant@0: self.SelectedElement = wire etisserant@0: self.SelectedElement.SetSelectedSegment(0) etisserant@0: else: etisserant@0: self.SelectedElement.SetSelected(False) etisserant@0: self.SelectedElement = step etisserant@0: self.SelectedElement.SetSelected(True) etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def AddStepAction(self): etisserant@0: if isinstance(self.SelectedElement, SFC_Step): etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: if not connectors["action"]: etisserant@0: dialog = ActionBlockDialog(self.Parent) etisserant@0: dialog.SetQualifierList(self.Controler.GetQualifierTypes()) etisserant@0: dialog.SetActionList(self.Controler.GetCurrentElementEditingActions()) etisserant@0: dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars()) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: actions = dialog.GetValues() etisserant@0: self.SelectedElement.AddAction() etisserant@0: self.RefreshStepModel(self.SelectedElement) etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: pos = connectors["action"].GetPosition(False) etisserant@0: id = self.GetNewId() etisserant@0: actionblock = SFC_ActionBlock(self, [], id) etisserant@0: actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2) etisserant@0: actionblock_connector = actionblock.GetConnector() etisserant@0: wire = self.ConnectConnectors(actionblock_connector, connectors["action"]) etisserant@0: wire.SetPoints([wxPoint(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wxPoint(pos.x, pos.y)]) etisserant@0: actionblock.SetActions(actions) etisserant@0: self.Blocks.append(actionblock) etisserant@0: self.Elements.append(actionblock) etisserant@0: self.Controler.AddCurrentElementEditingActionBlock(id) etisserant@0: self.RefreshActionBlockModel(actionblock) etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def AddDivergence(self): etisserant@0: if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step): etisserant@0: dialog = DivergenceCreateDialog(self.Parent) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: value = dialog.GetValues() etisserant@0: if value["type"] == SELECTION_DIVERGENCE: etisserant@0: if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step): etisserant@0: self.SelectedElement.SetSelectedSegment(None) etisserant@0: previous = self.SelectedElement.EndConnected etisserant@0: next = self.SelectedElement.StartConnected etisserant@0: self.SelectedElement.Clean() etisserant@0: self.Wires.remove(self.SelectedElement) etisserant@0: self.Elements.remove(self.SelectedElement) etisserant@0: self.SelectedElement = None etisserant@0: elif isinstance(self.SelectedElement, SFC_Step): etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: if connectors["output"]: etisserant@0: previous = connectors["output"] etisserant@0: wires = previous.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: next = wire.StartConnected etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: else: etisserant@0: self.SelectedElement.AddOutput() etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: self.RefreshStepModel(self.SelectedElement) etisserant@0: previous = connectors["output"] etisserant@0: next = None etisserant@0: else: etisserant@0: return etisserant@0: id = self.GetNewId() etisserant@0: divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id) etisserant@0: pos = previous.GetPosition(False) etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: wire_size = GetWireSize(previous_block) etisserant@0: divergence.SetPosition(pos.x, pos.y + wire_size) etisserant@0: divergence_connectors = divergence.GetConnectors() etisserant@0: wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) etisserant@0: previous_block.RefreshOutputPosition() etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)]) etisserant@0: self.Blocks.append(divergence) etisserant@0: self.Elements.append(divergence) etisserant@0: self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) etisserant@0: self.RefreshDivergenceModel(divergence) etisserant@0: for index, connector in enumerate(divergence_connectors["outputs"]): etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, connector) etisserant@0: pos = connector.GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: next_block = next.GetParentBlock() etisserant@0: divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) etisserant@0: divergence.RefreshConnectedPosition(connector) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: next_block.RefreshModel() etisserant@0: next = None etisserant@0: else: etisserant@0: transition = self.CreateTransition(connector) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: step = self.CreateStep("Step", transition_connectors["output"]) etisserant@0: elif value["type"] == SIMULTANEOUS_DIVERGENCE: etisserant@0: if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition): etisserant@0: self.SelectedElement.SetSelectedSegment(None) etisserant@0: previous = self.SelectedElement.EndConnected etisserant@0: next = self.SelectedElement.StartConnected etisserant@0: self.SelectedElement.Clean() etisserant@0: self.Wires.remove(self.SelectedElement) etisserant@0: self.Elements.remove(self.SelectedElement) etisserant@0: self.SelectedElement = None etisserant@0: elif isinstance(self.SelectedElement, SFC_Step): etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: if connectors["output"]: etisserant@0: previous = connectors["output"] etisserant@0: wires = previous.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: next = wire.StartConnected etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: else: etisserant@0: self.SelectedElement.AddOutput() etisserant@0: connectors = self.SelectedElement.GetConnectors() etisserant@0: self.RefreshStepModel(self.SelectedElement) etisserant@0: previous = connectors["output"] etisserant@0: next = None etisserant@0: transition = self.CreateTransition(previous) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: previous = transition_connectors["output"] etisserant@0: else: etisserant@0: return etisserant@0: id = self.GetNewId() etisserant@0: divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id) etisserant@0: pos = previous.GetPosition(False) etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: wire_size = GetWireSize(previous_block) etisserant@0: divergence.SetPosition(pos.x, pos.y + wire_size) etisserant@0: divergence_connectors = divergence.GetConnectors() etisserant@0: wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous) etisserant@0: previous_block.RefreshOutputPosition() etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)]) etisserant@0: self.Blocks.append(divergence) etisserant@0: self.Elements.append(divergence) etisserant@0: self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) etisserant@0: self.RefreshDivergenceModel(divergence) etisserant@0: for index, connector in enumerate(divergence_connectors["outputs"]): etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, connector) etisserant@0: pos = connector.GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: next_block = next.GetParentBlock() etisserant@0: divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) etisserant@0: divergence.RefreshConnectedPosition(connector) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: next_block.RefreshModel() etisserant@0: next = None etisserant@0: else: etisserant@0: step = self.CreateStep("Step", connector) etisserant@0: elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1: etisserant@0: next = None etisserant@0: for element in self.SelectedElement.GetElements(): etisserant@0: connectors = element.GetConnectors() etisserant@0: if not isinstance(element, SFC_Step) or connectors["output"] and next: etisserant@0: return etisserant@0: elif connectors["output"] and not next: etisserant@0: wires = connectors["output"].GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: if value["type"] == SELECTION_CONVERGENCE: etisserant@0: transition = wires[0][0].StartConnected.GetParentBlock() etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: wires = transition_connectors["output"].GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: next = wire.StartConnected etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: inputs = [] etisserant@0: for input in self.SelectedElement.GetElements(): etisserant@0: input_connectors = input.GetConnectors() etisserant@0: if not input_connectors["output"]: etisserant@0: input.AddOutput() etisserant@0: input.RefreshModel() etisserant@0: input_connectors = input.GetConnectors() etisserant@0: if value["type"] == SELECTION_CONVERGENCE: etisserant@0: transition = self.CreateTransition(input_connectors["output"]) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: inputs.append(transition_connectors["output"]) etisserant@0: else: etisserant@0: inputs.append(input_connectors["output"]) etisserant@0: elif value["type"] == SELECTION_CONVERGENCE: etisserant@0: wires = input_connectors["output"].GetWires() etisserant@0: transition = wires[0][0].StartConnected.GetParentBlock() etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: inputs.append(transition_connectors["output"]) etisserant@0: else: etisserant@0: inputs.append(input_connectors["output"]) etisserant@0: id = self.GetNewId() etisserant@0: divergence = SFC_Divergence(self, value["type"], len(inputs), id) etisserant@0: pos = inputs[0].GetPosition(False) etisserant@0: divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) etisserant@0: divergence_connectors = divergence.GetConnectors() etisserant@0: for i, input in enumerate(inputs): etisserant@0: pos = input.GetPosition(False) etisserant@0: wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input) etisserant@0: wire_size = GetWireSize(input) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)]) etisserant@0: input_block = input.GetParentBlock() etisserant@0: input_block.RefreshOutputPosition() etisserant@0: divergence.RefreshPosition() etisserant@0: pos = divergence_connectors["outputs"][0].GetRelPosition() etisserant@0: divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x) etisserant@0: self.Blocks.append(divergence) etisserant@0: self.Elements.append(divergence) etisserant@0: self.Controler.AddCurrentElementEditingDivergence(id, value["type"]) etisserant@0: self.RefreshDivergenceModel(divergence) etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0]) etisserant@0: pos = divergence_connectors["outputs"][0].GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: next_block = next.GetParentBlock() etisserant@0: divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y)) etisserant@0: divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0]) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: next_block.RefreshModel() etisserant@0: else: etisserant@0: if value["type"] == SELECTION_CONVERGENCE: etisserant@0: previous = divergence_connectors["outputs"][0] etisserant@0: else: etisserant@0: transition = self.CreateTransition(divergence_connectors["outputs"][0]) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: previous = transition_connectors["output"] etisserant@0: self.CreateStep("Step", previous) etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def AddDivergenceBranch(self, divergence): etisserant@0: if isinstance(divergence, SFC_Divergence): etisserant@0: type = divergence.GetType() etisserant@0: if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: etisserant@0: divergence.AddBranch() etisserant@0: divergence_connectors = divergence.GetConnectors() etisserant@0: if type == SELECTION_DIVERGENCE: etisserant@0: transition = self.CreateTransition(divergence_connectors["outputs"][-1]) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: previous = transition_connectors["output"] etisserant@0: else: etisserant@0: previous = divergence_connectors["outputs"][-1] etisserant@0: step = self.CreateStep("Step", previous) etisserant@0: self.Refresh() etisserant@0: etisserant@0: def AddJump(self): etisserant@0: if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output: etisserant@0: choices = [] etisserant@0: for block in self.Blocks: etisserant@0: if isinstance(block, SFC_Step): etisserant@0: choices.append(block.GetName()) etisserant@0: dialog = wxSingleChoiceDialog(self.Parent, "Add a new jump", "Please choose a target", choices, wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: value = dialog.GetStringSelection() etisserant@0: self.SelectedElement.AddOutput() etisserant@0: self.RefreshStepModel(self.SelectedElement) etisserant@0: step_connectors = self.SelectedElement.GetConnectors() etisserant@0: transition = self.CreateTransition(step_connectors["output"]) etisserant@0: transition_connectors = transition.GetConnectors() etisserant@0: id = self.GetNewId() etisserant@0: jump = SFC_Jump(self, value, id) etisserant@0: pos = transition_connectors["output"].GetPosition(False) etisserant@0: jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE) etisserant@0: self.Blocks.append(jump) etisserant@0: self.Elements.append(jump) etisserant@0: self.Controler.AddCurrentElementEditingJump(id) etisserant@0: jump_connector = jump.GetConnector() etisserant@0: wire = self.ConnectConnectors(jump_connector, transition_connectors["output"]) etisserant@0: transition.RefreshOutputPosition() etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wxPoint(pos.x, pos.y)]) etisserant@0: self.RefreshJumpModel(jump) etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def AddComment(self, bbox): etisserant@0: dialog = wxTextEntryDialog(self.Parent, "Add a new comment", "Please enter comment text", "", wxOK|wxCANCEL|wxTE_MULTILINE) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: value = dialog.GetValue() etisserant@0: id = self.GetNewId() etisserant@0: comment = Comment(self, value, id) etisserant@0: comment.SetPosition(bbox.x, bbox.y) etisserant@0: min_width, min_height = comment.GetMinSize() etisserant@0: comment.SetSize(max(min_width,bbox.width),max(min_height,bbox.height)) etisserant@0: self.Elements.append(comment) etisserant@0: self.Controler.AddCurrentElementEditingComment(id) etisserant@0: self.RefreshCommentModel(comment) etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def EditStepContent(self, step): etisserant@0: dialog = wxTextEntryDialog(self.Parent, "Edit step name", "Please enter step name", step.GetName(), wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: value = dialog.GetValue() etisserant@0: step.SetName(value) etisserant@0: min_size = step.GetMinSize() etisserant@0: size = step.GetSize() etisserant@0: step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1])) etisserant@0: step.RefreshModel() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def EditTransitionContent(self, transition): etisserant@0: dialog = TransitionContentDialog(self.Parent) etisserant@0: dialog.SetTransitions(self.Controler.GetCurrentElementEditingTransitions()) etisserant@0: dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition()}) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: values = dialog.GetValues() etisserant@0: transition.SetType(values["type"]) etisserant@0: transition.SetCondition(values["value"]) etisserant@0: transition.RefreshModel() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def EditJumpContent(self, jump): etisserant@0: choices = [] etisserant@0: for block in self.Blocks: etisserant@0: if isinstance(block, SFC_Step): etisserant@0: choices.append(block.GetName()) etisserant@0: dialog = wxSingleChoiceDialog(self.Parent, "Edit jump target", "Please choose a target", choices, wxOK|wxCANCEL) etisserant@0: dialog.SetSelection(choices.index(jump.GetTarget())) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: value = dialog.GetStringSelection() etisserant@0: jump.SetTarget(value) etisserant@0: jump.RefreshModel() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def EditActionBlockContent(self, actionblock): etisserant@0: dialog = ActionBlockDialog(self.Parent) etisserant@0: dialog.SetQualifierList(self.Controler.GetQualifierTypes()) etisserant@0: dialog.SetActionList(self.Controler.GetCurrentElementEditingActions()) etisserant@0: dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars()) etisserant@0: dialog.SetValues(actionblock.GetActions()) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: actions = dialog.GetValues() etisserant@0: actionblock.SetActions(actions) etisserant@0: actionblock.RefreshModel() etisserant@0: self.Refresh() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Delete element functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def DeleteStep(self, step): etisserant@0: step_connectors = step.GetConnectors() etisserant@0: if not step.GetInitial() or not step_connectors["output"]: etisserant@0: previous = step.GetPreviousConnector() etisserant@0: if previous: etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: else: etisserant@0: previous_block = None etisserant@0: next = step.GetNextConnector() etisserant@0: if next: etisserant@0: next_block = next.GetParentBlock() etisserant@0: else: etisserant@0: next_block = None etisserant@0: if isinstance(next_block, SFC_Transition): etisserant@0: self.RemoveTransition(next_block) etisserant@0: next = step.GetNextConnector() etisserant@0: if next: etisserant@0: next_block = next.GetParentBlock() etisserant@0: else: etisserant@0: next_block = None etisserant@0: elif isinstance(previous_block, SFC_Transition): etisserant@0: self.RemoveTransition(previous_block) etisserant@0: previous = step.GetPreviousConnector() etisserant@0: if previous: etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: else: etisserant@0: previous_block = None etisserant@0: wire = self.RemoveStep(step) etisserant@0: self.SelectedElement = None etisserant@0: if next_block: etisserant@0: if isinstance(next_block, SFC_Divergence) and next_block.GetType() == SIMULTANEOUS_CONVERGENCE and isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SIMULTANEOUS_DIVERGENCE: etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: next_block.RemoveBranch(next) etisserant@0: if next_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(next_block) etisserant@0: else: etisserant@0: next_block.RefreshModel() etisserant@0: previous_block.RemoveBranch(previous) etisserant@0: if previous_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: previous_block.RefreshModel() etisserant@0: else: etisserant@0: pos = previous.GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: wire_size = GetWireSize(previous_block) etisserant@0: previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y)) etisserant@0: wire.SetPoints([wxPoint(pos.x, pos.y + wire_size), wxPoint(pos.x, pos.y)]) etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.RefreshPosition() etisserant@0: next_block.RefreshModel() etisserant@0: else: etisserant@0: if isinstance(previous_block, SFC_Step): etisserant@0: previous_block.RemoveOutput() etisserant@0: self.RefreshStepModel(previous_block) etisserant@0: elif isinstance(previous_block, SFC_Divergence): etisserant@0: if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: previous_block.RemoveBranch(previous) etisserant@0: if previous_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: self.RefreshDivergenceModel(previous_block) etisserant@0: etisserant@0: def DeleteTransition(self, transition): etisserant@0: previous = transition.GetPreviousConnector() etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: next = transition.GetNextConnector() etisserant@0: next_block = next.GetParentBlock() etisserant@0: if isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SELECTION_DIVERGENCE and isinstance(next_block, SFC_Divergence) and next_block.GetType() == SELECTION_CONVERGENCE: etisserant@0: wires = previous.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: wires = next.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: transition.Clean() etisserant@0: self.Blocks.remove(transition) etisserant@0: self.Elements.remove(transition) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(transition.GetId()) etisserant@0: previous_block.RemoveBranch(previous) etisserant@0: if previous_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: self.RefreshDivergenceModel(previous_block) etisserant@0: next_block.RemoveBranch(next) etisserant@0: if next_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(next_block) etisserant@0: else: etisserant@0: self.RefreshDivergenceModel(next_block) etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: etisserant@0: def DeleteDivergence(self, divergence): etisserant@0: connectors = divergence.GetConnectors() etisserant@0: type = divergence.GetType() etisserant@0: if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: wires = connectors["outputs"][0].GetWires() etisserant@0: if len(wires) > 1: etisserant@0: return etisserant@0: elif len(wires) == 1: etisserant@0: next = wires[0][0].StartConnected etisserant@0: next_block = next.GetParentBlock() etisserant@0: wire = wires[0][0] etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: else: etisserant@0: next = None etisserant@0: next_block = None etisserant@0: for index, connector in enumerate(connectors["inputs"]): etisserant@0: if next and index == 0: etisserant@0: wires = connector.GetWires() etisserant@0: wire = wires[0][0] etisserant@0: previous = wires[0][0].EndConnected etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: else: etisserant@0: if type == SELECTION_CONVERGENCE: etisserant@0: wires = connector.GetWires() etisserant@0: previous_block = wires[0][0].EndConnected.GetParentBlock() etisserant@0: self.RemoveTransition(previous_block) etisserant@0: wires = connector.GetWires() etisserant@0: wire = wires[0][0] etisserant@0: previous_connector = wire.EndConnected etisserant@0: previous_block = previous_connector.GetParentBlock() etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: if isinstance(previous_block, SFC_Step): etisserant@0: previous_block.RemoveOutput() etisserant@0: self.RefreshStepModel(previous_block) etisserant@0: elif isinstance(previous_block, SFC_Divergence): etisserant@0: if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: etisserant@0: previous_block.RemoveBranch(previous_connector) etisserant@0: if previous_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: self.RefreshDivergenceModel(previous_block) etisserant@0: else: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: divergence.Clean() etisserant@0: self.Blocks.remove(divergence) etisserant@0: self.Elements.remove(divergence) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(divergence.GetId()) etisserant@0: if next: etisserant@0: wire = self.ConnectConnectors(next, previous) etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: pos = previous.GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: wire_size = GetWireSize(previous_block) etisserant@0: previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y)) etisserant@0: wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), etisserant@0: wxPoint(previous_pos.x, previous_pos.y)]) etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.RefreshPosition() etisserant@0: next_block.RefreshModel() etisserant@0: elif divergence.GetBranchNumber() == 1: etisserant@0: wires = connectors["inputs"][0].GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: previous = wire.EndConnected etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: wires = connectors["outputs"][0].GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: next = wire.StartConnected etisserant@0: next_block = next.GetParentBlock() etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: divergence.Clean() etisserant@0: self.Blocks.remove(divergence) etisserant@0: self.Elements.remove(divergence) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(divergence.GetId()) etisserant@0: wire = self.ConnectConnectors(next, previous) etisserant@0: previous_pos = previous.GetPosition(False) etisserant@0: next_pos = next.GetPosition(False) etisserant@0: wire_size = GetWireSize(previous_block) etisserant@0: previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y)) etisserant@0: wire.SetPoints([wxPoint(previous_pos.x, previous_pos.y + wire_size), etisserant@0: wxPoint(previous_pos.x, previous_pos.y)]) etisserant@0: if isinstance(next_block, SFC_Divergence): etisserant@0: next_block.RefreshPosition() etisserant@0: next_block.RefreshModel() etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: etisserant@0: def DeleteJump(self, jump): etisserant@0: previous = jump.GetPreviousConnector() etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: if isinstance(previous_block, SFC_Transition): etisserant@0: self.RemoveTransition(previous_block) etisserant@0: previous = jump.GetPreviousConnector() etisserant@0: if previous: etisserant@0: previous_block = previous.GetParentBlock() etisserant@0: else: etisserant@0: previous_block = None etisserant@0: wires = previous.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: jump.Clean() etisserant@0: self.Blocks.remove(jump) etisserant@0: self.Elements.remove(jump) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(jump.GetId()) etisserant@0: if isinstance(previous_block, SFC_Step): etisserant@0: previous_block.RemoveOutput() etisserant@0: self.RefreshStepModel(previous_block) etisserant@0: elif isinstance(previous_block, SFC_Divergence): etisserant@0: if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: previous_block.RemoveBranch(previous) etisserant@0: if previous_block.GetBranchNumber() < 2: etisserant@0: self.DeleteDivergence(previous_block) etisserant@0: else: etisserant@0: previous_block.RefreshModel() etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: etisserant@0: def DeleteActionBlock(self, actionblock): etisserant@0: connector = actionblock.GetConnector() etisserant@0: wires = connector.GetWires() etisserant@0: if len(wires) != 1: etisserant@0: return etisserant@0: wire = wires[0][0] etisserant@0: step = wire.EndConnected.GetParentBlock() etisserant@0: wire.Clean() etisserant@0: self.Wires.remove(wire) etisserant@0: self.Elements.remove(wire) etisserant@0: actionblock.Clean() etisserant@0: self.Blocks.remove(actionblock) etisserant@0: self.Elements.remove(actionblock) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(actionblock.GetId()) etisserant@0: step.RemoveAction() etisserant@0: self.RefreshStepModel(step) etisserant@0: step.RefreshOutputPosition() etisserant@0: step.RefreshOutputModel(True) etisserant@0: self.Parent.RefreshProjectTree() etisserant@0: etisserant@0: def DeleteComment(self, comment): etisserant@0: self.Elements.remove(self.SelectedElement) etisserant@0: self.Controler.RemoveCurrentElementEditingInstance(comment.GetId()) etisserant@0: etisserant@0: def DeleteWire(self, wire): etisserant@0: pass etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Edit Transition Content Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: [wxID_TRANSITIONCONTENTDIALOG, wxID_TRANSITIONCONTENTDIALOGMAINPANEL, etisserant@0: wxID_TRANSITIONCONTENTDIALOGREFERENCE, wxID_TRANSITIONCONTENTDIALOGINLINE, etisserant@0: wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(6)] etisserant@0: etisserant@0: class TransitionContentDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_TRANSITIONCONTENTDIALOG, etisserant@0: name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Edit transition') etisserant@0: self.SetClientSize(wx.Size(300, 200)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_TRANSITIONCONTENTDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(300, 200), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.radioButton1 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, etisserant@0: label='Reference', name='radioButton1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(114, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON1, self.OnTypeChanged) etisserant@0: self.radioButton1.SetValue(True) etisserant@0: etisserant@0: self.Reference = wx.Choice(id=wxID_TRANSITIONCONTENTDIALOGREFERENCE, etisserant@0: name='Reference', parent=self.MainPanel, pos=wx.Point(48, 48), etisserant@0: size=wx.Size(200, 24), style=0) etisserant@0: etisserant@0: self.radioButton2 = wx.RadioButton(id=wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, etisserant@0: label='Inline', name='radioButton2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 72), size=wx.Size(114, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_TRANSITIONCONTENTDIALOGRADIOBUTTON2, self.OnTypeChanged) etisserant@0: self.radioButton2.SetValue(False) etisserant@0: etisserant@0: self.Inline = wx.TextCtrl(id=wxID_TRANSITIONCONTENTDIALOGINLINE, etisserant@0: name='Inline', parent=self.MainPanel, pos=wx.Point(48, 96), etisserant@0: size=wx.Size(200, 24), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) etisserant@0: etisserant@0: def OnOK(self, event): etisserant@0: error = [] etisserant@0: if self.radioButton1.GetValue() and self.Reference.GetStringSelection() == "": etisserant@0: error.append("Reference") etisserant@0: if self.radioButton2.GetValue() and self.Inline.GetValue() == "": etisserant@0: error.append("Inline") etisserant@0: if len(error) > 0: etisserant@0: text = "" etisserant@0: for i, item in enumerate(error): etisserant@0: if i == 0: etisserant@0: text += item etisserant@0: elif i == len(error) - 1: etisserant@0: text += " and %s"%item etisserant@0: else: etisserant@0: text += ", %s"%item etisserant@0: message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: self.EndModal(wxID_OK) etisserant@0: etisserant@0: def OnTypeChanged(self, event): etisserant@0: if self.radioButton1.GetValue(): etisserant@0: self.Reference.Enable(True) etisserant@0: self.Inline.Enable(False) etisserant@0: else: etisserant@0: self.Reference.Enable(False) etisserant@0: self.Inline.Enable(True) etisserant@0: event.Skip() etisserant@0: etisserant@0: def SetTransitions(self, transitions): etisserant@0: for transition in transitions: etisserant@0: self.Reference.Append(transition) etisserant@0: etisserant@0: def SetValues(self, values): etisserant@0: if values["type"] == "reference": etisserant@0: self.radioButton1.SetValue(True) etisserant@0: self.radioButton2.SetValue(False) etisserant@0: self.Reference.Enable(True) etisserant@0: self.Inline.Enable(False) etisserant@0: self.Reference.SetStringSelection(values["value"]) etisserant@0: elif values["type"] == "inline": etisserant@0: self.radioButton1.SetValue(False) etisserant@0: self.radioButton2.SetValue(True) etisserant@0: self.Reference.Enable(False) etisserant@0: self.Inline.Enable(True) etisserant@0: self.Inline.SetValue(values["value"]) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: if self.radioButton1.GetValue(): etisserant@0: values["type"] = "reference" etisserant@0: values["value"] = self.Reference.GetStringSelection() etisserant@0: else: etisserant@0: values["type"] = "inline" etisserant@0: values["value"] = self.Inline.GetValue() etisserant@0: return values etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create New Divergence Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: [wxID_DIVERGENCECREATEDIALOG, wxID_DIVERGENCECREATEDIALOGMAINPANEL, etisserant@0: wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, etisserant@0: wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, etisserant@0: wxID_DIVERGENCECREATEDIALOGSEQUENCES, wxID_DIVERGENCECREATEDIALOGPREVIEW, etisserant@0: wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, etisserant@0: wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(11)] etisserant@0: etisserant@0: class DivergenceCreateDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_DIVERGENCECREATEDIALOG, etisserant@0: name='DivergencePropertiesDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Create a new divergence or convergence') etisserant@0: self.SetClientSize(wx.Size(500, 260)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(600, 220), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT1, etisserant@0: label='Type:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(200, 17), style=0) etisserant@0: etisserant@0: self.radioButton1 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, etisserant@0: label='Selection Divergence', name='radioButton1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 48), size=wx.Size(200, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON1, self.OnTypeChanged) etisserant@0: self.radioButton1.SetValue(True) etisserant@0: etisserant@0: self.radioButton2 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, etisserant@0: label='Selection Convergence', name='radioButton2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 72), size=wx.Size(200, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON2, self.OnTypeChanged) etisserant@0: self.radioButton2.SetValue(False) etisserant@0: etisserant@0: self.radioButton3 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, etisserant@0: label='Simultaneous Divergence', name='radioButton3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 96), size=wx.Size(200, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON3, self.OnTypeChanged) etisserant@0: self.radioButton3.SetValue(False) etisserant@0: etisserant@0: self.radioButton4 = wx.RadioButton(id=wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, etisserant@0: label='Simultaneous Convergence', name='radioButton4', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 120), size=wx.Size(200, 24), style=0) etisserant@0: EVT_RADIOBUTTON(self, wxID_DIVERGENCECREATEDIALOGRADIOBUTTON4, self.OnTypeChanged) etisserant@0: self.radioButton4.SetValue(False) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT2, etisserant@0: label='Number of sequences:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 150), size=wx.Size(200, 17), style=0) etisserant@0: etisserant@0: self.Sequences = wx.SpinCtrl(id=wxID_DIVERGENCECREATEDIALOGSEQUENCES, etisserant@0: name='Sequences', parent=self.MainPanel, pos=wx.Point(24, 174), etisserant@0: size=wx.Size(200, 24), style=0, min=2, max=20) etisserant@0: EVT_SPINCTRL(self, wxID_DIVERGENCECREATEDIALOGSEQUENCES, self.OnSequencesChanged) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_DIVERGENCECREATEDIALOGSTATICTEXT3, etisserant@0: label='Preview:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(250, 24), size=wx.Size(100, 17), style=0) etisserant@0: etisserant@0: self.Preview = wx.Panel(id=wxID_DIVERGENCECREATEDIALOGPREVIEW, etisserant@0: name='Preview', parent=self.MainPanel, pos=wx.Point(250, 48), etisserant@0: size=wx.Size(225, 150), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) etisserant@0: self.Preview.SetBackgroundColour(wxColour(255,255,255)) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: self.Divergence = None etisserant@0: etisserant@0: EVT_PAINT(self, self.OnPaint) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = {} etisserant@0: if self.radioButton1.GetValue(): etisserant@0: values["type"] = SELECTION_DIVERGENCE etisserant@0: elif self.radioButton2.GetValue(): etisserant@0: values["type"] = SELECTION_CONVERGENCE etisserant@0: elif self.radioButton3.GetValue(): etisserant@0: values["type"] = SIMULTANEOUS_DIVERGENCE etisserant@0: else: etisserant@0: values["type"] = SIMULTANEOUS_CONVERGENCE etisserant@0: values["number"] = self.Sequences.GetValue() etisserant@0: return values etisserant@0: etisserant@0: def OnTypeChanged(self, event): etisserant@0: self.RefreshPreview() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSequencesChanged(self, event): etisserant@0: self.RefreshPreview() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshPreview(self): etisserant@0: dc = wxClientDC(self.Preview) etisserant@0: dc.Clear() etisserant@0: if self.radioButton1.GetValue(): etisserant@0: self.Divergence = SFC_Divergence(self.Preview, SELECTION_DIVERGENCE, self.Sequences.GetValue()) etisserant@0: elif self.radioButton2.GetValue(): etisserant@0: self.Divergence = SFC_Divergence(self.Preview, SELECTION_CONVERGENCE, self.Sequences.GetValue()) etisserant@0: elif self.radioButton3.GetValue(): etisserant@0: self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_DIVERGENCE, self.Sequences.GetValue()) etisserant@0: else: etisserant@0: self.Divergence = SFC_Divergence(self.Preview, SIMULTANEOUS_CONVERGENCE, self.Sequences.GetValue()) etisserant@0: width, height = self.Divergence.GetSize() etisserant@0: clientsize = self.Preview.GetClientSize() etisserant@0: x = (clientsize.width - width) / 2 etisserant@0: y = (clientsize.height - height) / 2 etisserant@0: self.Divergence.SetPosition(x, y) etisserant@0: self.Divergence.Draw(dc) etisserant@0: etisserant@0: def OnPaint(self, event): etisserant@0: self.RefreshPreview() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Action Block Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: class ActionTable(wxPyGridTableBase): etisserant@0: etisserant@0: """ etisserant@0: A custom wxGrid Table using user supplied data etisserant@0: """ etisserant@0: def __init__(self, parent, data, colnames): etisserant@0: # The base class must be initialized *first* etisserant@0: wxPyGridTableBase.__init__(self) etisserant@0: self.data = data etisserant@0: self.colnames = colnames etisserant@0: self.Parent = parent etisserant@0: # XXX etisserant@0: # we need to store the row length and collength to etisserant@0: # see if the table has changed size etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: etisserant@0: def GetNumberCols(self): etisserant@0: return len(self.colnames) etisserant@0: etisserant@0: def GetNumberRows(self): etisserant@0: return len(self.data) etisserant@0: etisserant@0: def GetColLabelValue(self, col): etisserant@0: if col < len(self.colnames): etisserant@0: return self.colnames[col] etisserant@0: etisserant@0: def GetRowLabelValues(self, row): etisserant@0: return row etisserant@0: etisserant@0: def GetValue(self, row, col): etisserant@0: if row < self.GetNumberRows(): etisserant@0: name = str(self.data[row].get(self.GetColLabelValue(col), "")) etisserant@0: return name etisserant@0: etisserant@0: def GetValueByName(self, row, colname): etisserant@0: return self.data[row].get(colname) etisserant@0: etisserant@0: def SetValue(self, row, col, value): etisserant@0: if col < len(self.colnames): etisserant@0: self.data[row][self.GetColLabelValue(col)] = value etisserant@0: etisserant@0: def ResetView(self, grid): etisserant@0: """ etisserant@0: (wxGrid) -> Reset the grid view. Call this to etisserant@0: update the grid if rows and columns have been added or deleted etisserant@0: """ etisserant@0: grid.BeginBatch() etisserant@0: for current, new, delmsg, addmsg in [ etisserant@0: (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), etisserant@0: (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), etisserant@0: ]: etisserant@0: if new < current: etisserant@0: msg = wxGridTableMessage(self,delmsg,new,current-new) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: elif new > current: etisserant@0: msg = wxGridTableMessage(self,addmsg,new-current) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: self.UpdateValues(grid) etisserant@0: grid.EndBatch() etisserant@0: etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: # update the column rendering scheme etisserant@0: self._updateColAttrs(grid) etisserant@0: etisserant@0: # update the scrollbars and the displayed part of the grid etisserant@0: grid.AdjustScrollbars() etisserant@0: grid.ForceRefresh() etisserant@0: etisserant@0: def UpdateValues(self, grid): etisserant@0: """Update all displayed values""" etisserant@0: # This sends an event to the grid table to update all of the values etisserant@0: msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: etisserant@0: def _updateColAttrs(self, grid): etisserant@0: """ etisserant@0: wxGrid -> update the column attributes to add the etisserant@0: appropriate renderer given the column name. etisserant@0: etisserant@0: Otherwise default to the default renderer. etisserant@0: """ etisserant@0: etisserant@0: for col in range(self.GetNumberCols()): etisserant@0: attr = wxGridCellAttr() etisserant@0: attr.SetAlignment(self.Parent.ColAlignements[col], wxALIGN_CENTRE) etisserant@0: grid.SetColAttr(col, attr) etisserant@0: grid.SetColSize(col, self.Parent.ColSizes[col]) etisserant@0: etisserant@0: typelist = None etisserant@0: accesslist = None etisserant@0: for row in range(self.GetNumberRows()): etisserant@0: for col in range(self.GetNumberCols()): etisserant@0: editor = None etisserant@0: renderer = None etisserant@0: readonly = False etisserant@0: colname = self.GetColLabelValue(col) etisserant@0: if colname == "Qualifier": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.QualifierList) etisserant@0: if colname == "Duration": etisserant@0: editor = wxGridCellTextEditor() etisserant@0: renderer = wxGridCellStringRenderer() etisserant@0: if self.Parent.DurationList[self.data[row]["Qualifier"]]: etisserant@0: readonly = False etisserant@0: else: etisserant@0: readonly = True etisserant@0: self.data[row]["Duration"] = "" etisserant@0: elif colname == "Type": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.TypeList) etisserant@0: elif colname == "Value": etisserant@0: type = self.data[row]["Type"] etisserant@0: if type == "Action": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.ActionList) etisserant@0: elif type == "Variable": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.VariableList) etisserant@0: elif type == "Inline": etisserant@0: editor = wxGridCellTextEditor() etisserant@0: renderer = wxGridCellStringRenderer() etisserant@0: elif colname == "Indicator": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.VariableList) etisserant@0: etisserant@0: grid.SetCellEditor(row, col, editor) etisserant@0: grid.SetCellRenderer(row, col, renderer) etisserant@0: grid.SetReadOnly(row, col, readonly) etisserant@0: etisserant@0: grid.SetCellBackgroundColour(row, col, wxWHITE) etisserant@0: etisserant@0: def SetData(self, data): etisserant@0: self.data = data etisserant@0: etisserant@0: def GetData(self): etisserant@0: return self.data etisserant@0: etisserant@0: def GetCurrentIndex(self): etisserant@0: return self.CurrentIndex etisserant@0: etisserant@0: def SetCurrentIndex(self, index): etisserant@0: self.CurrentIndex = index etisserant@0: etisserant@0: def AppendRow(self, row_content): etisserant@0: self.data.append(row_content) etisserant@0: etisserant@0: def RemoveRow(self, row_index): etisserant@0: self.data.pop(row_index) etisserant@0: etisserant@0: def MoveRow(self, row_index, move, grid): etisserant@0: new_index = max(0, min(row_index + move, len(self.data) - 1)) etisserant@0: if new_index != row_index: etisserant@0: self.data.insert(new_index, self.data.pop(row_index)) etisserant@0: grid.SetGridCursor(new_index, grid.GetGridCursorCol()) etisserant@0: etisserant@0: def Empty(self): etisserant@0: self.data = [] etisserant@0: self.editors = [] etisserant@0: etisserant@0: [wxID_ACTIONBLOCKDIALOG, wxID_ACTIONBLOCKDIALOGMAINPANEL, etisserant@0: wxID_ACTIONBLOCKDIALOGVARIABLESGRID, wxID_ACTIONBLOCKDIALOGSTATICTEXT1, etisserant@0: wxID_ACTIONBLOCKDIALOGADDBUTTON,wxID_ACTIONBLOCKDIALOGDELETEBUTTON, etisserant@0: wxID_ACTIONBLOCKDIALOGUPBUTTON, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(8)] etisserant@0: etisserant@0: class ActionBlockDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_ACTIONBLOCKDIALOG, etisserant@0: name='ActionBlockDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Edit action block properties') etisserant@0: self.SetClientSize(wx.Size(500, 300)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_ACTIONBLOCKDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(500, 300), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_ACTIONBLOCKDIALOGSTATICTEXT1, etisserant@0: label='Actions:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(95, 17), style=0) etisserant@0: etisserant@0: self.ActionsGrid = wx.grid.Grid(id=wxID_ACTIONBLOCKDIALOGVARIABLESGRID, etisserant@0: name='ActionsGrid', parent=self.MainPanel, pos=wx.Point(24, 44), etisserant@0: size=wx.Size(450, 150), style=wxVSCROLL) etisserant@0: self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, etisserant@0: 'Sans')) etisserant@0: self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, etisserant@0: False, 'Sans')) etisserant@0: self.ActionsGrid.DisableDragGridSize() etisserant@0: self.ActionsGrid.EnableScrolling(False, True) etisserant@0: EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange) etisserant@0: etisserant@0: self.AddButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGADDBUTTON, label='Add', etisserant@0: name='AddButton', parent=self.MainPanel, pos=wx.Point(245, 204), etisserant@0: size=wx.Size(72, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGADDBUTTON, self.OnAddButton) etisserant@0: etisserant@0: self.DeleteButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDELETEBUTTON, label='Delete', etisserant@0: name='DeleteButton', parent=self.MainPanel, pos=wx.Point(325, 204), etisserant@0: size=wx.Size(72, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDELETEBUTTON, self.OnDeleteButton) etisserant@0: etisserant@0: self.UpButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGUPBUTTON, label='^', etisserant@0: name='UpButton', parent=self.MainPanel, pos=wx.Point(405, 204), etisserant@0: size=wx.Size(32, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGUPBUTTON, self.OnUpButton) etisserant@0: etisserant@0: self.DownButton = wx.Button(id=wxID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', etisserant@0: name='DownButton', parent=self.MainPanel, pos=wx.Point(445, 204), etisserant@0: size=wx.Size(32, 32), style=0) etisserant@0: EVT_BUTTON(self, wxID_ACTIONBLOCKDIALOGDOWNBUTTON, self.OnDownButton) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT) etisserant@0: etisserant@0: self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} etisserant@0: self.Table = ActionTable(self, [], ["Qualifier","Duration","Type","Value","Indicator"]) etisserant@0: self.TypeList = "Action,Variable,Inline" etisserant@0: self.ColSizes = [60, 90, 80, 110, 80] etisserant@0: self.ColAlignements = [wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT, wxALIGN_LEFT] etisserant@0: etisserant@0: self.ActionsGrid.SetTable(self.Table) etisserant@0: self.ActionsGrid.SetRowLabelSize(0) etisserant@0: etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: etisserant@0: def OnAddButton(self, event): etisserant@0: self.Table.AppendRow(self.DefaultValue.copy()) etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDeleteButton(self, event): etisserant@0: row = self.ActionsGrid.GetGridCursorRow() etisserant@0: self.Table.RemoveRow(row) etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnUpButton(self, event): etisserant@0: row = self.ActionsGrid.GetGridCursorRow() etisserant@0: self.Table.MoveRow(row, -1, self.ActionsGrid) etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDownButton(self, event): etisserant@0: row = self.ActionsGrid.GetGridCursorRow() etisserant@0: self.Table.MoveRow(row, 1, self.ActionsGrid) etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnActionsGridCellChange(self, event): etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: event.Skip() etisserant@0: etisserant@0: def SetQualifierList(self, list): etisserant@0: self.QualifierList = "" etisserant@0: sep = "" etisserant@0: for qualifier in list.keys(): etisserant@0: self.QualifierList += "%s%s"%(sep, qualifier) etisserant@0: sep = "," etisserant@0: self.DurationList = list etisserant@0: etisserant@0: def SetVariableList(self, list): etisserant@0: self.VariableList = "" etisserant@0: sep = "" etisserant@0: for variable in list: etisserant@0: self.VariableList += "%s%s"%(sep, variable["Name"]) etisserant@0: sep = "," etisserant@0: etisserant@0: def SetActionList(self, list): etisserant@0: self.ActionList = "" etisserant@0: sep = "" etisserant@0: for action in list: etisserant@0: self.ActionList += "%s%s"%(sep, action) etisserant@0: sep = "," etisserant@0: etisserant@0: def SetValues(self, actions): etisserant@0: for action in actions: etisserant@0: row = {"Qualifier" : action["qualifier"], "Value" : action["value"], etisserant@0: "Indicator" : action["indicator"]} etisserant@0: if action["type"] == "reference": etisserant@0: if action["value"] in self.ActionList: etisserant@0: row["Type"] = "Action" etisserant@0: elif action["value"] in self.VariableList: etisserant@0: row["Type"] = "Variable" etisserant@0: else: etisserant@0: row["Type"] = "Inline" etisserant@0: else: etisserant@0: row["Type"] = "Inline" etisserant@0: if "duration" in action: etisserant@0: row["Duration"] = action["duration"] etisserant@0: self.Table.AppendRow(row) etisserant@0: self.Table.ResetView(self.ActionsGrid) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: values = [] etisserant@0: for data in self.Table.GetData(): etisserant@0: action = {"qualifier" : data["Qualifier"], "value" : data["Value"], etisserant@0: "indicator" : data["Indicator"]} etisserant@0: if data["Type"] in ["Action", "Variable"]: etisserant@0: action["type"] = "reference" etisserant@0: else: etisserant@0: action["type"] = "inline" etisserant@0: if data["Duration"] != "": etisserant@0: action["duration"] = data["Duration"] etisserant@0: values.append(action) etisserant@0: return values