Skip to content

Commit

Permalink
Added Support for Programs and Routines [UNTESTED]. All Primary Templ…
Browse files Browse the repository at this point in the history
…ates Built.
  • Loading branch information
root committed Jan 31, 2017
1 parent c1b2f0f commit a95b8ea
Showing 1 changed file with 186 additions and 5 deletions.
191 changes: 186 additions & 5 deletions src/lib/PIA/Rockwell/XML/Templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ def __init__(self, SchemaRevision = "1.0", SoftwareRevision = "30.00"):
def getControllerRoot(self):
return self.Controller

def checkIfChild(self, nodeTag):
assert type(nodeTag) == str
for node in self.root:
if node.tag == NodeTag: return False
return True

def addController(self, Controller):
assert etree.iselement(Controller.getLocalRoot()) and Datatype.getLocalRoot().tag = "Controller"
assert etree.iselement(Controller.getLocalRoot()) and Controller.getLocalRoot().tag = "Controller"
if not self.checkIfChild("Controller"):
self.Controller = etree.SubElement(self.root, "Controller")
self.Controller.append(Datatype)
Expand Down Expand Up @@ -67,25 +73,25 @@ def addDatatype(self, Datatype):
self.Datatypes.append(Datatype)

def addModule(self, Module):
assert etree.iselement(Module.getLocalRoot()) and Datatype.getLocalRoot().tag = "Module"
assert etree.iselement(Module.getLocalRoot()) and Module.getLocalRoot().tag = "Module"
if not self.checkIfChild("Modules"):
self.Modules = etree.SubElement(self.root, "Modules")
self.Modules.append(Datatype)

def addAddOnInstructionDefinition(self, AddOnInstructionDefinition):
assert etree.iselement(AddOnInstructionDefinition.getLocalRoot()) and Datatype.getLocalRoot().tag = "AddOnInstructionDefinition"
assert etree.iselement(AddOnInstructionDefinition.getLocalRoot()) and AddOnInstructionDefinition.getLocalRoot().tag = "AddOnInstructionDefinition"
if not self.checkIfChild("AddOnInstructionDefinitions"):
self.AddOnInstructionDefinitions = etree.SubElement(self.root, "AddOnInstructionDefinitions")
self.AddOnInstructionDefinitions.append(Datatype)

def addProgram(self, Program):
assert etree.iselement(Program.getLocalRoot()) and Datatype.getLocalRoot().tag = "Program"
assert etree.iselement(Program.getLocalRoot()) and Program.getLocalRoot().tag = "Program"
if not self.checkIfChild("Programs"):
self.Programs = etree.SubElement(self.root, "Programs")
self.Programs.append(Datatype)

def addTask(self, Task):
assert etree.iselement(Task.getLocalRoot()) and Datatype.getLocalRoot().tag = "Task"
assert etree.iselement(Task.getLocalRoot()) and Task.getLocalRoot().tag = "Task"
if not self.checkIfChild("Tasks"):
self.Tasks = etree.SubElement(self.root, "Tasks")
self.Tasks.append(Datatype)
Expand Down Expand Up @@ -281,6 +287,181 @@ def getLocalRoot(self):
def __str__(self):
return etree.tostring(self.root, pretty_print = True)

