plcopen/plcopen.py
author greg
Tue, 15 Jan 2008 10:51:18 +0100
changeset 148 a083d4a94bd3
parent 147 5ef987c1b927
child 151 aaa80b48bead
permissions -rw-r--r--
add setup.py and plcopeneditor_postinst.py to build windows installer
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("formattedText", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    50
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    51
    cls.text = ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    52
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    53
    def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    54
        return self.text
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    55
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    56
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    57
    def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    58
        self.text = text
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    59
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    60
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    61
    def loadXMLTree(self, tree):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    62
        self.text = GetAttributeValue(tree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    63
        if len(self.text.splitlines()) > 1:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    64
            self.text = self.text[1:].rstrip()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    65
    setattr(cls, "loadXMLTree", loadXMLTree)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    66
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    67
    def generateXMLText(self, name, indent, extras = {}):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    68
        ind1, ind2 = getIndent(indent, name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    69
        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
    70
            text = ind1 + "<%s>\n<![CDATA[\n"%name
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    71
            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
    72
            text += "]]>\n" + ind1 + "</%s>\n"%name
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    73
            return text
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    74
        else:
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    75
            return ind1 + "<%s><![CDATA[%s]]></%s>\n"%(name, self.text, name)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    76
    setattr(cls, "generateXMLText", generateXMLText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    77
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    78
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    79
        index = self.text.find(old_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    80
        while index != -1:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    81
            if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    82
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    83
            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
    84
                index = self.text.find(old_name, index + len(old_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    85
            else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    86
                self.text = self.text[:index] + new_name + self.text[index + len(old_name):]
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    87
                index = self.text.find(old_name, index + len(new_name))
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    88
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
    89
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
    90
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
    91
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    92
    cls.singleLineAttributes = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
    93
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    94
    def setName(self, name):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    95
        self.contentHeader.setName(name)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    96
    setattr(cls, "setName", setName)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    97
        
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    98
    def getName(self):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
    99
        return self.contentHeader.getName()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   100
    setattr(cls, "getName", getName)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   101
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   102
    def getFileHeader(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   103
        fileheader = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   104
        fileheader["companyName"] = self.fileHeader.getCompanyName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   105
        if self.fileHeader.getCompanyURL():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   106
            fileheader["companyURL"] = self.fileHeader.getCompanyURL()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   107
        fileheader["productName"] = self.fileHeader.getProductName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   108
        fileheader["productVersion"] = self.fileHeader.getProductVersion()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   109
        if self.fileHeader.getProductRelease():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   110
            fileheader["productRelease"] = self.fileHeader.getProductRelease()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   111
        fileheader["creationDateTime"] = self.fileHeader.getCreationDateTime()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   112
        if self.fileHeader.getContentDescription():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   113
            fileheader["contentDescription"] = self.fileHeader.getContentDescription()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   114
        return fileheader
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   115
    setattr(cls, "getFileHeader", getFileHeader)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   116
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   117
    def setFileHeader(self, fileheader):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   118
        self.fileHeader.setCompanyName(fileheader["companyName"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   119
        if "companyURL" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   120
            self.fileHeader.setCompanyURL(fileheader["companyURL"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   121
        self.fileHeader.setProductName(fileheader["productName"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   122
        self.fileHeader.setProductVersion(fileheader["productVersion"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   123
        if "productRelease" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   124
            self.fileHeader.setProductRelease(fileheader["productRelease"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   125
        self.fileHeader.setCreationDateTime(fileheader["creationDateTime"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   126
        if "contentDescription" in fileheader:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   127
            self.fileHeader.setContentDescription(fileheader["contentDescription"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   128
    setattr(cls, "setFileHeader", setFileHeader)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   129
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   130
    def getContentHeader(self):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   131
        contentheader = {}
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   132
        contentheader["projectName"] = self.contentHeader.getName()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   133
        if self.contentHeader.getVersion():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   134
            contentheader["projectVersion"] = self.contentHeader.getVersion()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   135
        if self.contentHeader.getModificationDateTime():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   136
            contentheader["modificationDateTime"] = self.contentHeader.getModificationDateTime()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   137
        if self.contentHeader.getOrganization():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   138
            contentheader["organization"] = self.contentHeader.getOrganization()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   139
        if self.contentHeader.getAuthor():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   140
            contentheader["authorName"] = self.contentHeader.getAuthor()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   141
        if self.contentHeader.getLanguage():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   142
            contentheader["language"] = self.contentHeader.getLanguage()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   143
        contentheader["pageSize"] = self.contentHeader.getPageSize()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   144
        contentheader["scaling"] = self.contentHeader.getScaling()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   145
        return contentheader
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   146
    setattr(cls, "getContentHeader", getContentHeader)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   147
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   148
    def setContentHeader(self, contentheader):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   149
        self.contentHeader.setName(contentheader["projectName"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   150
        if "projectVersion" in contentheader:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   151
            self.contentHeader.setVersion(contentheader["projectVersion"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   152
        if "modificationDateTime" in contentheader:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   153
            self.contentHeader.setModificationDateTime(contentheader["modificationDateTime"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   154
        if "organization" in contentheader:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   155
            self.contentHeader.setOrganization(contentheader["organization"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   156
        if "authorName" in contentheader:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   157
            self.contentHeader.setAuthor(contentheader["authorName"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   158
        if "language" in contentheader:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   159
            self.contentHeader.setLanguage(contentheader["language"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   160
        self.contentHeader.setPageSize(*contentheader["pageSize"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   161
        self.contentHeader.setScaling(contentheader["scaling"])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   162
    setattr(cls, "setContentHeader", setContentHeader)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   163
    
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   164
    def getDataTypes(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   165
        return self.types.getDataTypeElements()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   166
    setattr(cls, "getDataTypes", getDataTypes)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   167
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   168
    def getDataType(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   169
        return self.types.getDataTypeElement(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   170
    setattr(cls, "getDataType", getDataType)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   171
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   172
    def appendDataType(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   173
        self.types.appendDataTypeElement(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   174
    setattr(cls, "appendDataType", appendDataType)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   175
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   176
    def insertDataType(self, index, datatype):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   177
        self.types.insertDataTypeElement(index, datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   178
    setattr(cls, "insertDataType", insertDataType)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   179
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   180
    def removeDataType(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   181
        self.types.removeDataTypeElement(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   182
    setattr(cls, "removeDataType", removeDataType)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   183
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   184
    def getPous(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   185
        return self.types.getPouElements()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   186
    setattr(cls, "getPous", getPous)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   187
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   188
    def getPou(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   189
        return self.types.getPouElement(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   190
    setattr(cls, "getPou", getPou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   191
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   192
    def appendPou(self, name, pou_type, body_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   193
        self.types.appendPouElement(name, pou_type, body_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   194
    setattr(cls, "appendPou", appendPou)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   195
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   196
    def insertPou(self, index, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   197
        self.types.insertPouElement(index, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   198
    setattr(cls, "insertPou", insertPou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   199
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   200
    def removePou(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   201
        self.types.removePouElement(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   202
    setattr(cls, "removePou", removePou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   203
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   204
    def getConfigurations(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   205
        configurations = self.instances.configurations.getConfiguration()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   206
        if configurations:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   207
            return configurations
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   208
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   209
    setattr(cls, "getConfigurations", getConfigurations)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   210
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   211
    def getConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   212
        for configuration in self.instances.configurations.getConfiguration():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   213
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   214
                return configuration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   215
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   216
    setattr(cls, "getConfiguration", getConfiguration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   217
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   218
    def addConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   219
        for configuration in self.instances.configurations.getConfiguration():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   220
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   221
                raise ValueError, "\"%s\" configuration already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   222
        new_configuration = PLCOpenClasses["configurations_configuration"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   223
        new_configuration.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   224
        self.instances.configurations.appendConfiguration(new_configuration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   225
    setattr(cls, "addConfiguration", addConfiguration)    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   226
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   227
    def removeConfiguration(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   228
        found = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   229
        for idx, configuration in enumerate(self.instances.configurations.getConfiguration()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   230
            if configuration.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   231
                self.instances.configurations.removeConfiguration(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   232
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   233
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   234
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   235
            raise ValueError, "\"%s\" configuration doesn't exist !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   236
    setattr(cls, "removeConfiguration", removeConfiguration)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   237
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   238
    def getConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   239
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   240
        if configuration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   241
            for resource in configuration.getResource():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   242
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   243
                    return resource
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   244
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   245
    setattr(cls, "getConfigurationResource", getConfigurationResource)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   246
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   247
    def addConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   248
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   249
        if configuration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   250
            for resource in configuration.getResource():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   251
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   252
                    raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   253
            new_resource = PLCOpenClasses["configuration_resource"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   254
            new_resource.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   255
            configuration.appendResource(new_resource)
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   256
    setattr(cls, "addConfigurationResource", addConfigurationResource)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   257
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   258
    def removeConfigurationResource(self, config_name, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   259
        configuration = self.getConfiguration(config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   260
        if configuration:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   261
            found = False
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   262
            for idx, resource in enumerate(configuration.getResource()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   263
                if resource.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   264
                    configuration.removeResource(idx)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   265
                    found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   266
                    break
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   267
            if not found:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   268
                raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   269
    setattr(cls, "removeConfigurationResource", removeConfigurationResource)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   270
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 pou in self.types.getPouElements():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   273
            pou.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   274
        for configuration in self.instances.configurations.getConfiguration():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   275
            configuration.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("project_fileHeader", None)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   279
if cls:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   280
    cls.singleLineAttributes = False
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   281
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   282
cls = PLCOpenClasses.get("project_contentHeader", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   283
if cls:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   284
    cls.singleLineAttributes = False
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   285
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   286
    def setPageSize(self, width, height):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   287
        self.coordinateInfo.setPageSize(width, height)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   288
    setattr(cls, "setPageSize", setPageSize)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   289
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   290
    def getPageSize(self):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   291
        return self.coordinateInfo.getPageSize()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   292
    setattr(cls, "getPageSize", getPageSize)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   293
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   294
    def setScaling(self, scaling):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   295
        for language, (x, y) in scaling.items():
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   296
            self.coordinateInfo.setScaling(language, x, y)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   297
    setattr(cls, "setScaling", setScaling)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   298
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   299
    def getScaling(self):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   300
        scaling = {}
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   301
        scaling["FBD"] = self.coordinateInfo.getScaling("FBD")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   302
        scaling["LD"] = self.coordinateInfo.getScaling("LD")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   303
        scaling["SFC"] = self.coordinateInfo.getScaling("SFC")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   304
        return scaling
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   305
    setattr(cls, "getScaling", getScaling)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   306
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   307
cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   308
if cls:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   309
    def setPageSize(self, width, height):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   310
        if width == 0 and height == 0:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   311
            self.deletePageSize()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   312
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   313
            if self.pageSize is None:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   314
                self.addPageSize()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   315
            self.pageSize.setX(width)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   316
            self.pageSize.setY(height)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   317
    setattr(cls, "setPageSize", setPageSize)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   318
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   319
    def getPageSize(self):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   320
        if self.pageSize is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   321
            return self.pageSize.getX(), self.pageSize.getY()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   322
        return 0, 0
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   323
    setattr(cls, "getPageSize", getPageSize)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   324
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   325
    def setScaling(self, language, x, y):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   326
        if language == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   327
            self.fbd.scaling.setX(x)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   328
            self.fbd.scaling.setY(y)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   329
        elif language == "LD":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   330
            self.ld.scaling.setX(x)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   331
            self.ld.scaling.setY(y)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   332
        elif language == "SFC":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   333
            self.sfc.scaling.setX(x)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   334
            self.sfc.scaling.setY(y)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   335
    setattr(cls, "setScaling", setScaling)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   336
    
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   337
    def getScaling(self, language):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   338
        if language == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   339
            return self.fbd.scaling.getX(), self.fbd.scaling.getY()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   340
        elif language == "LD":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   341
            return self.ld.scaling.getX(), self.ld.scaling.getY()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   342
        elif language == "SFC":
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   343
            return self.sfc.scaling.getX(), self.sfc.scaling.getY()
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   344
        return 0, 0
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   345
    setattr(cls, "getScaling", getScaling)
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
   346
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   347
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
   348
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   349
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   350
        for resource in self.getResource():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   351
            resource.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   352
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   353
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   354
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   355
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
   356
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   357
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   358
        for instance in self.getPouInstance():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   359
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   360
        for task in self.getTask():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   361
            task.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   362
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   363
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   364
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
   365
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   366
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   367
        if self.single == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   368
            self.single = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   369
        for instance in self.getPouInstance():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   370
            instance.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   371
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   372
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   373
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
   374
if cls:
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   375
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   376
        if self.type == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   377
            self.type = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   378
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   379
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   380
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
   381
if cls:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   382
    def getDataTypeElements(self):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   383
        return self.dataTypes.getDataType()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   384
    setattr(cls, "getDataTypeElements", getDataTypeElements)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   385
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   386
    def getDataTypeElement(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   387
        elements = self.dataTypes.getDataType()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   388
        for element in elements:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   389
            if element.getName() == name:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   390
                return element
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   391
        return None
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   392
    setattr(cls, "getDataTypeElement", getDataTypeElement)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   393
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   394
    def appendDataTypeElement(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   395
        for element in self.dataTypes.getDataType():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   396
            if element.getName() == name:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   397
                raise ValueError, "\"%s\" Data Type already exists !!!"%name
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   398
        new_datatype = PLCOpenClasses["dataTypes_dataType"]()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   399
        new_datatype.setName(name)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   400
        new_datatype.baseType.setContent("BOOL", None)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   401
        self.dataTypes.appendDataType(new_datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   402
    setattr(cls, "appendDataTypeElement", appendDataTypeElement)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   403
        
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   404
    def insertDataTypeElement(self, index, datatype):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   405
        self.dataTypes.insertDataType(index, datatype)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   406
    setattr(cls, "insertDataTypeElement", insertDataTypeElement)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   407
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   408
    def removeDataTypeElement(self, name):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   409
        found = False
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   410
        for idx, element in enumerate(self.dataTypes.getDataType()):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   411
            if element.getName() == name:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   412
                self.dataTypes.removeDataType(idx)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   413
                found = True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   414
                break
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   415
        if not found:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   416
            raise ValueError, "\"%s\" Data Type doesn't exist !!!"%name
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   417
    setattr(cls, "removeDataTypeElement", removeDataTypeElement)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   418
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   419
    def getPouElements(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   420
        return self.pous.getPou()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   421
    setattr(cls, "getPouElements", getPouElements)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   422
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   423
    def getPouElement(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   424
        elements = self.pous.getPou()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   425
        for element in elements:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   426
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   427
                return element
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   428
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   429
    setattr(cls, "getPouElement", getPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   430
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   431
    def appendPouElement(self, name, pou_type, body_type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   432
        for element in self.pous.getPou():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   433
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   434
                raise ValueError, "\"%s\" POU already exists !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   435
        new_pou = PLCOpenClasses["pous_pou"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   436
        new_pou.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   437
        new_pou.pouType.setValue(pou_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   438
        new_pou.setBody(PLCOpenClasses["body"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   439
        new_pou.setBodyType(body_type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   440
        self.pous.appendPou(new_pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   441
    setattr(cls, "appendPouElement", appendPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   442
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   443
    def insertPouElement(self, index, pou):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   444
        self.pous.insertPou(index, pou)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   445
    setattr(cls, "insertPouElement", insertPouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   446
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   447
    def removePouElement(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   448
        found = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   449
        for idx, element in enumerate(self.pous.getPou()):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   450
            if element.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   451
                self.pous.removePou(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   452
                found = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   453
                break
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   454
        if not found:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   455
            raise ValueError, "\"%s\" POU doesn't exist !!!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   456
    setattr(cls, "removePouElement", removePouElement)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   457
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   458
def setBodyType(self, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   459
    if type == "IL":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   460
        self.body.setContent("IL", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   461
    elif type == "ST":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   462
        self.body.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   463
    elif type == "LD":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   464
        self.body.setContent("LD", PLCOpenClasses["body_LD"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   465
    elif type == "FBD":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   466
        self.body.setContent("FBD", PLCOpenClasses["body_FBD"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   467
    elif type == "SFC":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   468
        self.body.setContent("SFC", PLCOpenClasses["body_SFC"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   469
    else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   470
        raise ValueError, "%s isn't a valid body type!"%type
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   471
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   472
def getBodyType(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   473
    return self.body.getContent()["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   474
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   475
def resetExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   476
    self.body.resetExecutionOrder()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   477
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   478
def compileExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   479
    self.body.compileExecutionOrder()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   480
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   481
def setElementExecutionOrder(self, instance, new_executionOrder):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   482
    self.body.setElementExecutionOrder(instance, new_executionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   483
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   484
def addInstance(self, name, instance):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   485
    self.body.appendContentInstance(name, instance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   486
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   487
def getInstances(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   488
    return self.body.getContentInstances()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   489
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   490
def getInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   491
    return self.body.getContentInstance(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   492
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   493
def getRandomInstance(self, exclude):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   494
    return self.body.getContentRandomInstance(exclude)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   495
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   496
def getInstanceByName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   497
    return self.body.getContentInstanceByName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   498
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   499
def removeInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   500
    self.body.removeContentInstance(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   501
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   502
def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   503
    self.body.setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   504
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   505
def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   506
    return self.body.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   507
setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   508
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   509
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
   510
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   511
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   512
    setattr(cls, "getBodyType", getBodyType)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   513
    setattr(cls, "resetExecutionOrder", resetExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   514
    setattr(cls, "compileExecutionOrder", compileExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   515
    setattr(cls, "setElementExecutionOrder", setElementExecutionOrder)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   516
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   517
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   518
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   519
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   520
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   521
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   522
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   523
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   524
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   525
    def getVars(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   526
        vars = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   527
        reverse_types = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   528
        for name, value in VarTypes.items():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   529
            reverse_types[value] = name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   530
        for varlist in self.interface.getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   531
            vars.append((reverse_types[varlist["name"]], varlist["value"]))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   532
        return vars
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   533
    setattr(cls, "getVars", getVars)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   534
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   535
    def setVars(self, vars):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   536
        self.interface.setContent([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   537
        for vartype, varlist in vars:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   538
            self.interface.appendContent(VarTypes[vartype], varlist)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   539
    setattr(cls, "setVars", setVars)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   540
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   541
    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
   542
        content = self.interface.getContent()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   543
        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
   544
            content.append({"name" : "localVars", "value" : PLCOpenClasses["varList"]()})
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   545
        else:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   546
            varlist = content[-1]["value"]
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   547
            variables = varlist.getVariable()
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   548
            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
   549
                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
   550
        var = PLCOpenClasses["varListPlain_variable"]()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   551
        var.setName(name)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   552
        var_type = PLCOpenClasses["dataType"]()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   553
        derived_type = PLCOpenClasses["derived"]()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   554
        derived_type.setName(type)
143
015a34da60eb Bug on FunctionBlock type variables management fixed
lbessard
parents: 141
diff changeset
   555
        var_type.setContent("derived", derived_type)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   556
        var.setType(var_type)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   557
        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
   558
    setattr(cls, "addPouVar", addPouVar)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   559
    
94
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   560
    def changePouVar(self, old_type, old_name, new_type, new_name):
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   561
        content = self.interface.getContent()
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   562
        for varlist in content:
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   563
            variables = varlist["value"].getVariable()
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   564
            for var in variables:
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   565
                if var.getName() == old_name:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   566
                    vartype_content = var.getType().getContent()
141
c0242a51774c Bug with String not recognized fixed
lbessard
parents: 125
diff changeset
   567
                    if vartype_content["name"] == "derived" and vartype_content["value"].getName() == old_type:
94
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   568
                        var.setName(new_name)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
   569
                        vartype_content["value"].setName(new_type)
94
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   570
                        return
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   571
    setattr(cls, "changePouVar", changePouVar)
e7f5a251f251 Bug on block modification fixed
lbessard
parents: 89
diff changeset
   572
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   573
    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
   574
        content = self.interface.getContent()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   575
        for varlist in content:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   576
            variables = varlist["value"].getVariable()
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   577
            for var in variables:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   578
                if var.getName() == name:
143
015a34da60eb Bug on FunctionBlock type variables management fixed
lbessard
parents: 141
diff changeset
   579
                    vartype_content = var.getType().getContent()
015a34da60eb Bug on FunctionBlock type variables management fixed
lbessard
parents: 141
diff changeset
   580
                    if vartype_content["name"] == "derived" and vartype_content["value"].getName() == type:
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   581
                        variables.remove(var)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   582
                        break
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   583
            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
   584
                content.remove(varlist)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   585
                break
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   586
    setattr(cls, "removePouVar", removePouVar)
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   587
    
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   588
    def hasBlock(self, name):
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   589
        if self.getBodyType() in ["FBD", "LD", "SFC"]:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   590
            for instance in self.getInstances():
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   591
                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
   592
                    return True
89
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   593
            if self.transitions:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   594
                for transition in self.transitions.getTransition():
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   595
                    result = transition.hasBlock(name)
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   596
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   597
                        return result
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   598
            if self.actions:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   599
                for action in self.actions.getAction():
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   600
                    result = action.hasBlock(name)
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   601
                    if result:
a6ff2b3fcc25 Bug on block deletion fixed
lbessard
parents: 77
diff changeset
   602
                        return result
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   603
        return False
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   604
    setattr(cls, "hasBlock", hasBlock)
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   605
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   606
    def addTransition(self, name, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   607
        if not self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   608
            self.addTransitions()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   609
            self.transitions.setTransition([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   610
        transition = PLCOpenClasses["transitions_transition"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   611
        transition.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   612
        transition.setBodyType(type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   613
        self.transitions.appendTransition(transition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   614
    setattr(cls, "addTransition", addTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   615
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   616
    def getTransition(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   617
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   618
            for transition in self.transitions.getTransition():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   619
                if transition.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   620
                    return transition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   621
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   622
    setattr(cls, "getTransition", getTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   623
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   624
    def getTransitionList(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   625
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   626
            return self.transitions.getTransition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   627
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   628
    setattr(cls, "getTransitionList", getTransitionList)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   629
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   630
    def removeTransition(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   631
        if self.transitions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   632
            transitions = self.transitions.getTransition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   633
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   634
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   635
            while i < len(transitions) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   636
                if transitions[i].getName() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   637
                    transitions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   638
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   639
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   640
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   641
                raise ValueError, "Transition with name %s doesn't exists!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   642
    setattr(cls, "removeTransition", removeTransition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   643
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   644
    def addAction(self, name, type):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   645
        if not self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   646
            self.addActions()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   647
            self.actions.setAction([])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   648
        action = PLCOpenClasses["actions_action"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   649
        action.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   650
        action.setBodyType(type)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   651
        self.actions.appendAction(action)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   652
    setattr(cls, "addAction", addAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   653
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   654
    def getAction(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   655
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   656
            for action in self.actions.getAction():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   657
                if action.getName() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   658
                    return action
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   659
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   660
    setattr(cls, "getAction", getAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   661
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   662
    def getActionList(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   663
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   664
            return self.actions.getAction()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   665
        return []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   666
    setattr(cls, "getActionList", getActionList)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   667
        
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   668
    def removeAction(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   669
        if self.actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   670
            actions = self.actions.getAction()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   671
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   672
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   673
            while i < len(actions) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   674
                if actions[i].getName() == name:
46
4379e98a30aa Bug on SFC generation fixed
lbessard
parents: 27
diff changeset
   675
                    actions.pop(i)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   676
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   677
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   678
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   679
                raise ValueError, "Action with name %s doesn't exists!"%name
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   680
    setattr(cls, "removeAction", removeAction)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   681
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   682
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   683
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   684
        for action in self.getActionList():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   685
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   686
        for transition in self.getTransitionList():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   687
            transition.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   688
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   689
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   690
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
   691
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   692
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   693
    setattr(cls, "getBodyType", getBodyType)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   694
    setattr(cls, "resetExecutionOrder", resetExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   695
    setattr(cls, "compileExecutionOrder", compileExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   696
    setattr(cls, "setElementExecutionOrder", setElementExecutionOrder)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   697
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   698
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   699
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   700
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   701
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   702
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   703
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   704
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   705
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   706
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   707
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   708
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   709
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   710
    def hasBlock(self, name):
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   711
        if self.getBodyType() in ["FBD", "LD", "SFC"]:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   712
            for instance in self.getInstances():
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   713
                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
   714
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   715
        return False
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   716
    setattr(cls, "hasBlock", hasBlock)
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   717
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   718
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
   719
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   720
    setattr(cls, "setBodyType", setBodyType)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   721
    setattr(cls, "getBodyType", getBodyType)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   722
    setattr(cls, "resetExecutionOrder", resetExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   723
    setattr(cls, "compileExecutionOrder", compileExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   724
    setattr(cls, "setElementExecutionOrder", setElementExecutionOrder)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   725
    setattr(cls, "addInstance", addInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   726
    setattr(cls, "getInstances", getInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   727
    setattr(cls, "getInstance", getInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   728
    setattr(cls, "getRandomInstance", getRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   729
    setattr(cls, "getInstanceByName", getInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   730
    setattr(cls, "removeInstance", removeInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   731
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   732
    setattr(cls, "getText", getText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   733
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   734
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   735
        self.body.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   736
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   737
68
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   738
    def hasBlock(self, name):
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   739
        if self.getBodyType() in ["FBD", "LD", "SFC"]:
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   740
            for instance in self.getInstances():
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   741
                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
   742
                    return True
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   743
        return False
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   744
    setattr(cls, "hasBlock", hasBlock)
66308e07402c Adding support for allowing declarations of function block into POU interface
lbessard
parents: 67
diff changeset
   745
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   746
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
   747
if cls:
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   748
    cls.currentExecutionOrderId = 0
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   749
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   750
    def resetCurrentExecutionOrderId(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   751
        self.currentExecutionOrderId = 0
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   752
    setattr(cls, "resetCurrentExecutionOrderId", resetCurrentExecutionOrderId)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   753
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   754
    def getNewExecutionOrderId(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   755
        self.currentExecutionOrderId += 1
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   756
        return self.currentExecutionOrderId
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   757
    setattr(cls, "getNewExecutionOrderId", getNewExecutionOrderId)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   758
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   759
    def resetExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   760
        if self.content["name"] == "FBD":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   761
            for element in self.content["value"].getContent():
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   762
                if not isinstance(element["value"], (PLCOpenClasses.get("comment", None), PLCOpenClasses.get("connector", None), PLCOpenClasses.get("continuation", None))):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   763
                    element["value"].setExecutionOrderId(0)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   764
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   765
            raise TypeError, "Can only generate execution order on FBD networks!"
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   766
    setattr(cls, "resetExecutionOrder", resetExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   767
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   768
    def compileExecutionOrder(self):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   769
        if self.content["name"] == "FBD":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   770
            self.resetExecutionOrder()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   771
            self.resetCurrentExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   772
            for element in self.content["value"].getContent():
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   773
                if isinstance(element["value"], PLCOpenClasses.get("outVariable", None)) and element["value"].getExecutionOrderId() == 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   774
                    connections = element["value"].connectionPointIn.getConnections()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   775
                    if connections and len(connections) == 1:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   776
                        self.compileElementExecutionOrder(connections[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   777
                    element["value"].setExecutionOrderId(self.getNewExecutionOrderId())
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   778
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   779
            raise TypeError, "Can only generate execution order on FBD networks!"
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   780
    setattr(cls, "compileExecutionOrder", compileExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   781
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   782
    def compileElementExecutionOrder(self, link):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   783
        if self.content["name"] == "FBD":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   784
            localid = link.getRefLocalId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   785
            instance = self.getContentInstance(localid)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   786
            if isinstance(instance, PLCOpenClasses.get("block", None)) and instance.getExecutionOrderId() == 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   787
                for variable in instance.inputVariables.getVariable():
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   788
                    connections = variable.connectionPointIn.getConnections()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   789
                    if connections and len(connections) == 1:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   790
                        self.compileElementExecutionOrder(connections[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   791
                instance.setExecutionOrderId(self.getNewExecutionOrderId())
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   792
            elif isinstance(instance, PLCOpenClasses.get("continuation", None)) and instance.getExecutionOrderId() == 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   793
                name = instance.getName()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   794
                for tmp_instance in self.getContentInstances():
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   795
                    if isinstance(tmp_instance, PLCOpenClasses.get("connector", None)) and tmp_instance.getName() == name and tmp_instance.getExecutionOrderId() == 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   796
                        connections = tmp_instance.connectionPointIn.getConnections()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   797
                        if connections and len(connections) == 1:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   798
                            self.compileElementExecutionOrder(connections[0])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   799
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   800
            raise TypeError, "Can only generate execution order on FBD networks!"
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   801
    setattr(cls, "compileElementExecutionOrder", compileElementExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   802
    
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   803
    def setElementExecutionOrder(self, instance, new_executionOrder):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   804
        if self.content["name"] == "FBD":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   805
            old_executionOrder = instance.getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   806
            if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   807
                for element in self.content["value"].getContent():
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   808
                    if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("comment", None)):
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   809
                        element_executionOrder = element["value"].getExecutionOrderId()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   810
                        if old_executionOrder <= element_executionOrder <= new_executionOrder:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   811
                            element["value"].setExecutionOrderId(element_executionOrder - 1)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   812
                        if new_executionOrder <= element_executionOrder <= old_executionOrder:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   813
                            element["value"].setExecutionOrderId(element_executionOrder + 1)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   814
            instance.setExecutionOrderId(new_executionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   815
        else:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   816
            raise TypeError, "Can only generate execution order on FBD networks!"
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   817
    setattr(cls, "setElementExecutionOrder", setElementExecutionOrder)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 108
diff changeset
   818
    
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   819
    def appendContentInstance(self, name, instance):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   820
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   821
            self.content["value"].appendContent(name, instance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   822
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   823
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   824
    setattr(cls, "appendContentInstance", appendContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   825
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   826
    def getContentInstances(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   827
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   828
            instances = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   829
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   830
                instances.append(element["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   831
            return instances
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   832
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   833
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   834
    setattr(cls, "getContentInstances", getContentInstances)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   835
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   836
    def getContentInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   837
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   838
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   839
                if element["value"].getLocalId() == id:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   840
                    return element["value"]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   841
            return None
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   842
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   843
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   844
    setattr(cls, "getContentInstance", getContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   845
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   846
    def getContentRandomInstance(self, exclude):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   847
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   848
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   849
                if element["value"].getLocalId() not in exclude:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   850
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   851
            return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   852
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   853
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   854
    setattr(cls, "getContentRandomInstance", getContentRandomInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   855
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   856
    def getContentInstanceByName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   857
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   858
            for element in self.content["value"].getContent():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   859
                if element["value"].getLocalId() == name:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   860
                    return element["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   861
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   862
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   863
    setattr(cls, "getContentInstanceByName", getContentInstanceByName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   864
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   865
    def removeContentInstance(self, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   866
        if self.content["name"] in ["LD","FBD","SFC"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   867
            i = 0
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   868
            removed = False
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   869
            elements = self.content["value"].getContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   870
            while i < len(elements) and not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   871
                if elements[i]["value"].getLocalId() == id:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   872
                    self.content["value"].removeContent(i)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   873
                    removed = True
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   874
                i += 1
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   875
            if not removed:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   876
                raise ValueError, "Instance with id %d doesn't exists!"%id
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   877
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   878
            raise TypeError, "%s body don't have instances!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   879
    setattr(cls, "removeContentInstance", removeContentInstance)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   880
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   881
    def setText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   882
        if self.content["name"] in ["IL","ST"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   883
            self.content["value"].setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   884
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   885
            raise TypeError, "%s body don't have text!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   886
    setattr(cls, "setText", setText)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   887
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   888
    def getText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   889
        if self.content["name"] in ["IL","ST"]:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   890
            return self.content["value"].getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   891
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   892
            raise TypeError, "%s body don't have text!"%self.content["name"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   893
    setattr(cls, "getText", getText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   894
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   895
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   896
        if self.content["name"] in ["IL", "ST"]:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   897
            self.content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   898
        else:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   899
            for element in self.content["value"].getContent():
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   900
                element["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   901
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   902
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   903
def getX(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   904
    return self.position.getX()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   905
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   906
def getY(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   907
    return self.position.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   908
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   909
def setX(self, x):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   910
    self.position.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   911
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   912
def setY(self, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   913
    self.position.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   914
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   915
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
   916
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   917
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   918
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   919
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   920
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   921
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   922
    def setContentText(self, text):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   923
        self.content.setText(text)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   924
    setattr(cls, "setContentText", setContentText)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   925
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   926
    def getContentText(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   927
        return self.content.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   928
    setattr(cls, "getContentText", getContentText)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   929
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   930
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   931
        self.content.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   932
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   933
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   934
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
   935
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   936
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   937
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   938
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   939
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   940
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   941
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   942
        if self.typeName == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   943
            self.typeName = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   944
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   945
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   946
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
   947
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   948
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   949
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   950
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   951
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   952
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   953
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   954
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   955
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   956
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   957
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   958
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   959
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   960
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
   961
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   962
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   963
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   964
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   965
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   966
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   967
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   968
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   969
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   970
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   971
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   972
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   973
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   974
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
   975
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   976
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   977
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   978
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   979
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   980
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   981
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   982
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   983
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
   984
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   985
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
   986
if cls:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   987
    setattr(cls, "getX", getX)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   988
    setattr(cls, "getY", getY)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   989
    setattr(cls, "setX", setX)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   990
    setattr(cls, "setY", setY)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   991
    
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   992
    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
   993
        pass
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   994
    setattr(cls, "updateElementName", updateElementName)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   995
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
   996
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
   997
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   998
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
   999
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1000
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1001
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1002
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1003
    def setContactEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1004
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1005
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1006
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1007
    setattr(cls, "setContactEdge", setContactEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1008
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1009
    def getContactEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1010
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1011
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1012
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1013
    setattr(cls, "getContactEdge", getContactEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1014
58
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
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1017
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1018
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1019
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1020
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
  1021
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1022
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1023
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1024
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1025
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1026
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1027
    def setCoilStorage(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1028
        if not self.storage:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1029
            self.storage = PLCOpenClasses["storageModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1030
        self.storage.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1031
    setattr(cls, "setCoilStorage", setCoilStorage)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1032
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1033
    def getCoilStorage(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1034
        if self.storage:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1035
            return self.storage.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1036
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1037
    setattr(cls, "getCoilStorage", getCoilStorage)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1038
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1039
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1040
        if self.variable == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1041
            self.variable = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1042
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1043
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1044
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
  1045
if cls:
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1046
    setattr(cls, "getX", getX)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1047
    setattr(cls, "getY", getY)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1048
    setattr(cls, "setX", setX)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1049
    setattr(cls, "setY", setY)
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1050
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1051
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1052
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1053
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1054
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1055
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
  1056
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1057
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1058
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1059
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1060
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1061
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1062
    def setConditionContent(self, type, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1063
        if not self.condition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1064
            self.addCondition()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1065
        if type == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1066
            condition = PLCOpenClasses["condition_reference"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1067
            condition.setName(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1068
        elif type == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1069
            condition = PLCOpenClasses["condition_inline"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1070
            condition.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1071
            condition.setText(value)
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1072
        elif type == "connection":
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1073
            condition = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1074
        self.condition.setContent(type, condition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1075
    setattr(cls, "setConditionContent", setConditionContent)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1076
        
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1077
    def getConditionContent(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1078
        if self.condition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1079
            content = self.condition.getContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1080
            values = {"type" : content["name"]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1081
            if values["type"] == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1082
                values["value"] = content["value"].getName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1083
            elif values["type"] == "inline":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1084
                values["value"] = content["value"].getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1085
            return values
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1086
        return ""
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1087
    setattr(cls, "getConditionContent", getConditionContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1088
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1089
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1090
        if self.condition:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1091
            content = self.condition.getContent()
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1092
            if content["name"] == "reference":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1093
                if content["value"].getName() == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1094
                    content["value"].setName(new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1095
            elif content["name"] == "inline":
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1096
                content["value"].updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1097
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1098
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1099
    def addConnection(self):
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1100
        if self.condition:
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1101
            content = self.condition.getContent()
69
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1102
            if content["name"] != "connection":
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1103
                self.condition.setContent("connection", [])
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1104
                content = self.condition.getContent()
8fbff50141f8 Bug on transition connection fixed
lbessard
parents: 68
diff changeset
  1105
            content["value"].append(PLCOpenClasses["connection"]())
63
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1106
    setattr(cls, "addConnection", addConnection)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1107
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1108
    def removeConnection(self, idx):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1109
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1110
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1111
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1112
                content["value"].pop(idx)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1113
        setattr(cls, "removeConnection", removeConnection)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1114
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1115
    def removeConnections(self):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1116
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1117
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1118
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1119
                content["value"] = []
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1120
    setattr(cls, "removeConnections", removeConnections)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1121
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1122
    def getConnections(self):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1123
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1124
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1125
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1126
                return content["value"]
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1127
    setattr(cls, "getConnections", getConnections)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1128
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1129
    def setConnectionId(self, idx, id):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1130
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1131
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1132
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1133
                content["value"][idx].setRefLocalId(id)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1134
    setattr(cls, "setConnectionId", setConnectionId)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1135
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1136
    def getConnectionId(self, idx):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1137
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1138
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1139
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1140
                return content["value"][idx].getRefLocalId()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1141
        return None
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1142
    setattr(cls, "getConnectionId", getConnectionId)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1143
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1144
    def setConnectionPoints(self, idx, points):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1145
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1146
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1147
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1148
                content["value"][idx].setPoints(points)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1149
    setattr(cls, "setConnectionPoints", setConnectionPoints)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1150
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1151
    def getConnectionPoints(self, idx):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1152
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1153
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1154
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1155
                return content["value"][idx].getPoints()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1156
        return None
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1157
    setattr(cls, "getConnectionPoints", getConnectionPoints)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1158
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1159
    def setConnectionParameter(self, idx, parameter):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1160
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1161
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1162
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1163
                content["value"][idx].setFormalParameter(parameter)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1164
    setattr(cls, "setConnectionParameter", setConnectionParameter)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1165
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1166
    def getConnectionParameter(self, idx):
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1167
        if self.condition:
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1168
            content = self.condition.getContent()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1169
            if content["name"] == "connection":
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1170
                return content["value"][idx].getFormalParameter()
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1171
        return None
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1172
    setattr(cls, "getConnectionParameter", getConnectionParameter)
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1173
    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1174
    setattr(cls, "addConnection", addConnection)    
04a02b4b2a57 Adding support for connecting transition to LD rung and FBD network
lbessard
parents: 58
diff changeset
  1175
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1176
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
  1177
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1178
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1179
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1180
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1181
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1182
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1183
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1184
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1185
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1186
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1187
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
  1188
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1189
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1190
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1191
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1192
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1193
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1194
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1195
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1196
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1197
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1198
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
  1199
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1200
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1201
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1202
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1203
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1204
    
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1205
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1206
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1207
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1208
    
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1209
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
  1210
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1211
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1212
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1213
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1214
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1215
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1216
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1217
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1218
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1219
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1220
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
  1221
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1222
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1223
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1224
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1225
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1226
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1227
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1228
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1229
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1230
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1231
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
  1232
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1233
    def setQualifierValue(self, value):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1234
        if self.qualifier:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1235
            self.qualifier.setValue(value)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1236
    setattr(cls, "setQualifierValue", setQualifierValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1237
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1238
    def getQualifierValue(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1239
        if self.qualifier:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1240
            return self.qualifier.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1241
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1242
    setattr(cls, "getQualifierValue", getQualifierValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1243
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1244
    def setReferenceName(self, name):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1245
        if self.reference:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1246
            self.reference.setName(name)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1247
    setattr(cls, "setReferenceName", setReferenceName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1248
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1249
    def getReferenceName(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1250
        if self.reference:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1251
            return self.reference.getName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1252
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1253
    setattr(cls, "getReferenceName", getReferenceName)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1254
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1255
    def setInlineContent(self, content):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1256
        if self.inline:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1257
            self.inline.setContent("ST", PLCOpenClasses["formattedText"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1258
            self.inline.setText(content)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1259
    setattr(cls, "setInlineContent", setInlineContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1260
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1261
    def getInlineContent(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1262
        if self.inline:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1263
            return self.inline.getText()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1264
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1265
    setattr(cls, "getInlineContent", getInlineContent)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1266
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1267
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1268
        if self.reference and self.reference.getName() == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1269
            self.reference.setName(new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1270
        if self.inline:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1271
            self.inline.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1272
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1273
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1274
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
  1275
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1276
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1277
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1278
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1279
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1280
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1281
    def setActions(self, actions):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1282
        self.action = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1283
        for params in actions:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1284
            action = PLCOpenClasses["actionBlock_action"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1285
            action.addQualifier()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1286
            action.setQualifierValue(params["qualifier"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1287
            if params["type"] == "reference":
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1288
                action.addReference()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1289
                action.setReferenceName(params["value"])
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1290
            else:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1291
                action.addInline()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1292
                action.setInlineContent(params["value"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1293
            if "duration" in params:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1294
                action.setDuration(params["duration"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1295
            if "indicator" in params:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1296
                action.setIndicator(params["indicator"])
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1297
            self.action.append(action)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1298
    setattr(cls, "setActions", setActions)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1299
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1300
    def getActions(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1301
        actions = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1302
        for action in self.action:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1303
            params = {}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1304
            params["qualifier"] = action.getQualifierValue()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  1305
            if params["qualifier"] is None:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 94
diff changeset
  1306
                params["qualifier"] = "N"
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1307
            if action.getReference():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1308
                params["type"] = "reference"
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1309
                params["value"] = action.getReferenceName()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1310
            elif action.getInline():
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1311
                params["type"] = "inline"
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1312
                params["value"] = action.getInlineContent()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1313
            duration = action.getDuration()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1314
            if duration:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1315
                params["duration"] = duration
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1316
            indicator = action.getIndicator()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1317
            if indicator:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1318
                params["indicator"] = indicator
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1319
            actions.append(params)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1320
        return actions
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1321
    setattr(cls, "getActions", getActions)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1322
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1323
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1324
        for action in self.action:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1325
            action.updateElementName(old_name, new_name)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1326
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1327
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1328
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
  1329
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1330
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1331
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1332
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1333
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1334
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1335
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1336
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1337
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1338
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1339
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1340
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1341
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1342
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1343
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1344
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1345
    setattr(cls, "getConnectorEdge", getConnectorEdge)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1346
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1347
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1348
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1349
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1350
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1351
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1352
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
  1353
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1354
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1355
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1356
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1357
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1358
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1359
    def setConnectorEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1360
        if not self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1361
            self.edge = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1362
        self.edge.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1363
    setattr(cls, "setConnectorEdge", setConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1364
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1365
    def getConnectorEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1366
        if self.edge:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1367
            return self.edge.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1368
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1369
    setattr(cls, "getConnectorEdge", getConnectorEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1370
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1371
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1372
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1373
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1374
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1375
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1376
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
  1377
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1378
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1379
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1380
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1381
    setattr(cls, "setY", setY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1382
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1383
    def setInputEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1384
        if not self.edgeIn:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1385
            self.edgeIn = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1386
        self.edgeIn.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1387
    setattr(cls, "setInputEdge", setInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1388
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1389
    def getInputEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1390
        if self.edgeIn:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1391
            return self.edgeIn.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1392
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1393
    setattr(cls, "getInputEdge", getInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1394
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1395
    def setOutputEdge(self, edge):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1396
        if not self.edgeOut:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1397
            self.edgeOut = PLCOpenClasses["edgeModifierType"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1398
        self.edgeOut.setValue(edge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1399
    setattr(cls, "setInputEdge", setInputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1400
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1401
    def getOutputEdge(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1402
        if self.edgeOut:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1403
            return self.edgeOut.getValue()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1404
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1405
    setattr(cls, "getOutputEdge", getOutputEdge)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1406
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1407
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1408
        if self.expression == old_name:
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1409
            self.expression = new_name
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1410
    setattr(cls, "updateElementName", updateElementName)
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1411
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1412
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
  1413
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1414
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1415
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1416
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1417
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1418
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1419
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1420
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1421
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1422
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1423
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
  1424
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1425
    setattr(cls, "getX", getX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1426
    setattr(cls, "getY", getY)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1427
    setattr(cls, "setX", setX)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1428
    setattr(cls, "setY", setY)
58
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1429
    
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1430
    def updateElementName(self, old_name, new_name):
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1431
        pass
39cd981ff242 Changing file headers
lbessard
parents: 47
diff changeset
  1432
    setattr(cls, "updateElementName", updateElementName)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1433
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1434
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
  1435
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1436
    def setPoints(self, points):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1437
        self.position = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1438
        for point in points:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1439
            position = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1440
            position.setX(point.x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1441
            position.setY(point.y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1442
            self.position.append(position)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1443
    setattr(cls, "setPoints", setPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1444
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1445
    def getPoints(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1446
        points = []
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1447
        for position in self.position:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1448
            points.append((position.getX(),position.getY()))
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1449
        return points
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1450
    setattr(cls, "getPoints", getPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1451
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1452
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
  1453
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1454
    def setRelPosition(self, x, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1455
        self.relPosition = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1456
        self.relPosition.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1457
        self.relPosition.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1458
    setattr(cls, "setRelPosition", setRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1459
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1460
    def getRelPosition(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1461
        if self.relPosition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1462
            return self.relPosition.getX(), self.relPosition.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1463
        else:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1464
            return self.relPosition
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1465
    setattr(cls, "getRelPosition", getRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1466
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1467
    def addConnection(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1468
        if not self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1469
            self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1470
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1471
            self.content["value"].append(PLCOpenClasses["connection"]())
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1472
    setattr(cls, "addConnection", addConnection)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1473
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1474
    def removeConnection(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1475
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1476
            self.content["value"].pop(idx)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1477
        if len(self.content["value"]) == 0:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1478
            self.content = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1479
    setattr(cls, "removeConnection", removeConnection)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1480
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1481
    def removeConnections(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1482
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1483
            self.content = None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1484
    setattr(cls, "removeConnections", removeConnections)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1485
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1486
    def getConnections(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1487
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1488
            return self.content["value"]
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1489
    setattr(cls, "getConnections", getConnections)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1490
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1491
    def setConnectionId(self, idx, id):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1492
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1493
            self.content["value"][idx].setRefLocalId(id)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1494
    setattr(cls, "setConnectionId", setConnectionId)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1495
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1496
    def getConnectionId(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1497
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1498
            return self.content["value"][idx].getRefLocalId()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1499
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1500
    setattr(cls, "getConnectionId", getConnectionId)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1501
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1502
    def setConnectionPoints(self, idx, points):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1503
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1504
            self.content["value"][idx].setPoints(points)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1505
    setattr(cls, "setConnectionPoints", setConnectionPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1506
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1507
    def getConnectionPoints(self, idx):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1508
        if self.content:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1509
            return self.content["value"][idx].getPoints()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1510
        return None
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1511
    setattr(cls, "getConnectionPoints", getConnectionPoints)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1512
27
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1513
    def setConnectionParameter(self, idx, parameter):
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1514
        if self.content:
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1515
            self.content["value"][idx].setFormalParameter(parameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1516
    setattr(cls, "setConnectionParameter", setConnectionParameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1517
    
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1518
    def getConnectionParameter(self, idx):
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1519
        if self.content:
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1520
            return self.content["value"][idx].getFormalParameter()
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1521
        return None
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1522
    setattr(cls, "getConnectionParameter", getConnectionParameter)
dae55dd9ee14 Current developping version
lbessard
parents: 6
diff changeset
  1523
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1524
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
  1525
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1526
    def setRelPosition(self, x, y):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1527
        self.relPosition = PLCOpenClasses["position"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1528
        self.relPosition.setX(x)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1529
        self.relPosition.setY(y)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1530
    setattr(cls, "setRelPosition", setRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1531
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1532
    def getRelPosition(self):
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1533
        if self.relPosition:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1534
            return self.relPosition.getX(), self.relPosition.getY()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1535
        return self.relPosition
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1536
    setattr(cls, "getRelPosition", getRelPosition)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1537
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1538
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
  1539
if cls:
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1540
    def setValue(self, value):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1541
        if value.startswith("[") and value.endswith("]"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1542
            arrayValue = PLCOpenClasses["value_arrayValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1543
            self.content = {"name":"arrayValue","value":arrayValue}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1544
        elif value.startswith("(") and value.endswith(")"):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1545
            structValue = PLCOpenClasses["value_structValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1546
            self.content = {"name":"structValue","value":structValue}
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1547
        else:
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1548
            simpleValue = PLCOpenClasses["value_simpleValue"]()
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1549
            self.content = {"name":"simpleValue","value":simpleValue}
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1550
        self.content["value"].setValue(value)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1551
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1552
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1553
    def getValue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1554
        return self.content["value"].getValue()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1555
    setattr(cls, "getValue", getValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1556
147
5ef987c1b927 Bug on array initial value parsing fixed
lbessard
parents: 145
diff changeset
  1557
def extractValues(values):
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1558
    items = values.split(",")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1559
    i = 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1560
    while i < len(items):
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1561
        opened = items[i - 1].count("(") + items[i - 1].count("[")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1562
        closed = items[i - 1].count(")") + items[i - 1].count("]")
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1563
        if opened > closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1564
            items[i - 1] = ','.join([items[i - 1], items.pop(i)])
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1565
        elif opened == closed:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1566
            i += 1
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1567
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1568
            raise ValueError, "\"%s\" is an invalid value!"%value
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1569
    return items
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1570
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1571
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
  1572
if cls:
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1573
    arrayValue_model = re.compile("([0-9]*)\((.*)\)$")
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1574
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1575
    def setValue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1576
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1577
        for item in extractValues(value[1:-1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1578
            item = item.strip()
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1579
            element = PLCOpenClasses["arrayValue_value"]()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1580
            result = arrayValue_model.match(item)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1581
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1582
                groups = result.groups()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1583
                element.setRepetitionValue(int(groups[0]))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1584
                element.setValue(groups[1].strip())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1585
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1586
                element.setValue(item)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1587
            self.value.append(element)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1588
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1589
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1590
    def getValue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1591
        values = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1592
        for element in self.value:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1593
            repetition = element.getRepetitionValue()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1594
            if repetition is not None and repetition > 1:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1595
                values.append("%d(%s)"%(repetition, element.getValue()))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1596
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1597
                values.append(element.getValue())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1598
        return "[%s]"%", ".join(values)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1599
    setattr(cls, "getValue", getValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1600
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 63
diff changeset
  1601
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
  1602
if cls:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1603
    structValue_model = re.compile("(.*):=(.*)")
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1604
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1605
    def setValue(self, value):
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1606
        self.value = []
145
4fb225afddf4 Adding scaling
lbessard
parents: 143
diff changeset
  1607
        for item in extractValues(value[1:-1]):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1608
            result = arrayValue_model.match(item)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1609
            if result is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1610
                groups = result.groups()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1611
                element = PLCOpenClasses["structValue_value"]()
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1612
                element.setMember(groups[0].strip())
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1613
                element.setValue(groups[1].strip())
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1614
            self.value.append(element)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1615
    setattr(cls, "setValue", setValue)
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1616
    
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1617
    def getValue(self):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1618
        values = []
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1619
        for element in self.value:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1620
            values.append("%s := %s"%(element.getMember(), element.getValue()))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 118
diff changeset
  1621
        return "(%s)"%", ".join(values)
2
93bc4c2cf376 PLCGenerator finished
lbessard
parents: 1
diff changeset
  1622
    setattr(cls, "getValue", getValue)