|
@@ -9,6 +9,7 @@ import { UAUserWriteMask } from "./UAUserWriteMask";
|
|
|
import { UAWriteMask } from "./UAWriteMask";
|
|
|
import { UAAccessRestriction } from "./UAAccessRestriction";
|
|
|
import { type IAddressSpace } from "./IAddressSpace";
|
|
|
+import { ReferenceTypeIds } from "./opcua_node_ids";
|
|
|
export class UABaseNode implements IToXML{
|
|
|
|
|
|
public static nullBaseNode=new UABaseNode({browseName: "", addressSpace: {} as IAddressSpace, nodeId: NodeId.nullNodeId});
|
|
@@ -17,7 +18,7 @@ export class UABaseNode implements IToXML{
|
|
|
public nodeId: NodeId;
|
|
|
public nodeClass="UABaseNode";
|
|
|
public browseName: string;
|
|
|
- public addressSpace?: IAddressSpace
|
|
|
+ public addressSpace: IAddressSpace
|
|
|
public displayName?: string; //LocText
|
|
|
public description?: string; //LocText
|
|
|
public symbolicName?: string; //SymbolicName
|
|
@@ -63,11 +64,25 @@ export class UABaseNode implements IToXML{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- setParent(node: UABaseNode, refType: String) {
|
|
|
- for(const ref of this.references) {
|
|
|
- //ref.
|
|
|
+ setParent(newParentNode: UABaseNode, newRefType: string) {
|
|
|
+ const hierReferences=this.addressSpace.getSubTreeAsList("ns=0;i="+ReferenceTypeIds.HierarchicalReferences);
|
|
|
+ let href;
|
|
|
+ for(const r of this.references) { //find current href in references
|
|
|
+ href=hierReferences.find((n) => {n.browseName===r.referenceType})
|
|
|
+ }
|
|
|
+ for(let i=this.references.length;i--;i>=0) { //remove current href from references
|
|
|
+ const r=this.references[i];
|
|
|
+ if(r.referenceType==href?.browseName)
|
|
|
+ this.references.splice(i,1);
|
|
|
}
|
|
|
- //TODO replace parent-like references in both directions.
|
|
|
+ const newRefA=new UAReference(this.nodeId, newRefType, newParentNode.nodeId, true);
|
|
|
+ newRefA.fromNode=this;
|
|
|
+ newRefA.toNode=newParentNode;
|
|
|
+ this.references.push(newRefA);
|
|
|
+ const newRefB=new UAReference(newParentNode.nodeId, newRefType, this.nodeId, false);
|
|
|
+ newRefB.fromNode=this;
|
|
|
+ newRefB.toNode=newParentNode;
|
|
|
+ this.references.push(newRefB);
|
|
|
}
|
|
|
|
|
|
getParentRef(): UAReference|null{
|