217 time_values = [int(v) for v in values[:2]] |
217 time_values = [int(v) for v in values[:2]] |
218 seconds = float(values[2]) |
218 seconds = float(values[2]) |
219 time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
219 time_values.extend([int(seconds), int((seconds % 1) * 1000000)]) |
220 text = "T#" |
220 text = "T#" |
221 if time_values[0] != 0: |
221 if time_values[0] != 0: |
222 text += "%dh"%time_values[0] |
222 text += "%dh" % time_values[0] |
223 if time_values[1] != 0: |
223 if time_values[1] != 0: |
224 text += "%dm"%time_values[1] |
224 text += "%dm" % time_values[1] |
225 if time_values[2] != 0: |
225 if time_values[2] != 0: |
226 text += "%ds"%time_values[2] |
226 text += "%ds" % time_values[2] |
227 if time_values[3] != 0: |
227 if time_values[3] != 0: |
228 if time_values[3] % 1000 != 0: |
228 if time_values[3] % 1000 != 0: |
229 text += "%.3fms"%(float(time_values[3]) / 1000) |
229 text += "%.3fms" % (float(time_values[3]) / 1000) |
230 else: |
230 else: |
231 text += "%dms"%(time_values[3] / 1000) |
231 text += "%dms" % (time_values[3] / 1000) |
232 task.set("interval", text) |
232 task.set("interval", text) |
233 |
233 |
234 # Update resources pou instance attributes |
234 # Update resources pou instance attributes |
235 for pouInstance in ResourceInstancesXpath(resource): |
235 for pouInstance in ResourceInstancesXpath(resource): |
236 type_name = pouInstance.attrib.pop("type") |
236 type_name = pouInstance.attrib.pop("type") |
415 |
415 |
416 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
416 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
417 |
417 |
418 def appenddataType(self, name): |
418 def appenddataType(self, name): |
419 if self.getdataType(name) is not None: |
419 if self.getdataType(name) is not None: |
420 raise ValueError, "\"%s\" Data Type already exists !!!"%name |
420 raise ValueError, "\"%s\" Data Type already exists !!!" % name |
421 self.types.appenddataTypeElement(name) |
421 self.types.appenddataTypeElement(name) |
422 setattr(cls, "appenddataType", appenddataType) |
422 setattr(cls, "appenddataType", appenddataType) |
423 |
423 |
424 def insertdataType(self, index, datatype): |
424 def insertdataType(self, index, datatype): |
425 self.types.insertdataTypeElement(index, datatype) |
425 self.types.insertdataTypeElement(index, datatype) |
900 setattr(cls, "getpouElement", getpouElement) |
900 setattr(cls, "getpouElement", getpouElement) |
901 |
901 |
902 def appendpouElement(self, name, pou_type, body_type): |
902 def appendpouElement(self, name, pou_type, body_type): |
903 for element in self.pous.getpou(): |
903 for element in self.pous.getpou(): |
904 if TextMatched(element.getname(), name): |
904 if TextMatched(element.getname(), name): |
905 raise ValueError, _("\"%s\" POU already exists !!!")%name |
905 raise ValueError, _("\"%s\" POU already exists !!!") % name |
906 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
906 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
907 self.pous.appendpou(new_pou) |
907 self.pous.appendpou(new_pou) |
908 new_pou.setname(name) |
908 new_pou.setname(name) |
909 new_pou.setpouType(pou_type) |
909 new_pou.setpouType(pou_type) |
910 new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
910 new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
1099 def setbodyType(self, body_type): |
1099 def setbodyType(self, body_type): |
1100 if len(self.body) > 0: |
1100 if len(self.body) > 0: |
1101 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1101 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1102 self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
1102 self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
1103 else: |
1103 else: |
1104 raise ValueError, "%s isn't a valid body type!"%type |
1104 raise ValueError, "%s isn't a valid body type!" % type |
1105 setattr(cls, "setbodyType", setbodyType) |
1105 setattr(cls, "setbodyType", setbodyType) |
1106 |
1106 |
1107 def getbodyType(self): |
1107 def getbodyType(self): |
1108 if len(self.body) > 0: |
1108 if len(self.body) > 0: |
1109 return self.body[0].getcontent().getLocalTag() |
1109 return self.body[0].getcontent().getLocalTag() |
1646 |
1646 |
1647 def appendcontentInstance(self, instance): |
1647 def appendcontentInstance(self, instance): |
1648 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1648 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1649 self.content.appendcontent(instance) |
1649 self.content.appendcontent(instance) |
1650 else: |
1650 else: |
1651 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1651 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1652 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1652 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1653 |
1653 |
1654 def getcontentInstances(self): |
1654 def getcontentInstances(self): |
1655 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1655 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1656 return self.content.getcontent() |
1656 return self.content.getcontent() |
1657 else: |
1657 else: |
1658 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1658 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1659 setattr(cls, "getcontentInstances", getcontentInstances) |
1659 setattr(cls, "getcontentInstances", getcontentInstances) |
1660 |
1660 |
1661 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1661 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1662 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1662 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1663 def getcontentInstance(self, local_id): |
1663 def getcontentInstance(self, local_id): |
1665 instance = instance_by_id_xpath(self.content, localId=local_id) |
1665 instance = instance_by_id_xpath(self.content, localId=local_id) |
1666 if len(instance) > 0: |
1666 if len(instance) > 0: |
1667 return instance[0] |
1667 return instance[0] |
1668 return None |
1668 return None |
1669 else: |
1669 else: |
1670 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1670 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1671 setattr(cls, "getcontentInstance", getcontentInstance) |
1671 setattr(cls, "getcontentInstance", getcontentInstance) |
1672 |
1672 |
1673 def getcontentInstancesIds(self): |
1673 def getcontentInstancesIds(self): |
1674 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1674 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1675 return OrderedDict([(instance.getlocalId(), True) |
1675 return OrderedDict([(instance.getlocalId(), True) |
1676 for instance in self.content]) |
1676 for instance in self.content]) |
1677 else: |
1677 else: |
1678 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1678 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1679 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1679 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1680 |
1680 |
1681 def getcontentInstanceByName(self, name): |
1681 def getcontentInstanceByName(self, name): |
1682 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1682 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1683 instance = instance_by_name_xpath(self.content) |
1683 instance = instance_by_name_xpath(self.content) |
1684 if len(instance) > 0: |
1684 if len(instance) > 0: |
1685 return instance[0] |
1685 return instance[0] |
1686 return None |
1686 return None |
1687 else: |
1687 else: |
1688 raise TypeError, _("%s body don't have instances!")%self.content.getLocalTag() |
1688 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1689 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1689 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1690 |
1690 |
1691 def removecontentInstance(self, local_id): |
1691 def removecontentInstance(self, local_id): |
1692 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1692 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1693 instance = instance_by_id_xpath(self.content, localId=local_id) |
1693 instance = instance_by_id_xpath(self.content, localId=local_id) |
1694 if len(instance) > 0: |
1694 if len(instance) > 0: |
1695 self.content.remove(instance[0]) |
1695 self.content.remove(instance[0]) |
1696 else: |
1696 else: |
1697 raise ValueError, _("Instance with id %d doesn't exist!")%id |
1697 raise ValueError, _("Instance with id %d doesn't exist!") % id |
1698 else: |
1698 else: |
1699 raise TypeError, "%s body don't have instances!"%self.content.getLocalTag() |
1699 raise TypeError, "%s body don't have instances!" % self.content.getLocalTag() |
1700 setattr(cls, "removecontentInstance", removecontentInstance) |
1700 setattr(cls, "removecontentInstance", removecontentInstance) |
1701 |
1701 |
1702 def settext(self, text): |
1702 def settext(self, text): |
1703 if self.content.getLocalTag() in ["IL","ST"]: |
1703 if self.content.getLocalTag() in ["IL","ST"]: |
1704 self.content.setanyText(text) |
1704 self.content.setanyText(text) |
1705 else: |
1705 else: |
1706 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1706 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1707 setattr(cls, "settext", settext) |
1707 setattr(cls, "settext", settext) |
1708 |
1708 |
1709 def gettext(self): |
1709 def gettext(self): |
1710 if self.content.getLocalTag() in ["IL","ST"]: |
1710 if self.content.getLocalTag() in ["IL","ST"]: |
1711 return self.content.getanyText() |
1711 return self.content.getanyText() |
1712 else: |
1712 else: |
1713 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1713 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1714 setattr(cls, "gettext", gettext) |
1714 setattr(cls, "gettext", gettext) |
1715 |
1715 |
1716 def hasblock(self, block_type): |
1716 def hasblock(self, block_type): |
1717 if self.content.getLocalTag() in ["IL","ST"]: |
1717 if self.content.getLocalTag() in ["IL","ST"]: |
1718 return self.content.hasblock(block_type) |
1718 return self.content.hasblock(block_type) |
1719 else: |
1719 else: |
1720 raise TypeError, _("%s body don't have text!")%self.content.getLocalTag() |
1720 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1721 setattr(cls, "hasblock", hasblock) |
1721 setattr(cls, "hasblock", hasblock) |
1722 |
1722 |
1723 def updateElementName(self, old_name, new_name): |
1723 def updateElementName(self, old_name, new_name): |
1724 if self.content.getLocalTag() in ["IL", "ST"]: |
1724 if self.content.getLocalTag() in ["IL", "ST"]: |
1725 self.content.updateElementName(old_name, new_name) |
1725 self.content.updateElementName(old_name, new_name) |