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