Viewer.py
author lbessard
Fri, 09 Jan 2009 17:09:59 +0100
changeset 297 e837b67cb184
parent 292 800e100038ae
child 299 15669fe26e56
permissions -rw-r--r--
Adding help menu for inserting complex variable in graphical viewer
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: 3
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: 3
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
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    26
if wx.VERSION >= (2, 8, 0):
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    27
    USE_AUI = True
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    28
else:
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    29
    USE_AUI = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
from plcopen.structures import *
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
    32
from PLCControler import ITEM_POU
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    33
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    34
from Dialogs import *
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    35
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    36
from types import TupleType
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    37
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    38
SCROLLBAR_UNIT = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    39
WINDOW_BORDER = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    40
SCROLL_ZONE = 10
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    42
def AppendMenu(parent, help, id, kind, text):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    43
    if wx.VERSION >= (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    44
        parent.Append(help=help, id=id, kind=kind, text=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    45
    else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    46
        parent.Append(helpString=help, id=id, kind=kind, item=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    47
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    48
if wx.Platform == '__WXMSW__':
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    49
    faces = { 'times': 'Times New Roman',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    50
              'mono' : 'Courier New',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    51
              'helv' : 'Arial',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    52
              'other': 'Comic Sans MS',
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
    53
              'size' : 20,
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    54
             }
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    55
else:
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    56
    faces = { 'times': 'Times',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    57
              'mono' : 'Courier',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    58
              'helv' : 'Helvetica',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    59
              'other': 'new century schoolbook',
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
    60
              'size' : 20,
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    61
             }
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    62
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    63
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    64
#                       Graphic elements Viewer base class
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    65
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    66
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    67
# ID Constants for alignment menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    68
[ID_VIEWERALIGNMENTMENUITEMS0, ID_VIEWERALIGNMENTMENUITEMS1,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    69
 ID_VIEWERALIGNMENTMENUITEMS2, ID_VIEWERALIGNMENTMENUITEMS4,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    70
 ID_VIEWERALIGNMENTMENUITEMS5, ID_VIEWERALIGNMENTMENUITEMS6,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    71
] = [wx.NewId() for _init_coll_AlignmentMenu_Items in range(6)]
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    72
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    73
# ID Constants for contextual menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    74
[ID_VIEWERCONTEXTUALMENUITEMS0, ID_VIEWERCONTEXTUALMENUITEMS1,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    75
 ID_VIEWERCONTEXTUALMENUITEMS2, ID_VIEWERCONTEXTUALMENUITEMS3,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    76
 ID_VIEWERCONTEXTUALMENUITEMS5, ID_VIEWERCONTEXTUALMENUITEMS6,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    77
 ID_VIEWERCONTEXTUALMENUITEMS8, ID_VIEWERCONTEXTUALMENUITEMS9,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    78
 ID_VIEWERCONTEXTUALMENUITEMS11, ID_VIEWERCONTEXTUALMENUITEMS12,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    79
 ID_VIEWERCONTEXTUALMENUITEMS14, ID_VIEWERCONTEXTUALMENUITEMS16,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    80
 ID_VIEWERCONTEXTUALMENUITEMS17,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
    81
] = [wx.NewId() for _init_coll_ContextualMenu_Items in range(13)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    82
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    83
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    84
class ViewerDropTarget(wx.TextDropTarget):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    85
    
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    86
    def __init__(self, parent):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    87
        wx.TextDropTarget.__init__(self)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
    88
        self.ParentWindow = parent
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    89
    
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
    90
    def OnDropText(self, x, y, data):
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
    91
        x, y = self.ParentWindow.CalcUnscrolledPosition(x, y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
    92
        scaling = self.ParentWindow.Scaling
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    93
        message = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    94
        try:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    95
            values = eval(data)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    96
        except:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    97
            message = "Invalid value \"%s\" for viewer block"%data
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    98
            values = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    99
        if not isinstance(values, TupleType):
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   100
            message = "Invalid value \"%s\" for viewer block"%data
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   101
            values = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   102
        if values is not None:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   103
            if values[1] == "debug":
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   104
                pass
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   105
            elif values[1] == "program":
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   106
                message = "Programs can't be used by other POUs!"
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   107
            elif values[1] in ["function", "functionBlock", "program"]:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   108
                name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   109
                words = self.ParentWindow.TagName.split("::")
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   110
                if name == values[0]:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   111
                    message = "\"%s\" can't use itself!"%name
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   112
                elif type == "function" and values[1] != "function":
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   113
                    message = "Function Blocks can't be used in Functions!"
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   114
                elif words[0] == "T" and values[1] != "function":
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   115
                    message = "Function Blocks can't be used in Transitions!"
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   116
                elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug):
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   117
                    message = "\"%s\" is already used by \"%s\"!"%(name, values[0])
195
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   118
                else:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   119
                    blockname = values[2]
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   120
                    if len(values) > 3:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   121
                        blockinputs = values[3]
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   122
                    else:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   123
                        blockinputs = None
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   124
                    if values[1] != "function" and blockname == "":
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   125
                        dialog = wx.TextEntryDialog(self.ParentWindow.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   126
                        if dialog.ShowModal() == wx.ID_OK:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   127
                            blockname = dialog.GetValue()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   128
                        else:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   129
                            return
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   130
                        dialog.Destroy()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   131
                    if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   132
                        message = "\"%s\" pou already exists!"%blockname
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   133
                    elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(self.ParentWindow.GetTagName(), self.ParentWindow.Debug)]:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   134
                        message = "\"%s\" element for this pou already exists!"%blockname
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   135
                    else:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   136
                        id = self.ParentWindow.GetNewId()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   137
                        block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   138
                        width, height = block.GetMinSize()
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   139
                        if scaling is not None:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   140
                            x = round(float(x) / float(scaling[0])) * scaling[0]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   141
                            y = round(float(y) / float(scaling[1])) * scaling[1]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   142
                            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   143
                            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   144
                        block.SetPosition(x, y)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   145
                        block.SetSize(width, height)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   146
                        self.ParentWindow.AddBlock(block)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   147
                        self.ParentWindow.Controler.AddEditedElementBlock(self.ParentWindow.GetTagName(), id, values[0], blockname)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   148
                        self.ParentWindow.RefreshBlockModel(block)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   149
                        self.ParentWindow.RefreshBuffer()
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   150
                        self.ParentWindow.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   151
                        self.ParentWindow.RefreshVisibleElements()
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   152
                        self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName())
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   153
                        self.ParentWindow.Refresh(False)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   154
            elif values[1] != "location":
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   155
                tagname = self.ParentWindow.GetTagName()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   156
                if values[3] == tagname:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   157
                    if values[1] == "Output":
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   158
                        var_class = OUTPUT
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   159
                    elif values[1] == "InOut":
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   160
                        var_class = INPUT
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   161
                    else:
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   162
                        var_class = INPUT
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   163
                    tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   164
                    if tree is not None:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   165
                        if len(tree) > 0:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   166
                            menu = wx.Menu(title='')
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   167
                            self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   168
                            self.ParentWindow.PopupMenuXY(menu)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   169
                        else:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   170
                            self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2])
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   171
                    else:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   172
                        message = "Unknown variable \"%s\" this POU!" % values[0]
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   173
                else:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   174
                    message = "Variable don't belong to this POU!"
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   175
        if message is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   176
            wx.CallAfter(self.ShowMessage, message)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   177
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   178
    def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   179
        for child_name, child_type, child_tree in tree:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   180
            if base_path:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   181
                child_path = "%s.%s" % (base_path, child_name)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   182
            else:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   183
                child_path = child_name
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   184
            if len(child_tree) == 1 and isinstance(child_tree[0], ListType):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   185
                child_path += "[0]"
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   186
                child_name += "[]"
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   187
                child_tree = child_tree[0]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   188
            new_id = wx.NewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   189
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   190
            self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   191
            if len(child_tree) > 0:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   192
                new_id = wx.NewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   193
                child_menu = wx.Menu(title='')
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   194
                self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   195
                menu.AppendMenu(new_id, "%s." % child_name, child_menu)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   196
            
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   197
    def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   198
        def AddVariableFunction(event):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   199
            self.AddParentVariableBlock(x, y, scaling, var_class, var_name, var_type)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   200
        return AddVariableFunction
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   201
    
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   202
    def AddParentVariableBlock(self, x, y, scaling, var_class, var_name, var_type):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   203
        id = self.ParentWindow.GetNewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   204
        variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   205
        width, height = variable.GetMinSize()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   206
        if scaling is not None:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   207
            x = round(float(x) / float(scaling[0])) * scaling[0]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   208
            y = round(float(y) / float(scaling[1])) * scaling[1]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   209
            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   210
            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   211
        variable.SetPosition(x, y)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   212
        variable.SetSize(width, height)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   213
        self.ParentWindow.AddBlock(variable)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   214
        self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_class)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   215
        self.ParentWindow.RefreshVariableModel(variable)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   216
        self.ParentWindow.RefreshBuffer()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   217
        self.ParentWindow.RefreshScrollBars()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   218
        self.ParentWindow.RefreshVisibleElements()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   219
        self.ParentWindow.Refresh(False)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   220
    
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   221
    def ShowMessage(self, message):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   222
        message = wx.MessageDialog(self.ParentWindow, message, "Error", wx.OK|wx.ICON_ERROR)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   223
        message.ShowModal()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   224
        message.Destroy()
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   225
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   226
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   227
"""
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   228
Class that implements a Viewer based on a wx.ScrolledWindow for drawing and 
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   229
manipulating graphic elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   230
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   231
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   232
class Viewer(wx.ScrolledWindow):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
    
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   234
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   235
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   236
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   237
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   238
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   239
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   240
    
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   241
    # Create Alignment Menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   242
    def _init_coll_AlignmentMenu_Items(self, parent):
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   243
        # Create menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   244
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS0,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   245
              kind=wx.ITEM_NORMAL, text=u'Left')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   246
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS1,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   247
              kind=wx.ITEM_NORMAL, text=u'Center')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   248
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS2,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   249
              kind=wx.ITEM_NORMAL, text=u'Right')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   250
        parent.AppendSeparator()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   251
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS4,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   252
              kind=wx.ITEM_NORMAL, text=u'Top')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   253
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS5,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   254
              kind=wx.ITEM_NORMAL, text=u'Middle')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   255
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS6,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   256
              kind=wx.ITEM_NORMAL, text=u'Bottom')
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   257
        # Link menu event to corresponding called functions
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   258
        self.Bind(wx.EVT_MENU, self.OnAlignLeftMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   259
              id=ID_VIEWERALIGNMENTMENUITEMS0)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   260
        self.Bind(wx.EVT_MENU, self.OnAlignCenterMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   261
              id=ID_VIEWERALIGNMENTMENUITEMS1)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   262
        self.Bind(wx.EVT_MENU, self.OnAlignRightMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   263
              id=ID_VIEWERALIGNMENTMENUITEMS2)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   264
        self.Bind(wx.EVT_MENU, self.OnAlignTopMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   265
              id=ID_VIEWERALIGNMENTMENUITEMS4)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   266
        self.Bind(wx.EVT_MENU, self.OnAlignMiddleMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   267
              id=ID_VIEWERALIGNMENTMENUITEMS5)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   268
        self.Bind(wx.EVT_MENU, self.OnAlignBottomMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   269
              id=ID_VIEWERALIGNMENTMENUITEMS6)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   270
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   271
    # Create Contextual Menu items
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   272
    def _init_coll_ContextualMenu_Items(self, parent):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
        # Create menu items
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   274
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS0,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
              kind=wx.ITEM_RADIO, text=u'No Modifier')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   276
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS1,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
              kind=wx.ITEM_RADIO, text=u'Negated')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   278
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS2,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
              kind=wx.ITEM_RADIO, text=u'Rising Edge')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   280
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS3,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
              kind=wx.ITEM_RADIO, text=u'Falling Edge')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   283
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS5,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   284
              kind=wx.ITEM_NORMAL, text=u'Add Wire Segment')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   285
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS6,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   286
              kind=wx.ITEM_NORMAL, text=u'Delete Wire Segment')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   287
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   288
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS8,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   289
              kind=wx.ITEM_NORMAL, text=u'Add Divergence Branch')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   290
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS9,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   291
              kind=wx.ITEM_NORMAL, text=u'Delete Divergence Branch')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   292
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   293
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS11,
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   294
              kind=wx.ITEM_NORMAL, text=u'Clear Execution Order')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   295
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS12,
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   296
              kind=wx.ITEM_NORMAL, text=u'Reset Execution Order')
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   297
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   298
        parent.AppendMenu(ID_VIEWERCONTEXTUALMENUITEMS14, "Alignment", self.AlignmentMenu)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   299
        parent.AppendSeparator()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   300
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS16,
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
   301
              kind=wx.ITEM_NORMAL, text=u'Edit Block')
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   302
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS17,
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
              kind=wx.ITEM_NORMAL, text=u'Delete')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
        # Link menu event to corresponding called functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
        self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   306
              id=ID_VIEWERCONTEXTUALMENUITEMS0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
        self.Bind(wx.EVT_MENU, self.OnNegatedMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   308
              id=ID_VIEWERCONTEXTUALMENUITEMS1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
        self.Bind(wx.EVT_MENU, self.OnRisingEdgeMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   310
              id=ID_VIEWERCONTEXTUALMENUITEMS2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   311
        self.Bind(wx.EVT_MENU, self.OnFallingEdgeMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   312
              id=ID_VIEWERCONTEXTUALMENUITEMS3)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   313
        self.Bind(wx.EVT_MENU, self.OnAddSegmentMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   314
              id=ID_VIEWERCONTEXTUALMENUITEMS5)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   315
        self.Bind(wx.EVT_MENU, self.OnDeleteSegmentMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   316
              id=ID_VIEWERCONTEXTUALMENUITEMS6)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   317
        self.Bind(wx.EVT_MENU, self.OnAddBranchMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   318
              id=ID_VIEWERCONTEXTUALMENUITEMS8)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   319
        self.Bind(wx.EVT_MENU, self.OnDeleteBranchMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   320
              id=ID_VIEWERCONTEXTUALMENUITEMS9)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   321
        self.Bind(wx.EVT_MENU, self.OnClearExecutionOrderMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   322
              id=ID_VIEWERCONTEXTUALMENUITEMS11)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   323
        self.Bind(wx.EVT_MENU, self.OnResetExecutionOrderMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   324
              id=ID_VIEWERCONTEXTUALMENUITEMS12)
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
   325
        self.Bind(wx.EVT_MENU, self.OnEditBlockMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   326
              id=ID_VIEWERCONTEXTUALMENUITEMS16)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   328
              id=ID_VIEWERCONTEXTUALMENUITEMS17)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   329
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
    # Create and initialize Contextual Menu
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
    def _init_menus(self):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   332
        self.AlignmentMenu = wx.Menu(title='')
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   333
        self.ContextualMenu = wx.Menu(title='')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   334
        
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   335
        self._init_coll_AlignmentMenu_Items(self.AlignmentMenu)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   336
        self._init_coll_ContextualMenu_Items(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   337
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   338
    # Create a new Viewer
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   339
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   340
        wx.ScrolledWindow.__init__(self, parent, pos=wx.Point(0, 0), size=wx.Size(0, 0), 
195
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   341
            style=wx.HSCROLL | wx.VSCROLL)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   342
        self._init_menus()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
        # Adding a rubberband to Viewer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
        self.rubberBand = RubberBand(drawingSurface=self)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   345
        self.SetBackgroundColour(wx.Colour(255,255,255))
224
e5bf78b847e1 Bug with AutoBufferedPaintDC and Background style fixed
lbessard
parents: 222
diff changeset
   346
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
        self.Scaling = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
        self.DrawGrid = True
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   350
        self.GridBrush = wx.TRANSPARENT_BRUSH
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   351
        self.PageSize = None
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   352
        self.PagePen = wx.TRANSPARENT_PEN
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   353
        self.DrawingWire = False
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   354
        self.current_id = 0
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   355
        self.TagName = tagname
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   356
        self.Errors = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   357
        self.Debug = debug
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   358
        self.InstancePath = instancepath
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   359
        
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   360
        # Initialize Block, Wire and Comment numbers
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   361
        self.block_id = self.wire_id = self.comment_id = 0
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   362
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   363
        # Initialize Viewer mode to Selection mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   364
        self.Mode = MODE_SELECTION
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   365
        self.SavedMode = False
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   366
        self.CurrentLanguage = "FBD"
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   367
        
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   368
        self.ParentWindow = window
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   369
        self.Controler = controler
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   370
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   371
        if not self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   372
            self.SetDropTarget(ViewerDropTarget(self))
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   373
        
156
2a2e974302fe Adding support for Viewer font
lbessard
parents: 155
diff changeset
   374
        dc = wx.ClientDC(self)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   375
        font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   376
        dc.SetFont(font)
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   377
        width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   378
        while width > 260:
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
   379
            faces["size"] -= 1
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   380
            font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   381
            dc.SetFont(font)
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   382
            width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   383
        self.SetFont(font)
156
2a2e974302fe Adding support for Viewer font
lbessard
parents: 155
diff changeset
   384
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   385
        self.ResetView()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   386
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   387
        # Link Viewer event to corresponding methods
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   388
        self.Bind(wx.EVT_PAINT, self.OnPaint)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   389
        self.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   390
        self.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   391
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnViewerLeftDClick)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   392
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   393
        self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
   394
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   395
        self.Bind(wx.EVT_MOTION, self.OnViewerMotion)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   396
        self.Bind(wx.EVT_CHAR, self.OnChar)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   397
        self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow)
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   398
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   399
        self.Bind(wx.EVT_SIZE, self.OnMoveWindow)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   400
    
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   401
    def GetScrolledRect(self, rect):
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   402
        rect.x, rect.y = self.CalcScrolledPosition(rect.x, rect.y)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   403
        return rect
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   404
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   405
    def GetScaling(self):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   406
        return self.Scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   407
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   408
    def SetTagName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   409
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   410
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   411
    def GetTagName(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   412
        return self.TagName
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   413
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   414
    def GetInstancePath(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   415
        return self.InstancePath
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   416
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   417
    def IsViewing(self, tagname):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   418
        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   419
            return self.InstancePath == tagname
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   420
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   421
            return self.TagName == tagname
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   422
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
    # Returns a new id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
    def GetNewId(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
        self.current_id += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
        return self.current_id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   427
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   428
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   429
    def __del__(self):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   430
        self.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   432
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   433
    def GetLogicalDC(self, buffered=False):
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   434
        if buffered:
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   435
            dc = wx.AutoBufferedPaintDC(self)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   436
        else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   437
            dc = wx.ClientDC(self)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   438
        dc.SetFont(self.GetFont())
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   439
        if wx.VERSION >= (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   440
            self.DoPrepareDC(dc)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   441
        else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   442
            self.PrepareDC(dc)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   443
        return dc
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   444
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   445
    def GetMiniFont(self):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   446
        font = self.GetFont()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   447
        return wx.Font(font.GetPointSize() * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   448
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   449
#-------------------------------------------------------------------------------
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   450
#                         Element management functions
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   451
#-------------------------------------------------------------------------------
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   452
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   453
    def AddBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   454
        self.block_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   455
        self.Blocks[block] = self.block_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   456
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   457
    def AddWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   458
        self.wire_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   459
        self.Wires[wire] = self.wire_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   460
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   461
    def AddComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   462
        self.comment_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   463
        self.Comments[comment] = self.comment_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   464
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   465
    def IsBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   466
        return self.Blocks.get(block, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   467
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   468
    def IsWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   469
        return self.Wires.get(wire, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   470
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   471
    def IsComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   472
        return self.Comments.get(comment, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   473
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   474
    def RemoveBlock(self, block):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   475
        self.Blocks.pop(block)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   476
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   477
    def RemoveWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   478
        self.Wires.pop(wire)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   479
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   480
    def RemoveComment(self, comment):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   481
        self.Comments.pop(comment)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   482
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   483
    def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   484
        blocks = self.Blocks.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   485
        wires = self.Wires.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   486
        comments = self.Comments.keys()
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   487
        if sort_blocks:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
   488
            blocks.sort(lambda x, y: cmp(self.Blocks[x], self.Blocks[y]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   489
        if sort_wires:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
   490
            wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   491
        if sort_comments:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
   492
            comments.sort(lambda x, y: cmp(self.Comments[x], self.Comments[y]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   493
        return blocks + wires + comments
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   494
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   495
    def RefreshVisibleElements(self, xp = None, yp = None):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   496
        x, y = self.CalcUnscrolledPosition(0, 0)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   497
        if xp is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   498
            x = xp * self.GetScrollPixelsPerUnit()[0]
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   499
        if yp is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   500
            y = yp * self.GetScrollPixelsPerUnit()[1]
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   501
        width, height = self.GetClientSize()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   502
        screen = wx.Rect(x, y, width, height)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   503
        for comment in self.Comments:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   504
            comment.TestVisible(screen)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   505
        for wire in self.Wires:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   506
            wire.TestVisible(screen)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   507
        for block in self.Blocks:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   508
            block.TestVisible(screen)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   509
            
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   510
#-------------------------------------------------------------------------------
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
#                              Reset functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   514
    # Resets Viewer lists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   515
    def ResetView(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   516
        self.Blocks = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   517
        self.Wires = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   518
        self.Comments = {}
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   519
        self.Subscribed = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
        self.SelectedElement = None
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
   521
        self.HighlightedElement = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   523
    def Flush(self):
264
11d5e2cb6faa Bug on debug step without output fixed
lbessard
parents: 261
diff changeset
   524
        for element, iec_path in self.Subscribed.iteritems():
11d5e2cb6faa Bug on debug step without output fixed
lbessard
parents: 261
diff changeset
   525
            self.Controler.UnsubscribeDebugIECVariable(iec_path, element)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   526
        for block in self.Blocks:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   527
            block.Flush()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   528
    
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   529
    # Remove all elements
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   530
    def CleanView(self):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   531
        for block in self.Blocks.keys():
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   532
            block.Clean()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   533
        self.ResetView()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   534
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   535
    # Changes Viewer mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
    def SetMode(self, mode):
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   537
        if self.Mode != mode or mode == MODE_SELECTION:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   538
            self.Mode = mode
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   539
            self.SavedMode = False
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   540
        else:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   541
            self.SavedMode = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
        # Reset selection
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   543
        if self.Mode != MODE_SELECTION and self.SelectedElement:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
            self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
            self.SelectedElement = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   546
    
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   547
    # Return current drawing mode
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   548
    def GetDrawingMode(self):
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   549
        return self.ParentWindow.GetDrawingMode()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   550
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   551
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   552
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   553
        self.Controler.BufferProject()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   554
        self.ParentWindow.RefreshTitle()
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   555
        self.ParentWindow.RefreshEditMenu()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   556
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   557
    # Refresh the current scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   558
    def RefreshScaling(self, refresh=True):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   559
        properties = self.Controler.GetProjectProperties(self.Debug)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   560
        scaling = properties["scaling"][self.CurrentLanguage]
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   561
        if scaling != (0, 0):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   562
            self.Scaling = scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   563
            if self.DrawGrid:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   564
                bitmap = wx.EmptyBitmap(*scaling)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   565
                dc = wx.MemoryDC(bitmap)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   566
                dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   567
                dc.Clear()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   568
                dc.SetPen(wx.Pen(wx.Colour(180, 180, 180)))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   569
                dc.DrawPoint(0, 0)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   570
                self.GridBrush = wx.BrushFromBitmap(bitmap)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   571
            else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   572
                self.GridBrush = wx.TRANSPARENT_BRUSH
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   573
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   574
            self.Scaling = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   575
            self.GridBrush = wx.TRANSPARENT_BRUSH
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   576
        page_size = properties["pageSize"]
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   577
        if page_size != (0, 0):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   578
            self.PageSize = map(int, page_size)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   579
            self.PagePen = wx.Pen(wx.Colour(180, 180, 180))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   580
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   581
            self.PageSize = None
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   582
            self.PagePen = wx.TRANSPARENT_PEN
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   583
        if refresh:
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
   584
            self.Refresh(False)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   585
        
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   586
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   587
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   588
#                          Refresh functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   589
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   590
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   591
    def ResetBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   592
        pass
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   593
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   594
    # Refresh Viewer elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   595
    def RefreshView(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
        self.current_id = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   597
        # Start by reseting Viewer
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   598
        self.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
        self.ResetView()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   600
        instance = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
        # List of ids of already loaded blocks
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
        ids = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
        # Load Blocks until they are all loaded
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   604
        while instance is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   605
            instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, exclude = ids, debug = self.Debug)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   606
            if instance is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
                self.loadInstance(instance, ids)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   608
        self.RefreshScrollBars()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   609
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   610
        for wire in self.Wires:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   611
            if not wire.IsConnectedCompatible():
222
8ce5c2635976 Adding support for underlying type incompatible wire loaded instead of removing them
lbessard
parents: 218
diff changeset
   612
                wire.MarkAsInvalid()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   613
            if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   614
                block = wire.EndConnected.GetParentBlock()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   615
                if isinstance(block, LD_PowerRail):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   616
                    wire.SetValue(True)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   617
                if isinstance(block, FBD_Block):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   618
                    blockname = block.GetName()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   619
                    connectorname = wire.EndConnected.GetName()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   620
                    if blockname != "":
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   621
                        iec_path = "%s.%s.%s"%(self.InstancePath, block.GetName(), connectorname)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   622
                    else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   623
                        if connectorname == "":
279
2ad276084038 Bug involving possible name conflict between return value and ouputs fixed
lbessard
parents: 277
diff changeset
   624
                            iec_path = "%s.%s%d"%(self.InstancePath, block.GetType(), block.GetId())
2ad276084038 Bug involving possible name conflict between return value and ouputs fixed
lbessard
parents: 277
diff changeset
   625
                        else:
2ad276084038 Bug involving possible name conflict between return value and ouputs fixed
lbessard
parents: 277
diff changeset
   626
                            iec_path = "%s.%s%d_%s"%(self.InstancePath, block.GetType(), block.GetId(), connectorname)
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   627
                    if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), wire) is not None:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   628
                        self.Subscribed[wire] = iec_path.upper()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   629
                    else:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   630
                        wire.SetValue("undefined")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   631
                elif isinstance(block, FBD_Variable):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   632
                    iec_path = "%s.%s"%(self.InstancePath, block.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   633
                    if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), wire) is not None:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   634
                        self.Subscribed[wire] = iec_path.upper()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   635
                    else:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   636
                        wire.SetValue("undefined")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   637
                elif isinstance(block, FBD_Connector):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   638
                    wire.SetValue("undefined")
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   639
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   640
        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   641
            for block in self.Blocks.keys():
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   642
                block.SpreadCurrent()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   643
                if isinstance(block, LD_Contact):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   644
                    iec_path = "%s.%s"%(self.InstancePath, block.GetName())
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   645
                    if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   646
                        self.Subscribed[block] = iec_path.upper()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   647
                elif isinstance(block, SFC_Step):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   648
                    iec_path = "%s.%s.X"%(self.InstancePath, block.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   649
                    if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   650
                        self.Subscribed[block] = iec_path.upper()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   651
                elif isinstance(block, SFC_Transition):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   652
                    connectors = block.GetConnectors()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   653
                    previous_steps = self.GetPreviousSteps(connectors["input"])
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   654
                    next_steps = self.GetNextSteps(connectors["output"])
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   655
                    iec_path = "%s.%s->%s"%(self.InstancePath, ",".join(previous_steps), ",".join(next_steps))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   656
                    if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   657
                        self.Subscribed[block] = iec_path.upper()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   658
                
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   659
        self.RefreshVisibleElements()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   660
        self.ShowErrors()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
   661
        self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   662
    
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   663
    def GetPreviousSteps(self, connector):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   664
        steps = []
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   665
        for wire, handle in connector.GetWires():
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   666
            previous = wire.GetOtherConnected(connector).GetParentBlock()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   667
            if isinstance(previous, SFC_Step):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   668
                steps.append(previous.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   669
            elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   670
                connectors = previous.GetConnectors()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   671
                for input in connectors["inputs"]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   672
                    steps.extend(self.GetPreviousSteps(input))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   673
        return steps
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   674
    
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   675
    def GetNextSteps(self, connector):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   676
        steps = []
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   677
        for wire, handle in connector.GetWires():
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   678
            next = wire.GetOtherConnected(connector).GetParentBlock()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   679
            if isinstance(next, SFC_Step):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   680
                steps.append(next.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   681
            elif isinstance(next, SFC_Jump):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   682
                steps.append(next.GetTarget())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   683
            elif isinstance(next, SFC_Divergence) and next.GetType() in [SIMULTANEOUS_DIVERGENCE, SELECTION_CONVERGENCE]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   684
                connectors = next.GetConnectors()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   685
                for output in connectors["outputs"]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   686
                    steps.extend(self.GetNextSteps(output))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   687
        return steps
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   688
    
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   689
    def GetMaxSize(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   690
        maxx = maxy = 0
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   691
        for element in self.GetElements():
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   692
            bbox = element.GetBoundingBox()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   693
            maxx = max(maxx, bbox.x + bbox.width)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   694
            maxy = max(maxy, bbox.y + bbox.height)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   695
        return maxx, maxy
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   696
    
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   697
    def RefreshScrollBars(self):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   698
        xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   699
        window_size = self.GetClientSize()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   700
        maxx, maxy = self.GetMaxSize()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   701
        maxx = max(maxx + WINDOW_BORDER, xstart * SCROLLBAR_UNIT + window_size[0])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   702
        maxy = max(maxy + WINDOW_BORDER, ystart * SCROLLBAR_UNIT + window_size[1])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   703
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   704
            extent = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   705
            maxx = max(maxx, extent.x + extent.width)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   706
            maxy = max(maxy, extent.y + extent.height)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   707
        self.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   708
            round(maxx / SCROLLBAR_UNIT), round(maxy / SCROLLBAR_UNIT), 
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   709
            xstart, ystart, True)
95
ee66a9a1748b Corrections for wx version 2.8.4 and Windows
lbessard
parents: 94
diff changeset
   710
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   711
    # Load instance from given informations
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   712
    def loadInstance(self, instance, ids):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   713
        ids.append(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   714
        self.current_id = max(self.current_id, instance["id"]) 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   715
        if instance["type"] == "input":
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   716
            variable = FBD_Variable(self, INPUT, instance["name"], instance["value_type"], instance["id"], instance["executionOrder"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   717
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   718
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   719
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   720
            connectors = variable.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   721
            connectors["output"].SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   722
            if instance["connector"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   723
                connectors["output"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   724
            if instance["connector"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   725
                connectors["output"].SetEdge(instance["connector"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   726
        elif instance["type"] == "output":
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   727
            variable = FBD_Variable(self, OUTPUT, instance["name"], instance["value_type"], instance["id"], instance["executionOrder"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   728
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   729
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   730
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   731
            connectors = variable.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   732
            connectors["input"].SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   733
            if instance["connector"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   734
                connectors["input"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   735
            if instance["connector"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   736
                connectors["input"].SetEdge(instance["connector"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   737
            self.CreateWires(connectors["input"], instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   738
        elif instance["type"] == "inout":
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   739
            variable = FBD_Variable(self, INOUT, instance["name"], instance["value_type"], instance["id"], instance["executionOrder"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   740
            variable.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   741
            variable.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   742
            self.AddBlock(variable)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   743
            connectors = variable.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   744
            connectors["output"].SetPosition(wx.Point(*instance["connectors"]["output"]["position"]))
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   745
            connectors["input"].SetPosition(wx.Point(*instance["connectors"]["input"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   746
            if instance["connectors"]["output"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   747
                connectors["output"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   748
            if instance["connectors"]["output"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   749
                connectors["output"].SetEdge(instance["connectors"]["output"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   750
            if instance["connectors"]["input"]["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   751
                connectors["input"].SetNegated(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   752
            if instance["connectors"]["input"]["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   753
                connectors["input"].SetEdge(instance["connectors"]["input"]["edge"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   754
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   755
        elif instance["type"] == "continuation":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   756
            connection = FBD_Connector(self, CONTINUATION, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   757
            connection.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   758
            connection.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   759
            self.AddBlock(connection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   760
            connector = connection.GetConnector()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   761
            connector.SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   762
        elif instance["type"] == "connection":
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   763
            connection = FBD_Connector(self, CONNECTOR, instance["name"], instance["id"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   764
            connection.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   765
            connection.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   766
            self.AddBlock(connection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   767
            connector = connection.GetConnector()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   768
            connector.SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   769
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   770
        elif instance["type"] == "comment":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   771
            comment = Comment(self, instance["content"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   772
            comment.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   773
            comment.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   774
            self.AddComment(comment)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   775
        elif instance["type"] == "leftPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   776
            leftpowerrail = LD_PowerRail(self, LEFTRAIL, instance["id"], [True for i in range(len(instance["connectors"]))])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   777
            leftpowerrail.SetPosition(instance["x"], instance["y"])
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   778
            leftpowerrail.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   779
            self.AddBlock(leftpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   780
            connectors = leftpowerrail.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   781
            for i, connector in enumerate(instance["connectors"]):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   782
                connectors[i].SetPosition(wx.Point(*connector["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   783
        elif instance["type"] == "rightPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   784
            rightpowerrail = LD_PowerRail(self, RIGHTRAIL, instance["id"], [True for i in range(len(instance["connectors"]))])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   785
            rightpowerrail.SetPosition(instance["x"], instance["y"])
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   786
            rightpowerrail.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   787
            self.AddBlock(rightpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   788
            connectors = rightpowerrail.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   789
            for i, connector in enumerate(instance["connectors"]):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   790
                connectors[i].SetPosition(wx.Point(*connector["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   791
                self.CreateWires(connectors[i], connector["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   792
        elif instance["type"] == "contact":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   793
            if instance["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   794
                negated = instance["negated"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   795
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   796
                negated = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   797
            if instance["edge"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   798
                edge = instance["edge"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   799
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   800
                edge = "none"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   801
            if negated and edge == "none":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   802
                contact_type = CONTACT_REVERSE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   803
            elif not negated and edge == "rising":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   804
                contact_type = CONTACT_RISING
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   805
            elif not negated and edge == "falling":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   806
                contact_type = CONTACT_FALLING
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   807
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   808
                contact_type = CONTACT_NORMAL
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   809
            contact = LD_Contact(self, contact_type, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   810
            contact.SetPosition(instance["x"], instance["y"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   811
            contact.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   812
            self.AddBlock(contact)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   813
            connectors = contact.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   814
            connectors["input"].SetPosition(wx.Point(*instance["connectors"]["input"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   815
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   816
            connectors["output"].SetPosition(wx.Point(*instance["connectors"]["output"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   817
        elif instance["type"] == "coil":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   818
            if instance["negated"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   819
                negated = instance["negated"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   820
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   821
                negated = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   822
            if instance["storage"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   823
                storage = instance["storage"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   824
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   825
                storage = "none"
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   826
            if instance["edge"]:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   827
                edge = instance["edge"]
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   828
            else:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   829
                edge = "none"
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   830
            if negated and storage == "none" and edge == "none":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   831
                coil_type = COIL_REVERSE
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   832
            elif not negated and edge == "none" and storage == "set":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   833
                coil_type = COIL_SET
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   834
            elif not negated and edge == "none" and storage == "reset":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   835
                coil_type = COIL_RESET
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   836
            elif not negated and storage == "none" and edge == "rising":
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   837
                coil_type = COIL_RISING
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   838
            elif not negated and storage == "none" and edge == "falling":
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   839
                coil_type = COIL_FALLING
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   840
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   841
                coil_type = COIL_NORMAL
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   842
            coil = LD_Coil(self, coil_type, instance["name"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   843
            coil.SetPosition(instance["x"], instance["y"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   844
            coil.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   845
            self.AddBlock(coil)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   846
            connectors = coil.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   847
            connectors["input"].SetPosition(wx.Point(*instance["connectors"]["input"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   848
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   849
            connectors["output"].SetPosition(wx.Point(*instance["connectors"]["output"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   850
        elif instance["type"] == "step":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   851
            if instance["initial"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   852
                initial = instance["initial"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   853
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   854
                initial = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   855
            step = SFC_Step(self, instance["name"], initial, instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   856
            step.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   857
            step.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   858
            self.AddBlock(step)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   859
            if "output" in instance["connectors"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   860
                step.AddOutput()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   861
            if "action" in instance["connectors"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   862
                step.AddAction()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   863
            connectors = step.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   864
            if connectors["input"]:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   865
                connectors["input"].SetPosition(wx.Point(*instance["connectors"]["input"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   866
                self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   867
            if connectors["output"]:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   868
                connectors["output"].SetPosition(wx.Point(*instance["connectors"]["output"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   869
            if connectors["action"]:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   870
                connectors["action"].SetPosition(wx.Point(*instance["connectors"]["action"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   871
        elif instance["type"] == "transition":
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   872
            transition = SFC_Transition(self, instance["condition_type"], instance["condition"], instance["priority"], instance["id"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   873
            transition.SetPosition(instance["x"], instance["y"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   874
            transition.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   875
            self.AddBlock(transition)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   876
            connectors = transition.GetConnectors()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   877
            connectors["input"].SetPosition(wx.Point(*instance["connectors"]["input"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   878
            self.CreateWires(connectors["input"], instance["connectors"]["input"]["links"], ids)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   879
            connectors["output"].SetPosition(wx.Point(*instance["connectors"]["output"]["position"]))
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   880
            if instance["condition_type"] == "connection":
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   881
                self.CreateWires(connectors["connection"], instance["connectors"]["connection"]["links"], ids)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   882
        elif instance["type"] in ["selectionDivergence", "selectionConvergence", "simultaneousDivergence", "simultaneousConvergence"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   883
            if instance["type"] == "selectionDivergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   884
                divergence = SFC_Divergence(self, SELECTION_DIVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   885
                    len(instance["connectors"]["outputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   886
            elif instance["type"] == "selectionConvergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   887
                divergence = SFC_Divergence(self, SELECTION_CONVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   888
                    len(instance["connectors"]["inputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   889
            elif instance["type"] == "simultaneousDivergence":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   890
                divergence = SFC_Divergence(self, SIMULTANEOUS_DIVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   891
                    len(instance["connectors"]["outputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   892
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   893
                divergence = SFC_Divergence(self, SIMULTANEOUS_CONVERGENCE, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   894
                    len(instance["connectors"]["inputs"]), instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   895
            divergence.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   896
            divergence.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   897
            self.AddBlock(divergence)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   898
            connectors = divergence.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   899
            for i, input_connector in enumerate(instance["connectors"]["inputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   900
                connector = connectors["inputs"][i]
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   901
                connector.SetPosition(wx.Point(*input_connector["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   902
                self.CreateWires(connector, input_connector["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   903
            for i, output_connector in enumerate(instance["connectors"]["outputs"]):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   904
                connector = connectors["outputs"][i]
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   905
                connector.SetPosition(wx.Point(*output_connector["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   906
        elif instance["type"] == "jump":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   907
            jump = SFC_Jump(self, instance["target"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   908
            jump.SetPosition(instance["x"], instance["y"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   909
            jump.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   910
            self.AddBlock(jump)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   911
            connector = jump.GetConnector()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   912
            connector.SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   913
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   914
        elif instance["type"] == "actionBlock":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   915
            actionBlock = SFC_ActionBlock(self, instance["actions"], instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   916
            actionBlock.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   917
            actionBlock.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   918
            self.AddBlock(actionBlock)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   919
            connector = actionBlock.GetConnector()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   920
            connector.SetPosition(wx.Point(*instance["connector"]["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   921
            self.CreateWires(connector, instance["connector"]["links"], ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   922
        else:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   923
            connectors = {"inputs" : [], "outputs" : []}
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   924
            executionControl = False
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   925
            for input in instance["connectors"]["inputs"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   926
                if input["negated"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   927
                    connectors["inputs"].append((input["name"], None, "negated"))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   928
                elif input["edge"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   929
                    connectors["inputs"].append((input["name"], None, input["edge"]))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   930
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   931
                    connectors["inputs"].append((input["name"], None, "none"))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   932
            for output in instance["connectors"]["outputs"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   933
                if output["negated"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   934
                    connectors["outputs"].append((output["name"], None, "negated"))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   935
                elif output["edge"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   936
                    connectors["outputs"].append((output["name"], None, output["edge"]))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   937
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   938
                    connectors["outputs"].append((output["name"], None, "none"))
290
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   939
            if len(connectors["inputs"]) > 0 and connectors["inputs"][0][0] == "EN":
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   940
		connectors["inputs"].pop(0)
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   941
	        executionControl = True
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   942
            if len(connectors["outputs"]) > 0 and connectors["outputs"][0][0] == "ENO":
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   943
                connectors["outputs"].pop(0)
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   944
                executionControl = True
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   945
            if instance["name"] is None:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   946
                instance["name"] = ""
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   947
            block = FBD_Block(self, instance["type"], instance["name"], 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   948
                    instance["id"], len(connectors["inputs"]), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   949
                    connectors=connectors, executionControl=executionControl, 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   950
                    executionOrder=instance["executionOrder"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   951
            block.SetPosition(instance["x"], instance["y"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   952
            block.SetSize(instance["width"], instance["height"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   953
            self.AddBlock(block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   954
            connectors = block.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   955
            for i, input_connector in enumerate(instance["connectors"]["inputs"]):
195
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   956
                if i < len(connectors["inputs"]):
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   957
                    connector = connectors["inputs"][i]
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   958
                    connector.SetPosition(wx.Point(*input_connector["position"]))
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   959
                    if input_connector["negated"]:
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   960
                        connector.SetNegated(True)
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   961
                    if input_connector["edge"] != "none":
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   962
                        connector.SetEdge(input_connector["edge"])
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   963
                    self.CreateWires(connector, input_connector["links"], ids)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   964
            for i, output_connector in enumerate(instance["connectors"]["outputs"]):
195
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   965
                if i < len(connectors["outputs"]):
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   966
                    connector = connectors["outputs"][i]
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   967
                    if output_connector["negated"]:
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   968
                        connector.SetNegated(True)
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   969
                    if output_connector["edge"] != "none":
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   970
                        connector.SetEdge(output_connector["edge"])
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   971
                    connector.SetPosition(wx.Point(*output_connector["position"]))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   972
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   973
    def CreateWires(self, start_connector, links, ids):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   974
        for link in links:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   975
            refLocalId = link["refLocalId"]
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   976
            if refLocalId is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   977
                if refLocalId not in ids:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   978
                    new_instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, refLocalId, debug = self.Debug)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   979
                    if new_instance is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   980
                        self.loadInstance(new_instance, ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   981
                connected = self.FindElementById(refLocalId)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   982
                if connected is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   983
                    points = link["points"]
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   984
                    end_connector = connected.GetConnector(wx.Point(points[-1][0], points[-1][1]), link["formalParameter"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   985
                    if end_connector is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   986
                        wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   987
                        wire.SetPoints(points)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   988
                        start_connector.Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   989
                        end_connector.Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   990
                        wire.ConnectStartPoint(None, start_connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   991
                        wire.ConnectEndPoint(None, end_connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   992
                        self.AddWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   993
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   994
    def IsOfType(self, type, reference):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   995
        return self.Controler.IsOfType(type, reference, self.Debug)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   996
    
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   997
    def IsEndType(self, type):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   998
        return self.Controler.IsEndType(type)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   999
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1000
    def GetBlockType(self, type, inputs = None):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1001
        return self.Controler.GetBlockType(type, inputs, self.Debug)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1002
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1003
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1004
#                          Search Element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1005
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1006
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1007
    def FindBlock(self, pos):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1008
        for block in self.Blocks:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1009
            if block.HitTest(pos) or block.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1010
                return block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1011
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1012
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1013
    def FindWire(self, pos):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1014
        for wire in self.Wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1015
            if wire.HitTest(pos) or wire.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1016
                return wire
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1017
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1018
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1019
    def FindElement(self, pos, exclude_group = False):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1020
        if self.SelectedElement and not (exclude_group and isinstance(self.SelectedElement, Graphic_Group)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1021
            if self.SelectedElement.HitTest(pos) or self.SelectedElement.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1022
                return self.SelectedElement
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1023
        for element in self.GetElements():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1024
            if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1025
                return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1026
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1027
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1028
    def FindBlockConnector(self, pos, direction = None, exclude = None):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1029
        for block in self.Blocks:
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1030
            result = block.TestConnector(pos, direction, exclude)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1031
            if result:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1032
                return result
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1033
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1034
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1035
    def FindElementById(self, id):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1036
        for element in self.Blocks:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1037
            if element.GetId() == id:
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1038
                return element
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1039
        for element in self.Comments:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1040
            if element.GetId() == id:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1041
                return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1042
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1043
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1044
    def SearchElements(self, bbox):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1045
        elements = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1046
        for element in self.GetElements():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1047
            if element.IsInSelection(bbox):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1048
                elements.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1049
        return elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1050
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1051
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1052
#                           Popup menu functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1053
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1054
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1055
    def PopupBlockMenu(self, connector = None):
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1056
        if connector is not None and connector.IsCompatible("BOOL"):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1057
            type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1058
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1059
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1060
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, type != "function")
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1061
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, type != "function")
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1062
        else:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1063
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1064
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1065
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1066
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1067
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1068
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1069
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1070
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1071
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1072
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1073
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1074
        if connector is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1075
            if connector.IsNegated():
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1076
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS1, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1077
            elif connector.GetEdge() == "rising":
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1078
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS2, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1079
            elif connector.GetEdge() == "falling":
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1080
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS3, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1081
            else:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1082
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS0, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1083
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1084
    
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1085
    def PopupWireMenu(self, delete=True):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1086
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1087
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1088
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1089
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1090
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, True)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1091
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, delete)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1092
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1093
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1094
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1095
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1096
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1097
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1098
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1099
    def PopupDivergenceMenu(self, connector):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1100
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1101
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1102
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1103
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1104
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1105
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1106
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1107
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, connector)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1108
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1109
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1110
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1111
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1112
    
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1113
    def PopupGroupMenu(self):
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1114
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1115
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1116
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1117
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1118
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1119
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1120
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1121
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1122
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1123
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1124
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1125
        self.PopupMenu(self.ContextualMenu)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1126
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1127
    def PopupDefaultMenu(self, block = True):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1128
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1129
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1130
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1131
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1132
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1133
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1134
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1135
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1136
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1137
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1138
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1139
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1140
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1141
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1142
#                            Menu items functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1143
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1144
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1145
    def OnAlignLeftMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1146
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1147
            self.SelectedElement.AlignElements(ALIGN_LEFT, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1148
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1149
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1150
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1151
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1152
    def OnAlignCenterMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1153
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1154
            self.SelectedElement.AlignElements(ALIGN_CENTER, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1155
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1156
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1157
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1158
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1159
    def OnAlignRightMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1160
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1161
            self.SelectedElement.AlignElements(ALIGN_RIGHT, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1162
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1163
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1164
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1165
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1166
    def OnAlignTopMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1167
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1168
            self.SelectedElement.AlignElements(None, ALIGN_TOP)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1169
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1170
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1171
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1172
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1173
    def OnAlignMiddleMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1174
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1175
            self.SelectedElement.AlignElements(None, ALIGN_MIDDLE)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1176
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1177
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1178
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1179
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1180
    def OnAlignBottomMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1181
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1182
            self.SelectedElement.AlignElements(None, ALIGN_BOTTOM)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1183
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1184
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1185
        event.Skip()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1186
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1187
    def OnNoModifierMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1188
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1189
            self.SelectedElement.SetConnectorNegated(False)
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1190
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1191
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1192
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1193
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1194
    def OnNegatedMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1195
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1196
            self.SelectedElement.SetConnectorNegated(True)
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1197
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1198
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1199
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1200
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1201
    def OnRisingEdgeMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1202
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1203
            self.SelectedElement.SetConnectorEdge("rising")
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1204
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1205
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1206
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1207
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1208
    def OnFallingEdgeMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1209
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1210
            self.SelectedElement.SetConnectorEdge("falling")
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1211
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1212
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1213
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1214
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1215
    def OnAddSegmentMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1216
        if self.SelectedElement is not None and self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1217
            self.SelectedElement.AddSegment()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1218
            self.SelectedElement.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1219
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1220
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1221
    def OnDeleteSegmentMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1222
        if self.SelectedElement is not None and self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1223
            self.SelectedElement.DeleteSegment()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1224
            self.SelectedElement.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1225
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1226
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1227
    def OnAddBranchMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1228
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1229
            self.AddDivergenceBranch(self.SelectedElement)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1230
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1231
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1232
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1233
    def OnDeleteBranchMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1234
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1235
            self.RemoveDivergenceBranch(self.SelectedElement)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1236
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1237
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1238
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1239
    def OnEditBlockMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1240
        if self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1241
            self.ParentWindow.EditProjectElement(ITEM_POU, "P::%s"%self.SelectedElement.GetType())
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1242
        event.Skip()
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1243
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1244
    def OnDeleteMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1245
        if self.SelectedElement is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1246
            self.SelectedElement.Delete()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1247
            self.SelectedElement = None
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1248
            self.RefreshBuffer()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1249
            self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1250
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1251
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1252
    def OnClearExecutionOrderMenu(self, event):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1253
        self.Controler.ClearEditedElementExecutionOrder(self.TagName)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1254
        self.RefreshBuffer()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1255
        self.RefreshView()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1256
        
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1257
    def OnResetExecutionOrderMenu(self, event):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1258
        self.Controler.ResetEditedElementExecutionOrder(self.TagName)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1259
        self.RefreshBuffer()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1260
        self.RefreshView()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1261
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1262
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1263
#                          Mouse event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1264
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1265
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1266
    def OnViewerLeftDown(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1267
        if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1268
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1269
            pos = event.GetLogicalPosition(dc)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1270
            if event.ControlDown() and self.SelectedElement is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1271
                element = self.FindElement(pos, True)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1272
                if element is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1273
                    if isinstance(self.SelectedElement, Graphic_Group):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1274
                        self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1275
                        self.SelectedElement.SelectElement(element)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1276
                    elif self.SelectedElement is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1277
                        group = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1278
                        group.SelectElement(self.SelectedElement)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1279
                        group.SelectElement(element)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1280
                        self.SelectedElement = group
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1281
                    elements = self.SelectedElement.GetElements()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1282
                    if len(elements) == 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1283
                        self.SelectedElement = element
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1284
                    elif len(elements) == 1:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1285
                        self.SelectedElement = elements[0]
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1286
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1287
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1288
                element = self.FindElement(pos)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1289
                if not self.Debug and (element is None or element.TestHandle(pos) == (0, 0)):
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1290
                    connector = self.FindBlockConnector(pos)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1291
                else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1292
                    connector = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1293
                if not self.Debug and self.DrawingWire:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1294
                    self.DrawingWire = False
174
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1295
                    if self.SelectedElement is not None:
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1296
                        if element is None or element.TestHandle(pos) == (0, 0):
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1297
                            connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1298
                        if connector is not None:
174
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1299
                            event.Dragging = lambda : True
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1300
                            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1301
                        if self.SelectedElement.EndConnected is not None:
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1302
                            self.SelectedElement.ResetPoints()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1303
                            self.SelectedElement.GeneratePoints()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1304
                            self.SelectedElement.RefreshModel()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1305
                            self.SelectedElement.SetSelected(True)
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1306
                            element = self.SelectedElement
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1307
                            self.RefreshBuffer()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1308
                        else:
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1309
                            rect = self.SelectedElement.GetRedrawRect()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1310
                            self.SelectedElement.Delete()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1311
                            self.SelectedElement = None
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1312
                            element = None
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1313
                            self.RefreshRect(self.GetScrolledRect(rect), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1314
                elif not self.Debug and connector is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1315
                    self.DrawingWire = True
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1316
                    scaled_pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1317
                    if (connector.GetDirection() == EAST):
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1318
                        wire = Wire(self, [wx.Point(pos.x, pos.y), EAST], [wx.Point(scaled_pos.x, scaled_pos.y), WEST])
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1319
                    else:
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1320
                        wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(scaled_pos.x, scaled_pos.y), EAST])
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1321
                    wire.oldPos = scaled_pos
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1322
                    wire.Handle = (HANDLE_POINT, 0)
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1323
                    wire.ProcessDragging(0, 0, False, None)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1324
                    wire.Handle = (HANDLE_POINT, 1)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1325
                    self.AddWire(wire)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1326
                    if self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1327
                        self.SelectedElement.SetSelected(False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1328
                    self.SelectedElement = wire
259
fae941a87cff Bug with invisible created wires fixed
lbessard
parents: 253
diff changeset
  1329
                    self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1330
                    self.SelectedElement.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1331
                else:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1332
                    if self.SelectedElement is not None and self.SelectedElement != element:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1333
                        self.SelectedElement.SetSelected(False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1334
                        self.SelectedElement = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1335
                    if element is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1336
                        self.SelectedElement = element
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1337
                        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1338
                            Graphic_Element.OnLeftDown(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1339
                        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1340
                            self.SelectedElement.OnLeftDown(event, dc, self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1341
                        self.SelectedElement.Refresh()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1342
                    else:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1343
                        self.rubberBand.Reset()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1344
                        self.rubberBand.OnLeftDown(event, dc, self.Scaling)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1345
        elif self.Mode in [MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1346
                           MODE_CONTACT, MODE_COIL, MODE_POWERRAIL, MODE_INITIALSTEP, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1347
                           MODE_STEP, MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION]:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1348
            self.rubberBand.Reset()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1349
            self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1350
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1351
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1352
    def OnViewerLeftUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1353
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1354
            if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1355
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1356
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1357
                if len(elements) == 1:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1358
                    self.SelectedElement = elements[0]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1359
                    self.SelectedElement.SetSelected(True)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1360
                elif len(elements) > 1:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1361
                    self.SelectedElement = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1362
                    self.SelectedElement.SetElements(elements)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1363
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1364
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1365
                bbox = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1366
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)                
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1367
                if self.Mode == MODE_BLOCK:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1368
                    wx.CallAfter(self.AddNewBlock, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1369
                elif self.Mode == MODE_VARIABLE:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1370
                    wx.CallAfter(self.AddNewVariable, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1371
                elif self.Mode == MODE_CONNECTION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1372
                    wx.CallAfter(self.AddNewConnection, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1373
                elif self.Mode == MODE_COMMENT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1374
                    wx.CallAfter(self.AddNewComment, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1375
                elif self.Mode == MODE_CONTACT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1376
                    wx.CallAfter(self.AddNewContact, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1377
                elif self.Mode == MODE_COIL:
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1378
                    wx.CallAfter(self.AddNewCoil, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1379
                elif self.Mode == MODE_POWERRAIL:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1380
                    wx.CallAfter(self.AddNewPowerRail, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1381
                elif self.Mode == MODE_INITIALSTEP:
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1382
                    wx.CallAfter(self.AddNewStep, bbox, True)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1383
                elif self.Mode == MODE_STEP:
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1384
                    wx.CallAfter(self.AddNewStep, bbox, False)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1385
                elif self.Mode == MODE_TRANSITION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1386
                    wx.CallAfter(self.AddNewTransition, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1387
                elif self.Mode == MODE_DIVERGENCE:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1388
                    wx.CallAfter(self.AddNewDivergence, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1389
                elif self.Mode == MODE_JUMP:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1390
                    wx.CallAfter(self.AddNewJump, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1391
                elif self.Mode == MODE_ACTION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1392
                    wx.CallAfter(self.AddNewActionBlock, bbox)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1393
        elif self.Mode == MODE_SELECTION and self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1394
            dc = self.GetLogicalDC()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1395
            if not self.Debug and self.DrawingWire:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1396
                pos = event.GetLogicalPosition(dc)
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1397
                connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection())
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1398
                if self.SelectedElement.EndConnected is not None:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1399
                    self.DrawingWire = False
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1400
                    self.SelectedElement.StartConnected.HighlightParentBlock(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1401
                    self.SelectedElement.EndConnected.HighlightParentBlock(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1402
                    self.SelectedElement.ResetPoints()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1403
                    self.SelectedElement.OnMotion(event, dc, self.Scaling)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1404
                    self.SelectedElement.GeneratePoints()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1405
                    self.SelectedElement.RefreshModel()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1406
                    if self.HighlightedElement is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1407
                        self.HighlightedElement.SetHighlighted(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1408
                        self.HighlightedElement = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1409
                    self.SelectedElement.SetHighlighted(True)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1410
                    self.HighlightedElement = self.SelectedElement
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1411
                    self.SelectedElement.SetSelected(True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1412
                    self.RefreshBuffer()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1413
                elif connector is None or self.SelectedElement.GetDragging():
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1414
                    self.DrawingWire = False
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1415
                    rect = self.SelectedElement.GetRedrawRect()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1416
                    self.SelectedElement.Delete()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1417
                    self.SelectedElement = None
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1418
                    self.RefreshRect(self.GetScrolledRect(rect), False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1419
            else:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1420
                if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1421
                    Graphic_Element.OnLeftUp(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1422
                else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1423
                    self.SelectedElement.OnLeftUp(event, dc, self.Scaling)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1424
                wx.CallAfter(self.SetCursor, wx.NullCursor)
106
3fc63036de16 Adding support for variable type compatibility check after drag and drop
lbessard
parents: 102
diff changeset
  1425
        if self.Mode != MODE_SELECTION and not self.SavedMode:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  1426
            wx.CallAfter(self.ParentWindow.ResetCurrentMode)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1427
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1428
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1429
    def OnViewerRightDown(self, event):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1430
        if self.Mode == MODE_SELECTION:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1431
            dc = self.GetLogicalDC()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1432
            pos = event.GetLogicalPosition(dc)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1433
            element = self.FindElement(pos)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1434
            if self.SelectedElement is not None and self.SelectedElement != element:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1435
                self.SelectedElement.SetSelected(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1436
                self.SelectedElement = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1437
            if element:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1438
                self.SelectedElement = element
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1439
                if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1440
                    Graphic_Element.OnRightDown(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1441
                else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1442
                    self.SelectedElement.OnRightDown(event, dc, self.Scaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1443
                self.SelectedElement.Refresh()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1444
        event.Skip()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1445
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1446
    def OnViewerRightUp(self, event):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1447
        dc = self.GetLogicalDC()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1448
        if self.SelectedElement is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1449
            if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1450
                Graphic_Element.OnRightUp(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1451
            else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1452
                self.SelectedElement.OnRightUp(event, dc, self.Scaling)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1453
            wx.CallAfter(self.SetCursor, wx.NullCursor)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1454
        elif not self.Debug:
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1455
            self.PopupDefaultMenu(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1456
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1457
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1458
    def OnViewerLeftDClick(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1459
        if self.Mode == MODE_SELECTION and self.SelectedElement is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1460
            if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1461
                Graphic_Element.OnLeftDClick(self.SelectedElement, event, self.GetLogicalDC(), self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1462
            elif event.ControlDown() and self.IsBlock(self.SelectedElement) and self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug):
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1463
                self.ParentWindow.EditProjectElement(ITEM_POU, self.SelectedElement.GetType())
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1464
            else:
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1465
                self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1466
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1467
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1468
    def OnViewerMotion(self, event):
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1469
        refresh = False
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1470
        dc = self.GetLogicalDC()
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1471
        pos = GetScaledEventPosition(event, dc, self.Scaling)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1472
        if not event.Dragging():
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1473
            highlighted = self.FindElement(pos) 
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1474
            if self.HighlightedElement is not None and self.HighlightedElement != highlighted:
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1475
                self.HighlightedElement.SetHighlighted(False)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1476
                self.HighlightedElement = None
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1477
            if highlighted is not None and self.HighlightedElement != highlighted:
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1478
                highlighted.SetHighlighted(True)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1479
            self.HighlightedElement = highlighted
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1480
        if self.rubberBand.IsShown():
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1481
            self.rubberBand.OnMotion(event, dc, self.Scaling)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1482
        elif not self.Debug and self.Mode == MODE_SELECTION and self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1483
            if self.DrawingWire:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1484
                connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection(), self.SelectedElement.EndConnected)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1485
                if not connector or self.SelectedElement.EndConnected == None:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1486
                    self.SelectedElement.ResetPoints()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1487
                    movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1488
                    self.SelectedElement.GeneratePoints()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1489
                    if movex != 0 or movey != 0:
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1490
                        self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1491
            else:
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1492
                movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1493
                if movex != 0 or movey != 0:
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1494
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
95
ee66a9a1748b Corrections for wx version 2.8.4 and Windows
lbessard
parents: 94
diff changeset
  1495
        self.UpdateScrollPos(event)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1496
        event.Skip()
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1497
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1498
    def OnLeaveViewer(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1499
        if self.SelectedElement is not None and self.SelectedElement.GetDragging():
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1500
            event.Skip()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1501
        elif self.HighlightedElement is not None:
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1502
            self.HighlightedElement.SetHighlighted(False)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1503
            self.HighlightedElement = None
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1504
        event.Skip()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1505
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1506
    def UpdateScrollPos(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1507
        if (event.Dragging() and self.SelectedElement is not None) or self.rubberBand.IsShown():
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1508
            position = event.GetPosition()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1509
            move_window = wx.Point()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1510
            window_size = self.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1511
            xstart, ystart = self.GetViewStart()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1512
            if position.x < SCROLL_ZONE and xstart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1513
                move_window.x = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1514
            elif position.x > window_size[0] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1515
                move_window.x = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1516
            if position.y < SCROLL_ZONE and ystart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1517
                move_window.y = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1518
            elif position.y > window_size[1] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1519
                move_window.y = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1520
            if move_window.x != 0 or move_window.y != 0:
267
a95bfb76a1eb Bug on refresh in any Viewer fixed
lbessard
parents: 264
diff changeset
  1521
                self.RefreshVisibleElements(xp = xstart + move_window.x, yp = ystart + move_window.y)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1522
                self.Scroll(xstart + move_window.x, ystart + move_window.y)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1523
            self.RefreshScrollBars()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1524
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1525
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1526
#                          Keyboard event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1527
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1528
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1529
    def OnChar(self, event):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1530
        xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1531
        xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1532
        ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1533
        keycode = event.GetKeyCode()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1534
        if self.Scaling is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1535
            scaling = self.Scaling
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1536
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1537
            scaling = (8, 8)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1538
        if not self.Debug and keycode == wx.WXK_DELETE and self.SelectedElement is not None:
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1539
            rect = self.SelectedElement.GetRedrawRect(1, 1)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1540
            self.SelectedElement.Delete()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1541
            self.SelectedElement = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1542
            self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1543
            self.RefreshScrollBars()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1544
            self.SetCursor(wx.NullCursor)
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1545
            self.RefreshRect(self.GetScrolledRect(rect), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1546
        elif not self.Debug and keycode == wx.WXK_RETURN and self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1547
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1548
        elif keycode == wx.WXK_LEFT:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1549
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1550
                self.Scroll(0, ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1551
            elif event.ControlDown():
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1552
                event.Skip()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1553
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1554
                self.SelectedElement.Move(-scaling[0], 0)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1555
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1556
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1557
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1558
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1559
        elif keycode == wx.WXK_RIGHT:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1560
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1561
                self.Scroll(xmax, ypos)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1562
            elif event.ControlDown():
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1563
                event.Skip()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1564
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1565
                self.SelectedElement.Move(scaling[0], 0)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1566
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1567
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1568
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1569
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1570
        elif keycode == wx.WXK_UP:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1571
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1572
                self.Scroll(xpos, 0)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1573
            elif event.ControlDown():
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1574
                event.Skip()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1575
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1576
                self.SelectedElement.Move(0, -scaling[1])
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1577
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1578
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1579
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1580
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1581
        elif keycode == wx.WXK_DOWN:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1582
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1583
                self.Scroll(xpos, ymax)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1584
            elif event.ControlDown():
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1585
                event.Skip()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1586
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1587
                self.SelectedElement.Move(0, scaling[1])
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1588
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1589
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1590
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1591
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1592
        elif not self.Debug and keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging:
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1593
            if self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement):
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1594
                self.CopyBlock(self.SelectedElement, wx.Point(*self.SelectedElement.GetPosition()))
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1595
                self.RefreshBuffer()
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1596
                self.RefreshScrollBars()
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1597
                self.ParentWindow.RefreshVariablePanel(self.TagName)
267
a95bfb76a1eb Bug on refresh in any Viewer fixed
lbessard
parents: 264
diff changeset
  1598
                self.RefreshVisibleElements()
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1599
                self.SelectedElement.Refresh()
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1600
            else:
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1601
                event.Skip()
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1602
        else:
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1603
            event.Skip()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1604
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1605
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1606
#                          Model adding functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1607
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1608
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1609
    def GetScaledSize(self, width, height):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1610
        if self.Scaling is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1611
            width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0]
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1612
            height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1613
        return width, height
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1614
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1615
    def AddNewBlock(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1616
        dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1617
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1618
        dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1619
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1620
        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1621
        dialog.SetMinBlockSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1622
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1623
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1624
            values = dialog.GetValues()
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1625
            values.setdefault("name", "")
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1626
            block = FBD_Block(self, values["type"], values["name"], id, 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1627
                    values["extension"], values["inputs"], 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1628
                    executionControl = values["executionControl"],
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1629
                    executionOrder = values["executionOrder"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1630
            block.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1631
            block.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1632
            self.AddBlock(block)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1633
            self.Controler.AddEditedElementBlock(self.TagName, id, values["type"], values.get("name", None))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1634
            self.RefreshBlockModel(block)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1635
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1636
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1637
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1638
            self.ParentWindow.RefreshVariablePanel(self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  1639
            self.ParentWindow.RefreshInstancesTree()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1640
            block.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1641
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1642
    
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1643
    def AddNewVariable(self, bbox):
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1644
        words = self.TagName.split("::")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1645
        if words[0] == "T":
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1646
            dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler, words[2])
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1647
        else:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1648
            dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1649
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1650
        dialog.SetMinVariableSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1651
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1652
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1653
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1654
            for var in vars:
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1655
                if var["Edit"]:
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1656
                    varlist.append((var["Name"], var["Class"], var["Type"]))
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1657
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1658
        if returntype:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1659
            varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1660
        dialog.SetVariables(varlist)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1661
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1662
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1663
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1664
            variable = FBD_Variable(self, values["type"], values["name"], values["value_type"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1665
            variable.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1666
            variable.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1667
            self.AddBlock(variable)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1668
            self.Controler.AddEditedElementVariable(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1669
            self.RefreshVariableModel(variable)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1670
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1671
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1672
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1673
            variable.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1674
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1675
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1676
    def AddNewConnection(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1677
        dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1678
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1679
        dialog.SetMinConnectionSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1680
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1681
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1682
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1683
            connection = FBD_Connector(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1684
            connection.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1685
            connection.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1686
            self.AddBlock(connection)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1687
            self.Controler.AddEditedElementConnection(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1688
            self.RefreshConnectionModel(connection)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1689
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1690
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1691
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1692
            connection.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1693
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1694
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1695
    def AddNewComment(self, bbox):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1696
        if wx.VERSION >= (2, 5, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1697
            dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1698
        else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1699
            dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1700
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1701
            value = dialog.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1702
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1703
            comment = Comment(self, value, id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1704
            comment.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1705
            min_width, min_height = comment.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1706
            comment.SetSize(*self.GetScaledSize(max(min_width,bbox.width),max(min_height,bbox.height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1707
            self.AddComment(comment)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1708
            self.Controler.AddEditedElementComment(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1709
            self.RefreshCommentModel(comment)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1710
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1711
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1712
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1713
            comment.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1714
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1715
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1716
    def AddNewContact(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1717
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1718
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1719
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1720
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1721
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1722
            for var in vars:
277
5fc11b2d4fbb Bug in contact edition not allowing output referencing fixed
lbessard
parents: 275
diff changeset
  1723
                if var["Type"] == "BOOL":
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1724
                    varlist.append(var["Name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1725
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1726
        dialog.SetValues({"name":"","type":CONTACT_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1727
        dialog.SetElementSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1728
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1729
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1730
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1731
            contact = LD_Contact(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1732
            contact.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1733
            contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1734
            self.AddBlock(contact)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1735
            self.Controler.AddEditedElementContact(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1736
            self.RefreshContactModel(contact)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1737
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1738
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1739
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1740
            contact.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1741
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1742
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1743
    def AddNewCoil(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1744
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1745
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1746
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1747
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1748
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1749
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1750
                if var["Class"] != "Input" and var["Type"] == "BOOL":
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1751
                    varlist.append(var["Name"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1752
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1753
        if returntype == "BOOL":
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1754
            varlist.append(self.Controler.GetEditedElementName(self.TagName))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1755
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1756
        dialog.SetValues({"name":"","type":COIL_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1757
        dialog.SetElementSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1758
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1759
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1760
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1761
            coil = LD_Coil(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1762
            coil.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1763
            coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1764
            self.AddBlock(coil)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1765
            self.Controler.AddEditedElementCoil(self.TagName, id)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1766
            self.RefreshCoilModel(coil)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1767
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1768
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1769
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1770
            coil.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1771
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1772
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1773
    def AddNewPowerRail(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1774
        dialog = LDPowerRailDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1775
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1776
        dialog.SetMinSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1777
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1778
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1779
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1780
            powerrail = LD_PowerRail(self, values["type"], id, [True for i in xrange(values["number"])])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1781
            powerrail.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1782
            powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1783
            self.AddBlock(powerrail)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1784
            self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1785
            self.RefreshPowerRailModel(powerrail)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1786
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1787
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1788
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1789
            powerrail.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1790
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1791
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1792
    def AddNewStep(self, bbox, initial = False):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1793
        dialog = StepContentDialog(self.ParentWindow, self.Controler, initial)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1794
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1795
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1796
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1797
        dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1798
        dialog.SetMinStepSize((bbox.width, bbox.height))
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1799
        if dialog.ShowModal() == wx.ID_OK:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1800
            id = self.GetNewId()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1801
            values = dialog.GetValues()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1802
            step = SFC_Step(self, values["name"], initial, id)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1803
            if values["input"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1804
                step.AddInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1805
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1806
                step.RemoveInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1807
            if values["output"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1808
                step.AddOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1809
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1810
                step.RemoveOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1811
            if values["action"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1812
                step.AddAction()    
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1813
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1814
                step.RemoveAction()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1815
            step.SetPosition(bbox.x, bbox.y)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1816
            min_width, min_height = step.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1817
            step.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1818
            self.AddBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1819
            self.Controler.AddEditedElementStep(self.TagName, id)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1820
            self.RefreshStepModel(step)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1821
            self.RefreshBuffer()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1822
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1823
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1824
            step.Refresh()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1825
        dialog.Destroy()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1826
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1827
    def AddNewTransition(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1828
        dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1829
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1830
        dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1831
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1832
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1833
            values = dialog.GetValues()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1834
            transition = SFC_Transition(self, values["type"], values["value"], values["priority"], id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1835
            transition.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1836
            min_width, min_height = transition.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1837
            transition.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1838
            self.AddBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1839
            self.Controler.AddEditedElementTransition(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1840
            self.RefreshTransitionModel(transition)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1841
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1842
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1843
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1844
            transition.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1845
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1846
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1847
    def AddNewDivergence(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1848
        dialog = DivergenceCreateDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1849
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1850
        dialog.SetMinSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1851
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1852
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1853
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1854
            divergence = SFC_Divergence(self, values["type"], values["number"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1855
            divergence.SetPosition(bbox.x, bbox.y)
111
0ec40799ba11 Bug on divergence creation with null size fixed
lbessard
parents: 108
diff changeset
  1856
            min_width, min_height = divergence.GetMinSize(True)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1857
            divergence.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1858
            self.AddBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1859
            self.Controler.AddEditedElementDivergence(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1860
            self.RefreshDivergenceModel(divergence)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1861
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1862
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1863
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1864
            divergence.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1865
        dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1866
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1867
    def AddNewJump(self, bbox):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1868
        choices = []
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1869
        for block in self.Blocks:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1870
            if isinstance(block, SFC_Step):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1871
                choices.append(block.GetName())
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1872
        dialog = wx.SingleChoiceDialog(self.ParentWindow, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1873
        if dialog.ShowModal() == wx.ID_OK:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1874
            id = self.GetNewId()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1875
            value = dialog.GetStringSelection()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1876
            jump = SFC_Jump(self, value, id)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1877
            jump.SetPosition(bbox.x, bbox.y)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1878
            min_width, min_height = jump.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1879
            jump.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1880
            self.AddBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1881
            self.Controler.AddEditedElementJump(self.TagName, id)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1882
            self.RefreshJumpModel(jump)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1883
            self.RefreshBuffer()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1884
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1885
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1886
            jump.Refresh()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1887
        dialog.Destroy()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1888
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1889
    def AddNewActionBlock(self, bbox):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1890
        dialog = ActionBlockDialog(self.ParentWindow)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1891
        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1892
        dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1893
        dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1894
        if dialog.ShowModal() == wx.ID_OK:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1895
            actions = dialog.GetValues()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1896
            id = self.GetNewId()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1897
            actionblock = SFC_ActionBlock(self, actions, id)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1898
            actionblock.SetPosition(bbox.x, bbox.y)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1899
            min_width, min_height = actionblock.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1900
            actionblock.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1901
            self.AddBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1902
            self.Controler.AddEditedElementActionBlock(self.TagName, id)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1903
            self.RefreshActionBlockModel(actionblock)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1904
            self.RefreshBuffer()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1905
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1906
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1907
            actionblock.Refresh()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1908
        dialog.Destroy()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1909
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1910
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1911
#                          Edit element content functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1912
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1913
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1914
    def EditBlockContent(self, block):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1915
        dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1916
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1917
        dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1918
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1919
        variable_names = self.Controler.GetEditedElementVariables(self.TagName, self.Debug)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1920
        if block.GetName() != "":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1921
            variable_names.remove(block.GetName())
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1922
        dialog.SetPouElementNames(variable_names)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1923
        dialog.SetMinBlockSize(block.GetSize())
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1924
        old_values = {"name" : block.GetName(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1925
                      "type" : block.GetType(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1926
                      "extension" : block.GetExtension(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1927
                      "inputs" : block.GetInputTypes(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1928
                      "executionControl" : block.GetExecutionControl(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1929
                      "executionOrder" : block.GetExecutionOrder()}
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1930
        dialog.SetValues(old_values)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1931
        if dialog.ShowModal() == wx.ID_OK:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1932
            new_values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1933
            rect = block.GetRedrawRect(1, 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1934
            if "name" in new_values:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1935
                block.SetName(new_values["name"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1936
            else:
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1937
                block.SetName("")
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1938
            block.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"]))
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1939
            block.SetType(new_values["type"], new_values["extension"], executionControl = new_values["executionControl"])
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1940
            block.SetExecutionOrder(new_values["executionOrder"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1941
            rect = rect.Union(block.GetRedrawRect())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1942
            self.RefreshBlockModel(block)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1943
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1944
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1945
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1946
            self.ParentWindow.RefreshVariablePanel(self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  1947
            self.ParentWindow.RefreshInstancesTree()
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1948
            if old_values["executionOrder"] != new_values["executionOrder"]:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1949
                self.RefreshView()
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1950
            else:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1951
                block.Refresh(rect)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1952
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1953
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1954
    def EditVariableContent(self, variable):
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1955
        words = self.TagName.split("::")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1956
        if words[0] == "T":
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1957
            dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler, words[2])
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1958
        else:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1959
            dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1960
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1961
        dialog.SetMinVariableSize(variable.GetSize())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1962
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1963
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1964
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1965
            for var in vars:
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1966
                if var["Edit"]:
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1967
                    varlist.append((var["Name"], var["Class"], var["Type"]))
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1968
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1969
        if returntype:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1970
            varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1971
        dialog.SetVariables(varlist)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1972
        old_values = {"name" : variable.GetName(), "type" : variable.GetType(), 
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1973
            "executionOrder" : variable.GetExecutionOrder()}
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1974
        dialog.SetValues(old_values)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1975
        if dialog.ShowModal() == wx.ID_OK:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1976
            new_values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1977
            rect = variable.GetRedrawRect(1, 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1978
            variable.SetName(new_values["name"])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1979
            variable.SetType(new_values["type"], new_values["value_type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1980
            variable.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"]))
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1981
            variable.SetExecutionOrder(new_values["executionOrder"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1982
            rect = rect.Union(variable.GetRedrawRect())
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1983
            if old_values["type"] != new_values["type"]:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1984
                id = variable.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1985
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1986
                self.Controler.AddEditedElementVariable(self.TagName, id, new_values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1987
            self.RefreshVariableModel(variable)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1988
            if old_values["executionOrder"] != new_values["executionOrder"]:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1989
                self.RefreshView()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1990
            self.RefreshBuffer()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1991
            self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1992
            self.RefreshScrollBars()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  1993
            variable.Refresh(rect)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1994
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1995
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1996
    def EditConnectionContent(self, connection):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1997
        dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1998
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1999
        dialog.SetMinConnectionSize(connection.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2000
        values = {"name" : connection.GetName(), "type" : connection.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2001
        dialog.SetValues(values)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2002
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2003
            old_type = connection.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2004
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2005
            rect = connection.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2006
            connection.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2007
            connection.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2008
            connection.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2009
            rect = rect.Union(connection.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2010
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2011
                id = connection.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2012
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2013
                self.Controler.AddEditedElementConnection(self.TagName, id, values["type"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2014
            self.RefreshConnectionModel(connection)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2015
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2016
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2017
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2018
            connection.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2019
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2020
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2021
    def EditContactContent(self, contact):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2022
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2023
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2024
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2025
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2026
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2027
            for var in vars:
277
5fc11b2d4fbb Bug in contact edition not allowing output referencing fixed
lbessard
parents: 275
diff changeset
  2028
                if var["Type"] == "BOOL":
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2029
                    varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2030
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2031
        values = {"name" : contact.GetName(), "type" : contact.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2032
        dialog.SetValues(values)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2033
        dialog.SetElementSize(contact.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2034
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2035
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2036
            rect = contact.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2037
            contact.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2038
            contact.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2039
            contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2040
            rect = rect.Union(contact.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2041
            self.RefreshContactModel(contact)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2042
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2043
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2044
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2045
            contact.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2046
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2047
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2048
    def EditCoilContent(self, coil):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2049
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2050
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2051
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2052
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2053
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2054
            for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2055
                if var["Class"] != "Input" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2056
                    varlist.append(var["Name"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2057
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2058
        if returntype == "BOOL":
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2059
            varlist.append(self.Controler.GetEditedElementName(self.TagName))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2060
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2061
        values = {"name" : coil.GetName(), "type" : coil.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2062
        dialog.SetValues(values)
61
dc7142ae9438 Adding possibility to change Type and Pin number of power rails
lbessard
parents: 58
diff changeset
  2063
        dialog.SetElementSize(coil.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2064
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2065
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2066
            rect = coil.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2067
            coil.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2068
            coil.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2069
            coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2070
            rect = rect.Union(coil.GetRedrawRect())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2071
            self.RefreshCoilModel(coil)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2072
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2073
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2074
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2075
            coil.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2076
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2077
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2078
    def EditPowerRailContent(self, powerrail):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2079
        dialog = LDPowerRailDialog(self.ParentWindow, self.Controler, powerrail.GetType(), len(powerrail.GetConnectors()))
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2080
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2081
        dialog.SetMinSize(powerrail.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2082
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2083
            old_type = powerrail.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2084
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2085
            rect = powerrail.GetRedrawRect(1, 1)
61
dc7142ae9438 Adding possibility to change Type and Pin number of power rails
lbessard
parents: 58
diff changeset
  2086
            powerrail.SetType(values["type"], [True for i in xrange(values["number"])])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2087
            powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2088
            rect = rect.Union(powerrail.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2089
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2090
                id = powerrail.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2091
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2092
                self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2093
            self.RefreshPowerRailModel(powerrail)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2094
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2095
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2096
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2097
            powerrail.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2098
        dialog.Destroy()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2099
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2100
    def EditStepContent(self, step):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2101
        dialog = StepContentDialog(self.ParentWindow, self.Controler, step.GetInitial())
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2102
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2103
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2104
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2105
        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: 70
diff changeset
  2106
        dialog.SetMinStepSize(step.GetSize())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2107
        values = {"name" : step.GetName()}
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2108
        connectors = step.GetConnectors()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2109
        values["input"] = connectors["input"] != None
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2110
        values["output"] = connectors["output"] != None
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2111
        values["action"] = connectors["action"] != None
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2112
        dialog.SetValues(values)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2113
        if dialog.ShowModal() == wx.ID_OK:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2114
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2115
            rect = step.GetRedrawRect(1, 1)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2116
            step.SetName(values["name"])
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2117
            if values["input"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2118
                step.AddInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2119
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2120
                step.RemoveInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2121
            if values["output"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2122
                step.AddOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2123
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2124
                step.RemoveOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2125
            if values["action"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2126
                step.AddAction()    
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2127
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2128
                step.RemoveAction()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2129
            step.UpdateSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2130
            rect = rect.Union(step.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2131
            self.RefreshStepModel(step)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2132
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2133
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2134
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2135
            step.Refresh(rect)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2136
        
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2137
    def EditTransitionContent(self, transition):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2138
        dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2139
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2140
        dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2141
        dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2142
        dialog.SetElementSize(transition.GetSize())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2143
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2144
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2145
            rect = transition.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2146
            transition.SetType(values["type"],values["value"])
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2147
            transition.SetPriority(values["priority"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2148
            rect = rect.Union(transition.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2149
            self.RefreshTransitionModel(transition)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2150
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2151
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2152
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2153
            transition.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2154
        dialog.Destroy()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2155
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2156
    def EditJumpContent(self, jump):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2157
        choices = []
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2158
        for block in self.Blocks:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2159
            if isinstance(block, SFC_Step):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2160
                choices.append(block.GetName())
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2161
        dialog = wx.SingleChoiceDialog(self.ParentWindow, "Edit jump target", "Please choose a target", choices, wx.OK|wx.CANCEL)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2162
        dialog.SetSelection(choices.index(jump.GetTarget()))
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2163
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2164
            value = dialog.GetStringSelection()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2165
            rect = jump.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2166
            jump.SetTarget(value)
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2167
            rect = rect.Union(jump.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2168
            self.RefreshJumpModel(jump)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2169
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2170
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2171
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2172
            jump.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2173
        dialog.Destroy()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2174
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2175
    def EditActionBlockContent(self, actionblock):
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2176
        dialog = ActionBlockDialog(self.ParentWindow)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2177
        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2178
        dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2179
        dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2180
        dialog.SetValues(actionblock.GetActions())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2181
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2182
            actions = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2183
            rect = actionblock.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2184
            actionblock.SetActions(actions)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2185
            actionblock.SetSize(*self.GetScaledSize(*actionblock.GetSize()))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2186
            rect = rect.Union(actionblock.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2187
            self.RefreshActionBlockModel(actionblock)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2188
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2189
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2190
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2191
            actionblock.Refresh(rect)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2192
        dialog.Destroy()
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2193
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2194
    def EditCommentContent(self, comment):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2195
        if wx.VERSION >= (2, 5, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2196
            dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2197
        else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2198
            dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2199
        if dialog.ShowModal() == wx.ID_OK:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2200
            value = dialog.GetValue()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2201
            rect = comment.GetRedrawRect(1, 1)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2202
            comment.SetContent(value)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2203
            comment.SetSize(*self.GetScaledSize(*comment.GetSize()))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2204
            rect = rect.Union(comment.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2205
            self.RefreshCommentModel(comment)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2206
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2207
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2208
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2209
            comment.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2210
        dialog.Destroy()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2211
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2212
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2213
#                          Model update functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2214
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2215
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2216
    def RefreshBlockModel(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2217
        blockid = block.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2218
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2219
        infos["type"] = block.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2220
        infos["name"] = block.GetName()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2221
        if self.CurrentLanguage == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2222
            infos["executionOrder"] = block.GetExecutionOrder()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2223
        infos["x"], infos["y"] = block.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2224
        infos["width"], infos["height"] = block.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2225
        infos["connectors"] = block.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2226
        self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2227
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2228
    def RefreshVariableModel(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2229
        variableid = variable.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2230
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2231
        infos["name"] = variable.GetName()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2232
        if self.CurrentLanguage == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2233
            infos["executionOrder"] = variable.GetExecutionOrder()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2234
        infos["x"], infos["y"] = variable.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2235
        infos["width"], infos["height"] = variable.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2236
        infos["connectors"] = variable.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2237
        self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2238
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2239
    def RefreshConnectionModel(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2240
        connectionid = connection.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2241
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2242
        infos["name"] = connection.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2243
        infos["x"], infos["y"] = connection.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2244
        infos["width"], infos["height"] = connection.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2245
        infos["connector"] = connection.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2246
        self.Controler.SetEditedElementConnectionInfos(self.TagName, connectionid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2247
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2248
    def RefreshCommentModel(self, comment):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2249
        commentid = comment.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2250
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2251
        infos["content"] = comment.GetContent()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2252
        infos["x"], infos["y"] = comment.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2253
        infos["width"], infos["height"] = comment.GetSize()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2254
        self.Controler.SetEditedElementCommentInfos(self.TagName, commentid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2255
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2256
    def RefreshPowerRailModel(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2257
        powerrailid = powerrail.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2258
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2259
        infos["x"], infos["y"] = powerrail.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2260
        infos["width"], infos["height"] = powerrail.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2261
        infos["connectors"] = powerrail.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2262
        self.Controler.SetEditedElementPowerRailInfos(self.TagName, powerrailid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2263
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2264
    def RefreshContactModel(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2265
        contactid = contact.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2266
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2267
        infos["name"] = contact.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2268
        infos["type"] = contact.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2269
        infos["x"], infos["y"] = contact.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2270
        infos["width"], infos["height"] = contact.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2271
        infos["connectors"] = contact.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2272
        self.Controler.SetEditedElementContactInfos(self.TagName, contactid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2273
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2274
    def RefreshCoilModel(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2275
        coilid = coil.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2276
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2277
        infos["name"] = coil.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2278
        infos["type"] = coil.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2279
        infos["x"], infos["y"] = coil.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2280
        infos["width"], infos["height"] = coil.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2281
        infos["connectors"] = coil.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2282
        self.Controler.SetEditedElementCoilInfos(self.TagName, coilid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2283
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2284
    def RefreshStepModel(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2285
        stepid = step.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2286
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2287
        infos["name"] = step.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2288
        infos["initial"] = step.GetInitial()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2289
        infos["x"], infos["y"] = step.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2290
        infos["width"], infos["height"] = step.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2291
        infos["connectors"] = step.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2292
        self.Controler.SetEditedElementStepInfos(self.TagName, stepid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2293
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2294
    def RefreshTransitionModel(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2295
        transitionid = transition.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2296
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2297
        infos["type"] = transition.GetType()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2298
        infos["priority"] = transition.GetPriority()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2299
        infos["condition"] = transition.GetCondition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2300
        infos["x"], infos["y"] = transition.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2301
        infos["width"], infos["height"] = transition.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2302
        infos["connectors"] = transition.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2303
        self.Controler.SetEditedElementTransitionInfos(self.TagName, transitionid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2304
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2305
    def RefreshDivergenceModel(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2306
        divergenceid = divergence.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2307
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2308
        infos["x"], infos["y"] = divergence.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2309
        infos["width"], infos["height"] = divergence.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2310
        infos["connectors"] = divergence.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2311
        self.Controler.SetEditedElementDivergenceInfos(self.TagName, divergenceid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2312
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2313
    def RefreshJumpModel(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2314
        jumpid = jump.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2315
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2316
        infos["target"] = jump.GetTarget()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2317
        infos["x"], infos["y"] = jump.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2318
        infos["width"], infos["height"] = jump.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2319
        infos["connector"] = jump.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2320
        self.Controler.SetEditedElementJumpInfos(self.TagName, jumpid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2321
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2322
    def RefreshActionBlockModel(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2323
        actionblockid = actionblock.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2324
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2325
        infos["actions"] = actionblock.GetActions()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2326
        infos["x"], infos["y"] = actionblock.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2327
        infos["width"], infos["height"] = actionblock.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2328
        infos["connector"] = actionblock.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2329
        self.Controler.SetEditedElementActionBlockInfos(self.TagName, actionblockid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2330
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2331
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2332
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2333
#                          Model delete functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2334
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2335
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2336
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2337
    def DeleteBlock(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2338
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2339
        for output in block.GetConnectors()["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2340
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2341
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2342
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2343
        block.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2344
        self.RemoveBlock(block)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2345
        self.Controler.RemoveEditedElementInstance(self.TagName, block.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2346
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2347
            element.RefreshModel()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2348
        wx.CallAfter(self.ParentWindow.RefreshVariablePanel, self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2349
        wx.CallAfter(self.ParentWindow.RefreshInstancesTree)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2350
        
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2351
    def DeleteVariable(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2352
        connectors = variable.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2353
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2354
            elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2355
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2356
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2357
        variable.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2358
        self.RemoveBlock(variable)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2359
        self.Controler.RemoveEditedElementInstance(self.TagName, variable.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2360
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2361
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2362
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2363
    def DeleteConnection(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2364
        if connection.GetType() == CONTINUATION:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2365
            elements = connection.GetConnector().GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2366
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2367
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2368
        connection.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2369
        self.RemoveBlock(connection)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2370
        self.Controler.RemoveEditedElementInstance(self.TagName, connection.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2371
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2372
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2373
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2374
    def DeleteComment(self, comment):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2375
        self.RemoveComment(comment)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2376
        self.Controler.RemoveEditedElementInstance(self.TagName, comment.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2377
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2378
    def DeleteWire(self, wire):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2379
        if wire in self.Wires:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2380
            connected = wire.GetConnected()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2381
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2382
            self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2383
            for connector in connected:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2384
                connector.RefreshParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2385
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2386
    def DeleteContact(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2387
        connectors = contact.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2388
        elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2389
        contact.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2390
        self.RemoveBlock(contact)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2391
        self.Controler.RemoveEditedElementInstance(self.TagName, contact.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2392
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2393
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2394
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2395
    def DeleteCoil(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2396
        connectors = coil.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2397
        elements = connectors["output"].GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2398
        coil.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2399
        self.RemoveBlock(coil)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2400
        self.Controler.RemoveEditedElementInstance(self.TagName, coil.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2401
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2402
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2403
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2404
    def DeletePowerRail(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2405
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2406
        if powerrail.GetType() == LEFTRAIL:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2407
            for connector in powerrail.GetConnectors():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2408
                for element in connector.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2409
                    if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2410
                        elements.append(element)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2411
        powerrail.Clean()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2412
        self.RemoveBlock(powerrail)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2413
        self.Controler.RemoveEditedElementInstance(self.TagName, powerrail.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2414
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2415
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2416
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2417
    def DeleteStep(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2418
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2419
        connectors = step.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2420
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2421
            for element in connectors["output"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2422
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2423
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2424
        if connectors["action"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2425
            for element in connectors["action"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2426
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2427
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2428
        step.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2429
        self.RemoveBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2430
        self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2431
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2432
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2433
            
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2434
    def DeleteTransition(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2435
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2436
        connectors = transition.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2437
        if connectors["output"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2438
            for element in connectors["output"].GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2439
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2440
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2441
        transition.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2442
        self.RemoveBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2443
        self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2444
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2445
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2446
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2447
    def DeleteDivergence(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2448
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2449
        connectors = divergence.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2450
        for output in connectors["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2451
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2452
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2453
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2454
        divergence.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2455
        self.RemoveBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2456
        self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2457
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2458
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2459
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2460
    def DeleteJump(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2461
        jump.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2462
        self.RemoveBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2463
        self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2464
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2465
    def DeleteActionBlock(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2466
        actionblock.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2467
        self.RemoveBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2468
        self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2469
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2470
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2471
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2472
#                            Editing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2473
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2474
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2475
    def Cut(self):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2476
        if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)):
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 158
diff changeset
  2477
            self.ParentWindow.SetCopyBuffer(self.SelectedElement.Clone(self))
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2478
            rect = self.SelectedElement.GetRedrawRect(1, 1)
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2479
            self.SelectedElement.Delete()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2480
            self.SelectedElement = None
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2481
            self.RefreshBuffer()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2482
            self.RefreshScrollBars()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2483
            self.ParentWindow.RefreshVariablePanel(self.TagName)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2484
            self.ParentWindow.RefreshInstancesTree()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  2485
            self.RefreshRect(self.GetScrolledRect(rect), False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2486
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2487
    def Copy(self):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2488
        if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)):
162
e746ff4aa8be Bug on Element Paste fixed
lbessard
parents: 158
diff changeset
  2489
            self.ParentWindow.SetCopyBuffer(self.SelectedElement.Clone(self))
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2490
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2491
    def Paste(self):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2492
        element = self.ParentWindow.GetCopyBuffer()
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2493
        if not self.Debug and element is not None and self.CanAddElement(element):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2494
            block = self.CopyBlock(element, wx.Point(*self.CalcUnscrolledPosition(30, 30)))
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2495
            if self.SelectedElement is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2496
                self.SelectedElement.SetSelected(False)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2497
            self.SelectedElement = block
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2498
            self.SelectedElement.SetSelected(True)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2499
            self.RefreshBuffer()
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2500
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2501
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2502
            self.ParentWindow.RefreshVariablePanel(self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2503
            self.ParentWindow.RefreshInstancesTree()
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2504
        else:
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2505
            message = wx.MessageDialog(self, "You can't paste the element in buffer here!", "Error", wx.OK|wx.ICON_ERROR)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2506
            message.ShowModal()
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2507
            message.Destroy()
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2508
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2509
    def CanAddElement(self, block):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2510
        if isinstance(block, Graphic_Group):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2511
            return block.CanAddBlocks(self)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2512
        elif self.CurrentLanguage == "SFC":
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2513
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2514
        elif self.CurrentLanguage == "LD" and not isinstance(block, (SFC_Step, SFC_Transition, SFC_Divergence, SFC_Jump, SFC_ActionBlock)):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2515
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2516
        elif self.CurrentLanguage == "FBD" and isinstance(block, (FBD_Block, FBD_Variable, FBD_Connector, Comment)):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2517
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2518
        return False
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2519
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2520
    def GenerateNewName(self, element):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2521
        if isinstance(element, FBD_Block):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2522
            names = [varname.upper() for varname in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2523
            format = "Block%d"
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2524
        elif isinstance(element, SFC_Step):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2525
            names = [block.GetName().upper() for block in self.Blocks if isinstance(block, SFC_Step)]
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2526
            format = "Step%d"
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2527
        i = 1
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2528
        while (format%i).upper() in names:
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2529
            i += 1
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2530
        return format%i
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2531
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2532
    def IsNamedElement(self, element):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2533
        return isinstance(element, FBD_Block) and element.GetName() != "" or isinstance(element, SFC_Step)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2534
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2535
    def CopyBlock(self, element, pos):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2536
        id = self.GetNewId()
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2537
        if isinstance(element, Graphic_Group):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2538
            block = element.Clone(self, pos=pos)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2539
        else:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2540
            if self.IsNamedElement(element):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2541
                name = self.GenerateNewName(element)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2542
                block = element.Clone(self, id, name, pos)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2543
            else:
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2544
                name = None
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2545
                block = element.Clone(self, id, pos=pos)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2546
            self.AddBlockInModel(block)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2547
        return block
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2548
    
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2549
    def AddBlockInModel(self, block):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2550
        if isinstance(block, Comment):
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2551
            self.AddComment(block)
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2552
            self.Controler.AddEditedElementComment(self.TagName, block.GetId())
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2553
            self.RefreshCommentModel(block)
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2554
        else:
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2555
            self.AddBlock(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2556
            if isinstance(block, FBD_Block):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2557
                self.Controler.AddEditedElementBlock(self.TagName, block.GetId(), block.GetType(), block.GetName())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2558
                self.RefreshBlockModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2559
            elif isinstance(block, FBD_Variable):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2560
                self.Controler.AddEditedElementVariable(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2561
                self.RefreshVariableModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2562
            elif isinstance(block, FBD_Connector):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2563
                self.Controler.AddEditedElementConnection(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2564
                self.RefreshConnectionModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2565
            elif isinstance(block, LD_Contact):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2566
                self.Controler.AddEditedElementContact(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2567
                self.RefreshContactModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2568
            elif isinstance(block, LD_Coil):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2569
                self.Controler.AddEditedElementCoil(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2570
                self.RefreshCoilModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2571
            elif isinstance(block, LD_PowerRail):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2572
                self.Controler.AddEditedElementPowerRail(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2573
                self.RefreshPowerRailModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2574
            elif isinstance(block, SFC_Step):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2575
                self.Controler.AddEditedElementStep(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2576
                self.RefreshStepModel(block)    
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2577
            elif isinstance(block, SFC_Transition):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2578
                self.Controler.AddEditedElementTransition(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2579
                self.RefreshTransitionModel(block)       
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2580
            elif isinstance(block, SFC_Divergence):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2581
                self.Controler.AddEditedElementDivergence(self.TagName, block.GetId(), block.GetType())
202
e219803fdd11 Bug on SFC_Divergence copying fixed
lbessard
parents: 198
diff changeset
  2582
                self.RefreshDivergenceModel(block)
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2583
            elif isinstance(block, SFC_Jump):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2584
                self.Controler.AddEditedElementJump(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2585
                self.RefreshJumpModel(block)       
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2586
            elif isinstance(block, SFC_ActionBlock):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2587
                self.Controler.AddEditedElementActionBlock(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2588
                self.RefreshActionBlockModel(block)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2589
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2590
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2591
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2592
#                        Errors showing functions
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2593
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2594
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2595
    def ClearErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2596
        self.Errors = []
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2597
        self.RefreshView()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2598
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2599
    def AddShownError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2600
        self.Errors.append((infos, start, end))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2601
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2602
    def ShowErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2603
        for infos, start, end in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2604
            if infos[0] in ["io_variable", "block", "coil", "contact", "transition", "step", "action_block"]:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2605
                block = self.FindElementById(infos[1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2606
                if block is not None:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2607
                    block.AddError(infos[2:], start, end)    
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2608
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2609
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2610
#                            Drawing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2611
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2612
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2613
    def OnScrollWindow(self, event):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2614
        if event.GetOrientation() == wx.HORIZONTAL:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2615
            self.RefreshVisibleElements(xp = event.GetPosition())
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2616
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2617
            self.RefreshVisibleElements(yp = event.GetPosition())
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2618
        event.Skip()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2619
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2620
    def OnMouseWheelWindow(self, event):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2621
        x, y = self.GetViewStart()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2622
        yp = max(0, min(y - event.GetWheelRotation() / event.GetWheelDelta() * 3, self.GetVirtualSize()[1] / self.GetScrollPixelsPerUnit()[1]))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2623
        self.RefreshVisibleElements(yp = yp)
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2624
        self.Scroll(x, yp)
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2625
        
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2626
    def OnMoveWindow(self, event):
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
  2627
        if not USE_AUI:
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
  2628
            self.GetBestSize()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2629
        self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2630
        self.RefreshVisibleElements()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2631
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2632
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2633
    def DoDrawing(self, dc, printing = False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2634
        if printing:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2635
            if getattr(dc, "printing", False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2636
                font = wx.Font(self.GetFont().GetPointSize(), wx.MODERN, wx.NORMAL, wx.NORMAL)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2637
                dc.SetFont(font)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2638
            else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2639
                dc.SetFont(self.GetFont())
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2640
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2641
            dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2642
            dc.Clear()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2643
            dc.BeginDrawing()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2644
        if self.Scaling is not None and self.DrawGrid and not printing:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2645
            dc.SetPen(wx.TRANSPARENT_PEN)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2646
            dc.SetBrush(self.GridBrush)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2647
            xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2648
            window_size = self.GetClientSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2649
            width, height = self.GetVirtualSize()
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2650
            width = max(width, xstart * SCROLLBAR_UNIT + window_size[0])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2651
            height = max(height, ystart * SCROLLBAR_UNIT + window_size[1])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2652
            dc.DrawRectangle(0, 0, width, height)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2653
        if self.PageSize is not None and not printing:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2654
            dc.SetPen(self.PagePen)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2655
            xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2656
            window_size = self.GetClientSize()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2657
            for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], window_size[0], self.PageSize[0]):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2658
                dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, ystart * SCROLLBAR_UNIT, 
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2659
                            xstart * SCROLLBAR_UNIT + x + 1, ystart * SCROLLBAR_UNIT + window_size[1])
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2660
            for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], window_size[1], self.PageSize[1]):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2661
                dc.DrawLine(xstart * SCROLLBAR_UNIT, ystart * SCROLLBAR_UNIT + y + 1, 
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2662
                            xstart * SCROLLBAR_UNIT + window_size[0], ystart * SCROLLBAR_UNIT + y + 1)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  2663
        
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  2664
        # Draw all elements
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2665
        for comment in self.Comments:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2666
            if comment != self.SelectedElement and (comment.IsVisible() or printing):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2667
                comment.Draw(dc)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2668
        for wire in self.Wires:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2669
            if wire != self.SelectedElement and (wire.IsVisible() or printing):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2670
                 if not self.Debug or wire.GetValue() != True:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2671
                    wire.Draw(dc)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2672
        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2673
            for wire in self.Wires:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2674
                if wire != self.SelectedElement and (wire.IsVisible() or printing) and wire.GetValue() == True:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2675
                    wire.Draw(dc)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2676
        for block in self.Blocks:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2677
            if block != self.SelectedElement and (block.IsVisible() or printing):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2678
                block.Draw(dc)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2679
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2680
        if self.SelectedElement is not None and (self.SelectedElement.IsVisible() or printing):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2681
            self.SelectedElement.Draw(dc)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2682
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2683
        if not printing:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2684
            if self.rubberBand.IsShown():
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2685
                self.rubberBand.Draw(dc)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2686
            dc.EndDrawing()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2687
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2688
    def OnPaint(self, event):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2689
        self.DoDrawing(self.GetLogicalDC(True))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2690
        event.Skip()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2691
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2692