plcopen/plcopen.py
author laurent
Fri, 18 Nov 2011 17:39:12 +0100
changeset 590 b2442bb10c0b
parent 576 3f2024f30553
child 594 41e62b3174dc
permissions -rw-r--r--
Fixing bug when modifying the name of a derived data type
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: 47
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
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
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: 47
diff changeset
    19
#General Public License for more details.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
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
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    25
from xmlclass import *
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    26
from structures import *
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    27
from types import *
166
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
    28
import os, re
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
Dictionary that makes the relation between var names in plcopen and displayed values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    34
            "Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
            "Global" : "globalVars", "Access" : "accessVars"}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    37
searchResultVarTypes = {
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    38
    "inputVars": "var_input",
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    39
    "outputVars": "var_output",
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    40
    "inOutVars": "var_inout"
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    41
}
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
    42
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
Define in which order var types must be displayed
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    46
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    47
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    48
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    49
Define which action qualifier must be associated with a duration 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    50
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    51
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    52
    "P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    53
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    54
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    55
FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)" 
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    56
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    57
def update_address(address, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    58
    result = address_model.match(address)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    59
    if result is None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    60
        return address
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    61
    groups = result.groups()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    62
    return groups[0] + new_leading + groups[2]
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
    63
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    64
def _init_and_compare(function, v1, v2):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    65
    if v1 is None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    66
        return v2
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    67
    if v2 is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    68
        return function(v1, v2)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    69
    return v1
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    70
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    71
"""
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    72
Helper class for bounding_box calculation 
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    73
"""
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    74
class rect:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    75
    
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    76
    def __init__(self, x=None, y=None, width=None, height=None):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    77
        self.x_min = x
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    78
        self.x_max = None
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    79
        self.y_min = y
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    80
        self.y_max = None
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    81
        if width is not None and x is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    82
            self.x_max = x + width
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    83
        if height is not None and y is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    84
            self.y_max = y + height
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    85
    
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    86
    def update(self, x, y):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    87
        self.x_min = _init_and_compare(min, self.x_min, x)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    88
        self.x_max = _init_and_compare(max, self.x_max, x)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    89
        self.y_min = _init_and_compare(min, self.y_min, y)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    90
        self.y_max = _init_and_compare(max, self.y_max, y)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    91
        
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    92
    def union(self, rect):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    93
        self.x_min = _init_and_compare(min, self.x_min, rect.x_min)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    94
        self.x_max = _init_and_compare(max, self.x_max, rect.x_max)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    95
        self.y_min = _init_and_compare(min, self.y_min, rect.y_min)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    96
        self.y_max = _init_and_compare(max, self.y_max, rect.y_max)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    97
    
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    98
    def bounding_box(self):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
    99
        width = height = None
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   100
        if self.x_min is not None and self.x_max is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   101
            width = self.x_max - self.x_min
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   102
        if self.y_min is not None and self.y_max is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   103
            height = self.y_max - self.y_min
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   104
        return self.x_min, self.y_min, width, height
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   105
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   106
def TextLenInRowColumn(text):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   107
    if text == "":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   108
        return (0, 0)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   109
    lines = text.split("\n")
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   110
    return len(lines) - 1, len(lines[-1])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   111
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   112
def TestTextElement(text, criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   113
    lines = text.splitlines()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   114
    if not criteria["case_sensitive"]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   115
        text = text.upper()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   116
    test_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   117
    result = criteria["pattern"].search(text)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   118
    while result is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   119
        start = TextLenInRowColumn(text[:result.start()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   120
        end = TextLenInRowColumn(text[:result.end() - 1])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   121
        test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1])))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   122
        result = criteria["pattern"].search(text, result.end())
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   123
    return test_result
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   124
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   125
PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd"))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   126
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   127
ElementNameToClass = {}
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
   128
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   129
cls = PLCOpenClasses.get("formattedText", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   130
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   131
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   132
        index = self.text.find(old_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   133
        while index != -1:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   134
            if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   135
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   136
            elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   137
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   138
            else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   139
                self.text = self.text[:index] + new_name + self.text[index + len(old_name):]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   140
                index = self.text.find(old_name, index + len(new_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   141
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   142
    
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   143
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   144
        startpos = 0
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   145
        result = address_model.search(self.text, startpos)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   146
        while result is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   147
            groups = result.groups()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   148
            new_address = groups[0] + new_leading + groups[2]
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   149
            self.text = self.text[:result.start()] + new_address + self.text[result.end():]
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   150
            startpos = result.start() + len(new_address)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   151
            result = address_model.search(self.text, startpos)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   152
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   153
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   154
    def Search(self, criteria, parent_infos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   155
        return [(tuple(parent_infos),) + result for result in TestTextElement(self.gettext(), criteria)]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   156
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   157
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   158
cls = PLCOpenClasses.get("project", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   159
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   160
    cls.singleLineAttributes = False
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   161
    cls.EnumeratedDataTypeValues = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   162
    cls.CustomDataTypeRange = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   163
    cls.CustomTypeHierarchy = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   164
    cls.ElementUsingTree = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   165
    cls.CustomBlockTypes = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   166
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   167
    def setname(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   168
        self.contentHeader.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   169
    setattr(cls, "setname", setname)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   170
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   171
    def getname(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   172
        return self.contentHeader.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   173
    setattr(cls, "getname", getname)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   174
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   175
    def getfileHeader(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   176
        fileheader = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   177
        fileheader["companyName"] = self.fileHeader.getcompanyName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   178
        if self.fileHeader.getcompanyURL():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   179
            fileheader["companyURL"] = self.fileHeader.getcompanyURL()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   180
        fileheader["productName"] = self.fileHeader.getproductName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   181
        fileheader["productVersion"] = self.fileHeader.getproductVersion()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   182
        if self.fileHeader.getproductRelease():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   183
            fileheader["productRelease"] = self.fileHeader.getproductRelease()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   184
        fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   185
        if self.fileHeader.getcontentDescription():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   186
            fileheader["contentDescription"] = self.fileHeader.getcontentDescription()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   187
        return fileheader
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   188
    setattr(cls, "getfileHeader", getfileHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   189
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   190
    def setfileHeader(self, fileheader):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   191
        self.fileHeader.setcompanyName(fileheader["companyName"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   192
        if fileheader.has_key("companyURL"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   193
            self.fileHeader.setcompanyURL(fileheader["companyURL"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   194
        self.fileHeader.setproductName(fileheader["productName"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   195
        self.fileHeader.setproductVersion(fileheader["productVersion"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   196
        if fileheader.has_key("productRelease"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   197
            self.fileHeader.setproductRelease(fileheader["productRelease"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   198
        self.fileHeader.setcreationDateTime(fileheader["creationDateTime"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   199
        if fileheader.has_key("contentDescription"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   200
            self.fileHeader.setcontentDescription(fileheader["contentDescription"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   201
    setattr(cls, "setfileHeader", setfileHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   202
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   203
    def getcontentHeader(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   204
        contentheader = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   205
        contentheader["projectName"] = self.contentHeader.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   206
        if self.contentHeader.getversion():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   207
            contentheader["projectVersion"] = self.contentHeader.getversion()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   208
        if self.contentHeader.getmodificationDateTime():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   209
            contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   210
        if self.contentHeader.getorganization():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   211
            contentheader["organization"] = self.contentHeader.getorganization()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   212
        if self.contentHeader.getauthor():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   213
            contentheader["authorName"] = self.contentHeader.getauthor()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   214
        if self.contentHeader.getlanguage():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   215
            contentheader["language"] = self.contentHeader.getlanguage()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   216
        contentheader["pageSize"] = self.contentHeader.getpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   217
        contentheader["scaling"] = self.contentHeader.getscaling()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   218
        return contentheader
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   219
    setattr(cls, "getcontentHeader", getcontentHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   220
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   221
    def setcontentHeader(self, contentheader):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   222
        self.contentHeader.setname(contentheader["projectName"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   223
        if contentheader.has_key("projectVersion"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   224
            self.contentHeader.setversion(contentheader["projectVersion"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   225
        if contentheader.has_key("modificationDateTime"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   226
            self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   227
        if contentheader.has_key("organization"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   228
            self.contentHeader.setorganization(contentheader["organization"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   229
        if contentheader.has_key("authorName"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   230
            self.contentHeader.setauthor(contentheader["authorName"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   231
        if contentheader.has_key("language"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   232
            self.contentHeader.setlanguage(contentheader["language"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   233
        self.contentHeader.setpageSize(*contentheader["pageSize"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   234
        self.contentHeader.setscaling(contentheader["scaling"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   235
    setattr(cls, "setcontentHeader", setcontentHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   236
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   237
    def getdataTypes(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   238
        return self.types.getdataTypeElements()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   239
    setattr(cls, "getdataTypes", getdataTypes)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   240
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   241
    def getdataType(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   242
        return self.types.getdataTypeElement(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   243
    setattr(cls, "getdataType", getdataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   244
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   245
    def appenddataType(self, name):
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   246
        if self.CustomTypeHierarchy.has_key(name):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   247
            raise ValueError, "\"%s\" Data Type already exists !!!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   248
        self.types.appenddataTypeElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   249
        self.AddCustomDataType(self.getdataType(name))
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   250
    setattr(cls, "appenddataType", appenddataType)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   251
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   252
    def insertdataType(self, index, datatype):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   253
        self.types.insertdataTypeElement(index, datatype)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   254
        self.AddCustomDataType(datatype)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   255
    setattr(cls, "insertdataType", insertdataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   256
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   257
    def removedataType(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   258
        self.types.removedataTypeElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   259
        self.RefreshDataTypeHierarchy()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   260
        self.RefreshElementUsingTree()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   261
    setattr(cls, "removedataType", removedataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   262
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   263
    def getpous(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   264
        return self.types.getpouElements()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   265
    setattr(cls, "getpous", getpous)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   266
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   267
    def getpou(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   268
        return self.types.getpouElement(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   269
    setattr(cls, "getpou", getpou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   270
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   271
    def appendpou(self, name, pou_type, body_type):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   272
        self.types.appendpouElement(name, pou_type, body_type)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   273
        self.AddCustomBlockType(self.getpou(name))
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   274
    setattr(cls, "appendpou", appendpou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   275
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   276
    def insertpou(self, index, pou):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   277
        self.types.insertpouElement(index, pou)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   278
        self.AddCustomBlockType(pou)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   279
    setattr(cls, "insertpou", insertpou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   280
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   281
    def removepou(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   282
        self.types.removepouElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   283
        self.RefreshCustomBlockTypes()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   284
        self.RefreshElementUsingTree()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   285
    setattr(cls, "removepou", removepou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   286
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   287
    def getconfigurations(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   288
        configurations = self.instances.configurations.getconfiguration()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   289
        if configurations:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   290
            return configurations
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   291
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   292
    setattr(cls, "getconfigurations", getconfigurations)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   293
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   294
    def getconfiguration(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   295
        for configuration in self.instances.configurations.getconfiguration():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   296
            if configuration.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   297
                return configuration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   298
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   299
    setattr(cls, "getconfiguration", getconfiguration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   300
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   301
    def addconfiguration(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   302
        for configuration in self.instances.configurations.getconfiguration():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   303
            if configuration.getname() == name:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   304
                raise ValueError, _("\"%s\" configuration already exists !!!")%name
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   305
        new_configuration = PLCOpenClasses["configurations_configuration"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   306
        new_configuration.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   307
        self.instances.configurations.appendconfiguration(new_configuration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   308
    setattr(cls, "addconfiguration", addconfiguration)    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   309
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   310
    def removeconfiguration(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   311
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   312
        for idx, configuration in enumerate(self.instances.configurations.getconfiguration()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   313
            if configuration.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   314
                self.instances.configurations.removeconfiguration(idx)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   315
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   316
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   317
        if not found:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   318
            raise ValueError, ("\"%s\" configuration doesn't exist !!!")%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   319
    setattr(cls, "removeconfiguration", removeconfiguration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   320
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   321
    def getconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   322
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   323
        if configuration:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   324
            for resource in configuration.getresource():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   325
                if resource.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   326
                    return resource
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   327
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   328
    setattr(cls, "getconfigurationResource", getconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   329
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   330
    def addconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   331
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   332
        if configuration:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   333
            for resource in configuration.getresource():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   334
                if resource.getname() == name:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   335
                    raise ValueError, _("\"%s\" resource already exists in \"%s\" configuration !!!")%(name, config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   336
            new_resource = PLCOpenClasses["configuration_resource"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   337
            new_resource.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   338
            configuration.appendresource(new_resource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   339
    setattr(cls, "addconfigurationResource", addconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   340
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   341
    def removeconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   342
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   343
        if configuration:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
            found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   345
            for idx, resource in enumerate(configuration.getresource()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   346
                if resource.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   347
                    configuration.removeresource(idx)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
                    found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
                    break
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   350
            if not found:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
   351
                raise ValueError, _("\"%s\" resource doesn't exist in \"%s\" configuration !!!")%(name, config_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   352
    setattr(cls, "removeconfigurationResource", removeconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   353
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   354
    def updateElementName(self, old_name, new_name):
348
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
   355
        for datatype in self.types.getdataTypeElements():
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   356
            datatype.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   357
        for pou in self.types.getpouElements():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   358
            pou.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   359
        for configuration in self.instances.configurations.getconfiguration():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   360
            configuration.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   361
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   362
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   363
    def updateElementAddress(self, old_leading, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   364
        address_model = re.compile(FILTER_ADDRESS_MODEL % old_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   365
        for pou in self.types.getpouElements():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   366
            pou.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   367
        for configuration in self.instances.configurations.getconfiguration():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   368
            configuration.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   369
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   370
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   371
    def removeVariableByAddress(self, address):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   372
        for pou in self.types.getpouElements():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   373
            pou.removeVariableByAddress(address)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   374
        for configuration in self.instances.configurations.getconfiguration():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   375
            configuration.removeVariableByAddress(address)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   376
    setattr(cls, "removeVariableByAddress", removeVariableByAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   377
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   378
    def removeVariableByFilter(self, leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   379
        address_model = re.compile(FILTER_ADDRESS_MODEL % leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   380
        for pou in self.types.getpouElements():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   381
            pou.removeVariableByFilter(address_model)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   382
        for configuration in self.instances.configurations.getconfiguration():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   383
            configuration.removeVariableByFilter(address_model)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   384
    setattr(cls, "removeVariableByFilter", removeVariableByFilter)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   385
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   386
    def RefreshDataTypeHierarchy(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   387
        self.EnumeratedDataTypeValues = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   388
        self.CustomDataTypeRange = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   389
        self.CustomTypeHierarchy = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   390
        for datatype in self.getdataTypes():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   391
            self.AddCustomDataType(datatype)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   392
    setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   393
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   394
    def AddCustomDataType(self, datatype):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   395
        name = datatype.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   396
        basetype_content = datatype.getbaseType().getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   397
        if basetype_content["value"] is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   398
            self.CustomTypeHierarchy[name] = basetype_content["name"]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   399
        elif basetype_content["name"] in ["string", "wstring"]:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   400
            self.CustomTypeHierarchy[name] = basetype_content["name"].upper()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   401
        elif basetype_content["name"] == "derived":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   402
            self.CustomTypeHierarchy[name] = basetype_content["value"].getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   403
        elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   404
            range = (basetype_content["value"].range.getlower(), 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   405
                     basetype_content["value"].range.getupper())
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   406
            self.CustomDataTypeRange[name] = range
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   407
            base_type = basetype_content["value"].baseType.getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   408
            if base_type["value"] is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   409
                self.CustomTypeHierarchy[name] = base_type["name"]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   410
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   411
                self.CustomTypeHierarchy[name] = base_type["value"].getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   412
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   413
            if basetype_content["name"] == "enum":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   414
                values = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   415
                for value in basetype_content["value"].values.getvalue():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   416
                    values.append(value.getname())
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   417
                self.EnumeratedDataTypeValues[name] = values
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   418
            self.CustomTypeHierarchy[name] = "ANY_DERIVED"
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   419
    setattr(cls, "AddCustomDataType", AddCustomDataType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   420
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   421
    # Update Block types with user-defined pou added
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   422
    def RefreshCustomBlockTypes(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   423
        # Reset the tree of user-defined pou cross-use
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   424
        self.CustomBlockTypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   425
        for pou in self.getpous():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   426
            self.AddCustomBlockType(pou)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   427
    setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   428
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   429
    def AddCustomBlockType(self, pou): 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   430
        pou_name = pou.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   431
        pou_type = pou.getpouType()
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   432
        block_infos = {"name" : pou_name, "type" : pou_type, "extensible" : False,
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   433
                       "inputs" : [], "outputs" : [], "comment" : "",
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   434
                       "generate" : generate_block, "initialise" : initialise_block}
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   435
        if pou.getinterface():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   436
            return_type = pou.interface.getreturnType()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   437
            if return_type:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   438
                var_type = return_type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   439
                if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   440
                    block_infos["outputs"].append(("", var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   441
                elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   442
                    block_infos["outputs"].append(("", var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   443
                else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   444
                    block_infos["outputs"].append(("", var_type["name"], "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   445
            for type, varlist in pou.getvars():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   446
                if type == "InOut":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   447
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   448
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   449
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   450
                            block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   451
                            block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   452
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   453
                            block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   454
                            block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   455
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   456
                            block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   457
                            block_infos["outputs"].append((var.getname(), var_type["name"], "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   458
                elif type == "Input":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   459
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   460
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   461
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   462
                            block_infos["inputs"].append((var.getname(), var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   463
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   464
                            block_infos["inputs"].append((var.getname(), var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   465
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   466
                            block_infos["inputs"].append((var.getname(), var_type["name"], "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   467
                elif type == "Output":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   468
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   469
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   470
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   471
                            block_infos["outputs"].append((var.getname(), var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   472
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   473
                            block_infos["outputs"].append((var.getname(), var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   474
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   475
                            block_infos["outputs"].append((var.getname(), var_type["name"], "none"))    
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   476
        if pou.getbodyType() in ["FBD","LD","SFC"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   477
            for instance in pou.getinstances():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   478
                if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)):
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   479
                    block_infos["comment"] = instance.getcontentText()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   480
        self.CustomBlockTypes.append(block_infos)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   481
    setattr(cls, "AddCustomBlockType", AddCustomBlockType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   482
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   483
    def RefreshElementUsingTree(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   484
        # Reset the tree of user-defined element cross-use
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   485
        self.ElementUsingTree = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   486
        pous = self.getpous()
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   487
        datatypes = self.getdataTypes()
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   488
        # Reference all the user-defined elementu names and initialize the tree of 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   489
        # user-defined elemnt cross-use
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   490
        elementnames = [datatype.getname() for datatype in datatypes] + \
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   491
                       [pou.getname() for pou in pous]
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   492
        for name in elementnames:
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   493
            self.ElementUsingTree[name] = []
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   494
        # Analyze each datatype
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   495
        for datatype in datatypes:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   496
            name = datatype.getname()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   497
            basetype_content = datatype.baseType.getcontent()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   498
            if basetype_content["name"] == "derived":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   499
                typename = basetype_content["value"].getname()
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   500
                if name in self.ElementUsingTree[typename]:
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   501
                    self.ElementUsingTree[typename].append(name)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   502
            elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned", "array"]:
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   503
                base_type = basetype_content["value"].baseType.getcontent()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   504
                if base_type["name"] == "derived":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   505
                    typename = base_type["value"].getname()
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   506
                    if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]:
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   507
                        self.ElementUsingTree[typename].append(name)
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   508
            elif basetype_content["name"] == "struct":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   509
                for element in basetype_content["value"].getvariable():
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   510
                    type_content = element.type.getcontent()
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   511
                    if type_content["name"] == "derived":
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   512
                        typename = type_content["value"].getname()
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   513
                        if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]:
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
   514
                            self.ElementUsingTree[typename].append(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   515
        # Analyze each pou
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   516
        for pou in pous:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   517
            name = pou.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   518
            if pou.interface:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   519
                # Extract variables from every varLists
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   520
                for type, varlist in pou.getvars():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   521
                    for var in varlist.getvariable():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   522
                        vartype_content = var.gettype().getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   523
                        if vartype_content["name"] == "derived":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   524
                            typename = vartype_content["value"].getname()
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   525
                            if self.ElementUsingTree.has_key(typename) and name not in self.ElementUsingTree[typename]:
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   526
                                self.ElementUsingTree[typename].append(name)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   527
    setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   528
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   529
    def GetParentType(self, type):
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   530
        if self.CustomTypeHierarchy.has_key(type):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   531
            return self.CustomTypeHierarchy[type]
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   532
        elif TypeHierarchy.has_key(type):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   533
            return TypeHierarchy[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   534
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   535
    setattr(cls, "GetParentType", GetParentType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   536
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   537
    def GetBaseType(self, type):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   538
        parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   539
        if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   540
            if parent_type.startswith("ANY"):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   541
                return type
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   542
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   543
                return self.GetBaseType(parent_type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   544
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   545
    setattr(cls, "GetBaseType", GetBaseType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   546
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   547
    def GetSubrangeBaseTypes(self, exclude):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   548
        derived = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   549
        for type in self.CustomTypeHierarchy.keys():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   550
            for base_type in DataTypeRange.keys():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   551
                if self.IsOfType(type, base_type) and not self.IsOfType(type, exclude):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   552
                    derived.append(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   553
                    break
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   554
        return DataTypeRange.keys() + derived
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   555
    setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   556
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   557
    """
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   558
    returns true if the given data type is the same that "reference" meta-type or one of its types.
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   559
    """
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   560
    def IsOfType(self, type, reference):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   561
        if reference is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   562
            return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   563
        elif type == reference:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   564
            return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   565
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   566
            parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   567
            if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   568
                return self.IsOfType(parent_type, reference)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   569
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   570
    setattr(cls, "IsOfType", IsOfType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   571
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   572
    # Return if pou given by name is used by another pou
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   573
    def ElementIsUsed(self, name):
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   574
        if self.ElementUsingTree.has_key(name):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   575
            return len(self.ElementUsingTree[name]) > 0
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   576
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   577
    setattr(cls, "ElementIsUsed", ElementIsUsed)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   578
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   579
    def DataTypeIsDerived(self, name):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   580
        return name in self.CustomTypeHierarchy.values()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   581
    setattr(cls, "DataTypeIsDerived", DataTypeIsDerived)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   582
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   583
    # Return if pou given by name is directly or undirectly used by the reference pou
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   584
    def ElementIsUsedBy(self, name, reference):
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   585
        if self.ElementUsingTree.has_key(name):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   586
            list = self.ElementUsingTree[name]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   587
            # Test if pou is directly used by reference
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   588
            if reference in list:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   589
                return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   590
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   591
                # Test if pou is undirectly used by reference, by testing if pous 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   592
                # that directly use pou is directly or undirectly used by reference
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   593
                used = False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   594
                for element in list:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   595
                    used |= self.ElementIsUsedBy(element, reference)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   596
                return used
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   597
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   598
    setattr(cls, "ElementIsUsedBy", ElementIsUsedBy)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   599
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   600
    def GetDataTypeRange(self, type):
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   601
        if self.CustomDataTypeRange.has_key(type):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   602
            return self.CustomDataTypeRange[type]
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   603
        elif DataTypeRange.has_key(type):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   604
            return DataTypeRange[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   605
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   606
            parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   607
            if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   608
                return self.GetDataTypeRange(parent_type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   609
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   610
    setattr(cls, "GetDataTypeRange", GetDataTypeRange)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   611
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   612
    def GetEnumeratedDataTypeValues(self, type = None):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   613
        if type is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   614
            all_values = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   615
            for values in self.EnumeratedDataTypeValues.values():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   616
                all_values.extend(values)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   617
            return all_values
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   618
        elif self.EnumeratedDataTypeValues.has_key(type):
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
   619
            return self.EnumeratedDataTypeValues[type]
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   620
        return []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   621
    setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   622
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   623
    # Function that returns the block definition associated to the block type given
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   624
    def GetCustomBlockType(self, type, inputs = None):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   625
        for customblocktype in self.CustomBlockTypes:
539
8dbb1de154c1 Fix bug when compiling pou including user-defined blocks with unconnected input
laurent
parents: 491
diff changeset
   626
            if inputs is not None and inputs != "undefined":
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   627
                customblock_inputs = tuple([var_type for name, var_type, modifier in customblocktype["inputs"]])
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   628
                same_inputs = inputs == customblock_inputs
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   629
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   630
                same_inputs = True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   631
            if customblocktype["name"] == type and same_inputs:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   632
                return customblocktype
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   633
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   634
    setattr(cls, "GetCustomBlockType", GetCustomBlockType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   635
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   636
    # Return Block types checking for recursion
251
cc5377a296ea Fix bug in popup menu and function block types in Variable Panel
lbessard
parents: 246
diff changeset
   637
    def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False):
238
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   638
        type = None
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   639
        if exclude != "":
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   640
            pou = self.getpou(exclude)
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   641
            if pou is not None:
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   642
                type = pou.getpouType()
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   643
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   644
        for customblocktype in self.CustomBlockTypes:
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   645
            if customblocktype["type"] != "program" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]) and not (onlyfunctions and customblocktype["type"] != "function"):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   646
                customblocktypes.append(customblocktype)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   647
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   648
    setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   649
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   650
    # Return Function Block types checking for recursion
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   651
    def GetCustomFunctionBlockTypes(self, exclude = ""):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   652
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   653
        for customblocktype in self.CustomBlockTypes:
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   654
            if customblocktype["type"] == "functionBlock" and customblocktype["name"] != exclude and not self.ElementIsUsedBy(exclude, customblocktype["name"]):
246
9cf9694e8d66 Bug with GetCustomFunctionBlockTypes without exclusion POU fixed
lbessard
parents: 238
diff changeset
   655
                customblocktypes.append(customblocktype["name"])
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   656
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   657
    setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   658
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   659
    # Return Block types checking for recursion
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   660
    def GetCustomBlockResource(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   661
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   662
        for customblocktype in self.CustomBlockTypes:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   663
            if customblocktype["type"] == "program":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   664
                customblocktypes.append(customblocktype["name"])
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   665
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   666
    setattr(cls, "GetCustomBlockResource", GetCustomBlockResource)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   667
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   668
    # Return Data Types checking for recursion
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   669
    def GetCustomDataTypes(self, exclude = "", only_locatable = False):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   670
        customdatatypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   671
        for customdatatype in self.getdataTypes():
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   672
            if not only_locatable or self.IsLocatableType(customdatatype):
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   673
                customdatatype_name = customdatatype.getname()
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   674
                if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name):
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   675
                    customdatatypes.append(customdatatype_name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   676
        return customdatatypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   677
    setattr(cls, "GetCustomDataTypes", GetCustomDataTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   678
552
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   679
    # Return if Data Type can be used for located variables
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   680
    def IsLocatableType(self, datatype):
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   681
        basetype_content = datatype.baseType.getcontent()
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   682
        if basetype_content["name"] in ["enum", "struct"]:
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   683
            return False
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   684
        elif basetype_content["name"] == "derived":
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   685
            base_type = self.getdataType(basetype_content["value"].getname())
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   686
            if base_type is not None:
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   687
                return self.IsLocatableType(base_type)
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   688
        elif basetype_content["name"] == "array":
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   689
            array_base_type = basetype_content["value"].baseType.getcontent()
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   690
            if array_base_type["value"] is not None and array_base_type["name"] not in ["string", "wstring"]:
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   691
                base_type = self.getdataType(array_base_type["value"].getname())
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   692
                if base_type is not None:
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   693
                    return self.IsLocatableType(base_type)
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   694
        return True
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   695
    setattr(cls, "IsLocatableType", IsLocatableType)
a387f258814a Disabling location definition for enumerated and structure variables
laurent
parents: 550
diff changeset
   696
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   697
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   698
        result = self.types.Search(criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   699
        for configuration in self.instances.configurations.getconfiguration():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   700
            result.extend(configuration.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   701
        return result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   702
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   703
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   704
cls = PLCOpenClasses.get("project_fileHeader", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   705
if cls:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   706
    cls.singleLineAttributes = False
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   707
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   708
cls = PLCOpenClasses.get("project_contentHeader", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   709
if cls:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   710
    cls.singleLineAttributes = False
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   711
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   712
    def setpageSize(self, width, height):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   713
        self.coordinateInfo.setpageSize(width, height)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   714
    setattr(cls, "setpageSize", setpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   715
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   716
    def getpageSize(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   717
        return self.coordinateInfo.getpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   718
    setattr(cls, "getpageSize", getpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   719
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   720
    def setscaling(self, scaling):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   721
        for language, (x, y) in scaling.items():
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   722
            self.coordinateInfo.setscaling(language, x, y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   723
    setattr(cls, "setscaling", setscaling)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   724
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   725
    def getscaling(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   726
        scaling = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   727
        scaling["FBD"] = self.coordinateInfo.getscaling("FBD")
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   728
        scaling["LD"] = self.coordinateInfo.getscaling("LD")
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   729
        scaling["SFC"] = self.coordinateInfo.getscaling("SFC")
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   730
        return scaling
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   731
    setattr(cls, "getscaling", getscaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   732
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   733
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   734
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   735
    def setpageSize(self, width, height):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   736
        if width == 0 and height == 0:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   737
            self.deletepageSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   738
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   739
            if self.pageSize is None:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   740
                self.addpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   741
            self.pageSize.setx(width)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   742
            self.pageSize.sety(height)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   743
    setattr(cls, "setpageSize", setpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   744
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   745
    def getpageSize(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   746
        if self.pageSize is not None:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   747
            return self.pageSize.getx(), self.pageSize.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   748
        return 0, 0
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   749
    setattr(cls, "getpageSize", getpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   750
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   751
    def setscaling(self, language, x, y):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   752
        if language == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   753
            self.fbd.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   754
            self.fbd.scaling.sety(y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   755
        elif language == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   756
            self.ld.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   757
            self.ld.scaling.sety(y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   758
        elif language == "SFC":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   759
            self.sfc.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   760
            self.sfc.scaling.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   761
    setattr(cls, "setscaling", setscaling)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   762
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   763
    def getscaling(self, language):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   764
        if language == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   765
            return self.fbd.scaling.getx(), self.fbd.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   766
        elif language == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   767
            return self.ld.scaling.getx(), self.ld.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   768
        elif language == "SFC":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   769
            return self.sfc.scaling.getx(), self.sfc.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   770
        return 0, 0
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   771
    setattr(cls, "getscaling", getscaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   772
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   773
def _Search(attributes, criteria, parent_infos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   774
    search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   775
    for attr, value in attributes:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   776
        if value is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   777
            search_result.extend([(tuple(parent_infos + [attr]),) + result for result in TestTextElement(value, criteria)])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   778
    return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   779
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   780
def _updateConfigurationResourceElementName(self, old_name, new_name):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   781
    for varlist in self.getglobalVars():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   782
        for var in varlist.getvariable():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   783
            var_address = var.getaddress()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   784
            if var_address is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   785
                if var_address == old_name:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   786
                    var.setaddress(new_name)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   787
                if var.getname() == old_name:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   788
                    var.setname(new_name)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   789
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   790
def _updateConfigurationResourceElementAddress(self, address_model, new_leading):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   791
    for varlist in self.getglobalVars():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   792
        for var in varlist.getvariable():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   793
            var_address = var.getaddress()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   794
            if var_address is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   795
                var.setaddress(update_address(var_address, address_model, new_leading))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   796
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   797
def _removeConfigurationResourceVariableByAddress(self, address):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   798
    for varlist in self.getglobalVars():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   799
        variables = varlist.getvariable()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   800
        for i in xrange(len(variables)-1, -1, -1):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   801
            if variables[i].getaddress() == address:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   802
                variables.pop(i)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   803
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   804
def _removeConfigurationResourceVariableByFilter(self, address_model):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   805
    for varlist in self.getglobalVars():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   806
        variables = varlist.getvariable()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   807
        for i in xrange(len(variables)-1, -1, -1):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   808
            var_address = variables[i].getaddress()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   809
            if var_address is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   810
                result = address_model.match(var_address)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   811
                if result is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   812
                    variables.pop(i)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   813
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   814
def _SearchInConfigurationResource(self, criteria, parent_infos=[]):
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
   815
    search_result = _Search([("name", self.getname())], criteria, parent_infos)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   816
    var_number = 0
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   817
    for varlist in self.getglobalVars():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   818
        variable_type = searchResultVarTypes.get("globalVars", "var_local")
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   819
        variables = varlist.getvariable()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   820
        for modifier, has_modifier in [("constant", varlist.getconstant()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   821
                                       ("retain", varlist.getretain()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   822
                                       ("non_retain", varlist.getnonretain())]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   823
            if has_modifier:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   824
                for result in TestTextElement(modifier, criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   825
                    search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   826
                break
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   827
        for variable in variables:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   828
            search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   829
            var_number += 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   830
    return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   831
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   832
cls = PLCOpenClasses.get("configurations_configuration", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   833
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   834
    def updateElementName(self, old_name, new_name):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   835
        _updateConfigurationResourceElementName(self, old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   836
        for resource in self.getresource():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   837
            resource.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   838
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   839
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   840
    def updateElementAddress(self, address_model, new_leading):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   841
        _updateConfigurationResourceElementAddress(self, address_model, new_leading)
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   842
        for resource in self.getresource():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   843
            resource.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   844
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   845
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   846
    setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   847
    setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   848
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   849
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   850
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   851
        parent_infos = parent_infos + ["C::%s" % self.getname()]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   852
        filter = criteria["filter"]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   853
        if filter == "all" or "configuration" in filter:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   854
            search_result = _SearchInConfigurationResource(self, criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   855
            for resource in self.getresource():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   856
                search_result.extend(resource.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   857
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   858
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   859
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   860
cls = PLCOpenClasses.get("configuration_resource", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   861
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   862
    def updateElementName(self, old_name, new_name):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   863
        _updateConfigurationResourceElementName(self, old_name, new_name)
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   864
        for instance in self.getpouInstance():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   865
            instance.updateElementName(old_name, new_name)
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   866
        for task in self.gettask():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   867
            task.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   868
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   869
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   870
    def updateElementAddress(self, address_model, new_leading):
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   871
        _updateConfigurationResourceElementAddress(self, address_model, new_leading)
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   872
        for task in self.gettask():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   873
            task.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   874
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   875
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   876
    setattr(cls, "removeVariableByAddress", _removeConfigurationResourceVariableByAddress)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   877
    setattr(cls, "removeVariableByFilter", _removeConfigurationResourceVariableByFilter)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   878
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   879
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   880
        parent_infos = parent_infos[:-1] + ["R::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   881
        search_result = _SearchInConfigurationResource(self, criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   882
        task_number = 0
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   883
        instance_number = 0
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   884
        for task in self.gettask():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   885
            results = TestTextElement(task.getname(), criteria)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   886
            for result in results:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   887
                search_result.append((tuple(parent_infos + ["task", task_number, "name"]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   888
            search_result.extend(task.Search(criteria, parent_infos + ["task", task_number]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   889
            task_number += 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   890
            for instance in task.getpouInstance():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   891
                search_result.extend(task.Search(criteria, parent_infos + ["instance", instance_number]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   892
                for result in results:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   893
                    search_result.append((tuple(parent_infos + ["instance", instance_number, "task"]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   894
                instance_number += 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   895
        for instance in self.getpouInstance():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   896
            search_result.extend(instance.Search(criteria, parent_infos + ["instance", instance_number]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   897
            instance_number += 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   898
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   899
    setattr(cls, "Search", Search)
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   900
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   901
cls = PLCOpenClasses.get("resource_task", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   902
if cls:
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   903
    def compatibility(self, tree):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   904
        if tree.hasAttribute("interval"):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   905
            interval = GetAttributeValue(tree._attrs["interval"])
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   906
            result = time_model.match(interval)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   907
            if result is not None:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   908
                values = result.groups()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   909
                time_values = [int(v) for v in values[:2]]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   910
                seconds = float(values[2])
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   911
                time_values.extend([int(seconds), int((seconds % 1) * 1000000)])
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   912
                text = "t#"
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   913
                if time_values[0] != 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   914
                    text += "%dh"%time_values[0]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   915
                if time_values[1] != 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   916
                    text += "%dm"%time_values[1]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   917
                if time_values[2] != 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   918
                    text += "%ds"%time_values[2]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   919
                if time_values[3] != 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   920
                    if time_values[3] % 1000 != 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   921
                        text += "%.3fms"%(float(time_values[3]) / 1000)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   922
                    else:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   923
                        text += "%dms"%(time_values[3] / 1000)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   924
                NodeSetAttr(tree, "interval", text)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   925
    setattr(cls, "compatibility", compatibility)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   926
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   927
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   928
        if self.single == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   929
            self.single = new_name
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   930
        if self.interval == old_name:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   931
            self.interval = new_name
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   932
        for instance in self.getpouInstance():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   933
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   934
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   935
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   936
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   937
        if self.single is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   938
            self.single = update_address(self.single, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   939
        if self.interval is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   940
            self.interval = update_address(self.interval, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   941
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
   942
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   943
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   944
        return _Search([("single", self.getsingle()), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   945
                        ("interval", self.getinterval()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   946
                        ("priority", str(self.getpriority()))],
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   947
                       criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   948
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   949
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   950
cls = PLCOpenClasses.get("pouInstance", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   951
if cls:
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   952
    def compatibility(self, tree):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   953
        if tree.hasAttribute("type"):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   954
            NodeRenameAttr(tree, "type", "typeName")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   955
    setattr(cls, "compatibility", compatibility)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
   956
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   957
    def updateElementName(self, old_name, new_name):
417
218142afdb53 fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents: 394
diff changeset
   958
        if self.typeName == old_name:
218142afdb53 fix renaming variables (broken by pouInstance.type -> pouInstance.typeName)
b.taylor@willowglen.ca
parents: 394
diff changeset
   959
            self.typeName = new_name
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   960
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   961
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   962
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   963
        return _Search([("name", self.getname()), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   964
                        ("type", self.gettypeName())],
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   965
                       criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   966
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   967
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   968
cls = PLCOpenClasses.get("varListPlain_variable", None)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   969
if cls:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   970
    def gettypeAsText(self):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   971
        vartype_content = self.gettype().getcontent()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   972
        # Variable type is a user data type
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   973
        if vartype_content["name"] == "derived":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   974
            return vartype_content["value"].getname()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   975
        # Variable type is a string type
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   976
        elif vartype_content["name"] in ["string", "wstring"]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   977
            return vartype_content["name"].upper()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   978
        # Variable type is an array
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   979
        elif vartype_content["name"] == "array":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   980
            base_type = vartype_content["value"].baseType.getcontent()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   981
            # Array derived directly from a user defined type 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   982
            if base_type["name"] == "derived":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   983
                basetype_name = base_type["value"].getname()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   984
            # Array derived directly from a string type 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   985
            elif base_type["name"] in ["string", "wstring"]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   986
                basetype_name = base_type["name"].upper()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   987
            # Array derived directly from an elementary type 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   988
            else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   989
                basetype_name = base_type["name"]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   990
            return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "%s..%s" % (x.getlower(), x.getupper()), vartype_content["value"].getdimension())), basetype_name)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   991
        # Variable type is an elementary type
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   992
        return vartype_content["name"]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   993
    setattr(cls, "gettypeAsText", gettypeAsText)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   994
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   995
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   996
        search_result = _Search([("name", self.getname()), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   997
                                 ("type", self.gettypeAsText()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   998
                                 ("address", self.getaddress())],
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
   999
                                criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1000
        initial = self.getinitialValue()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1001
        if initial is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1002
            search_result.extend(_Search([("initial", initial.getvalue())], criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1003
        doc = self.getdocumentation()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1004
        if doc is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1005
            search_result.extend(doc.Search(criterias, parent_infos + ["documentation"]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1006
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1007
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1008
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1009
cls = PLCOpenClasses.get("project_types", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1010
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1011
    def getdataTypeElements(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1012
        return self.dataTypes.getdataType()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1013
    setattr(cls, "getdataTypeElements", getdataTypeElements)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1014
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1015
    def getdataTypeElement(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1016
        elements = self.dataTypes.getdataType()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1017
        for element in elements:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1018
            if element.getname() == name:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1019
                return element
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1020
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1021
    setattr(cls, "getdataTypeElement", getdataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1022
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1023
    def appenddataTypeElement(self, name):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1024
        new_datatype = PLCOpenClasses["dataTypes_dataType"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1025
        new_datatype.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1026
        new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1027
        self.dataTypes.appenddataType(new_datatype)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1028
    setattr(cls, "appenddataTypeElement", appenddataTypeElement)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
  1029
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1030
    def insertdataTypeElement(self, index, dataType):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1031
        self.dataTypes.insertdataType(index, dataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1032
    setattr(cls, "insertdataTypeElement", insertdataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1033
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1034
    def removedataTypeElement(self, name):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1035
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1036
        for idx, element in enumerate(self.dataTypes.getdataType()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1037
            if element.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1038
                self.dataTypes.removedataType(idx)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1039
                found = True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1040
                break
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1041
        if not found:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1042
            raise ValueError, _("\"%s\" Data Type doesn't exist !!!")%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1043
    setattr(cls, "removedataTypeElement", removedataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1044
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1045
    def getpouElements(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1046
        return self.pous.getpou()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1047
    setattr(cls, "getpouElements", getpouElements)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1048
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1049
    def getpouElement(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1050
        elements = self.pous.getpou()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1051
        for element in elements:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1052
            if element.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1053
                return element
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1054
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1055
    setattr(cls, "getpouElement", getpouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1056
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1057
    def appendpouElement(self, name, pou_type, body_type):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1058
        for element in self.pous.getpou():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1059
            if element.getname() == name:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1060
                raise ValueError, _("\"%s\" POU already exists !!!")%name
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1061
        new_pou = PLCOpenClasses["pous_pou"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1062
        new_pou.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1063
        new_pou.setpouType(pou_type)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1064
        new_pou.appendbody(PLCOpenClasses["body"]())
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1065
        new_pou.setbodyType(body_type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1066
        self.pous.appendpou(new_pou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1067
    setattr(cls, "appendpouElement", appendpouElement)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1068
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1069
    def insertpouElement(self, index, pou):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1070
        self.pous.insertpou(index, pou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1071
    setattr(cls, "insertpouElement", insertpouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1072
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1073
    def removepouElement(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1074
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1075
        for idx, element in enumerate(self.pous.getpou()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1076
            if element.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1077
                self.pous.removepou(idx)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1078
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1079
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1080
        if not found:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1081
            raise ValueError, _("\"%s\" POU doesn't exist !!!")%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1082
    setattr(cls, "removepouElement", removepouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1083
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1084
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1085
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1086
        filter = criteria["filter"]
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1087
        for datatype in self.dataTypes.getdataType():
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1088
            search_result.extend(datatype.Search(criteria, parent_infos))
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1089
        for pou in self.pous.getpou():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1090
            search_result.extend(pou.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1091
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1092
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1093
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1094
def _updateBaseTypeElementName(self, old_name, new_name):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1095
    self.baseType.updateElementName(old_name, new_name)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1096
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1097
cls = PLCOpenClasses.get("dataTypes_dataType", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1098
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1099
    setattr(cls, "updateElementName", _updateBaseTypeElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1100
    
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1101
    def Search(self, criteria, parent_infos=[]):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1102
        search_result = []
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1103
        filter = criteria["filter"]
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1104
        if filter == "all" or "datatype" in filter:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1105
            parent_infos = parent_infos + ["D::%s" % self.getname()]
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1106
            search_result.extend(_Search([("name", self.getname())], criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1107
            search_result.extend(self.baseType.Search(criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1108
            if self.initialValue is not None:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1109
                search_result.extend(_Search([("initial", self.initialValue.getvalue())], criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1110
        return search_result
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1111
    setattr(cls, "Search", Search)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1112
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1113
cls = PLCOpenClasses.get("dataType", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1114
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1115
    
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1116
    def updateElementName(self, old_name, new_name):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1117
        if self.content["name"] in ["derived", "array", "subrangeSigned", "subrangeUnsigned"]:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1118
            self.content["value"].updateElementName(old_name, new_name)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1119
        elif self.content["name"] == "struct":
590
b2442bb10c0b Fixing bug when modifying the name of a derived data type
laurent
parents: 576
diff changeset
  1120
            for element in self.content["value"].getvariable():
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1121
                element_type = element.type.updateElementName(old_name, new_name)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1122
    setattr(cls, "updateElementName", updateElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1123
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1124
    def Search(self, criteria, parent_infos=[]):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1125
        search_result = []
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1126
        if self.content["name"] in ["derived", "array", "enum", "subrangeSigned", "subrangeUnsigned"]:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1127
            search_result.extend(self.content["value"].Search(criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1128
        elif self.content["name"] == "struct":
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1129
            for i, element in enumerate(self.content["value"].getvariable()):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1130
                search_result.extend(element.Search(criteria, parent_infos + ["struct", i]))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1131
        else:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1132
            basetype = self.content["name"]
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1133
            if basetype in ["string", "wstring"]:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1134
                basetype = basetype.upper()
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1135
            search_result.extend(_Search([("base", basetype)], criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1136
        return search_result
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1137
    setattr(cls, "Search", Search)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1138
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1139
cls = PLCOpenClasses.get("derivedTypes_array", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1140
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1141
    setattr(cls, "updateElementName", _updateBaseTypeElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1142
    
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1143
    def Search(self, criteria, parent_infos=[]):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1144
        search_result = self.baseType.Search(criteria, parent_infos)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1145
        for i, dimension in enumerate(self.getdimension()):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1146
            search_result.extend(_Search([("lower", dimension.getlower()),
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1147
                                          ("upper", dimension.getupper())],
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1148
                                         criteria, parent_infos + ["range", i]))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1149
        return search_result
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1150
    setattr(cls, "Search", Search)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1151
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1152
def _SearchInSubrange(self, criteria, parent_infos=[]):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1153
    search_result = self.baseType.Search(criteria, parent_infos)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1154
    search_result.extend(_Search([("lower", self.range.getlower()),
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1155
                                  ("upper", self.range.getupper())],
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1156
                                 criteria, parent_infos))
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1157
    return search_result
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1158
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1159
cls = PLCOpenClasses.get("derivedTypes_subrangeSigned", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1160
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1161
    setattr(cls, "updateElementName", _updateBaseTypeElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1162
    setattr(cls, "Search", _SearchInSubrange)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1163
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1164
cls = PLCOpenClasses.get("derivedTypes_subrangeUnsigned", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1165
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1166
    setattr(cls, "updateElementName", _updateBaseTypeElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1167
    setattr(cls, "Search", _SearchInSubrange)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1168
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1169
cls = PLCOpenClasses.get("derivedTypes_enum", None)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1170
if cls:
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1171
    
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1172
    def updateElementName(self, old_name, new_name):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1173
        pass
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1174
    setattr(cls, "updateElementName", updateElementName)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1175
    
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1176
    def Search(self, criteria, parent_infos=[]):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1177
        search_result = []
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1178
        for i, value in enumerate(self.values.getvalue()):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1179
            for result in TestTextElement(value.getname(), criteria):
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1180
                search_result.append((tuple(parent_infos + ["value", i]),) + result)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1181
        return search_result
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1182
    setattr(cls, "Search", Search)
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1183
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1184
cls = PLCOpenClasses.get("pous_pou", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1185
if cls:
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1186
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1187
    def setbodyType(self, type):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1188
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1189
            if type == "IL":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1190
                self.body[0].setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1191
            elif type == "ST":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1192
                self.body[0].setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1193
            elif type == "LD":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1194
                self.body[0].setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1195
            elif type == "FBD":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1196
                self.body[0].setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1197
            elif type == "SFC":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1198
                self.body[0].setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1199
            else:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1200
                raise ValueError, "%s isn't a valid body type!"%type
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1201
    setattr(cls, "setbodyType", setbodyType)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1202
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1203
    def getbodyType(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1204
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1205
            return self.body[0].getcontent()["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1206
    setattr(cls, "getbodyType", getbodyType)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1207
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1208
    def resetexecutionOrder(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1209
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1210
            self.body[0].resetexecutionOrder()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1211
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1212
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1213
    def compileexecutionOrder(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1214
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1215
            self.body[0].compileexecutionOrder()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1216
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1217
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1218
    def setelementExecutionOrder(self, instance, new_executionOrder):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1219
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1220
            self.body[0].setelementExecutionOrder(instance, new_executionOrder)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1221
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1222
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1223
    def addinstance(self, name, instance):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1224
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1225
            self.body[0].appendcontentInstance(name, instance)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1226
    setattr(cls, "addinstance", addinstance)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1227
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1228
    def getinstances(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1229
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1230
            return self.body[0].getcontentInstances()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1231
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1232
    setattr(cls, "getinstances", getinstances)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1233
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1234
    def getinstance(self, id):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1235
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1236
            return self.body[0].getcontentInstance(id)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1237
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1238
    setattr(cls, "getinstance", getinstance)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1239
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1240
    def getrandomInstance(self, exclude):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1241
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1242
            return self.body[0].getcontentRandomInstance(exclude)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1243
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1244
    setattr(cls, "getrandomInstance", getrandomInstance)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1245
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1246
    def getinstanceByName(self, name):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1247
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1248
            return self.body[0].getcontentInstanceByName(name)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1249
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1250
    setattr(cls, "getinstanceByName", getinstanceByName)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1251
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1252
    def removeinstance(self, id):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1253
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1254
            self.body[0].removecontentInstance(id)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1255
    setattr(cls, "removeinstance", removeinstance)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1256
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1257
    def settext(self, text):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1258
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1259
            self.body[0].settext(text)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1260
    setattr(cls, "settext", settext)
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1261
    
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1262
    def gettext(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1263
        if len(self.body) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1264
            return self.body[0].gettext()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1265
        return ""
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1266
    setattr(cls, "gettext", gettext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1267
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1268
    def getvars(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1269
        vars = []
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1270
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1271
            reverse_types = {}
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1272
            for name, value in VarTypes.items():
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1273
                reverse_types[value] = name
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1274
            for varlist in self.interface.getcontent():
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1275
                vars.append((reverse_types[varlist["name"]], varlist["value"]))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1276
        return vars
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1277
    setattr(cls, "getvars", getvars)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1278
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1279
    def setvars(self, vars):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1280
        if self.interface is None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1281
            self.interface = PLCOpenClasses["pou_interface"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1282
        self.interface.setcontent([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1283
        for vartype, varlist in vars:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1284
            self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1285
    setattr(cls, "setvars", setvars)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1286
    
435
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1287
    def addpouVar(self, type, name, location="", description=""):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1288
        if self.interface is None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1289
            self.interface = PLCOpenClasses["pou_interface"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1290
        content = self.interface.getcontent()
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1291
        if len(content) == 0 or content[-1]["name"] != "localVars":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1292
            content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()})
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1293
        else:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1294
            varlist = content[-1]["value"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1295
            variables = varlist.getvariable()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1296
            if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1297
                content.append({"name" : "localVars", "value" : PLCOpenClasses["interface_localVars"]()})
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1298
        var = PLCOpenClasses["varListPlain_variable"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1299
        var.setname(name)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1300
        var_type = PLCOpenClasses["dataType"]()
435
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1301
        if type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]:
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1302
            if type == "STRING":
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1303
                var_type.setcontent({"name" : "string", "value" : PLCOpenClasses["elementaryTypes_string"]()})
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1304
            elif type == "WSTRING":
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1305
                var_type.setcontent({"name" : "wstring", "value" : PLCOpenClasses["elementaryTypes_wstring"]()})
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1306
            else:
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1307
                var_type.setcontent({"name" : type, "value" : None})
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1308
        else:
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1309
            derived_type = PLCOpenClasses["derivedTypes_derived"]()
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1310
            derived_type.setname(type)
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1311
            var_type.setcontent({"name" : "derived", "value" : derived_type})
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1312
        var.settype(var_type)
435
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1313
        if location != "":
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1314
            var.setaddress(location)
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1315
        if description != "":
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1316
            ft = PLCOpenClasses["formattedText"]()
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1317
            ft.settext(description)
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1318
            var.setdocumentation(ft)
893d04aff708 Adding support for individually adding variable to POU interface
laurent
parents: 427
diff changeset
  1319
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1320
        content[-1]["value"].appendvariable(var)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1321
    setattr(cls, "addpouVar", addpouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1322
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1323
    def changepouVar(self, old_type, old_name, new_type, new_name):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1324
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1325
            content = self.interface.getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1326
            for varlist in content:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1327
                variables = varlist["value"].getvariable()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1328
                for var in variables:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1329
                    if var.getname() == old_name:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1330
                        vartype_content = var.gettype().getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1331
                        if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1332
                            var.setname(new_name)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1333
                            vartype_content["value"].setname(new_type)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1334
                            return
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1335
    setattr(cls, "changepouVar", changepouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1336
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1337
    def removepouVar(self, type, name):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1338
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1339
            content = self.interface.getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1340
            for varlist in content:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1341
                variables = varlist["value"].getvariable()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1342
                for var in variables:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1343
                    if var.getname() == name:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1344
                        vartype_content = var.gettype().getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1345
                        if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1346
                            variables.remove(var)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1347
                            break
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1348
                if len(varlist["value"].getvariable()) == 0:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1349
                    content.remove(varlist)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
  1350
                    break
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1351
    setattr(cls, "removepouVar", removepouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1352
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1353
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1354
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1355
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1356
                if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name:
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1357
                    return True
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1358
            if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1359
                for transition in self.transitions.gettransition():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1360
                    result = transition.hasblock(name)
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1361
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1362
                        return result
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1363
            if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1364
                for action in self.actions.getaction():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1365
                    result = action.hasblock(name)
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1366
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
  1367
                        return result
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1368
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1369
    setattr(cls, "hasblock", hasblock)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1370
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1371
    def addtransition(self, name, type):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1372
        if not self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1373
            self.addtransitions()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1374
            self.transitions.settransition([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1375
        transition = PLCOpenClasses["transitions_transition"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1376
        transition.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1377
        transition.setbodyType(type)
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1378
        if type == "ST":
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1379
            transition.settext(":= ;")
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1380
        elif type == "IL":
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1381
            transition.settext("\tST\t%s"%name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1382
        self.transitions.appendtransition(transition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1383
    setattr(cls, "addtransition", addtransition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1384
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1385
    def gettransition(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1386
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1387
            for transition in self.transitions.gettransition():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1388
                if transition.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1389
                    return transition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1390
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1391
    setattr(cls, "gettransition", gettransition)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1392
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1393
    def gettransitionList(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1394
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1395
            return self.transitions.gettransition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1396
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1397
    setattr(cls, "gettransitionList", gettransitionList)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1398
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1399
    def removetransition(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1400
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1401
            transitions = self.transitions.gettransition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1402
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1403
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1404
            while i < len(transitions) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1405
                if transitions[i].getname() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
  1406
                    transitions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1407
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1408
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1409
            if not removed:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 417
diff changeset
  1410
                raise ValueError, _("Transition with name %s doesn't exist!")%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1411
    setattr(cls, "removetransition", removetransition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1412
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1413
    def addaction(self, name, type):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1414
        if not self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1415
            self.addactions()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1416
            self.actions.setaction([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1417
        action = PLCOpenClasses["actions_action"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1418
        action.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1419
        action.setbodyType(type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1420
        self.actions.appendaction(action)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1421
    setattr(cls, "addaction", addaction)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1422
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1423
    def getaction(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1424
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1425
            for action in self.actions.getaction():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1426
                if action.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1427
                    return action
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1428
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1429
    setattr(cls, "getaction", getaction)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1430
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1431
    def getactionList(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1432
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1433
            return self.actions.getaction()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1434
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1435
    setattr(cls, "getactionList", getactionList)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1436
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1437
    def removeaction(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1438
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1439
            actions = self.actions.getaction()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1440
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1441
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1442
            while i < len(actions) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1443
                if actions[i].getname() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
  1444
                    actions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1445
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1446
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1447
            if not removed:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 417
diff changeset
  1448
                raise ValueError, _("Action with name %s doesn't exist!")%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1449
    setattr(cls, "removeaction", removeaction)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1450
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1451
    def updateElementName(self, old_name, new_name):
348
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1452
        if self.interface:
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1453
            for content in self.interface.getcontent():
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1454
                for var in content["value"].getvariable():
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1455
                    var_address = var.getaddress()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1456
                    if var_address is not None:
470
cc64bbb1d654 Bug on updateElementName fixed
laurent
parents: 461
diff changeset
  1457
                        if var_address == old_name:
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1458
                            var.setaddress(new_name)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1459
                        if var.getname() == old_name:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1460
                            var.setname(new_name)
348
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1461
                    var_type_content = var.gettype().getcontent()
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1462
                    if var_type_content["name"] == "derived":
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1463
                        if var_type_content["value"].getname() == old_name:
09fdd7616a86 Bug preventing variable or datatype type name to change when POU or datatype name changed fixed
greg
parents: 295
diff changeset
  1464
                            var_type_content["value"].setname(new_name)
394
2e9fc0ad6095 Bug when renaming POU fixed
laurent
parents: 391
diff changeset
  1465
        self.body[0].updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1466
        for action in self.getactionList():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1467
            action.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1468
        for transition in self.gettransitionList():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1469
            transition.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1470
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1471
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1472
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1473
        if self.interface:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1474
            for content in self.interface.getcontent():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1475
                for var in content["value"].getvariable():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1476
                    var_address = var.getaddress()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1477
                    if var_address is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1478
                        var.setaddress(update_address(var_address, address_model, new_leading))
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1479
        self.body[0].updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1480
        for action in self.getactionList():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1481
            action.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1482
        for transition in self.gettransitionList():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1483
            transition.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1484
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1485
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1486
    def removeVariableByAddress(self, address):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1487
        if self.interface:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1488
            for content in self.interface.getcontent():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1489
                variables = content["value"].getvariable()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1490
                for i in xrange(len(variables)-1, -1, -1):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1491
                    if variables[i].getaddress() == address:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1492
                        variables.pop(i)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1493
    setattr(cls, "removeVariableByAddress", removeVariableByAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1494
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1495
    def removeVariableByFilter(self, address_model):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1496
        if self.interface:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1497
            for content in self.interface.getcontent():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1498
                variables = content["value"].getvariable()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1499
                for i in xrange(len(variables)-1, -1, -1):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1500
                    var_address = variables[i].getaddress()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1501
                    if var_address is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1502
                        result = address_model.match(var_address)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1503
                        if result is not None:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1504
                            variables.pop(i)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1505
    setattr(cls, "removeVariableByFilter", removeVariableByFilter)
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1506
    
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1507
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1508
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1509
        filter = criteria["filter"]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1510
        if filter == "all" or self.getpouType() in filter:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1511
            parent_infos = parent_infos + ["P::%s" % self.getname()]
576
3f2024f30553 Adding support for searching pattern in datatype elements
laurent
parents: 566
diff changeset
  1512
            search_result.extend(_Search([("name", self.getname())], criteria, parent_infos))
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1513
            if self.interface is not None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1514
                var_number = 0
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1515
                for content in self.interface.getcontent():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1516
                    variable_type = searchResultVarTypes.get(content["value"], "var_local")
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1517
                    variables = content["value"].getvariable()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1518
                    for modifier, has_modifier in [("constant", content["value"].getconstant()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1519
                                                   ("retain", content["value"].getretain()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1520
                                                   ("non_retain", content["value"].getnonretain())]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1521
                        if has_modifier:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1522
                            for result in TestTextElement(modifier, criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1523
                                search_result.append((tuple(parent_infos + [variable_type, (var_number, var_number + len(variables)), modifier]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1524
                            break
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1525
                    for variable in variables:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1526
                        search_result.extend(variable.Search(criteria, parent_infos + [variable_type, var_number]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1527
                        var_number += 1
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1528
            if len(self.body) > 0:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1529
                search_result.extend(self.body[0].Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1530
            for action in self.getactionList():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1531
                search_result.extend(action.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1532
            for transition in self.gettransitionList():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1533
                search_result.extend(transition.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1534
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1535
    setattr(cls, "Search", Search)
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1536
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1537
def setbodyType(self, type):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1538
    if type == "IL":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1539
        self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1540
    elif type == "ST":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1541
        self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1542
    elif type == "LD":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1543
        self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1544
    elif type == "FBD":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1545
        self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1546
    elif type == "SFC":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1547
        self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()})
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1548
    else:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1549
        raise ValueError, "%s isn't a valid body type!"%type
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1550
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1551
def getbodyType(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1552
    return self.body.getcontent()["name"]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1553
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1554
def resetexecutionOrder(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1555
    self.body.resetexecutionOrder()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1556
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1557
def compileexecutionOrder(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1558
    self.body.compileexecutionOrder()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1559
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1560
def setelementExecutionOrder(self, instance, new_executionOrder):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1561
    self.body.setelementExecutionOrder(instance, new_executionOrder)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1562
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1563
def addinstance(self, name, instance):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1564
    self.body.appendcontentInstance(name, instance)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1565
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1566
def getinstances(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1567
    return self.body.getcontentInstances()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1568
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1569
def getinstance(self, id):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1570
    return self.body.getcontentInstance(id)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1571
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1572
def getrandomInstance(self, exclude):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1573
    return self.body.getcontentRandomInstance(exclude)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1574
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1575
def getinstanceByName(self, name):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1576
    return self.body.getcontentInstanceByName(name)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1577
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1578
def removeinstance(self, id):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1579
    self.body.removecontentInstance(id)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1580
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1581
def settext(self, text):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1582
    self.body.settext(text)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1583
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1584
def gettext(self):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1585
    return self.body.gettext()
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  1586
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1587
cls = PLCOpenClasses.get("transitions_transition", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1588
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1589
    setattr(cls, "setbodyType", setbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1590
    setattr(cls, "getbodyType", getbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1591
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1592
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1593
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1594
    setattr(cls, "addinstance", addinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1595
    setattr(cls, "getinstances", getinstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1596
    setattr(cls, "getinstance", getinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1597
    setattr(cls, "getrandomInstance", getrandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1598
    setattr(cls, "getinstanceByName", getinstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1599
    setattr(cls, "removeinstance", removeinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1600
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1601
    setattr(cls, "gettext", gettext)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1602
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1603
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1604
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1605
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1606
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1607
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1608
        self.body.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1609
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1610
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1611
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1612
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1613
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1614
                if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name:
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1615
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1616
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1617
    setattr(cls, "hasblock", hasblock)
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1618
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1619
    def Search(self, criteria, parent_infos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1620
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1621
        parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1622
        for result in TestTextElement(self.getname(), criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1623
            search_result.append((tuple(parent_infos + ["name"]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1624
        search_result.extend(self.body.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1625
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1626
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1627
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1628
cls = PLCOpenClasses.get("actions_action", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1629
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1630
    setattr(cls, "setbodyType", setbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1631
    setattr(cls, "getbodyType", getbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1632
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1633
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1634
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1635
    setattr(cls, "addinstance", addinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1636
    setattr(cls, "getinstances", getinstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1637
    setattr(cls, "getinstance", getinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1638
    setattr(cls, "getrandomInstance", getrandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1639
    setattr(cls, "getinstanceByName", getinstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1640
    setattr(cls, "removeinstance", removeinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1641
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1642
    setattr(cls, "gettext", gettext)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1643
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1644
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1645
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1646
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1647
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1648
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1649
        self.body.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1650
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1651
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1652
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1653
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1654
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1655
                if isinstance(instance, PLCOpenClasses["fbdObjects_block"]) and instance.getinstanceName() == name:
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1656
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1657
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1658
    setattr(cls, "hasblock", hasblock)
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1659
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1660
    def Search(self, criteria, parent_infos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1661
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1662
        parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1663
        for result in TestTextElement(self.getname(), criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1664
            search_result.append((tuple(parent_infos + ["name"]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1665
        search_result.extend(self.body.Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1666
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1667
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1668
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1669
cls = PLCOpenClasses.get("body", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1670
if cls:
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1671
    cls.currentExecutionOrderId = 0
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1672
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1673
    def resetcurrentExecutionOrderId(self):
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1674
        object.__setattr__(self, "currentExecutionOrderId", 0)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1675
    setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1676
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1677
    def getnewExecutionOrderId(self):
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1678
        object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1679
        return self.currentExecutionOrderId
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1680
    setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1681
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1682
    def resetexecutionOrder(self):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1683
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1684
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1685
                if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), 
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1686
                                                     PLCOpenClasses.get("commonObjects_connector", None), 
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1687
                                                     PLCOpenClasses.get("commonObjects_continuation", None))):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1688
                    element["value"].setexecutionOrderId(0)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1689
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1690
            raise TypeError, _("Can only generate execution order on FBD networks!")
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1691
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1692
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1693
    def compileexecutionOrder(self):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1694
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1695
            self.resetexecutionOrder()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1696
            self.resetcurrentExecutionOrderId()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1697
            for element in self.content["value"].getcontent():
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1698
                if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_outVariable", None)) and element["value"].getexecutionOrderId() == 0:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1699
                    connections = element["value"].connectionPointIn.getconnections()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1700
                    if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1701
                        self.compileelementExecutionOrder(connections[0])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1702
                    element["value"].setexecutionOrderId(self.getnewExecutionOrderId())
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1703
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1704
            raise TypeError, _("Can only generate execution order on FBD networks!")
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1705
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1706
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1707
    def compileelementExecutionOrder(self, link):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1708
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1709
            localid = link.getrefLocalId()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1710
            instance = self.getcontentInstance(localid)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1711
            if isinstance(instance, PLCOpenClasses.get("fbdObjects_block", None)) and instance.getexecutionOrderId() == 0:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1712
                for variable in instance.inputVariables.getvariable():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1713
                    connections = variable.connectionPointIn.getconnections()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1714
                    if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1715
                        self.compileelementExecutionOrder(connections[0])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1716
                instance.setexecutionOrderId(self.getnewExecutionOrderId())
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1717
            elif isinstance(instance, PLCOpenClasses.get("commonObjects_continuation", None)) and instance.getexecutionOrderId() == 0:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1718
                name = instance.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1719
                for tmp_instance in self.getcontentInstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1720
                    if isinstance(tmp_instance, PLCOpenClasses.get("commonObjects_connector", None)) and tmp_instance.getname() == name and tmp_instance.getexecutionOrderId() == 0:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1721
                        connections = tmp_instance.connectionPointIn.getconnections()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1722
                        if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1723
                            self.compileelementExecutionOrder(connections[0])
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1724
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1725
            raise TypeError, _("Can only generate execution order on FBD networks!")
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1726
    setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1727
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1728
    def setelementExecutionOrder(self, instance, new_executionOrder):
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1729
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1730
            old_executionOrder = instance.getexecutionOrderId()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1731
            if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1732
                for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1733
                    if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("commonObjects_comment", None)):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1734
                        element_executionOrder = element["value"].getexecutionOrderId()
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1735
                        if old_executionOrder <= element_executionOrder <= new_executionOrder:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1736
                            element["value"].setexecutionOrderId(element_executionOrder - 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1737
                        if new_executionOrder <= element_executionOrder <= old_executionOrder:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1738
                            element["value"].setexecutionOrderId(element_executionOrder + 1)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1739
            instance.setexecutionOrderId(new_executionOrder)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1740
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1741
            raise TypeError, _("Can only generate execution order on FBD networks!")
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1742
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1743
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1744
    def appendcontentInstance(self, name, instance):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1745
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1746
            self.content["value"].appendcontent({"name" : name, "value" : instance})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1747
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1748
            raise TypeError, _("%s body don't have instances!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1749
    setattr(cls, "appendcontentInstance", appendcontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1750
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1751
    def getcontentInstances(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1752
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1753
            instances = []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1754
            for element in self.content["value"].getcontent():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1755
                instances.append(element["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1756
            return instances
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1757
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1758
            raise TypeError, _("%s body don't have instances!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1759
    setattr(cls, "getcontentInstances", getcontentInstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1760
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1761
    def getcontentInstance(self, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1762
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1763
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1764
                if element["value"].getlocalId() == id:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1765
                    return element["value"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1766
            return None
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1767
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1768
            raise TypeError, _("%s body don't have instances!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1769
    setattr(cls, "getcontentInstance", getcontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1770
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1771
    def getcontentRandomInstance(self, exclude):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1772
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1773
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1774
                if element["value"].getlocalId() not in exclude:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1775
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1776
            return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1777
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1778
            raise TypeError, _("%s body don't have instances!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1779
    setattr(cls, "getcontentRandomInstance", getcontentRandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1780
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1781
    def getcontentInstanceByName(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1782
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1783
            for element in self.content["value"].getcontent():
193
e18e354a8006 But on getinstanceByName in pou class fixed
lbessard
parents: 187
diff changeset
  1784
                if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1785
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1786
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1787
            raise TypeError, _("%s body don't have instances!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1788
    setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1789
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1790
    def removecontentInstance(self, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1791
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1792
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1793
            removed = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1794
            elements = self.content["value"].getcontent()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1795
            while i < len(elements) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1796
                if elements[i]["value"].getlocalId() == id:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1797
                    self.content["value"].removecontent(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1798
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1799
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1800
            if not removed:
427
22d16c457d87 improved English spelling & grammar
b.taylor@willowglen.ca
parents: 417
diff changeset
  1801
                raise ValueError, _("Instance with id %d doesn't exist!")%id
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1802
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1803
            raise TypeError, "%s body don't have instances!"%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1804
    setattr(cls, "removecontentInstance", removecontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1805
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1806
    def settext(self, text):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1807
        if self.content["name"] in ["IL","ST"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1808
            self.content["value"].settext(text)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1809
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1810
            raise TypeError, _("%s body don't have text!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1811
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1812
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1813
    def gettext(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1814
        if self.content["name"] in ["IL","ST"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1815
            return self.content["value"].gettext()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1816
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  1817
            raise TypeError, _("%s body don't have text!")%self.content["name"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1818
    setattr(cls, "gettext", gettext)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1819
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1820
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1821
        if self.content["name"] in ["IL", "ST"]:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1822
            self.content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1823
        else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1824
            for element in self.content["value"].getcontent():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1825
                element["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1826
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1827
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1828
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1829
        if self.content["name"] in ["IL", "ST"]:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1830
            self.content["value"].updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1831
        else:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1832
            for element in self.content["value"].getcontent():
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1833
                element["value"].updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1834
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1835
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1836
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1837
        if self.content["name"] in ["IL", "ST"]:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1838
            search_result = self.content["value"].Search(criteria, parent_infos + ["body", 0])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1839
        else:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1840
            search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1841
            for element in self.content["value"].getcontent():
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1842
                search_result.extend(element["value"].Search(criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1843
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1844
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1845
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1846
def getx(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1847
    return self.position.getx()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1848
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1849
def gety(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1850
    return self.position.gety()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1851
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1852
def setx(self, x):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1853
    self.position.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1854
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1855
def sety(self, y):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1856
    self.position.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1857
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1858
def _getBoundingBox(self):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1859
    return rect(self.getx(), self.gety(), self.getwidth(), self.getheight())
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1860
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1861
def _getConnectionsBoundingBox(connectionPointIn):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1862
    bbox = rect()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1863
    connections = connectionPointIn.getconnections()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1864
    if connections is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1865
        for connection in connections:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1866
            for x, y in connection.getpoints():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1867
                bbox.update(x, y)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1868
    return bbox
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1869
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1870
def _getBoundingBoxSingle(self):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1871
    bbox = _getBoundingBox(self)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1872
    if self.connectionPointIn is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1873
        bbox.union(_getConnectionsBoundingBox(self.connectionPointIn))
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1874
    return bbox
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1875
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1876
def _getBoundingBoxMultiple(self):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1877
    bbox = _getBoundingBox(self)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1878
    for connectionPointIn in self.getconnectionPointIn():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1879
        bbox.union(_getConnectionsBoundingBox(connectionPointIn))
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1880
    return bbox
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1881
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1882
def _filterConnections(connectionPointIn, localId, connections):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1883
    in_connections = connectionPointIn.getconnections()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1884
    if in_connections is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1885
        to_delete = []
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1886
        for i, connection in enumerate(in_connections):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1887
            connected = connection.getrefLocalId()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1888
            if not connections.has_key((localId, connected)) and \
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1889
               not connections.has_key((connected, localId)):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1890
                to_delete.append(i)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1891
        to_delete.reverse()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1892
        for i in to_delete:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1893
            connectionPointIn.removeconnection(i)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1894
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1895
def _filterConnectionsSingle(self, connections):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1896
    if self.connectionPointIn is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1897
        _filterConnections(self.connectionPointIn, self.localId, connections)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1898
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1899
def _filterConnectionsMultiple(self, connections):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1900
    for connectionPointIn in self.getconnectionPointIn():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1901
        _filterConnections(connectionPointIn, self.localId, connections)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1902
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1903
def _getconnectionsdefinition(instance, connections_end):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1904
    id = instance.getlocalId()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1905
    return dict([((id, end), True) for end in connections_end])
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1906
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1907
def _updateConnectionsId(connectionPointIn, translation):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1908
    connections_end = []
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1909
    connections = connectionPointIn.getconnections()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1910
    if connections is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1911
        for connection in connections:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1912
            refLocalId = connection.getrefLocalId()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1913
            new_reflocalId = translation.get(refLocalId, refLocalId)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1914
            connection.setrefLocalId(new_reflocalId)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1915
            connections_end.append(new_reflocalId)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1916
    return connections_end
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1917
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1918
def _updateConnectionsIdSingle(self, translation):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1919
    connections_end = []
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1920
    if self.connectionPointIn is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1921
        connections_end = _updateConnectionsId(self.connectionPointIn, translation)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1922
    return _getconnectionsdefinition(self, connections_end)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1923
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1924
def _updateConnectionsIdMultiple(self, translation):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1925
    connections_end = []
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1926
    for connectionPointIn in self.getconnectionPointIn():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1927
        connections_end.extend(_updateConnectionsId(connectionPointIn, translation))
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1928
    return _getconnectionsdefinition(self, connections_end)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1929
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1930
def _translate(self, dx, dy):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1931
    self.setx(self.getx() + dx)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1932
    self.sety(self.gety() + dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1933
    
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1934
def _translateConnections(connectionPointIn, dx, dy):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1935
    connections = connectionPointIn.getconnections()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1936
    if connections is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1937
        for connection in connections:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1938
            for position in connection.getposition():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1939
                position.setx(position.getx() + dx)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1940
                position.sety(position.gety() + dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1941
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1942
def _translateSingle(self, dx, dy):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1943
    _translate(self, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1944
    if self.connectionPointIn is not None:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1945
        _translateConnections(self.connectionPointIn, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1946
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1947
def _translateMultiple(self, dx, dy):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1948
    _translate(self, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1949
    for connectionPointIn in self.getconnectionPointIn():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1950
        _translateConnections(connectionPointIn, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1951
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1952
def _updateElementName(self, old_name, new_name):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1953
    pass
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1954
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1955
def _updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1956
    pass
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1957
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1958
def _SearchInElement(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1959
    return []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1960
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1961
_connectionsFunctions = {
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1962
    "bbox": {"none": _getBoundingBox,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1963
             "single": _getBoundingBoxSingle,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1964
             "multiple": _getBoundingBoxMultiple},
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1965
    "translate": {"none": _translate,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1966
               "single": _translateSingle,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1967
               "multiple": _translateMultiple},
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1968
    "filter": {"none": lambda self, connections: None,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1969
               "single": _filterConnectionsSingle,
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1970
               "multiple": _filterConnectionsMultiple},
387
fcae4e40f296 Bug when copying InVariable fixed
laurent
parents: 384
diff changeset
  1971
    "update": {"none": lambda self, translation: {},
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1972
               "single": _updateConnectionsIdSingle,
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1973
               "multiple": _updateConnectionsIdMultiple},
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1974
}
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1975
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1976
def _initElementClass(name, classname, connectionPointInType="none"):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1977
    ElementNameToClass[name] = classname
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1978
    cls = PLCOpenClasses.get(classname, None)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1979
    if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1980
        setattr(cls, "getx", getx)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1981
        setattr(cls, "gety", gety)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1982
        setattr(cls, "setx", setx)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1983
        setattr(cls, "sety", sety)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1984
        setattr(cls, "updateElementName", _updateElementName)
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  1985
        setattr(cls, "updateElementAddress", _updateElementAddress)
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1986
        setattr(cls, "getBoundingBox", _connectionsFunctions["bbox"][connectionPointInType])
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1987
        setattr(cls, "translate", _connectionsFunctions["translate"][connectionPointInType])
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1988
        setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType])
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  1989
        setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType])
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  1990
        setattr(cls, "Search", _SearchInElement)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1991
    return cls
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1992
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1993
def _getexecutionOrder(instance, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1994
    executionOrder = instance.getexecutionOrderId()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1995
    if executionOrder is None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1996
        executionOrder = 0
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1997
    specific_values["executionOrder"] = executionOrder
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1998
    
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  1999
def _getdefaultmodifiers(instance, infos):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2000
    infos["negated"] = instance.getnegated()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2001
    infos["edge"] = instance.getedge()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2002
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2003
def _getinputmodifiers(instance, infos):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2004
    infos["negated"] = instance.getnegatedIn()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2005
    infos["edge"] = instance.getedgeIn()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2006
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2007
def _getoutputmodifiers(instance, infos):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2008
    infos["negated"] = instance.getnegatedOut()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2009
    infos["edge"] = instance.getedgeOut()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2010
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2011
MODIFIERS_FUNCTIONS = {"default": _getdefaultmodifiers,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2012
                       "input": _getinputmodifiers,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2013
                       "output": _getoutputmodifiers}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2014
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2015
def _getconnectioninfos(instance, connection, links=False, modifiers=None, parameter=False):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2016
    infos = {"position": connection.getrelPositionXY()}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2017
    if parameter:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2018
        infos["name"] = instance.getformalParameter()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2019
    MODIFIERS_FUNCTIONS.get(modifiers, lambda x, y: None)(instance, infos)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2020
    if links:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2021
        infos["links"] = []
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2022
        connections = connection.getconnections()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2023
        if connections is not None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2024
            for link in connections:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2025
                dic = {"refLocalId": link.getrefLocalId(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2026
                       "points": link.getpoints(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2027
                       "formalParameter": link.getformalParameter()}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2028
                infos["links"].append(dic)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2029
    return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2030
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2031
def _getelementinfos(instance):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2032
    return {"id": instance.getlocalId(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2033
            "x": instance.getx(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2034
            "y": instance.gety(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2035
            "height": instance.getheight(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2036
            "width": instance.getwidth(),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2037
            "specific_values": {},
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2038
            "inputs": [],
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2039
            "outputs": []}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2040
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2041
def _getvariableinfosFunction(type, input, output):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2042
    def getvariableinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2043
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2044
        infos["type"] = type
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2045
        specific_values = infos["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2046
        specific_values["name"] = self.getexpression()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2047
        _getexecutionOrder(self, specific_values)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2048
        if input and output:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2049
            infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2050
            infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2051
        elif input:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2052
            infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "default"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2053
        elif output:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2054
            infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2055
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2056
    return getvariableinfos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2057
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2058
def _getconnectorinfosFunction(type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2059
    def getvariableinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2060
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2061
        infos["type"] = type
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2062
        infos["specific_values"]["name"] = self.getname()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2063
        if type == "connector":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2064
            infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2065
        elif type == "continuation":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2066
            infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2067
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2068
    return getvariableinfos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2069
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2070
def _getpowerrailinfosFunction(type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2071
    def getpowerrailinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2072
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2073
        infos["type"] = type
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2074
        if type == "rightPowerRail":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2075
            for connectionPointIn in self.getconnectionPointIn():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2076
                infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True))
550
cfa295862d55 Fix Driven drawing in LD editor
pizza
parents: 539
diff changeset
  2077
            infos["specific_values"]["connectors"] = len(infos["inputs"])
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2078
        elif type == "leftPowerRail":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2079
            for connectionPointOut in self.getconnectionPointOut():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2080
                infos["outputs"].append(_getconnectioninfos(self, connectionPointOut))
550
cfa295862d55 Fix Driven drawing in LD editor
pizza
parents: 539
diff changeset
  2081
            infos["specific_values"]["connectors"] = len(infos["outputs"])
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2082
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2083
    return getpowerrailinfos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2084
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2085
def _getldelementinfosFunction(type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2086
    def getldelementinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2087
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2088
        infos["type"] = type
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2089
        specific_values = infos["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2090
        specific_values["name"] = self.getvariable()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2091
        _getexecutionOrder(self, specific_values)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2092
        specific_values["negated"] = self.getnegated()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2093
        specific_values["edge"] = self.getedge()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2094
        if type == "coil":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2095
            specific_values["storage"] = self.getstorage()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2096
        infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2097
        infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2098
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2099
    return getldelementinfos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2100
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2101
DIVERGENCE_TYPES = {(True, True): "simultaneousDivergence",
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2102
                    (True, False): "selectionDivergence",
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2103
                    (False, True): "simultaneousConvergence",
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2104
                    (False, False): "selectionConvergence"}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2105
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2106
def _getdivergenceinfosFunction(divergence, simultaneous):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2107
    def getdivergenceinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2108
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2109
        infos["type"] = DIVERGENCE_TYPES[(divergence, simultaneous)]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2110
        if divergence:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2111
            infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2112
            for connectionPointOut in self.getconnectionPointOut():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2113
                infos["outputs"].append(_getconnectioninfos(self, connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2114
            infos["specific_values"]["connectors"] = len(infos["outputs"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2115
        else:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2116
            for connectionPointIn in self.getconnectionPointIn():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2117
                infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2118
            infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2119
            infos["specific_values"]["connectors"] = len(infos["inputs"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2120
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2121
    return getdivergenceinfos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2122
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2123
cls = _initElementClass("comment", "commonObjects_comment")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2124
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2125
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2126
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2127
        infos["type"] = "comment"
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2128
        infos["specific_values"]["content"] = self.getcontentText()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2129
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2130
    setattr(cls, "getinfos", getinfos)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2131
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2132
    def setcontentText(self, text):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2133
        self.content.settext(text)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2134
    setattr(cls, "setcontentText", setcontentText)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2135
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2136
    def getcontentText(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2137
        return self.content.gettext()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2138
    setattr(cls, "getcontentText", getcontentText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2139
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2140
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2141
        self.content.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2142
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2143
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2144
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2145
        self.content.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2146
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2147
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2148
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2149
        return self.content.Search(criteria, parent_infos + ["comment", self.getlocalId(), "content"])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2150
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2151
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2152
cls = _initElementClass("block", "fbdObjects_block")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2153
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2154
    def getBoundingBox(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2155
        bbox = _getBoundingBox(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2156
        for input in self.inputVariables.getvariable():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2157
            bbox.union(_getConnectionsBoundingBox(input.connectionPointIn))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2158
        return bbox
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2159
    setattr(cls, "getBoundingBox", getBoundingBox)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2160
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2161
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2162
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2163
        infos["type"] = self.gettypeName()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2164
        specific_values = infos["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2165
        specific_values["name"] = self.getinstanceName()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2166
        _getexecutionOrder(self, specific_values)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2167
        for variable in self.inputVariables.getvariable():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2168
            infos["inputs"].append(_getconnectioninfos(variable, variable.connectionPointIn, True, "default", True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2169
        for variable in self.outputVariables.getvariable():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2170
            infos["outputs"].append(_getconnectioninfos(variable, variable.connectionPointOut, False, "default", True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2171
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2172
    setattr(cls, "getinfos", getinfos)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2173
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2174
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2175
        if self.typeName == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2176
            self.typeName = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2177
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2178
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2179
    def filterConnections(self, connections):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2180
        for input in self.inputVariables.getvariable():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2181
            _filterConnections(input.connectionPointIn, self.localId, connections)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2182
    setattr(cls, "filterConnections", filterConnections)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2183
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2184
    def updateConnectionsId(self, translation):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2185
        connections_end = []
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2186
        for input in self.inputVariables.getvariable():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2187
            connections_end.extend(_updateConnectionsId(input.connectionPointIn, translation))
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2188
        return _getconnectionsdefinition(self, connections_end)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2189
    setattr(cls, "updateConnectionsId", updateConnectionsId)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2190
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2191
    def translate(self, dx, dy):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2192
        _translate(self, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2193
        for input in self.inputVariables.getvariable():
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2194
            _translateConnections(input.connectionPointIn, dx, dy)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2195
    setattr(cls, "translate", translate)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2196
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2197
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2198
        parent_infos = parent_infos + ["block", self.getlocalId()]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2199
        search_result = _Search([("name", self.getinstanceName()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2200
                                 ("type", self.gettypeName())],
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2201
                                criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2202
        for i, variable in enumerate(self.inputVariables.getvariable()):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2203
            for result in TestTextElement(variable.getformalParameter(), criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2204
                search_result.append((tuple(parent_infos + ["input", i]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2205
        for i, variable in enumerate(self.outputVariables.getvariable()):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2206
            for result in TestTextElement(variable.getformalParameter(), criteria):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2207
                search_result.append((tuple(parent_infos + ["output", i]),) + result)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2208
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2209
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2210
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2211
cls = _initElementClass("leftPowerRail", "ldObjects_leftPowerRail")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2212
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2213
    setattr(cls, "getinfos", _getpowerrailinfosFunction("leftPowerRail"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2214
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2215
cls = _initElementClass("rightPowerRail", "ldObjects_rightPowerRail", "multiple")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2216
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2217
    setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2218
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2219
cls = _initElementClass("contact", "ldObjects_contact", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2220
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2221
    setattr(cls, "getinfos", _getldelementinfosFunction("contact"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2222
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2223
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2224
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2225
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2226
    setattr(cls, "updateElementName", updateElementName)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2227
    
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2228
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2229
        self.variable = update_address(self.variable, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2230
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2231
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2232
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2233
        return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2234
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2235
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2236
cls = _initElementClass("coil", "ldObjects_coil", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2237
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2238
    setattr(cls, "getinfos", _getldelementinfosFunction("coil"))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2239
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2240
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2241
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2242
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2243
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2244
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2245
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2246
        self.variable = update_address(self.variable, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2247
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2248
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2249
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2250
        return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2251
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2252
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2253
cls = _initElementClass("step", "sfcObjects_step", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2254
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2255
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2256
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2257
        infos["type"] = "step"
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2258
        specific_values = infos["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2259
        specific_values["name"] = self.getname()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2260
        specific_values["initial"] = self.getinitialStep()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2261
        if self.connectionPointIn:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2262
            infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2263
        if self.connectionPointOut:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2264
            infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2265
        if self.connectionPointOutAction:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2266
            specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2267
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2268
    setattr(cls, "getinfos", getinfos)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2269
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2270
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2271
        return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2272
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2273
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2274
cls = PLCOpenClasses.get("transition_condition", None)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2275
if cls:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2276
    def compatibility(self, tree):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2277
        connections = []
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2278
        for child in tree.childNodes:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2279
            if child.nodeName == "connection":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2280
                connections.append(child)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2281
        if len(connections) > 0:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2282
            node = CreateNode("connectionPointIn")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2283
            relPosition = CreateNode("relPosition")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2284
            NodeSetAttr(relPosition, "x", "0")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2285
            NodeSetAttr(relPosition, "y", "0")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2286
            node.childNodes.append(relPosition)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2287
            node.childNodes.extend(connections)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2288
            tree.childNodes = [node]
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2289
    setattr(cls, "compatibility", compatibility)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2290
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2291
cls = _initElementClass("transition", "sfcObjects_transition", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2292
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2293
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2294
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2295
        infos["type"] = "transition"
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2296
        specific_values = infos["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2297
        priority = self.getpriority()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2298
        if priority is None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2299
            priority = 0
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2300
        specific_values["priority"] = priority
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2301
        condition = self.getconditionContent()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2302
        specific_values["condition_type"] = condition["type"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2303
        if specific_values["condition_type"] == "connection":
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2304
            specific_values["connection"] = _getconnectioninfos(self, condition["value"], True)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2305
        else:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2306
            specific_values["condition"] = condition["value"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2307
        infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2308
        infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2309
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2310
    setattr(cls, "getinfos", getinfos)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2311
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2312
    def setconditionContent(self, type, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2313
        if not self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2314
            self.addcondition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2315
        if type == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2316
            condition = PLCOpenClasses["condition_reference"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2317
            condition.setname(value)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2318
        elif type == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2319
            condition = PLCOpenClasses["condition_inline"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2320
            condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2321
            condition.settext(value)
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  2322
        elif type == "connection":
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2323
            type = "connectionPointIn"
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2324
            condition = PLCOpenClasses["connectionPointIn"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2325
        self.condition.setcontent({"name" : type, "value" : condition})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2326
    setattr(cls, "setconditionContent", setconditionContent)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2327
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2328
    def getconditionContent(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2329
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2330
            content = self.condition.getcontent()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2331
            values = {"type" : content["name"]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2332
            if values["type"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2333
                values["value"] = content["value"].getname()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2334
            elif values["type"] == "inline":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2335
                values["value"] = content["value"].gettext()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2336
            elif values["type"] == "connectionPointIn":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2337
                values["type"] = "connection"
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2338
                values["value"] = content["value"]
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2339
            return values
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2340
        return ""
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2341
    setattr(cls, "getconditionContent", getconditionContent)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2342
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2343
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2344
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2345
            content = self.condition.getcontent()
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2346
            if content["name"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2347
                if content["value"].getname() == old_name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2348
                    content["value"].setname(new_name)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2349
            elif content["name"] == "inline":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2350
                content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2351
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2352
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2353
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2354
        if self.condition:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2355
            content = self.condition.getcontent()
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2356
            if content["name"] == "reference":
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2357
                content["value"].setname(update_address(content["value"].getname(), address_model, new_leading))
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2358
            elif content["name"] == "inline":
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2359
                content["value"].updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2360
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2361
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2362
    def getconnections(self):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  2363
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2364
            content = self.condition.getcontent()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2365
            if content["name"] == "connectionPointIn":
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2366
                return content["value"].getconnections()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2367
    setattr(cls, "getconnections", getconnections)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2368
    
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2369
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2370
        parent_infos = parent_infos + ["transition", self.getlocalId()]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2371
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2372
        content = self.condition.getcontent()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2373
        if content["name"] == "reference":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2374
            search_result.extend(_Search([("reference", content["value"].getname())], criteria, parent_infos))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2375
        elif content["name"] == "inline":
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2376
            search_result.extend(content["value"].Search(criteria, parent_infos + ["inline"]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2377
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2378
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2379
    
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2380
cls = _initElementClass("selectionDivergence", "sfcObjects_selectionDivergence", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2381
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2382
    setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2384
cls = _initElementClass("selectionConvergence", "sfcObjects_selectionConvergence", "multiple")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2385
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2386
    setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2387
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2388
cls = _initElementClass("simultaneousDivergence", "sfcObjects_simultaneousDivergence", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2389
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2390
    setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2391
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2392
cls = _initElementClass("simultaneousConvergence", "sfcObjects_simultaneousConvergence", "multiple")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2393
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2394
    setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2395
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2396
cls = _initElementClass("jumpStep", "sfcObjects_jumpStep", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2397
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2398
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2399
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2400
        infos["type"] = "jump"
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2401
        infos["specific_values"]["target"] = self.gettargetName()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2402
        infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2403
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2404
    setattr(cls, "getinfos", getinfos)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2405
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2406
    def Search(self, criteria, parent_infos):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2407
        return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2408
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2409
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2410
cls = PLCOpenClasses.get("actionBlock_action", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2411
if cls:
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2412
    def compatibility(self, tree):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2413
        relPosition = reduce(lambda x, y: x | (y.nodeName == "relPosition"), tree.childNodes, False)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2414
        if not tree.hasAttribute("localId"):
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2415
            NodeSetAttr(tree, "localId", "0")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2416
        if not relPosition:
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2417
            node = CreateNode("relPosition")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2418
            NodeSetAttr(node, "x", "0")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2419
            NodeSetAttr(node, "y", "0")
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2420
            tree.childNodes.insert(0, node)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2421
    setattr(cls, "compatibility", compatibility)
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2422
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2423
    def setreferenceName(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2424
        if self.reference:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2425
            self.reference.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2426
    setattr(cls, "setreferenceName", setreferenceName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2427
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2428
    def getreferenceName(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2429
        if self.reference:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2430
            return self.reference.getname()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2431
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2432
    setattr(cls, "getreferenceName", getreferenceName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2433
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2434
    def setinlineContent(self, content):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2435
        if self.inline:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2436
            self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2437
            self.inline.settext(content)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2438
    setattr(cls, "setinlineContent", setinlineContent)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2439
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2440
    def getinlineContent(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2441
        if self.inline:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2442
            return self.inline.gettext()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2443
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2444
    setattr(cls, "getinlineContent", getinlineContent)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2445
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2446
    def updateElementName(self, old_name, new_name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2447
        if self.reference and self.reference.getname() == old_name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2448
            self.reference.setname(new_name)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2449
        if self.inline:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2450
            self.inline.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2451
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2452
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2453
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2454
        if self.reference:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2455
            self.reference.setname(update_address(self.reference.getname(), address_model, new_leading))
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2456
        if self.inline:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2457
            self.inline.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2458
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2459
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2460
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2461
        qualifier = self.getqualifier()
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2462
        if qualifier is None:
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2463
            qualifier = "N"
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2464
        return _Search([("inline", self.getinlineContent()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2465
                        ("reference", self.getreferenceName()), 
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2466
                        ("qualifier", qualifier),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2467
                        ("duration", self.getduration()),
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2468
                        ("indicator", self.getindicator())],
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2469
                       criteria, parent_infos)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2470
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2471
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2472
cls = _initElementClass("actionBlock", "commonObjects_actionBlock", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2473
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2474
    def compatibility(self, tree):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2475
        for child in tree.childNodes[:]:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2476
            if child.nodeName == "connectionPointOut":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2477
                tree.childNodes.remove(child)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2478
    setattr(cls, "compatibility", compatibility)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2479
    
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2480
    def getinfos(self):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2481
        infos = _getelementinfos(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2482
        infos["type"] = "actionBlock"
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2483
        infos["specific_values"]["actions"] = self.getactions()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2484
        infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2485
        return infos
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2486
    setattr(cls, "getinfos", getinfos)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2487
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2488
    def setactions(self, actions):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2489
        self.action = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2490
        for params in actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2491
            action = PLCOpenClasses["actionBlock_action"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2492
            action.setqualifier(params["qualifier"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2493
            if params["type"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2494
                action.addreference()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2495
                action.setreferenceName(params["value"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2496
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2497
                action.addinline()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2498
                action.setinlineContent(params["value"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
  2499
            if params.has_key("duration"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2500
                action.setduration(params["duration"])
379
e4c26ee9c998 Code rewritten, replacing all list containing tests by dict key defining tests
laurent
parents: 348
diff changeset
  2501
            if params.has_key("indicator"):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2502
                action.setindicator(params["indicator"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2503
            self.action.append(action)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2504
    setattr(cls, "setactions", setactions)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2505
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2506
    def getactions(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2507
        actions = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2508
        for action in self.action:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2509
            params = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2510
            params["qualifier"] = action.getqualifier()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  2511
            if params["qualifier"] is None:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  2512
                params["qualifier"] = "N"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2513
            if action.getreference():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2514
                params["type"] = "reference"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2515
                params["value"] = action.getreferenceName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2516
            elif action.getinline():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2517
                params["type"] = "inline"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2518
                params["value"] = action.getinlineContent()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2519
            duration = action.getduration()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2520
            if duration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2521
                params["duration"] = duration
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2522
            indicator = action.getindicator()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2523
            if indicator:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2524
                params["indicator"] = indicator
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2525
            actions.append(params)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2526
        return actions
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2527
    setattr(cls, "getactions", getactions)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2528
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2529
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2530
        for action in self.action:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2531
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2532
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2533
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2534
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2535
        for action in self.action:
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2536
            action.updateElementAddress(address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2537
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2538
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2539
    def Search(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2540
        parent_infos = parent_infos + ["action_block", self.getlocalId()]
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2541
        search_result = []
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2542
        for idx, action in enumerate(self.action):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2543
            search_result.extend(action.Search(criteria, parent_infos + ["action", idx]))
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2544
        return search_result
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2545
    setattr(cls, "Search", Search)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2546
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2547
def _SearchInIOVariable(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2548
    return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2549
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2550
cls = _initElementClass("inVariable", "fbdObjects_inVariable")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2551
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2552
    setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True))
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2553
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2554
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2555
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2556
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2557
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2558
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2559
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2560
        self.expression = update_address(self.expression, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2561
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2562
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2563
    setattr(cls, "Search", _SearchInIOVariable)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2564
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2565
cls = _initElementClass("outVariable", "fbdObjects_outVariable", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2566
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2567
    setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2568
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2569
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2570
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2571
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2572
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2573
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2574
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2575
        self.expression = update_address(self.expression, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2576
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2577
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2578
    setattr(cls, "Search", _SearchInIOVariable)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2579
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2580
cls = _initElementClass("inOutVariable", "fbdObjects_inOutVariable", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2581
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2582
    setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2583
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2584
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2585
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2586
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2587
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  2588
461
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2589
    def updateElementAddress(self, address_model, new_leading):
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2590
        self.expression = update_address(self.expression, address_model, new_leading)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2591
    setattr(cls, "updateElementAddress", updateElementAddress)
649a8465148d Adding support for updating or removing located variables by their address or leading address numbers
laurent
parents: 435
diff changeset
  2592
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2593
    setattr(cls, "Search", _SearchInIOVariable)
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2594
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2595
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2596
def _SearchInConnector(self, criteria, parent_infos=[]):
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2597
    return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()])
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2598
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2599
cls = _initElementClass("continuation", "commonObjects_continuation")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2600
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2601
    setattr(cls, "getinfos", _getconnectorinfosFunction("continuation"))
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2602
    setattr(cls, "Search", _SearchInConnector)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2603
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2604
cls = _initElementClass("connector", "commonObjects_connector", "single")
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2605
if cls:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 379
diff changeset
  2606
    setattr(cls, "getinfos", _getconnectorinfosFunction("connector"))
566
6014ef82a98a Adding support for searching text or regular expression in whole project
laurent
parents: 557
diff changeset
  2607
    setattr(cls, "Search", _SearchInConnector)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2608
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2609
cls = PLCOpenClasses.get("connection", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2610
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2611
    def setpoints(self, points):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2612
        self.position = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2613
        for point in points:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2614
            position = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2615
            position.setx(point.x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2616
            position.sety(point.y)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2617
            self.position.append(position)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2618
    setattr(cls, "setpoints", setpoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2619
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2620
    def getpoints(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2621
        points = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2622
        for position in self.position:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2623
            points.append((position.getx(),position.gety()))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2624
        return points
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2625
    setattr(cls, "getpoints", getpoints)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2626
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2627
cls = PLCOpenClasses.get("connectionPointIn", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2628
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2629
    def setrelPositionXY(self, x, y):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2630
        self.relPosition = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2631
        self.relPosition.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2632
        self.relPosition.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2633
    setattr(cls, "setrelPositionXY", setrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2634
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2635
    def getrelPositionXY(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2636
        if self.relPosition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2637
            return self.relPosition.getx(), self.relPosition.gety()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2638
        else:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2639
            return self.relPosition
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2640
    setattr(cls, "getrelPositionXY", getrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2641
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2642
    def addconnection(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2643
        if not self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2644
            self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]}
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2645
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2646
            self.content["value"].append(PLCOpenClasses["connection"]())
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2647
    setattr(cls, "addconnection", addconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2648
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2649
    def removeconnection(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2650
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2651
            self.content["value"].pop(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2652
        if len(self.content["value"]) == 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2653
            self.content = None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2654
    setattr(cls, "removeconnection", removeconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2655
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2656
    def removeconnections(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2657
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2658
            self.content = None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2659
    setattr(cls, "removeconnections", removeconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2660
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2661
    def getconnections(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2662
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2663
            return self.content["value"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2664
    setattr(cls, "getconnections", getconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2665
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2666
    def setconnectionId(self, idx, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2667
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2668
            self.content["value"][idx].setrefLocalId(id)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2669
    setattr(cls, "setconnectionId", setconnectionId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2670
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2671
    def getconnectionId(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2672
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2673
            return self.content["value"][idx].getrefLocalId()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2674
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2675
    setattr(cls, "getconnectionId", getconnectionId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2676
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2677
    def setconnectionPoints(self, idx, points):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2678
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2679
            self.content["value"][idx].setpoints(points)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2680
    setattr(cls, "setconnectionPoints", setconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2681
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2682
    def getconnectionPoints(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2683
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2684
            return self.content["value"][idx].getpoints()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2685
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2686
    setattr(cls, "getconnectionPoints", getconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2687
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2688
    def setconnectionParameter(self, idx, parameter):
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  2689
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2690
            self.content["value"][idx].setformalParameter(parameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2691
    setattr(cls, "setconnectionParameter", setconnectionParameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2692
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2693
    def getconnectionParameter(self, idx):
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  2694
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2695
            return self.content["value"][idx].getformalParameter()
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  2696
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2697
    setattr(cls, "getconnectionParameter", getconnectionParameter)
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  2698
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2699
cls = PLCOpenClasses.get("connectionPointOut", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2700
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2701
    def setrelPositionXY(self, x, y):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2702
        self.relPosition = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2703
        self.relPosition.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2704
        self.relPosition.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2705
    setattr(cls, "setrelPositionXY", setrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2706
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2707
    def getrelPositionXY(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2708
        if self.relPosition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2709
            return self.relPosition.getx(), self.relPosition.gety()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2710
        return self.relPosition
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2711
    setattr(cls, "getrelPositionXY", getrelPositionXY)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2712
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2713
cls = PLCOpenClasses.get("value", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2714
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2715
    def setvalue(self, value):
557
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2716
        value = value.strip()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2717
        if value.startswith("[") and value.endswith("]"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2718
            arrayValue = PLCOpenClasses["value_arrayValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2719
            self.content = {"name" : "arrayValue", "value" : arrayValue}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2720
        elif value.startswith("(") and value.endswith(")"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2721
            structValue = PLCOpenClasses["value_structValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2722
            self.content = {"name" : "structValue", "value" : structValue}
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2723
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2724
            simpleValue = PLCOpenClasses["value_simpleValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2725
            self.content = {"name" : "simpleValue", "value": simpleValue}
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2726
        self.content["value"].setvalue(value)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2727
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2728
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2729
    def getvalue(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2730
        return self.content["value"].getvalue()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2731
    setattr(cls, "getvalue", getvalue)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2732
147
5ef987c1b927 Bug on array initial value parsing fixed
lbessard
parents: 145
diff changeset
  2733
def extractValues(values):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2734
    items = values.split(",")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2735
    i = 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2736
    while i < len(items):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2737
        opened = items[i - 1].count("(") + items[i - 1].count("[")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2738
        closed = items[i - 1].count(")") + items[i - 1].count("]")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2739
        if opened > closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2740
            items[i - 1] = ','.join([items[i - 1], items.pop(i)])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2741
        elif opened == closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2742
            i += 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2743
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 389
diff changeset
  2744
            raise ValueError, _("\"%s\" is an invalid value!")%value
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2745
    return items
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2746
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2747
cls = PLCOpenClasses.get("value_arrayValue", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2748
if cls:
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2749
    arrayValue_model = re.compile("([0-9]*)\((.*)\)$")
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2750
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2751
    def setvalue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2752
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2753
        for item in extractValues(value[1:-1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2754
            item = item.strip()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2755
            element = PLCOpenClasses["arrayValue_value"]()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2756
            result = arrayValue_model.match(item)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2757
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2758
                groups = result.groups()
389
6a72016d721a Adding support for plcopen version 2.01
laurent
parents: 387
diff changeset
  2759
                element.setrepetitionValue(groups[0])
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2760
                element.setvalue(groups[1].strip())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2761
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2762
                element.setvalue(item)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2763
            self.value.append(element)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2764
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2765
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2766
    def getvalue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2767
        values = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2768
        for element in self.value:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2769
            repetition = element.getrepetitionValue()
557
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2770
            if repetition is not None and int(repetition) > 1:
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2771
                value = element.getvalue()
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2772
                if value is None:
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2773
                    value = ""
0f591ac019f3 Fix bug in extraction and computation of array initial value
laurent
parents: 552
diff changeset
  2774
                values.append("%s(%s)"%(repetition, value))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2775
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2776
                values.append(element.getvalue())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2777
        return "[%s]"%", ".join(values)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2778
    setattr(cls, "getvalue", getvalue)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2779
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2780
cls = PLCOpenClasses.get("value_structValue", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  2781
if cls:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2782
    structValue_model = re.compile("(.*):=(.*)")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2783
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2784
    def setvalue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2785
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  2786
        for item in extractValues(value[1:-1]):
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
  2787
            result = structValue_model.match(item)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2788
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2789
                groups = result.groups()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2790
                element = PLCOpenClasses["structValue_value"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2791
                element.setmember(groups[0].strip())
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2792
                element.setvalue(groups[1].strip())
295
c6ef6d92ce16 Adding support for editing and using struct data types
lbessard
parents: 286
diff changeset
  2793
                self.value.append(element)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2794
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2795
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2796
    def getvalue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2797
        values = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  2798
        for element in self.value:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2799
            values.append("%s := %s"%(element.getmember(), element.getvalue()))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  2800
        return "(%s)"%", ".join(values)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  2801
    setattr(cls, "getvalue", getvalue)