--- a/PLCControler.py Wed Aug 28 11:53:50 2013 +0200
+++ b/PLCControler.py Thu Aug 29 00:28:39 2013 +0200
@@ -1258,16 +1258,16 @@
dimensions.append((dimension.getlower(), dimension.getupper()))
base_type = vartype_content.baseType.getcontent()
base_type_type = base_type.getLocalTag()
- if base_type is None or base_type_type in ["string", "wstring"]:
+ if base_type_type == "derived": + base_type_name = base_type.getname() base_type_name = base_type_type.upper()
- base_type_name = base_type.getname()
tempvar["Type"] = ("array", base_type_name, dimensions)
tempvar["Type"] = vartype_content_type.upper()
initial = var.getinitialValue()
tempvar["Initial Value"] = initial.getvalue()
@@ -2460,7 +2460,7 @@
if blocktype_infos["type"] != "function" and blockname is not None:
block.setinstanceName(blockname)
self.AddEditedElementPouVar(tagname, blocktype, blockname)
- element.addinstance("block", block)
+ element.addinstance(block) self.Project.RefreshElementUsingTree()
def SetEditedElementBlockInfos(self, tagname, id, infos):
@@ -2506,7 +2506,8 @@
block.inputVariables.setvariable([])
block.outputVariables.setvariable([])
for connector in value["inputs"]:
- variable = plcopen.inputVariables_variable()
+ variable = PLCOpenParser.CreateElement("variable", "inputVariables") + block.inputVariables.appendvariable(variable) variable.setformalParameter(connector.GetName())
if connector.IsNegated():
variable.setnegated(True)
@@ -2515,9 +2516,9 @@
position = connector.GetRelPosition()
variable.connectionPointIn.setrelPositionXY(position.x, position.y)
self.SetConnectionWires(variable.connectionPointIn, connector)
- block.inputVariables.appendvariable(variable)
for connector in value["outputs"]:
- variable = plcopen.outputVariables_variable()
+ variable = PLCOpenParser.CreateElement("variable", "outputVariables") + block.outputVariables.appendvariable(variable) variable.setformalParameter(connector.GetName())
if connector.IsNegated():
variable.setnegated(True)
@@ -2526,23 +2527,18 @@
position = connector.GetRelPosition()
variable.addconnectionPointOut()
variable.connectionPointOut.setrelPositionXY(position.x, position.y)
- block.outputVariables.appendvariable(variable)
self.Project.RefreshElementUsingTree()
- def AddEditedElementVariable(self, tagname, id, type):
+ def AddEditedElementVariable(self, tagname, id, var_type): element = self.GetEditedElement(tagname)
- if element is not None:
- variable = plcopen.fbdObjects_inVariable()
- variable = plcopen.fbdObjects_outVariable()
- variable = plcopen.fbdObjects_inOutVariable()
+ if element is not None: + variable = PLCOpenParser.CreateElement( + INOUT: "inOutVariable"}[var_type], "fbdObjects") - element.addinstance(name, variable)
+ element.addinstance(variable) def SetEditedElementVariableInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2552,7 +2548,9 @@
for param, value in infos.items():
- variable.setexpression(value)
+ expression = PLCOpenParser.CreateElement("expression", variable.getLocalTag()) + expression.text = value + variable.setexpression(expression) elif param == "executionOrder" and variable.getexecutionOrderId() != value:
element.setelementExecutionOrder(variable, value)
@@ -2588,17 +2586,14 @@
variable.connectionPointIn.setrelPositionXY(position.x, position.y)
self.SetConnectionWires(variable.connectionPointIn, input)
- def AddEditedElementConnection(self, tagname, id, type):
+ def AddEditedElementConnection(self, tagname, id, connection_type): element = self.GetEditedElement(tagname)
- connection = plcopen.commonObjects_connector()
- elif type == CONTINUATION:
- connection = plcopen.commonObjects_continuation()
+ connection = PLCOpenParser.CreateElement( + {CONNECTOR: "connector", + CONTINUATION: "continuation"}[connection_type], "commonObjects") connection.setlocalId(id)
- element.addinstance(name, connection)
+ element.addinstance(connection) def SetEditedElementConnectionInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2619,10 +2614,10 @@
elif param == "connector":
position = value.GetRelPosition()
- if isinstance(connection, plcopen.commonObjects_continuation):
+ if isinstance(connection, PLCOpenParser.GetElementClass("continuation", "commonObjects")): connection.addconnectionPointOut()
connection.connectionPointOut.setrelPositionXY(position.x, position.y)
- elif isinstance(connection, plcopen.commonObjects_connector):
+ elif isinstance(connection, PLCOpenParser.GetElementClass("connector", "commonObjects")): connection.addconnectionPointIn()
connection.connectionPointIn.setrelPositionXY(position.x, position.y)
self.SetConnectionWires(connection.connectionPointIn, value)
@@ -2630,9 +2625,9 @@
def AddEditedElementComment(self, tagname, id):
element = self.GetEditedElement(tagname)
- comment = plcopen.commonObjects_comment()
+ comment = PLCOpenParser.CreateElement("comment", "commonObjects") - element.addinstance("comment", comment)
+ element.addinstance(comment) def SetEditedElementCommentInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2650,17 +2645,14 @@
- def AddEditedElementPowerRail(self, tagname, id, type):
+ def AddEditedElementPowerRail(self, tagname, id, powerrail_type): element = self.GetEditedElement(tagname)
- powerrail = plcopen.ldObjects_leftPowerRail()
- elif type == RIGHTRAIL:
- name = "rightPowerRail"
- powerrail = plcopen.ldObjects_rightPowerRail()
+ powerrail = PLCOpenParser.CreateElement( + {LEFTRAIL: "leftPowerRail", + RIGHTRAIL: "rightPowerRail"}[powerrail_type], "ldObjects") - element.addinstance(name, powerrail)
+ element.addinstance(powerrail) def SetEditedElementPowerRailInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2678,28 +2670,28 @@
elif param == "connectors":
- if isinstance(powerrail, plcopen.ldObjects_leftPowerRail):
+ if isinstance(powerrail, PLCOpenParser.GetElementClass("leftPowerRail", "ldObjects")): powerrail.setconnectionPointOut([])
for connector in value["outputs"]:
position = connector.GetRelPosition()
- connection = plcopen.leftPowerRail_connectionPointOut()
+ connection = PLCOpenParser.CreateElement("connectionPointOut", "leftPowerRail") + powerrail.appendconnectionPointOut(connection) connection.setrelPositionXY(position.x, position.y)
- powerrail.connectionPointOut.append(connection)
- elif isinstance(powerrail, plcopen.ldObjects_rightPowerRail):
+ elif isinstance(powerrail, PLCOpenParser.GetElementClass("rightPowerRail", "ldObjects")): powerrail.setconnectionPointIn([])
for connector in value["inputs"]:
position = connector.GetRelPosition()
- connection = plcopen.connectionPointIn()
+ connection = PLCOpenParser.CreateElement("connectionPointIn", "rightPowerRail") + powerrail.appendconnectionPointIn(connection) connection.setrelPositionXY(position.x, position.y)
self.SetConnectionWires(connection, connector)
- powerrail.connectionPointIn.append(connection)
def AddEditedElementContact(self, tagname, id):
element = self.GetEditedElement(tagname)
- contact = plcopen.ldObjects_contact()
+ contact = PLCOpenParser.CreateElement("contact", "ldObjects") - element.addinstance("contact", contact)
+ element.addinstance(contact) def SetEditedElementContactInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2709,7 +2701,9 @@
for param, value in infos.items():
- contact.setvariable(value)
+ variable = PLCOpenParser.CreateElement("variable", "contact") + contact.setvariable(variable) if value == CONTACT_NORMAL:
contact.setnegated(False)
@@ -2745,9 +2739,9 @@
def AddEditedElementCoil(self, tagname, id):
element = self.GetEditedElement(tagname)
- coil = plcopen.ldObjects_coil()
+ coil = PLCOpenParser.CreateElement("coil", "ldObjects") - element.addinstance("coil", coil)
+ element.addinstance(coil) def SetEditedElementCoilInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2757,7 +2751,9 @@
for param, value in infos.items():
- coil.setvariable(value)
+ variable = PLCOpenParser.CreateElement("variable", "coil") + coil.setvariable(variable) @@ -2805,9 +2801,9 @@
def AddEditedElementStep(self, tagname, id):
element = self.GetEditedElement(tagname)
- step = plcopen.sfcObjects_step()
+ step = PLCOpenParser.CreateElement("step", "sfcObjects") - element.addinstance("step", step)
+ element.addinstance(step) def SetEditedElementStepInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2855,9 +2851,9 @@
def AddEditedElementTransition(self, tagname, id):
element = self.GetEditedElement(tagname)
- transition = plcopen.sfcObjects_transition()
+ transition = PLCOpenParser.CreateElement("transition", "sfcObjects") transition.setlocalId(id)
- element.addinstance("transition", transition)
+ element.addinstance(transition) def SetEditedElementTransitionInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2893,25 +2889,31 @@
transition.connectionPointOut.setrelPositionXY(position.x, position.y)
elif infos.get("type", None) == "connection" and param == "connection" and value:
transition.setconditionContent("connection", None)
- self.SetConnectionWires(transition.condition.content["value"], value)
+ self.SetConnectionWires(transition.condition.content, value) - def AddEditedElementDivergence(self, tagname, id, type):
+ def AddEditedElementDivergence(self, tagname, id, divergence_type): element = self.GetEditedElement(tagname)
- if type == SELECTION_DIVERGENCE:
- name = "selectionDivergence"
- divergence = plcopen.sfcObjects_selectionDivergence()
- elif type == SELECTION_CONVERGENCE:
- name = "selectionConvergence"
- divergence = plcopen.sfcObjects_selectionConvergence()
- elif type == SIMULTANEOUS_DIVERGENCE:
- name = "simultaneousDivergence"
- divergence = plcopen.sfcObjects_simultaneousDivergence()
- elif type == SIMULTANEOUS_CONVERGENCE:
- name = "simultaneousConvergence"
- divergence = plcopen.sfcObjects_simultaneousConvergence()
+ divergence = PLCOpenParser.CreateElement( + {SELECTION_DIVERGENCE: "selectionDivergence", + SELECTION_CONVERGENCE: "selectionConvergence", + SIMULTANEOUS_DIVERGENCE: "simultaneousDivergence", + SIMULTANEOUS_CONVERGENCE: "simultaneousConvergence"}.get( + divergence_type), "sfcObjects") divergence.setlocalId(id)
- element.addinstance(name, divergence)
+ element.addinstance(divergence) + PLCOpenParser.GetElementClass(divergence_type, "sfcObjects")) + for divergence_type in ["selectionDivergence", "simultaneousDivergence", + "selectionConvergence", "simultaneousConvergence"]] + def GetDivergenceType(self, divergence): + for divergence_type, divergence_class in self.DivergenceTypes: + if isinstance(divergence, divergence_class): def SetEditedElementDivergenceInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2930,7 +2932,8 @@
elif param == "connectors":
input_connectors = value["inputs"]
- if isinstance(divergence, (plcopen.sfcObjects_selectionDivergence, plcopen.sfcObjects_simultaneousDivergence)):
+ divergence_type = self.GetDivergenceType(divergence) + if divergence_type in ["selectionDivergence", "simultaneousDivergence"]: position = input_connectors[0].GetRelPosition()
divergence.addconnectionPointIn()
divergence.connectionPointIn.setrelPositionXY(position.x, position.y)
@@ -2939,15 +2942,12 @@
divergence.setconnectionPointIn([])
for input_connector in input_connectors:
position = input_connector.GetRelPosition()
- if isinstance(divergence, plcopen.sfcObjects_selectionConvergence):
- connection = plcopen.selectionConvergence_connectionPointIn()
- connection = plcopen.connectionPointIn()
+ connection = PLCOpenParser.CreateElement("connectionPointIn", divergence_type) + divergence.appendconnectionPointIn(connection) connection.setrelPositionXY(position.x, position.y)
self.SetConnectionWires(connection, input_connector)
- divergence.appendconnectionPointIn(connection)
output_connectors = value["outputs"]
- if isinstance(divergence, (plcopen.sfcObjects_selectionConvergence, plcopen.sfcObjects_simultaneousConvergence)):
+ if divergence_type in ["selectionConvergence", "simultaneousConvergence"]: position = output_connectors[0].GetRelPosition()
divergence.addconnectionPointOut()
divergence.connectionPointOut.setrelPositionXY(position.x, position.y)
@@ -2955,19 +2955,16 @@
divergence.setconnectionPointOut([])
for output_connector in output_connectors:
position = output_connector.GetRelPosition()
- if isinstance(divergence, plcopen.sfcObjects_selectionDivergence):
- connection = plcopen.selectionDivergence_connectionPointOut()
- connection = plcopen.simultaneousDivergence_connectionPointOut()
+ connection = PLCOpenParser.CreateElement("connectionPointOut", divergence_type) + divergence.appendconnectionPointOut(connection) connection.setrelPositionXY(position.x, position.y)
- divergence.appendconnectionPointOut(connection)
def AddEditedElementJump(self, tagname, id):
element = self.GetEditedElement(tagname)
- jump = plcopen.sfcObjects_jumpStep()
+ jump = PLCOpenParser.CreateElement("jumpStep", "sfcObjects") - element.addinstance("jumpStep", jump)
+ element.addinstance(jump) def SetEditedElementJumpInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -2995,9 +2992,9 @@
def AddEditedElementActionBlock(self, tagname, id):
element = self.GetEditedElement(tagname)
- actionBlock = plcopen.commonObjects_actionBlock()
+ actionBlock = PLCOpenParser.CreateElement("actionBlock", "commonObjects") actionBlock.setlocalId(id)
- element.addinstance("actionBlock", actionBlock)
+ element.addinstance(actionBlock) def SetEditedElementActionBlockInfos(self, tagname, id, infos):
element = self.GetEditedElement(tagname)
@@ -3026,7 +3023,7 @@
element = self.GetEditedElement(tagname)
instance = element.getinstance(id)
- if isinstance(instance, plcopen.fbdObjects_block):
+ if isinstance(instance, PLCOpenParser.GetElementClass("block", "fbdObjects")): self.RemoveEditedElementPouVar(tagname, instance.gettypeName(), instance.getinstanceName())
element.removeinstance(id)
self.Project.RefreshElementUsingTree()
--- a/plcopen/plcopen.py Wed Aug 28 11:53:50 2013 +0200
+++ b/plcopen/plcopen.py Thu Aug 29 00:28:39 2013 +0200
@@ -880,7 +880,7 @@
- ft = PLCOpenParser.CreateElementClass("formattedText")
+ ft = PLCOpenParser.CreateElement("formattedText") ft.setanyText(description)
globalvars[-1].appendvariable(var)
@@ -1079,9 +1079,9 @@
def appenddataTypeElement(self, name):
new_datatype = PLCOpenParser.CreateElement("dataType", "dataTypes")
+ self.dataTypes.appenddataType(new_datatype) new_datatype.setname(name)
new_datatype.baseType.setcontent(PLCOpenParser.CreateElement("BOOL"))
- self.dataTypes.appenddataType(new_datatype)
setattr(cls, "appenddataTypeElement", appenddataTypeElement)
def insertdataTypeElement(self, index, dataType):
@@ -1116,11 +1116,11 @@
if element.getname() == name:
raise ValueError, _("\"%s\" POU already exists !!!")%name
new_pou = PLCOpenParser.CreateElement("pou", "pous")
+ self.pous.appendpou(new_pou) new_pou.setpouType(pou_type)
- new_pou.appendbody(PLCOpenParser.CreateElement("body"))
+ new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) new_pou.setbodyType(body_type)
- self.pous.appendpou(new_pou)
setattr(cls, "appendpouElement", appendpouElement)
def insertpouElement(self, index, pou):
@@ -1260,7 +1260,7 @@
def setbodyType(self, body_type):
if body_type in ["IL", "ST", "LD", "FBD", "SFC"]:
- self.body[0].setcontent(PLCOpenParser.CreateElementClass(body_type, "body"))
+ self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) raise ValueError, "%s isn't a valid body type!"%type
setattr(cls, "setbodyType", setbodyType)
@@ -1285,9 +1285,9 @@
self.body[0].setelementExecutionOrder(instance, new_executionOrder)
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
- def addinstance(self, name, instance):
+ def addinstance(self, instance): - self.body[0].appendcontentInstance(name, instance)
+ self.body[0].appendcontentInstance(instance) setattr(cls, "addinstance", addinstance)
@@ -1345,7 +1345,6 @@
if self.interface is None:
self.interface = PLCOpenParser.CreateElement("interface", "pou")
self.interface.setcontent(vars)
- print self.interface.tostring()
setattr(cls, "setvars", setvars)
def addpouLocalVar(self, var_type, name, location="", description=""):
@@ -1366,8 +1365,8 @@
varlist = content[-1]["value"]
variables = varlist.getvariable()
if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress():
- self.appendcontent(PLCOpenParser.CreateElementClass(var_class, "interface"))
- var = PLCOpenParser.CreateElementClass("variable", "varListPlain")
+ self.appendcontent(PLCOpenParser.CreateElement(var_class, "interface")) + var = PLCOpenParser.CreateElement("variable", "varListPlain") var_type_obj = PLCOpenParser.CreateElement("dataType")
if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]:
@@ -1441,21 +1440,21 @@
setattr(cls, "hasblock", hasblock)
def addtransition(self, name, body_type):
- if not self.transitions:
+ if self.transitions is None: self.transitions.settransition([])
transition = PLCOpenParser.CreateElement("transition", "transitions")
+ self.transitions.appendtransition(transition) transition.setbodyType(body_type)
transition.setanyText(":= ;")
transition.setanyText("\tST\t%s"%name)
- self.transitions.appendtransition(transition)
setattr(cls, "addtransition", addtransition)
def gettransition(self, name):
+ if self.transitions is not None: for transition in self.transitions.gettransition():
if transition.getname() == name:
@@ -1463,13 +1462,13 @@
setattr(cls, "gettransition", gettransition)
def gettransitionList(self):
+ if self.transitions is not None: return self.transitions.gettransition()
setattr(cls, "gettransitionList", gettransitionList)
def removetransition(self, name):
+ if self.transitions is not None: for transition in self.transitions.gettransition():
if transition.getname() == name:
@@ -1486,17 +1485,17 @@
setattr(cls, "removetransition", removetransition)
def addaction(self, name, body_type):
+ if self.actions is None: self.actions.setaction([])
action = PLCOpenParser.CreateElement("action", "actions")
+ self.actions.appendaction(action) action.setbodyType(body_type)
- self.actions.appendaction(action)
setattr(cls, "addaction", addaction)
def getaction(self, name):
+ if self.actions is not None: for action in self.actions.getaction():
if action.getname() == name:
@@ -1510,7 +1509,7 @@
setattr(cls, "getactionList", getactionList)
def removeaction(self, name):
+ if self.actions is not None: for action in self.actions.getaction():
if action.getname() == name:
@@ -1527,7 +1526,7 @@
setattr(cls, "removeaction", removeaction)
def updateElementName(self, old_name, new_name):
+ if self.interface is not None: for content in self.interface.getcontent():
for var in content.getvariable():
var_address = var.getaddress()
@@ -1548,7 +1547,7 @@
setattr(cls, "updateElementName", updateElementName)
def updateElementAddress(self, address_model, new_leading):
+ if self.interface is not None: for content in self.interface.getcontent():
for var in content.getvariable():
var_address = var.getaddress()
@@ -1562,7 +1561,7 @@
setattr(cls, "updateElementAddress", updateElementAddress)
def removeVariableByAddress(self, address):
+ if self.interface is not None: for content in self.interface.getcontent():
for variable in content.getvariable():
if variable.getaddress() == address:
@@ -1570,7 +1569,7 @@
setattr(cls, "removeVariableByAddress", removeVariableByAddress)
def removeVariableByFilter(self, address_model):
+ if self.interface is not None: for content in self.interface.getcontent():
for variable in content.getvariable():
var_address = variable.getaddress()
@@ -1628,8 +1627,8 @@
def setelementExecutionOrder(self, instance, new_executionOrder):
self.body.setelementExecutionOrder(instance, new_executionOrder)
-def addinstance(self, name, instance):
- self.body.appendcontentInstance(name, instance)
+def addinstance(self, instance): + self.body.appendcontentInstance(instance) return self.body.getcontentInstances()
@@ -1801,18 +1800,18 @@
raise TypeError, _("Can only generate execution order on FBD networks!")
setattr(cls, "setelementExecutionOrder", setelementExecutionOrder)
- def appendcontentInstance(self, name, instance):
+ def appendcontentInstance(self, instance): if self.content.getLocalTag() in ["LD","FBD","SFC"]:
self.content.appendcontent(instance)
- raise TypeError, _("%s body don't have instances!")%self.content["name"]
+ 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()
- raise TypeError, _("%s body don't have instances!")%self.content["name"]
+ raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() setattr(cls, "getcontentInstances", getcontentInstances)
def getcontentInstance(self, local_id):
@@ -1822,7 +1821,7 @@
- raise TypeError, _("%s body don't have instances!")%self.content["name"]
+ raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() setattr(cls, "getcontentInstance", getcontentInstance)
def getcontentRandomInstance(self, exclude):
@@ -1835,7 +1834,7 @@
- raise TypeError, _("%s body don't have instances!")%self.content["name"]
+ raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() setattr(cls, "getcontentRandomInstance", getcontentRandomInstance)
def getcontentInstanceByName(self, name):
@@ -1845,7 +1844,7 @@
- raise TypeError, _("%s body don't have instances!")%self.content["name"]
+ raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() setattr(cls, "getcontentInstanceByName", getcontentInstanceByName)
def removecontentInstance(self, local_id):
@@ -1856,28 +1855,28 @@
raise ValueError, _("Instance with id %d doesn't exist!")%id
- raise TypeError, "%s body don't have instances!"%self.content["name"]
+ raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() setattr(cls, "removecontentInstance", removecontentInstance)
if self.content.getLocalTag() in ["IL","ST"]:
self.content.setanyText(text)
- raise TypeError, _("%s body don't have text!")%self.content["name"]
+ raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() setattr(cls, "settext", settext)
if self.content.getLocalTag() in ["IL","ST"]:
return self.content.getanyText()
- raise TypeError, _("%s body don't have text!")%self.content["name"]
+ 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)
- raise TypeError, _("%s body don't have text!")%self.content["name"]
+ raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() setattr(cls, "hasblock", hasblock)
def updateElementName(self, old_name, new_name):
@@ -2140,12 +2139,12 @@
-def _getldelementinfosFunction(type):
+def _getldelementinfosFunction(ld_element_type): def getldelementinfos(self):
infos = _getelementinfos(self)
+ infos["type"] = ld_element_type specific_values = infos["specific_values"]
- specific_values["name"] = self.getvariable()
+ specific_values["name"] = self.getvariable().text _getexecutionOrder(self, specific_values)
specific_values["negated"] = self.getnegated()
specific_values["edge"] = self.getedge()
@@ -2274,39 +2273,31 @@
setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail"))
+def _UpdateLDElementName(self, old_name, new_name): + if self.variable.text == old_name: + self.variable.text = new_name +def _UpdateLDElementAddress(self, address_model, new_leading): + self.variable.text = update_address(self.variable.text, address_model, new_leading) +def _getSearchInLDElement(ld_element_type): + def SearchInLDElement(self, criteria, parent_infos=[]): + return _Search([("reference", self.variable.text)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) + return SearchInLDElement cls = _initElementClass("contact", "ldObjects", "single")
setattr(cls, "getinfos", _getldelementinfosFunction("contact"))
- def updateElementName(self, old_name, new_name):
- if self.variable == old_name:
- self.variable = new_name
- setattr(cls, "updateElementName", updateElementName)
- def updateElementAddress(self, address_model, new_leading):
- self.variable = update_address(self.variable, address_model, new_leading)
- setattr(cls, "updateElementAddress", updateElementAddress)
- def Search(self, criteria, parent_infos=[]):
- return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()])
- setattr(cls, "Search", Search)
+ setattr(cls, "updateElementName", _UpdateLDElementName) + setattr(cls, "updateElementAddress", _UpdateLDElementAddress) + setattr(cls, "Search", _getSearchInLDElement("contact")) cls = _initElementClass("coil", "ldObjects", "single")
setattr(cls, "getinfos", _getldelementinfosFunction("coil"))
- def updateElementName(self, old_name, new_name):
- if self.variable == old_name:
- self.variable = new_name
- setattr(cls, "updateElementName", updateElementName)
- def updateElementAddress(self, address_model, new_leading):
- self.variable = update_address(self.variable, address_model, new_leading)
- setattr(cls, "updateElementAddress", updateElementAddress)
- def Search(self, criteria, parent_infos=[]):
- return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()])
- setattr(cls, "Search", Search)
+ setattr(cls, "updateElementName", _UpdateLDElementName) + setattr(cls, "updateElementAddress", _UpdateLDElementAddress) + setattr(cls, "Search", _getSearchInLDElement("coil")) cls = _initElementClass("step", "sfcObjects", "single")
@@ -2370,16 +2361,16 @@
def setconditionContent(self, condition_type, value):
+ if condition_type == "connection": + condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") + condition = PLCOpenParser.CreateElement(condition_type, "condition") + self.condition.setcontent(condition) if condition_type == "reference":
- condition = PLCOpenParser.CreateElement("reference", "condition")
elif condition_type == "inline":
- condition = PLCOpenParser.CreateElement("inline", "condition")
- condition.setcontent(PLCOpenParser.GetElementClass("ST", "inline"))
- condition.setanyText(value)
- elif condition_type == "connection":
- condition = PLCOpenParser.CreateElementClass("connectionPointIn")
- self.condition.setcontent(condition)
+ condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) + condition.settext(value) setattr(cls, "setconditionContent", setconditionContent)
def getconditionContent(self):
@@ -2389,7 +2380,7 @@
if values["type"] == "reference":
values["value"] = content.getname()
elif values["type"] == "inline":
- values["value"] = content.getanyText()
+ values["value"] = content.gettext() elif values["type"] == "connectionPointIn":
values["type"] = "connection"
values["value"] = content
@@ -2400,7 +2391,7 @@
def getconditionConnection(self):
content = self.condition.getcontent()
- if content.getLocalTag() == "connectionPointIn":
+ if content.getLocalTag() == "connection": setattr(cls, "getconditionConnection", getconditionConnection)
@@ -2533,7 +2524,7 @@
def setinlineContent(self, content):
- self.inline.setcontent(PLCOpenParser.CreateElementClass("ST", "action"))
+ self.inline.setcontent(PLCOpenParser.CreateElement("ST", "action")) self.inline.setanyText(content)
setattr(cls, "setinlineContent", setinlineContent)
@@ -2645,51 +2636,34 @@
setattr(cls, "Search", Search)
def _SearchInIOVariable(self, criteria, parent_infos=[]):
- return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()])
+ return _Search([("expression", self.expression.text)], criteria, parent_infos + ["io_variable", self.getlocalId()]) +def _UpdateIOElementName(self, old_name, new_name): + if self.expression.text == old_name: + self.expression.text = new_name +def _UpdateIOElementAddress(self, old_name, new_name): + self.expression.text = update_address(self.expression.text, address_model, new_leading) cls = _initElementClass("inVariable", "fbdObjects")
setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True))
- def updateElementName(self, old_name, new_name):
- if self.expression == old_name:
- self.expression = new_name
- setattr(cls, "updateElementName", updateElementName)
- def updateElementAddress(self, address_model, new_leading):
- self.expression = update_address(self.expression, address_model, new_leading)
- setattr(cls, "updateElementAddress", updateElementAddress)
+ setattr(cls, "updateElementName", _UpdateIOElementName) + setattr(cls, "updateElementAddress", _UpdateIOElementAddress) setattr(cls, "Search", _SearchInIOVariable)
cls = _initElementClass("outVariable", "fbdObjects", "single")
setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False))
- def updateElementName(self, old_name, new_name):
- if self.expression == old_name:
- self.expression = new_name
- setattr(cls, "updateElementName", updateElementName)
- def updateElementAddress(self, address_model, new_leading):
- self.expression = update_address(self.expression, address_model, new_leading)
- setattr(cls, "updateElementAddress", updateElementAddress)
+ setattr(cls, "updateElementName", _UpdateIOElementName) + setattr(cls, "updateElementAddress", _UpdateIOElementAddress) setattr(cls, "Search", _SearchInIOVariable)
cls = _initElementClass("inOutVariable", "fbdObjects", "single")
setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True))
- def updateElementName(self, old_name, new_name):
- if self.expression == old_name:
- self.expression = new_name
- setattr(cls, "updateElementName", updateElementName)
- def updateElementAddress(self, address_model, new_leading):
- self.expression = update_address(self.expression, address_model, new_leading)
- setattr(cls, "updateElementAddress", updateElementAddress)
+ setattr(cls, "updateElementName", _UpdateIOElementName) + setattr(cls, "updateElementAddress", _UpdateIOElementAddress) setattr(cls, "Search", _SearchInIOVariable)
@@ -2721,11 +2695,11 @@
def setpoints(self, points):
- position = PLCOpenParser.CreateElement("position")
+ position = PLCOpenParser.CreateElement("position", "connection") positions.append(position)
- self.positions = positions
+ self.position = positions setattr(cls, "setpoints", setpoints)
@@ -2738,7 +2712,7 @@
cls = PLCOpenParser.GetElementClass("connectionPointIn")
def setrelPositionXY(self, x, y):
- self.relPosition = PLCOpenParser.CreateElement("position")
+ self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointIn") setattr(cls, "setrelPositionXY", setrelPositionXY)
@@ -2750,7 +2724,7 @@
setattr(cls, "getrelPositionXY", getrelPositionXY)
- self.appendcontent(PLCOpenParser.CreateElement("connection"))
+ self.append(PLCOpenParser.CreateElement("connection", "connectionPointIn")) setattr(cls, "addconnection", addconnection)
def removeconnection(self, idx):
@@ -2766,43 +2740,57 @@
return self.xpath("ppx:connection", namespaces=PLCOpenParser.NSMAP)
setattr(cls, "getconnections", getconnections)
+ def getconnection(self, idx): + connection = self.xpath("ppx:connection[position()=%d]" % (idx + 1), + namespaces=PLCOpenParser.NSMAP) + if len(connection) > 0: + setattr(cls, "getconnection", getconnection) def setconnectionId(self, idx, local_id):
- if len(self.content) > idx:
- self.content[idx].setrefLocalId(local_id)
+ connection = self.getconnection(idx) + if connection is not None: + connection.setrefLocalId(local_id) setattr(cls, "setconnectionId", setconnectionId)
def getconnectionId(self, idx):
- if len(self.content) > idx:
- return self.content[idx].getrefLocalId()
+ connection = self.getconnection(idx) + if connection is not None: + return connection.getrefLocalId() setattr(cls, "getconnectionId", getconnectionId)
def setconnectionPoints(self, idx, points):
- if len(self.content) > idx:
- self.content[idx].setpoints(points)
+ connection = self.getconnection(idx) + if connection is not None: + connection.setpoints(points) setattr(cls, "setconnectionPoints", setconnectionPoints)
def getconnectionPoints(self, idx):
- if len(self.content) > idx:
- return self.content[idx].getpoints()
+ connection = self.getconnection(idx) + if connection is not None: + return connection.getpoints() setattr(cls, "getconnectionPoints", getconnectionPoints)
def setconnectionParameter(self, idx, parameter):
- if len(self.content) > idx:
- self.content[idx].setformalParameter(parameter)
+ connection = self.getconnection(idx) + if connection is not None: + connection.setformalParameter(parameter) setattr(cls, "setconnectionParameter", setconnectionParameter)
def getconnectionParameter(self, idx):
- if len(self.content) > idx:
- return self.content[idx].getformalParameter()
+ connection = self.getconnection(idx) + if connection is not None: + return connection.getformalParameter() setattr(cls, "getconnectionParameter", getconnectionParameter)
cls = PLCOpenParser.GetElementClass("connectionPointOut")
def setrelPositionXY(self, x, y):
- self.relPosition = PLCOpenParser.CreateElement("position")
+ self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") setattr(cls, "setrelPositionXY", setrelPositionXY)
@@ -2868,8 +2856,11 @@
for element in self.value:
- repetition = element.getrepetitionValue()
- if repetition is not None and int(repetition) > 1:
+ repetition = int(element.getrepetitionValue()) value = element.getvalue()