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