SSpaceItem.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. SPainter,
  24. SPath2D,
  25. SPoint,
  26. SPolygonUtil,
  27. SRect,
  28. STextAlign
  29. } from "@saga-web/draw/lib";
  30. import { Space } from "../../types/floor/Space";
  31. import { SMouseEvent } from "@saga-web/base/lib";
  32. import { ItemOrder } from "../../config/ItemOrder";
  33. import { ItemColor } from "../../config/ItemColor";
  34. /**
  35. * 模型空间item
  36. *
  37. * @author 郝建龙
  38. */
  39. export class SSpaceItem 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. onMouseDown(event: SMouseEvent): boolean {
  124. console.log("spaceDown");
  125. if (this.selectable) {
  126. this.selected = !this.selected;
  127. }
  128. this.$emit("click", event);
  129. return true;
  130. } // Function onMouseDown()
  131. /**
  132. * 鼠标移动事件
  133. *
  134. * @param event 事件参数
  135. */
  136. onMouseMove(event: SMouseEvent): boolean {
  137. return false;
  138. } // Function onMouseMove()
  139. /**
  140. * 鼠标抬起事件
  141. *
  142. * @param event 事件参数
  143. * @return boolean
  144. */
  145. onMouseUp(event: SMouseEvent): boolean {
  146. console.log("spaceUp");
  147. return false;
  148. } // Function onClick()
  149. /**
  150. * 判断点是否在区域内
  151. *
  152. * @param x
  153. * @param y
  154. */
  155. contains(x: number, y: number): boolean {
  156. let arr = this.pointArr;
  157. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  158. return false;
  159. }
  160. for (let i = 1; i < arr.length; i++) {
  161. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  162. return false;
  163. }
  164. }
  165. return true;
  166. } // Function contains()
  167. /**
  168. * Item绘制操作
  169. *
  170. * @param painter painter对象
  171. */
  172. onDraw(painter: SPainter): void {
  173. painter.pen.color = ItemColor.spaceBorderColor;
  174. if (this.selected) {
  175. painter.brush.color = ItemColor.selectColor;
  176. } else if (this.highLightFlag) {
  177. painter.brush.color = ItemColor.spaceHighColor;
  178. } else {
  179. painter.brush.color = ItemColor.spaceColor;
  180. }
  181. painter.pen.lineWidth = painter.toPx(1);
  182. painter.drawPath(this.path);
  183. painter.brush.color = SColor.Black;
  184. painter.font.size = painter.toPx(10);
  185. // painter.font.size = 500;
  186. painter.font.textAlign = STextAlign.Center;
  187. painter.drawText(
  188. this.data.Name,
  189. this.data.Location.Points[0].X,
  190. -this.data.Location.Points[0].Y
  191. );
  192. } // Function onDraw()
  193. } // Class SSpaceItem