SFCViewer.py
author Laurent Bessard
Wed, 05 Sep 2012 11:20:53 +0200
changeset 757 628dd4762b57
parent 720 2a9d4eafaddd
permissions -rw-r--r--
Fix ActionBlockDialog layout
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
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
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
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
0
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
import wx
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
from types import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
from Viewer import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
    29
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
class SFC_Viewer(Viewer):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
    32
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
    33
        Viewer.__init__(self, parent, tagname, window, controler, debug, instancepath)
112
317148fc1225 Adding support for block copy
lbessard
parents: 90
diff changeset
    34
        self.CurrentLanguage = "SFC"
0
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()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
    50
        transition = SFC_Transition(self, "reference", "", 0, id)
0
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()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    59
        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
    60
        self.AddBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
    61
        self.Controler.AddEditedElementTransition(self.TagName, id)
0
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))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
    69
            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
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)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
    93
        self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
0
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()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   113
        wire.SetPoints([wx.Point(pos.x, pos.y + GetWireSize(previous)), wx.Point(pos.x, pos.y)])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   114
        self.AddBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   115
        self.Controler.AddEditedElementStep(self.TagName, id)
0
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))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   123
            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
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
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 382
diff changeset
   151
        action = step.GetActionConnected()
0
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)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   156
        self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId())
