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