TipelineItem.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import { SPolylineItem, ItemOrder, SItemStatus } from '@saga-web/big/lib';
  2. import { SPainter, SColor, SRect } 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. import { uuid } from '@/components/mapClass/until';
  8. import { SMouseEvent } from '@saga-web/base/lib';
  9. /**
  10. * 管道item
  11. *
  12. * */
  13. export class TipelineItem extends SPolylineItem {
  14. /** 起始锚点 */
  15. startAnchor: SAnchorItem | null = null;
  16. /** 结束锚点 */
  17. endAnchor: SAnchorItem | null = null;
  18. /** 对应的图例ID */
  19. _graphElementId: string = "";
  20. get graphElementId(): string {
  21. return this._graphElementId;
  22. }
  23. set graphElementId(v: string) {
  24. this._graphElementId = v;
  25. if (this.data) {
  26. this.data.GraphElementId = this._graphElementId;
  27. }
  28. }
  29. /** 关联节点1ID */
  30. _node1Id: string = "";
  31. get node1Id(): string {
  32. return this._node1Id;
  33. }
  34. set node1Id(v: string) {
  35. this._node1Id = v;
  36. if (this.data) {
  37. this.data.Node1ID = this._node1Id;
  38. }
  39. }
  40. /** 关联节点2ID */
  41. _node2Id: string = "";
  42. get node2Id(): string {
  43. return this._node2Id;
  44. }
  45. set node2Id(v: string) {
  46. this._node2Id = v;
  47. if (this.data) {
  48. this.data.Node2ID = this._node2Id;
  49. }
  50. }
  51. /** 关联锚点1ID */
  52. _anchor1ID: string = "";
  53. get anchor1ID(): string {
  54. return this._anchor1ID;
  55. }
  56. set anchor1ID(v: string) {
  57. this._anchor1ID = v;
  58. if (this.data) {
  59. this.data.Anchor1ID = this._anchor1ID;
  60. }
  61. }
  62. /** 关联锚点2ID */
  63. _anchor2ID: string = "";
  64. get anchor2ID(): string {
  65. return this._anchor2ID;
  66. }
  67. set anchor2ID(v: string) {
  68. this._anchor2ID = v;
  69. if (this.data) {
  70. this.data.Anchor2ID = this._anchor2ID;
  71. }
  72. }
  73. /** 是否蒙版遮罩 */
  74. _maskFlag: boolean = false;
  75. get maskFlag(): boolean {
  76. return this._maskFlag;
  77. }
  78. set maskFlag(v: boolean) {
  79. if (v === this._maskFlag) {
  80. return
  81. }
  82. this._maskFlag = v;
  83. this.update()
  84. }
  85. /** 数据存储 */
  86. data: Relation | null = null;
  87. /** 接收事件作出修改 */
  88. changePos() {
  89. if (this.startAnchor) {
  90. // 判断删除equip后,不移动
  91. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  92. let p = this.startAnchor.mapToScene(0, 0);
  93. this.pointList[0] = new SPoint(p.x - this.x, p.y - this.y)
  94. }
  95. }
  96. if (this.endAnchor) {
  97. // 删除equip后
  98. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  99. let p = this.endAnchor.mapToScene(0, 0);
  100. this.pointList[
  101. this.pointList.length - 1
  102. ] = new SPoint(p.x - this.x, p.y - this.y)
  103. }
  104. }
  105. }
  106. constructor(parent: SGraphItem | null, data: Relation) {
  107. super(parent, []);
  108. this.zOrder = ItemOrder.polylineOrder;
  109. this.pointList = data.PointList.map(item => {
  110. return new SPoint(item.X, item.Y);
  111. });
  112. this.data = data;
  113. this.name = data.Name;
  114. if (!data.ID) {
  115. data.ID = uuid()
  116. }
  117. this.id = data.ID;
  118. if (data.GraphElementId) {
  119. this._graphElementId = data.GraphElementId
  120. }
  121. if (data.Node1ID) {
  122. this._node1Id = data.Node1ID
  123. }
  124. if (data.Node2ID) {
  125. this._node2Id = data.Node2ID
  126. }
  127. if (data.Anchor1ID) {
  128. this._anchor1ID = data.Anchor1ID
  129. }
  130. if (data.Anchor2ID) {
  131. this._anchor2ID = data.Anchor2ID
  132. }
  133. if (data.Properties.Zorder) {
  134. this.zOrder = data.Properties.Zorder;
  135. }
  136. if (data.Properties && data.Properties.Color) {
  137. this.strokeColor = new SColor(data.Properties.Color);
  138. }
  139. // if(data.Properties && data.Properties.LineDash){
  140. // this.LineDash = data.Properties.LineDash
  141. // }
  142. if (data.Properties && data.Properties.LineWidth) {
  143. this.lineWidth = data.Properties.LineWidth;
  144. }
  145. }
  146. /**
  147. * 鼠标按下事件
  148. *
  149. * @param event 保存事件参数
  150. * @return boolean
  151. */
  152. onMouseDown(event: SMouseEvent): boolean {
  153. if (event.buttons == 1)
  154. this.$emit("legendItemClick", event);
  155. super.onMouseDown(event);
  156. return true;
  157. } // Function onMouseDown()
  158. /** 获取data数据 */
  159. toData(): Relation | null {
  160. let pointList: Point[] = this.pointList.map(item => {
  161. return {
  162. X: item.x,
  163. Y: item.y
  164. }
  165. });
  166. if (this.data) {
  167. this.data.Name = this.name;
  168. this.data.PointList = pointList;
  169. this.data.Properties.Zorder = this.zOrder;
  170. this.data.Properties.LineWidth = this.lineWidth;
  171. // this.data.Properties.LineDash = this.LineDash;
  172. this.data.Properties.Color = this.strokeColor.value;
  173. }
  174. return this.data
  175. }
  176. // onDraw(painter: SPainter) {
  177. // if (this.maskFlag && this.status == SItemStatus.Normal) {
  178. // let color = new SColor(this.strokeColor)
  179. // color.alpha = color.alpha / 8
  180. // painter.pen.color = color
  181. // if (this.selected) {
  182. // painter.pen.lineWidth = painter.toPx(this.lineWidth * 2);
  183. // painter.shadow.shadowBlur = 10;
  184. // painter.shadow.shadowColor = new SColor(`#00000033`);
  185. // painter.shadow.shadowOffsetX = 5;
  186. // painter.shadow.shadowOffsetY = 5;
  187. // } else {
  188. // painter.pen.lineWidth = painter.toPx(this.lineWidth);
  189. // painter.shadow.shadowColor = SColor.Transparent
  190. // }
  191. // painter.drawPolyline(this.pointList)
  192. // painter.pen.color = new SColor('#ffffff80')
  193. // painter.drawPolyline(this.pointList)
  194. // } else {
  195. // super.onDraw(painter)
  196. // }
  197. // }
  198. /**
  199. * Item绘制框架
  200. *
  201. * @param painter painter对象
  202. * @param rect 绘制区域
  203. */
  204. onPaint(painter: SPainter, rect: SRect): void {
  205. super.onPaint(painter, rect);
  206. if (this.maskFlag && this.status == SItemStatus.Normal) {
  207. if (this.selected) {
  208. painter.pen.lineWidth = painter.toPx(this.lineWidth * 2);
  209. } else {
  210. painter.pen.lineWidth = painter.toPx(this.lineWidth);
  211. }
  212. painter.pen.color = new SColor('#ffffff80')
  213. painter.drawPolyline(this.pointList)
  214. }
  215. } // Function onPaint()
  216. }