|
| 1 | +try: |
| 2 | + import lxml |
| 3 | + from lxml import etree |
| 4 | +except ImportError as e: |
| 5 | + print e.message |
| 6 | + |
| 7 | +from AB.Rockwell.XML.Tools import * |
| 8 | +from Base_Template import Base_Template |
| 9 | + |
| 10 | +class Controller(Base_Template): |
| 11 | + ''' |
| 12 | + Controller Template: |
| 13 | + See L5X Manual for Details, |
| 14 | + These members are to be used when defining a Controller. |
| 15 | + ---------------------------------------------------------- |
| 16 | + For Information on this see the provided L5X Manual from Rockwell |
| 17 | + ''' |
| 18 | + def __init__(self, Name, Use = "Context", Description = ""): |
| 19 | + #Initialize Member Attributes |
| 20 | + assert isValidTag(Name) |
| 21 | + self.root = etree.Element('Controller') |
| 22 | + if Description != "": |
| 23 | + self.Desc = etree.SubElement(self.root, 'Description') |
| 24 | + self.setDescription(Description) |
| 25 | + self.root.append(self.Desc) |
| 26 | + |
| 27 | + def addDatatype(self, Datatype): |
| 28 | + assert etree.iselement(Datatype.getLocalRoot()) and Datatype.getLocalRoot().tag == "Datatype" |
| 29 | + if not self.checkIfChild("Datatypes"): |
| 30 | + self.Datatypes = etree.SubElement(self.root, "Datatypes") |
| 31 | + self.Datatypes.append(Datatype.getLocalRoot()) |
| 32 | + |
| 33 | + def addModule(self, Module): |
| 34 | + assert etree.iselement(Module.getLocalRoot()) and Module.getLocalRoot().tag == "Module" |
| 35 | + if not self.checkIfChild("Modules"): |
| 36 | + self.Modules = etree.SubElement(self.root, "Modules") |
| 37 | + self.Modules.append(Module.getLocalRoot()) |
| 38 | + |
| 39 | + |
| 40 | + def addAddOnInstructionDefinition(self, AddOnInstructionDefinition): |
| 41 | + assert etree.iselement(AddOnInstructionDefinition.getLocalRoot()) and AddOnInstructionDefinition.getLocalRoot().tag == "AddOnInstructionDefinition" |
| 42 | + if not self.checkIfChild("AddOnInstructionDefinitions"): |
| 43 | + self.AddOnInstructionDefinitions = etree.SubElement(self.root, "AddOnInstructionDefinitions") |
| 44 | + self.AddOnInstructionDefinitions.append(AddOnInstructionDefinition.getLocalRoot()) |
| 45 | + |
| 46 | + def addTag(self, Tag): |
| 47 | + assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag == "Tag" |
| 48 | + if not self.checkIfChild("Tags"): |
| 49 | + self.Tags = etree.SubElement(self.root, "Tags") |
| 50 | + self.Tags.append(Tag.getLocalRoot()) |
| 51 | + |
| 52 | + def addProgram(self, Program): |
| 53 | + assert etree.iselement(Program.getLocalRoot()) and Program.getLocalRoot().tag == "Program" |
| 54 | + if not self.checkIfChild("Programs"): |
| 55 | + self.Programs = etree.SubElement(self.root, "Programs") |
| 56 | + self.Programs.append(Program.getLocalRoot()) |
| 57 | + |
| 58 | + def addTask(self, Task): |
| 59 | + assert etree.iselement(Task.getLocalRoot()) and Task.getLocalRoot().tag == "Task" |
| 60 | + if not self.checkIfChild("Tasks"): |
| 61 | + self.Tasks = etree.SubElement(self.root, "Tasks") |
| 62 | + self.Tasks.append(Task.getLocalRoot()) |
| 63 | + |
| 64 | + def setParent(self, parent): |
| 65 | + assert etree.iselement(parent) and parent.tag == "Members" |
| 66 | + parent.append(self.getLocalRoot()) |
0 commit comments