STopologyParser.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { SParser } from "./SParser";
  2. import { ElementData } from "../types/ElementData";
  3. import { Legend } from "../types/topology/Legend";
  4. import { Marker } from "../types/topology/Marker";
  5. import { Relation } from "../types/topology/Relation";
  6. import {
  7. SImageLegendItem,
  8. SLineLegendItem,
  9. SNoneLegendItem,
  10. SRelation,
  11. SZoneLegendItem,
  12. SImageMarkerItem,
  13. SLineMarkerItem,
  14. STextMarkerItem
  15. } from "..";
  16. import { SGraphElementType } from "../enums/SGraphElementType";
  17. import {SMarkerType} from "../enums/SMarkerType";
  18. /**
  19. * 拓扑图信息解析器
  20. *
  21. */
  22. export class STopologyParser extends SParser {
  23. /** 图例list(非图例类型) */
  24. noneLegendList: SNoneLegendItem[] = [];
  25. /** 图例list(线类型) */
  26. lineLegendList: SLineLegendItem[] = [];
  27. /** 图例list(区域类型) */
  28. zoneLegendList: SZoneLegendItem[] = [];
  29. /** 图例list(图标类型) */
  30. imageLegendList: SImageLegendItem[] = [];
  31. /** 标识list(图类型) */
  32. imageMarkerList: SImageMarkerItem[] = [];
  33. /** 标识list(线类型) */
  34. lineMarkerList: SLineMarkerItem[] = [];
  35. /** 标识list(文本类型) */
  36. textMarkerList: STextMarkerItem[] = [];
  37. /** 管线关系对象关系list */
  38. relationList: SRelation[] = [];
  39. /**
  40. * 解析数据
  41. *
  42. * @param data 系统图数据
  43. * */
  44. parseData(data: ElementData): void {
  45. if (data.Nodes) {
  46. data.Nodes.forEach((t: Legend): void => {
  47. this.addLegend(t);
  48. });
  49. }
  50. if (data.Markers) {
  51. data.Markers.forEach((t: Marker): void => {
  52. this.addMarker(t);
  53. });
  54. }
  55. if (data.Relations) {
  56. data.Relations.forEach((t: Relation): void => {
  57. this.addRelation(t);
  58. });
  59. }
  60. } // Function parseData()
  61. /**
  62. * 添加图例节点至场景中
  63. *
  64. * @param t 图例节点数据
  65. * */
  66. private addLegend(t: Legend): void {
  67. if (t.GraphElementType == SGraphElementType.None) {
  68. let item = this.factory.createNoneLegend(t);
  69. this.noneLegendList.push(item);
  70. } else if (t.GraphElementType == SGraphElementType.Line) {
  71. let item = this.factory.createLineLegend(t);
  72. this.lineLegendList.push(item);
  73. } else if (t.GraphElementType == SGraphElementType.Zone) {
  74. let item = this.factory.createZoneLegend(t);
  75. this.zoneLegendList.push(item);
  76. } else if (t.GraphElementType == SGraphElementType.Image) {
  77. let item = this.factory.createImageLegend(t);
  78. this.imageLegendList.push(item);
  79. }
  80. } // Function addNode()
  81. /**
  82. * 添加标识对象至场景中
  83. *
  84. * @param t 标识对象数据
  85. * */
  86. private addMarker(t: Marker): void {
  87. if (t.Type == SMarkerType.Image) {
  88. let item = this.factory.createImageMarker(t);
  89. this.imageMarkerList.push(item);
  90. } else if (t.Type == SMarkerType.Line) {
  91. let item = this.factory.createLineMarker(t);
  92. this.lineMarkerList.push(item);
  93. } else if (t.Type == SMarkerType.Text) {
  94. let item = this.factory.createTextMarker(t);
  95. this.textMarkerList.push(item);
  96. }
  97. } // Function addMarker()
  98. /**
  99. * 添加管线关系至场景中
  100. *
  101. * @param t 管线关系对象数据
  102. * */
  103. private addRelation(t: Relation): void {
  104. let item = this.factory.createRelation(t);
  105. this.relationList.push(item);
  106. } // Function addRelation()
  107. } // class STopologyParser