etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor etisserant@0: #based on the plcopen standard. etisserant@0: # lbessard@58: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or lbessard@2: #modify it under the terms of the GNU General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@58: #General Public License for more details. etisserant@0: # lbessard@2: #You should have received a copy of the GNU General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: lbessard@2: from xmlclass import * lbessard@67: from types import * lbessard@77: import os etisserant@0: etisserant@0: """ etisserant@0: Dictionary that makes the relation between var names in plcopen and displayed values etisserant@0: """ etisserant@0: VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars", etisserant@0: "Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars", etisserant@0: "Global" : "globalVars", "Access" : "accessVars"} etisserant@0: etisserant@0: """ etisserant@0: Define in which order var types must be displayed etisserant@0: """ etisserant@0: VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"] etisserant@0: etisserant@0: """ etisserant@0: Define which action qualifier must be associated with a duration etisserant@0: """ etisserant@0: QualifierList = {"N" : False, "R" : False, "S" : False, "L" : True, "D" : True, etisserant@0: "P" : False, "P0" : False, "P1" : False, "SD" : True, "DS" : True, "SL" : True} etisserant@0: lbessard@77: PLCOpenClasses, PLCOpenTypes = GenerateClassesFromXSD(os.path.join(os.path.split(__file__)[0], "TC6_XML_V10_B.xsd")) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("formattedText", None) lbessard@67: if cls: lbessard@2: cls.text = "" lbessard@2: lbessard@2: def getText(self): lbessard@2: return self.text lbessard@2: setattr(cls, "getText", getText) lbessard@2: lbessard@2: def setText(self, text): lbessard@2: self.text = text lbessard@2: setattr(cls, "setText", setText) lbessard@2: lbessard@2: def loadXMLTree(self, tree): lbessard@2: self.text = GetAttributeValue(tree) lbessard@2: if len(self.text.splitlines()) > 1: lbessard@2: self.text = self.text[1:].rstrip() lbessard@2: setattr(cls, "loadXMLTree", loadXMLTree) lbessard@2: lbessard@2: def generateXMLText(self, name, indent, extras = {}): lbessard@2: ind1, ind2 = getIndent(indent, name) lbessard@2: if len(self.text.splitlines()) > 1: lbessard@67: text = ind1 + "<%s>\n\n" + ind1 + "\n"%name etisserant@0: return text lbessard@2: else: lbessard@67: return ind1 + "<%s>\n"%(name, self.text, name) lbessard@2: setattr(cls, "generateXMLText", generateXMLText) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: index = self.text.find(old_name) lbessard@58: while index != -1: lbessard@58: if index > 0 and (self.text[index - 1].isalnum() or self.text[index - 1] == "_"): lbessard@58: index = self.text.find(old_name, index + len(old_name)) lbessard@58: elif index < len(self.text) - len(old_name) and (self.text[index + len(old_name)].isalnum() or self.text[index + len(old_name)] == "_"): lbessard@58: index = self.text.find(old_name, index + len(old_name)) lbessard@58: else: lbessard@58: self.text = self.text[:index] + new_name + self.text[index + len(old_name):] lbessard@58: index = self.text.find(old_name, index + len(new_name)) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("project", None) lbessard@67: if cls: lbessard@2: cls.singleLineAttributes = False lbessard@2: lbessard@145: def setName(self, name): lbessard@145: self.contentHeader.setName(name) lbessard@145: setattr(cls, "setName", setName) lbessard@145: lbessard@145: def getName(self): lbessard@145: return self.contentHeader.getName() lbessard@145: setattr(cls, "getName", getName) lbessard@145: lbessard@2: def getFileHeader(self): lbessard@2: fileheader = {} lbessard@2: fileheader["companyName"] = self.fileHeader.getCompanyName() lbessard@2: if self.fileHeader.getCompanyURL(): lbessard@2: fileheader["companyURL"] = self.fileHeader.getCompanyURL() lbessard@2: fileheader["productName"] = self.fileHeader.getProductName() lbessard@2: fileheader["productVersion"] = self.fileHeader.getProductVersion() lbessard@2: if self.fileHeader.getProductRelease(): lbessard@2: fileheader["productRelease"] = self.fileHeader.getProductRelease() lbessard@2: fileheader["creationDateTime"] = self.fileHeader.getCreationDateTime() lbessard@2: if self.fileHeader.getContentDescription(): lbessard@2: fileheader["contentDescription"] = self.fileHeader.getContentDescription() lbessard@2: return fileheader lbessard@2: setattr(cls, "getFileHeader", getFileHeader) lbessard@2: lbessard@2: def setFileHeader(self, fileheader): lbessard@2: self.fileHeader.setCompanyName(fileheader["companyName"]) lbessard@2: if "companyURL" in fileheader: lbessard@2: self.fileHeader.setCompanyURL(fileheader["companyURL"]) lbessard@2: self.fileHeader.setProductName(fileheader["productName"]) lbessard@2: self.fileHeader.setProductVersion(fileheader["productVersion"]) lbessard@2: if "productRelease" in fileheader: lbessard@2: self.fileHeader.setProductRelease(fileheader["productRelease"]) lbessard@2: self.fileHeader.setCreationDateTime(fileheader["creationDateTime"]) lbessard@2: if "contentDescription" in fileheader: lbessard@2: self.fileHeader.setContentDescription(fileheader["contentDescription"]) lbessard@2: setattr(cls, "setFileHeader", setFileHeader) lbessard@2: lbessard@145: def getContentHeader(self): lbessard@145: contentheader = {} lbessard@145: contentheader["projectName"] = self.contentHeader.getName() lbessard@145: if self.contentHeader.getVersion(): lbessard@145: contentheader["projectVersion"] = self.contentHeader.getVersion() lbessard@145: if self.contentHeader.getModificationDateTime(): lbessard@145: contentheader["modificationDateTime"] = self.contentHeader.getModificationDateTime() lbessard@145: if self.contentHeader.getOrganization(): lbessard@145: contentheader["organization"] = self.contentHeader.getOrganization() lbessard@145: if self.contentHeader.getAuthor(): lbessard@145: contentheader["authorName"] = self.contentHeader.getAuthor() lbessard@145: if self.contentHeader.getLanguage(): lbessard@145: contentheader["language"] = self.contentHeader.getLanguage() lbessard@145: contentheader["pageSize"] = self.contentHeader.getPageSize() lbessard@145: contentheader["scaling"] = self.contentHeader.getScaling() lbessard@145: return contentheader lbessard@145: setattr(cls, "getContentHeader", getContentHeader) lbessard@145: lbessard@145: def setContentHeader(self, contentheader): lbessard@145: self.contentHeader.setName(contentheader["projectName"]) lbessard@145: if "projectVersion" in contentheader: lbessard@145: self.contentHeader.setVersion(contentheader["projectVersion"]) lbessard@145: if "modificationDateTime" in contentheader: lbessard@145: self.contentHeader.setModificationDateTime(contentheader["modificationDateTime"]) lbessard@145: if "organization" in contentheader: lbessard@145: self.contentHeader.setOrganization(contentheader["organization"]) lbessard@145: if "authorName" in contentheader: lbessard@145: self.contentHeader.setAuthor(contentheader["authorName"]) lbessard@145: if "language" in contentheader: lbessard@145: self.contentHeader.setLanguage(contentheader["language"]) lbessard@145: self.contentHeader.setPageSize(*contentheader["pageSize"]) lbessard@145: self.contentHeader.setScaling(contentheader["scaling"]) lbessard@145: setattr(cls, "setContentHeader", setContentHeader) lbessard@145: lbessard@125: def getDataTypes(self): lbessard@125: return self.types.getDataTypeElements() lbessard@125: setattr(cls, "getDataTypes", getDataTypes) lbessard@125: lbessard@125: def getDataType(self, name): lbessard@125: return self.types.getDataTypeElement(name) lbessard@125: setattr(cls, "getDataType", getDataType) lbessard@125: lbessard@125: def appendDataType(self, name): lbessard@125: self.types.appendDataTypeElement(name) lbessard@125: setattr(cls, "appendDataType", appendDataType) lbessard@125: lbessard@125: def insertDataType(self, index, datatype): lbessard@125: self.types.insertDataTypeElement(index, datatype) lbessard@125: setattr(cls, "insertDataType", insertDataType) lbessard@125: lbessard@125: def removeDataType(self, name): lbessard@125: self.types.removeDataTypeElement(name) lbessard@125: setattr(cls, "removeDataType", removeDataType) lbessard@2: lbessard@2: def getPous(self): lbessard@2: return self.types.getPouElements() lbessard@2: setattr(cls, "getPous", getPous) lbessard@2: lbessard@2: def getPou(self, name): lbessard@2: return self.types.getPouElement(name) lbessard@2: setattr(cls, "getPou", getPou) lbessard@2: lbessard@2: def appendPou(self, name, pou_type, body_type): lbessard@2: self.types.appendPouElement(name, pou_type, body_type) lbessard@2: setattr(cls, "appendPou", appendPou) etisserant@0: lbessard@2: def insertPou(self, index, pou): lbessard@2: self.types.insertPouElement(index, pou) lbessard@2: setattr(cls, "insertPou", insertPou) lbessard@2: lbessard@2: def removePou(self, name): lbessard@2: self.types.removePouElement(name) lbessard@2: setattr(cls, "removePou", removePou) lbessard@2: lbessard@2: def getConfigurations(self): lbessard@2: configurations = self.instances.configurations.getConfiguration() lbessard@2: if configurations: lbessard@2: return configurations lbessard@2: return [] lbessard@2: setattr(cls, "getConfigurations", getConfigurations) lbessard@2: lbessard@2: def getConfiguration(self, name): lbessard@2: for configuration in self.instances.configurations.getConfiguration(): lbessard@2: if configuration.getName() == name: lbessard@2: return configuration lbessard@2: return None lbessard@2: setattr(cls, "getConfiguration", getConfiguration) lbessard@2: lbessard@2: def addConfiguration(self, name): lbessard@2: for configuration in self.instances.configurations.getConfiguration(): lbessard@2: if configuration.getName() == name: lbessard@2: raise ValueError, "\"%s\" configuration already exists !!!"%name lbessard@2: new_configuration = PLCOpenClasses["configurations_configuration"]() lbessard@2: new_configuration.setName(name) lbessard@2: self.instances.configurations.appendConfiguration(new_configuration) lbessard@2: setattr(cls, "addConfiguration", addConfiguration) lbessard@2: lbessard@2: def removeConfiguration(self, name): lbessard@2: found = False lbessard@2: for idx, configuration in enumerate(self.instances.configurations.getConfiguration()): lbessard@2: if configuration.getName() == name: lbessard@2: self.instances.configurations.removeConfiguration(idx) lbessard@2: found = True lbessard@2: break lbessard@2: if not found: lbessard@2: raise ValueError, "\"%s\" configuration doesn't exist !!!"%name lbessard@2: setattr(cls, "removeConfiguration", removeConfiguration) lbessard@2: lbessard@2: def getConfigurationResource(self, config_name, name): lbessard@2: configuration = self.getConfiguration(config_name) lbessard@2: if configuration: lbessard@2: for resource in configuration.getResource(): lbessard@2: if resource.getName() == name: lbessard@2: return resource lbessard@2: return None lbessard@2: setattr(cls, "getConfigurationResource", getConfigurationResource) lbessard@2: lbessard@2: def addConfigurationResource(self, config_name, name): lbessard@2: configuration = self.getConfiguration(config_name) lbessard@2: if configuration: lbessard@2: for resource in configuration.getResource(): lbessard@2: if resource.getName() == name: lbessard@2: raise ValueError, "\"%s\" resource already exists in \"%s\" configuration !!!"%(name, config_name) lbessard@2: new_resource = PLCOpenClasses["configuration_resource"]() lbessard@2: new_resource.setName(name) lbessard@2: configuration.appendResource(new_resource) lbessard@145: setattr(cls, "addConfigurationResource", addConfigurationResource) lbessard@2: lbessard@2: def removeConfigurationResource(self, config_name, name): lbessard@2: configuration = self.getConfiguration(config_name) lbessard@2: if configuration: etisserant@0: found = False lbessard@2: for idx, resource in enumerate(configuration.getResource()): lbessard@2: if resource.getName() == name: lbessard@2: configuration.removeResource(idx) etisserant@0: found = True etisserant@0: break etisserant@0: if not found: lbessard@2: raise ValueError, "\"%s\" resource doesn't exist in \"%s\" configuration !!!"%(name, config_name) lbessard@2: setattr(cls, "removeConfigurationResource", removeConfigurationResource) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: for pou in self.types.getPouElements(): lbessard@58: pou.updateElementName(old_name, new_name) lbessard@58: for configuration in self.instances.configurations.getConfiguration(): lbessard@58: configuration.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("project_fileHeader", None) lbessard@67: if cls: lbessard@67: cls.singleLineAttributes = False lbessard@67: lbessard@145: cls = PLCOpenClasses.get("project_contentHeader", None) lbessard@145: if cls: lbessard@145: cls.singleLineAttributes = False lbessard@145: lbessard@145: def setPageSize(self, width, height): lbessard@145: self.coordinateInfo.setPageSize(width, height) lbessard@145: setattr(cls, "setPageSize", setPageSize) lbessard@145: lbessard@145: def getPageSize(self): lbessard@145: return self.coordinateInfo.getPageSize() lbessard@145: setattr(cls, "getPageSize", getPageSize) lbessard@145: lbessard@145: def setScaling(self, scaling): lbessard@145: for language, (x, y) in scaling.items(): lbessard@145: self.coordinateInfo.setScaling(language, x, y) lbessard@145: setattr(cls, "setScaling", setScaling) lbessard@145: lbessard@145: def getScaling(self): lbessard@145: scaling = {} lbessard@145: scaling["FBD"] = self.coordinateInfo.getScaling("FBD") lbessard@145: scaling["LD"] = self.coordinateInfo.getScaling("LD") lbessard@145: scaling["SFC"] = self.coordinateInfo.getScaling("SFC") lbessard@145: return scaling lbessard@145: setattr(cls, "getScaling", getScaling) lbessard@145: lbessard@145: cls = PLCOpenClasses.get("contentHeader_coordinateInfo", None) lbessard@145: if cls: lbessard@145: def setPageSize(self, width, height): lbessard@145: if width == 0 and height == 0: lbessard@145: self.deletePageSize() lbessard@145: else: lbessard@145: if self.pageSize is None: lbessard@145: self.addPageSize() lbessard@145: self.pageSize.setX(width) lbessard@145: self.pageSize.setY(height) lbessard@145: setattr(cls, "setPageSize", setPageSize) lbessard@145: lbessard@145: def getPageSize(self): lbessard@145: if self.pageSize is not None: lbessard@145: return self.pageSize.getX(), self.pageSize.getY() lbessard@145: return 0, 0 lbessard@145: setattr(cls, "getPageSize", getPageSize) lbessard@145: lbessard@145: def setScaling(self, language, x, y): lbessard@145: if language == "FBD": lbessard@145: self.fbd.scaling.setX(x) lbessard@145: self.fbd.scaling.setY(y) lbessard@145: elif language == "LD": lbessard@145: self.ld.scaling.setX(x) lbessard@145: self.ld.scaling.setY(y) lbessard@145: elif language == "SFC": lbessard@145: self.sfc.scaling.setX(x) lbessard@145: self.sfc.scaling.setY(y) lbessard@145: setattr(cls, "setScaling", setScaling) lbessard@145: lbessard@145: def getScaling(self, language): lbessard@145: if language == "FBD": lbessard@145: return self.fbd.scaling.getX(), self.fbd.scaling.getY() lbessard@145: elif language == "LD": lbessard@145: return self.ld.scaling.getX(), self.ld.scaling.getY() lbessard@145: elif language == "SFC": lbessard@145: return self.sfc.scaling.getX(), self.sfc.scaling.getY() lbessard@145: return 0, 0 lbessard@145: setattr(cls, "getScaling", getScaling) lbessard@145: lbessard@67: cls = PLCOpenClasses.get("configurations_configuration", None) lbessard@67: if cls: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: for resource in self.getResource(): lbessard@58: resource.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@58: lbessard@67: cls = PLCOpenClasses.get("configuration_resource", None) lbessard@67: if cls: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: for instance in self.getPouInstance(): lbessard@58: instance.updateElementName(old_name, new_name) lbessard@58: for task in self.getTask(): lbessard@58: task.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("resource_task", None) lbessard@67: if cls: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.single == old_name: lbessard@58: self.single = new_name lbessard@58: for instance in self.getPouInstance(): lbessard@58: instance.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("pouInstance", None) lbessard@67: if cls: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.type == old_name: lbessard@58: self.type = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("project_types", None) lbessard@67: if cls: lbessard@125: def getDataTypeElements(self): lbessard@125: return self.dataTypes.getDataType() lbessard@125: setattr(cls, "getDataTypeElements", getDataTypeElements) lbessard@125: lbessard@125: def getDataTypeElement(self, name): lbessard@125: elements = self.dataTypes.getDataType() lbessard@125: for element in elements: lbessard@125: if element.getName() == name: lbessard@125: return element lbessard@125: return None lbessard@125: setattr(cls, "getDataTypeElement", getDataTypeElement) lbessard@125: lbessard@125: def appendDataTypeElement(self, name): lbessard@125: for element in self.dataTypes.getDataType(): lbessard@125: if element.getName() == name: lbessard@125: raise ValueError, "\"%s\" Data Type already exists !!!"%name lbessard@125: new_datatype = PLCOpenClasses["dataTypes_dataType"]() lbessard@125: new_datatype.setName(name) lbessard@125: new_datatype.baseType.setContent("BOOL", None) lbessard@125: self.dataTypes.appendDataType(new_datatype) lbessard@125: setattr(cls, "appendDataTypeElement", appendDataTypeElement) lbessard@125: lbessard@125: def insertDataTypeElement(self, index, datatype): lbessard@125: self.dataTypes.insertDataType(index, datatype) lbessard@125: setattr(cls, "insertDataTypeElement", insertDataTypeElement) lbessard@125: lbessard@125: def removeDataTypeElement(self, name): lbessard@125: found = False lbessard@125: for idx, element in enumerate(self.dataTypes.getDataType()): lbessard@125: if element.getName() == name: lbessard@125: self.dataTypes.removeDataType(idx) lbessard@125: found = True lbessard@125: break lbessard@125: if not found: lbessard@125: raise ValueError, "\"%s\" Data Type doesn't exist !!!"%name lbessard@125: setattr(cls, "removeDataTypeElement", removeDataTypeElement) lbessard@125: lbessard@2: def getPouElements(self): lbessard@2: return self.pous.getPou() lbessard@2: setattr(cls, "getPouElements", getPouElements) lbessard@2: lbessard@2: def getPouElement(self, name): lbessard@2: elements = self.pous.getPou() lbessard@2: for element in elements: lbessard@2: if element.getName() == name: lbessard@2: return element lbessard@2: return None lbessard@2: setattr(cls, "getPouElement", getPouElement) lbessard@2: lbessard@2: def appendPouElement(self, name, pou_type, body_type): lbessard@2: for element in self.pous.getPou(): lbessard@2: if element.getName() == name: lbessard@2: raise ValueError, "\"%s\" POU already exists !!!"%name lbessard@2: new_pou = PLCOpenClasses["pous_pou"]() lbessard@2: new_pou.setName(name) lbessard@2: new_pou.pouType.setValue(pou_type) lbessard@2: new_pou.setBody(PLCOpenClasses["body"]()) lbessard@2: new_pou.setBodyType(body_type) lbessard@2: self.pous.appendPou(new_pou) lbessard@2: setattr(cls, "appendPouElement", appendPouElement) lbessard@2: lbessard@2: def insertPouElement(self, index, pou): lbessard@2: self.pous.insertPou(index, pou) lbessard@2: setattr(cls, "insertPouElement", insertPouElement) lbessard@2: lbessard@2: def removePouElement(self, name): lbessard@2: found = False lbessard@2: for idx, element in enumerate(self.pous.getPou()): lbessard@2: if element.getName() == name: lbessard@2: self.pous.removePou(idx) lbessard@2: found = True lbessard@2: break lbessard@2: if not found: lbessard@2: raise ValueError, "\"%s\" POU doesn't exist !!!"%name lbessard@2: setattr(cls, "removePouElement", removePouElement) lbessard@2: lbessard@2: def setBodyType(self, type): lbessard@2: if type == "IL": lbessard@2: self.body.setContent("IL", PLCOpenClasses["formattedText"]()) lbessard@2: elif type == "ST": lbessard@2: self.body.setContent("ST", PLCOpenClasses["formattedText"]()) lbessard@2: elif type == "LD": lbessard@2: self.body.setContent("LD", PLCOpenClasses["body_LD"]()) lbessard@2: elif type == "FBD": lbessard@2: self.body.setContent("FBD", PLCOpenClasses["body_FBD"]()) lbessard@2: elif type == "SFC": lbessard@2: self.body.setContent("SFC", PLCOpenClasses["body_SFC"]()) lbessard@2: else: lbessard@2: raise ValueError, "%s isn't a valid body type!"%type lbessard@2: lbessard@2: def getBodyType(self): lbessard@2: return self.body.getContent()["name"] lbessard@2: lbessard@118: def resetExecutionOrder(self): lbessard@118: self.body.resetExecutionOrder() lbessard@118: lbessard@118: def compileExecutionOrder(self): lbessard@118: self.body.compileExecutionOrder() lbessard@118: lbessard@118: def setElementExecutionOrder(self, instance, new_executionOrder): lbessard@118: self.body.setElementExecutionOrder(instance, new_executionOrder) lbessard@118: lbessard@2: def addInstance(self, name, instance): lbessard@2: self.body.appendContentInstance(name, instance) lbessard@2: lbessard@2: def getInstances(self): lbessard@2: return self.body.getContentInstances() lbessard@2: lbessard@2: def getInstance(self, id): lbessard@2: return self.body.getContentInstance(id) lbessard@2: lbessard@2: def getRandomInstance(self, exclude): lbessard@2: return self.body.getContentRandomInstance(exclude) lbessard@2: lbessard@2: def getInstanceByName(self, name): lbessard@2: return self.body.getContentInstanceByName(name) lbessard@2: lbessard@2: def removeInstance(self, id): lbessard@2: self.body.removeContentInstance(id) lbessard@2: lbessard@2: def setText(self, text): lbessard@2: self.body.setText(text) lbessard@2: lbessard@2: def getText(self): lbessard@2: return self.body.getText() lbessard@2: setattr(cls, "getText", getText) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("pous_pou", None) lbessard@67: if cls: lbessard@2: setattr(cls, "setBodyType", setBodyType) lbessard@2: setattr(cls, "getBodyType", getBodyType) lbessard@118: setattr(cls, "resetExecutionOrder", resetExecutionOrder) lbessard@118: setattr(cls, "compileExecutionOrder", compileExecutionOrder) lbessard@118: setattr(cls, "setElementExecutionOrder", setElementExecutionOrder) lbessard@2: setattr(cls, "addInstance", addInstance) lbessard@2: setattr(cls, "getInstances", getInstances) lbessard@2: setattr(cls, "getInstance", getInstance) lbessard@2: setattr(cls, "getRandomInstance", getRandomInstance) lbessard@2: setattr(cls, "getInstanceByName", getInstanceByName) lbessard@2: setattr(cls, "removeInstance", removeInstance) lbessard@2: setattr(cls, "setText", setText) lbessard@2: setattr(cls, "getText", getText) lbessard@2: lbessard@2: def getVars(self): lbessard@2: vars = [] lbessard@2: reverse_types = {} lbessard@2: for name, value in VarTypes.items(): lbessard@2: reverse_types[value] = name lbessard@2: for varlist in self.interface.getContent(): lbessard@2: vars.append((reverse_types[varlist["name"]], varlist["value"])) lbessard@2: return vars lbessard@2: setattr(cls, "getVars", getVars) lbessard@2: lbessard@2: def setVars(self, vars): lbessard@2: self.interface.setContent([]) lbessard@2: for vartype, varlist in vars: lbessard@2: self.interface.appendContent(VarTypes[vartype], varlist) lbessard@2: setattr(cls, "setVars", setVars) lbessard@2: lbessard@67: def addPouVar(self, type, name): lbessard@67: content = self.interface.getContent() lbessard@67: if len(content) == 0 or content[-1]["name"] != "localVars": lbessard@68: content.append({"name" : "localVars", "value" : PLCOpenClasses["varList"]()}) lbessard@68: else: lbessard@68: varlist = content[-1]["value"] lbessard@68: variables = varlist.getVariable() lbessard@68: if varlist.getConstant() or varlist.getRetain() or len(variables) > 0 and variables[0].getAddress(): lbessard@68: content.append({"name" : "localVars", "value" : PLCOpenClasses["varList"]()}) lbessard@67: var = PLCOpenClasses["varListPlain_variable"]() lbessard@67: var.setName(name) lbessard@67: var_type = PLCOpenClasses["dataType"]() lbessard@67: derived_type = PLCOpenClasses["derived"]() lbessard@67: derived_type.setName(type) lbessard@143: var_type.setContent("derived", derived_type) lbessard@67: var.setType(var_type) lbessard@67: content[-1]["value"].appendVariable(var) lbessard@67: setattr(cls, "addPouVar", addPouVar) lbessard@67: lbessard@94: def changePouVar(self, old_type, old_name, new_type, new_name): lbessard@94: content = self.interface.getContent() lbessard@94: for varlist in content: lbessard@94: variables = varlist["value"].getVariable() lbessard@94: for var in variables: lbessard@94: if var.getName() == old_name: lbessard@125: vartype_content = var.getType().getContent() lbessard@141: if vartype_content["name"] == "derived" and vartype_content["value"].getName() == old_type: lbessard@94: var.setName(new_name) lbessard@125: vartype_content["value"].setName(new_type) lbessard@94: return lbessard@94: setattr(cls, "changePouVar", changePouVar) lbessard@94: lbessard@67: def removePouVar(self, type, name): lbessard@67: content = self.interface.getContent() lbessard@67: for varlist in content: lbessard@67: variables = varlist["value"].getVariable() lbessard@67: for var in variables: lbessard@67: if var.getName() == name: lbessard@143: vartype_content = var.getType().getContent() lbessard@143: if vartype_content["name"] == "derived" and vartype_content["value"].getName() == type: lbessard@67: variables.remove(var) lbessard@67: break lbessard@67: if len(varlist["value"].getVariable()) == 0: lbessard@67: content.remove(varlist) lbessard@67: break lbessard@67: setattr(cls, "removePouVar", removePouVar) lbessard@68: lbessard@68: def hasBlock(self, name): lbessard@68: if self.getBodyType() in ["FBD", "LD", "SFC"]: lbessard@68: for instance in self.getInstances(): lbessard@68: if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name: lbessard@68: return True lbessard@89: if self.transitions: lbessard@89: for transition in self.transitions.getTransition(): lbessard@89: result = transition.hasBlock(name) lbessard@89: if result: lbessard@89: return result lbessard@89: if self.actions: lbessard@89: for action in self.actions.getAction(): lbessard@89: result = action.hasBlock(name) lbessard@89: if result: lbessard@89: return result lbessard@68: return False lbessard@68: setattr(cls, "hasBlock", hasBlock) lbessard@68: lbessard@2: def addTransition(self, name, type): lbessard@2: if not self.transitions: lbessard@2: self.addTransitions() lbessard@2: self.transitions.setTransition([]) lbessard@2: transition = PLCOpenClasses["transitions_transition"]() lbessard@2: transition.setName(name) lbessard@2: transition.setBodyType(type) lbessard@2: self.transitions.appendTransition(transition) lbessard@2: setattr(cls, "addTransition", addTransition) lbessard@2: lbessard@2: def getTransition(self, name): lbessard@2: if self.transitions: lbessard@2: for transition in self.transitions.getTransition(): lbessard@2: if transition.getName() == name: lbessard@2: return transition lbessard@2: return None lbessard@2: setattr(cls, "getTransition", getTransition) lbessard@2: lbessard@2: def getTransitionList(self): lbessard@2: if self.transitions: lbessard@2: return self.transitions.getTransition() lbessard@2: return [] lbessard@2: setattr(cls, "getTransitionList", getTransitionList) lbessard@2: lbessard@2: def removeTransition(self, name): lbessard@2: if self.transitions: lbessard@2: transitions = self.transitions.getTransition() lbessard@2: i = 0 lbessard@2: removed = False lbessard@2: while i < len(transitions) and not removed: lbessard@2: if transitions[i].getName() == name: lbessard@46: transitions.pop(i) lbessard@2: removed = True lbessard@2: i += 1 lbessard@2: if not removed: lbessard@2: raise ValueError, "Transition with name %s doesn't exists!"%name lbessard@2: setattr(cls, "removeTransition", removeTransition) lbessard@2: lbessard@2: def addAction(self, name, type): lbessard@2: if not self.actions: lbessard@2: self.addActions() lbessard@2: self.actions.setAction([]) lbessard@2: action = PLCOpenClasses["actions_action"]() lbessard@2: action.setName(name) lbessard@2: action.setBodyType(type) lbessard@2: self.actions.appendAction(action) lbessard@2: setattr(cls, "addAction", addAction) lbessard@2: lbessard@2: def getAction(self, name): lbessard@2: if self.actions: lbessard@2: for action in self.actions.getAction(): lbessard@2: if action.getName() == name: lbessard@2: return action lbessard@2: return None lbessard@2: setattr(cls, "getAction", getAction) lbessard@2: lbessard@2: def getActionList(self): lbessard@2: if self.actions: lbessard@2: return self.actions.getAction() lbessard@2: return [] lbessard@2: setattr(cls, "getActionList", getActionList) lbessard@2: lbessard@2: def removeAction(self, name): lbessard@2: if self.actions: lbessard@2: actions = self.actions.getAction() lbessard@2: i = 0 lbessard@2: removed = False lbessard@2: while i < len(actions) and not removed: lbessard@2: if actions[i].getName() == name: lbessard@46: actions.pop(i) lbessard@2: removed = True lbessard@2: i += 1 lbessard@2: if not removed: lbessard@2: raise ValueError, "Action with name %s doesn't exists!"%name lbessard@2: setattr(cls, "removeAction", removeAction) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: self.body.updateElementName(old_name, new_name) lbessard@58: for action in self.getActionList(): lbessard@58: action.updateElementName(old_name, new_name) lbessard@58: for transition in self.getTransitionList(): lbessard@58: transition.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("transitions_transition", None) lbessard@67: if cls: lbessard@2: setattr(cls, "setBodyType", setBodyType) lbessard@2: setattr(cls, "getBodyType", getBodyType) lbessard@118: setattr(cls, "resetExecutionOrder", resetExecutionOrder) lbessard@118: setattr(cls, "compileExecutionOrder", compileExecutionOrder) lbessard@118: setattr(cls, "setElementExecutionOrder", setElementExecutionOrder) lbessard@2: setattr(cls, "addInstance", addInstance) lbessard@2: setattr(cls, "getInstances", getInstances) lbessard@2: setattr(cls, "getInstance", getInstance) lbessard@2: setattr(cls, "getRandomInstance", getRandomInstance) lbessard@2: setattr(cls, "getInstanceByName", getInstanceByName) lbessard@2: setattr(cls, "removeInstance", removeInstance) lbessard@2: setattr(cls, "setText", setText) lbessard@2: setattr(cls, "getText", getText) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: self.body.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@68: def hasBlock(self, name): lbessard@68: if self.getBodyType() in ["FBD", "LD", "SFC"]: lbessard@68: for instance in self.getInstances(): lbessard@68: if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name: lbessard@68: return True lbessard@68: return False lbessard@68: setattr(cls, "hasBlock", hasBlock) lbessard@68: lbessard@67: cls = PLCOpenClasses.get("actions_action", None) lbessard@67: if cls: lbessard@2: setattr(cls, "setBodyType", setBodyType) lbessard@2: setattr(cls, "getBodyType", getBodyType) lbessard@118: setattr(cls, "resetExecutionOrder", resetExecutionOrder) lbessard@118: setattr(cls, "compileExecutionOrder", compileExecutionOrder) lbessard@118: setattr(cls, "setElementExecutionOrder", setElementExecutionOrder) lbessard@2: setattr(cls, "addInstance", addInstance) lbessard@2: setattr(cls, "getInstances", getInstances) lbessard@2: setattr(cls, "getInstance", getInstance) lbessard@2: setattr(cls, "getRandomInstance", getRandomInstance) lbessard@2: setattr(cls, "getInstanceByName", getInstanceByName) lbessard@2: setattr(cls, "removeInstance", removeInstance) lbessard@2: setattr(cls, "setText", setText) lbessard@2: setattr(cls, "getText", getText) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: self.body.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@68: def hasBlock(self, name): lbessard@68: if self.getBodyType() in ["FBD", "LD", "SFC"]: lbessard@68: for instance in self.getInstances(): lbessard@68: if isinstance(instance, PLCOpenClasses["block"]) and instance.getInstanceName() == name: lbessard@68: return True lbessard@68: return False lbessard@68: setattr(cls, "hasBlock", hasBlock) lbessard@68: lbessard@67: cls = PLCOpenClasses.get("body", None) lbessard@67: if cls: lbessard@118: cls.currentExecutionOrderId = 0 lbessard@118: lbessard@118: def resetCurrentExecutionOrderId(self): lbessard@118: self.currentExecutionOrderId = 0 lbessard@118: setattr(cls, "resetCurrentExecutionOrderId", resetCurrentExecutionOrderId) lbessard@118: lbessard@118: def getNewExecutionOrderId(self): lbessard@118: self.currentExecutionOrderId += 1 lbessard@118: return self.currentExecutionOrderId lbessard@118: setattr(cls, "getNewExecutionOrderId", getNewExecutionOrderId) lbessard@118: lbessard@118: def resetExecutionOrder(self): lbessard@118: if self.content["name"] == "FBD": lbessard@118: for element in self.content["value"].getContent(): lbessard@118: if not isinstance(element["value"], (PLCOpenClasses.get("comment", None), PLCOpenClasses.get("connector", None), PLCOpenClasses.get("continuation", None))): lbessard@118: element["value"].setExecutionOrderId(0) lbessard@118: else: lbessard@118: raise TypeError, "Can only generate execution order on FBD networks!" lbessard@118: setattr(cls, "resetExecutionOrder", resetExecutionOrder) lbessard@118: lbessard@118: def compileExecutionOrder(self): lbessard@118: if self.content["name"] == "FBD": lbessard@118: self.resetExecutionOrder() lbessard@118: self.resetCurrentExecutionOrderId() lbessard@118: for element in self.content["value"].getContent(): lbessard@118: if isinstance(element["value"], PLCOpenClasses.get("outVariable", None)) and element["value"].getExecutionOrderId() == 0: lbessard@118: connections = element["value"].connectionPointIn.getConnections() lbessard@118: if connections and len(connections) == 1: lbessard@118: self.compileElementExecutionOrder(connections[0]) lbessard@118: element["value"].setExecutionOrderId(self.getNewExecutionOrderId()) lbessard@118: else: lbessard@118: raise TypeError, "Can only generate execution order on FBD networks!" lbessard@118: setattr(cls, "compileExecutionOrder", compileExecutionOrder) lbessard@118: lbessard@118: def compileElementExecutionOrder(self, link): lbessard@118: if self.content["name"] == "FBD": lbessard@118: localid = link.getRefLocalId() lbessard@118: instance = self.getContentInstance(localid) lbessard@118: if isinstance(instance, PLCOpenClasses.get("block", None)) and instance.getExecutionOrderId() == 0: lbessard@118: for variable in instance.inputVariables.getVariable(): lbessard@118: connections = variable.connectionPointIn.getConnections() lbessard@118: if connections and len(connections) == 1: lbessard@118: self.compileElementExecutionOrder(connections[0]) lbessard@118: instance.setExecutionOrderId(self.getNewExecutionOrderId()) lbessard@118: elif isinstance(instance, PLCOpenClasses.get("continuation", None)) and instance.getExecutionOrderId() == 0: lbessard@118: name = instance.getName() lbessard@118: for tmp_instance in self.getContentInstances(): lbessard@118: if isinstance(tmp_instance, PLCOpenClasses.get("connector", None)) and tmp_instance.getName() == name and tmp_instance.getExecutionOrderId() == 0: lbessard@118: connections = tmp_instance.connectionPointIn.getConnections() lbessard@118: if connections and len(connections) == 1: lbessard@118: self.compileElementExecutionOrder(connections[0]) lbessard@118: else: lbessard@118: raise TypeError, "Can only generate execution order on FBD networks!" lbessard@118: setattr(cls, "compileElementExecutionOrder", compileElementExecutionOrder) lbessard@118: lbessard@118: def setElementExecutionOrder(self, instance, new_executionOrder): lbessard@118: if self.content["name"] == "FBD": lbessard@118: old_executionOrder = instance.getExecutionOrderId() lbessard@118: if old_executionOrder is not None and old_executionOrder != 0 and new_executionOrder != 0: lbessard@118: for element in self.content["value"].getContent(): lbessard@118: if element["value"] != instance and not isinstance(element["value"], PLCOpenClasses.get("comment", None)): lbessard@118: element_executionOrder = element["value"].getExecutionOrderId() lbessard@118: if old_executionOrder <= element_executionOrder <= new_executionOrder: lbessard@118: element["value"].setExecutionOrderId(element_executionOrder - 1) lbessard@118: if new_executionOrder <= element_executionOrder <= old_executionOrder: lbessard@118: element["value"].setExecutionOrderId(element_executionOrder + 1) lbessard@118: instance.setExecutionOrderId(new_executionOrder) lbessard@118: else: lbessard@118: raise TypeError, "Can only generate execution order on FBD networks!" lbessard@118: setattr(cls, "setElementExecutionOrder", setElementExecutionOrder) lbessard@118: lbessard@2: def appendContentInstance(self, name, instance): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: self.content["value"].appendContent(name, instance) lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "appendContentInstance", appendContentInstance) lbessard@2: lbessard@2: def getContentInstances(self): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: instances = [] lbessard@2: for element in self.content["value"].getContent(): lbessard@2: instances.append(element["value"]) lbessard@2: return instances lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "getContentInstances", getContentInstances) lbessard@2: lbessard@2: def getContentInstance(self, id): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: for element in self.content["value"].getContent(): lbessard@2: if element["value"].getLocalId() == id: lbessard@2: return element["value"] etisserant@0: return None lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "getContentInstance", getContentInstance) lbessard@2: lbessard@2: def getContentRandomInstance(self, exclude): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: for element in self.content["value"].getContent(): lbessard@2: if element["value"].getLocalId() not in exclude: lbessard@2: return element["value"] lbessard@2: return None lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "getContentRandomInstance", getContentRandomInstance) lbessard@2: lbessard@2: def getContentInstanceByName(self, name): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: for element in self.content["value"].getContent(): lbessard@2: if element["value"].getLocalId() == name: lbessard@2: return element["value"] lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "getContentInstanceByName", getContentInstanceByName) lbessard@2: lbessard@2: def removeContentInstance(self, id): lbessard@2: if self.content["name"] in ["LD","FBD","SFC"]: lbessard@2: i = 0 lbessard@2: removed = False lbessard@2: elements = self.content["value"].getContent() lbessard@2: while i < len(elements) and not removed: lbessard@2: if elements[i]["value"].getLocalId() == id: lbessard@2: self.content["value"].removeContent(i) lbessard@2: removed = True lbessard@2: i += 1 lbessard@2: if not removed: lbessard@2: raise ValueError, "Instance with id %d doesn't exists!"%id lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have instances!"%self.content["name"] lbessard@2: setattr(cls, "removeContentInstance", removeContentInstance) lbessard@2: lbessard@2: def setText(self, text): lbessard@2: if self.content["name"] in ["IL","ST"]: lbessard@2: self.content["value"].setText(text) lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have text!"%self.content["name"] lbessard@2: setattr(cls, "setText", setText) lbessard@2: lbessard@2: def getText(self): lbessard@2: if self.content["name"] in ["IL","ST"]: lbessard@2: return self.content["value"].getText() lbessard@2: else: lbessard@2: raise TypeError, "%s body don't have text!"%self.content["name"] lbessard@2: setattr(cls, "getText", getText) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.content["name"] in ["IL", "ST"]: lbessard@58: self.content["value"].updateElementName(old_name, new_name) lbessard@58: else: lbessard@58: for element in self.content["value"].getContent(): lbessard@58: element["value"].updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@2: def getX(self): lbessard@2: return self.position.getX() lbessard@2: lbessard@2: def getY(self): lbessard@2: return self.position.getY() lbessard@2: lbessard@2: def setX(self, x): lbessard@2: self.position.setX(x) lbessard@2: lbessard@2: def setY(self, y): lbessard@2: self.position.setY(y) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("comment", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setContentText(self, text): lbessard@2: self.content.setText(text) lbessard@2: setattr(cls, "setContentText", setContentText) etisserant@0: lbessard@2: def getContentText(self): lbessard@2: return self.content.getText() lbessard@2: setattr(cls, "getContentText", getContentText) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: self.content.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("block", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.typeName == old_name: lbessard@58: self.typeName = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("inputVariables_variable", None) lbessard@67: if cls: lbessard@2: def setConnectorEdge(self, edge): lbessard@2: if not self.edge: lbessard@2: self.edge = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edge.setValue(edge) lbessard@2: setattr(cls, "setConnectorEdge", setConnectorEdge) lbessard@2: lbessard@2: def getConnectorEdge(self): lbessard@2: if self.edge: lbessard@2: return self.edge.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getConnectorEdge", getConnectorEdge) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("outputVariables_variable", None) lbessard@67: if cls: lbessard@2: def setConnectorEdge(self, edge): lbessard@2: if not self.edge: lbessard@2: self.edge = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edge.setValue(edge) lbessard@2: setattr(cls, "setConnectorEdge", setConnectorEdge) lbessard@2: lbessard@2: def getConnectorEdge(self): lbessard@2: if self.edge: lbessard@2: return self.edge.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getConnectorEdge", getConnectorEdge) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("leftPowerRail", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("rightPowerRail", None) lbessard@67: if cls: lbessard@67: setattr(cls, "getX", getX) lbessard@67: setattr(cls, "getY", getY) lbessard@67: setattr(cls, "setX", setX) lbessard@67: setattr(cls, "setY", setY) lbessard@67: lbessard@67: def updateElementName(self, old_name, new_name): lbessard@67: pass lbessard@67: setattr(cls, "updateElementName", updateElementName) lbessard@67: lbessard@67: cls = PLCOpenClasses.get("contact", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setContactEdge(self, edge): lbessard@2: if not self.edge: lbessard@2: self.edge = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edge.setValue(edge) lbessard@2: setattr(cls, "setContactEdge", setContactEdge) lbessard@2: lbessard@2: def getContactEdge(self): lbessard@2: if self.edge: lbessard@2: return self.edge.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getContactEdge", getContactEdge) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.variable == old_name: lbessard@58: self.variable = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("coil", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setCoilStorage(self, edge): lbessard@2: if not self.storage: lbessard@2: self.storage = PLCOpenClasses["storageModifierType"]() lbessard@2: self.storage.setValue(edge) lbessard@2: setattr(cls, "setCoilStorage", setCoilStorage) lbessard@2: lbessard@2: def getCoilStorage(self): lbessard@2: if self.storage: lbessard@2: return self.storage.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getCoilStorage", getCoilStorage) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.variable == old_name: lbessard@58: self.variable = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("step", None) lbessard@67: if cls: lbessard@67: setattr(cls, "getX", getX) lbessard@67: setattr(cls, "getY", getY) lbessard@67: setattr(cls, "setX", setX) lbessard@67: setattr(cls, "setY", setY) lbessard@67: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("transition", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setConditionContent(self, type, value): lbessard@2: if not self.condition: lbessard@2: self.addCondition() lbessard@2: if type == "reference": lbessard@2: condition = PLCOpenClasses["condition_reference"]() lbessard@2: condition.setName(value) lbessard@2: elif type == "inline": lbessard@2: condition = PLCOpenClasses["condition_inline"]() lbessard@2: condition.setContent("ST", PLCOpenClasses["formattedText"]()) lbessard@2: condition.setText(value) lbessard@69: elif type == "connection": lbessard@69: condition = [] lbessard@2: self.condition.setContent(type, condition) lbessard@2: setattr(cls, "setConditionContent", setConditionContent) etisserant@0: lbessard@2: def getConditionContent(self): lbessard@2: if self.condition: lbessard@2: content = self.condition.getContent() lbessard@2: values = {"type" : content["name"]} lbessard@2: if values["type"] == "reference": lbessard@2: values["value"] = content["value"].getName() lbessard@2: elif values["type"] == "inline": lbessard@2: values["value"] = content["value"].getText() lbessard@2: return values lbessard@2: return "" lbessard@2: setattr(cls, "getConditionContent", getConditionContent) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.condition: lbessard@58: content = self.condition.getContent() lbessard@58: if content["name"] == "reference": lbessard@58: if content["value"].getName() == old_name: lbessard@58: content["value"].setName(new_name) lbessard@58: elif content["name"] == "inline": lbessard@58: content["value"].updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@63: def addConnection(self): lbessard@69: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@69: if content["name"] != "connection": lbessard@69: self.condition.setContent("connection", []) lbessard@69: content = self.condition.getContent() lbessard@69: content["value"].append(PLCOpenClasses["connection"]()) lbessard@63: setattr(cls, "addConnection", addConnection) lbessard@63: lbessard@63: def removeConnection(self, idx): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: content["value"].pop(idx) lbessard@63: setattr(cls, "removeConnection", removeConnection) lbessard@63: lbessard@63: def removeConnections(self): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: content["value"] = [] lbessard@63: setattr(cls, "removeConnections", removeConnections) lbessard@63: lbessard@63: def getConnections(self): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: return content["value"] lbessard@63: setattr(cls, "getConnections", getConnections) lbessard@63: lbessard@63: def setConnectionId(self, idx, id): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: content["value"][idx].setRefLocalId(id) lbessard@63: setattr(cls, "setConnectionId", setConnectionId) lbessard@63: lbessard@63: def getConnectionId(self, idx): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: return content["value"][idx].getRefLocalId() lbessard@63: return None lbessard@63: setattr(cls, "getConnectionId", getConnectionId) lbessard@63: lbessard@63: def setConnectionPoints(self, idx, points): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: content["value"][idx].setPoints(points) lbessard@63: setattr(cls, "setConnectionPoints", setConnectionPoints) lbessard@63: lbessard@63: def getConnectionPoints(self, idx): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: return content["value"][idx].getPoints() lbessard@63: return None lbessard@63: setattr(cls, "getConnectionPoints", getConnectionPoints) lbessard@63: lbessard@63: def setConnectionParameter(self, idx, parameter): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: content["value"][idx].setFormalParameter(parameter) lbessard@63: setattr(cls, "setConnectionParameter", setConnectionParameter) lbessard@63: lbessard@63: def getConnectionParameter(self, idx): lbessard@63: if self.condition: lbessard@63: content = self.condition.getContent() lbessard@63: if content["name"] == "connection": lbessard@63: return content["value"][idx].getFormalParameter() lbessard@63: return None lbessard@63: setattr(cls, "getConnectionParameter", getConnectionParameter) lbessard@63: lbessard@63: setattr(cls, "addConnection", addConnection) lbessard@63: lbessard@67: cls = PLCOpenClasses.get("selectionDivergence", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("selectionConvergence", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("simultaneousDivergence", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("simultaneousConvergence", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("jumpStep", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("actionBlock_action", None) lbessard@67: if cls: lbessard@2: def setQualifierValue(self, value): lbessard@2: if self.qualifier: lbessard@2: self.qualifier.setValue(value) lbessard@2: setattr(cls, "setQualifierValue", setQualifierValue) lbessard@2: lbessard@2: def getQualifierValue(self): lbessard@2: if self.qualifier: lbessard@2: return self.qualifier.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getQualifierValue", getQualifierValue) lbessard@2: lbessard@2: def setReferenceName(self, name): lbessard@2: if self.reference: lbessard@2: self.reference.setName(name) lbessard@2: setattr(cls, "setReferenceName", setReferenceName) lbessard@2: lbessard@2: def getReferenceName(self): lbessard@2: if self.reference: lbessard@2: return self.reference.getName() lbessard@2: return None lbessard@2: setattr(cls, "getReferenceName", getReferenceName) lbessard@2: lbessard@2: def setInlineContent(self, content): lbessard@2: if self.inline: lbessard@2: self.inline.setContent("ST", PLCOpenClasses["formattedText"]()) lbessard@2: self.inline.setText(content) lbessard@2: setattr(cls, "setInlineContent", setInlineContent) lbessard@2: lbessard@2: def getInlineContent(self): lbessard@2: if self.inline: lbessard@2: return self.inline.getText() lbessard@2: return None lbessard@2: setattr(cls, "getInlineContent", getInlineContent) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.reference and self.reference.getName() == old_name: lbessard@58: self.reference.setName(new_name) lbessard@58: if self.inline: lbessard@58: self.inline.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("actionBlock", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setActions(self, actions): lbessard@2: self.action = [] lbessard@2: for params in actions: lbessard@2: action = PLCOpenClasses["actionBlock_action"]() lbessard@2: action.addQualifier() lbessard@2: action.setQualifierValue(params["qualifier"]) lbessard@2: if params["type"] == "reference": lbessard@2: action.addReference() lbessard@2: action.setReferenceName(params["value"]) etisserant@0: else: lbessard@2: action.addInline() lbessard@2: action.setInlineContent(params["value"]) lbessard@2: if "duration" in params: lbessard@2: action.setDuration(params["duration"]) lbessard@2: if "indicator" in params: lbessard@2: action.setIndicator(params["indicator"]) lbessard@2: self.action.append(action) lbessard@2: setattr(cls, "setActions", setActions) lbessard@2: lbessard@2: def getActions(self): lbessard@2: actions = [] lbessard@2: for action in self.action: lbessard@2: params = {} lbessard@2: params["qualifier"] = action.getQualifierValue() lbessard@108: if params["qualifier"] is None: lbessard@108: params["qualifier"] = "N" lbessard@2: if action.getReference(): lbessard@2: params["type"] = "reference" lbessard@2: params["value"] = action.getReferenceName() lbessard@2: elif action.getInline(): lbessard@2: params["type"] = "inline" lbessard@2: params["value"] = action.getInlineContent() lbessard@2: duration = action.getDuration() lbessard@2: if duration: lbessard@2: params["duration"] = duration lbessard@2: indicator = action.getIndicator() lbessard@2: if indicator: lbessard@2: params["indicator"] = indicator lbessard@2: actions.append(params) lbessard@2: return actions lbessard@2: setattr(cls, "getActions", getActions) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: for action in self.action: lbessard@58: action.updateElementName(old_name, new_name) lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("inVariable", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setConnectorEdge(self, edge): lbessard@2: if not self.edge: lbessard@2: self.edge = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edge.setValue(edge) lbessard@2: setattr(cls, "setConnectorEdge", setConnectorEdge) lbessard@2: lbessard@2: def getConnectorEdge(self): lbessard@2: if self.edge: lbessard@2: return self.edge.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getConnectorEdge", getConnectorEdge) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.expression == old_name: lbessard@58: self.expression = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("outVariable", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setConnectorEdge(self, edge): lbessard@2: if not self.edge: lbessard@2: self.edge = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edge.setValue(edge) lbessard@2: setattr(cls, "setConnectorEdge", setConnectorEdge) lbessard@2: lbessard@2: def getConnectorEdge(self): lbessard@2: if self.edge: lbessard@2: return self.edge.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getConnectorEdge", getConnectorEdge) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.expression == old_name: lbessard@58: self.expression = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("inOutVariable", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@2: lbessard@2: def setInputEdge(self, edge): lbessard@2: if not self.edgeIn: lbessard@2: self.edgeIn = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edgeIn.setValue(edge) lbessard@2: setattr(cls, "setInputEdge", setInputEdge) lbessard@2: lbessard@2: def getInputEdge(self): lbessard@2: if self.edgeIn: lbessard@2: return self.edgeIn.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getInputEdge", getInputEdge) lbessard@2: lbessard@2: def setOutputEdge(self, edge): lbessard@2: if not self.edgeOut: lbessard@2: self.edgeOut = PLCOpenClasses["edgeModifierType"]() lbessard@2: self.edgeOut.setValue(edge) lbessard@2: setattr(cls, "setInputEdge", setInputEdge) lbessard@2: lbessard@2: def getOutputEdge(self): lbessard@2: if self.edgeOut: lbessard@2: return self.edgeOut.getValue() lbessard@2: return None lbessard@2: setattr(cls, "getOutputEdge", getOutputEdge) lbessard@2: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: if self.expression == old_name: lbessard@58: self.expression = new_name lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@58: lbessard@67: cls = PLCOpenClasses.get("continuation", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("connector", None) lbessard@67: if cls: lbessard@2: setattr(cls, "getX", getX) lbessard@2: setattr(cls, "getY", getY) lbessard@2: setattr(cls, "setX", setX) lbessard@2: setattr(cls, "setY", setY) lbessard@58: lbessard@58: def updateElementName(self, old_name, new_name): lbessard@58: pass lbessard@58: setattr(cls, "updateElementName", updateElementName) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("connection", None) lbessard@67: if cls: lbessard@2: def setPoints(self, points): lbessard@2: self.position = [] lbessard@2: for point in points: lbessard@2: position = PLCOpenClasses["position"]() lbessard@2: position.setX(point.x) lbessard@2: position.setY(point.y) lbessard@2: self.position.append(position) lbessard@2: setattr(cls, "setPoints", setPoints) lbessard@2: lbessard@2: def getPoints(self): lbessard@2: points = [] lbessard@2: for position in self.position: lbessard@2: points.append((position.getX(),position.getY())) lbessard@2: return points lbessard@2: setattr(cls, "getPoints", getPoints) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("connectionPointIn", None) lbessard@67: if cls: lbessard@2: def setRelPosition(self, x, y): lbessard@2: self.relPosition = PLCOpenClasses["position"]() lbessard@2: self.relPosition.setX(x) lbessard@2: self.relPosition.setY(y) lbessard@2: setattr(cls, "setRelPosition", setRelPosition) lbessard@2: lbessard@2: def getRelPosition(self): lbessard@2: if self.relPosition: lbessard@2: return self.relPosition.getX(), self.relPosition.getY() lbessard@2: else: etisserant@0: return self.relPosition lbessard@2: setattr(cls, "getRelPosition", getRelPosition) lbessard@2: lbessard@2: def addConnection(self): lbessard@2: if not self.content: lbessard@2: self.content = {"name":"connection","value":[PLCOpenClasses["connection"]()]} lbessard@2: else: lbessard@2: self.content["value"].append(PLCOpenClasses["connection"]()) lbessard@2: setattr(cls, "addConnection", addConnection) lbessard@2: lbessard@2: def removeConnection(self, idx): lbessard@2: if self.content: lbessard@2: self.content["value"].pop(idx) lbessard@2: if len(self.content["value"]) == 0: lbessard@2: self.content = None lbessard@2: setattr(cls, "removeConnection", removeConnection) lbessard@2: lbessard@2: def removeConnections(self): lbessard@2: if self.content: lbessard@2: self.content = None lbessard@2: setattr(cls, "removeConnections", removeConnections) lbessard@2: lbessard@2: def getConnections(self): lbessard@2: if self.content: lbessard@2: return self.content["value"] lbessard@2: setattr(cls, "getConnections", getConnections) lbessard@2: lbessard@2: def setConnectionId(self, idx, id): lbessard@2: if self.content: lbessard@2: self.content["value"][idx].setRefLocalId(id) lbessard@2: setattr(cls, "setConnectionId", setConnectionId) lbessard@2: lbessard@2: def getConnectionId(self, idx): lbessard@2: if self.content: lbessard@2: return self.content["value"][idx].getRefLocalId() lbessard@2: return None lbessard@2: setattr(cls, "getConnectionId", getConnectionId) lbessard@2: lbessard@2: def setConnectionPoints(self, idx, points): lbessard@2: if self.content: lbessard@2: self.content["value"][idx].setPoints(points) lbessard@2: setattr(cls, "setConnectionPoints", setConnectionPoints) lbessard@2: lbessard@2: def getConnectionPoints(self, idx): lbessard@2: if self.content: lbessard@2: return self.content["value"][idx].getPoints() lbessard@2: return None lbessard@2: setattr(cls, "getConnectionPoints", getConnectionPoints) lbessard@2: lbessard@27: def setConnectionParameter(self, idx, parameter): lbessard@27: if self.content: lbessard@27: self.content["value"][idx].setFormalParameter(parameter) lbessard@27: setattr(cls, "setConnectionParameter", setConnectionParameter) lbessard@27: lbessard@27: def getConnectionParameter(self, idx): lbessard@27: if self.content: lbessard@27: return self.content["value"][idx].getFormalParameter() lbessard@27: return None lbessard@27: setattr(cls, "getConnectionParameter", getConnectionParameter) lbessard@27: lbessard@67: cls = PLCOpenClasses.get("connectionPointOut", None) lbessard@67: if cls: lbessard@2: def setRelPosition(self, x, y): lbessard@2: self.relPosition = PLCOpenClasses["position"]() lbessard@2: self.relPosition.setX(x) lbessard@2: self.relPosition.setY(y) lbessard@2: setattr(cls, "setRelPosition", setRelPosition) lbessard@2: lbessard@2: def getRelPosition(self): lbessard@2: if self.relPosition: lbessard@2: return self.relPosition.getX(), self.relPosition.getY() lbessard@2: return self.relPosition lbessard@2: setattr(cls, "getRelPosition", getRelPosition) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("value", None) lbessard@67: if cls: lbessard@2: def setValue(self, value): lbessard@125: if value.startswith("[") and value.endswith("]"): lbessard@2: arrayValue = PLCOpenClasses["value_arrayValue"]() lbessard@2: self.content = {"name":"arrayValue","value":arrayValue} lbessard@125: elif value.startswith("(") and value.endswith(")"): lbessard@2: structValue = PLCOpenClasses["value_structValue"]() lbessard@2: self.content = {"name":"structValue","value":structValue} lbessard@2: else: lbessard@2: simpleValue = PLCOpenClasses["value_simpleValue"]() lbessard@2: self.content = {"name":"simpleValue","value":simpleValue} lbessard@125: self.content["value"].setValue(value) lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@125: return self.content["value"].getValue() lbessard@2: setattr(cls, "getValue", getValue) lbessard@2: lbessard@147: def extractValues(values): lbessard@145: items = values.split(",") lbessard@145: i = 1 lbessard@145: while i < len(items): lbessard@145: opened = items[i - 1].count("(") + items[i - 1].count("[") lbessard@145: closed = items[i - 1].count(")") + items[i - 1].count("]") lbessard@145: if opened > closed: lbessard@145: items[i - 1] = ','.join([items[i - 1], items.pop(i)]) lbessard@145: elif opened == closed: lbessard@145: i += 1 lbessard@145: else: lbessard@145: raise ValueError, "\"%s\" is an invalid value!"%value lbessard@145: return items lbessard@145: lbessard@67: cls = PLCOpenClasses.get("value_arrayValue", None) lbessard@67: if cls: lbessard@145: arrayValue_model = re.compile("([0-9]*)\((.*)\)$") lbessard@125: lbessard@125: def setValue(self, value): lbessard@2: self.value = [] lbessard@145: for item in extractValues(value[1:-1]): lbessard@125: item = item.strip() lbessard@2: element = PLCOpenClasses["arrayValue_value"]() lbessard@125: result = arrayValue_model.match(item) lbessard@125: if result is not None: lbessard@125: groups = result.groups() lbessard@125: element.setRepetitionValue(int(groups[0])) lbessard@125: element.setValue(groups[1].strip()) lbessard@125: else: lbessard@125: element.setValue(item) lbessard@2: self.value.append(element) lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@125: values = [] lbessard@125: for element in self.value: lbessard@125: repetition = element.getRepetitionValue() lbessard@125: if repetition is not None and repetition > 1: lbessard@125: values.append("%d(%s)"%(repetition, element.getValue())) lbessard@125: else: lbessard@125: values.append(element.getValue()) lbessard@125: return "[%s]"%", ".join(values) lbessard@2: setattr(cls, "getValue", getValue) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("value_structValue", None) lbessard@67: if cls: lbessard@125: structValue_model = re.compile("(.*):=(.*)") lbessard@125: lbessard@125: def setValue(self, value): lbessard@2: self.value = [] lbessard@145: for item in extractValues(value[1:-1]): lbessard@125: result = arrayValue_model.match(item) lbessard@125: if result is not None: lbessard@125: groups = result.groups() lbessard@125: element = PLCOpenClasses["structValue_value"]() lbessard@125: element.setMember(groups[0].strip()) lbessard@125: element.setValue(groups[1].strip()) lbessard@2: self.value.append(element) lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@125: values = [] lbessard@2: for element in self.value: lbessard@125: values.append("%s := %s"%(element.getMember(), element.getValue())) lbessard@125: return "(%s)"%", ".join(values) lbessard@2: setattr(cls, "getValue", getValue)