UAObjectType.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { XMLElem } from "@/util/XmlElem";
  2. import type { NamespaceTable } from "./NameSpaceTable";
  3. import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
  4. import type { UAObject } from "./UAObject";
  5. import type { UAVariable } from "./UAVariable";
  6. export class UAObjectType extends UABaseNode{
  7. public isAbstract: boolean;
  8. constructor(options: UAObjectTypeOptions) {
  9. super(options)
  10. this.isAbstract=options.isAbstract||false;
  11. }
  12. static fromXML(xmlObjType: any): UAObjectType{
  13. const bn=super.fromXML(xmlObjType)
  14. return new UAObjectType({nodeId: bn.nodeId,
  15. browseName: bn.browseName,
  16. displayName: bn.displayName,
  17. references: bn.references,
  18. isAbstract: xmlObjType['@_IsAbstract']==='true'});
  19. }
  20. toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
  21. const nid=UABaseNode.localNodeId(this.nodeId, lnst, gnst);
  22. const elem =new XMLElem('UAObjectType');
  23. elem.attr('NodeId', nid.toString())
  24. .attr('BrowseName', this.browseName)
  25. .attr('IsAbstract', this.isAbstract)
  26. .elem('DisplayName', this.displayName);
  27. const refs=elem.add(new XMLElem('References'))
  28. for(const ref of this.references) {
  29. if(ref.fromNode.nodeId.toString()==this.nodeId.toString()) //on load resolveReferences() duplicates references to both sides. skip them for export
  30. refs.add(ref.toXML(lnst, gnst));
  31. }
  32. return elem;
  33. }
  34. getModellingRule(){
  35. let res:any = "";
  36. this.references.forEach((ref)=>{
  37. if(ref.referenceType == "HasModellingRule"){
  38. res = ref.toNode.displayName;
  39. }
  40. })
  41. return res;
  42. }
  43. }
  44. export interface UAObjectTypeOptions extends UABaseNodeOptions{
  45. isAbstract?: boolean
  46. }