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