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