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