1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { UANodeSet } from "./UANodeSet";
- import { UABaseNode } from "./UABaseNode";
- import { NamespaceTable } from "./NameSpaceTable";
- import JSZip from "jszip";
- export class AddressSpace{
- nodeMap: Map<string, UABaseNode>;
- nst: NamespaceTable;
- nodesets: UANodeSet[];
- constructor(nodesets: UANodeSet[]) {
- this.nst=new NamespaceTable();
- this.nodeMap=new Map();
- this.nodesets=[];
- for(const nodeset of nodesets) {
- this.addNodeset(nodeset);
- }
- }
- public findNode(nodeId: string):UABaseNode|undefined {
- return this.nodeMap.get(nodeId)
- }
- 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().toString());
- }
- zip.file("project.json", JSON.stringify(fileNames));
- return zip.generateAsync({type:'blob'});
- }
- }
|