1690 else: |
1690 else: |
1691 raise TypeError, _("Can only generate execution order on FBD networks!") |
1691 raise TypeError, _("Can only generate execution order on FBD networks!") |
1692 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1692 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1693 |
1693 |
1694 def appendcontentInstance(self, instance): |
1694 def appendcontentInstance(self, instance): |
1695 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1695 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1696 self.content.appendcontent(instance) |
1696 self.content.appendcontent(instance) |
1697 else: |
1697 else: |
1698 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1698 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1699 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1699 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1700 |
1700 |
1701 def getcontentInstances(self): |
1701 def getcontentInstances(self): |
1702 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1702 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1703 return self.content.getcontent() |
1703 return self.content.getcontent() |
1704 else: |
1704 else: |
1705 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1705 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1706 setattr(cls, "getcontentInstances", getcontentInstances) |
1706 setattr(cls, "getcontentInstances", getcontentInstances) |
1707 |
1707 |
1708 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1708 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1709 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1709 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1710 def getcontentInstance(self, local_id): |
1710 def getcontentInstance(self, local_id): |
1711 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1711 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1712 instance = instance_by_id_xpath(self.content, localId=local_id) |
1712 instance = instance_by_id_xpath(self.content, localId=local_id) |
1713 if len(instance) > 0: |
1713 if len(instance) > 0: |
1714 return instance[0] |
1714 return instance[0] |
1715 return None |
1715 return None |
1716 else: |
1716 else: |
1717 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1717 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1718 setattr(cls, "getcontentInstance", getcontentInstance) |
1718 setattr(cls, "getcontentInstance", getcontentInstance) |
1719 |
1719 |
1720 def getcontentInstancesIds(self): |
1720 def getcontentInstancesIds(self): |
1721 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1721 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1722 return OrderedDict([(instance.getlocalId(), True) |
1722 return OrderedDict([(instance.getlocalId(), True) |
1723 for instance in self.content]) |
1723 for instance in self.content]) |
1724 else: |
1724 else: |
1725 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1725 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1726 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1726 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1727 |
1727 |
1728 def getcontentInstanceByName(self, name): |
1728 def getcontentInstanceByName(self, name): |
1729 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1729 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1730 instance = instance_by_name_xpath(self.content) |
1730 instance = instance_by_name_xpath(self.content) |
1731 if len(instance) > 0: |
1731 if len(instance) > 0: |
1732 return instance[0] |
1732 return instance[0] |
1733 return None |
1733 return None |
1734 else: |
1734 else: |
1735 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1735 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1736 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1736 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1737 |
1737 |
1738 def removecontentInstance(self, local_id): |
1738 def removecontentInstance(self, local_id): |
1739 if self.content.getLocalTag() in ["LD","FBD","SFC"]: |
1739 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1740 instance = instance_by_id_xpath(self.content, localId=local_id) |
1740 instance = instance_by_id_xpath(self.content, localId=local_id) |
1741 if len(instance) > 0: |
1741 if len(instance) > 0: |
1742 self.content.remove(instance[0]) |
1742 self.content.remove(instance[0]) |
1743 else: |
1743 else: |
1744 raise ValueError, _("Instance with id %d doesn't exist!") % id |
1744 raise ValueError, _("Instance with id %d doesn't exist!") % id |
1745 else: |
1745 else: |
1746 raise TypeError, "%s body don't have instances!" % self.content.getLocalTag() |
1746 raise TypeError, "%s body don't have instances!" % self.content.getLocalTag() |
1747 setattr(cls, "removecontentInstance", removecontentInstance) |
1747 setattr(cls, "removecontentInstance", removecontentInstance) |
1748 |
1748 |
1749 def settext(self, text): |
1749 def settext(self, text): |
1750 if self.content.getLocalTag() in ["IL","ST"]: |
1750 if self.content.getLocalTag() in ["IL", "ST"]: |
1751 self.content.setanyText(text) |
1751 self.content.setanyText(text) |
1752 else: |
1752 else: |
1753 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1753 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1754 setattr(cls, "settext", settext) |
1754 setattr(cls, "settext", settext) |
1755 |
1755 |
1756 def gettext(self): |
1756 def gettext(self): |
1757 if self.content.getLocalTag() in ["IL","ST"]: |
1757 if self.content.getLocalTag() in ["IL", "ST"]: |
1758 return self.content.getanyText() |
1758 return self.content.getanyText() |
1759 else: |
1759 else: |
1760 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1760 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1761 setattr(cls, "gettext", gettext) |
1761 setattr(cls, "gettext", gettext) |
1762 |
1762 |
1763 def hasblock(self, block_type): |
1763 def hasblock(self, block_type): |
1764 if self.content.getLocalTag() in ["IL","ST"]: |
1764 if self.content.getLocalTag() in ["IL", "ST"]: |
1765 return self.content.hasblock(block_type) |
1765 return self.content.hasblock(block_type) |
1766 else: |
1766 else: |
1767 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1767 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1768 setattr(cls, "hasblock", hasblock) |
1768 setattr(cls, "hasblock", hasblock) |
1769 |
1769 |