0
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:
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 327
diff changeset
   171
            if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None:
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   172
                element = self.FindElement(event, True)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   173
                if element and not self.IsWire(element):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
                    if isinstance(self.SelectedElement, Graphic_Group):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
                        self.SelectedElement.SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
                        group = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   178
                        self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
                        group.SelectElement(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   180
                        group.SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
                        self.SelectedElement = group
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   182
                    elements = self.SelectedElement.GetElements()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   183
                    if len(elements) == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   184
                        self.SelectedElement = element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   185
                    elif len(elements) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   186
                        self.SelectedElement = elements[0]
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 327
diff changeset
   187
                    self.SelectedElement.SetSelected(True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   188
            else:
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   189
                element = self.FindElement(event)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   190
                if self.SelectedElement and self.SelectedElement != element:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   191
                    if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   192
                        self.SelectedElement.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   193
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   194
                        self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   195
                    self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   196
                if element:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   197
                    self.SelectedElement = element
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   198
                    self.SelectedElement.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 122
diff changeset
   199
                    self.SelectedElement.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   200
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   201
                    self.rubberBand.Reset()
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   202
                    self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   203
        elif self.Mode == MODE_COMMENT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   204
            self.rubberBand.Reset()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   205
            self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   206
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   207
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   208
    def OnViewerLeftUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   209
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   210
            Viewer.OnViewerLeftUp(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   211
        elif self.rubberBand.IsShown():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
            if self.Mode == MODE_SELECTION:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   213
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   214
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   215
                if len(elements) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   216
                    self.SelectedElement = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   217
                    self.SelectedElement.SetElements(elements)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   218
                    self.SelectedElement.SetSelected(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   219
            elif self.Mode == MODE_COMMENT:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   220
                bbox = self.rubberBand.GetCurrentExtent()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   221
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   222
                wx.CallAfter(self.AddComment, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   223
        elif self.Mode == MODE_INITIALSTEP:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   224
            wx.CallAfter(self.AddInitialStep, GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   225
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   226
            if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   227
                self.SelectedElement.SetSelectedSegment(0)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   228
            else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   229
                self.SelectedElement.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 122
diff changeset
   230
                self.SelectedElement.Refresh()
382
42a9b03bba82 Redefine cursor switching procedure in graphic viewers
laurent
parents: 362
diff changeset
   231
            wx.CallAfter(self.SetCurrentCursor, 0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   232
        elif self.Mode == MODE_WIRE and self.SelectedElement:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
            self.SelectedElement.ResetPoints()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   234
            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   235
            self.SelectedElement.GeneratePoints()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   236
            self.SelectedElement.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   237
            self.SelectedElement.SetSelected(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   238
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   239
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   240
    def OnViewerRightUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   241
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   242
            Viewer.OnViewerRightUp(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   243
        else:
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   244
            element = self.FindElement(event)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   245
            if element:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   246
                if self.SelectedElement and self.SelectedElement != element:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   247
                    self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   248
                self.SelectedElement = element
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   249
                if self.IsWire(self.SelectedElement):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   250
                    self.SelectedElement.SetSelectedSegment(0)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   251
                else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   252
                    self.SelectedElement.SetSelected(True)
563
3f92a5e18804 - Fixing editing graphic element (handles, rubberband and highlight) in graphic editor in order to make them keep the same size whatever the zoom factor applied to graphic editor
laurent
parents: 409
diff changeset
   253
                    self.SelectedElement.OnRightUp(event, self.GetLogicalDC(), self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 122
diff changeset
   254
                    self.SelectedElement.Refresh()
382
42a9b03bba82 Redefine cursor switching procedure in graphic viewers
laurent
parents: 362
diff changeset
   255
                wx.CallAfter(self.SetCurrentCursor, 0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   256
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   257
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   258
    def OnViewerLeftDClick(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   259
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   260
            Viewer.OnViewerLeftDClick(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   261
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   262
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   263
            self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   264
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   265
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   266
    def OnViewerMotion(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   267
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   268
            Viewer.OnViewerMotion(self, event)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   269
        else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   270
            if self.rubberBand.IsShown():
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   271
                self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   272
            elif self.Mode == MODE_SELECTION and self.SelectedElement:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   273
                if not self.IsWire(self.SelectedElement) and not isinstance(self.SelectedElement, Graphic_Group):
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   274
                    self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 122
diff changeset
   275
                    self.SelectedElement.Refresh()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   276
            elif self.Mode == MODE_WIRE and self.SelectedElement:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   277
                self.SelectedElement.ResetPoints()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   278
                self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   279
                self.SelectedElement.GeneratePoints()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 122
diff changeset
   280
                self.SelectedElement.Refresh()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   281
            self.UpdateScrollPos(event)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   283
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   284
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   285
#                          Keyboard event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   286
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   287
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   288
    def OnChar(self, event):
362
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   289
        if self.GetDrawingMode() == FREEDRAWING_MODE:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   290
            Viewer.OnChar(self, event)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   291
        else:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   292
            xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   293
            xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   294
            ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   295
            keycode = event.GetKeyCode()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   296
            if self.Scaling:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   297
                scaling = self.Scaling
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   298
            else:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   299
                scaling = (8, 8)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   300
            if keycode == wx.WXK_DELETE and self.SelectedElement:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   301
                self.SelectedElement.Delete()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   302
                self.SelectedElement = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   303
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   304
                self.RefreshScrollBars()
362
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   305
                self.Refresh(False)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   306
            elif keycode == wx.WXK_LEFT:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   307
                if event.ControlDown() and event.ShiftDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   308
                    self.Scroll(0, ypos)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   309
                elif event.ControlDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   310
                    event.Skip()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   311
                elif self.SelectedElement:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   312
                    self.SelectedElement.Move(-scaling[0], 0)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   313
                    self.SelectedElement.RefreshModel()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   314
                    self.RefreshBuffer()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   315
                    self.RefreshScrollBars()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   316
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   317
            elif keycode == wx.WXK_RIGHT:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   318
                if event.ControlDown() and event.ShiftDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   319
                    self.Scroll(xmax, ypos)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   320
                elif event.ControlDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   321
                    event.Skip()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   322
                elif self.SelectedElement:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   323
                    self.SelectedElement.Move(scaling[0], 0)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   324
                    self.SelectedElement.RefreshModel()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   325
                    self.RefreshBuffer()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   326
                    self.RefreshScrollBars()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   327
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   328
            elif keycode == wx.WXK_UP:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   329
                if event.ControlDown() and event.ShiftDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   330
                    self.Scroll(xpos, 0)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   331
                elif event.ControlDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   332
                    event.Skip()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   333
                elif self.SelectedElement:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   334
                    self.SelectedElement.Move(0, -scaling[1])
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   335
                    self.SelectedElement.RefreshModel()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   336
                    self.RefreshBuffer()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   337
                    self.RefreshScrollBars()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   338
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   339
            elif keycode == wx.WXK_DOWN:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   340
                if event.ControlDown() and event.ShiftDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   341
                    self.Scroll(xpos, ymax)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   342
                elif event.ControlDown():
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   343
                    event.Skip()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   344
                elif self.SelectedElement:
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   345
                    self.SelectedElement.Move(0, scaling[1])
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   346
                    self.SelectedElement.RefreshModel()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   347
                    self.RefreshBuffer()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   348
                    self.RefreshScrollBars()
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   349
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False)
f56181aa99ea Fix bug preventing to copy block in SFC with SPACE key
greg
parents: 331
diff changeset
   350
            else:
112
317148fc1225 Adding support for block copy
lbessard
parents: 90
diff changeset
   351
                event.Skip()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   352
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
#                          Adding element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   356
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   357
    def AddInitialStep(self, pos):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 391
diff changeset
   358
        dialog = SFCStepNameDialog(self.ParentWindow, _("Please enter step name"), _("Add a new initial step"), "", wx.OK|wx.CANCEL)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   359
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   360
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
9
b29105e29081 Adding test on step names in SFC Editor
lbessard
parents: 5
diff changeset
   361
        dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   362
        if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   363
            id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   364
            name = dialog.GetValue()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   365
            step = SFC_Step(self, name, True, id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   366
            min_width, min_height = step.GetMinSize()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   367
            step.SetPosition(pos.x, pos.y)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   368
            width, height = step.GetSize()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   369
            step.SetSize(max(min_width, width), max(min_height, height))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   370
            self.AddBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   371
            self.Controler.AddEditedElementStep(self.TagName, id)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   372
            self.RefreshStepModel(step)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   373
            self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   374
            self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   375
            self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   376
        dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
    def AddStep(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   379
        if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, SFC_Step):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 391
diff changeset
   380
            dialog = SFCStepNameDialog(self.ParentWindow, _("Add a new step"), _("Please enter step name"), "", wx.OK|wx.CANCEL)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   381
            dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   382
            dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
9
b29105e29081 Adding test on step names in SFC Editor
lbessard
parents: 5
diff changeset
   383
            dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   384
            if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   385
                name = dialog.GetValue()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   386
                if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   387
                    self.SelectedElement.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   388
                    previous = self.SelectedElement.EndConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   389
                    next = self.SelectedElement.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   390
                    self.SelectedElement.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   391
                    self.RemoveWire(self.SelectedElement)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   392
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   393
                    connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   394
                    if connectors["output"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   395
                        previous = connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   396
                        wires = previous.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   397
                        if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   398
                            return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   399
                        wire = wires[0][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   400
                        next = wire.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   401
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   402
                        self.RemoveWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   403
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   404
                        self.SelectedElement.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   405
                        connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   406
                        self.RefreshStepModel(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   407
                        previous = connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   408
                        next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   409
                previous_block = previous.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   410
                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
   411
                    transition = self.CreateTransition(previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   412
                    transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   413
                    step = self.CreateStep(name, transition_connectors["output"], next)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   414
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   415
                    step = self.CreateStep(name, previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   416
                    step.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   417
                    step.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   418
                    step_connectors = step.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
                    transition = self.CreateTransition(step_connectors["output"], next)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   420
                if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   421
                    self.SelectedElement = wire
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   422
                    self.SelectedElement.SetSelectedSegment(0)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
                    self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
                    self.SelectedElement = step
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
                    self.SelectedElement.SetSelected(True)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   427
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   428
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   429
                self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   430
            dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   432
    def AddStepAction(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   433
        if isinstance(self.SelectedElement, SFC_Step):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   434
            connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   435
            if not connectors["action"]:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   436
                dialog = ActionBlockDialog(self.ParentWindow)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   437
                dialog.SetQualifierList(self.Controler.GetQualifierTypes())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   438
                dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   439
                dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   440
                if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   441
                    actions = dialog.GetValues()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   442
                    self.SelectedElement.AddAction()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   443
                    self.RefreshStepModel(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   444
                    connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   445
                    pos = connectors["action"].GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   446
                    id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   447
                    actionblock = SFC_ActionBlock(self, [], id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   448
                    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
   449
                    actionblock_connector = actionblock.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   450
                    wire = self.ConnectConnectors(actionblock_connector, connectors["action"])
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   451
                    wire.SetPoints([wx.Point(pos.x + SFC_WIRE_MIN_SIZE, pos.y), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   452
                    actionblock.SetActions(actions)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   453
                    self.AddBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   454
                    self.Controler.AddEditedElementActionBlock(self.TagName, id)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   455
                    self.RefreshActionBlockModel(actionblock)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   456
                    self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   457
                    self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   458
                    self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   459
                dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   460
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   461
    def AddDivergence(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
        if self.SelectedElement in self.Wires or isinstance(self.SelectedElement, Graphic_Group) or isinstance(self.SelectedElement, SFC_Step):        
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 391
diff changeset
   463
            dialog = SFCDivergenceDialog(self.ParentWindow)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 155
diff changeset
   464
            dialog.SetPreviewFont(self.GetFont())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   465
            if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   466
                value = dialog.GetValues()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
                if value["type"] == SELECTION_DIVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   468
                    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
   469
                        self.SelectedElement.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   470
                        previous = self.SelectedElement.EndConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   471
                        next = self.SelectedElement.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   472
                        self.SelectedElement.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   473
                        self.RemoveWire(self.SelectedElement)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   474
                        self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   475
                    elif isinstance(self.SelectedElement, SFC_Step):
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
                        if connectors["output"]:
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
                            wires = previous.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   480
                            if len(wires) != 1:
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
                            wire = wires[0][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   483
                            next = wire.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
                            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   485
                            self.RemoveWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   486
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   487
                            self.SelectedElement.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   488
                            connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   489
                            self.RefreshStepModel(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   490
                            previous = connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
                            next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   492
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
                        return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
                    id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
                    divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, value["number"], id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
                    pos = previous.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   497
                    previous_block = previous.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
                    wire_size = GetWireSize(previous_block)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
                    divergence.SetPosition(pos.x, pos.y + wire_size)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   500
                    divergence_connectors = divergence.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
                    wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
                    previous_block.RefreshOutputPosition()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   503
                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   504
                    self.AddBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   505
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
                    self.RefreshDivergenceModel(divergence)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
                    for index, connector in enumerate(divergence_connectors["outputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
                        if next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
                            wire = self.ConnectConnectors(next, connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
                            pos = connector.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
                            next_pos = next.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
                            next_block = next.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
                            divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
                            divergence.RefreshConnectedPosition(connector)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   515
                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   516
                            next_block.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
                            next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   518
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
                            transition = self.CreateTransition(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
                            transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
                            step = self.CreateStep("Step", transition_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
                elif value["type"] == SIMULTANEOUS_DIVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
                    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
   524
                        self.SelectedElement.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   525
                        previous = self.SelectedElement.EndConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   526
                        next = self.SelectedElement.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   527
                        self.SelectedElement.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   528
                        self.RemoveWire(self.SelectedElement)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   529
                        self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   530
                    elif isinstance(self.SelectedElement, SFC_Step):
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
                        if connectors["output"]:
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
                            wires = previous.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   535
                            if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
                                return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
                            wire = wires[0][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   538
                            next = wire.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
                            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   540
                            self.RemoveWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   541
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
                            self.SelectedElement.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   543
                            connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
                            self.RefreshStepModel(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
                            previous = connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
                            next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
                        transition = self.CreateTransition(previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
                        transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
                        previous = transition_connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   550
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   551
                        return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   552
                    id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   553
                    divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, value["number"], id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   554
                    pos = previous.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   555
                    previous_block = previous.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   556
                    wire_size = GetWireSize(previous_block)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   557
                    divergence.SetPosition(pos.x, pos.y + wire_size)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
                    divergence_connectors = divergence.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   559
                    wire = self.ConnectConnectors(divergence_connectors["inputs"][0], previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   560
                    previous_block.RefreshOutputPosition()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   561
                    wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   562
                    self.AddBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   563
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   564
                    self.RefreshDivergenceModel(divergence)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   565
                    for index, connector in enumerate(divergence_connectors["outputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   566
                        if next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   567
                            wire = self.ConnectConnectors(next, connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   568
                            pos = connector.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   569
                            next_pos = next.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   570
                            next_block = next.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   571
                            divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   572
                            divergence.RefreshConnectedPosition(connector)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   573
                            wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   574
                            next_block.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
                            next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
                            step = self.CreateStep("Step", connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
                elif isinstance(self.SelectedElement, Graphic_Group) and len(self.SelectedElement.GetElements()) > 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
                    next = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   580
                    for element in self.SelectedElement.GetElements():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   581
                        connectors = element.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
                        if not isinstance(element, SFC_Step) or connectors["output"] and next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
                            return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
                        elif connectors["output"] and not next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
                            wires = connectors["output"].GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
                            if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   587
                                return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   588
                            if value["type"] == SELECTION_CONVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   589
                                transition = wires[0][0].StartConnected.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   590
                                transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   591
                                wires = transition_connectors["output"].GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   592
                                if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   593
                                    return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   594
                            wire = wires[0][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   595
                            next = wire.StartConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
                            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   597
                            self.RemoveWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   598
                    inputs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
                    for input in self.SelectedElement.GetElements():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   600
                        input_connectors = input.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
                        if not input_connectors["output"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
                            input.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
                            input.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
                            input_connectors = input.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
                            if value["type"] == SELECTION_CONVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   606
                                transition = self.CreateTransition(input_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
                                transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
                                inputs.append(transition_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   609
                            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
                                inputs.append(input_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   611
                        elif value["type"] == SELECTION_CONVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   612
                            wires = input_connectors["output"].GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   613
                            transition = wires[0][0].StartConnected.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   614
                            transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   615
                            inputs.append(transition_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   616
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   617
                            inputs.append(input_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   618
                    id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   619
                    divergence = SFC_Divergence(self, value["type"], len(inputs), id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   620
                    pos = inputs[0].GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   621
                    divergence.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   622
                    divergence_connectors = divergence.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   623
                    for i, input in enumerate(inputs):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   624
                        pos = input.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   625
                        wire = self.ConnectConnectors(divergence_connectors["inputs"][i], input)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   626
                        wire_size = GetWireSize(input)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   627
                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   628
                        input_block = input.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   629
                        input_block.RefreshOutputPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   630
                    divergence.RefreshPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   631
                    pos = divergence_connectors["outputs"][0].GetRelPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   632
                    divergence.MoveConnector(divergence_connectors["outputs"][0], - pos.x)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   633
                    self.AddBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   634
                    self.Controler.AddEditedElementDivergence(self.TagName, id, value["type"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   635
                    self.RefreshDivergenceModel(divergence)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   636
                    if next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
                        wire = self.ConnectConnectors(next, divergence_connectors["outputs"][0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
                        pos = divergence_connectors["outputs"][0].GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   639
                        next_pos = next.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   640
                        next_block = next.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
                        divergence.RefreshOutputPosition((0, pos.y + SFC_WIRE_MIN_SIZE - next_pos.y))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
                        divergence.RefreshConnectedPosition(divergence_connectors["outputs"][0])
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   643
                        wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   644
                        next_block.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   645
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   646
                        if value["type"] == SELECTION_CONVERGENCE:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   647
                            previous = divergence_connectors["outputs"][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   648
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   649
                            transition = self.CreateTransition(divergence_connectors["outputs"][0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   650
                            transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   651
                            previous = transition_connectors["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   652
                        self.CreateStep("Step", previous)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   653
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   654
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   655
                self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
            dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   657
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   658
    def AddDivergenceBranch(self, divergence):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
        if isinstance(divergence, SFC_Divergence):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   660
            if self.GetDrawingMode() == FREEDRAWING_MODE:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   661
                divergence.AddBranch()
318
2a5421d0f286 Modifications on divergence not buffered fixed
lbessard
parents: 274
diff changeset
   662
                self.RefreshDivergenceModel(divergence)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   663
            else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   664
                type = divergence.GetType()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   665
                if type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   666
                    divergence.AddBranch()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   667
                    divergence_connectors = divergence.GetConnectors()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   668
                    if type == SELECTION_DIVERGENCE:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   669
                        transition = self.CreateTransition(divergence_connectors["outputs"][-1])
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   670
                        transition_connectors = transition.GetConnectors()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   671
                        previous = transition_connectors["output"]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   672
                    else:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   673
                        previous = divergence_connectors["outputs"][-1]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   674
                    step = self.CreateStep("Step", previous)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   675
            self.RefreshBuffer()
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   676
            self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   677
            self.Refresh(False)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   678
    
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   679
    def RemoveDivergenceBranch(self, divergence):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   680
        if isinstance(divergence, SFC_Divergence):
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   681
            if self.GetDrawingMode() == FREEDRAWING_MODE:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   682
                divergence.RemoveHandledBranch()
318
2a5421d0f286 Modifications on divergence not buffered fixed
lbessard
parents: 274
diff changeset
   683
                self.RefreshDivergenceModel(divergence)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   684
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   685
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   686
                self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   687
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   688
    def AddJump(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   689
        if isinstance(self.SelectedElement, SFC_Step) and not self.SelectedElement.Output:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   690
            choices = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   691
            for block in self.Blocks:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   692
                if isinstance(block, SFC_Step):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   693
                    choices.append(block.GetName())
720
2a9d4eafaddd Fix bug no title bar on wx.SingleChoiceDialogs
Laurent Bessard
parents: 563
diff changeset
   694
            dialog = wx.SingleChoiceDialog(self.ParentWindow, 
2a9d4eafaddd Fix bug no title bar on wx.SingleChoiceDialogs
Laurent Bessard
parents: 563
diff changeset
   695
                  _("Add a new jump"), _("Please choose a target"), 
2a9d4eafaddd Fix bug no title bar on wx.SingleChoiceDialogs
Laurent Bessard
parents: 563
diff changeset
   696
                  choices, wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   697
            if dialog.ShowModal() == wx.ID_OK:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   698
                value = dialog.GetStringSelection()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   699
                self.SelectedElement.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   700
                self.RefreshStepModel(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   701
                step_connectors = self.SelectedElement.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   702
                transition = self.CreateTransition(step_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   703
                transition_connectors = transition.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   704
                id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   705
                jump = SFC_Jump(self, value, id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   706
                pos = transition_connectors["output"].GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   707
                jump.SetPosition(pos.x, pos.y + SFC_WIRE_MIN_SIZE)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   708
                self.AddBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   709
                self.Controler.AddEditedElementJump(self.TagName, id)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   710
                jump_connector = jump.GetConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   711
                wire = self.ConnectConnectors(jump_connector, transition_connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   712
                transition.RefreshOutputPosition()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   713
                wire.SetPoints([wx.Point(pos.x, pos.y + SFC_WIRE_MIN_SIZE), wx.Point(pos.x, pos.y)])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   714
                self.RefreshJumpModel(jump)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   715
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 45
diff changeset
   716
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   717
                self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   718
            dialog.Destroy()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   719
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   720
    def EditStepContent(self, step):
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   721
        if self.GetDrawingMode() == FREEDRAWING_MODE:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   722
            Viewer.EditStepContent(self, step)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   723
        else:
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 391
diff changeset
   724
            dialog = SFCStepNameDialog(self.ParentWindow, _("Edit step name"), _("Please enter step name"), step.GetName(), wx.OK|wx.CANCEL)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   725
            dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 235
diff changeset
   726
            dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   727
            dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   728
            if dialog.ShowModal() == wx.ID_OK:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   729
                value = dialog.GetValue()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   730
                step.SetName(value)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   731
                min_size = step.GetMinSize()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   732
                size = step.GetSize()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   733
                step.UpdateSize(max(min_size[0], size[0]), max(min_size[1], size[1]))
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   734
                step.RefreshModel()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   735
                self.RefreshBuffer()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   736
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 145
diff changeset
   737
                self.Refresh(False)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 67
diff changeset
   738
            dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   739
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   740
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   741
#                          Delete element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   742
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   743
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   744
    def DeleteStep(self, step):
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   745
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   746
            Viewer.DeleteStep(self, step)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   747
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   748
            step_connectors = step.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   749
            if not step.GetInitial() or not step_connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   750
                previous = step.GetPreviousConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   751
                if previous:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   752
                    previous_block = previous.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   753
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   754
                    previous_block = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   755
                next = step.GetNextConnector()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   756
                if next:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   757
                    next_block = next.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   758
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   759
                    next_block = None
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   760
                if isinstance(next_block, SFC_Transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   761
                    self.RemoveTransition(next_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   762
                    next = step.GetNextConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   763
                    if next:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   764
                        next_block = next.GetParentBlock()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   765
                    else:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   766
                        next_block = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   767
                elif isinstance(previous_block, SFC_Transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   768
                    self.RemoveTransition(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   769
                    previous = step.GetPreviousConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   770
                    if previous:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   771
                        previous_block = previous.GetParentBlock()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   772
                    else:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   773
                        previous_block = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   774
                wire = self.RemoveStep(step)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   775
                self.SelectedElement = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   776
                if next_block:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   777
                    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
   778
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   779
                        self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   780
                        next_block.RemoveBranch(next)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   781
                        if next_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   782
                            self.DeleteDivergence(next_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   783
                        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   784
                            next_block.RefreshModel()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   785
                        previous_block.RemoveBranch(previous)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   786
                        if previous_block.GetBranchNumber() < 2:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   787
                            self.DeleteDivergence(previous_block)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   788
                        else:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   789
                            previous_block.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   790
                    else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   791
                        pos = previous.GetPosition(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   792
                        next_pos = next.GetPosition(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   793
                        wire_size = GetWireSize(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   794
                        previous_block.RefreshOutputPosition((0, pos.y + wire_size - next_pos.y))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   795
                        wire.SetPoints([wx.Point(pos.x, pos.y + wire_size), wx.Point(pos.x, pos.y)])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   796
                        if isinstance(next_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   797
                            next_block.RefreshPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   798
                        previous_block.RefreshOutputModel(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   799
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   800
                    if isinstance(previous_block, SFC_Step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   801
                        previous_block.RemoveOutput()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   802
                        self.RefreshStepModel(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   803
                    elif isinstance(previous_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   804
                        if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   805
                            self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   806
                        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   807
                            previous_block.RemoveBranch(previous)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   808
                            if previous_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   809
                                self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   810
                            else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   811
                                self.RefreshDivergenceModel(previous_block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   812
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   813
    def DeleteTransition(self, transition):
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   814
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   815
            Viewer.DeleteTransition(self, transition)
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
            previous = transition.GetPreviousConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   818
            previous_block = previous.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   819
            next = transition.GetNextConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   820
            next_block = next.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   821
            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
   822
                wires = previous.GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   823
                if len(wires) != 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   824
                    return
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   825
                wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   826
                wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   827
                self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   828
                wires = next.GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   829
                if len(wires) != 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   830
                    return
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   831
                wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   832
                wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   833
                self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   834
                transition.Clean()
44
c6e153273ea1 Bugs on SFCViewer fixed
lbessard
parents: 42
diff changeset
   835
                self.RemoveBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   836
                self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   837
                previous_block.RemoveBranch(previous)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   838
                if previous_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   839
                    self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   840
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   841
                    self.RefreshDivergenceModel(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   842
                next_block.RemoveBranch(next)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   843
                if next_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   844
                    self.DeleteDivergence(next_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   845
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   846
                    self.RefreshDivergenceModel(next_block)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   847
            
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   848
    def DeleteDivergence(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   849
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   850
            Viewer.DeleteDivergence(self, divergence)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   851
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   852
            connectors = divergence.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   853
            type = divergence.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   854
            if type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   855
                wires = connectors["outputs"][0].GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   856
                if len(wires) > 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   857
                    return
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   858
                elif len(wires) == 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   859
                    next = wires[0][0].StartConnected
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   860
                    next_block = next.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   861
                    wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   862
                    wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   863
                    self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   864
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   865
                    next = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   866
                    next_block = None
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   867
                for index, connector in enumerate(connectors["inputs"]):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   868
                    if next and index == 0:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   869
                        wires = connector.GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   870
                        wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   871
                        previous = wires[0][0].EndConnected
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   872
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   873
                        self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   874
                    else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   875
                        if type == SELECTION_CONVERGENCE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   876
                            wires = connector.GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   877
                            previous_block = wires[0][0].EndConnected.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   878
                            self.RemoveTransition(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   879
                        wires = connector.GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   880
                        wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   881
                        previous_connector = wire.EndConnected
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   882
                        previous_block = previous_connector.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   883
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   884
                        self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   885
                        if isinstance(previous_block, SFC_Step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   886
                            previous_block.RemoveOutput()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   887
                            self.RefreshStepModel(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   888
                        elif isinstance(previous_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   889
                            if previous_block.GetType() in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   890
                                previous_block.RemoveBranch(previous_connector)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   891
                                if previous_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   892
                                    self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   893
                                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   894
                                    self.RefreshDivergenceModel(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   895
                            else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   896
                                self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   897
                divergence.Clean()
44
c6e153273ea1 Bugs on SFCViewer fixed
lbessard
parents: 42
diff changeset
   898
                self.RemoveBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   899
                self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   900
                if next:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   901
                    wire = self.ConnectConnectors(next, previous)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   902
                    previous_block = previous.GetParentBlock()
45
42637f721b5b Bugs fixed
lbessard
parents: 44
diff changeset
   903
                    previous_pos = previous.GetPosition(False)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   904
                    next_pos = next.GetPosition(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   905
                    wire_size = GetWireSize(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   906
                    previous_block.RefreshOutputPosition((0, previous_pos.y + wire_size - next_pos.y))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   907
                    wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   908
                        wx.Point(previous_pos.x, previous_pos.y)])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   909
                    if isinstance(next_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   910
                        next_block.RefreshPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   911
                    previous_block.RefreshOutputModel(True)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   912
            elif divergence.GetBranchNumber() == 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   913
                wires = connectors["inputs"][0].GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   914
                if len(wires) != 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   915
                    return
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   916
                wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   917
                previous = wire.EndConnected
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   918
                previous_block = previous.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   919
                wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   920
                self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   921
                wires = connectors["outputs"][0].GetWires()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   922
                if len(wires) != 1:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   923
                    return
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   924
                wire = wires[0][0]
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   925
                next = wire.StartConnected
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   926
                next_block = next.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   927
                wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   928
                self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   929
                divergence.Clean()
44
c6e153273ea1 Bugs on SFCViewer fixed
lbessard
parents: 42
diff changeset
   930
                self.RemoveBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   931
                self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   932
                wire = self.ConnectConnectors(next, previous)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   933
                previous_pos = previous.GetPosition(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   934
                next_pos = next.GetPosition(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   935
                wire_size = GetWireSize(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   936
                previous_block.RefreshOutputPosition((previous_pos.x - next_pos.x, previous_pos.y + wire_size - next_pos.y))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   937
                wire.SetPoints([wx.Point(previous_pos.x, previous_pos.y + wire_size), 
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 58
diff changeset
   938
                    wx.Point(previous_pos.x, previous_pos.y)])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   939
                if isinstance(next_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   940
                    next_block.RefreshPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   941
                previous_block.RefreshOutputModel(True)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   942
            
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   943
    def DeleteJump(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   944
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   945
            Viewer.DeleteJump(self, jump)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   946
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   947
            previous = jump.GetPreviousConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   948
            previous_block = previous.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   949
            if isinstance(previous_block, SFC_Transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   950
                self.RemoveTransition(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   951
                previous = jump.GetPreviousConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   952
                if previous:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   953
                    previous_block = previous.GetParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   954
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   955
                    previous_block = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   956
            wires = previous.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   957
            if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   958
                return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   959
            wire = wires[0][0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   960
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   961
            self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   962
            jump.Clean()
44
c6e153273ea1 Bugs on SFCViewer fixed
lbessard
parents: 42
diff changeset
   963
            self.RemoveBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   964
            self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   965
            if isinstance(previous_block, SFC_Step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   966
                previous_block.RemoveOutput()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   967
                self.RefreshStepModel(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   968
            elif isinstance(previous_block, SFC_Divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   969
                if previous_block.GetType() in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   970
                    self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   971
                else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   972
                    previous_block.RemoveBranch(previous)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   973
                    if previous_block.GetBranchNumber() < 2:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   974
                        self.DeleteDivergence(previous_block)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   975
                    else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   976
                        previous_block.RefreshModel()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   977
            
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   978
    def DeleteActionBlock(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   979
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   980
            Viewer.DeleteActionBlock(self, actionblock)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   981
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   982
            connector = actionblock.GetConnector()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   983
            wires = connector.GetWires()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   984
            if len(wires) != 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   985
                return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   986
            wire = wires[0][0]
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   987
            step = wire.EndConnected.GetParentBlock()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   988
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   989
            self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   990
            actionblock.Clean()
44
c6e153273ea1 Bugs on SFCViewer fixed
lbessard
parents: 42
diff changeset
   991
            self.RemoveBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 112
diff changeset
   992
            self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   993
            step.RemoveAction()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   994
            self.RefreshStepModel(step)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   995
            step.RefreshOutputPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   996
            step.RefreshOutputModel(True)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   997
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   998
    def DeleteWire(self, wire):
28
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.DeleteWire(self, wire)
122
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1001
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1002
#-------------------------------------------------------------------------------
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1003
#                          Model update functions
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1004
#-------------------------------------------------------------------------------
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1005
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1006
    def RefreshBlockModel(self, block):
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1007
        blockid = block.GetId()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1008
        infos = {}
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1009
        infos["type"] = block.GetType()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1010
        infos["name"] = block.GetName()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1011
        infos["x"], infos["y"] = block.GetPosition()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1012
        infos["width"], infos["height"] = block.GetSize()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1013
        infos["connectors"] = block.GetConnectors()
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1014
        self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
e6faee0c271b Adding support for Project Tree selected item following current item edited.
lbessard
parents: 121
diff changeset
  1015