plcopen/plcopen.py
author lbessard
Mon, 15 Dec 2008 09:45:16 +0100
changeset 294 4a36f2ec8967
parent 286 67da12c94d2d
child 295 c6ef6d92ce16
permissions -rw-r--r--
Two bugs fixed:
- Errors on Tab close while removing variable panel
- Error in Cut/Copy/Paste function generating 'maximum recursion exceeded' exception
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
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
Define in which order var types must be displayed
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    42
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
Define which action qualifier must be associated with a duration 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    46
    "P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    47
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    48
PLCOpenClasses = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "TC6_XML_V10_B.xsd"))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    49
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    50
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
    51
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    52
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    53
        index = self.text.find(old_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    54
        while index != -1:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    55
            if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    56
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    57
            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
    58
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    59
            else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    60
                self.text = self.text[:index] + new_name + self.text[index + len(old_name):]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    61
                index = self.text.find(old_name, index + len(new_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    62
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    63
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    64
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
    65
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    66
    cls.singleLineAttributes = False
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    67
    cls.EnumeratedDataTypeValues = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    68
    cls.CustomDataTypeRange = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    69
    cls.CustomTypeHierarchy = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    70
    cls.ElementUsingTree = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
    71
    cls.CustomBlockTypes = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    72
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    73
    def setname(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    74
        self.contentHeader.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    75
    setattr(cls, "setname", setname)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    76
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    77
    def getname(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    78
        return self.contentHeader.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    79
    setattr(cls, "getname", getname)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    80
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    81
    def getfileHeader(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    82
        fileheader = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    83
        fileheader["companyName"] = self.fileHeader.getcompanyName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    84
        if self.fileHeader.getcompanyURL():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    85
            fileheader["companyURL"] = self.fileHeader.getcompanyURL()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    86
        fileheader["productName"] = self.fileHeader.getproductName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    87
        fileheader["productVersion"] = self.fileHeader.getproductVersion()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    88
        if self.fileHeader.getproductRelease():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    89
            fileheader["productRelease"] = self.fileHeader.getproductRelease()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    90
        fileheader["creationDateTime"] = self.fileHeader.getcreationDateTime()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    91
        if self.fileHeader.getcontentDescription():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    92
            fileheader["contentDescription"] = self.fileHeader.getcontentDescription()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    93
        return fileheader
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    94
    setattr(cls, "getfileHeader", getfileHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    95
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    96
    def setfileHeader(self, fileheader):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    97
        self.fileHeader.setcompanyName(fileheader["companyName"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    98
        if "companyURL" in fileheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
    99
            self.fileHeader.setcompanyURL(fileheader["companyURL"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   100
        self.fileHeader.setproductName(fileheader["productName"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   101
        self.fileHeader.setproductVersion(fileheader["productVersion"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   102
        if "productRelease" in fileheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   103
            self.fileHeader.setproductRelease(fileheader["productRelease"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   104
        self.fileHeader.setcreationDateTime(fileheader["creationDateTime"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   105
        if "contentDescription" in fileheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   106
            self.fileHeader.setcontentDescription(fileheader["contentDescription"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   107
    setattr(cls, "setfileHeader", setfileHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   108
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   109
    def getcontentHeader(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   110
        contentheader = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   111
        contentheader["projectName"] = self.contentHeader.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   112
        if self.contentHeader.getversion():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   113
            contentheader["projectVersion"] = self.contentHeader.getversion()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   114
        if self.contentHeader.getmodificationDateTime():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   115
            contentheader["modificationDateTime"] = self.contentHeader.getmodificationDateTime()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   116
        if self.contentHeader.getorganization():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   117
            contentheader["organization"] = self.contentHeader.getorganization()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   118
        if self.contentHeader.getauthor():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   119
            contentheader["authorName"] = self.contentHeader.getauthor()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   120
        if self.contentHeader.getlanguage():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   121
            contentheader["language"] = self.contentHeader.getlanguage()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   122
        contentheader["pageSize"] = self.contentHeader.getpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   123
        contentheader["scaling"] = self.contentHeader.getscaling()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   124
        return contentheader
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   125
    setattr(cls, "getcontentHeader", getcontentHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   126
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   127
    def setcontentHeader(self, contentheader):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   128
        self.contentHeader.setname(contentheader["projectName"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   129
        if "projectVersion" in contentheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   130
            self.contentHeader.setversion(contentheader["projectVersion"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   131
        if "modificationDateTime" in contentheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   132
            self.contentHeader.setmodificationDateTime(contentheader["modificationDateTime"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   133
        if "organization" in contentheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   134
            self.contentHeader.setorganization(contentheader["organization"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   135
        if "authorName" in contentheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   136
            self.contentHeader.setauthor(contentheader["authorName"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   137
        if "language" in contentheader:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   138
            self.contentHeader.setlanguage(contentheader["language"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   139
        self.contentHeader.setpageSize(*contentheader["pageSize"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   140
        self.contentHeader.setscaling(contentheader["scaling"])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   141
    setattr(cls, "setcontentHeader", setcontentHeader)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   142
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   143
    def getdataTypes(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   144
        return self.types.getdataTypeElements()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   145
    setattr(cls, "getdataTypes", getdataTypes)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   146
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   147
    def getdataType(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   148
        return self.types.getdataTypeElement(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   149
    setattr(cls, "getdataType", getdataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   150
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   151
    def appenddataType(self, name):
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   152
        if name in self.CustomTypeHierarchy:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   153
            raise ValueError, "\"%s\" Data Type already exists !!!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   154
        self.types.appenddataTypeElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   155
        self.AddCustomDataType(self.getdataType(name))
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   156
    setattr(cls, "appenddataType", appenddataType)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   157
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   158
    def insertdataType(self, index, datatype):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   159
        self.types.insertdataTypeElement(index, datatype)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   160
        self.AddCustomDataType(datatype)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   161
    setattr(cls, "insertdataType", insertdataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   162
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   163
    def removedataType(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   164
        self.types.removedataTypeElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   165
        self.RefreshDataTypeHierarchy()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   166
        self.RefreshElementUsingTree()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   167
    setattr(cls, "removedataType", removedataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   168
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   169
    def getpous(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   170
        return self.types.getpouElements()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   171
    setattr(cls, "getpous", getpous)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   172
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   173
    def getpou(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   174
        return self.types.getpouElement(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   175
    setattr(cls, "getpou", getpou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   176
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   177
    def appendpou(self, name, pou_type, body_type):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   178
        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
   179
        self.AddCustomBlockType(self.getpou(name))
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   180
    setattr(cls, "appendpou", appendpou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   182
    def insertpou(self, index, pou):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   183
        self.types.insertpouElement(index, pou)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   184
        self.AddCustomBlockType(pou)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   185
    setattr(cls, "insertpou", insertpou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   186
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   187
    def removepou(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   188
        self.types.removepouElement(name)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   189
        self.RefreshCustomBlockTypes()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   190
        self.RefreshElementUsingTree()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   191
    setattr(cls, "removepou", removepou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   192
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   193
    def getconfigurations(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   194
        configurations = self.instances.configurations.getconfiguration()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   195
        if configurations:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   196
            return configurations
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   197
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   198
    setattr(cls, "getconfigurations", getconfigurations)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   199
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   200
    def getconfiguration(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   201
        for configuration in self.instances.configurations.getconfiguration():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   202
            if configuration.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   203
                return configuration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   204
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   205
    setattr(cls, "getconfiguration", getconfiguration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   206
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   207
    def addconfiguration(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   208
        for configuration in self.instances.configurations.getconfiguration():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   209
            if configuration.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   210
                raise ValueError, "\"%s\" configuration already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   211
        new_configuration = PLCOpenClasses["configurations_configuration"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   212
        new_configuration.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   213
        self.instances.configurations.appendconfiguration(new_configuration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   214
    setattr(cls, "addconfiguration", addconfiguration)    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   215
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   216
    def removeconfiguration(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   217
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   218
        for idx, configuration in enumerate(self.instances.configurations.getconfiguration()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   219
            if configuration.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   220
                self.instances.configurations.removeconfiguration(idx)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   221
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   222
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   223
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   224
            raise ValueError, "\"%s\" configuration doesn't exist !!!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   225
    setattr(cls, "removeconfiguration", removeconfiguration)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   226
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   227
    def getconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   228
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   229
        if configuration:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   230
            for resource in configuration.getresource():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   231
                if resource.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   232
                    return resource
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   233
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   234
    setattr(cls, "getconfigurationResource", getconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   235
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   236
    def addconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   237
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   238
        if configuration:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   239
            for resource in configuration.getresource():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   240
                if resource.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   241
                    raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   242
            new_resource = PLCOpenClasses["configuration_resource"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   243
            new_resource.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   244
            configuration.appendresource(new_resource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   245
    setattr(cls, "addconfigurationResource", addconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   246
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   247
    def removeconfigurationResource(self, config_name, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   248
        configuration = self.getconfiguration(config_name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   249
        if configuration:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   250
            found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   251
            for idx, resource in enumerate(configuration.getresource()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   252
                if resource.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   253
                    configuration.removeresource(idx)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   254
                    found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   255
                    break
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   256
            if not found:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   257
                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
   258
    setattr(cls, "removeconfigurationResource", removeconfigurationResource)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   259
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   260
    def updateElementName(self, old_name, new_name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   261
        for pou in self.types.getpouElements():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   262
            pou.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   263
        for configuration in self.instances.configurations.getconfiguration():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   264
            configuration.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   265
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   266
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   267
    def RefreshDataTypeHierarchy(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   268
        self.EnumeratedDataTypeValues = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   269
        self.CustomDataTypeRange = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   270
        self.CustomTypeHierarchy = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   271
        for datatype in self.getdataTypes():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   272
            self.AddCustomDataType(datatype)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   273
    setattr(cls, "RefreshDataTypeHierarchy", RefreshDataTypeHierarchy)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   274
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   275
    def AddCustomDataType(self, datatype):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   276
        name = datatype.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   277
        basetype_content = datatype.getbaseType().getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   278
        if basetype_content["value"] is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   279
            self.CustomTypeHierarchy[name] = basetype_content["name"]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   280
        elif basetype_content["name"] in ["string", "wstring"]:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   281
            self.CustomTypeHierarchy[name] = basetype_content["name"].upper()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   282
        elif basetype_content["name"] == "derived":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   283
            self.CustomTypeHierarchy[name] = basetype_content["value"].getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   284
        elif basetype_content["name"] in ["subrangeSigned", "subrangeUnsigned"]:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   285
            range = (basetype_content["value"].range.getlower(), 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   286
                     basetype_content["value"].range.getupper())
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   287
            self.CustomDataTypeRange[name] = range
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   288
            base_type = basetype_content["value"].baseType.getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   289
            if base_type["value"] is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   290
                self.CustomTypeHierarchy[name] = base_type["name"]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   291
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   292
                self.CustomTypeHierarchy[name] = base_type["value"].getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   293
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   294
            if basetype_content["name"] == "enum":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   295
                values = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   296
                for value in basetype_content["value"].values.getvalue():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   297
                    values.append(value.getname())
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   298
                self.EnumeratedDataTypeValues[name] = values
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   299
            self.CustomTypeHierarchy[name] = "ANY_DERIVED"
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   300
    setattr(cls, "AddCustomDataType", AddCustomDataType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   301
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   302
    # Update Block types with user-defined pou added
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   303
    def RefreshCustomBlockTypes(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   304
        # 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
   305
        self.CustomBlockTypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   306
        for pou in self.getpous():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   307
            self.AddCustomBlockType(pou)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   308
    setattr(cls, "RefreshCustomBlockTypes", RefreshCustomBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   309
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   310
    def AddCustomBlockType(self, pou): 
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   311
        pou_name = pou.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   312
        pou_type = pou.getpouType()
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   313
        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
   314
                       "inputs" : [], "outputs" : [], "comment" : "",
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   315
                       "generate" : generate_block, "initialise" : initialise_block}
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   316
        if pou.getinterface():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   317
            return_type = pou.interface.getreturnType()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   318
            if return_type:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   319
                var_type = return_type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   320
                if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   321
                    block_infos["outputs"].append(("", var_type["value"].getname(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   322
                elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   323
                    block_infos["outputs"].append(("", var_type["name"].upper(), "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   324
                else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   325
                    block_infos["outputs"].append(("", var_type["name"], "none"))
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   326
            for type, varlist in pou.getvars():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   327
                if type == "InOut":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   328
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   329
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   330
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   331
                            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
   332
                            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
   333
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   334
                            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
   335
                            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
   336
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   337
                            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
   338
                            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
   339
                elif type == "Input":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   340
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   341
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   342
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   343
                            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
   344
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   345
                            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
   346
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   347
                            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
   348
                elif type == "Output":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   349
                    for var in varlist.getvariable():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   350
                        var_type = var.type.getcontent()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   351
                        if var_type["name"] == "derived":
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   352
                            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
   353
                        elif var_type["name"] in ["string", "wstring"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   354
                            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
   355
                        else:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   356
                            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
   357
        if pou.getbodyType() in ["FBD","LD","SFC"]:
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   358
            for instance in pou.getinstances():
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   359
                if isinstance(instance, PLCOpenClasses.get("commonObjects_comment", None)):
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   360
                    block_infos["comment"] = instance.getcontentText()
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   361
        self.CustomBlockTypes.append(block_infos)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   362
    setattr(cls, "AddCustomBlockType", AddCustomBlockType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   363
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   364
    def RefreshElementUsingTree(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   365
        # 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
   366
        self.ElementUsingTree = {}
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   367
        pous = self.getpous()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   368
        # 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
   369
        # user-defined elemnt cross-use
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   370
        pounames = [pou.getname() for pou in pous]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   371
        for name in pounames:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   372
            self.ElementUsingTree[name] = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   373
        # Analyze each pou
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   374
        for pou in pous:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   375
            name = pou.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   376
            if pou.interface:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   377
                # Extract variables from every varLists
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   378
                for type, varlist in pou.getvars():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   379
                    for var in varlist.getvariable():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   380
                        vartype_content = var.gettype().getcontent()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   381
                        if vartype_content["name"] == "derived":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   382
                            typename = vartype_content["value"].getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   383
                            if typename in pounames and name not in self.ElementUsingTree[typename]:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   384
                                self.ElementUsingTree[typename].append(name)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   385
    setattr(cls, "RefreshElementUsingTree", RefreshElementUsingTree)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   386
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   387
    def GetParentType(self, type):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   388
        if type in self.CustomTypeHierarchy:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   389
            return self.CustomTypeHierarchy[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   390
        elif type in TypeHierarchy:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   391
            return TypeHierarchy[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   392
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   393
    setattr(cls, "GetParentType", GetParentType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   394
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   395
    def GetBaseType(self, type):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   396
        parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   397
        if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   398
            if parent_type.startswith("ANY"):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   399
                return type
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   400
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   401
                return self.GetBaseType(parent_type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   402
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   403
    setattr(cls, "GetBaseType", GetBaseType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   404
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   405
    def GetSubrangeBaseTypes(self, exclude):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   406
        derived = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   407
        for type in self.CustomTypeHierarchy.keys():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   408
            for base_type in DataTypeRange.keys():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   409
                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
   410
                    derived.append(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   411
                    break
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   412
        return DataTypeRange.keys() + derived
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   413
    setattr(cls, "GetSubrangeBaseTypes", GetSubrangeBaseTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   414
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   415
    """
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   416
    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
   417
    """
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   418
    def IsOfType(self, type, reference):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   419
        if reference is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   420
            return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   421
        elif type == reference:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   422
            return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   423
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   424
            parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   425
            if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   426
                return self.IsOfType(parent_type, reference)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   427
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   428
    setattr(cls, "IsOfType", IsOfType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   429
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   430
    # 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
   431
    def ElementIsUsed(self, name):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   432
        if name in self.ElementUsingTree:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   433
            return len(self.ElementUsingTree[name]) > 0
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   434
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   435
    setattr(cls, "ElementIsUsed", ElementIsUsed)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   436
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   437
    def DataTypeIsDerived(self, name):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   438
        return name in self.CustomTypeHierarchy.values()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   439
    setattr(cls, "DataTypeIsDerived", DataTypeIsDerived)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   440
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   441
    # 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
   442
    def ElementIsUsedBy(self, name, reference):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   443
        if name in self.ElementUsingTree:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   444
            list = self.ElementUsingTree[name]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   445
            # Test if pou is directly used by reference
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   446
            if reference in list:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   447
                return True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   448
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   449
                # 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
   450
                # 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
   451
                used = False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   452
                for element in list:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   453
                    used |= self.ElementIsUsedBy(element, reference)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   454
                return used
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   455
        return False
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   456
    setattr(cls, "ElementIsUsedBy", ElementIsUsedBy)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   457
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   458
    def GetDataTypeRange(self, type):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   459
        if type in self.CustomDataTypeRange:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   460
            return self.CustomDataTypeRange[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   461
        elif type in DataTypeRange:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   462
            return DataTypeRange[type]
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   463
        else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   464
            parent_type = self.GetParentType(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   465
            if parent_type is not None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   466
                return self.GetDataTypeRange(parent_type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   467
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   468
    setattr(cls, "GetDataTypeRange", GetDataTypeRange)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   469
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   470
    def GetEnumeratedDataTypeValues(self, type = None):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   471
        if type is None:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   472
            all_values = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   473
            for values in self.EnumeratedDataTypeValues.values():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   474
                all_values.extend(values)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   475
            return all_values
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   476
        elif type in self.EnumeratedDataTypeValues:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   477
            return self.EnumeratedDataTypeValues(type)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   478
        return []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   479
    setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   480
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   481
    # 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
   482
    def GetCustomBlockType(self, type, inputs = None):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   483
        for customblocktype in self.CustomBlockTypes:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   484
            if inputs:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   485
                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
   486
                same_inputs = inputs == customblock_inputs
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   487
            else:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   488
                same_inputs = True
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   489
            if customblocktype["name"] == type and same_inputs:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   490
                return customblocktype
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   491
        return None
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   492
    setattr(cls, "GetCustomBlockType", GetCustomBlockType)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   493
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   494
    # 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
   495
    def GetCustomBlockTypes(self, exclude = "", onlyfunctions = False):
238
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   496
        type = None
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   497
        if exclude != "":
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   498
            pou = self.getpou(exclude)
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   499
            if pou is not None:
389f2046e495 Bug on GetCustomBlockTypes without exclusion or invalid pou fixed
lbessard
parents: 225
diff changeset
   500
                type = pou.getpouType()
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   501
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   502
        for customblocktype in self.CustomBlockTypes:
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   503
            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
   504
                customblocktypes.append(customblocktype)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   505
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   506
    setattr(cls, "GetCustomBlockTypes", GetCustomBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   507
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   508
    # Return Function Block types checking for recursion
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   509
    def GetCustomFunctionBlockTypes(self, exclude = ""):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   510
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   511
        for customblocktype in self.CustomBlockTypes:
286
67da12c94d2d Bug on custom POU list in plcopen model fixed
lbessard
parents: 282
diff changeset
   512
            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
   513
                customblocktypes.append(customblocktype["name"])
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   514
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   515
    setattr(cls, "GetCustomFunctionBlockTypes", GetCustomFunctionBlockTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   516
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   517
    # Return Block types checking for recursion
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   518
    def GetCustomBlockResource(self):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   519
        customblocktypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   520
        for customblocktype in self.CustomBlockTypes:
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   521
            if customblocktype["type"] == "program":
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   522
                customblocktypes.append(customblocktype["name"])
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   523
        return customblocktypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   524
    setattr(cls, "GetCustomBlockResource", GetCustomBlockResource)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   525
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   526
    # Return Data Types checking for recursion
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   527
    def GetCustomDataTypes(self, exclude = ""):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   528
        customdatatypes = []
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   529
        for customdatatype in self.getdataTypes():
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   530
            customdatatype_name = customdatatype.getname()
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   531
            if customdatatype_name != exclude and not self.ElementIsUsedBy(exclude, customdatatype_name):
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   532
                customdatatypes.append(customdatatype_name)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   533
        return customdatatypes
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   534
    setattr(cls, "GetCustomDataTypes", GetCustomDataTypes)
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   535
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   536
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
   537
if cls:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   538
    cls.singleLineAttributes = False
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   539
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   540
cls = PLCOpenClasses.get("project_contentHeader", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   541
if cls:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   542
    cls.singleLineAttributes = False
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   543
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   544
    def setpageSize(self, width, height):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   545
        self.coordinateInfo.setpageSize(width, height)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   546
    setattr(cls, "setpageSize", setpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   547
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   548
    def getpageSize(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   549
        return self.coordinateInfo.getpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   550
    setattr(cls, "getpageSize", getpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   551
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   552
    def setscaling(self, scaling):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   553
        for language, (x, y) in scaling.items():
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   554
            self.coordinateInfo.setscaling(language, x, y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   555
    setattr(cls, "setscaling", setscaling)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   556
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   557
    def getscaling(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   558
        scaling = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   559
        scaling["FBD"] = self.coordinateInfo.getscaling("FBD")
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   560
        scaling["LD"] = self.coordinateInfo.getscaling("LD")
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   561
        scaling["SFC"] = self.coordinateInfo.getscaling("SFC")
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   562
        return scaling
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   563
    setattr(cls, "getscaling", getscaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   564
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   565
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   566
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   567
    def setpageSize(self, width, height):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   568
        if width == 0 and height == 0:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   569
            self.deletepageSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   570
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   571
            if self.pageSize is None:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   572
                self.addpageSize()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   573
            self.pageSize.setx(width)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   574
            self.pageSize.sety(height)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   575
    setattr(cls, "setpageSize", setpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   576
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   577
    def getpageSize(self):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   578
        if self.pageSize is not None:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   579
            return self.pageSize.getx(), self.pageSize.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   580
        return 0, 0
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   581
    setattr(cls, "getpageSize", getpageSize)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   582
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   583
    def setscaling(self, language, x, y):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   584
        if language == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   585
            self.fbd.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   586
            self.fbd.scaling.sety(y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   587
        elif language == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   588
            self.ld.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   589
            self.ld.scaling.sety(y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   590
        elif language == "SFC":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   591
            self.sfc.scaling.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   592
            self.sfc.scaling.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   593
    setattr(cls, "setscaling", setscaling)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   594
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   595
    def getscaling(self, language):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   596
        if language == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   597
            return self.fbd.scaling.getx(), self.fbd.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   598
        elif language == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   599
            return self.ld.scaling.getx(), self.ld.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   600
        elif language == "SFC":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   601
            return self.sfc.scaling.getx(), self.sfc.scaling.gety()
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   602
        return 0, 0
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   603
    setattr(cls, "getscaling", getscaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   604
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   605
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
   606
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   607
    def updateElementName(self, old_name, new_name):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   608
        for resource in self.getresource():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   609
            resource.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   610
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   611
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   612
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   613
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
   614
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   615
    def updateElementName(self, old_name, new_name):
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   616
        for instance in self.getpouInstance():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   617
            instance.updateElementName(old_name, new_name)
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   618
        for task in self.gettask():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   619
            task.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   620
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   621
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   622
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
   623
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   624
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   625
        if self.single == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   626
            self.single = new_name
187
183486133b96 Bugs in configuration_ressource fixed
lbessard
parents: 166
diff changeset
   627
        for instance in self.getpouInstance():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   628
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   629
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   630
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   631
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
   632
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   633
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   634
        if self.type == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   635
            self.type = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   636
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   637
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   638
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
   639
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   640
    def getdataTypeElements(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   641
        return self.dataTypes.getdataType()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   642
    setattr(cls, "getdataTypeElements", getdataTypeElements)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   643
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   644
    def getdataTypeElement(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   645
        elements = self.dataTypes.getdataType()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   646
        for element in elements:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   647
            if element.getname() == name:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   648
                return element
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   649
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   650
    setattr(cls, "getdataTypeElement", getdataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   651
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   652
    def appenddataTypeElement(self, name):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   653
        new_datatype = PLCOpenClasses["dataTypes_dataType"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   654
        new_datatype.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   655
        new_datatype.baseType.setcontent({"name" : "BOOL", "value" : None})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   656
        self.dataTypes.appenddataType(new_datatype)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   657
    setattr(cls, "appenddataTypeElement", appenddataTypeElement)
225
7726c8ffda42 Moving Data types and POU types informations into project model
lbessard
parents: 200
diff changeset
   658
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   659
    def insertdataTypeElement(self, index, dataType):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   660
        self.dataTypes.insertdataType(index, dataType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   661
    setattr(cls, "insertdataTypeElement", insertdataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   662
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   663
    def removedataTypeElement(self, name):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   664
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   665
        for idx, element in enumerate(self.dataTypes.getdataType()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   666
            if element.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   667
                self.dataTypes.removedataType(idx)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   668
                found = True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   669
                break
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   670
        if not found:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   671
            raise ValueError, "\"%s\" Data Type doesn't exist !!!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   672
    setattr(cls, "removedataTypeElement", removedataTypeElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   673
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   674
    def getpouElements(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   675
        return self.pous.getpou()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   676
    setattr(cls, "getpouElements", getpouElements)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   677
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   678
    def getpouElement(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   679
        elements = self.pous.getpou()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   680
        for element in elements:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   681
            if element.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   682
                return element
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   683
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   684
    setattr(cls, "getpouElement", getpouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   685
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   686
    def appendpouElement(self, name, pou_type, body_type):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   687
        for element in self.pous.getpou():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   688
            if element.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   689
                raise ValueError, "\"%s\" POU already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   690
        new_pou = PLCOpenClasses["pous_pou"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   691
        new_pou.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   692
        new_pou.setpouType(pou_type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   693
        new_pou.setbody(PLCOpenClasses["body"]())
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   694
        new_pou.setbodyType(body_type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   695
        self.pous.appendpou(new_pou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   696
    setattr(cls, "appendpouElement", appendpouElement)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   697
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   698
    def insertpouElement(self, index, pou):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   699
        self.pous.insertpou(index, pou)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   700
    setattr(cls, "insertpouElement", insertpouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   701
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   702
    def removepouElement(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   703
        found = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   704
        for idx, element in enumerate(self.pous.getpou()):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   705
            if element.getname() == name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   706
                self.pous.removepou(idx)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   707
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   708
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   709
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   710
            raise ValueError, "\"%s\" POU doesn't exist !!!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   711
    setattr(cls, "removepouElement", removepouElement)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   712
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   713
def setbodyType(self, type):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   714
    if type == "IL":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   715
        self.body.setcontent({"name" : "IL", "value" : PLCOpenClasses["formattedText"]()})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   716
    elif type == "ST":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   717
        self.body.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   718
    elif type == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   719
        self.body.setcontent({"name" : "LD", "value" : PLCOpenClasses["body_LD"]()})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   720
    elif type == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   721
        self.body.setcontent({"name" : "FBD", "value" : PLCOpenClasses["body_FBD"]()})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   722
    elif type == "SFC":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   723
        self.body.setcontent({"name" : "SFC", "value" : PLCOpenClasses["body_SFC"]()})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   724
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   725
        raise ValueError, "%s isn't a valid body type!"%type
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   726
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   727
def getbodyType(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   728
    return self.body.getcontent()["name"]
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   729
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   730
def resetexecutionOrder(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   731
    self.body.resetexecutionOrder()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   732
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   733
def compileexecutionOrder(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   734
    self.body.compileexecutionOrder()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   735
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   736
def setelementExecutionOrder(self, instance, new_executionOrder):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   737
    self.body.setelementExecutionOrder(instance, new_executionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   738
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   739
def addinstance(self, name, instance):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   740
    self.body.appendcontentInstance(name, instance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   741
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   742
def getinstances(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   743
    return self.body.getcontentInstances()
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 getinstance(self, id):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   746
    return self.body.getcontentInstance(id)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   747
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   748
def getrandomInstance(self, exclude):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   749
    return self.body.getcontentRandomInstance(exclude)
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 getinstanceByName(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   752
    return self.body.getcontentInstanceByName(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   753
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   754
def removeinstance(self, id):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   755
    self.body.removecontentInstance(id)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   756
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   757
def settext(self, text):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   758
    self.body.settext(text)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   759
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   760
def gettext(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   761
    return self.body.gettext()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   762
setattr(cls, "gettext", gettext)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   763
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   764
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
   765
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   766
    setattr(cls, "setbodyType", setbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   767
    setattr(cls, "getbodyType", getbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   768
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   769
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   770
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   771
    setattr(cls, "addinstance", addinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   772
    setattr(cls, "getinstances", getinstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   773
    setattr(cls, "getinstance", getinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   774
    setattr(cls, "getrandomInstance", getrandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   775
    setattr(cls, "getinstanceByName", getinstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   776
    setattr(cls, "removeinstance", removeinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   777
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   778
    setattr(cls, "gettext", gettext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   779
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   780
    def getvars(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   781
        vars = []
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   782
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   783
            reverse_types = {}
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   784
            for name, value in VarTypes.items():
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   785
                reverse_types[value] = name
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   786
            for varlist in self.interface.getcontent():
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   787
                vars.append((reverse_types[varlist["name"]], varlist["value"]))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   788
        return vars
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   789
    setattr(cls, "getvars", getvars)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   790
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   791
    def setvars(self, vars):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   792
        if self.interface is None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   793
            self.interface = PLCOpenClasses["pou_interface"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   794
        self.interface.setcontent([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   795
        for vartype, varlist in vars:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   796
            self.interface.appendcontent({"name" : VarTypes[vartype], "value" : varlist})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   797
    setattr(cls, "setvars", setvars)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   798
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   799
    def addpouVar(self, type, name):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   800
        if self.interface is None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   801
            self.interface = PLCOpenClasses["pou_interface"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   802
        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
   803
        if len(content) == 0 or content[-1]["name"] != "localVars":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   804
            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
   805
        else:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   806
            varlist = content[-1]["value"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   807
            variables = varlist.getvariable()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   808
            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
   809
                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
   810
        var = PLCOpenClasses["varListPlain_variable"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   811
        var.setname(name)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   812
        var_type = PLCOpenClasses["dataType"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   813
        derived_type = PLCOpenClasses["derivedTypes_derived"]()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   814
        derived_type.setname(type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   815
        var_type.setcontent({"name" : "derived", "value" : derived_type})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   816
        var.settype(var_type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   817
        content[-1]["value"].appendvariable(var)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   818
    setattr(cls, "addpouVar", addpouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   819
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   820
    def changepouVar(self, old_type, old_name, new_type, new_name):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   821
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   822
            content = self.interface.getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   823
            for varlist in content:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   824
                variables = varlist["value"].getvariable()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   825
                for var in variables:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   826
                    if var.getname() == old_name:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   827
                        vartype_content = var.gettype().getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   828
                        if vartype_content["name"] == "derived" and vartype_content["value"].getname() == old_type:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   829
                            var.setname(new_name)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   830
                            vartype_content["value"].setname(new_type)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   831
                            return
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   832
    setattr(cls, "changepouVar", changepouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   833
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   834
    def removepouVar(self, type, name):
282
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   835
        if self.interface is not None:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   836
            content = self.interface.getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   837
            for varlist in content:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   838
                variables = varlist["value"].getvariable()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   839
                for var in variables:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   840
                    if var.getname() == name:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   841
                        vartype_content = var.gettype().getcontent()
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   842
                        if vartype_content["name"] == "derived" and vartype_content["value"].getname() == type:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   843
                            variables.remove(var)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   844
                            break
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   845
                if len(varlist["value"].getvariable()) == 0:
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   846
                    content.remove(varlist)
a18ddbbc5c58 Bugs on pous without interface fixed
lbessard
parents: 278
diff changeset
   847
                    break
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   848
    setattr(cls, "removepouVar", removepouVar)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   849
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   850
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   851
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   852
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   853
                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
   854
                    return True
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   855
            if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   856
                for transition in self.transitions.gettransition():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   857
                    result = transition.hasblock(name)
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   858
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   859
                        return result
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   860
            if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   861
                for action in self.actions.getaction():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   862
                    result = action.hasblock(name)
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   863
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   864
                        return result
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   865
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   866
    setattr(cls, "hasblock", hasblock)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   867
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   868
    def addtransition(self, name, type):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   869
        if not self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   870
            self.addtransitions()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   871
            self.transitions.settransition([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   872
        transition = PLCOpenClasses["transitions_transition"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   873
        transition.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   874
        transition.setbodyType(type)
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
   875
        if type == "ST":
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
   876
            transition.settext(":= ;")
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
   877
        elif type == "IL":
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
   878
            transition.settext("\tST\t%s"%name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   879
        self.transitions.appendtransition(transition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   880
    setattr(cls, "addtransition", addtransition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   881
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   882
    def gettransition(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   883
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   884
            for transition in self.transitions.gettransition():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   885
                if transition.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   886
                    return transition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   887
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   888
    setattr(cls, "gettransition", gettransition)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   889
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   890
    def gettransitionList(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   891
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   892
            return self.transitions.gettransition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   893
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   894
    setattr(cls, "gettransitionList", gettransitionList)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   895
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   896
    def removetransition(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   897
        if self.transitions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   898
            transitions = self.transitions.gettransition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   899
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   900
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   901
            while i < len(transitions) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   902
                if transitions[i].getname() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   903
                    transitions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   904
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   905
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   906
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   907
                raise ValueError, "Transition with name %s doesn't exists!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   908
    setattr(cls, "removetransition", removetransition)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   909
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   910
    def addaction(self, name, type):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   911
        if not self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   912
            self.addactions()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   913
            self.actions.setaction([])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   914
        action = PLCOpenClasses["actions_action"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   915
        action.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   916
        action.setbodyType(type)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   917
        self.actions.appendaction(action)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   918
    setattr(cls, "addaction", addaction)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   919
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   920
    def getaction(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   921
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   922
            for action in self.actions.getaction():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   923
                if action.getname() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   924
                    return action
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   925
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   926
    setattr(cls, "getaction", getaction)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   927
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   928
    def getactionList(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   929
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   930
            return self.actions.getaction()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   931
        return []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   932
    setattr(cls, "getactionList", getactionList)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   933
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   934
    def removeaction(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   935
        if self.actions:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   936
            actions = self.actions.getaction()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   937
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   938
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   939
            while i < len(actions) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   940
                if actions[i].getname() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   941
                    actions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   942
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   943
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   944
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   945
                raise ValueError, "Action with name %s doesn't exists!"%name
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   946
    setattr(cls, "removeaction", removeaction)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   947
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   948
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   949
        self.body.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   950
        for action in self.getactionList():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   951
            action.updateElementName(old_name, new_name)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   952
        for transition in self.gettransitionList():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   953
            transition.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   954
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   955
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   956
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
   957
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   958
    setattr(cls, "setbodyType", setbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   959
    setattr(cls, "getbodyType", getbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   960
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   961
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   962
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   963
    setattr(cls, "addinstance", addinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   964
    setattr(cls, "getinstances", getinstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   965
    setattr(cls, "getinstance", getinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   966
    setattr(cls, "getrandomInstance", getrandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   967
    setattr(cls, "getinstanceByName", getinstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   968
    setattr(cls, "removeinstance", removeinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   969
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   970
    setattr(cls, "gettext", gettext)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   971
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   972
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   973
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   974
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   975
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   976
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   977
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   978
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   979
                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
   980
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   981
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   982
    setattr(cls, "hasblock", hasblock)
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   983
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   984
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
   985
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   986
    setattr(cls, "setbodyType", setbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   987
    setattr(cls, "getbodyType", getbodyType)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   988
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   989
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   990
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   991
    setattr(cls, "addinstance", addinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   992
    setattr(cls, "getinstances", getinstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   993
    setattr(cls, "getinstance", getinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   994
    setattr(cls, "getrandomInstance", getrandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   995
    setattr(cls, "getinstanceByName", getinstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   996
    setattr(cls, "removeinstance", removeinstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   997
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
   998
    setattr(cls, "gettext", gettext)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   999
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1000
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1001
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1002
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1003
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1004
    def hasblock(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1005
        if self.getbodyType() in ["FBD", "LD", "SFC"]:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1006
            for instance in self.getinstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1007
                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
  1008
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1009
        return False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1010
    setattr(cls, "hasblock", hasblock)
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
  1011
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1012
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
  1013
if cls:
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1014
    cls.currentExecutionOrderId = 0
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1015
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1016
    def resetcurrentExecutionOrderId(self):
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1017
        object.__setattr__(self, "currentExecutionOrderId", 0)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1018
    setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1019
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1020
    def getnewExecutionOrderId(self):
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1021
        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
  1022
        return self.currentExecutionOrderId
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1023
    setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1024
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1025
    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
  1026
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1027
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1028
                if not isinstance(element["value"], (PLCOpenClasses.get("commonObjects_comment", None), 
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1029
                                                     PLCOpenClasses.get("commonObjects_connector", None), 
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1030
                                                     PLCOpenClasses.get("commonObjects_continuation", None))):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1031
                    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
  1032
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1033
            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
  1034
    setattr(cls, "resetexecutionOrder", resetexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1035
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1036
    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
  1037
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1038
            self.resetexecutionOrder()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1039
            self.resetcurrentExecutionOrderId()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1040
            for element in self.content["value"].getcontent():
200
8a1ed1959c69 Pou execution order id management fixed
lbessard
parents: 193
diff changeset
  1041
                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
  1042
                    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
  1043
                    if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1044
                        self.compileelementExecutionOrder(connections[0])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1045
                    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
  1046
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1047
            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
  1048
    setattr(cls, "compileexecutionOrder", compileexecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1049
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1050
    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
  1051
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1052
            localid = link.getrefLocalId()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1053
            instance = self.getcontentInstance(localid)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1054
            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
  1055
                for variable in instance.inputVariables.getvariable():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1056
                    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
  1057
                    if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1058
                        self.compileelementExecutionOrder(connections[0])
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1059
                instance.setexecutionOrderId(self.getnewExecutionOrderId())
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1060
            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
  1061
                name = instance.getname()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1062
                for tmp_instance in self.getcontentInstances():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1063
                    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
  1064
                        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
  1065
                        if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1066
                            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
  1067
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1068
            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
  1069
    setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1070
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1071
    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
  1072
        if self.content["name"] == "FBD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1073
            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
  1074
            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
  1075
                for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1076
                    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
  1077
                        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
  1078
                        if old_executionOrder <= element_executionOrder <= new_executionOrder:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1079
                            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
  1080
                        if new_executionOrder <= element_executionOrder <= old_executionOrder:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1081
                            element["value"].setexecutionOrderId(element_executionOrder + 1)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1082
            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
  1083
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
  1084
            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
  1085
    setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1086
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1087
    def appendcontentInstance(self, name, instance):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1088
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1089
            self.content["value"].appendcontent({"name" : name, "value" : instance})
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1090
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1091
            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
  1092
    setattr(cls, "appendcontentInstance", appendcontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1093
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1094
    def getcontentInstances(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1095
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1096
            instances = []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1097
            for element in self.content["value"].getcontent():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1098
                instances.append(element["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1099
            return instances
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1100
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1101
            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
  1102
    setattr(cls, "getcontentInstances", getcontentInstances)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1103
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1104
    def getcontentInstance(self, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1105
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1106
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1107
                if element["value"].getlocalId() == id:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1108
                    return element["value"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1109
            return None
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1110
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1111
            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
  1112
    setattr(cls, "getcontentInstance", getcontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1113
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1114
    def getcontentRandomInstance(self, exclude):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1115
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1116
            for element in self.content["value"].getcontent():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1117
                if element["value"].getlocalId() not in exclude:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1118
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1119
            return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1120
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1121
            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
  1122
    setattr(cls, "getcontentRandomInstance", getcontentRandomInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1123
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1124
    def getcontentInstanceByName(self, name):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1125
        if self.content["name"] in ["LD","FBD","SFC"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1126
            for element in self.content["value"].getcontent():
193
e18e354a8006 But on getinstanceByName in pou class fixed
lbessard
parents: 187
diff changeset
  1127
                if isinstance(element["value"], PLCOpenClasses.get("fbdObjects_block", None)) and element["value"].getinstanceName() == name:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1128
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1129
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1130
            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
  1131
    setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1132
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1133
    def removecontentInstance(self, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1134
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1135
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1136
            removed = False
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1137
            elements = self.content["value"].getcontent()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1138
            while i < len(elements) and not removed:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1139
                if elements[i]["value"].getlocalId() == id:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1140
                    self.content["value"].removecontent(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1141
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1142
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1143
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1144
                raise ValueError, "Instance with id %d doesn't exists!"%id
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1145
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1146
            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
  1147
    setattr(cls, "removecontentInstance", removecontentInstance)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1148
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1149
    def settext(self, text):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1150
        if self.content["name"] in ["IL","ST"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1151
            self.content["value"].settext(text)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1152
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1153
            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
  1154
    setattr(cls, "settext", settext)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1155
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1156
    def gettext(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1157
        if self.content["name"] in ["IL","ST"]:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1158
            return self.content["value"].gettext()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1159
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1160
            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
  1161
    setattr(cls, "gettext", gettext)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1162
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1163
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1164
        if self.content["name"] in ["IL", "ST"]:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1165
            self.content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1166
        else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1167
            for element in self.content["value"].getcontent():
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1168
                element["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1169
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1170
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1171
def getx(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1172
    return self.position.getx()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1173
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1174
def gety(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1175
    return self.position.gety()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1176
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1177
def setx(self, x):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1178
    self.position.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1179
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1180
def sety(self, y):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1181
    self.position.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1182
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1183
cls = PLCOpenClasses.get("commonObjects_comment", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1184
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1185
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1186
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1187
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1188
    setattr(cls, "sety", sety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1189
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1190
    def setcontentText(self, text):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1191
        self.content.settext(text)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1192
    setattr(cls, "setcontentText", setcontentText)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1193
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1194
    def getcontentText(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1195
        return self.content.gettext()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1196
    setattr(cls, "getcontentText", getcontentText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1197
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1198
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1199
        self.content.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1200
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1201
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1202
cls = PLCOpenClasses.get("fbdObjects_block", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1203
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1204
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1205
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1206
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1207
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1208
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1209
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1210
        if self.typeName == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1211
            self.typeName = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1212
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1213
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1214
cls = PLCOpenClasses.get("ldObjects_leftPowerRail", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1215
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1216
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1217
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1218
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1219
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1220
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1221
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1222
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1223
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1224
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1225
cls = PLCOpenClasses.get("ldObjects_rightPowerRail", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1226
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1227
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1228
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1229
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1230
    setattr(cls, "sety", sety)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1231
    
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1232
    def updateElementName(self, old_name, new_name):
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1233
        pass
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1234
    setattr(cls, "updateElementName", updateElementName)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1235
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1236
cls = PLCOpenClasses.get("ldObjects_contact", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1237
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1238
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1239
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1240
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1241
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1242
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1243
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1244
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1245
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1246
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1247
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1248
cls = PLCOpenClasses.get("ldObjects_coil", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1249
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1250
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1251
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1252
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1253
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1254
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1255
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1256
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1257
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1258
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1259
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1260
cls = PLCOpenClasses.get("sfcObjects_step", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1261
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1262
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1263
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1264
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1265
    setattr(cls, "sety", sety)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1266
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1267
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1268
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1269
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1270
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1271
cls = PLCOpenClasses.get("sfcObjects_transition", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1272
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1273
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1274
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1275
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1276
    setattr(cls, "sety", sety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1277
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1278
    def setconditionContent(self, type, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1279
        if not self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1280
            self.addcondition()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1281
        if type == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1282
            condition = PLCOpenClasses["condition_reference"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1283
            condition.setname(value)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1284
        elif type == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1285
            condition = PLCOpenClasses["condition_inline"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1286
            condition.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1287
            condition.settext(value)
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1288
        elif type == "connection":
166
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
  1289
            condition = [PLCOpenClasses["connection"]()]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1290
        self.condition.setcontent({"name" : type, "value" : condition})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1291
    setattr(cls, "setconditionContent", setconditionContent)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1292
        
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1293
    def getconditionContent(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1294
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1295
            content = self.condition.getcontent()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1296
            values = {"type" : content["name"]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1297
            if values["type"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1298
                values["value"] = content["value"].getname()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1299
            elif values["type"] == "inline":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1300
                values["value"] = content["value"].gettext()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1301
            return values
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1302
        return ""
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1303
    setattr(cls, "getconditionContent", getconditionContent)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1304
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1305
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1306
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1307
            content = self.condition.getcontent()
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1308
            if content["name"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1309
                if content["value"].getname() == old_name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1310
                    content["value"].setname(new_name)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1311
            elif content["name"] == "inline":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1312
                content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1313
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1314
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1315
    def addconnection(self):
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1316
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1317
            content = self.condition.getcontent()
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1318
            if content["name"] != "connection":
166
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
  1319
                self.condition.setcontent({"name" : "connection", "value" : [PLCOpenClasses["connection"]()]})
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1320
                content = self.condition.getcontent()
166
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
  1321
            else:
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
  1322
                content["value"].append(PLCOpenClasses["connection"]())
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1323
    setattr(cls, "addconnection", addconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1324
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1325
    def removeconnection(self, idx):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1326
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1327
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1328
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1329
                content["value"].pop(idx)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1330
        setattr(cls, "removeconnection", removeconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1331
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1332
    def removeconnections(self):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1333
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1334
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1335
            if content["name"] == "connection":
166
de1845119cdd Bug on transition connection fixed
lbessard
parents: 151
diff changeset
  1336
                content["value"] = [PLCOpenClasses["connection"]()]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1337
    setattr(cls, "removeconnections", removeconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1338
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1339
    def getconnections(self):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1340
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1341
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1342
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1343
                return content["value"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1344
    setattr(cls, "getconnections", getconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1345
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1346
    def setconnectionId(self, idx, id):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1347
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1348
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1349
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1350
                content["value"][idx].setrefLocalId(id)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1351
    setattr(cls, "setconnectionId", setconnectionId)
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 getconnectionId(self, idx):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1354
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1355
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1356
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1357
                return content["value"][idx].getrefLocalId()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1358
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1359
    setattr(cls, "getconnectionId", getconnectionId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1360
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1361
    def setconnectionPoints(self, idx, points):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1362
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1363
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1364
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1365
                content["value"][idx].setpoints(points)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1366
    setattr(cls, "setconnectionPoints", setconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1367
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1368
    def getconnectionPoints(self, idx):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1369
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1370
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1371
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1372
                return content["value"][idx].getpoints()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1373
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1374
    setattr(cls, "getconnectionPoints", getconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1375
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1376
    def setconnectionParameter(self, idx, parameter):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1377
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1378
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1379
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1380
                content["value"][idx].setformalParameter(parameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1381
    setattr(cls, "setconnectionParameter", setconnectionParameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1382
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1383
    def getconnectionParameter(self, idx):
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1384
        if self.condition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1385
            content = self.condition.getcontent()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1386
            if content["name"] == "connection":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1387
                return content["value"][idx].getformalParameter()
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1388
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1389
    setattr(cls, "getconnectionParameter", getconnectionParameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1390
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1391
cls = PLCOpenClasses.get("sfcObjects_selectionDivergence", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1392
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1393
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1394
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1395
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1396
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1397
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1398
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1399
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1400
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1401
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1402
cls = PLCOpenClasses.get("sfcObjects_selectionConvergence", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1403
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1404
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1405
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1406
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1407
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1408
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1409
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1410
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1411
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1412
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1413
cls = PLCOpenClasses.get("sfcObjects_simultaneousDivergence", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1414
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1415
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1416
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1417
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1418
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1419
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1420
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1421
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1422
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1423
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1424
cls = PLCOpenClasses.get("sfcObjects_simultaneousConvergence", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1425
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1426
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1427
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1428
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1429
    setattr(cls, "sety", sety)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1430
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1431
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1432
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1433
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1434
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1435
cls = PLCOpenClasses.get("sfcObjects_jumpStep", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1436
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1437
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1438
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1439
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1440
    setattr(cls, "sety", sety)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1441
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1442
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1443
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1444
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1445
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1446
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
  1447
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1448
    def setreferenceName(self, name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1449
        if self.reference:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1450
            self.reference.setname(name)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1451
    setattr(cls, "setreferenceName", setreferenceName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1452
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1453
    def getreferenceName(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1454
        if self.reference:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1455
            return self.reference.getname()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1456
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1457
    setattr(cls, "getreferenceName", getreferenceName)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1458
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1459
    def setinlineContent(self, content):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1460
        if self.inline:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1461
            self.inline.setcontent({"name" : "ST", "value" : PLCOpenClasses["formattedText"]()})
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1462
            self.inline.settext(content)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1463
    setattr(cls, "setinlineContent", setinlineContent)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1464
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1465
    def getinlineContent(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1466
        if self.inline:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1467
            return self.inline.gettext()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1468
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1469
    setattr(cls, "getinlineContent", getinlineContent)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1470
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1471
    def updateElementName(self, old_name, new_name):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1472
        if self.reference and self.reference.getname() == old_name:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1473
            self.reference.setname(new_name)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1474
        if self.inline:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1475
            self.inline.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1476
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1477
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1478
cls = PLCOpenClasses.get("commonObjects_actionBlock", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1479
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1480
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1481
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1482
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1483
    setattr(cls, "sety", sety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1484
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1485
    def setactions(self, actions):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1486
        self.action = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1487
        for params in actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1488
            action = PLCOpenClasses["actionBlock_action"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1489
            action.setqualifier(params["qualifier"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1490
            if params["type"] == "reference":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1491
                action.addreference()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1492
                action.setreferenceName(params["value"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1493
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1494
                action.addinline()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1495
                action.setinlineContent(params["value"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1496
            if "duration" in params:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1497
                action.setduration(params["duration"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1498
            if "indicator" in params:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1499
                action.setindicator(params["indicator"])
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1500
            self.action.append(action)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1501
    setattr(cls, "setactions", setactions)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1502
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1503
    def getactions(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1504
        actions = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1505
        for action in self.action:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1506
            params = {}
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1507
            params["qualifier"] = action.getqualifier()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  1508
            if params["qualifier"] is None:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  1509
                params["qualifier"] = "N"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1510
            if action.getreference():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1511
                params["type"] = "reference"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1512
                params["value"] = action.getreferenceName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1513
            elif action.getinline():
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1514
                params["type"] = "inline"
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1515
                params["value"] = action.getinlineContent()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1516
            duration = action.getduration()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1517
            if duration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1518
                params["duration"] = duration
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1519
            indicator = action.getindicator()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1520
            if indicator:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1521
                params["indicator"] = indicator
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1522
            actions.append(params)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1523
        return actions
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1524
    setattr(cls, "getactions", getactions)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1525
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1526
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1527
        for action in self.action:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1528
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1529
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1530
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1531
cls = PLCOpenClasses.get("fbdObjects_inVariable", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1532
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1533
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1534
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1535
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1536
    setattr(cls, "sety", sety)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1537
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1538
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1539
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1540
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1541
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1542
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1543
cls = PLCOpenClasses.get("fbdObjects_outVariable", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1544
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1545
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1546
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1547
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1548
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1549
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1550
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1551
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1552
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1553
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1554
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1555
cls = PLCOpenClasses.get("fbdObjects_inOutVariable", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1556
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1557
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1558
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1559
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1560
    setattr(cls, "sety", sety)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1561
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1562
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1563
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1564
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1565
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1566
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1567
cls = PLCOpenClasses.get("commonObjects_continuation", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1568
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1569
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1570
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1571
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1572
    setattr(cls, "sety", sety)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1573
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1574
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1575
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1576
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1577
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1578
cls = PLCOpenClasses.get("commonObjects_connector", None)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1579
if cls:
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1580
    setattr(cls, "getx", getx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1581
    setattr(cls, "gety", gety)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1582
    setattr(cls, "setx", setx)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1583
    setattr(cls, "sety", sety)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1584
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1585
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1586
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1587
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1588
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1589
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
  1590
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1591
    def setpoints(self, points):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1592
        self.position = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1593
        for point in points:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1594
            position = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1595
            position.setx(point.x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1596
            position.sety(point.y)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1597
            self.position.append(position)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1598
    setattr(cls, "setpoints", setpoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1599
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1600
    def getpoints(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1601
        points = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1602
        for position in self.position:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1603
            points.append((position.getx(),position.gety()))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1604
        return points
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1605
    setattr(cls, "getpoints", getpoints)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1606
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1607
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
  1608
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1609
    def setrelPositionXY(self, x, y):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1610
        self.relPosition = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1611
        self.relPosition.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1612
        self.relPosition.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1613
    setattr(cls, "setrelPositionXY", setrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1614
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1615
    def getrelPositionXY(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1616
        if self.relPosition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1617
            return self.relPosition.getx(), self.relPosition.gety()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1618
        else:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1619
            return self.relPosition
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1620
    setattr(cls, "getrelPositionXY", getrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1621
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1622
    def addconnection(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1623
        if not self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1624
            self.content = {"name" : "connection", "value" : [PLCOpenClasses["connection"]()]}
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1625
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1626
            self.content["value"].append(PLCOpenClasses["connection"]())
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1627
    setattr(cls, "addconnection", addconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1628
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1629
    def removeconnection(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1630
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1631
            self.content["value"].pop(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1632
        if len(self.content["value"]) == 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1633
            self.content = None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1634
    setattr(cls, "removeconnection", removeconnection)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1635
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1636
    def removeconnections(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1637
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1638
            self.content = None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1639
    setattr(cls, "removeconnections", removeconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1640
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1641
    def getconnections(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1642
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1643
            return self.content["value"]
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1644
    setattr(cls, "getconnections", getconnections)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1645
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1646
    def setconnectionId(self, idx, id):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1647
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1648
            self.content["value"][idx].setrefLocalId(id)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1649
    setattr(cls, "setconnectionId", setconnectionId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1650
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1651
    def getconnectionId(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1652
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1653
            return self.content["value"][idx].getrefLocalId()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1654
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1655
    setattr(cls, "getconnectionId", getconnectionId)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1656
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1657
    def setconnectionPoints(self, idx, points):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1658
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1659
            self.content["value"][idx].setpoints(points)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1660
    setattr(cls, "setconnectionPoints", setconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1661
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1662
    def getconnectionPoints(self, idx):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1663
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1664
            return self.content["value"][idx].getpoints()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1665
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1666
    setattr(cls, "getconnectionPoints", getconnectionPoints)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1667
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1668
    def setconnectionParameter(self, idx, parameter):
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1669
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1670
            self.content["value"][idx].setformalParameter(parameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1671
    setattr(cls, "setconnectionParameter", setconnectionParameter)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1672
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1673
    def getconnectionParameter(self, idx):
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1674
        if self.content:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1675
            return self.content["value"][idx].getformalParameter()
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1676
        return None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1677
    setattr(cls, "getconnectionParameter", getconnectionParameter)
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1678
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1679
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
  1680
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1681
    def setrelPositionXY(self, x, y):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1682
        self.relPosition = PLCOpenClasses["position"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1683
        self.relPosition.setx(x)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1684
        self.relPosition.sety(y)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1685
    setattr(cls, "setrelPositionXY", setrelPositionXY)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1686
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1687
    def getrelPositionXY(self):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1688
        if self.relPosition:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1689
            return self.relPosition.getx(), self.relPosition.gety()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1690
        return self.relPosition
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1691
    setattr(cls, "getrelPositionXY", getrelPositionXY)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1692
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1693
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
  1694
if cls:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1695
    def setvalue(self, value):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1696
        if value.startswith("[") and value.endswith("]"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1697
            arrayValue = PLCOpenClasses["value_arrayValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1698
            self.content = {"name" : "arrayValue", "value" : arrayValue}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1699
        elif value.startswith("(") and value.endswith(")"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1700
            structValue = PLCOpenClasses["value_structValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1701
            self.content = {"name" : "structValue", "value" : structValue}
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1702
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1703
            simpleValue = PLCOpenClasses["value_simpleValue"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1704
            self.content = {"name" : "simpleValue", "value": simpleValue}
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1705
        self.content["value"].setvalue(value)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1706
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1707
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1708
    def getvalue(self):
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1709
        return self.content["value"].getvalue()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1710
    setattr(cls, "getvalue", getvalue)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1711
147
5ef987c1b927 Bug on array initial value parsing fixed
lbessard
parents: 145
diff changeset
  1712
def extractValues(values):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1713
    items = values.split(",")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1714
    i = 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1715
    while i < len(items):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1716
        opened = items[i - 1].count("(") + items[i - 1].count("[")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1717
        closed = items[i - 1].count(")") + items[i - 1].count("]")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1718
        if opened > closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1719
            items[i - 1] = ','.join([items[i - 1], items.pop(i)])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1720
        elif opened == closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1721
            i += 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1722
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1723
            raise ValueError, "\"%s\" is an invalid value!"%value
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1724
    return items
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1725
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1726
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
  1727
if cls:
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1728
    arrayValue_model = re.compile("([0-9]*)\((.*)\)$")
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1729
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1730
    def setvalue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1731
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1732
        for item in extractValues(value[1:-1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1733
            item = item.strip()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1734
            element = PLCOpenClasses["arrayValue_value"]()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1735
            result = arrayValue_model.match(item)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1736
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1737
                groups = result.groups()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1738
                element.setrepetitionValue(int(groups[0]))
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1739
                element.setvalue(groups[1].strip())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1740
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1741
                element.setvalue(item)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1742
            self.value.append(element)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1743
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1744
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1745
    def getvalue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1746
        values = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1747
        for element in self.value:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1748
            repetition = element.getrepetitionValue()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1749
            if repetition is not None and repetition > 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1750
                values.append("%d(%s)"%(repetition, element.getvalue()))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1751
            else:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1752
                values.append(element.getvalue())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1753
        return "[%s]"%", ".join(values)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1754
    setattr(cls, "getvalue", getvalue)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1755
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1756
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
  1757
if cls:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1758
    structValue_model = re.compile("(.*):=(.*)")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1759
    
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1760
    def setvalue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1761
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1762
        for item in extractValues(value[1:-1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1763
            result = arrayValue_model.match(item)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1764
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1765
                groups = result.groups()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1766
                element = PLCOpenClasses["structValue_value"]()
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1767
                element.setmember(groups[0].strip())
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1768
                element.setvalue(groups[1].strip())
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1769
            self.value.append(element)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1770
    setattr(cls, "setvalue", setvalue)
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1771
    
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1772
    def getvalue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1773
        values = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1774
        for element in self.value:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1775
            values.append("%s := %s"%(element.getmember(), element.getvalue()))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1776
        return "(%s)"%", ".join(values)
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 147
diff changeset
  1777
    setattr(cls, "getvalue", getvalue)