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: # etisserant@0: #Copyright (C): 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 etisserant@0: #Lesser 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@6: import os, sys 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@2: PLCOpenClasses = {} lbessard@2: PLCOpenTypes = {} lbessard@47: base_folder = "" lbessard@47: for path in sys.path: lbessard@47: if os.path.isfile(os.path.join(path, "plcopen/TC6_XML_V10_B.xsd")): lbessard@47: base_folder = path lbessard@47: GenerateClassesFromXSD(os.path.join(base_folder, "plcopen/TC6_XML_V10_B.xsd")) lbessard@2: CreateClasses(PLCOpenClasses, PLCOpenTypes) lbessard@2: lbessard@2: if "dataType" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["dataType"] 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@2: self.value = tree.childNodes[1].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@2: ind3, ind4 = getIndent(indent + 1, self.value) lbessard@2: text += ind3 + "<%s/>\n"%self.value lbessard@2: text += ind1 + "\n"%name lbessard@2: return text lbessard@2: setattr(cls, "generateXMLText", generateXMLText) lbessard@2: lbessard@2: if "formattedText" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["formattedText"] 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: etisserant@0: text = ind1 + "<%s>\n"%name lbessard@2: text += "%s\n"%self.text etisserant@0: text += ind1 + "\n"%name etisserant@0: return text lbessard@2: else: lbessard@2: return ind1 + "<%s>%s\n"%(name, self.text, name) lbessard@2: setattr(cls, "generateXMLText", generateXMLText) lbessard@2: lbessard@2: if "project" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["project"] 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@2: PLCOpenClasses["project_fileHeader"].singleLineAttributes = False lbessard@2: lbessard@2: if "project_types" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["project_types"] lbessard@2: 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@2: if "pous_pou" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["pous_pou"] lbessard@2: 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@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@2: if "transitions_transition" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["transitions_transition"] lbessard@2: 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: if "actions_action" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["actions_action"] lbessard@2: 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: if "body" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["body"] lbessard@2: 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@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@2: if "comment" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["comment"] 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@2: lbessard@2: if "block" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["block"] 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: if "inputVariables_variable" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["inputVariables_variable"] 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@2: if "outputVariables_variable" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["outputVariables_variable"] 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@2: if "leftPowerRail" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["leftPowerRail"] 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: if "contact" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["contact"] 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@2: if "coil" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["coil"] 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@2: if "rightPowerRail" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["rightPowerRail"] 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: if "step" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["step"] 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: if "transition" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["transition"] 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@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@2: if "selectionDivergence" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["selectionDivergence"] 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: if "selectionConvergence" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["selectionConvergence"] 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: if "simultaneousDivergence" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["simultaneousDivergence"] 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: if "simultaneousDivergence" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["simultaneousConvergence"] 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: if "jumpStep" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["jumpStep"] 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: if "actionBlock_action" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["actionBlock_action"] lbessard@2: 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@2: if "actionBlock" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["actionBlock"] 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@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@2: if "inVariable" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["inVariable"] 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@2: if "outVariable" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["outVariable"] 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@2: if "inOutVariable" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["inOutVariable"] 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@2: if "continuation" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["continuation"] 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: if "connector" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["connector"] 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: if "connection" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["connection"] lbessard@2: 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@2: if "connectionPointIn" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["connectionPointIn"] lbessard@2: 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@2: if "connectionPointOut" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["connectionPointOut"] lbessard@2: 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@2: if "value" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["value"] lbessard@2: 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@2: if "value_arrayValue" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["value_arrayValue"] lbessard@2: 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@2: if "value_structValue" in PLCOpenClasses: lbessard@2: cls = PLCOpenClasses["value_structValue"] lbessard@2: 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)