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