SpaceItem.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphyItem } from "@saga-web/graphy/lib";
  21. import {
  22. SColor,
  23. SGradient,
  24. SPainter,
  25. SPath2D,
  26. SPoint,
  27. SPolygonUtil,
  28. SRect
  29. } from "@saga-web/draw/lib";
  30. import { Space } from "../types/Space";
  31. import { Opt } from "../types/Opt";
  32. import { SMouseEvent } from "@saga-web/base/lib";
  33. import { ItemOrder } from "../types/ItemOrder";
  34. /**
  35. * 模型空间item
  36. *
  37. * @author 郝建龙
  38. */
  39. export class SpaceItem extends SGraphyItem {
  40. /** 空间所有数据 */
  41. data: Space;
  42. /** 空间轮廓线坐标list */
  43. readonly pointArr: SPoint[][] = [];
  44. /** X坐标最小值 */
  45. minX = Number.MAX_SAFE_INTEGER;
  46. /** X坐标最大值 */
  47. maxX = Number.MIN_SAFE_INTEGER;
  48. /** Y坐标最小值 */
  49. minY = Number.MAX_SAFE_INTEGER;
  50. /** Y坐标最大值 */
  51. maxY = Number.MIN_SAFE_INTEGER;
  52. /** path对象 */
  53. private path = new SPath2D();
  54. /** 高亮状态 */
  55. private _highLightFlag: boolean = false;
  56. get highLightFlag(): boolean {
  57. return this._highLightFlag;
  58. } // Get highLightFlag
  59. set highLightFlag(value: boolean) {
  60. this._highLightFlag = value;
  61. this.update();
  62. } // Set highLightFlag
  63. /**
  64. * 构造函数
  65. *
  66. * @param parent 指向父对象
  67. * @param data 空间数据
  68. */
  69. constructor(parent: SGraphyItem | null, data: Space) {
  70. super(parent);
  71. this.data = data;
  72. this.zOrder = ItemOrder.spaceOrder;
  73. let tempArr = this.data.OutLine;
  74. if (tempArr && tempArr.length) {
  75. this.minX = tempArr[0][0].X;
  76. this.maxX = this.minX;
  77. this.minY = -tempArr[0][0].Y;
  78. this.maxY = this.minY;
  79. this.pointArr = tempArr.map((t): SPoint[] => {
  80. let temp = t.map(
  81. (it): SPoint => {
  82. let x = it.X,
  83. y = -it.Y;
  84. if (x < this.minX) {
  85. this.minX = x;
  86. }
  87. if (y < this.minY) {
  88. this.minY = y;
  89. }
  90. if (x > this.maxX) {
  91. this.maxX = x;
  92. }
  93. if (y > this.maxY) {
  94. this.maxY = y;
  95. }
  96. return new SPoint(x, y);
  97. }
  98. );
  99. this.path.polygon(temp);
  100. return temp;
  101. });
  102. }
  103. } // Constructor
  104. /**
  105. * Item对象边界区域
  106. *
  107. * @return SRect
  108. */
  109. boundingRect(): SRect {
  110. return new SRect(
  111. this.minX,
  112. this.minY,
  113. this.maxX - this.minX,
  114. this.maxY - this.minY
  115. );
  116. } // Function boundingRect()
  117. /**
  118. * 鼠标单击事件
  119. *
  120. * @param event 事件参数
  121. * @return boolean
  122. */
  123. onClick(event: SMouseEvent): boolean {
  124. if (this.selectable) {
  125. this.selected = !this.selected;
  126. }
  127. this.$emit("click", event);
  128. return true;
  129. } // Function onClick()
  130. /**
  131. * 鼠标移动事件
  132. *
  133. * @param event 事件参数
  134. */
  135. onMouseMove(event: SMouseEvent): boolean {
  136. return false;
  137. } // Function onMouseMove()
  138. /**
  139. * 判断点是否在区域内
  140. *
  141. * @param x
  142. * @param y
  143. */
  144. contains(x: number, y: number): boolean {
  145. let arr = this.pointArr;
  146. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  147. return false;
  148. }
  149. for (let i = 1; i < arr.length; i++) {
  150. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  151. return false;
  152. }
  153. }
  154. return true;
  155. } // Function contains()
  156. /**
  157. * Item绘制操作
  158. *
  159. * @param painter painter对象
  160. */
  161. onDraw(painter: SPainter): void {
  162. painter.pen.color = SColor.Transparent;
  163. if (this.selected) {
  164. painter.brush.color = Opt.selectColor;
  165. } else if (this.highLightFlag) {
  166. painter.brush.color = Opt.spaceHighColor;
  167. } else {
  168. painter.brush.color = Opt.spaceColor;
  169. }
  170. painter.pen.lineWidth = 200;
  171. painter.drawPath(this.path);
  172. painter.brush.color = SColor.Black;
  173. // painter.font.size = painter.toPx(10);
  174. painter.font.size = 500;
  175. painter.drawText(
  176. this.data.Name,
  177. this.data.Location.Points[0].X,
  178. -this.data.Location.Points[0].Y
  179. );
  180. } // Function onDraw()
  181. } // Class SpaceItem