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