Przeglądaj źródła

parent dialog: recursive reference select

parse/write isAbstract for uareferencetype
Martin Kunz 1 rok temu
rodzic
commit
6718ede26b
3 zmienionych plików z 39 dodań i 7 usunięć
  1. 12 3
      src/components/TheParent.vue
  2. 19 0
      src/ua/AddressSpace.ts
  3. 8 4
      src/ua/UAReferenceType.ts

+ 12 - 3
src/components/TheParent.vue

@@ -4,6 +4,7 @@ import { computed, ref } from 'vue';
 import TheTreeDialog from './TheTreeDialog.vue';
 import type { UABaseNode } from '@/ua/UABaseNode';
 import { ReferenceTypeIds } from '@/ua/opcua_node_ids';
+import type { UAReferenceType } from '@/ua/UAReferenceType';
 const store = useStore()
 
 const parentDialogOpen = ref(false);
@@ -14,7 +15,7 @@ const node = computed(() => {
 
 function clickNode(clickedNode: UABaseNode) {
   //TODO: replace parent references
-  node.value?.setParent(clickedNode, store.addressSpace?.findNode("ns=0;i="+ ReferenceTypeIds.HierarchicalReferences));
+  // node.value?.setParent(clickedNode, store.addressSpace?.findNode("ns=0;i="+ ReferenceTypeIds.HierarchicalReferences));
   parentDialogOpen.value=false;
 }
 
@@ -26,6 +27,13 @@ function filter(fnode: UABaseNode) {
   return false;
 }
 
+function getRefTypes():UABaseNode[] {
+  let list=(store.addressSpace?.getSubTreeAsList("ns=0;i="+ReferenceTypeIds.HierarchicalReferences)||[]) as UAReferenceType[];
+  list=list.filter((node) => node.isAbstract==false)
+  return list;
+}
+
+
 </script>
 
 <template>
@@ -47,8 +55,9 @@ function filter(fnode: UABaseNode) {
             <span class="input-group-text" id="inputGroup-sizing-default">Reference</span>
           </div>
           <select class="form-select" aria-label="Default select example">
-            <option selected v-text="node?.getParentRef()?.referenceType"></option>
-            <option value="1">...</option>
+            <option v-for="option in getRefTypes()" :value="option.nodeId.toString()" v-bind:key="option.nodeId.toString()">
+              {{ option.displayName }}
+            </option>
           </select>
         </div>
       </div>

+ 19 - 0
src/ua/AddressSpace.ts

@@ -3,6 +3,8 @@ import { UABaseNode } from "./UABaseNode";
 import { NamespaceTable } from "./NameSpaceTable";
 import YAML from 'yaml'
 import JSZip from "jszip";
+import { ReferenceTypeIds } from "./opcua_node_ids";
+import type { NodeId } from "./NodeId";
 
 export class AddressSpace{
 
@@ -26,6 +28,23 @@ export class AddressSpace{
         return this.nodeMap.get(nodeId)
     }
 
+    public getHierarchicalReferenceTypes() {
+
+    }
+
+    public getSubTreeAsList(nodeId: string): UABaseNode[] {
+        const node=this.findNode(nodeId);
+        if(!node)
+            throw new Error(`Nodeid ${nodeId} not found`)
+        const nlist:UABaseNode[]=[node];
+        for(const n of node.getChildren()) {
+            const list=this.getSubTreeAsList(n.nodeId.toString());
+            nlist.push(...list);
+        }
+        return nlist;
+    }
+
+    
     public  addNodeset(nodeset: UANodeSet) {
         nodeset.reIndex(this.nst);
         for(const node of nodeset.nodes) {

+ 8 - 4
src/ua/UAReferenceType.ts

@@ -3,17 +3,20 @@ import type { NamespaceTable } from "./NameSpaceTable";
 import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
 
 export class UAReferenceType extends UABaseNode{
+    public isAbstract: boolean;
 
     constructor(options: UAReferenceTypeOptions) {
         super(options)
+        this.isAbstract=options.isAbstract||false;
     }
 
-    static  fromXML(uaMethod: any): UAReferenceType{
-        const bn=super.fromXML(uaMethod)
+    static  fromXML(xmlRefType: any): UAReferenceType{
+        const bn=super.fromXML(xmlRefType)
         return new UAReferenceType({nodeId: bn.nodeId, 
                             browseName: bn.browseName, 
                             displayName: bn.displayName,
-                            references: bn.references});
+                            references: bn.references,
+                            isAbstract: xmlRefType['@_IsAbstract']==='true'});
     }
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
@@ -21,6 +24,7 @@ export class UAReferenceType extends UABaseNode{
         const elem =new XMLElem('UAReferenceType');
         elem.attr('NodeId', nid.toString())
             .attr('BrowseName', this.browseName)
+            .attr('IsAbstract', this.isAbstract)
             .elem('DisplayName', this.displayName);
         const refs=elem.add(new XMLElem('References'))
         for(const ref of this.references) {
@@ -32,5 +36,5 @@ export class UAReferenceType extends UABaseNode{
 }
 
 export interface UAReferenceTypeOptions extends UABaseNodeOptions{
-   
+    isAbstract?: boolean
 }