1077 return None |
1077 return None |
1078 setattr(cls, "getdataTypeElement", getdataTypeElement) |
1078 setattr(cls, "getdataTypeElement", getdataTypeElement) |
1079 |
1079 |
1080 def appenddataTypeElement(self, name): |
1080 def appenddataTypeElement(self, name): |
1081 new_datatype = PLCOpenParser.CreateElement("dataType", "dataTypes") |
1081 new_datatype = PLCOpenParser.CreateElement("dataType", "dataTypes") |
|
1082 self.dataTypes.appenddataType(new_datatype) |
1082 new_datatype.setname(name) |
1083 new_datatype.setname(name) |
1083 new_datatype.baseType.setcontent(PLCOpenParser.CreateElement("BOOL")) |
1084 new_datatype.baseType.setcontent(PLCOpenParser.CreateElement("BOOL")) |
1084 self.dataTypes.appenddataType(new_datatype) |
|
1085 setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
1085 setattr(cls, "appenddataTypeElement", appenddataTypeElement) |
1086 |
1086 |
1087 def insertdataTypeElement(self, index, dataType): |
1087 def insertdataTypeElement(self, index, dataType): |
1088 self.dataTypes.insertdataType(index, dataType) |
1088 self.dataTypes.insertdataType(index, dataType) |
1089 setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
1089 setattr(cls, "insertdataTypeElement", insertdataTypeElement) |
1114 def appendpouElement(self, name, pou_type, body_type): |
1114 def appendpouElement(self, name, pou_type, body_type): |
1115 for element in self.pous.getpou(): |
1115 for element in self.pous.getpou(): |
1116 if element.getname() == name: |
1116 if element.getname() == name: |
1117 raise ValueError, _("\"%s\" POU already exists !!!")%name |
1117 raise ValueError, _("\"%s\" POU already exists !!!")%name |
1118 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
1118 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
|
1119 self.pous.appendpou(new_pou) |
1119 new_pou.setname(name) |
1120 new_pou.setname(name) |
1120 new_pou.setpouType(pou_type) |
1121 new_pou.setpouType(pou_type) |
1121 new_pou.appendbody(PLCOpenParser.CreateElement("body")) |
1122 new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
1122 new_pou.setbodyType(body_type) |
1123 new_pou.setbodyType(body_type) |
1123 self.pous.appendpou(new_pou) |
|
1124 setattr(cls, "appendpouElement", appendpouElement) |
1124 setattr(cls, "appendpouElement", appendpouElement) |
1125 |
1125 |
1126 def insertpouElement(self, index, pou): |
1126 def insertpouElement(self, index, pou): |
1127 self.pous.insertpou(index, pou) |
1127 self.pous.insertpou(index, pou) |
1128 setattr(cls, "insertpouElement", insertpouElement) |
1128 setattr(cls, "insertpouElement", insertpouElement) |
1258 setattr(cls, "getdescription", getdescription) |
1258 setattr(cls, "getdescription", getdescription) |
1259 |
1259 |
1260 def setbodyType(self, body_type): |
1260 def setbodyType(self, body_type): |
1261 if len(self.body) > 0: |
1261 if len(self.body) > 0: |
1262 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1262 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1263 self.body[0].setcontent(PLCOpenParser.CreateElementClass(body_type, "body")) |
1263 self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
1264 else: |
1264 else: |
1265 raise ValueError, "%s isn't a valid body type!"%type |
1265 raise ValueError, "%s isn't a valid body type!"%type |
1266 setattr(cls, "setbodyType", setbodyType) |
1266 setattr(cls, "setbodyType", setbodyType) |
1267 |
1267 |
1268 def getbodyType(self): |
1268 def getbodyType(self): |
1283 def setelementExecutionOrder(self, instance, new_executionOrder): |
1283 def setelementExecutionOrder(self, instance, new_executionOrder): |
1284 if len(self.body) > 0: |
1284 if len(self.body) > 0: |
1285 self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
1285 self.body[0].setelementExecutionOrder(instance, new_executionOrder) |
1286 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1286 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1287 |
1287 |
1288 def addinstance(self, name, instance): |
1288 def addinstance(self, instance): |
1289 if len(self.body) > 0: |
1289 if len(self.body) > 0: |
1290 self.body[0].appendcontentInstance(name, instance) |
1290 self.body[0].appendcontentInstance(instance) |
1291 setattr(cls, "addinstance", addinstance) |
1291 setattr(cls, "addinstance", addinstance) |
1292 |
1292 |
1293 def getinstances(self): |
1293 def getinstances(self): |
1294 if len(self.body) > 0: |
1294 if len(self.body) > 0: |
1295 return self.body[0].getcontentInstances() |
1295 return self.body[0].getcontentInstances() |
1343 |
1343 |
1344 def setvars(self, vars): |
1344 def setvars(self, vars): |
1345 if self.interface is None: |
1345 if self.interface is None: |
1346 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1346 self.interface = PLCOpenParser.CreateElement("interface", "pou") |
1347 self.interface.setcontent(vars) |
1347 self.interface.setcontent(vars) |
1348 print self.interface.tostring() |
|
1349 setattr(cls, "setvars", setvars) |
1348 setattr(cls, "setvars", setvars) |
1350 |
1349 |
1351 def addpouLocalVar(self, var_type, name, location="", description=""): |
1350 def addpouLocalVar(self, var_type, name, location="", description=""): |
1352 self.addpouVar(var_type, name, location=location, description=description) |
1351 self.addpouVar(var_type, name, location=location, description=description) |
1353 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1352 setattr(cls, "addpouLocalVar", addpouLocalVar) |
1364 self.appendcontent(PLCOpenParser.CreateElement(var_class, "interface")) |
1363 self.appendcontent(PLCOpenParser.CreateElement(var_class, "interface")) |
1365 else: |
1364 else: |
1366 varlist = content[-1]["value"] |
1365 varlist = content[-1]["value"] |
1367 variables = varlist.getvariable() |
1366 variables = varlist.getvariable() |
1368 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1367 if varlist.getconstant() or varlist.getretain() or len(variables) > 0 and variables[0].getaddress(): |
1369 self.appendcontent(PLCOpenParser.CreateElementClass(var_class, "interface")) |
1368 self.appendcontent(PLCOpenParser.CreateElement(var_class, "interface")) |
1370 var = PLCOpenParser.CreateElementClass("variable", "varListPlain") |
1369 var = PLCOpenParser.CreateElement("variable", "varListPlain") |
1371 var.setname(name) |
1370 var.setname(name) |
1372 var_type_obj = PLCOpenParser.CreateElement("dataType") |
1371 var_type_obj = PLCOpenParser.CreateElement("dataType") |
1373 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1372 if var_type in [x for x,y in TypeHierarchy_list if not x.startswith("ANY")]: |
1374 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
1373 var_type_obj.setcontent(PLCOpenParser.CreateElement( |
1375 var_type.lower() if var_type in ["STRING", "WSTRING"] |
1374 var_type.lower() if var_type in ["STRING", "WSTRING"] |
1439 return self.body[0].hasblock(block_type) |
1438 return self.body[0].hasblock(block_type) |
1440 return False |
1439 return False |
1441 setattr(cls, "hasblock", hasblock) |
1440 setattr(cls, "hasblock", hasblock) |
1442 |
1441 |
1443 def addtransition(self, name, body_type): |
1442 def addtransition(self, name, body_type): |
1444 if not self.transitions: |
1443 if self.transitions is None: |
1445 self.addtransitions() |
1444 self.addtransitions() |
1446 self.transitions.settransition([]) |
1445 self.transitions.settransition([]) |
1447 transition = PLCOpenParser.CreateElement("transition", "transitions") |
1446 transition = PLCOpenParser.CreateElement("transition", "transitions") |
|
1447 self.transitions.appendtransition(transition) |
1448 transition.setname(name) |
1448 transition.setname(name) |
1449 transition.setbodyType(body_type) |
1449 transition.setbodyType(body_type) |
1450 if body_type == "ST": |
1450 if body_type == "ST": |
1451 transition.setanyText(":= ;") |
1451 transition.setanyText(":= ;") |
1452 elif body_type == "IL": |
1452 elif body_type == "IL": |
1453 transition.setanyText("\tST\t%s"%name) |
1453 transition.setanyText("\tST\t%s"%name) |
1454 self.transitions.appendtransition(transition) |
|
1455 setattr(cls, "addtransition", addtransition) |
1454 setattr(cls, "addtransition", addtransition) |
1456 |
1455 |
1457 def gettransition(self, name): |
1456 def gettransition(self, name): |
1458 if self.transitions: |
1457 if self.transitions is not None: |
1459 for transition in self.transitions.gettransition(): |
1458 for transition in self.transitions.gettransition(): |
1460 if transition.getname() == name: |
1459 if transition.getname() == name: |
1461 return transition |
1460 return transition |
1462 return None |
1461 return None |
1463 setattr(cls, "gettransition", gettransition) |
1462 setattr(cls, "gettransition", gettransition) |
1464 |
1463 |
1465 def gettransitionList(self): |
1464 def gettransitionList(self): |
1466 if self.transitions: |
1465 if self.transitions is not None: |
1467 return self.transitions.gettransition() |
1466 return self.transitions.gettransition() |
1468 return [] |
1467 return [] |
1469 setattr(cls, "gettransitionList", gettransitionList) |
1468 setattr(cls, "gettransitionList", gettransitionList) |
1470 |
1469 |
1471 def removetransition(self, name): |
1470 def removetransition(self, name): |
1472 if self.transitions: |
1471 if self.transitions is not None: |
1473 removed = False |
1472 removed = False |
1474 for transition in self.transitions.gettransition(): |
1473 for transition in self.transitions.gettransition(): |
1475 if transition.getname() == name: |
1474 if transition.getname() == name: |
1476 if transition.getbodyType() in ["FBD", "LD", "SFC"]: |
1475 if transition.getbodyType() in ["FBD", "LD", "SFC"]: |
1477 for instance in transition.getinstances(): |
1476 for instance in transition.getinstances(): |
1484 if not removed: |
1483 if not removed: |
1485 raise ValueError, _("Transition with name %s doesn't exist!")%name |
1484 raise ValueError, _("Transition with name %s doesn't exist!")%name |
1486 setattr(cls, "removetransition", removetransition) |
1485 setattr(cls, "removetransition", removetransition) |
1487 |
1486 |
1488 def addaction(self, name, body_type): |
1487 def addaction(self, name, body_type): |
1489 if not self.actions: |
1488 if self.actions is None: |
1490 self.addactions() |
1489 self.addactions() |
1491 self.actions.setaction([]) |
1490 self.actions.setaction([]) |
1492 action = PLCOpenParser.CreateElement("action", "actions") |
1491 action = PLCOpenParser.CreateElement("action", "actions") |
|
1492 self.actions.appendaction(action) |
1493 action.setname(name) |
1493 action.setname(name) |
1494 action.setbodyType(body_type) |
1494 action.setbodyType(body_type) |
1495 self.actions.appendaction(action) |
|
1496 setattr(cls, "addaction", addaction) |
1495 setattr(cls, "addaction", addaction) |
1497 |
1496 |
1498 def getaction(self, name): |
1497 def getaction(self, name): |
1499 if self.actions: |
1498 if self.actions is not None: |
1500 for action in self.actions.getaction(): |
1499 for action in self.actions.getaction(): |
1501 if action.getname() == name: |
1500 if action.getname() == name: |
1502 return action |
1501 return action |
1503 return None |
1502 return None |
1504 setattr(cls, "getaction", getaction) |
1503 setattr(cls, "getaction", getaction) |
1546 for transition in self.gettransitionList(): |
1545 for transition in self.gettransitionList(): |
1547 transition.updateElementName(old_name, new_name) |
1546 transition.updateElementName(old_name, new_name) |
1548 setattr(cls, "updateElementName", updateElementName) |
1547 setattr(cls, "updateElementName", updateElementName) |
1549 |
1548 |
1550 def updateElementAddress(self, address_model, new_leading): |
1549 def updateElementAddress(self, address_model, new_leading): |
1551 if self.interface: |
1550 if self.interface is not None: |
1552 for content in self.interface.getcontent(): |
1551 for content in self.interface.getcontent(): |
1553 for var in content.getvariable(): |
1552 for var in content.getvariable(): |
1554 var_address = var.getaddress() |
1553 var_address = var.getaddress() |
1555 if var_address is not None: |
1554 if var_address is not None: |
1556 var.setaddress(update_address(var_address, address_model, new_leading)) |
1555 var.setaddress(update_address(var_address, address_model, new_leading)) |
1560 for transition in self.gettransitionList(): |
1559 for transition in self.gettransitionList(): |
1561 transition.updateElementAddress(address_model, new_leading) |
1560 transition.updateElementAddress(address_model, new_leading) |
1562 setattr(cls, "updateElementAddress", updateElementAddress) |
1561 setattr(cls, "updateElementAddress", updateElementAddress) |
1563 |
1562 |
1564 def removeVariableByAddress(self, address): |
1563 def removeVariableByAddress(self, address): |
1565 if self.interface: |
1564 if self.interface is not None: |
1566 for content in self.interface.getcontent(): |
1565 for content in self.interface.getcontent(): |
1567 for variable in content.getvariable(): |
1566 for variable in content.getvariable(): |
1568 if variable.getaddress() == address: |
1567 if variable.getaddress() == address: |
1569 content.remove(variable) |
1568 content.remove(variable) |
1570 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
1569 setattr(cls, "removeVariableByAddress", removeVariableByAddress) |
1571 |
1570 |
1572 def removeVariableByFilter(self, address_model): |
1571 def removeVariableByFilter(self, address_model): |
1573 if self.interface: |
1572 if self.interface is not None: |
1574 for content in self.interface.getcontent(): |
1573 for content in self.interface.getcontent(): |
1575 for variable in content.getvariable(): |
1574 for variable in content.getvariable(): |
1576 var_address = variable.getaddress() |
1575 var_address = variable.getaddress() |
1577 if var_address is not None: |
1576 if var_address is not None: |
1578 result = address_model.match(var_address) |
1577 result = address_model.match(var_address) |
1799 instance.setexecutionOrderId(new_executionOrder) |
1798 instance.setexecutionOrderId(new_executionOrder) |
1800 else: |
1799 else: |
1801 raise TypeError, _("Can only generate execution order on FBD networks!") |
1800 raise TypeError, _("Can only generate execution order on FBD networks!") |
1802 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1801 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1803 |
1802 |
1804 def appendcontentInstance(self, name, instance): |
1803 def appendcontentInstance(self, instance): |
1805 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1804 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1806 self.content.appendcontent(instance) |
1805 self.content.appendcontent(instance) |
1807 else: |
1806 else: |
1808 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1807 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1809 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1808 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1810 |
1809 |
1811 def getcontentInstances(self): |
1810 def getcontentInstances(self): |
1812 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1811 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1813 return self.content.getcontent() |
1812 return self.content.getcontent() |
1814 else: |
1813 else: |
1815 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1814 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1816 setattr(cls, "getcontentInstances", getcontentInstances) |
1815 setattr(cls, "getcontentInstances", getcontentInstances) |
1817 |
1816 |
1818 def getcontentInstance(self, local_id): |
1817 def getcontentInstance(self, local_id): |
1819 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1818 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1820 instance = self.content.xpath("*[@localId=%d]" % local_id) |
1819 instance = self.content.xpath("*[@localId=%d]" % local_id) |
1821 if len(instance) > 0: |
1820 if len(instance) > 0: |
1822 return instance[0] |
1821 return instance[0] |
1823 return None |
1822 return None |
1824 else: |
1823 else: |
1825 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1824 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1826 setattr(cls, "getcontentInstance", getcontentInstance) |
1825 setattr(cls, "getcontentInstance", getcontentInstance) |
1827 |
1826 |
1828 def getcontentRandomInstance(self, exclude): |
1827 def getcontentRandomInstance(self, exclude): |
1829 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1828 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1830 instance = self.content.xpath("*%s[position()=1]" % |
1829 instance = self.content.xpath("*%s[position()=1]" % |
1833 if len(exclude) > 0 else "")) |
1832 if len(exclude) > 0 else "")) |
1834 if len(instance) > 0: |
1833 if len(instance) > 0: |
1835 return instance[0] |
1834 return instance[0] |
1836 return None |
1835 return None |
1837 else: |
1836 else: |
1838 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1837 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1839 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1838 setattr(cls, "getcontentRandomInstance", getcontentRandomInstance) |
1840 |
1839 |
1841 def getcontentInstanceByName(self, name): |
1840 def getcontentInstanceByName(self, name): |
1842 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1841 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1843 instance = self.content.xpath("ppx:block[@instanceName=%s]" % name, namespaces=PLCOpenParser.NSMAP) |
1842 instance = self.content.xpath("ppx:block[@instanceName=%s]" % name, namespaces=PLCOpenParser.NSMAP) |
1844 if len(instance) > 0: |
1843 if len(instance) > 0: |
1845 return instance[0] |
1844 return instance[0] |
1846 return None |
1845 return None |
1847 else: |
1846 else: |
1848 raise TypeError, _("%s body don't have instances!")%self.content["name"] |
1847 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1849 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1848 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1850 |
1849 |
1851 def removecontentInstance(self, local_id): |
1850 def removecontentInstance(self, local_id): |
1852 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1851 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1853 instance = self.content.xpath("*[@localId=%d]" % local_id) |
1852 instance = self.content.xpath("*[@localId=%d]" % local_id) |
1854 if len(instance) > 0: |
1853 if len(instance) > 0: |
1855 self.content.remove(instance[0]) |
1854 self.content.remove(instance[0]) |
1856 else: |
1855 else: |
1857 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1856 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1858 else: |
1857 else: |
1859 raise TypeError, "%s body don't have instances!"%self.content["name"] |
1858 raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() |
1860 setattr(cls, "removecontentInstance", removecontentInstance) |
1859 setattr(cls, "removecontentInstance", removecontentInstance) |
1861 |
1860 |
1862 def settext(self, text): |
1861 def settext(self, text): |
1863 if self.content.getLocalTag() in ["IL","ST"]: |
1862 if self.content.getLocalTag() in ["IL","ST"]: |
1864 self.content.setanyText(text) |
1863 self.content.setanyText(text) |
1865 else: |
1864 else: |
1866 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1865 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1867 setattr(cls, "settext", settext) |
1866 setattr(cls, "settext", settext) |
1868 |
1867 |
1869 def gettext(self): |
1868 def gettext(self): |
1870 if self.content.getLocalTag() in ["IL","ST"]: |
1869 if self.content.getLocalTag() in ["IL","ST"]: |
1871 return self.content.getanyText() |
1870 return self.content.getanyText() |
1872 else: |
1871 else: |
1873 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1872 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1874 setattr(cls, "gettext", gettext) |
1873 setattr(cls, "gettext", gettext) |
1875 |
1874 |
1876 def hasblock(self, block_type): |
1875 def hasblock(self, block_type): |
1877 if self.content.getLocalTag() in ["IL","ST"]: |
1876 if self.content.getLocalTag() in ["IL","ST"]: |
1878 return self.content.hasblock(block_type) |
1877 return self.content.hasblock(block_type) |
1879 else: |
1878 else: |
1880 raise TypeError, _("%s body don't have text!")%self.content["name"] |
1879 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1881 setattr(cls, "hasblock", hasblock) |
1880 setattr(cls, "hasblock", hasblock) |
1882 |
1881 |
1883 def updateElementName(self, old_name, new_name): |
1882 def updateElementName(self, old_name, new_name): |
1884 if self.content.getLocalTag() in ["IL", "ST"]: |
1883 if self.content.getLocalTag() in ["IL", "ST"]: |
1885 self.content.updateElementName(old_name, new_name) |
1884 self.content.updateElementName(old_name, new_name) |
2138 infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
2137 infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
2139 infos["specific_values"]["connectors"] = len(infos["outputs"]) |
2138 infos["specific_values"]["connectors"] = len(infos["outputs"]) |
2140 return infos |
2139 return infos |
2141 return getpowerrailinfos |
2140 return getpowerrailinfos |
2142 |
2141 |
2143 def _getldelementinfosFunction(type): |
2142 def _getldelementinfosFunction(ld_element_type): |
2144 def getldelementinfos(self): |
2143 def getldelementinfos(self): |
2145 infos = _getelementinfos(self) |
2144 infos = _getelementinfos(self) |
2146 infos["type"] = type |
2145 infos["type"] = ld_element_type |
2147 specific_values = infos["specific_values"] |
2146 specific_values = infos["specific_values"] |
2148 specific_values["name"] = self.getvariable() |
2147 specific_values["name"] = self.getvariable().text |
2149 _getexecutionOrder(self, specific_values) |
2148 _getexecutionOrder(self, specific_values) |
2150 specific_values["negated"] = self.getnegated() |
2149 specific_values["negated"] = self.getnegated() |
2151 specific_values["edge"] = self.getedge() |
2150 specific_values["edge"] = self.getedge() |
2152 if type == "coil": |
2151 if type == "coil": |
2153 specific_values["storage"] = self.getstorage() |
2152 specific_values["storage"] = self.getstorage() |
2272 |
2271 |
2273 cls = _initElementClass("rightPowerRail", "ldObjects", "multiple") |
2272 cls = _initElementClass("rightPowerRail", "ldObjects", "multiple") |
2274 if cls: |
2273 if cls: |
2275 setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
2274 setattr(cls, "getinfos", _getpowerrailinfosFunction("rightPowerRail")) |
2276 |
2275 |
|
2276 def _UpdateLDElementName(self, old_name, new_name): |
|
2277 if self.variable.text == old_name: |
|
2278 self.variable.text = new_name |
|
2279 |
|
2280 def _UpdateLDElementAddress(self, address_model, new_leading): |
|
2281 self.variable.text = update_address(self.variable.text, address_model, new_leading) |
|
2282 |
|
2283 def _getSearchInLDElement(ld_element_type): |
|
2284 def SearchInLDElement(self, criteria, parent_infos=[]): |
|
2285 return _Search([("reference", self.variable.text)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) |
|
2286 return SearchInLDElement |
|
2287 |
2277 cls = _initElementClass("contact", "ldObjects", "single") |
2288 cls = _initElementClass("contact", "ldObjects", "single") |
2278 if cls: |
2289 if cls: |
2279 setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
2290 setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
2280 |
2291 setattr(cls, "updateElementName", _UpdateLDElementName) |
2281 def updateElementName(self, old_name, new_name): |
2292 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2282 if self.variable == old_name: |
2293 setattr(cls, "Search", _getSearchInLDElement("contact")) |
2283 self.variable = new_name |
|
2284 setattr(cls, "updateElementName", updateElementName) |
|
2285 |
|
2286 def updateElementAddress(self, address_model, new_leading): |
|
2287 self.variable = update_address(self.variable, address_model, new_leading) |
|
2288 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2289 |
|
2290 def Search(self, criteria, parent_infos=[]): |
|
2291 return _Search([("reference", self.getvariable())], criteria, parent_infos + ["contact", self.getlocalId()]) |
|
2292 setattr(cls, "Search", Search) |
|
2293 |
2294 |
2294 cls = _initElementClass("coil", "ldObjects", "single") |
2295 cls = _initElementClass("coil", "ldObjects", "single") |
2295 if cls: |
2296 if cls: |
2296 setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
2297 setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
2297 |
2298 setattr(cls, "updateElementName", _UpdateLDElementName) |
2298 def updateElementName(self, old_name, new_name): |
2299 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2299 if self.variable == old_name: |
2300 setattr(cls, "Search", _getSearchInLDElement("coil")) |
2300 self.variable = new_name |
|
2301 setattr(cls, "updateElementName", updateElementName) |
|
2302 |
|
2303 def updateElementAddress(self, address_model, new_leading): |
|
2304 self.variable = update_address(self.variable, address_model, new_leading) |
|
2305 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2306 |
|
2307 def Search(self, criteria, parent_infos=[]): |
|
2308 return _Search([("reference", self.getvariable())], criteria, parent_infos + ["coil", self.getlocalId()]) |
|
2309 setattr(cls, "Search", Search) |
|
2310 |
2301 |
2311 cls = _initElementClass("step", "sfcObjects", "single") |
2302 cls = _initElementClass("step", "sfcObjects", "single") |
2312 if cls: |
2303 if cls: |
2313 def getinfos(self): |
2304 def getinfos(self): |
2314 infos = _getelementinfos(self) |
2305 infos = _getelementinfos(self) |
2368 setattr(cls, "getinfos", getinfos) |
2359 setattr(cls, "getinfos", getinfos) |
2369 |
2360 |
2370 def setconditionContent(self, condition_type, value): |
2361 def setconditionContent(self, condition_type, value): |
2371 if not self.condition: |
2362 if not self.condition: |
2372 self.addcondition() |
2363 self.addcondition() |
|
2364 if condition_type == "connection": |
|
2365 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
|
2366 else: |
|
2367 condition = PLCOpenParser.CreateElement(condition_type, "condition") |
|
2368 self.condition.setcontent(condition) |
2373 if condition_type == "reference": |
2369 if condition_type == "reference": |
2374 condition = PLCOpenParser.CreateElement("reference", "condition") |
|
2375 condition.setname(value) |
2370 condition.setname(value) |
2376 elif condition_type == "inline": |
2371 elif condition_type == "inline": |
2377 condition = PLCOpenParser.CreateElement("inline", "condition") |
2372 condition.setcontent(PLCOpenParser.CreateElement("ST", "inline")) |
2378 condition.setcontent(PLCOpenParser.GetElementClass("ST", "inline")) |
2373 condition.settext(value) |
2379 condition.setanyText(value) |
|
2380 elif condition_type == "connection": |
|
2381 condition = PLCOpenParser.CreateElementClass("connectionPointIn") |
|
2382 self.condition.setcontent(condition) |
|
2383 setattr(cls, "setconditionContent", setconditionContent) |
2374 setattr(cls, "setconditionContent", setconditionContent) |
2384 |
2375 |
2385 def getconditionContent(self): |
2376 def getconditionContent(self): |
2386 if self.condition: |
2377 if self.condition: |
2387 content = self.condition.getcontent() |
2378 content = self.condition.getcontent() |
2388 values = {"type" : content.getLocalTag()} |
2379 values = {"type" : content.getLocalTag()} |
2389 if values["type"] == "reference": |
2380 if values["type"] == "reference": |
2390 values["value"] = content.getname() |
2381 values["value"] = content.getname() |
2391 elif values["type"] == "inline": |
2382 elif values["type"] == "inline": |
2392 values["value"] = content.getanyText() |
2383 values["value"] = content.gettext() |
2393 elif values["type"] == "connectionPointIn": |
2384 elif values["type"] == "connectionPointIn": |
2394 values["type"] = "connection" |
2385 values["type"] = "connection" |
2395 values["value"] = content |
2386 values["value"] = content |
2396 return values |
2387 return values |
2397 return "" |
2388 return "" |
2398 setattr(cls, "getconditionContent", getconditionContent) |
2389 setattr(cls, "getconditionContent", getconditionContent) |
2399 |
2390 |
2400 def getconditionConnection(self): |
2391 def getconditionConnection(self): |
2401 if self.condition: |
2392 if self.condition: |
2402 content = self.condition.getcontent() |
2393 content = self.condition.getcontent() |
2403 if content.getLocalTag() == "connectionPointIn": |
2394 if content.getLocalTag() == "connection": |
2404 return content |
2395 return content |
2405 return None |
2396 return None |
2406 setattr(cls, "getconditionConnection", getconditionConnection) |
2397 setattr(cls, "getconditionConnection", getconditionConnection) |
2407 |
2398 |
2408 def getBoundingBox(self): |
2399 def getBoundingBox(self): |
2643 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2634 search_result.extend(action.Search(criteria, parent_infos + ["action", idx])) |
2644 return search_result |
2635 return search_result |
2645 setattr(cls, "Search", Search) |
2636 setattr(cls, "Search", Search) |
2646 |
2637 |
2647 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2638 def _SearchInIOVariable(self, criteria, parent_infos=[]): |
2648 return _Search([("expression", self.getexpression())], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
2639 return _Search([("expression", self.expression.text)], criteria, parent_infos + ["io_variable", self.getlocalId()]) |
|
2640 |
|
2641 def _UpdateIOElementName(self, old_name, new_name): |
|
2642 if self.expression.text == old_name: |
|
2643 self.expression.text = new_name |
|
2644 |
|
2645 def _UpdateIOElementAddress(self, old_name, new_name): |
|
2646 self.expression.text = update_address(self.expression.text, address_model, new_leading) |
2649 |
2647 |
2650 cls = _initElementClass("inVariable", "fbdObjects") |
2648 cls = _initElementClass("inVariable", "fbdObjects") |
2651 if cls: |
2649 if cls: |
2652 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2650 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
2653 |
2651 setattr(cls, "updateElementName", _UpdateIOElementName) |
2654 def updateElementName(self, old_name, new_name): |
2652 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2655 if self.expression == old_name: |
|
2656 self.expression = new_name |
|
2657 setattr(cls, "updateElementName", updateElementName) |
|
2658 |
|
2659 def updateElementAddress(self, address_model, new_leading): |
|
2660 self.expression = update_address(self.expression, address_model, new_leading) |
|
2661 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2662 |
|
2663 setattr(cls, "Search", _SearchInIOVariable) |
2653 setattr(cls, "Search", _SearchInIOVariable) |
2664 |
2654 |
2665 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2655 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2666 if cls: |
2656 if cls: |
2667 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2657 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
2668 |
2658 setattr(cls, "updateElementName", _UpdateIOElementName) |
2669 def updateElementName(self, old_name, new_name): |
2659 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2670 if self.expression == old_name: |
|
2671 self.expression = new_name |
|
2672 setattr(cls, "updateElementName", updateElementName) |
|
2673 |
|
2674 def updateElementAddress(self, address_model, new_leading): |
|
2675 self.expression = update_address(self.expression, address_model, new_leading) |
|
2676 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2677 |
|
2678 setattr(cls, "Search", _SearchInIOVariable) |
2660 setattr(cls, "Search", _SearchInIOVariable) |
2679 |
2661 |
2680 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2662 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2681 if cls: |
2663 if cls: |
2682 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2664 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
2683 |
2665 setattr(cls, "updateElementName", _UpdateIOElementName) |
2684 def updateElementName(self, old_name, new_name): |
2666 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2685 if self.expression == old_name: |
|
2686 self.expression = new_name |
|
2687 setattr(cls, "updateElementName", updateElementName) |
|
2688 |
|
2689 def updateElementAddress(self, address_model, new_leading): |
|
2690 self.expression = update_address(self.expression, address_model, new_leading) |
|
2691 setattr(cls, "updateElementAddress", updateElementAddress) |
|
2692 |
|
2693 setattr(cls, "Search", _SearchInIOVariable) |
2667 setattr(cls, "Search", _SearchInIOVariable) |
2694 |
2668 |
2695 |
2669 |
2696 def _SearchInConnector(self, criteria, parent_infos=[]): |
2670 def _SearchInConnector(self, criteria, parent_infos=[]): |
2697 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2671 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2764 |
2738 |
2765 def getconnections(self): |
2739 def getconnections(self): |
2766 return self.xpath("ppx:connection", namespaces=PLCOpenParser.NSMAP) |
2740 return self.xpath("ppx:connection", namespaces=PLCOpenParser.NSMAP) |
2767 setattr(cls, "getconnections", getconnections) |
2741 setattr(cls, "getconnections", getconnections) |
2768 |
2742 |
|
2743 def getconnection(self, idx): |
|
2744 connection = self.xpath("ppx:connection[position()=%d]" % (idx + 1), |
|
2745 namespaces=PLCOpenParser.NSMAP) |
|
2746 if len(connection) > 0: |
|
2747 return connection[0] |
|
2748 return None |
|
2749 setattr(cls, "getconnection", getconnection) |
|
2750 |
2769 def setconnectionId(self, idx, local_id): |
2751 def setconnectionId(self, idx, local_id): |
2770 if len(self.content) > idx: |
2752 connection = self.getconnection(idx) |
2771 self.content[idx].setrefLocalId(local_id) |
2753 if connection is not None: |
|
2754 connection.setrefLocalId(local_id) |
2772 setattr(cls, "setconnectionId", setconnectionId) |
2755 setattr(cls, "setconnectionId", setconnectionId) |
2773 |
2756 |
2774 def getconnectionId(self, idx): |
2757 def getconnectionId(self, idx): |
2775 if len(self.content) > idx: |
2758 connection = self.getconnection(idx) |
2776 return self.content[idx].getrefLocalId() |
2759 if connection is not None: |
|
2760 return connection.getrefLocalId() |
2777 return None |
2761 return None |
2778 setattr(cls, "getconnectionId", getconnectionId) |
2762 setattr(cls, "getconnectionId", getconnectionId) |
2779 |
2763 |
2780 def setconnectionPoints(self, idx, points): |
2764 def setconnectionPoints(self, idx, points): |
2781 if len(self.content) > idx: |
2765 connection = self.getconnection(idx) |
2782 self.content[idx].setpoints(points) |
2766 if connection is not None: |
|
2767 connection.setpoints(points) |
2783 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2768 setattr(cls, "setconnectionPoints", setconnectionPoints) |
2784 |
2769 |
2785 def getconnectionPoints(self, idx): |
2770 def getconnectionPoints(self, idx): |
2786 if len(self.content) > idx: |
2771 connection = self.getconnection(idx) |
2787 return self.content[idx].getpoints() |
2772 if connection is not None: |
|
2773 return connection.getpoints() |
2788 return [] |
2774 return [] |
2789 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2775 setattr(cls, "getconnectionPoints", getconnectionPoints) |
2790 |
2776 |
2791 def setconnectionParameter(self, idx, parameter): |
2777 def setconnectionParameter(self, idx, parameter): |
2792 if len(self.content) > idx: |
2778 connection = self.getconnection(idx) |
2793 self.content[idx].setformalParameter(parameter) |
2779 if connection is not None: |
|
2780 connection.setformalParameter(parameter) |
2794 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2781 setattr(cls, "setconnectionParameter", setconnectionParameter) |
2795 |
2782 |
2796 def getconnectionParameter(self, idx): |
2783 def getconnectionParameter(self, idx): |
2797 if len(self.content) > idx: |
2784 connection = self.getconnection(idx) |
2798 return self.content[idx].getformalParameter() |
2785 if connection is not None: |
|
2786 return connection.getformalParameter() |
2799 return None |
2787 return None |
2800 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2788 setattr(cls, "getconnectionParameter", getconnectionParameter) |
2801 |
2789 |
2802 cls = PLCOpenParser.GetElementClass("connectionPointOut") |
2790 cls = PLCOpenParser.GetElementClass("connectionPointOut") |
2803 if cls: |
2791 if cls: |
2804 def setrelPositionXY(self, x, y): |
2792 def setrelPositionXY(self, x, y): |
2805 self.relPosition = PLCOpenParser.CreateElement("position") |
2793 self.relPosition = PLCOpenParser.CreateElement("relPosition", "connectionPointOut") |
2806 self.relPosition.setx(x) |
2794 self.relPosition.setx(x) |
2807 self.relPosition.sety(y) |
2795 self.relPosition.sety(y) |
2808 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2796 setattr(cls, "setrelPositionXY", setrelPositionXY) |
2809 |
2797 |
2810 def getrelPositionXY(self): |
2798 def getrelPositionXY(self): |