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("dataType", None) lbessard@67: if cls: lbessard@2: cls.value = None lbessard@2: lbessard@2: def getValue(self): lbessard@2: return self.value lbessard@2: setattr(cls, "getValue", getValue) lbessard@2: lbessard@2: def setValue(self, value): lbessard@2: self.value = value lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def loadXMLTree(self, tree): lbessard@67: node = tree.childNodes[1] lbessard@67: if node.nodeName == "derived": lbessard@67: self.value = PLCOpenClasses["derived"]() lbessard@67: self.value.loadXMLTree(node) lbessard@67: else: lbessard@67: self.value = node.nodeName 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: text = ind1 + "<%s>\n"%name lbessard@67: if isinstance(self.value, (StringType, UnicodeType)): lbessard@67: ind3, ind4 = getIndent(indent + 1, self.value) lbessard@67: text += ind3 + "<%s/>\n"%self.value lbessard@67: else: lbessard@67: text += self.value.generateXMLText("derived", indent + 1) lbessard@2: text += ind1 + "\n"%name lbessard@2: return text lbessard@2: setattr(cls, "generateXMLText", generateXMLText) 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@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@2: def setName(self, name): lbessard@2: self.contentHeader.setName(name) lbessard@2: setattr(cls, "setName", setName) etisserant@0: lbessard@2: def getName(self): lbessard@2: return self.contentHeader.getName() lbessard@2: setattr(cls, "getName", getName) 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@2: 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@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@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@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@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@67: var_type.setValue(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@94: var_type = var.getType().getValue() lbessard@94: if isinstance(var_type, PLCOpenClasses["derived"]) and var_type.getName() == old_type: lbessard@94: var.setName(new_name) lbessard@94: var.getType().getValue().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@67: var_type = var.getType().getValue() lbessard@67: if isinstance(var_type, PLCOpenClasses["derived"]) and var_type.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@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@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@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@2: try: lbessard@2: value = eval(value) lbessard@2: except: lbessard@2: pass lbessard@2: if type(value) == ListType: lbessard@2: arrayValue = PLCOpenClasses["value_arrayValue"]() lbessard@2: arrayValue.setValue(value) lbessard@2: self.content = {"name":"arrayValue","value":arrayValue} lbessard@2: elif type(value) == DictType: lbessard@2: structValue = PLCOpenClasses["value_structValue"]() lbessard@2: structValue.setValue(value) lbessard@2: self.content = {"name":"structValue","value":structValue} lbessard@2: else: lbessard@2: simpleValue = PLCOpenClasses["value_simpleValue"]() lbessard@2: simpleValue.setValue(str(value)) lbessard@2: self.content = {"name":"simpleValue","value":simpleValue} lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@2: value = self.content["value"].getValue() lbessard@2: try: lbessard@2: value = eval(value) lbessard@2: except: lbessard@2: pass lbessard@2: return value lbessard@2: setattr(cls, "getValue", getValue) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("value_arrayValue", None) lbessard@67: if cls: lbessard@2: def setValue(self, array): lbessard@2: self.value = [] lbessard@2: for value in array: lbessard@2: element = PLCOpenClasses["arrayValue_value"]() lbessard@2: element.setValue(value) lbessard@2: self.value.append(element) lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@2: return [element.getValue() for element in self.value] lbessard@2: setattr(cls, "getValue", getValue) lbessard@2: lbessard@67: cls = PLCOpenClasses.get("value_structValue", None) lbessard@67: if cls: lbessard@2: def setValue(self, dict): lbessard@2: self.value = [] lbessard@2: for name,value in dict.items(): lbessard@2: element = PLCOpenClasses["structValue_value"]() lbessard@2: element.setMember(name) lbessard@2: element.setValue(value) lbessard@2: self.value.append(element) lbessard@2: setattr(cls, "setValue", setValue) lbessard@2: lbessard@2: def getValue(self): lbessard@2: value = {} lbessard@2: for element in self.value: lbessard@2: value[element.getMember()] = element.getValue() lbessard@2: return value lbessard@2: setattr(cls, "getValue", getValue)