TipelineItem.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { SPolylineItem, ItemOrder, SItemStatus } 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. _maskFlag: boolean = false;
  73. get maskFlag(): boolean {
  74. return this._maskFlag;
  75. }
  76. set maskFlag(v: boolean) {
  77. if (v === this._maskFlag) {
  78. return
  79. }
  80. this._maskFlag = v;
  81. this.update()
  82. }
  83. /** 数据存储 */
  84. data: Relation | null = null;
  85. /** 接收事件作出修改 */
  86. changePos() {
  87. if (this.startAnchor) {
  88. // 判断删除equip后,不移动
  89. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  90. this.pointList[0] = this.startAnchor.mapToScene(0, 0);
  91. }
  92. }
  93. if (this.endAnchor) {
  94. // 删除equip后
  95. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  96. this.pointList[
  97. this.pointList.length - 1
  98. ] = this.endAnchor.mapToScene(0, 0);
  99. }
  100. }
  101. }
  102. constructor(parent: SGraphItem | null, data: Relation) {
  103. super(parent, []);
  104. this.zOrder = ItemOrder.polylineOrder;
  105. this.pointList = data.PointList.map(item => {
  106. return new SPoint(item.X, item.Y);
  107. });
  108. this.data = data;
  109. this.name = data.Name;
  110. this.id = data.ID;
  111. if (data.GraphElementId) {
  112. this._graphElementId = data.GraphElementId
  113. }
  114. if (data.Node1ID) {
  115. this._node1Id = data.Node1ID
  116. }
  117. if (data.Node2ID) {
  118. this._node2Id = data.Node2ID
  119. }
  120. if (data.Anchor1ID) {
  121. this._anchor1ID = data.Anchor1ID
  122. }
  123. if (data.Anchor2ID) {
  124. this._anchor2ID = data.Anchor2ID
  125. }
  126. if (data.Properties && data.Properties.Color) {
  127. this.strokeColor = new SColor(data.Properties.Color);
  128. }
  129. // if(data.Properties && data.Properties.LineDash){
  130. // this.LineDash = data.Properties.LineDash
  131. // }
  132. if (data.Properties && data.Properties.LineWidth) {
  133. this.lineWidth = data.Properties.LineWidth;
  134. }
  135. }
  136. /** 获取data数据 */
  137. toData(): Relation | null {
  138. let pointList: Point[] = this.pointList.map(item => {
  139. return {
  140. X: item.x,
  141. Y: item.y
  142. }
  143. });
  144. if (this.data) {
  145. this.data.PointList = pointList;
  146. this.data.Properties.LineWidth = this.lineWidth;
  147. // this.data.Properties.LineDash = this.LineDash;
  148. this.data.Properties.Color = this.strokeColor.value;
  149. }
  150. return this.data
  151. }
  152. onDraw(painter: SPainter) {
  153. if (this.maskFlag && this.status == SItemStatus.Normal) {
  154. let color = new SColor(this.strokeColor)
  155. color.alpha = 100;
  156. painter.pen.color = color;
  157. painter.drawPolyline(this.pointList);
  158. } else {
  159. super.onDraw(painter);
  160. }
  161. }
  162. }