class Program():
'''
Program Template:
See L5X Manual for Details,
These members are to be used when defining a datatype.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Name, Type = "Normal", Description = ""):
#Initialize Member Attributes
assert isValidTag(Name)
self.root = etree.Element("Program")
self.root.set("Name", Name)
self.root.set("Type", Type)
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def setMainRoutine(self, RoutineName):
assert type(RoutineName) == str
self.root.set("MainRoutineName", RoutineName)

def checkIfChild(self, nodeTag):
assert type(nodeTag) == str
for node in self.root:
if node.tag == NodeTag: return False
return True

def addRoutine(self, Routine):
assert etree.iselement(Routine.getLocalRoot()) and Routine.getLocalRoot().tag = "Routine"
if not self.checkIfChild("Routines"):
self.Routines = etree.SubElement(self.root, "Routines")
self.Routines.append(Routine)

def addTag(self, Tag):
assert etree.iselement(Tag.getLocalRoot()) and Tag.getLocalRoot().tag = "Tag"
if not self.checkIfChild("Tags"):
self.Tags = etree.SubElement(self.root, "Tags")
self.Tags.append(Tag)

def setAttribute(self, **kwargs):
for key in kwargs:
if not key in self.root.keys():
raise KeyError("Program has No Attribute: <%s>" % key)

for key in kwargs:
self.root.set(key, kwargs[key])

def setDescription(self, Description):
assert type(Description) == str
if self.Desc == None:
self.Desc = etree.SubElement(self.root, 'Description')
self.root.append(self.Desc)
self.Desc.text = etree.CDATA(Description)

def setParent(self, parent):
assert etree.iselement(root) and root.tag == "Programs"
root.append(self.root)

def getLocalRoot(self):
return self.root

def __str__(self):
return etree.tostring(self.root, pretty_print = True)

class Routine():
'''
Routine Template:
See L5X Manual for Details,
These members are to be used when defining a datatype.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Name, Description = ""):
#Initialize Member Attributes
assert isValidTag(Name)
self.root = etree.Element("Routine")
self.root.set("Name", Name)
self.root.set("Type", "RLL")
if Description != "":
self.Desc = etree.SubElement(self.root, 'Description')
self.setDescription(Description)
self.root.append(self.Desc)

def checkIfChild(self, nodeTag):
assert type(nodeTag) == str
for node in self.root:
if node.tag == NodeTag: return False
return True

def addRung(self, Rung):
assert etree.iselement(Rung.getLocalRoot()) and Rung.getLocalRoot().tag = "Rung"
if not self.checkIfChild("RLLContent"):
self.RLLContent = etree.SubElement(self.root, "RLLContent")
self.RLLContent.append(Rung)

def setAttribute(self, **kwargs):
for key in kwargs:
if not key in self.root.keys():
raise KeyError("Routine has No Attribute: <%s>" % key)

for key in kwargs:
self.root.set(key, kwargs[key])

def setDescription(self, Description):
assert type(Description) == str
if self.Desc == None:
self.Desc = etree.SubElement(self.root, 'Description')
self.root.append(self.Desc)
self.Desc.text = etree.CDATA(Description)

def setParent(self, parent):
assert etree.iselement(root) and root.tag == "Routines"
root.append(self.root)

def getLocalRoot(self):
return self.root

def __str__(self):
return etree.tostring(self.root, pretty_print = True)

class Rung():
'''
Rung Template:
See L5X Manual for Details,
These members are to be used when defining a datatype.
----------------------------------------------------------
For Information on this see the provided L5X Manual from Rockwell
'''
def __init__(self, Number, Comment = "", Content = "NOP();"):
#Initialize Member Attributes
assert isValidTag(TypeName)
self.root = etree.Element("Rung")
self.root.set("Number", str(Number))
self.root.set("Type", "N")
if Comment != "":
self.Comment = etree.SubElement(self.root, 'Comment')
self.setComment(Comment)
self.root.append(self.Comment)

self.rungContent = etree.SubElement(self.root, "Text")
self.setRungContent(Content)

def setRungContent(self, Content):
assert type(Content) == str
self.rungContent.text = etree.CDATA(Content)

def setAttribute(self, **kwargs):
for key in kwargs:
if not key in self.root.keys():
raise KeyError("Rung has No Attribute: <%s>" % key)

for key in kwargs:
self.root.set(key, kwargs[key])

def setComment(self, Comment):
assert type(Comment) == str
if self.Comment == None:
self.Comment = etree.SubElement(self.root, 'Comment')
self.root.append(self.Comment)
self.Comment.text = etree.CDATA(Comment)

def setParent(self, parent):
assert etree.iselement(root) and root.tag == "RLLContent"
root.append(self.root)

def getLocalRoot(self):
return self.root

def __str__(self):
return etree.tostring(self.root, pretty_print = True)




# class Datatype():
# def __init__(self,):

0 comments on commit a95b8ea

Please sign in to comment.