From f1f35981ea70abfdf79066a2be83559543a1563d Mon Sep 17 00:00:00 2001 From: Stefan Profanter Date: Fri, 10 Apr 2020 16:27:08 +0200 Subject: [PATCH] fix(nodeset-compiler): Use ParentNodeId attribute for parent node where possible --- tools/nodeset_compiler/nodes.py | 5 +++++ tools/nodeset_compiler/nodeset.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/tools/nodeset_compiler/nodes.py b/tools/nodeset_compiler/nodes.py index 33d126eb2..16cf059f0 100644 --- a/tools/nodeset_compiler/nodes.py +++ b/tools/nodeset_compiler/nodes.py @@ -74,6 +74,7 @@ class Node(object): self.modelUri = None self.parent = None self.parentReference = None + self.parentIdAttribute = None def __str__(self): return self.__class__.__name__ + "(" + str(self.id) + ")" @@ -104,6 +105,8 @@ class Node(object): self.eventNotifier = int(av) elif at == "SymbolicName": self.symbolicName = String(av) + elif at == "ParentNodeId": + self.parentIdAttribute = NodeId(av) for x in xmlelement.childNodes: if x.nodeType != x.ELEMENT_NODE: @@ -177,6 +180,8 @@ class Node(object): self.browseName.ns = nsMapping[self.browseName.ns] if hasattr(self, 'dataType') and isinstance(self.dataType, NodeId): self.dataType.ns = nsMapping[self.dataType.ns] + if self.parentIdAttribute is not None: + self.parentIdAttribute.ns = nsMapping[self.parentIdAttribute.ns] new_refs = set() for ref in self.references: ref.source.ns = nsMapping[ref.source.ns] diff --git a/tools/nodeset_compiler/nodeset.py b/tools/nodeset_compiler/nodeset.py index cbc0a8dc7..385d25cbc 100644 --- a/tools/nodeset_compiler/nodeset.py +++ b/tools/nodeset_compiler/nodeset.py @@ -388,6 +388,17 @@ class NodeSet(object): # ModellingRule, Root node do not have a parent continue + # Check if the Nodeset explicitly defines a parent node + if node.parentIdAttribute is not None: + for ref in node.references: + if ref.target == node.parentIdAttribute: + node.parent = self.nodes[node.parentIdAttribute] + node.parentReference = self.nodes[ref.referenceType] + break + if node.parent is not None: + # if found, then stop here. Otherwise try to automatically determine parent based on refs + continue + parentref = node.getParentReference(parentreftypes) if parentref is not None: node.parent = self.nodes[parentref.target]