editors/SFCViewer.py
author Edouard Tisserant
Wed, 31 Jul 2013 10:45:07 +0900
branch1.1 Korean release
changeset 1280 72a826dfcfbb
parent 814 5743cbdff669
child 1347 533741e5075c
permissions -rw-r--r--
RC4
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
from types import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
from Viewer import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
class SFC_Viewer(Viewer):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
        Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
        self.CurrentLanguage = "SFC"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
    def ConnectConnectors(self, start, end):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
        startpoint = [start.GetPosition(False), start.GetDirection()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
        endpoint = [end.GetPosition(False), end.GetDirection()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
        wire = Wire(self, startpoint, endpoint)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
        self.AddWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
        start.Connect((wire, 0), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
        end.Connect((wire, -1), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
        wire.ConnectStartPoint(None, start)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
        wire.ConnectEndPoint(None, end)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
        return wire
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    def CreateTransition(self, connector, next = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
        previous = connector.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    50
        id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
        transition = SFC_Transition(self, "reference", "", 0, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
        pos = connector.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
        transition.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
        transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
        wire = self.ConnectConnectors(transition_connectors["input"], connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
        if isinstance(previous, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
            previous.RefreshConnectedPosition(connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
            previous.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        self.AddBlock(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
        self.Controler.AddEditedElementTransition(self.TagName, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
        self.RefreshTransitionModel(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
        if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
            wire = self.ConnectConnectors(next, transition_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
            pos = transition_connectors["output"].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
            next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
            next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
            transition.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
            if isinstance(next_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
                next_block.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
            transition.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
        return transition
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
    def RemoveTransition(self, transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
        connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
        input_wires = connectors["input"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
        if len(input_wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    80
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    81
        input_wire = input_wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    82
        previous = input_wire.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
        input_wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
        self.RemoveWire(input_wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
        output_wires = connectors["output"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    86
        if len(output_wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        output_wire = output_wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
        next = output_wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
        output_wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
        self.RemoveWire(output_wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
        transition.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
        self.RemoveBlock(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
        self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
        wire = self.ConnectConnectors(next, previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
        return wire
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
    def CreateStep(self, name, connector, next = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
        previous = connector.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
        id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
        step = SFC_Step(self, name, False, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
        if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
            step.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
        min_width, min_height = step.GetMinSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
        pos = connector.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        step.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
        step.SetSize(min_width, min_height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
        step_connectors = step.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
        wire = self.ConnectConnectors(step_connectors["input"], connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
        if isinstance(previous, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
            previous.RefreshConnectedPosition(connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
            previous.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
        self.AddBlock(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        self.Controler.AddEditedElementStep(self.TagName, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
        self.RefreshStepModel(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
            wire = self.ConnectConnectors(next, step_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
            pos = step_connectors["output"].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
            next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
            next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
            step.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
            if isinstance(next_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
                next_block.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
            step.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
        return step
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
    def RemoveStep(self, step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        connectors = step.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
        if connectors["input"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
            input_wires = connectors["input"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
            if len(input_wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
            input_wire = input_wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
            previous = input_wire.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
            input_wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
            self.RemoveWire(input_wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
            previous = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
        if connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
            output_wires = connectors["output"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
            if len(output_wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
            output_wire = output_wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
            next = output_wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
            output_wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
            self.RemoveWire(output_wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
            next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        action = step.GetActionConnected()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
        if action:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
            self.DeleteActionBlock(action.GetParentBlock())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
        step.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
        self.RemoveBlock(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
        self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
        if next and previous:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
            wire = self.ConnectConnectors(next, previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
            return wire
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
            return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
#                          Mouse event functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
    def OnViewerLeftDown(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            Viewer.OnViewerLeftDown(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
        elif self.Mode == MODE_SELECTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
            if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
                element = self.FindElement(event, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
                if element and not self.IsWire(element):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
                    if isinstance(self.SelectedElement, Graphic_Group):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
                        self.SelectedElement.SelectElement(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                        group = Graphic_Group(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                        self.SelectedElement.SetSelected(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
                        group.SelectElement(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
                        group.SelectElement(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                        self.SelectedElement = group
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                    elements = self.SelectedElement.GetElements()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
                    if len(elements) == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                        self.SelectedElement = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
                    elif len(elements) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                        self.SelectedElement = elements[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
                    self.SelectedElement.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
                element = self.FindElement(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                if self.SelectedElement and self.SelectedElement != element:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
                    if self.IsWire(self.SelectedElement):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                        self.SelectedElement.SetSelectedSegment(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                        self.SelectedElement.SetSelected(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
                    self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
                if element:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
                    self.SelectedElement = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                    self.SelectedElement.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
                    self.SelectedElement.Refresh()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
                    self.rubberBand.Reset()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
                    self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
        elif self.Mode == MODE_COMMENT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
            self.rubberBand.Reset()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
            self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
    def OnViewerLeftUp(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
            Viewer.OnViewerLeftUp(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
        elif self.rubberBand.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
            if self.Mode == MODE_SELECTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
                if len(elements) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                    self.SelectedElement = Graphic_Group(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
                    self.SelectedElement.SetElements(elements)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                    self.SelectedElement.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
            elif self.Mode == MODE_COMMENT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                bbox = self.rubberBand.GetCurrentExtent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                wx.CallAfter(self.AddComment, bbox)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
        elif self.Mode == MODE_INITIALSTEP:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
            wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
            if self.IsWire(self.SelectedElement):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
                self.SelectedElement.SetSelectedSegment(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
                self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
                self.SelectedElement.Refresh()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            wx.CallAfter(self.SetCurrentCursor, 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
        elif self.Mode == MODE_WIRE and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
            self.SelectedElement.ResetPoints()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
            self.SelectedElement.GeneratePoints()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
            self.SelectedElement.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
            self.SelectedElement.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
    def OnViewerRightUp(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
            Viewer.OnViewerRightUp(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
            element = self.FindElement(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
            if element:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
                if self.SelectedElement and self.SelectedElement != element:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
                    self.SelectedElement.SetSelected(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
                self.SelectedElement = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                if self.IsWire(self.SelectedElement):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                    self.SelectedElement.SetSelectedSegment(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
                    self.SelectedElement.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                    self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                    self.SelectedElement.Refresh()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                wx.CallAfter(self.SetCurrentCursor, 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
    def OnViewerLeftDClick(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
            Viewer.OnViewerLeftDClick(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
            self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
    def OnViewerMotion(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
            Viewer.OnViewerMotion(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
            if self.rubberBand.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
            elif self.Mode == MODE_SELECTION and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
                if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
                    self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                    self.SelectedElement.Refresh()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
            elif self.Mode == MODE_WIRE and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
                self.SelectedElement.ResetPoints()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
                self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
                self.SelectedElement.GeneratePoints()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
                self.SelectedElement.Refresh()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
            self.UpdateScrollPos(event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
        event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
#                          Keyboard event functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
    def OnChar(self, event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
            Viewer.OnChar(self, event)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
            xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
            xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
            ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
            keycode = event.GetKeyCode()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
            if self.Scaling:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
                scaling = self.Scaling
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                scaling = (8, 8)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
            if keycode == wx.WXK_DELETE and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                self.SelectedElement.Delete()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
                self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
            elif keycode == wx.WXK_LEFT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                if event.ControlDown() and event.ShiftDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                    self.Scroll(0, ypos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
                elif event.ControlDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
                    event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                elif self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                    self.SelectedElement.Move(-scaling[0], 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                    self.SelectedElement.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                    self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
            elif keycode == wx.WXK_RIGHT:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                if event.ControlDown() and event.ShiftDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
                    self.Scroll(xmax, ypos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
                elif event.ControlDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
                    event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
                elif self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
                    self.SelectedElement.Move(scaling[0], 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
                    self.SelectedElement.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
                    self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
            elif keycode == wx.WXK_UP:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                if event.ControlDown() and event.ShiftDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
                    self.Scroll(xpos, 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
                elif event.ControlDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
                    event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
                elif self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
                    self.SelectedElement.Move(0, -scaling[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
                    self.SelectedElement.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
                    self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
            elif keycode == wx.WXK_DOWN:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
                if event.ControlDown() and event.ShiftDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
                    self.Scroll(xpos, ymax)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
                elif event.ControlDown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
                    event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
                elif self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                    self.SelectedElement.Move(0, scaling[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
                    self.SelectedElement.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
                    self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
                event.Skip()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
#                          Adding element functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
    def AddInitialStep(self, pos):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
        dialog = SFCStepNameDialog(self.ParentWindow, _("Please enter step name"), _("Add a new initial step"), "", wx.OK|wx.CANCEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
        dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
            id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
            name = dialog.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
            step = SFC_Step(self, name, True, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
            min_width, min_height = step.GetMinSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
            step.SetPosition(pos.x, pos.y)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
            width, height = step.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
            step.SetSize(max(min_width, width), max(min_height, height))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
            self.AddBlock(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
            self.Controler.AddEditedElementStep(self.TagName, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
            self.RefreshStepModel(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
            self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
            self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
            self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
    def AddStep(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
        if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
            dialog = SFCStepNameDialog(self.ParentWindow, _("Add a new step"), _("Please enter step name"), "", wx.OK|wx.CANCEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
            dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
            dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
            dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
                name = dialog.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
                if self.IsWire(self.SelectedElement):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
                    self.SelectedElement.SetSelectedSegment(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
                    previous = self.SelectedElement.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
                    next = self.SelectedElement.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
                    self.SelectedElement.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
                    self.RemoveWire(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
                    connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
                    if connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
                        previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
                        wires = previous.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
                        if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
                            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
                        wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
                        next = wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
                        wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
                        self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
                        self.SelectedElement.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
                        connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
                        self.RefreshStepModel(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
                        previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
                        next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
                previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
                if isinstance(previous_block, SFC_Step) or isinstance(previous_block, SFC_Divergence) and previous_block.GetType() in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
                    transition = self.CreateTransition(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
                    transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
                    step = self.CreateStep(name, transition_connectors["output"], next)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
                    step = self.CreateStep(name, previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
                    step.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
                    step.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
                    step_connectors = step.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
                    transition = self.CreateTransition(step_connectors["output"], next)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
                if self.IsWire(self.SelectedElement):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
                    self.SelectedElement = wire
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
                    self.SelectedElement.SetSelectedSegment(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
                    self.SelectedElement.SetSelected(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
                    self.SelectedElement = step
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
                    self.SelectedElement.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
    def AddStepAction(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
        if isinstance(self.SelectedElement, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
            connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
            if not connectors["action"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
                dialog = ActionBlockDialog(self.ParentWindow)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
                dialog.SetQualifierList(self.Controler.GetQualifierTypes())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
                dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
                dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
                if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
                    actions = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
                    self.SelectedElement.AddAction()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
                    self.RefreshStepModel(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
                    connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
                    pos = connectors["action"].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
                    id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
                    actionblock = SFC_ActionBlock(self, [], id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
                    actionblock.SetPosition(pos.x + SFC_WIRE_MIN_SIZE, pos.y - SFC_STEP_DEFAULT_SIZE[1] / 2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
                    actionblock_connector = actionblock.GetConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
                    wire = self.ConnectConnectors(actionblock_connector, connectors["action"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
                    wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
                    actionblock.SetActions(actions)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
                    self.AddBlock(actionblock)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
                    self.Controler.AddEditedElementActionBlock(self.TagName, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
                    self.RefreshActionBlockModel(actionblock)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
                    self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
                    self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
                dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
    def AddDivergence(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   463
        if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step):        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
            dialog = SFCDivergenceDialog(self.ParentWindow)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
            dialog.SetPreviewFont(self.GetFont())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
                value = dialog.GetValues()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
                if value["type"] == SELECTION_DIVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
                    if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
                        self.SelectedElement.SetSelectedSegment(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
                        previous = self.SelectedElement.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
                        next = self.SelectedElement.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
                        self.SelectedElement.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
                        self.RemoveWire(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
                        self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
                    elif isinstance(self.SelectedElement, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
                        connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
                        if connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
                            previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
                            wires = previous.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
                            if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
                                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
                            wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
                            next = wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
                            wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
                            self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
                            self.SelectedElement.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
                            connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
                            self.RefreshStepModel(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
                            previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
                            next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
                        return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
                    id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
                    divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
                    pos = previous.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
                    previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
                    wire_size = GetWireSize(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
                    divergence.SetPosition(pos.x, pos.y + wire_size)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
                    divergence_connectors = divergence.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
                    wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
                    previous_block.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
                    self.AddBlock(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
                    self.RefreshDivergenceModel(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
                    for index, connector in enumerate(divergence_connectors["outputs"]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
                        if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
                            wire = self.ConnectConnectors(next, connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
                            pos = connector.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
                            next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   513
                            next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
                            divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
                            divergence.RefreshConnectedPosition(connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
                            next_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
                            next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
                            transition = self.CreateTransition(connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
                            transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
                            step = self.CreateStep("Step", transition_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
                elif value["type"] == SIMULTANEOUS_DIVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
                    if self.SelectedElement in self.Wires and isinstance(self.SelectedElement.EndConnected.GetParentBlock(), SFC_Transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
                        self.SelectedElement.SetSelectedSegment(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
                        previous = self.SelectedElement.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
                        next = self.SelectedElement.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
                        self.SelectedElement.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
                        self.RemoveWire(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
                        self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
                    elif isinstance(self.SelectedElement, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
                        connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
                        if connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
                            previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
                            wires = previous.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
                            if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
                                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
                            wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
                            next = wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
                            wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
                            self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
                            self.SelectedElement.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
                            connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
                            self.RefreshStepModel(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
                            previous = connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
                            next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
                        transition = self.CreateTransition(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
                        transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
                        previous = transition_connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
                        return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
                    id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
                    divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
                    pos = previous.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
                    previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
                    wire_size = GetWireSize(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
                    divergence.SetPosition(pos.x, pos.y + wire_size)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
                    divergence_connectors = divergence.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
                    wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
                    previous_block.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
                    self.AddBlock(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
                    self.RefreshDivergenceModel(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
                    for index, connector in enumerate(divergence_connectors["outputs"]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
                        if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
                            wire = self.ConnectConnectors(next, connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
                            pos = connector.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
                            next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
                            next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
                            divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
                            divergence.RefreshConnectedPosition(connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
                            next_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
                            next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
                            step = self.CreateStep("Step", connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
                elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
                    next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
                    for element in self.SelectedElement.GetElements():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
                        connectors = element.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
                        if not isinstance(element, SFC_Step) or connectors["output"] and next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
                            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
                        elif connectors["output"] and not next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
                            wires = connectors["output"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
                            if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
                                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
                            if value["type"] == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
                                transition = wires[0][0].StartConnected.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
                                transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
                                wires = transition_connectors["output"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
                                if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
                                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
                            wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
                            next = wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
                            wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
                            self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
                    inputs = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
                    for input in self.SelectedElement.GetElements():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
                        input_connectors = input.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   602
                        if not input_connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   603
                            input.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
                            input.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
                            input_connectors = input.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
                            if value["type"] == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
                                transition = self.CreateTransition(input_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
                                transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
                                inputs.append(transition_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
                                inputs.append(input_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
                        elif value["type"] == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                            wires = input_connectors["output"].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
                            transition = wires[0][0].StartConnected.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
                            transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
                            inputs.append(transition_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
                            inputs.append(input_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
                    id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
                    divergence = SFC_Divergence(self, value["type"], len(inputs), id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
                    pos = inputs[0].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
                    divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
                    divergence_connectors = divergence.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
                    for i, input in enumerate(inputs):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
                        pos = input.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
                        wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
                        wire_size = GetWireSize(input)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
                        input_block = input.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
                        input_block.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
                    divergence.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
                    pos = divergence_connectors["outputs"][0].GetRelPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
                    divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
                    self.AddBlock(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
                    self.RefreshDivergenceModel(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
                    if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
                        wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
                        pos = divergence_connectors["outputs"][0].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
                        next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                        next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                        divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
                        divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
                        wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
                        next_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
                        if value["type"] == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
                            previous = divergence_connectors["outputs"][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
                            transition = self.CreateTransition(divergence_connectors["outputs"][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
                            transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
                            previous = transition_connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
                        self.CreateStep("Step", previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
    def AddDivergenceBranch(self, divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
        if isinstance(divergence, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
                divergence.AddBranch()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
                self.RefreshDivergenceModel(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
                type = divergence.GetType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
                if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
                    divergence.AddBranch()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
                    divergence_connectors = divergence.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
                    if type == SELECTION_DIVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
                        transition = self.CreateTransition(divergence_connectors["outputs"][-1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
                        transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
                        previous = transition_connectors["output"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
                        previous = divergence_connectors["outputs"][-1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
                    step = self.CreateStep("Step", previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
            self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
            self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
            self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
    def RemoveDivergenceBranch(self, divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
        if isinstance(divergence, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
            if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
                divergence.RemoveHandledBranch()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
                self.RefreshDivergenceModel(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
    def AddJump(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
        if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
            choices = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
            for block in self.Blocks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
                if isinstance(block, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
                    choices.append(block.GetName())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            dialog = wx.SingleChoiceDialog(self.ParentWindow, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
                  _("Add a new jump"), _("Please choose a target"), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
                  choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
                value = dialog.GetStringSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
                self.SelectedElement.AddOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
                self.RefreshStepModel(self.SelectedElement)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
                step_connectors = self.SelectedElement.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
                transition = self.CreateTransition(step_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
                transition_connectors = transition.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
                id = self.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
                jump = SFC_Jump(self, value, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
                pos = transition_connectors["output"].GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
                jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
                self.AddBlock(jump)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
                self.Controler.AddEditedElementJump(self.TagName, id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
                jump_connector = jump.GetConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
                wire = self.ConnectConnectors(jump_connector, transition_connectors["output"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
                transition.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
                wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
                self.RefreshJumpModel(jump)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
    def EditStepContent(self, step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
            Viewer.EditStepContent(self, step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
            dialog = SFCStepNameDialog(self.ParentWindow, _("Edit step name"), _("Please enter step name"), step.GetName(), wx.OK|wx.CANCEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
            dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
            dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
            dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
            if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
                value = dialog.GetValue()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
                step.SetName(value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
                min_size = step.GetMinSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
                size = step.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
                step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
                step.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
                self.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
                self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
                self.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
            dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
#                          Delete element functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
    def DeleteStep(self, step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
            Viewer.DeleteStep(self, step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
            step_connectors = step.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
            if not step.GetInitial() or not step_connectors["output"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
                previous = step.GetPreviousConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
                if previous:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
                    previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
                    previous_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
                next = step.GetNextConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
                if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
                    next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
                    next_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
                if isinstance(next_block, SFC_Transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                    self.RemoveTransition(next_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
                    next = step.GetNextConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
                    if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
                        next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
                        next_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                elif isinstance(previous_block, SFC_Transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                    self.RemoveTransition(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
                    previous = step.GetPreviousConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
                    if previous:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
                        previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
                        previous_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
                wire = self.RemoveStep(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
                self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
                if next_block:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
                    if isinstance(next_block, SFC_Divergence) and next_block.GetType() == SIMULTANEOUS_CONVERGENCE and isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SIMULTANEOUS_DIVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
                        wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
                        self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
                        next_block.RemoveBranch(next)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   782
                        if next_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
                            self.DeleteDivergence(next_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
                            next_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
                        previous_block.RemoveBranch(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
                        if previous_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
                            self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
                            previous_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
                        pos = previous.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
                        next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
                        wire_size = GetWireSize(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
                        previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   797
                        if isinstance(next_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
                            next_block.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
                        previous_block.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   800
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
                    if isinstance(previous_block, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   802
                        previous_block.RemoveOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   803
                        self.RefreshStepModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
                    elif isinstance(previous_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   805
                        if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   806
                            self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   807
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   808
                            previous_block.RemoveBranch(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   809
                            if previous_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   810
                                self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
                                self.RefreshDivergenceModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   813
        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
    def DeleteTransition(self, transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   816
            Viewer.DeleteTransition(self, transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
            previous = transition.GetPreviousConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   819
            previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
            next = transition.GetNextConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
            next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   822
            if isinstance(previous_block, SFC_Divergence) and previous_block.GetType() == SELECTION_DIVERGENCE and isinstance(next_block, SFC_Divergence) and next_block.GetType() == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
                wires = previous.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
                if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   825
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
                wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
                wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   828
                self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
                wires = next.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
                if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
                wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
                wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
                self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
                transition.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
                self.RemoveBlock(transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   837
                self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
                previous_block.RemoveBranch(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
                if previous_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
                    self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
                    self.RefreshDivergenceModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
                next_block.RemoveBranch(next)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   844
                if next_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   845
                    self.DeleteDivergence(next_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   847
                    self.RefreshDivergenceModel(next_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   848
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
    def DeleteDivergence(self, divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   851
            Viewer.DeleteDivergence(self, divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   852
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   853
            connectors = divergence.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   854
            type = divergence.GetType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   855
            if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   856
                wires = connectors["outputs"][0].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   857
                if len(wires) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   859
                elif len(wires) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
                    next = wires[0][0].StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   861
                    next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   862
                    wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   863
                    wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
                    self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
                    next = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   867
                    next_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   868
                for index, connector in enumerate(connectors["inputs"]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
                    if next and index == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   870
                        wires = connector.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
                        wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
                        previous = wires[0][0].EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
                        wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
                        self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
                        if type == SELECTION_CONVERGENCE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
                            wires = connector.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   878
                            previous_block = wires[0][0].EndConnected.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   879
                            self.RemoveTransition(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
                        wires = connector.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   881
                        wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
                        previous_connector = wire.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   883
                        previous_block = previous_connector.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   884
                        wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
                        self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
                        if isinstance(previous_block, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
                            previous_block.RemoveOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   888
                            self.RefreshStepModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   889
                        elif isinstance(previous_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   890
                            if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   891
                                previous_block.RemoveBranch(previous_connector)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
                                if previous_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   893
                                    self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
                                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   895
                                    self.RefreshDivergenceModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   896
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   897
                                self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   898
                divergence.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
                self.RemoveBlock(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
                self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
                if next:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
                    wire = self.ConnectConnectors(next, previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
                    previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
                    previous_pos = previous.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
                    next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
                    wire_size = GetWireSize(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
                    previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   908
                    wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   909
                        wx.Point(previous_pos.x, previous_pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   910
                    if isinstance(next_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
                        next_block.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
                    previous_block.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   913
            elif divergence.GetBranchNumber() == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   914
                wires = connectors["inputs"][0].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   915
                if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   916
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   917
                wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   918
                previous = wire.EndConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   919
                previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
                wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
                self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
                wires = connectors["outputs"][0].GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   923
                if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   924
                    return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   925
                wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   926
                next = wire.StartConnected
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   927
                next_block = next.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   928
                wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
                self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   930
                divergence.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   931
                self.RemoveBlock(divergence)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
                self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
                wire = self.ConnectConnectors(next, previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
                previous_pos = previous.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
                next_pos = next.GetPosition(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   936
                wire_size = GetWireSize(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
                previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   938
                wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   939
                    wx.Point(previous_pos.x, previous_pos.y)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   940
                if isinstance(next_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
                    next_block.RefreshPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
                previous_block.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   943
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
    def DeleteJump(self, jump):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   945
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   946
            Viewer.DeleteJump(self, jump)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   947
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   948
            previous = jump.GetPreviousConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   949
            previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   950
            if isinstance(previous_block, SFC_Transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   951
                self.RemoveTransition(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   952
                previous = jump.GetPreviousConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   953
                if previous:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   954
                    previous_block = previous.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   955
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   956
                    previous_block = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
            wires = previous.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
            if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   960
            wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   961
            wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
            self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   963
            jump.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
            self.RemoveBlock(jump)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
            self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
            if isinstance(previous_block, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
                previous_block.RemoveOutput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
                self.RefreshStepModel(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   969
            elif isinstance(previous_block, SFC_Divergence):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
                if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
                    self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
                    previous_block.RemoveBranch(previous)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
                    if previous_block.GetBranchNumber() < 2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
                        self.DeleteDivergence(previous_block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
                        previous_block.RefreshModel()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
    def DeleteActionBlock(self, actionblock):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   980
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   981
            Viewer.DeleteActionBlock(self, actionblock)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
            connector = actionblock.GetConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   984
            wires = connector.GetWires()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   985
            if len(wires) != 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   986
                return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   987
            wire = wires[0][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   988
            step = wire.EndConnected.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   989
            wire.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   990
            self.RemoveWire(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   991
            actionblock.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   992
            self.RemoveBlock(actionblock)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   993
            self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   994
            step.RemoveAction()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   995
            self.RefreshStepModel(step)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   996
            step.RefreshOutputPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   997
            step.RefreshOutputModel(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   998
            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   999
    def DeleteWire(self, wire):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1000
        if self.GetDrawingMode() == FREEDRAWING_MODE:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1001
            Viewer.DeleteWire(self, wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1002
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1003
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1004
#                          Model update functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1005
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1006
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1007
    def RefreshBlockModel(self, block):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1008
        blockid = block.GetId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1009
        infos = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1010
        infos["type"] = block.GetType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1011
        infos["name"] = block.GetName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1012
        infos["x"], infos["y"] = block.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1013
        infos["width"], infos["height"] = block.GetSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1014
        infos["connectors"] = block.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1015
        self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1016