744 return factory.GetRoot() |
744 return factory.GetRoot() |
745 |
745 |
746 return None |
746 return None |
747 |
747 |
748 def GetInstanceList(self, root, name, debug = False): |
748 def GetInstanceList(self, root, name, debug = False): |
749 project = self.GetProject(debug) |
749 instances = [] |
750 if project is not None: |
750 project = self.GetProject(debug) |
751 instances = [] |
751 if project is not None: |
752 factory = InstancesPathFactory(instances) |
752 factory = InstancesPathFactory(instances) |
753 |
753 |
754 parser = etree.XMLParser() |
754 parser = etree.XMLParser() |
755 parser.resolvers.add(LibraryResolver(self, debug)) |
755 parser.resolvers.add(LibraryResolver(self, debug)) |
756 |
756 |
762 ("instances_ns", "AddInstance"): factory.AddInstance}) |
762 ("instances_ns", "AddInstance"): factory.AddInstance}) |
763 |
763 |
764 instances_path_xslt_tree(root, |
764 instances_path_xslt_tree(root, |
765 instance_type=etree.XSLT.strparam(name)) |
765 instance_type=etree.XSLT.strparam(name)) |
766 |
766 |
767 if len(instances) > 0: |
767 return instances |
768 return instances |
768 |
769 |
|
770 return None |
|
771 |
|
772 def SearchPouInstances(self, tagname, debug = False): |
769 def SearchPouInstances(self, tagname, debug = False): |
773 project = self.GetProject(debug) |
770 project = self.GetProject(debug) |
774 if project is not None: |
771 if project is not None: |
775 words = tagname.split("::") |
772 words = tagname.split("::") |
776 if words[0] == "P": |
773 if words[0] == "P": |
824 |
821 |
825 # Return if data type given by name is used by another data type or pou |
822 # Return if data type given by name is used by another data type or pou |
826 def DataTypeIsUsed(self, name, debug = False): |
823 def DataTypeIsUsed(self, name, debug = False): |
827 project = self.GetProject(debug) |
824 project = self.GetProject(debug) |
828 if project is not None: |
825 if project is not None: |
829 return self.GetInstanceList(project, name, debug) is not None |
826 return len(self.GetInstanceList(project, name, debug)) > 0 |
830 return False |
827 return False |
831 |
828 |
832 # Return if pou given by name is used by another pou |
829 # Return if pou given by name is used by another pou |
833 def PouIsUsed(self, name, debug = False): |
830 def PouIsUsed(self, name, debug = False): |
834 project = self.GetProject(debug) |
831 project = self.GetProject(debug) |
835 if project is not None: |
832 if project is not None: |
836 return self.GetInstanceList(project, name, debug) is not None |
833 return len(self.GetInstanceList(project, name, debug)) > 0 |
837 return False |
834 return False |
838 |
835 |
839 # Return if pou given by name is directly or undirectly used by the reference pou |
836 # Return if pou given by name is directly or undirectly used by the reference pou |
840 def PouIsUsedBy(self, name, reference, debug = False): |
837 def PouIsUsedBy(self, name, reference, debug = False): |
841 pou_infos = self.GetPou(reference, debug) |
838 pou_infos = self.GetPou(reference, debug) |
842 if pou_infos is not None: |
839 if pou_infos is not None: |
843 return self.GetInstanceList(pou_infos, name, debug) is not None |
840 return len(self.GetInstanceList(pou_infos, name, debug)) > 0 |
844 return False |
841 return False |
845 |
842 |
846 def GenerateProgram(self, filepath=None): |
843 def GenerateProgram(self, filepath=None): |
847 errors = [] |
844 errors = [] |
848 warnings = [] |
845 warnings = [] |
1625 for category in self.TotalTypes] |
1622 for category in self.TotalTypes] |
1626 blocktypes.append({"name" : USER_DEFINED_POUS, |
1623 blocktypes.append({"name" : USER_DEFINED_POUS, |
1627 "list": [pou.getblockInfos() |
1624 "list": [pou.getblockInfos() |
1628 for pou in project.getpous(name, filter) |
1625 for pou in project.getpous(name, filter) |
1629 if (name is None or |
1626 if (name is None or |
1630 self.GetInstanceList(pou, name, debug) is None)]}) |
1627 len(self.GetInstanceList(pou, name, debug)) > 0)]}) |
1631 return blocktypes |
1628 return blocktypes |
1632 return self.TotalTypes |
1629 return self.TotalTypes |
1633 |
1630 |
1634 # Return Function Block types checking for recursion |
1631 # Return Function Block types checking for recursion |
1635 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1632 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1645 blocktypes.append(block["name"]) |
1642 blocktypes.append(block["name"]) |
1646 if project is not None: |
1643 if project is not None: |
1647 blocktypes.extend([pou.getname() |
1644 blocktypes.extend([pou.getname() |
1648 for pou in project.getpous(name, ["functionBlock"]) |
1645 for pou in project.getpous(name, ["functionBlock"]) |
1649 if (name is None or |
1646 if (name is None or |
1650 self.GetInstanceList(pou, name, debug) is None)]) |
1647 len(self.GetInstanceList(pou, name, debug)) > 0)]) |
1651 return blocktypes |
1648 return blocktypes |
1652 |
1649 |
1653 # Return Block types checking for recursion |
1650 # Return Block types checking for recursion |
1654 def GetBlockResource(self, debug = False): |
1651 def GetBlockResource(self, debug = False): |
1655 blocktypes = [] |
1652 blocktypes = [] |
1679 datatypes.extend([ |
1676 datatypes.extend([ |
1680 datatype.getname() |
1677 datatype.getname() |
1681 for datatype in project.getdataTypes(name) |
1678 for datatype in project.getdataTypes(name) |
1682 if (not only_locatables or self.IsLocatableDataType(datatype, debug)) |
1679 if (not only_locatables or self.IsLocatableDataType(datatype, debug)) |
1683 and (name is None or |
1680 and (name is None or |
1684 self.GetInstanceList(datatype, name, debug) is None)]) |
1681 len(self.GetInstanceList(datatype, name, debug)) > 0)]) |
1685 if confnodetypes: |
1682 if confnodetypes: |
1686 for category in self.GetConfNodeDataTypes(name, only_locatables): |
1683 for category in self.GetConfNodeDataTypes(name, only_locatables): |
1687 datatypes.extend(category["list"]) |
1684 datatypes.extend(category["list"]) |
1688 return datatypes |
1685 return datatypes |
1689 |
1686 |