|
@@ -5,13 +5,14 @@ import { assert } from "@/util/assert";
|
|
|
import { XMLElem, type IToXML } from "@/util/XmlElem";
|
|
|
|
|
|
export class UABaseNode implements IToXML{
|
|
|
- children: UABaseNode[]=[];
|
|
|
constructor(public nodeId: NodeId,
|
|
|
public browseName: string,
|
|
|
public displayName: string,
|
|
|
public references: UAReference[]) {
|
|
|
}
|
|
|
|
|
|
+ public static nullBaseNode=new UABaseNode(NodeId.nullNodeId,"","",[]);
|
|
|
+
|
|
|
reIndex(nst: NamespaceTable, onst: NamespaceTable) {
|
|
|
const nsName=onst.getUri(this.nodeId.namespace);
|
|
|
assert(nsName!=undefined)
|
|
@@ -24,13 +25,9 @@ export class UABaseNode implements IToXML{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- resolveChildren(nm: Map<string, UABaseNode>) {
|
|
|
+ getChildren(): UABaseNode[] {
|
|
|
+ const children: UABaseNode[]=[];
|
|
|
for(const ref of this.references) {
|
|
|
- const node=nm.get(ref.ref.toString())
|
|
|
- if(node==undefined) {
|
|
|
- //TODO: parse all types/nodes
|
|
|
- continue;
|
|
|
- }
|
|
|
switch(ref.referenceType) {
|
|
|
case 'HasComponent':
|
|
|
case 'HasOrderedComponent':
|
|
@@ -38,25 +35,43 @@ export class UABaseNode implements IToXML{
|
|
|
case 'HasProperty':
|
|
|
case 'HasSubtype':
|
|
|
case 'HasAddIn':
|
|
|
- if(ref.isForward) {
|
|
|
- if(!this.children.includes(node))
|
|
|
- this.children.push(node);
|
|
|
- } else {
|
|
|
- if(!node.children.includes(this))
|
|
|
- node.children.push(this);
|
|
|
+ if(ref.isForward&&ref.fromNode===this) {
|
|
|
+ if(!children.includes(ref.toNode))
|
|
|
+ children.push(ref.toNode);
|
|
|
+ }
|
|
|
+ if(!ref.isForward&&ref.toNode===this) {
|
|
|
+ if(!children.includes(ref.fromNode))
|
|
|
+ children.push(ref.fromNode);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ return children;
|
|
|
+ }
|
|
|
+
|
|
|
+ resolveReferences(nm: Map<string, UABaseNode>) {
|
|
|
+ for(const ref of this.references) {
|
|
|
+ const fromNode=nm.get(ref.fromRef.toString())
|
|
|
+ if(fromNode)
|
|
|
+ ref.fromNode=fromNode;
|
|
|
+ const toNode=nm.get(ref.toRef.toString())
|
|
|
+ if(toNode) //TODO: if we cant find the node; the parser is incomplete or the nodeset is broken
|
|
|
+ ref.toNode=toNode;
|
|
|
+ if(ref.fromNode===this&&toNode){ //add this reference to referenced node
|
|
|
+ if(!ref.toNode.references.includes(ref))
|
|
|
+ ref.toNode.references.push(ref);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- static fromXML(xmlObject: any): UABaseNode{
|
|
|
+ static fromXML(xmlObject: any): UABaseNode{
|
|
|
const xmlReferences=xmlObject['References'];
|
|
|
const references:UAReference[]=[];
|
|
|
+ const nodeId=coerceNodeId(xmlObject['@_NodeId']);
|
|
|
for(const xmlref of xmlReferences.Reference) {
|
|
|
- references.push(UAReference.fromXML(xmlref));
|
|
|
+ references.push(UAReference.fromXML(xmlref, nodeId));
|
|
|
}
|
|
|
- const ua=new UABaseNode(coerceNodeId(xmlObject['@_NodeId']), xmlObject['@_BrowseName'], xmlObject['DisplayName'], references);
|
|
|
+ const ua=new UABaseNode(nodeId, xmlObject['@_BrowseName'], xmlObject['DisplayName'], references);
|
|
|
return ua;
|
|
|
}
|
|
|
|