--- a/plcopen/plcopen.py Fri Aug 11 15:18:19 2017 +0300
+++ b/plcopen/plcopen.py Mon Aug 14 19:13:01 2017 +0300
@@ -49,14 +49,14 @@
VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
"""
-Define which action qualifier must be associated with a duration
+Define which action qualifier must be associated with a duration
"""
-QualifierList = OrderedDict([("N", False), ("R", False), ("S", False),
- ("L", True), ("D", True), ("P", False), ("P0", False),
+QualifierList = OrderedDict([("N", False), ("R", False), ("S", False),
+ ("L", True), ("D", True), ("P", False), ("P0", False),
("P1", False), ("SD", True), ("DS", True), ("SL", True)])
-FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)"
+FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)"
def update_address(address, address_model, new_leading):
result = address_model.match(address)
@@ -73,10 +73,10 @@
return v1
"""
-Helper class for bounding_box calculation
+Helper class for bounding_box calculation
"""
class rect:
-
+
def __init__(self, x=None, y=None, width=None, height=None):
self.x_min = x
self.x_max = None
@@ -86,19 +86,19 @@
self.x_max = x + width
if height is not None and y is not None:
self.y_max = y + height
-
+
def update(self, x, y):
self.x_min = _init_and_compare(min, self.x_min, x)
self.x_max = _init_and_compare(max, self.x_max, x)
self.y_min = _init_and_compare(min, self.y_min, y)
self.y_max = _init_and_compare(max, self.y_max, y)
-
+
def union(self, rect):
self.x_min = _init_and_compare(min, self.x_min, rect.x_min)
self.x_max = _init_and_compare(max, self.x_max, rect.x_max)
self.y_min = _init_and_compare(min, self.y_min, rect.y_min)
self.y_max = _init_and_compare(max, self.y_max, rect.y_max)
-
+
def bounding_box(self):
width = height = None
if self.x_min is not None and self.x_max is not None:
@@ -125,7 +125,7 @@
test_result = []
result = criteria["pattern"].search(text)
while result is not None:
- prev_pos=result.endpos
+ prev_pos=result.endpos
start = TextLenInRowColumn(text[:result.start()])
end = TextLenInRowColumn(text[:result.end() - 1])
test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1])))
@@ -141,11 +141,11 @@
PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
LOAD_POU_PROJECT_TEMPLATE = """
-<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201"
- xmlns:xhtml="http://www.w3.org/1999/xhtml"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.plcopen.org/xml/tc6_0201">
- <fileHeader companyName="" productName="" productVersion=""
+ <fileHeader companyName="" productName="" productVersion=""
creationDateTime="1970-01-01T00:00:00"/>
<contentHeader name="paste_project">
<coordinateInfo>
@@ -176,8 +176,8 @@
PLCOpen_v1_xml = PLCOpen_v1_file.read()
PLCOpen_v1_file.close()
PLCOpen_v1_xml = PLCOpen_v1_xml.replace(
- "http://www.plcopen.org/xml/tc6.xsd",
- "http://www.plcopen.org/xml/tc6_0201")
+ "http://www.plcopen.org/xml/tc6.xsd",
+ "http://www.plcopen.org/xml/tc6_0201")
PLCOpen_v1_xsd = etree.XMLSchema(etree.fromstring(PLCOpen_v1_xml))
# XPath for file compatibility process
@@ -190,21 +190,21 @@
def LoadProjectXML(project_xml):
project_xml = project_xml.replace(
- "http://www.plcopen.org/xml/tc6.xsd",
+ "http://www.plcopen.org/xml/tc6.xsd",
"http://www.plcopen.org/xml/tc6_0201")
for cre, repl in [
(re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
(re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
project_xml = cre.sub(repl, project_xml)
-
+
try:
tree, error = PLCOpenParser.LoadXMLString(project_xml)
if error is None:
return tree, None
-
+
if PLCOpen_v1_xsd.validate(tree):
# Make file compatible with PLCOpen v2
-
+
# Update resource interval value
for resource in ProjectResourcesXPath(tree):
for task in resource.gettask():
@@ -229,13 +229,13 @@
else:
text += "%dms"%(time_values[3] / 1000)
task.set("interval", text)
-
+
# Update resources pou instance attributes
for pouInstance in ResourceInstancesXpath(resource):
type_name = pouInstance.attrib.pop("type")
if type_name is not None:
pouInstance.set("typeName", type_name)
-
+
# Update transitions condition
for transition_condition in TransitionsConditionXPath(tree):
connections = ConditionConnectionsXPath(transition_condition)
@@ -245,23 +245,23 @@
connectionPointIn.setrelPositionXY(0, 0)
for connection in connections:
connectionPointIn.append(connection)
-
+
# Update actionBlocks
for actionBlock in ActionBlocksXPath(tree):
for connectionPointOut in ActionBlocksConnectionPointOutXPath(actionBlock):
actionBlock.remove(connectionPointOut)
-
+
for action in actionBlock.getaction():
action.set("localId", "0")
relPosition = PLCOpenParser.CreateElement("relPosition", "action")
relPosition.set("x", "0")
relPosition.set("y", "0")
action.setrelPosition(relPosition)
-
+
return tree, None
-
+
return tree, error
-
+
except Exception, e:
return None, e.message
@@ -288,9 +288,9 @@
def SaveProject(project, filepath):
project_file = open(filepath, 'w')
project_file.write(etree.tostring(
- project,
- pretty_print=True,
- xml_declaration=True,
+ project,
+ pretty_print=True,
+ xml_declaration=True,
encoding='utf-8'))
project_file.close()
@@ -302,7 +302,7 @@
text = pattern.sub(new_name, text)
self.setanyText(text)
setattr(cls, "updateElementName", updateElementName)
-
+
def updateElementAddress(self, address_model, new_leading):
text = self.getanyText()
startpos = 0
@@ -315,28 +315,28 @@
result = address_model.search(text, startpos)
self.setanyText(text)
setattr(cls, "updateElementAddress", updateElementAddress)
-
+
def hasblock(self, block_type):
- text = self.getanyText()
+ text = self.getanyText()
pattern = re.compile('\\b' + block_type + '\\b', re.IGNORECASE)
return pattern.search(text) is not None
setattr(cls, "hasblock", hasblock)
-
+
def Search(self, criteria, parent_infos):
return [(tuple(parent_infos),) + result for result in TestTextElement(self.getanyText(), criteria)]
setattr(cls, "Search", Search)
-
+
cls = PLCOpenParser.GetElementClass("project")
if cls:
-
+
def setname(self, name):
self.contentHeader.setname(name)
setattr(cls, "setname", setname)
-
+
def getname(self):
return self.contentHeader.getname()
setattr(cls, "getname", getname)
-
+
def getfileHeader(self):
fileheader_obj = self.fileHeader
return {
@@ -351,7 +351,7 @@
("contentDescription", fileheader_obj.getcontentDescription())]
}
setattr(cls, "getfileHeader", getfileHeader)
-
+
def setfileHeader(self, fileheader):
fileheader_obj = self.fileHeader
for attr in ["companyName", "companyURL", "productName",
@@ -361,7 +361,7 @@
if value is not None:
setattr(fileheader_obj, attr, value)
setattr(cls, "setfileHeader", setfileHeader)
-
+
def getcontentHeader(self):
contentheader_obj = self.contentHeader
contentheader = {
@@ -378,7 +378,7 @@
contentheader["scaling"] = self.contentHeader.getscaling()
return contentheader
setattr(cls, "getcontentHeader", getcontentHeader)
-
+
def setcontentHeader(self, contentheader):
contentheader_obj = self.contentHeader
for attr, value in contentheader.iteritems():
@@ -392,7 +392,7 @@
elif attr in ["modificationDateTime", "organization", "language"]:
setattr(contentheader_obj, attr, value)
setattr(cls, "setcontentHeader", setcontentHeader)
-
+
def gettypeElementFunc(element_type):
elements_xpath = PLCOpen_XPath(
"ppx:types/ppx:%(element_type)ss/ppx:%(element_type)s[@name=$name]" % locals())
@@ -402,7 +402,7 @@
return elements[0]
return None
return gettypeElement
-
+
datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType")
filtered_datatypes_xpath = PLCOpen_XPath(
"ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]")
@@ -411,43 +411,43 @@
return filtered_datatypes_xpath(self, exclude=exclude)
return datatypes_xpath(self)
setattr(cls, "getdataTypes", getdataTypes)
-
+
setattr(cls, "getdataType", gettypeElementFunc("dataType"))
-
+
def appenddataType(self, name):
if self.getdataType(name) is not None:
raise ValueError, "\"%s\" Data Type already exists !!!"%name
self.types.appenddataTypeElement(name)
setattr(cls, "appenddataType", appenddataType)
-
+
def insertdataType(self, index, datatype):
self.types.insertdataTypeElement(index, datatype)
setattr(cls, "insertdataType", insertdataType)
-
+
def removedataType(self, name):
self.types.removedataTypeElement(name)
setattr(cls, "removedataType", removedataType)
-
+
def getpous(self, exclude=None, filter=[]):
return self.xpath(
- "ppx:types/ppx:pous/ppx:pou%s%s" %
+ "ppx:types/ppx:pous/ppx:pou%s%s" %
(("[@name!='%s']" % exclude) if exclude is not None else '',
("[%s]" % " or ".join(
map(lambda x: "@pouType='%s'" % x, filter)))
if len(filter) > 0 else ""),
namespaces=PLCOpenParser.NSMAP)
setattr(cls, "getpous", getpous)
-
+
setattr(cls, "getpou", gettypeElementFunc("pou"))
-
+
def appendpou(self, name, pou_type, body_type):
self.types.appendpouElement(name, pou_type, body_type)
setattr(cls, "appendpou", appendpou)
-
+
def insertpou(self, index, pou):
self.types.insertpouElement(index, pou)
setattr(cls, "insertpou", insertpou)
-
+
def removepou(self, name):
self.types.removepouElement(name)
setattr(cls, "removepou", removepou)
@@ -473,7 +473,7 @@
new_configuration = PLCOpenParser.CreateElement("configuration", "configurations")
new_configuration.setname(name)
self.instances.configurations.appendconfiguration(new_configuration)
- setattr(cls, "addconfiguration", addconfiguration)
+ setattr(cls, "addconfiguration", addconfiguration)
def removeconfiguration(self, name):
configuration = self.getconfiguration(name)
@@ -481,7 +481,7 @@
raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name
self.instances.configurations.remove(configuration)
setattr(cls, "removeconfiguration", removeconfiguration)
-
+
resources_xpath = PLCOpen_XPath(
"ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]")
def getconfigurationResource(self, config_name, name):
@@ -562,11 +562,11 @@
cls = PLCOpenParser.GetElementClass("contentHeader", "project")
if cls:
-
+
def setpageSize(self, width, height):
self.coordinateInfo.setpageSize(width, height)
setattr(cls, "setpageSize", setpageSize)
-
+
def getpageSize(self):
return self.coordinateInfo.getpageSize()
setattr(cls, "getpageSize", getpageSize)
@@ -575,7 +575,7 @@
for language, (x, y) in scaling.items():
self.coordinateInfo.setscaling(language, x, y)
setattr(cls, "setscaling", setscaling)
-
+
def getscaling(self):
scaling = {}
scaling["FBD"] = self.coordinateInfo.getscaling("FBD")
@@ -595,7 +595,7 @@
self.pageSize.setx(width)
self.pageSize.sety(height)
setattr(cls, "setpageSize", setpageSize)
-
+
def getpageSize(self):
if self.pageSize is not None:
return self.pageSize.getx(), self.pageSize.gety()
@@ -613,7 +613,7 @@
self.sfc.scaling.setx(x)
self.sfc.scaling.sety(y)
setattr(cls, "setscaling", setscaling)
-
+
def getscaling(self, language):
if language == "FBD":
return self.fbd.scaling.getx(), self.fbd.scaling.gety()
@@ -685,7 +685,7 @@
cls = PLCOpenParser.GetElementClass("configuration", "configurations")
if cls:
-
+
def addglobalVar(self, var_type, name, location="", description=""):
globalvars = self.getglobalVars()
if len(globalvars) == 0:
@@ -701,7 +701,7 @@
var.setdocumentation(ft)
globalvars[-1].appendvariable(var)
setattr(cls, "addglobalVar", addglobalVar)
-
+
def updateElementName(self, old_name, new_name):
_updateConfigurationResourceElementName(self, old_name, new_name)
for resource in self.getresource():
@@ -727,7 +727,7 @@
search_result.extend(resource.Search(criteria, parent_infos))
return search_result
setattr(cls, "Search", Search)
-
+
cls = PLCOpenParser.GetElementClass("resource", "configuration")
if cls:
def updateElementName(self, old_name, new_name):
@@ -788,7 +788,7 @@
setattr(cls, "updateElementAddress", updateElementAddress)
def Search(self, criteria, parent_infos=[]):
- return _Search([("single", self.getsingle()),
+ return _Search([("single", self.getsingle()),
("interval", self.getinterval()),
("priority", str(self.getpriority()))],
criteria, parent_infos)
@@ -802,7 +802,7 @@
setattr(cls, "updateElementName", updateElementName)
def Search(self, criteria, parent_infos=[]):
- return _Search([("name", self.getname()),
+ return _Search([("name", self.getname()),
("type", self.gettypeName())],
criteria, parent_infos)
setattr(cls, "Search", Search)
@@ -822,22 +822,22 @@
elif vartype_content_name == "array":
base_type = vartype_content.baseType.getcontent()
base_type_name = base_type.getLocalTag()
- # Array derived directly from a user defined type
+ # Array derived directly from a user defined type
if base_type_name == "derived":
basetype_name = base_type.getname()
- # Array derived directly from a string type
+ # Array derived directly from a string type
elif base_type_name in ["string", "wstring"]:
basetype_name = base_type_name.upper()
- # Array derived directly from an elementary type
+ # Array derived directly from an elementary type
else:
basetype_name = base_type_name
return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "%s..%s" % (x.getlower(), x.getupper()), vartype_content.getdimension())), basetype_name)
# Variable type is an elementary type
return vartype_content_name
setattr(cls, "gettypeAsText", gettypeAsText)
-
+
def Search(self, criteria, parent_infos=[]):
- search_result = _Search([("name", self.getname()),
+ search_result = _Search([("name", self.getname()),
("type", self.gettypeAsText()),
("location", self.getaddress())],
criteria, parent_infos)
@@ -855,7 +855,7 @@
def getdataTypeElements(self):
return self.dataTypes.getdataType()
setattr(cls, "getdataTypeElements", getdataTypeElements)
-
+
def getdataTypeElement(self, name):
elements = self.dataTypes.getdataType()
for element in elements:
@@ -870,11 +870,11 @@
new_datatype.setname(name)
new_datatype.baseType.setcontent(PLCOpenParser.CreateElement("BOOL", "dataType"))
setattr(cls, "appenddataTypeElement", appenddataTypeElement)
-
+
def insertdataTypeElement(self, index, dataType):
self.dataTypes.insertdataType(index, dataType)
setattr(cls, "insertdataTypeElement", insertdataTypeElement)
-
+
def removedataTypeElement(self, name):
found = False
for element in self.dataTypes.getdataType():
@@ -885,11 +885,11 @@
if not found:
raise ValueError, _("\"%s\" Data Type doesn't exist !!!")%name
setattr(cls, "removedataTypeElement", removedataTypeElement)
-
+
def getpouElements(self):
return self.pous.getpou()
setattr(cls, "getpouElements", getpouElements)
-
+
def getpouElement(self, name):
elements = self.pous.getpou()
for element in elements:
@@ -909,11 +909,11 @@
new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou"))
new_pou.setbodyType(body_type)
setattr(cls, "appendpouElement", appendpouElement)
-
+
def insertpouElement(self, index, pou):
self.pous.insertpou(index, pou)
setattr(cls, "insertpouElement", insertpouElement)
-
+
def removepouElement(self, name):
found = False
for element in self.pous.getpou():
@@ -941,7 +941,7 @@
cls = PLCOpenParser.GetElementClass("dataType", "dataTypes")
if cls:
setattr(cls, "updateElementName", _updateBaseTypeElementName)
-
+
def Search(self, criteria, parent_infos=[]):
search_result = []
filter = criteria["filter"]
@@ -956,7 +956,7 @@
cls = PLCOpenParser.GetElementClass("dataType")
if cls:
-
+
def updateElementName(self, old_name, new_name):
content_name = self.content.getLocalTag()
if content_name in ["derived", "array", "subrangeSigned", "subrangeUnsigned"]:
@@ -987,7 +987,7 @@
if TextMatched(self.name, old_name):
self.name = new_name
setattr(cls, "updateElementName", updateElementName)
-
+
def Search(self, criteria, parent_infos=[]):
return [(tuple(parent_infos),) + result for result in TestTextElement(self.name, criteria)]
setattr(cls, "Search", Search)
@@ -995,7 +995,7 @@
cls = PLCOpenParser.GetElementClass("array", "dataType")
if cls:
setattr(cls, "updateElementName", _updateBaseTypeElementName)
-
+
def Search(self, criteria, parent_infos=[]):
search_result = self.baseType.Search(criteria, parent_infos)
for i, dimension in enumerate(self.getdimension()):
@@ -1024,11 +1024,11 @@
cls = PLCOpenParser.GetElementClass("enum", "dataType")
if cls:
-
+
def updateElementName(self, old_name, new_name):
pass
setattr(cls, "updateElementName", updateElementName)
-
+
enumerated_datatype_values_xpath = PLCOpen_XPath("ppx:values/ppx:value")
def Search(self, criteria, parent_infos=[]):
search_result = []
@@ -1044,21 +1044,21 @@
if type_content_type == "derived":
return type_content.getname()
return type_content_type.upper()
-
+
cls = PLCOpenParser.GetElementClass("pou", "pous")
if cls:
-
+
block_inputs_xpath = PLCOpen_XPath(
"ppx:interface/*[self::ppx:inputVars or self::ppx:inOutVars]/ppx:variable")
block_outputs_xpath = PLCOpen_XPath(
"ppx:interface/*[self::ppx:outputVars or self::ppx:inOutVars]/ppx:variable")
- def getblockInfos(self):
+ def getblockInfos(self):
block_infos = {
- "name" : self.getname(),
- "type" : self.getpouType(),
+ "name" : self.getname(),
+ "type" : self.getpouType(),
"extensible" : False,
- "inputs" : [],
- "outputs" : [],
+ "inputs" : [],
+ "outputs" : [],
"comment" : self.getdescription()}
if self.interface is not None:
return_type = self.interface.getreturnType()
@@ -1071,15 +1071,15 @@
block_infos["outputs"].extend(
[(var.getname(), _getvariableTypeinfos(var.type), "none")
for var in block_outputs_xpath(self)])
-
- block_infos["usage"] = ("\n (%s) => (%s)" %
- (", ".join(["%s:%s" % (input[1], input[0])
+
+ block_infos["usage"] = ("\n (%s) => (%s)" %
+ (", ".join(["%s:%s" % (input[1], input[0])
for input in block_infos["inputs"]]),
- ", ".join(["%s:%s" % (output[1], output[0])
+ ", ".join(["%s:%s" % (output[1], output[0])
for output in block_infos["outputs"]])))
return block_infos
setattr(cls, "getblockInfos", getblockInfos)
-
+
def setdescription(self, description):
doc = self.getdocumentation()
if doc is None:
@@ -1087,14 +1087,14 @@
self.setdocumentation(doc)
doc.setanyText(description)
setattr(cls, "setdescription", setdescription)
-
+
def getdescription(self):
doc = self.getdocumentation()
if doc is not None:
return doc.getanyText()
return ""
setattr(cls, "getdescription", getdescription)
-
+
def setbodyType(self, body_type):
if len(self.body) > 0:
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]:
@@ -1102,66 +1102,66 @@
else:
raise ValueError, "%s isn't a valid body type!"%type
setattr(cls, "setbodyType", setbodyType)
-
+
def getbodyType(self):
if len(self.body) > 0:
return self.body[0].getcontent().getLocalTag()
setattr(cls, "getbodyType", getbodyType)
-
+
def resetexecutionOrder(self):
if len(self.body) > 0:
self.body[0].resetexecutionOrder()
setattr(cls, "resetexecutionOrder", resetexecutionOrder)
-
+
def compileexecutionOrder(self):
if len(self.body) > 0:
self.body[0].compileexecutionOrder()
setattr(cls, "compileexecutionOrder", compileexecutionOrder)
-
+
def setelementExecutionOrder(self, instance, new_executionOrder):
if len(self.body) > 0:
self.body[0].setelementExecutionOrder(instance, new_executionOrder)
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
-
+
def addinstance(self, instance):
if len(self.body) > 0:
self.body[0].appendcontentInstance(instance)
setattr(cls, "addinstance", addinstance)
-
+
def getinstances(self):
if len(self.body) > 0:
return self.body[0].getcontentInstances()
return []
setattr(cls, "getinstances", getinstances)
-
+
def getinstance(self, id):
if len(self.body) > 0:
return self.body[0].getcontentInstance(id)
return None
setattr(cls, "getinstance", getinstance)
-
+
def getinstancesIds(self):
if len(self.body) > 0:
return self.body[0].getcontentInstancesIds()
return []
setattr(cls, "getinstancesIds", getinstancesIds)
-
+
def getinstanceByName(self, name):
if len(self.body) > 0:
return self.body[0].getcontentInstanceByName(name)
return None
setattr(cls, "getinstanceByName", getinstanceByName)
-
+
def removeinstance(self, id):
if len(self.body) > 0:
self.body[0].removecontentInstance(id)
setattr(cls, "removeinstance", removeinstance)
-
+
def settext(self, text):
if len(self.body) > 0:
self.body[0].settext(text)
setattr(cls, "settext", settext)
-
+
def gettext(self):
if len(self.body) > 0:
return self.body[0].gettext()
@@ -1178,17 +1178,17 @@
vars.append((reverse_types[varlist.getLocalTag()], varlist))
return vars
setattr(cls, "getvars", getvars)
-
+
def setvars(self, vars):
if self.interface is None:
self.interface = PLCOpenParser.CreateElement("interface", "pou")
self.interface.setcontent(vars)
setattr(cls, "setvars", setvars)
-
+
def addpouExternalVar(self, var_type, name):
self.addpouVar(var_type, name, "externalVars")
setattr(cls, "addpouExternalVar", addpouExternalVar)
-
+
def addpouVar(self, var_type, name, var_class="localVars", location="", description="", initval=""):
if self.interface is None:
self.interface = PLCOpenParser.CreateElement("interface", "pou")
@@ -1218,11 +1218,11 @@
el = PLCOpenParser.CreateElement("initialValue", "variable")
el.setvalue(initval)
var.setinitialValue(el)
-
+
varlist.appendvariable(var)
setattr(cls, "addpouVar", addpouVar)
setattr(cls, "addpouLocalVar", addpouVar)
-
+
def changepouVar(self, old_type, old_name, new_type, new_name):
if self.interface is not None:
content = self.interface.getcontent()
@@ -1236,7 +1236,7 @@
vartype_content.setname(new_type)
return
setattr(cls, "changepouVar", changepouVar)
-
+
def removepouVar(self, var_type, name):
if self.interface is not None:
content = self.interface.getcontent()
@@ -1255,14 +1255,14 @@
if self.getbodyType() in ["SFC"]:
for instance in self.getinstances():
if isinstance(instance, PLCOpenParser.GetElementClass("step", "sfcObjects")) and TextMatched(instance.getname(), name):
- return True
+ return True
return False
setattr(cls, "hasstep", hasstep)
-
+
def hasblock(self, name=None, block_type=None):
if self.getbodyType() in ["FBD", "LD", "SFC"]:
for instance in self.getinstances():
- if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and
+ if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and
(TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type))):
return True
if self.transitions:
@@ -1279,7 +1279,7 @@
return self.body[0].hasblock(block_type)
return False
setattr(cls, "hasblock", hasblock)
-
+
def addtransition(self, name, body_type):
if self.transitions is None:
self.addtransitions()
@@ -1291,7 +1291,7 @@
if body_type == "ST":
transition.settext(":= ;")
setattr(cls, "addtransition", addtransition)
-
+
def gettransition(self, name):
if self.transitions is not None:
for transition in self.transitions.gettransition():
@@ -1299,13 +1299,13 @@
return transition
return None
setattr(cls, "gettransition", gettransition)
-
+
def gettransitionList(self):
if self.transitions is not None:
return self.transitions.gettransition()
return []
setattr(cls, "gettransitionList", gettransitionList)
-
+
def removetransition(self, name):
if self.transitions is not None:
removed = False
@@ -1314,7 +1314,7 @@
if transition.getbodyType() in ["FBD", "LD", "SFC"]:
for instance in transition.getinstances():
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")):
- self.removepouVar(instance.gettypeName(),
+ self.removepouVar(instance.gettypeName(),
instance.getinstanceName())
self.transitions.remove(transition)
removed = True
@@ -1332,7 +1332,7 @@
action.setname(name)
action.setbodyType(body_type)
setattr(cls, "addaction", addaction)
-
+
def getaction(self, name):
if self.actions is not None:
for action in self.actions.getaction():
@@ -1340,13 +1340,13 @@
return action
return None
setattr(cls, "getaction", getaction)
-
+
def getactionList(self):
if self.actions is not None:
return self.actions.getaction()
return []
setattr(cls, "getactionList", getactionList)
-
+
def removeaction(self, name):
if self.actions is not None:
removed = False
@@ -1355,7 +1355,7 @@
if action.getbodyType() in ["FBD", "LD", "SFC"]:
for instance in action.getinstances():
if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")):
- self.removepouVar(instance.gettypeName(),
+ self.removepouVar(instance.gettypeName(),
instance.getinstanceName())
self.actions.remove(action)
removed = True
@@ -1417,7 +1417,7 @@
if result is not None:
content.remove(variable)
setattr(cls, "removeVariableByFilter", removeVariableByFilter)
-
+
def Search(self, criteria, parent_infos=[]):
search_result = []
filter = criteria["filter"]
@@ -1494,7 +1494,7 @@
def hasblock(self, name=None, block_type=None):
if self.getbodyType() in ["FBD", "LD", "SFC"]:
for instance in self.getinstances():
- if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and
+ if (isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")) and
(TextMatched(instance.getinstanceName(), name) or TextMatched(instance.gettypeName(), block_type))):
return True
elif block_type is not None:
@@ -1506,7 +1506,7 @@
def updateElementAddress(self, address_model, new_leading):
self.body.updateElementAddress(address_model, new_leading)
-
+
cls = PLCOpenParser.GetElementClass("transition", "transitions")
if cls:
@@ -1526,7 +1526,7 @@
setattr(cls, "hasblock", hasblock)
setattr(cls, "updateElementName", updateElementName)
setattr(cls, "updateElementAddress", updateElementAddress)
-
+
def Search(self, criteria, parent_infos):
search_result = []
parent_infos = parent_infos[:-1] + ["T::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())]
@@ -1554,7 +1554,7 @@
setattr(cls, "hasblock", hasblock)
setattr(cls, "updateElementName", updateElementName)
setattr(cls, "updateElementAddress", updateElementAddress)
-
+
def Search(self, criteria, parent_infos):
search_result = []
parent_infos = parent_infos[:-1] + ["A::%s::%s" % (parent_infos[-1].split("::")[1], self.getname())]
@@ -1571,24 +1571,24 @@
def resetcurrentExecutionOrderId(self):
object.__setattr__(self, "currentExecutionOrderId", 0)
setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
-
+
def getnewExecutionOrderId(self):
object.__setattr__(self, "currentExecutionOrderId", self.currentExecutionOrderId + 1)
return self.currentExecutionOrderId
setattr(cls, "getnewExecutionOrderId", getnewExecutionOrderId)
-
+
def resetexecutionOrder(self):
if self.content.getLocalTag() == "FBD":
for element in self.content.getcontent():
- if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"),
- PLCOpenParser.GetElementClass("connector", "commonObjects"),
+ if not isinstance(element, (PLCOpenParser.GetElementClass("comment", "commonObjects"),
+ PLCOpenParser.GetElementClass("connector", "commonObjects"),
PLCOpenParser.GetElementClass("continuation", "commonObjects"))):
element.setexecutionOrderId(0)
self.checkedBlocksDict.clear()
else:
raise TypeError, _("Can only generate execution order on FBD networks!")
setattr(cls, "resetexecutionOrder", resetexecutionOrder)
-
+
def compileexecutionOrder(self):
if self.content.getLocalTag() == "FBD":
self.resetexecutionOrder()
@@ -1602,7 +1602,7 @@
else:
raise TypeError, _("Can only generate execution order on FBD networks!")
setattr(cls, "compileexecutionOrder", compileexecutionOrder)
-
+
def compileelementExecutionOrder(self, link):
if self.content.getLocalTag() == "FBD":
localid = link.getrefLocalId()
@@ -1626,7 +1626,7 @@
else:
raise TypeError, _("Can only generate execution order on FBD networks!")
setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder)
-
+
def setelementExecutionOrder(self, instance, new_executionOrder):
if self.content.getLocalTag() == "FBD":
old_executionOrder = instance.getexecutionOrderId()
@@ -1642,21 +1642,21 @@
else:
raise TypeError, _("Can only generate execution order on FBD networks!")
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
-
+
def appendcontentInstance(self, instance):
if self.content.getLocalTag() in ["LD","FBD","SFC"]:
self.content.appendcontent(instance)
else:
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "appendcontentInstance", appendcontentInstance)
-
+
def getcontentInstances(self):
if self.content.getLocalTag() in ["LD","FBD","SFC"]:
return self.content.getcontent()
else:
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "getcontentInstances", getcontentInstances)
-
+
instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]")
def getcontentInstance(self, local_id):
@@ -1668,7 +1668,7 @@
else:
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "getcontentInstance", getcontentInstance)
-
+
def getcontentInstancesIds(self):
if self.content.getLocalTag() in ["LD","FBD","SFC"]:
return OrderedDict([(instance.getlocalId(), True)
@@ -1676,7 +1676,7 @@
else:
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "getcontentInstancesIds", getcontentInstancesIds)
-
+
def getcontentInstanceByName(self, name):
if self.content.getLocalTag() in ["LD","FBD","SFC"]:
instance = instance_by_name_xpath(self.content)
@@ -1686,7 +1686,7 @@
else:
raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag()
setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
-
+
def removecontentInstance(self, local_id):
if self.content.getLocalTag() in ["LD","FBD","SFC"]:
instance = instance_by_id_xpath(self.content, localId=local_id)
@@ -1697,7 +1697,7 @@
else:
raise TypeError, "%s body don't have instances!"%self.content.getLocalTag()
setattr(cls, "removecontentInstance", removecontentInstance)
-
+
def settext(self, text):
if self.content.getLocalTag() in ["IL","ST"]:
self.content.setanyText(text)
@@ -1711,14 +1711,14 @@
else:
raise TypeError, _("%s body don't have text!")%self.content.getLocalTag()
setattr(cls, "gettext", gettext)
-
+
def hasblock(self, block_type):
if self.content.getLocalTag() in ["IL","ST"]:
return self.content.hasblock(block_type)
else:
raise TypeError, _("%s body don't have text!")%self.content.getLocalTag()
setattr(cls, "hasblock", hasblock)
-
+
def updateElementName(self, old_name, new_name):
if self.content.getLocalTag() in ["IL", "ST"]:
self.content.updateElementName(old_name, new_name)
@@ -1753,7 +1753,7 @@
def setx(self, x):
self.position.setx(x)
-
+
def sety(self, y):
self.position.sety(y)
@@ -1828,7 +1828,7 @@
def _translate(self, dx, dy):
self.setx(self.getx() + dx)
self.sety(self.gety() + dy)
-
+
def _translateConnections(connectionPointIn, dx, dy):
connections = connectionPointIn.getconnections()
if connections is not None:
@@ -1892,11 +1892,11 @@
def setcontentText(self, text):
self.content.setanyText(text)
setattr(cls, "setcontentText", setcontentText)
-
+
def getcontentText(self):
return self.content.getanyText()
setattr(cls, "getcontentText", getcontentText)
-
+
def updateElementName(self, old_name, new_name):
self.content.updateElementName(old_name, new_name)
setattr(cls, "updateElementName", updateElementName)
@@ -2004,7 +2004,7 @@
condition.setcontent(PLCOpenParser.CreateElement("ST", "inline"))
condition.settext(value)
setattr(cls, "setconditionContent", setconditionContent)
-
+
def getconditionContent(self):
if self.condition is not None:
content = self.condition.getcontent()
@@ -2035,21 +2035,21 @@
bbox.union(_getConnectionsBoundingBox(condition_connection))
return bbox
setattr(cls, "getBoundingBox", getBoundingBox)
-
+
def translate(self, dx, dy):
_translateSingle(self, dx, dy)
condition_connection = self.getconditionConnection()
if condition_connection is not None:
_translateConnections(condition_connection, dx, dy)
setattr(cls, "translate", translate)
-
+
def filterConnections(self, connections):
_filterConnectionsSingle(self, connections)
condition_connection = self.getconditionConnection()
if condition_connection is not None:
_filterConnections(condition_connection, self.localId, connections)
setattr(cls, "filterConnections", filterConnections)
-
+
def updateConnectionsId(self, translation):
connections_end = []
if self.connectionPointIn is not None:
@@ -2087,7 +2087,7 @@
return condition_connection.getconnections()
return None
setattr(cls, "getconnections", getconnections)
-
+
def Search(self, criteria, parent_infos=[]):
parent_infos = parent_infos + ["transition", self.getlocalId()]
search_result = []
@@ -2104,7 +2104,7 @@
_initElementClass("selectionConvergence", "sfcObjects", "multiple")
_initElementClass("simultaneousDivergence", "sfcObjects", "single")
_initElementClass("simultaneousConvergence", "sfcObjects", "multiple")
-
+
cls = _initElementClass("jumpStep", "sfcObjects", "single")
if cls:
def Search(self, criteria, parent_infos):
@@ -2117,7 +2117,7 @@
if self.reference is not None:
self.reference.setname(name)
setattr(cls, "setreferenceName", setreferenceName)
-
+
def getreferenceName(self):
if self.reference is not None:
return self.reference.getname()
@@ -2129,7 +2129,7 @@
self.inline.setcontent(PLCOpenParser.CreateElement("ST", "inline"))
self.inline.settext(content)
setattr(cls, "setinlineContent", setinlineContent)
-
+
def getinlineContent(self):
if self.inline is not None:
return self.inline.gettext()
@@ -2155,7 +2155,7 @@
if qualifier is None:
qualifier = "N"
return _Search([("inline", self.getinlineContent()),
- ("reference", self.getreferenceName()),
+ ("reference", self.getreferenceName()),
("qualifier", qualifier),
("duration", self.getduration()),
("indicator", self.getindicator())],
@@ -2318,33 +2318,33 @@
def removeconnections(self):
self.content = None
setattr(cls, "removeconnections", removeconnections)
-
+
connection_xpath = PLCOpen_XPath("ppx:connection")
connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]")
def getconnections(self):
return connection_xpath(self)
setattr(cls, "getconnections", getconnections)
-
+
def getconnection(self, idx):
connection = connection_by_position_xpath(self, pos=idx+1)
if len(connection) > 0:
return connection[0]
return None
setattr(cls, "getconnection", getconnection)
-
+
def setconnectionId(self, idx, local_id):
connection = self.getconnection(idx)
if connection is not None:
connection.setrefLocalId(local_id)
setattr(cls, "setconnectionId", setconnectionId)
-
+
def getconnectionId(self, idx):
connection = self.getconnection(idx)
if connection is not None:
return connection.getrefLocalId()
return None
setattr(cls, "getconnectionId", getconnectionId)
-
+
def setconnectionPoints(self, idx, points):
connection = self.getconnection(idx)
if connection is not None:
@@ -2363,7 +2363,7 @@
if connection is not None:
connection.setformalParameter(parameter)
setattr(cls, "setconnectionParameter", setconnectionParameter)
-
+
def getconnectionParameter(self, idx):
connection = self.getconnection(idx)
if connection is not None:
@@ -2398,7 +2398,7 @@
content.setvalue(value)
self.setcontent(content)
setattr(cls, "setvalue", setvalue)
-
+
def getvalue(self):
return self.content.getvalue()
setattr(cls, "getvalue", getvalue)
@@ -2420,7 +2420,7 @@
cls = PLCOpenParser.GetElementClass("arrayValue", "value")
if cls:
arrayValue_model = re.compile("([0-9]+)\((.*)\)$")
-
+
def setvalue(self, value):
elements = []
for item in extractValues(value[1:-1]):
@@ -2436,7 +2436,7 @@
elements.append(element)
self.value = elements
setattr(cls, "setvalue", setvalue)
-
+
def getvalue(self):
values = []
for element in self.value:
@@ -2457,7 +2457,7 @@
cls = PLCOpenParser.GetElementClass("structValue", "value")
if cls:
structValue_model = re.compile("(.*):=(.*)")
-
+
def setvalue(self, value):
elements = []
for item in extractValues(value[1:-1]):
@@ -2470,11 +2470,10 @@
elements.append(element)
self.value = elements
setattr(cls, "setvalue", setvalue)
-
+
def getvalue(self):
values = []
for element in self.value:
values.append("%s := %s"%(element.getmember(), element.getvalue()))
return "(%s)"%", ".join(values)
setattr(cls, "getvalue", getvalue)
-