Martin Kunz пре 1 година
родитељ
комит
89c8614965
5 измењених фајлова са 42 додато и 26 уклоњено
  1. 17 0
      src/components/TheModels.vue
  2. 5 5
      src/ua/UABaseNode.ts
  3. 4 1
      src/ua/UANodeSet.ts
  4. 14 1
      src/ua/UAObject.ts
  5. 2 19
      src/ua/UAReference.ts

+ 17 - 0
src/components/TheModels.vue

@@ -1,6 +1,22 @@
 <script setup lang="ts">
 <script setup lang="ts">
 import {useStore} from '@/util/store'
 import {useStore} from '@/util/store'
 const store = useStore()
 const store = useStore()
+
+async function exportProject() {
+  const blob=await store.addressSpace?.export();
+  if(blob)
+    downloadBlob(blob, "proj.zip");
+}
+
+function downloadBlob(blob: Blob, filename: string) {
+  let link = document.createElement('a')
+  link.href = window.URL.createObjectURL(blob)
+  link.download = filename
+  document.body.appendChild(link);
+  link.click()
+  document.body.removeChild(link);
+}
+
 </script>
 </script>
 
 
 <template>
 <template>
@@ -17,6 +33,7 @@ const store = useStore()
       </p>
       </p>
     </div>
     </div>
   </div>
   </div>
+  <a   @click.prevent="exportProject()" >export</a>
 </div>
 </div>
 </template>
 </template>
 
 

+ 5 - 5
src/ua/UABaseNode.ts

@@ -1,6 +1,6 @@
 import type { NamespaceTable } from "./NameSpaceTable";
 import type { NamespaceTable } from "./NameSpaceTable";
 import { NodeId } from "./NodeId";
 import { NodeId } from "./NodeId";
-import { ReferencyType, UAReference } from "./UAReference";
+import { UAReference } from "./UAReference";
 import { assert } from "@/util/assert";
 import { assert } from "@/util/assert";
 import { XMLElem, type IToXML } from "@/util/XmlElem";
 import { XMLElem, type IToXML } from "@/util/XmlElem";
 
 
@@ -32,10 +32,10 @@ export class UABaseNode implements IToXML{
                 continue;
                 continue;
             }
             }
             switch(ref.referenceType) {
             switch(ref.referenceType) {
-                case ReferencyType.HasComponent:
-                case ReferencyType.Organizes:
-                case ReferencyType.HasProperty:
-                case ReferencyType.HasSubtype:
+                case 'HasComponent':
+                case 'Organizes':
+                case 'HasProperty':
+                case 'HasSubtype':
                     if(ref.isForward) {
                     if(ref.isForward) {
                         if(!this.children.includes(node))
                         if(!this.children.includes(node))
                             this.children.push(node);
                             this.children.push(node);

+ 4 - 1
src/ua/UANodeSet.ts

@@ -36,6 +36,9 @@ export class UANodeSet implements IToXML{
         for(const model of this.models) {
         for(const model of this.models) {
             xmlModels.add(model.toXML())
             xmlModels.add(model.toXML())
         }
         }
+        for(const node of this.nodes) {
+            xmlModels.add(node.toXML())
+        }
         return elem;
         return elem;
     }
     }
 
 
@@ -63,7 +66,7 @@ export class UANodeSet implements IToXML{
             }
             }
         }
         }
         const parser = new XMLParser(parseOptions);
         const parser = new XMLParser(parseOptions);
-        const xml= await (await fetch(url)).text()
+        const xml= await (await fetch(url)).text();
         const xmlObj = parser.parse(xml);
         const xmlObj = parser.parse(xml);
         const models: Model[]=[];
         const models: Model[]=[];
         const xmlModels=xmlObj['UANodeSet']['Models'];
         const xmlModels=xmlObj['UANodeSet']['Models'];

+ 14 - 1
src/ua/UAObject.ts

@@ -1,3 +1,4 @@
+import { XMLElem } from "@/util/XmlElem";
 import type { NodeId } from "./NodeId";
 import type { NodeId } from "./NodeId";
 import { UABaseNode } from "./UABaseNode";
 import { UABaseNode } from "./UABaseNode";
 import { UAReference } from "./UAReference";
 import { UAReference } from "./UAReference";
@@ -14,5 +15,17 @@ export class UAObject extends UABaseNode {
         const bn=super.fromXML(uaObject)
         const bn=super.fromXML(uaObject)
         return new UAObject(bn.nodeId, bn.browseName, bn.displayName, bn.references);
         return new UAObject(bn.nodeId, bn.browseName, bn.displayName, bn.references);
     }
     }
-    
+
+
+    toXML(): XMLElem {
+        const elem =new XMLElem('UAVariable');
+        elem.attr('NodeID', this.nodeId.toString())
+            .attr('BrowseName', this.browseName)
+            .attr('DisplayName', this.displayName);
+        const refs=elem.add(new XMLElem('References'))
+        for(const ref of this.references) {
+            refs.add(ref.toXML());
+        }
+        return elem;
+    }
 }
 }

+ 2 - 19
src/ua/UAReference.ts

@@ -4,7 +4,7 @@ import { NodeId } from "./NodeId";
 import { assert } from "@/util/assert";
 import { assert } from "@/util/assert";
 
 
 export class UAReference implements IToXML{
 export class UAReference implements IToXML{
-    constructor(public referenceType: ReferencyType,
+    constructor(public referenceType: string,
                 public ref: NodeId,
                 public ref: NodeId,
                 public isForward: boolean) {
                 public isForward: boolean) {
     }
     }
@@ -26,25 +26,8 @@ export class UAReference implements IToXML{
     }
     }
 
 
     static fromXML(uaReference: any): UAReference {
     static fromXML(uaReference: any): UAReference {
-        return new UAReference(ReferencyType[uaReference['@_ReferenceType'] as keyof typeof ReferencyType], 
+        return new UAReference(uaReference['@_ReferenceType'], 
                                 NodeId.coerceNodeId(uaReference['#text']), 
                                 NodeId.coerceNodeId(uaReference['#text']), 
                                 uaReference['@_IsForward']!="false");
                                 uaReference['@_IsForward']!="false");
     }
     }
 }
 }
-
-
-export enum ReferencyType {
-    HasComponent  = 1,
-    HasProperty =2,
-    Organizes =3,
-    HasOrderedComponent =4,
-    HasModellingRule =5,
-    HasTypeDefinition =6,
-    HasEncoding =7,
-    HasDescription =8,
-    GeneratesEvent =9,
-    AlwaysGeneratesEvent=10,
-    HasNotifier=11,
-    HasSubtype=12
-
-}