SPipeItem.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2021. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SGraphItem, SAnchorItem } from "@persagy-web/graph/lib/";
  27. import { SMouseEvent } from "@persagy-web/base/lib";
  28. import { SPoint, SColor } from "@persagy-web/draw";
  29. import { SLineStyle } from "@persagy-web/graph/";
  30. import { SPolylineItem } from "../shape/SPolylineItem";
  31. import { SRelation } from "../../enums/SRelation";
  32. /**
  33. * 基础管道
  34. *
  35. * @author 韩耀龙 <han_yao_long@163.com>
  36. */
  37. export class SPipeItem extends SPolylineItem {
  38. //属性
  39. /** 关系型数据 */
  40. _relationData: SRelation | null = null;
  41. set relationData(val) {
  42. this._relationData = val;
  43. this.initData();
  44. } // set legendData()
  45. get relationData(): SRelation | null {
  46. return this._relationData;
  47. } // get legendData()
  48. /** 起始锚点 */
  49. startAnchor: SAnchorItem | null = null;
  50. /** 结束锚点 */
  51. endAnchor: SAnchorItem | null = null;
  52. /** 关联锚点1ID */
  53. _anchor1Id: string = "";
  54. get anchor1Id(): string {
  55. return this._anchor1Id;
  56. } // get anchor1Id()
  57. set anchor1Id(v: string) {
  58. this._anchor1Id = v;
  59. if (this.relationData) {
  60. this.relationData.anchor1Id = this._anchor1Id;
  61. }
  62. } // set anchor1Id()
  63. /** 关联锚点2ID */
  64. _anchor2Id: string = "";
  65. get anchor2Id(): string {
  66. return this._anchor2Id;
  67. } // get anchor2Id()
  68. set anchor2Id(v: string) {
  69. this._anchor2Id = v;
  70. if (this.relationData) {
  71. this.relationData.anchor2Id = this._anchor2Id;
  72. }
  73. } // set anchor2Id()
  74. /** 关联节点1ID */
  75. _node1Id: string = "";
  76. get node1Id(): string {
  77. return this._node1Id;
  78. } // get node1Id()
  79. set node1Id(v: string) {
  80. this._node1Id = v;
  81. if (this.relationData) {
  82. this.relationData.node1Id = this._node1Id;
  83. }
  84. } // set node1Id()
  85. /** 关联节点2ID */
  86. _node2Id: string = "";
  87. get node2Id(): string {
  88. return this._node2Id;
  89. } // get node2Id()
  90. set node2Id(v: string) {
  91. this._node2Id = v;
  92. if (this.relationData) {
  93. this.relationData.node2Id = this._node2Id;
  94. }
  95. } // set node2Id()
  96. /**
  97. * 构造函数
  98. *
  99. * @param parent 指向父对象
  100. * @param data 数据
  101. */
  102. constructor(parent: SGraphItem | null, data: SRelation) {
  103. super(parent, []);
  104. this.relationData = data;
  105. }
  106. /**
  107. * 设置relationData 时 对 item 做设置
  108. */
  109. initData(): void {
  110. const data = this.relationData;
  111. if (!data) return;
  112. // 名称
  113. this.name = data.name;
  114. // 线样式
  115. // @ts-ignore
  116. this.lineStyle = SLineStyle[data.lineType]
  117. ? SLineStyle[data.lineType]
  118. : SLineStyle.Solid;
  119. // 折线点
  120. if (data.pointList) {
  121. let setPointList: SPoint[];
  122. setPointList = data.pointList.map(i => {
  123. return new SPoint(i.x, i.y);
  124. });
  125. this.pointList = setPointList;
  126. }
  127. //锚点
  128. if (data.node1Id) {
  129. this._node1Id = data.node1Id;
  130. }
  131. if (data.node2Id) {
  132. this._node2Id = data.node2Id;
  133. }
  134. if (data.anchor1Id) {
  135. this._anchor1Id = data.anchor1Id;
  136. }
  137. if (data.anchor2Id) {
  138. this._anchor2Id = data.anchor2Id;
  139. }
  140. // 样式
  141. if (data.style && data.style.default) {
  142. // 颜色
  143. if (data.style.default.strokeColor) {
  144. this.strokeColor = new SColor(data.style.default.strokeColor);
  145. }
  146. // 线宽
  147. if (data.style.default.lineWidth) {
  148. this.lineWidth = data.style.default.lineWidth;
  149. }
  150. }
  151. }
  152. /**
  153. * 鼠标按下事件
  154. *
  155. * @param event 保存事件参数
  156. * @return 是否处理该事件
  157. */
  158. onMouseDown(event: SMouseEvent): boolean {
  159. super.onMouseDown(event);
  160. return true;
  161. }
  162. /**
  163. * 接收事件作出修改
  164. */
  165. changePos() {
  166. if (this.startAnchor) {
  167. // 判断删除equip后,不移动
  168. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  169. let p = this.startAnchor.mapToScene(0, 0);
  170. this.pointList[0] = new SPoint(p.x - this.x, p.y - this.y);
  171. }
  172. }
  173. if (this.endAnchor) {
  174. // 删除equip后
  175. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  176. let p = this.endAnchor.mapToScene(0, 0);
  177. this.pointList[this.pointList.length - 1] = new SPoint(
  178. p.x - this.x,
  179. p.y - this.y
  180. );
  181. }
  182. }
  183. }
  184. /**
  185. * 返回对象储存的相关数据
  186. *
  187. * @return 相关数据
  188. */
  189. toData(): any {
  190. this.moveToOrigin(this.x, this.y);
  191. const data = this.relationData;
  192. if (!data) return;
  193. // 折线点集存在
  194. if (this.pointList.length) {
  195. const Line = this.pointList.map(pos => {
  196. return {
  197. x: pos.x,
  198. y: pos.y
  199. };
  200. });
  201. data.pointList = Line;
  202. }
  203. data.style.default.strokeColor = this.strokeColor.value;
  204. data.style.default.lineWidth = this.lineWidth;
  205. return data;
  206. }
  207. }