plcopen/plcopen.py
author lbessard
Thu, 02 Aug 2007 17:54:42 +0200
changeset 59 af079a11837b
parent 58 39cd981ff242
child 63 04a02b4b2a57
permissions -rw-r--r--
Adding header for files published under LGPL
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 *
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 2
diff changeset
    26
import os, sys
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
Dictionary that makes the relation between var names in plcopen and displayed values
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
            "Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars",
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
            "Global" : "globalVars", "Access" : "accessVars"}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    34
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
Define in which order var types must be displayed
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
Define which action qualifier must be associated with a duration 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    42
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
    "P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    46
PLCOpenClasses = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    47
PLCOpenTypes = {}
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
    48
base_folder = ""
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
    49
for path in sys.path:
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
    50
    if os.path.isfile(os.path.join(path, "plcopen/TC6_XML_V10_B.xsd")):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
    51
        base_folder = path
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 46
diff changeset
    52
GenerateClassesFromXSD(os.path.join(base_folder, "plcopen/TC6_XML_V10_B.xsd"))
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    53
CreateClasses(PLCOpenClasses, PLCOpenTypes)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    54
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    55
if "dataType" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    56
    cls = PLCOpenClasses["dataType"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    57
    cls.value = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    58
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    59
    def getValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    60
        return self.value
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    61
    setattr(cls, "getValue", getValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    62
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    63
    def setValue(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    64
        self.value = value
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    65
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    66
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    67
    def loadXMLTree(self, tree):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    68
        self.value = tree.childNodes[1].nodeName
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    69
    setattr(cls, "loadXMLTree", loadXMLTree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    70
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    71
    def generateXMLText(self, name, indent, extras = {}):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    72
        ind1, ind2 = getIndent(indent, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    73
        text = ind1 + "<%s>\n"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    74
        ind3, ind4 = getIndent(indent + 1, self.value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    75
        text += ind3 + "<%s/>\n"%self.value
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    76
        text += ind1 + "</%s>\n"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    77
        return text
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    78
    setattr(cls, "generateXMLText", generateXMLText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    79
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    80
if "formattedText" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    81
    cls = PLCOpenClasses["formattedText"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    82
    cls.text = ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    83
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    84
    def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    85
        return self.text
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    86
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    87
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    88
    def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    89
        self.text = text
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    90
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    91
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    92
    def loadXMLTree(self, tree):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    93
        self.text = GetAttributeValue(tree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    94
        if len(self.text.splitlines()) > 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    95
            self.text = self.text[1:].rstrip()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    96
    setattr(cls, "loadXMLTree", loadXMLTree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    97
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    98
    def generateXMLText(self, name, indent, extras = {}):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    99
        ind1, ind2 = getIndent(indent, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   100
        if len(self.text.splitlines()) > 1:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   101
            text = ind1 + "<%s>\n"%name
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   102
            text += "%s\n"%self.text
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
            text += ind1 + "</%s>\n"%name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
            return text
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   105
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   106
            return ind1 + "<%s>%s</%s>\n"%(name, self.text, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   107
    setattr(cls, "generateXMLText", generateXMLText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   108
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   109
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   110
        index = self.text.find(old_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   111
        while index != -1:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   112
            if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   113
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   114
            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
   115
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   116
            else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   117
                self.text = self.text[:index] + new_name + self.text[index + len(old_name):]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   118
                index = self.text.find(old_name, index + len(new_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   119
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   120
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   121
if "project" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   122
    cls = PLCOpenClasses["project"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   123
    cls.singleLineAttributes = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   124
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   125
    def getFileHeader(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   126
        fileheader = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   127
        fileheader["companyName"] = self.fileHeader.getCompanyName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   128
        if self.fileHeader.getCompanyURL():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   129
            fileheader["companyURL"] = self.fileHeader.getCompanyURL()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   130
        fileheader["productName"] = self.fileHeader.getProductName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   131
        fileheader["productVersion"] = self.fileHeader.getProductVersion()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   132
        if self.fileHeader.getProductRelease():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   133
            fileheader["productRelease"] = self.fileHeader.getProductRelease()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   134
        fileheader["creationDateTime"] = self.fileHeader.getCreationDateTime()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   135
        if self.fileHeader.getContentDescription():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   136
            fileheader["contentDescription"] = self.fileHeader.getContentDescription()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   137
        return fileheader
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   138
    setattr(cls, "getFileHeader", getFileHeader)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   139
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   140
    def setFileHeader(self, fileheader):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   141
        self.fileHeader.setCompanyName(fileheader["companyName"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   142
        if "companyURL" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   143
            self.fileHeader.setCompanyURL(fileheader["companyURL"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   144
        self.fileHeader.setProductName(fileheader["productName"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   145
        self.fileHeader.setProductVersion(fileheader["productVersion"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   146
        if "productRelease" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   147
            self.fileHeader.setProductRelease(fileheader["productRelease"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   148
        self.fileHeader.setCreationDateTime(fileheader["creationDateTime"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   149
        if "contentDescription" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   150
            self.fileHeader.setContentDescription(fileheader["contentDescription"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   151
    setattr(cls, "setFileHeader", setFileHeader)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   152
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   153
    def setName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   154
        self.contentHeader.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   155
    setattr(cls, "setName", setName)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   156
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   157
    def getName(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   158
        return self.contentHeader.getName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   159
    setattr(cls, "getName", getName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   160
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   161
    def getPous(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   162
        return self.types.getPouElements()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   163
    setattr(cls, "getPous", getPous)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   164
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   165
    def getPou(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   166
        return self.types.getPouElement(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   167
    setattr(cls, "getPou", getPou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   168
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   169
    def appendPou(self, name, pou_type, body_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   170
        self.types.appendPouElement(name, pou_type, body_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   171
    setattr(cls, "appendPou", appendPou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   172
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   173
    def insertPou(self, index, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   174
        self.types.insertPouElement(index, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   175
    setattr(cls, "insertPou", insertPou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   176
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   177
    def removePou(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   178
        self.types.removePouElement(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   179
    setattr(cls, "removePou", removePou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   180
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   181
    def getConfigurations(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   182
        configurations = self.instances.configurations.getConfiguration()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   183
        if configurations:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   184
            return configurations
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   185
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   186
    setattr(cls, "getConfigurations", getConfigurations)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   187
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   188
    def getConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   189
        for configuration in self.instances.configurations.getConfiguration():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   190
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   191
                return configuration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   192
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   193
    setattr(cls, "getConfiguration", getConfiguration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   194
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   195
    def addConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   196
        for configuration in self.instances.configurations.getConfiguration():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   197
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   198
                raise ValueError, "\"%s\" configuration already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   199
        new_configuration = PLCOpenClasses["configurations_configuration"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   200
        new_configuration.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   201
        self.instances.configurations.appendConfiguration(new_configuration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   202
    setattr(cls, "addConfiguration", addConfiguration)    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   203
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   204
    def removeConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   205
        found = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   206
        for idx, configuration in enumerate(self.instances.configurations.getConfiguration()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   207
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   208
                self.instances.configurations.removeConfiguration(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   209
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   210
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   211
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   212
            raise ValueError, "\"%s\" configuration doesn't exist !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   213
    setattr(cls, "removeConfiguration", removeConfiguration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   214
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   215
    def getConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   216
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   217
        if configuration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   218
            for resource in configuration.getResource():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   219
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   220
                    return resource
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   221
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   222
    setattr(cls, "getConfigurationResource", getConfigurationResource)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   223
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   224
    def addConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   225
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   226
        if configuration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   227
            for resource in configuration.getResource():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   228
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   229
                    raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   230
            new_resource = PLCOpenClasses["configuration_resource"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   231
            new_resource.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   232
            configuration.appendResource(new_resource)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   233
    setattr(cls, "addConfigurationResource", addConfigurationResource)    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   234
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   235
    def removeConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   236
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   237
        if configuration:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   238
            found = False
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   239
            for idx, resource in enumerate(configuration.getResource()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   240
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   241
                    configuration.removeResource(idx)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   242
                    found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   243
                    break
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   244
            if not found:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   245
                raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   246
    setattr(cls, "removeConfigurationResource", removeConfigurationResource)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   247
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   248
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   249
        for pou in self.types.getPouElements():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   250
            pou.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   251
        for configuration in self.instances.configurations.getConfiguration():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   252
            configuration.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   253
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   254
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   255
PLCOpenClasses["project_fileHeader"].singleLineAttributes = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   256
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   257
if "configurations_configuration" in PLCOpenClasses:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   258
    cls = PLCOpenClasses["configurations_configuration"]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   259
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   260
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   261
        for resource in self.getResource():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   262
            resource.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   263
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   264
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   265
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   266
if "configuration_resource" in PLCOpenClasses:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   267
    cls = PLCOpenClasses["configuration_resource"]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   268
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   269
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   270
        for instance in self.getPouInstance():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   271
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   272
        for task in self.getTask():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   273
            task.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   274
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   275
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   276
if "resource_task" in PLCOpenClasses:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   277
    cls = PLCOpenClasses["resource_task"]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   278
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   279
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   280
        if self.single == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   281
            self.single = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   282
        for instance in self.getPouInstance():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   283
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   284
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   285
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   286
if "pouInstance" in PLCOpenClasses:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   287
    cls = PLCOpenClasses["pouInstance"]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   288
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   289
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   290
        if self.type == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   291
            self.type = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   292
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   293
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   294
if "project_types" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   295
    cls = PLCOpenClasses["project_types"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   296
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   297
    def getPouElements(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   298
        return self.pous.getPou()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   299
    setattr(cls, "getPouElements", getPouElements)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   300
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   301
    def getPouElement(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   302
        elements = self.pous.getPou()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   303
        for element in elements:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   304
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   305
                return element
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   306
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   307
    setattr(cls, "getPouElement", getPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   308
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   309
    def appendPouElement(self, name, pou_type, body_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   310
        for element in self.pous.getPou():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   311
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   312
                raise ValueError, "\"%s\" POU already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   313
        new_pou = PLCOpenClasses["pous_pou"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   314
        new_pou.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   315
        new_pou.pouType.setValue(pou_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   316
        new_pou.setBody(PLCOpenClasses["body"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   317
        new_pou.setBodyType(body_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   318
        self.pous.appendPou(new_pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   319
    setattr(cls, "appendPouElement", appendPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   320
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   321
    def insertPouElement(self, index, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   322
        self.pous.insertPou(index, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   323
    setattr(cls, "insertPouElement", insertPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   324
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   325
    def removePouElement(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   326
        found = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   327
        for idx, element in enumerate(self.pous.getPou()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   328
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   329
                self.pous.removePou(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   330
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   331
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   332
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   333
            raise ValueError, "\"%s\" POU doesn't exist !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   334
    setattr(cls, "removePouElement", removePouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   335
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   336
def setBodyType(self, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   337
    if type == "IL":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   338
        self.body.setContent("IL", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   339
    elif type == "ST":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   340
        self.body.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   341
    elif type == "LD":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   342
        self.body.setContent("LD", PLCOpenClasses["body_LD"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   343
    elif type == "FBD":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   344
        self.body.setContent("FBD", PLCOpenClasses["body_FBD"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   345
    elif type == "SFC":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   346
        self.body.setContent("SFC", PLCOpenClasses["body_SFC"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   347
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   348
        raise ValueError, "%s isn't a valid body type!"%type
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   349
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   350
def getBodyType(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   351
    return self.body.getContent()["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   352
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   353
def addInstance(self, name, instance):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   354
    self.body.appendContentInstance(name, instance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   355
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   356
def getInstances(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   357
    return self.body.getContentInstances()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   358
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   359
def getInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   360
    return self.body.getContentInstance(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   361
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   362
def getRandomInstance(self, exclude):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   363
    return self.body.getContentRandomInstance(exclude)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   364
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   365
def getInstanceByName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   366
    return self.body.getContentInstanceByName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   367
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   368
def removeInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   369
    self.body.removeContentInstance(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   370
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   371
def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   372
    self.body.setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   373
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   374
def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   375
    return self.body.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   376
setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   377
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   378
if "pous_pou" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   379
    cls = PLCOpenClasses["pous_pou"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   380
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   381
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   382
    setattr(cls, "getBodyType", getBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   383
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   384
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   385
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   386
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   387
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   388
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   389
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   390
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   391
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   392
    def getVars(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   393
        vars = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   394
        reverse_types = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   395
        for name, value in VarTypes.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   396
            reverse_types[value] = name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   397
        for varlist in self.interface.getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   398
            vars.append((reverse_types[varlist["name"]], varlist["value"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   399
        return vars
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   400
    setattr(cls, "getVars", getVars)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   401
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   402
    def setVars(self, vars):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   403
        self.interface.setContent([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   404
        for vartype, varlist in vars:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   405
            self.interface.appendContent(VarTypes[vartype], varlist)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   406
    setattr(cls, "setVars", setVars)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   407
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   408
    def addTransition(self, name, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   409
        if not self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   410
            self.addTransitions()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   411
            self.transitions.setTransition([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   412
        transition = PLCOpenClasses["transitions_transition"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   413
        transition.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   414
        transition.setBodyType(type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   415
        self.transitions.appendTransition(transition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   416
    setattr(cls, "addTransition", addTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   417
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   418
    def getTransition(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   419
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   420
            for transition in self.transitions.getTransition():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   421
                if transition.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   422
                    return transition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   423
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   424
    setattr(cls, "getTransition", getTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   425
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   426
    def getTransitionList(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   427
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   428
            return self.transitions.getTransition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   429
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   430
    setattr(cls, "getTransitionList", getTransitionList)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   431
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   432
    def removeTransition(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   433
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   434
            transitions = self.transitions.getTransition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   435
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   436
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   437
            while i < len(transitions) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   438
                if transitions[i].getName() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   439
                    transitions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   440
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   441
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   442
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   443
                raise ValueError, "Transition with name %s doesn't exists!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   444
    setattr(cls, "removeTransition", removeTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   445
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   446
    def addAction(self, name, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   447
        if not self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   448
            self.addActions()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   449
            self.actions.setAction([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   450
        action = PLCOpenClasses["actions_action"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   451
        action.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   452
        action.setBodyType(type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   453
        self.actions.appendAction(action)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   454
    setattr(cls, "addAction", addAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   455
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   456
    def getAction(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   457
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   458
            for action in self.actions.getAction():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   459
                if action.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   460
                    return action
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   461
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   462
    setattr(cls, "getAction", getAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   463
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   464
    def getActionList(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   465
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   466
            return self.actions.getAction()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   467
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   468
    setattr(cls, "getActionList", getActionList)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   469
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   470
    def removeAction(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   471
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   472
            actions = self.actions.getAction()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   473
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   474
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   475
            while i < len(actions) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   476
                if actions[i].getName() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   477
                    actions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   478
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   479
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   480
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   481
                raise ValueError, "Action with name %s doesn't exists!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   482
    setattr(cls, "removeAction", removeAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   483
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   484
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   485
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   486
        for action in self.getActionList():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   487
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   488
        for transition in self.getTransitionList():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   489
            transition.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   490
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   491
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   492
if "transitions_transition" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   493
    cls = PLCOpenClasses["transitions_transition"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   494
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   495
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   496
    setattr(cls, "getBodyType", getBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   497
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   498
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   499
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   500
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   501
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   502
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   503
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   504
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   505
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   506
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   507
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   508
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   509
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   510
if "actions_action" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   511
    cls = PLCOpenClasses["actions_action"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   512
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   513
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   514
    setattr(cls, "getBodyType", getBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   515
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   516
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   517
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   518
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   519
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   520
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   521
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   522
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   523
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   524
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   525
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   526
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   527
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   528
if "body" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   529
    cls = PLCOpenClasses["body"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   530
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   531
    def appendContentInstance(self, name, instance):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   532
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   533
            self.content["value"].appendContent(name, instance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   534
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   535
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   536
    setattr(cls, "appendContentInstance", appendContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   537
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   538
    def getContentInstances(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   539
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   540
            instances = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   541
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   542
                instances.append(element["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   543
            return instances
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   544
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   545
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   546
    setattr(cls, "getContentInstances", getContentInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   547
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   548
    def getContentInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   549
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   550
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   551
                if element["value"].getLocalId() == id:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   552
                    return element["value"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   553
            return None
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   554
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   555
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   556
    setattr(cls, "getContentInstance", getContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   557
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   558
    def getContentRandomInstance(self, exclude):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   559
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   560
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   561
                if element["value"].getLocalId() not in exclude:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   562
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   563
            return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   564
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   565
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   566
    setattr(cls, "getContentRandomInstance", getContentRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   567
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   568
    def getContentInstanceByName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   569
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   570
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   571
                if element["value"].getLocalId() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   572
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   573
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   574
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   575
    setattr(cls, "getContentInstanceByName", getContentInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   576
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   577
    def removeContentInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   578
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   579
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   580
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   581
            elements = self.content["value"].getContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   582
            while i < len(elements) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   583
                if elements[i]["value"].getLocalId() == id:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   584
                    self.content["value"].removeContent(i)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   585
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   586
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   587
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   588
                raise ValueError, "Instance with id %d doesn't exists!"%id
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   589
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   590
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   591
    setattr(cls, "removeContentInstance", removeContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   592
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   593
    def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   594
        if self.content["name"] in ["IL","ST"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   595
            self.content["value"].setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   596
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   597
            raise TypeError, "%s body don't have text!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   598
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   599
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   600
    def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   601
        if self.content["name"] in ["IL","ST"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   602
            return self.content["value"].getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   603
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   604
            raise TypeError, "%s body don't have text!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   605
    setattr(cls, "getText", getText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   606
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   607
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   608
        if self.content["name"] in ["IL", "ST"]:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   609
            self.content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   610
        else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   611
            for element in self.content["value"].getContent():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   612
                element["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   613
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   614
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   615
def getX(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   616
    return self.position.getX()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   617
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   618
def getY(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   619
    return self.position.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   620
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   621
def setX(self, x):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   622
    self.position.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   623
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   624
def setY(self, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   625
    self.position.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   626
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   627
if "comment" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   628
    cls = PLCOpenClasses["comment"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   629
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   630
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   631
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   632
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   633
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   634
    def setContentText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   635
        self.content.setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   636
    setattr(cls, "setContentText", setContentText)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   638
    def getContentText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   639
        return self.content.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   640
    setattr(cls, "getContentText", getContentText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   641
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   642
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   643
        self.content.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   644
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   645
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   646
if "block" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   647
    cls = PLCOpenClasses["block"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   648
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   649
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   650
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   651
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   652
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   653
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   654
        if self.typeName == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   655
            self.typeName = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   656
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   657
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   658
if "inputVariables_variable" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   659
    cls = PLCOpenClasses["inputVariables_variable"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   660
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   661
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   662
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   663
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   664
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   665
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   666
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   667
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   668
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   669
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   670
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   671
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   672
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   673
if "outputVariables_variable" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   674
    cls = PLCOpenClasses["outputVariables_variable"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   675
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   676
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   677
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   678
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   679
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   680
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   681
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   682
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   683
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   684
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   685
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   686
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   687
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   688
if "leftPowerRail" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   689
    cls = PLCOpenClasses["leftPowerRail"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   690
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   691
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   692
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   693
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   694
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   695
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   696
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   697
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   698
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   699
if "contact" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   700
    cls = PLCOpenClasses["contact"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   701
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   702
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   703
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   704
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   705
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   706
    def setContactEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   707
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   708
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   709
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   710
    setattr(cls, "setContactEdge", setContactEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   711
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   712
    def getContactEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   713
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   714
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   715
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   716
    setattr(cls, "getContactEdge", getContactEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   717
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   718
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   719
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   720
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   721
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   722
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   723
if "coil" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   724
    cls = PLCOpenClasses["coil"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   725
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   726
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   727
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   728
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   729
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   730
    def setCoilStorage(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   731
        if not self.storage:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   732
            self.storage = PLCOpenClasses["storageModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   733
        self.storage.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   734
    setattr(cls, "setCoilStorage", setCoilStorage)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   735
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   736
    def getCoilStorage(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   737
        if self.storage:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   738
            return self.storage.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   739
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   740
    setattr(cls, "getCoilStorage", getCoilStorage)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   741
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   742
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   743
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   744
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   745
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   746
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   747
if "rightPowerRail" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   748
    cls = PLCOpenClasses["rightPowerRail"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   749
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   750
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   751
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   752
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   753
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   754
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   755
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   756
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   757
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   758
if "step" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   759
    cls = PLCOpenClasses["step"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   760
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   761
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   762
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   763
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   764
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   765
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   766
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   767
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   768
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   769
if "transition" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   770
    cls = PLCOpenClasses["transition"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   771
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   772
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   773
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   774
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   775
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   776
    def setConditionContent(self, type, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   777
        if not self.condition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   778
            self.addCondition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   779
        if type == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   780
            condition = PLCOpenClasses["condition_reference"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   781
            condition.setName(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   782
        elif type == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   783
            condition = PLCOpenClasses["condition_inline"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   784
            condition.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   785
            condition.setText(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   786
        self.condition.setContent(type, condition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   787
    setattr(cls, "setConditionContent", setConditionContent)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   788
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   789
    def getConditionContent(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   790
        if self.condition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   791
            content = self.condition.getContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   792
            values = {"type" : content["name"]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   793
            if values["type"] == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   794
                values["value"] = content["value"].getName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   795
            elif values["type"] == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   796
                values["value"] = content["value"].getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   797
            return values
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   798
        return ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   799
    setattr(cls, "getConditionContent", getConditionContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   800
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   801
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   802
        if self.condition:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   803
            content = self.condition.getContent()
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   804
            if content["name"] == "reference":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   805
                if content["value"].getName() == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   806
                    content["value"].setName(new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   807
            elif content["name"] == "inline":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   808
                content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   809
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   810
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   811
if "selectionDivergence" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   812
    cls = PLCOpenClasses["selectionDivergence"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   813
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   814
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   815
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   816
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   817
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   818
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   819
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   820
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   821
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   822
if "selectionConvergence" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   823
    cls = PLCOpenClasses["selectionConvergence"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   824
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   825
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   826
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   827
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   828
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   829
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   830
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   831
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   832
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   833
if "simultaneousDivergence" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   834
    cls = PLCOpenClasses["simultaneousDivergence"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   835
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   836
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   837
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   838
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   839
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   840
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   841
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   842
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   843
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   844
if "simultaneousDivergence" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   845
    cls = PLCOpenClasses["simultaneousConvergence"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   846
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   847
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   848
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   849
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   850
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   851
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   852
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   853
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   854
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   855
if "jumpStep" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   856
    cls = PLCOpenClasses["jumpStep"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   857
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   858
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   859
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   860
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   861
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   862
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   863
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   864
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   865
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   866
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   867
if "actionBlock_action" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   868
    cls = PLCOpenClasses["actionBlock_action"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   869
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   870
    def setQualifierValue(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   871
        if self.qualifier:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   872
            self.qualifier.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   873
    setattr(cls, "setQualifierValue", setQualifierValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   874
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   875
    def getQualifierValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   876
        if self.qualifier:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   877
            return self.qualifier.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   878
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   879
    setattr(cls, "getQualifierValue", getQualifierValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   880
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   881
    def setReferenceName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   882
        if self.reference:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   883
            self.reference.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   884
    setattr(cls, "setReferenceName", setReferenceName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   885
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   886
    def getReferenceName(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   887
        if self.reference:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   888
            return self.reference.getName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   889
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   890
    setattr(cls, "getReferenceName", getReferenceName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   891
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   892
    def setInlineContent(self, content):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   893
        if self.inline:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   894
            self.inline.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   895
            self.inline.setText(content)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   896
    setattr(cls, "setInlineContent", setInlineContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   897
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   898
    def getInlineContent(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   899
        if self.inline:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   900
            return self.inline.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   901
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   902
    setattr(cls, "getInlineContent", getInlineContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   903
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   904
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   905
        if self.reference and self.reference.getName() == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   906
            self.reference.setName(new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   907
        if self.inline:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   908
            self.inline.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   909
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   910
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   911
if "actionBlock" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   912
    cls = PLCOpenClasses["actionBlock"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   913
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   914
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   915
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   916
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   917
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   918
    def setActions(self, actions):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   919
        self.action = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   920
        for params in actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   921
            action = PLCOpenClasses["actionBlock_action"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   922
            action.addQualifier()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   923
            action.setQualifierValue(params["qualifier"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   924
            if params["type"] == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   925
                action.addReference()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   926
                action.setReferenceName(params["value"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   927
            else:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   928
                action.addInline()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   929
                action.setInlineContent(params["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   930
            if "duration" in params:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   931
                action.setDuration(params["duration"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   932
            if "indicator" in params:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   933
                action.setIndicator(params["indicator"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   934
            self.action.append(action)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   935
    setattr(cls, "setActions", setActions)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   936
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   937
    def getActions(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   938
        actions = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   939
        for action in self.action:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   940
            params = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   941
            params["qualifier"] = action.getQualifierValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   942
            if action.getReference():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   943
                params["type"] = "reference"
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   944
                params["value"] = action.getReferenceName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   945
            elif action.getInline():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   946
                params["type"] = "inline"
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   947
                params["value"] = action.getInlineContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   948
            duration = action.getDuration()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   949
            if duration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   950
                params["duration"] = duration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   951
            indicator = action.getIndicator()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   952
            if indicator:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   953
                params["indicator"] = indicator
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   954
            actions.append(params)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   955
        return actions
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   956
    setattr(cls, "getActions", getActions)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   957
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   958
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   959
        for action in self.action:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   960
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   961
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   962
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   963
if "inVariable" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   964
    cls = PLCOpenClasses["inVariable"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   965
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   966
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   967
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   968
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   969
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   970
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   971
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   972
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   973
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   974
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   975
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   976
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   977
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   978
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   979
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   980
    setattr(cls, "getConnectorEdge", getConnectorEdge)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   981
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   982
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   983
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   984
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   985
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   986
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   987
if "outVariable" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   988
    cls = PLCOpenClasses["outVariable"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   989
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   990
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   991
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   992
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   993
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   994
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   995
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   996
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   997
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   998
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   999
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1000
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1001
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1002
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1003
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1004
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1005
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1006
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1007
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1008
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1009
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1010
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1011
if "inOutVariable" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1012
    cls = PLCOpenClasses["inOutVariable"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1013
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1014
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1015
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1016
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1017
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1018
    def setInputEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1019
        if not self.edgeIn:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1020
            self.edgeIn = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1021
        self.edgeIn.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1022
    setattr(cls, "setInputEdge", setInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1023
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1024
    def getInputEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1025
        if self.edgeIn:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1026
            return self.edgeIn.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1027
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1028
    setattr(cls, "getInputEdge", getInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1029
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1030
    def setOutputEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1031
        if not self.edgeOut:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1032
            self.edgeOut = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1033
        self.edgeOut.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1034
    setattr(cls, "setInputEdge", setInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1035
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1036
    def getOutputEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1037
        if self.edgeOut:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1038
            return self.edgeOut.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1039
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1040
    setattr(cls, "getOutputEdge", getOutputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1041
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1042
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1043
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1044
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1045
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1046
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1047
if "continuation" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1048
    cls = PLCOpenClasses["continuation"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1049
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1050
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1051
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1052
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1053
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1054
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1055
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1056
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1057
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1058
if "connector" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1059
    cls = PLCOpenClasses["connector"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1060
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1061
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1062
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1063
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1064
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1065
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1066
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1067
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1068
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1069
if "connection" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1070
    cls = PLCOpenClasses["connection"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1071
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1072
    def setPoints(self, points):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1073
        self.position = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1074
        for point in points:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1075
            position = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1076
            position.setX(point.x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1077
            position.setY(point.y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1078
            self.position.append(position)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1079
    setattr(cls, "setPoints", setPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1080
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1081
    def getPoints(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1082
        points = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1083
        for position in self.position:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1084
            points.append((position.getX(),position.getY()))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1085
        return points
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1086
    setattr(cls, "getPoints", getPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1087
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1088
if "connectionPointIn" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1089
    cls = PLCOpenClasses["connectionPointIn"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1090
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1091
    def setRelPosition(self, x, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1092
        self.relPosition = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1093
        self.relPosition.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1094
        self.relPosition.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1095
    setattr(cls, "setRelPosition", setRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1096
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1097
    def getRelPosition(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1098
        if self.relPosition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1099
            return self.relPosition.getX(), self.relPosition.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1100
        else:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1101
            return self.relPosition
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1102
    setattr(cls, "getRelPosition", getRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1103
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1104
    def addConnection(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1105
        if not self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1106
            self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1107
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1108
            self.content["value"].append(PLCOpenClasses["connection"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1109
    setattr(cls, "addConnection", addConnection)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1110
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1111
    def removeConnection(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1112
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1113
            self.content["value"].pop(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1114
        if len(self.content["value"]) == 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1115
            self.content = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1116
    setattr(cls, "removeConnection", removeConnection)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1117
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1118
    def removeConnections(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1119
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1120
            self.content = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1121
    setattr(cls, "removeConnections", removeConnections)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1122
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1123
    def getConnections(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1124
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1125
            return self.content["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1126
    setattr(cls, "getConnections", getConnections)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1127
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1128
    def setConnectionId(self, idx, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1129
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1130
            self.content["value"][idx].setRefLocalId(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1131
    setattr(cls, "setConnectionId", setConnectionId)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1132
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1133
    def getConnectionId(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1134
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1135
            return self.content["value"][idx].getRefLocalId()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1136
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1137
    setattr(cls, "getConnectionId", getConnectionId)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1138
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1139
    def setConnectionPoints(self, idx, points):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1140
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1141
            self.content["value"][idx].setPoints(points)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1142
    setattr(cls, "setConnectionPoints", setConnectionPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1143
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1144
    def getConnectionPoints(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1145
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1146
            return self.content["value"][idx].getPoints()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1147
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1148
    setattr(cls, "getConnectionPoints", getConnectionPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1149
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1150
    def setConnectionParameter(self, idx, parameter):
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1151
        if self.content:
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1152
            self.content["value"][idx].setFormalParameter(parameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1153
    setattr(cls, "setConnectionParameter", setConnectionParameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1154
    
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1155
    def getConnectionParameter(self, idx):
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1156
        if self.content:
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1157
            return self.content["value"][idx].getFormalParameter()
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1158
        return None
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1159
    setattr(cls, "getConnectionParameter", getConnectionParameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1160
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1161
if "connectionPointOut" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1162
    cls = PLCOpenClasses["connectionPointOut"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1163
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1164
    def setRelPosition(self, x, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1165
        self.relPosition = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1166
        self.relPosition.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1167
        self.relPosition.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1168
    setattr(cls, "setRelPosition", setRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1169
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1170
    def getRelPosition(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1171
        if self.relPosition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1172
            return self.relPosition.getX(), self.relPosition.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1173
        return self.relPosition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1174
    setattr(cls, "getRelPosition", getRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1175
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1176
if "value" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1177
    cls = PLCOpenClasses["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1178
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1179
    def setValue(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1180
        try:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1181
            value = eval(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1182
        except:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1183
            pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1184
        if type(value) == ListType:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1185
            arrayValue = PLCOpenClasses["value_arrayValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1186
            arrayValue.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1187
            self.content = {"name":"arrayValue","value":arrayValue}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1188
        elif type(value) == DictType:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1189
            structValue = PLCOpenClasses["value_structValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1190
            structValue.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1191
            self.content = {"name":"structValue","value":structValue}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1192
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1193
            simpleValue = PLCOpenClasses["value_simpleValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1194
            simpleValue.setValue(str(value))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1195
            self.content = {"name":"simpleValue","value":simpleValue}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1196
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1197
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1198
    def getValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1199
        value = self.content["value"].getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1200
        try:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1201
            value = eval(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1202
        except:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1203
            pass
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1204
        return value
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1205
    setattr(cls, "getValue", getValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1206
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1207
if "value_arrayValue" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1208
    cls = PLCOpenClasses["value_arrayValue"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1209
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1210
    def setValue(self, array):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1211
        self.value = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1212
        for value in array:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1213
            element = PLCOpenClasses["arrayValue_value"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1214
            element.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1215
            self.value.append(element)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1216
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1217
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1218
    def getValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1219
        return [element.getValue() for element in self.value]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1220
    setattr(cls, "getValue", getValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1221
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1222
if "value_structValue" in PLCOpenClasses:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1223
    cls = PLCOpenClasses["value_structValue"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1224
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1225
    def setValue(self, dict):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1226
        self.value = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1227
        for name,value in dict.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1228
            element = PLCOpenClasses["structValue_value"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1229
            element.setMember(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1230
            element.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1231
            self.value.append(element)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1232
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1233
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1234
    def getValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1235
        value = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1236
        for element in self.value:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1237
            value[element.getMember()] = element.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1238
        return value
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1239
    setattr(cls, "getValue", getValue)