123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { UANodeSet } from "./UANodeSet";
- 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";
- import {sconfig} from "@/util/ServerConfig"
- export class AddressSpace{
- nodeMap: Map<string, UABaseNode>;
- nst: NamespaceTable;
- nodesets: UANodeSet[];
- mapping: Map<string, IMappingValue>;
- constructor(nodesets: UANodeSet[]) {
- this.nst=new NamespaceTable();
- this.nodeMap=new Map();
- this.nodesets=[];
- this.mapping=new Map();
- for(const nodeset of nodesets) {
- this.addNodeset(nodeset);
- }
- }
- public findNode(nodeId: string):UABaseNode|undefined {
- 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) {
- this.nodeMap.set(node.nodeId.toString(), node);
- }
- nodeset.resolveReferences(this.nodeMap);
- this.nodesets.push(nodeset);
- }
- static async load(files: string[]) {
- const promises:Promise<UANodeSet>[] = []
- for(const file of files) {
- promises.push(UANodeSet.load(file));
- }
- const sets:UANodeSet[]= [];
- for(const p of promises) {
- sets.push(await p)
- }
- return new AddressSpace(sets);
- }
- public exportProject() {
- const zip = new JSZip();
- const fileNames:string[]=[];
- for(const ns of this.nodesets) {
- fileNames.push(ns.fileName);
- zip.file(ns.fileName, ns.toXML(ns.nameSpaceTable, this.nst).toString());
- }
- sconfig.nodesets = fileNames;
- zip.file("project.json", JSON.stringify(sconfig));
- const mapString=YAML.stringify(this.mapping.values());
- zip.file("mapping.yaml", mapString)
- return zip.generateAsync({type:'blob'});
- }
- }
- export interface IMappingValue {
- path: string;
- read: string;
- write: string;
- }
|