Browse Source

set new parent from parent dialog

Martin Kunz 1 year ago
parent
commit
de2c4b9fcd
2 changed files with 23 additions and 10 deletions
  1. 3 5
      src/components/TheParent.vue
  2. 20 5
      src/ua/UABaseNode.ts

+ 3 - 5
src/components/TheParent.vue

@@ -17,7 +17,6 @@ const selectedParent = ref(UABaseNode.nullBaseNode);
 function clickNode(clickedNode: UABaseNode) {
   selectedParent.value=clickedNode;
   parentDialogOpen.value=false;
- //clickedNode.setParent()
 }
 
 watch(node, async (newNode, _oldNode) => {
@@ -25,7 +24,7 @@ watch(node, async (newNode, _oldNode) => {
 })
 
 function okPressed() {
-  console.log('TODO: Handle OK Button');
+  node.value?.setParent(selectedParent.value, selectedRefType.value);
 }
 defineExpose({ okPressed })
 
@@ -39,8 +38,7 @@ function filter(fnode: UABaseNode) {
 
 function getRefTypes():UABaseNode[] {
   let list=(store.addressSpace?.getSubTreeAsList("ns=0;i="+ReferenceTypeIds.HierarchicalReferences)) as UAReferenceType[];
-  list=list.filter((node) => node.isAbstract==false);
-  return list;
+  return list.filter((node) => node.isAbstract==false);
 }
 </script>
 
@@ -54,7 +52,7 @@ function getRefTypes():UABaseNode[] {
             <span class="input-group-text" id="inputGroup-sizing-default">Name</span>
           </div>
           <input readonly type="text" class="form-control" aria-label="Default"
-            aria-describedby="inputGroup-sizing-default" :value="node?.getParent()?.displayName">
+            aria-describedby="inputGroup-sizing-default" :value="selectedParent.displayName">
             <button class="btn btn-light" @click="parentDialogOpen = true">...</button>
 
         </div>

+ 20 - 5
src/ua/UABaseNode.ts

@@ -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{