TipelineItem.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { SPolylineItem } from '@saga-web/big/lib';
  2. import { SPainter, SColor } from '@saga-web/draw';
  3. import { SAnchorItem, SGraphItem } from '@saga-web/graph/lib';
  4. import { Relation } from '../types/Relation';
  5. import { SPoint } from "@saga-web/draw/lib";
  6. import {Point} from "@saga-web/big/lib/types/Point";
  7. /**
  8. * 管道item
  9. *
  10. * */
  11. export class TipelineItem extends SPolylineItem {
  12. /** 起始锚点 */
  13. startAnchor: SAnchorItem | null = null;
  14. /** 结束锚点 */
  15. endAnchor: SAnchorItem | null = null;
  16. /** 对应的图例ID */
  17. _graphElementId: string = "";
  18. get graphElementId(): string {
  19. return this._graphElementId;
  20. }
  21. set graphElementId(v: string) {
  22. this._graphElementId = v;
  23. if (this.data) {
  24. this.data.GraphElementId = this._graphElementId;
  25. }
  26. }
  27. /** 关联节点1ID */
  28. _node1Id: string = "";
  29. get node1Id(): string {
  30. return this._node1Id;
  31. }
  32. set node1Id(v: string) {
  33. this._node1Id = v;
  34. if (this.data) {
  35. this.data.Node1ID = this._node1Id;
  36. }
  37. }
  38. /** 关联节点2ID */
  39. _node2Id: string = "";
  40. get node2Id(): string {
  41. return this._node2Id;
  42. }
  43. set node2Id(v: string) {
  44. this._node2Id = v;
  45. if (this.data) {
  46. this.data.Node2ID = this._node2Id;
  47. }
  48. }
  49. /** 关联锚点1ID */
  50. _anchor1ID: string = "";
  51. get anchor1ID(): string {
  52. return this._anchor1ID;
  53. }
  54. set anchor1ID(v: string) {
  55. this._anchor1ID = v;
  56. if (this.data) {
  57. this.data.Anchor1ID = this._anchor1ID;
  58. }
  59. }
  60. /** 关联锚点2ID */
  61. _anchor2ID: string = "";
  62. get anchor2ID(): string {
  63. return this._anchor2ID;
  64. }
  65. set anchor2ID(v: string) {
  66. this._anchor2ID = v;
  67. if (this.data) {
  68. this.data.Anchor2ID = this._anchor2ID;
  69. }
  70. }
  71. /** 数据存储 */
  72. data: Relation | null = null;
  73. /** 接收事件作出修改 */
  74. changePos() {
  75. if (this.startAnchor) {
  76. // 判断删除equip后,不移动
  77. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  78. this.pointList[0] = this.startAnchor.mapToScene(0, 0);
  79. }
  80. }
  81. if (this.endAnchor) {
  82. // 删除equip后
  83. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  84. this.pointList[
  85. this.pointList.length - 1
  86. ] = this.endAnchor.mapToScene(0, 0);
  87. }
  88. }
  89. }
  90. constructor(parent: SGraphItem | null, data: Relation) {
  91. super(parent, []);
  92. this.pointList = data.PointList.map(item => {
  93. return new SPoint(item.X,item.Y);
  94. });
  95. this.data = data;
  96. this.id = data.ID;
  97. if (data.GraphElementId) {
  98. this._graphElementId = data.GraphElementId
  99. }
  100. if (data.Node1ID) {
  101. this._node1Id = data.Node1ID
  102. }
  103. if (data.Node2ID) {
  104. this._node2Id = data.Node2ID
  105. }
  106. if (data.Anchor1ID) {
  107. this._anchor1ID = data.Anchor1ID
  108. }
  109. if (data.Anchor2ID) {
  110. this._anchor2ID = data.Anchor2ID
  111. }
  112. }
  113. /** 获取data数据 */
  114. getData(): Relation | null {
  115. let pointList:Point[] = this.pointList.map(item => {
  116. return {
  117. X: item.x,
  118. Y: item.y
  119. }
  120. });
  121. if (this.data) {
  122. this.data.PointList = pointList;
  123. }
  124. return this.data
  125. }
  126. }