448 |
448 |
449 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
449 setattr(cls, "getdataType", gettypeElementFunc("dataType")) |
450 |
450 |
451 def appenddataType(self, name): |
451 def appenddataType(self, name): |
452 if self.getdataType(name) is not None: |
452 if self.getdataType(name) is not None: |
453 raise ValueError, "\"%s\" Data Type already exists !!!" % name |
453 raise ValueError("\"%s\" Data Type already exists !!!" % name) |
454 self.types.appenddataTypeElement(name) |
454 self.types.appenddataTypeElement(name) |
455 setattr(cls, "appenddataType", appenddataType) |
455 setattr(cls, "appenddataType", appenddataType) |
456 |
456 |
457 def insertdataType(self, index, datatype): |
457 def insertdataType(self, index, datatype): |
458 self.types.insertdataTypeElement(index, datatype) |
458 self.types.insertdataTypeElement(index, datatype) |
503 return None |
503 return None |
504 setattr(cls, "getconfiguration", getconfiguration) |
504 setattr(cls, "getconfiguration", getconfiguration) |
505 |
505 |
506 def addconfiguration(self, name): |
506 def addconfiguration(self, name): |
507 if self.getconfiguration(name) is not None: |
507 if self.getconfiguration(name) is not None: |
508 raise ValueError, _("\"%s\" configuration already exists !!!") % name |
508 raise ValueError(_("\"%s\" configuration already exists !!!") % name) |
509 new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
509 new_configuration = PLCOpenParser.CreateElement("configuration", "configurations") |
510 new_configuration.setname(name) |
510 new_configuration.setname(name) |
511 self.instances.configurations.appendconfiguration(new_configuration) |
511 self.instances.configurations.appendconfiguration(new_configuration) |
512 setattr(cls, "addconfiguration", addconfiguration) |
512 setattr(cls, "addconfiguration", addconfiguration) |
513 |
513 |
514 def removeconfiguration(self, name): |
514 def removeconfiguration(self, name): |
515 configuration = self.getconfiguration(name) |
515 configuration = self.getconfiguration(name) |
516 if configuration is None: |
516 if configuration is None: |
517 raise ValueError, ("\"%s\" configuration doesn't exist !!!") % name |
517 raise ValueError(_("\"%s\" configuration doesn't exist !!!") % name) |
518 self.instances.configurations.remove(configuration) |
518 self.instances.configurations.remove(configuration) |
519 setattr(cls, "removeconfiguration", removeconfiguration) |
519 setattr(cls, "removeconfiguration", removeconfiguration) |
520 |
520 |
521 resources_xpath = PLCOpen_XPath( |
521 resources_xpath = PLCOpen_XPath( |
522 "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
522 "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]") |
528 return None |
528 return None |
529 setattr(cls, "getconfigurationResource", getconfigurationResource) |
529 setattr(cls, "getconfigurationResource", getconfigurationResource) |
530 |
530 |
531 def addconfigurationResource(self, config_name, name): |
531 def addconfigurationResource(self, config_name, name): |
532 if self.getconfigurationResource(config_name, name) is not None: |
532 if self.getconfigurationResource(config_name, name) is not None: |
533 msg = _("\"{a1}\" resource already exists in \"{a2}\" configuration !!!").format(a1=name, a2=config_name) |
533 raise ValueError( |
534 raise ValueError, msg |
534 _("\"{a1}\" resource already exists in \"{a2}\" configuration !!!"). |
|
535 format(a1=name, a2=config_name)) |
|
536 |
535 configuration = self.getconfiguration(config_name) |
537 configuration = self.getconfiguration(config_name) |
536 if configuration is not None: |
538 if configuration is not None: |
537 new_resource = PLCOpenParser.CreateElement("resource", "configuration") |
539 new_resource = PLCOpenParser.CreateElement("resource", "configuration") |
538 new_resource.setname(name) |
540 new_resource.setname(name) |
539 configuration.appendresource(new_resource) |
541 configuration.appendresource(new_resource) |
546 resource = self.getconfigurationResource(config_name, name) |
548 resource = self.getconfigurationResource(config_name, name) |
547 if resource is not None: |
549 if resource is not None: |
548 configuration.remove(resource) |
550 configuration.remove(resource) |
549 found = True |
551 found = True |
550 if not found: |
552 if not found: |
551 msg = _("\"{a1}\" resource doesn't exist in \"{a2}\" configuration !!!").format(a1=name, a2=config_name) |
553 raise ValueError( |
552 raise ValueError, msg |
554 _("\"{a1}\" resource doesn't exist in \"{a2}\" configuration !!!"). |
|
555 format(a1=name, a2=config_name)) |
|
556 |
553 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
557 setattr(cls, "removeconfigurationResource", removeconfigurationResource) |
554 |
558 |
555 def updateElementName(self, old_name, new_name): |
559 def updateElementName(self, old_name, new_name): |
556 for datatype in self.getdataTypes(): |
560 for datatype in self.getdataTypes(): |
557 datatype.updateElementName(old_name, new_name) |
561 datatype.updateElementName(old_name, new_name) |
944 setattr(cls, "getpouElement", getpouElement) |
948 setattr(cls, "getpouElement", getpouElement) |
945 |
949 |
946 def appendpouElement(self, name, pou_type, body_type): |
950 def appendpouElement(self, name, pou_type, body_type): |
947 for element in self.pous.getpou(): |
951 for element in self.pous.getpou(): |
948 if TextMatched(element.getname(), name): |
952 if TextMatched(element.getname(), name): |
949 raise ValueError, _("\"%s\" POU already exists !!!") % name |
953 raise ValueError(_("\"%s\" POU already exists !!!") % name) |
950 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
954 new_pou = PLCOpenParser.CreateElement("pou", "pous") |
951 self.pous.appendpou(new_pou) |
955 self.pous.appendpou(new_pou) |
952 new_pou.setname(name) |
956 new_pou.setname(name) |
953 new_pou.setpouType(pou_type) |
957 new_pou.setpouType(pou_type) |
954 new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
958 new_pou.appendbody(PLCOpenParser.CreateElement("body", "pou")) |
1151 def setbodyType(self, body_type): |
1155 def setbodyType(self, body_type): |
1152 if len(self.body) > 0: |
1156 if len(self.body) > 0: |
1153 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1157 if body_type in ["IL", "ST", "LD", "FBD", "SFC"]: |
1154 self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
1158 self.body[0].setcontent(PLCOpenParser.CreateElement(body_type, "body")) |
1155 else: |
1159 else: |
1156 raise ValueError, "%s isn't a valid body type!" % type |
1160 raise ValueError("%s isn't a valid body type!" % type) |
1157 setattr(cls, "setbodyType", setbodyType) |
1161 setattr(cls, "setbodyType", setbodyType) |
1158 |
1162 |
1159 def getbodyType(self): |
1163 def getbodyType(self): |
1160 if len(self.body) > 0: |
1164 if len(self.body) > 0: |
1161 return self.body[0].getcontent().getLocalTag() |
1165 return self.body[0].getcontent().getLocalTag() |
1692 TextMatched(tmp_instance.getname(), instance.getname()) and tmp_instance.getexecutionOrderId() == 0): |
1696 TextMatched(tmp_instance.getname(), instance.getname()) and tmp_instance.getexecutionOrderId() == 0): |
1693 connections = tmp_instance.connectionPointIn.getconnections() |
1697 connections = tmp_instance.connectionPointIn.getconnections() |
1694 if connections and len(connections) == 1: |
1698 if connections and len(connections) == 1: |
1695 self.compileelementExecutionOrder(connections[0]) |
1699 self.compileelementExecutionOrder(connections[0]) |
1696 else: |
1700 else: |
1697 raise TypeError, _("Can only generate execution order on FBD networks!") |
1701 raise TypeError(_("Can only generate execution order on FBD networks!")) |
1698 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1702 setattr(cls, "compileelementExecutionOrder", compileelementExecutionOrder) |
1699 |
1703 |
1700 def setelementExecutionOrder(self, instance, new_executionOrder): |
1704 def setelementExecutionOrder(self, instance, new_executionOrder): |
1701 if self.content.getLocalTag() == "FBD": |
1705 if self.content.getLocalTag() == "FBD": |
1702 old_executionOrder = instance.getexecutionOrderId() |
1706 old_executionOrder = instance.getexecutionOrderId() |
1708 element.setexecutionOrderId(element_executionOrder - 1) |
1712 element.setexecutionOrderId(element_executionOrder - 1) |
1709 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1713 if new_executionOrder <= element_executionOrder <= old_executionOrder: |
1710 element.setexecutionOrderId(element_executionOrder + 1) |
1714 element.setexecutionOrderId(element_executionOrder + 1) |
1711 instance.setexecutionOrderId(new_executionOrder) |
1715 instance.setexecutionOrderId(new_executionOrder) |
1712 else: |
1716 else: |
1713 raise TypeError, _("Can only generate execution order on FBD networks!") |
1717 raise TypeError(_("Can only generate execution order on FBD networks!")) |
1714 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1718 setattr(cls, "setelementExecutionOrder", setelementExecutionOrder) |
1715 |
1719 |
1716 def appendcontentInstance(self, instance): |
1720 def appendcontentInstance(self, instance): |
1717 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1721 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1718 self.content.appendcontent(instance) |
1722 self.content.appendcontent(instance) |
1719 else: |
1723 else: |
1720 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1724 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1721 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1725 setattr(cls, "appendcontentInstance", appendcontentInstance) |
1722 |
1726 |
1723 def getcontentInstances(self): |
1727 def getcontentInstances(self): |
1724 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1728 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1725 return self.content.getcontent() |
1729 return self.content.getcontent() |
1726 else: |
1730 else: |
1727 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1731 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1728 setattr(cls, "getcontentInstances", getcontentInstances) |
1732 setattr(cls, "getcontentInstances", getcontentInstances) |
1729 |
1733 |
1730 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1734 instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]") |
1731 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1735 instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]") |
1732 |
1736 |
1735 instance = instance_by_id_xpath(self.content, localId=local_id) |
1739 instance = instance_by_id_xpath(self.content, localId=local_id) |
1736 if len(instance) > 0: |
1740 if len(instance) > 0: |
1737 return instance[0] |
1741 return instance[0] |
1738 return None |
1742 return None |
1739 else: |
1743 else: |
1740 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1744 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1741 setattr(cls, "getcontentInstance", getcontentInstance) |
1745 setattr(cls, "getcontentInstance", getcontentInstance) |
1742 |
1746 |
1743 def getcontentInstancesIds(self): |
1747 def getcontentInstancesIds(self): |
1744 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1748 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1745 return OrderedDict([(instance.getlocalId(), True) |
1749 return OrderedDict([(instance.getlocalId(), True) |
1746 for instance in self.content]) |
1750 for instance in self.content]) |
1747 else: |
1751 else: |
1748 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1752 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1749 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1753 setattr(cls, "getcontentInstancesIds", getcontentInstancesIds) |
1750 |
1754 |
1751 def getcontentInstanceByName(self, name): |
1755 def getcontentInstanceByName(self, name): |
1752 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1756 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1753 instance = instance_by_name_xpath(self.content) |
1757 instance = instance_by_name_xpath(self.content) |
1754 if len(instance) > 0: |
1758 if len(instance) > 0: |
1755 return instance[0] |
1759 return instance[0] |
1756 return None |
1760 return None |
1757 else: |
1761 else: |
1758 raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag() |
1762 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1759 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1763 setattr(cls, "getcontentInstanceByName", getcontentInstanceByName) |
1760 |
1764 |
1761 def removecontentInstance(self, local_id): |
1765 def removecontentInstance(self, local_id): |
1762 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1766 if self.content.getLocalTag() in ["LD", "FBD", "SFC"]: |
1763 instance = instance_by_id_xpath(self.content, localId=local_id) |
1767 instance = instance_by_id_xpath(self.content, localId=local_id) |
1764 if len(instance) > 0: |
1768 if len(instance) > 0: |
1765 self.content.remove(instance[0]) |
1769 self.content.remove(instance[0]) |
1766 else: |
1770 else: |
1767 raise ValueError, _("Instance with id %d doesn't exist!") % id |
1771 raise ValueError(_("Instance with id %d doesn't exist!") % id) |
1768 else: |
1772 else: |
1769 raise TypeError, "%s body don't have instances!" % self.content.getLocalTag() |
1773 raise TypeError(_("%s body don't have instances!") % self.content.getLocalTag()) |
1770 setattr(cls, "removecontentInstance", removecontentInstance) |
1774 setattr(cls, "removecontentInstance", removecontentInstance) |
1771 |
1775 |
1772 def settext(self, text): |
1776 def settext(self, text): |
1773 if self.content.getLocalTag() in ["IL", "ST"]: |
1777 if self.content.getLocalTag() in ["IL", "ST"]: |
1774 self.content.setanyText(text) |
1778 self.content.setanyText(text) |
1775 else: |
1779 else: |
1776 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1780 raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
1777 setattr(cls, "settext", settext) |
1781 setattr(cls, "settext", settext) |
1778 |
1782 |
1779 def gettext(self): |
1783 def gettext(self): |
1780 if self.content.getLocalTag() in ["IL", "ST"]: |
1784 if self.content.getLocalTag() in ["IL", "ST"]: |
1781 return self.content.getanyText() |
1785 return self.content.getanyText() |
1782 else: |
1786 else: |
1783 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1787 raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
1784 setattr(cls, "gettext", gettext) |
1788 setattr(cls, "gettext", gettext) |
1785 |
1789 |
1786 def hasblock(self, block_type): |
1790 def hasblock(self, block_type): |
1787 if self.content.getLocalTag() in ["IL", "ST"]: |
1791 if self.content.getLocalTag() in ["IL", "ST"]: |
1788 return self.content.hasblock(block_type) |
1792 return self.content.hasblock(block_type) |
1789 else: |
1793 else: |
1790 raise TypeError, _("%s body don't have text!") % self.content.getLocalTag() |
1794 raise TypeError(_("%s body don't have text!") % self.content.getLocalTag()) |
1791 setattr(cls, "hasblock", hasblock) |
1795 setattr(cls, "hasblock", hasblock) |
1792 |
1796 |
1793 def updateElementName(self, old_name, new_name): |
1797 def updateElementName(self, old_name, new_name): |
1794 if self.content.getLocalTag() in ["IL", "ST"]: |
1798 if self.content.getLocalTag() in ["IL", "ST"]: |
1795 self.content.updateElementName(old_name, new_name) |
1799 self.content.updateElementName(old_name, new_name) |