SSpaceItemSS.ts 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 {
  21. SColor,
  22. SPainter,
  23. SPath,
  24. SPoint,
  25. SPolygonUtil,
  26. SRect,
  27. STextAlign
  28. } from "@saga-web/draw/lib";
  29. import { Space } from "../../types/floor/Space";
  30. import { SMouseEvent } from "@saga-web/base/lib";
  31. import { ItemOrder } from "../..";
  32. import { ItemColor } from "../..";
  33. import { SGraphItem } from "@saga-web/graph/lib";
  34. /**
  35. * 模型空间item
  36. *
  37. * @author 郝建龙
  38. */
  39. export class SSpaceItem extends SGraphItem {
  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 SPath();
  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. private _showBaseName: boolean = false;
  65. get showBaseName(): boolean {
  66. return this._showBaseName;
  67. } // Get showBaseName
  68. set showBaseName(value: boolean) {
  69. this._showBaseName = value;
  70. this.update();
  71. } // Set showBaseName
  72. /** 是否名字大小 */
  73. private _nameSize: number = 10;
  74. get nameSize(): number {
  75. return this._nameSize;
  76. } // Get nameSize
  77. set nameSize(value: number) {
  78. this._nameSize = value;
  79. this.update();
  80. } // Set nameSize
  81. /** 名字是否缩放 */
  82. private _nameTransform: boolean = false;
  83. get nameTransform(): boolean {
  84. return this._nameTransform;
  85. } // Get nameTransform
  86. set nameTransform(value: boolean) {
  87. this._nameTransform = value;
  88. this.update();
  89. } // Set nameTransform
  90. /** 名字颜色 */
  91. private _nameColor: string = "#000000";
  92. get nameColor(): string {
  93. return this._nameColor;
  94. } // Get nameColor
  95. set nameColor(value: string) {
  96. this._nameColor = value;
  97. this.update();
  98. } // Set nameColor
  99. /**
  100. * 构造函数
  101. *
  102. * @param parent 指向父对象
  103. * @param data 空间数据
  104. */
  105. constructor(parent: SGraphItem | null, data: Space) {
  106. super(parent);
  107. this.data = data;
  108. this.zOrder = ItemOrder.spaceOrder;
  109. let tempArr = this.data.OutLine;
  110. this.name = data.Name || "";
  111. if (tempArr && tempArr.length) {
  112. this.minX = tempArr[0][0].X;
  113. this.maxX = this.minX;
  114. this.minY = -tempArr[0][0].Y;
  115. this.maxY = this.minY;
  116. this.pointArr = tempArr.map((t): SPoint[] => {
  117. let temp = t.map(
  118. (it): SPoint => {
  119. let x = it.X,
  120. y = -it.Y;
  121. if (x < this.minX) {
  122. this.minX = x;
  123. }
  124. if (y < this.minY) {
  125. this.minY = y;
  126. }
  127. if (x > this.maxX) {
  128. this.maxX = x;
  129. }
  130. if (y > this.maxY) {
  131. this.maxY = y;
  132. }
  133. return new SPoint(x, y);
  134. }
  135. );
  136. this.path.polygon(temp);
  137. return temp;
  138. });
  139. }
  140. } // Constructor
  141. /**
  142. * Item对象边界区域
  143. *
  144. * @return SRect
  145. */
  146. boundingRect(): SRect {
  147. return new SRect(
  148. this.minX,
  149. this.minY,
  150. this.maxX - this.minX,
  151. this.maxY - this.minY
  152. );
  153. } // Function boundingRect()
  154. // /**
  155. // * 鼠标单击事件
  156. // *
  157. // * @param event 事件参数
  158. // * @return boolean
  159. // */
  160. // onMouseDown(event: SMouseEvent): boolean {
  161. // console.log("spaceDown");
  162. // this.$emit("click", event);
  163. // return true;
  164. // } // Function onMouseDown()
  165. // /**
  166. // * 鼠标移动事件
  167. // *
  168. // * @param event 事件参数
  169. // */
  170. // onMouseMove(event: SMouseEvent): boolean {
  171. // return false;
  172. // } // Function onMouseMove()
  173. // /**
  174. // * 鼠标抬起事件
  175. // *
  176. // * @param event 事件参数
  177. // * @return boolean
  178. // */
  179. // onMouseUp(event: SMouseEvent): boolean {
  180. // console.log("spaceUp");
  181. // return false;
  182. // } // Function onClick()
  183. /**
  184. * 判断点是否在区域内
  185. *
  186. * @param x
  187. * @param y
  188. */
  189. contains(x: number, y: number): boolean {
  190. let arr = this.pointArr;
  191. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  192. return false;
  193. }
  194. for (let i = 1; i < arr.length; i++) {
  195. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  196. return false;
  197. }
  198. }
  199. return true;
  200. } // Function contains()
  201. /**
  202. * Item绘制操作
  203. *
  204. * @param painter painter对象
  205. */
  206. onDraw(painter: SPainter): void {
  207. painter.pen.color = ItemColor.spaceBorderColor;
  208. if (this.selected) {
  209. painter.brush.color = ItemColor.selectColor;
  210. } else if (this.highLightFlag) {
  211. painter.brush.color = ItemColor.spaceHighColor;
  212. } else {
  213. painter.brush.color = ItemColor.spaceColor;
  214. }
  215. painter.pen.lineWidth = painter.toPx(1);
  216. painter.drawPath(this.path);
  217. if (this.showBaseName) {
  218. if (this.name && this.name != "null") {
  219. painter.brush.color = new SColor(this.nameColor);
  220. if (this.nameTransform) {
  221. painter.font.size = this.nameSize;
  222. } else {
  223. painter.font.size = painter.toPx(this.nameSize);
  224. }
  225. // painter.font.size = 500;
  226. painter.font.textAlign = STextAlign.Center;
  227. painter.drawText(
  228. this.name,
  229. this.data.Location.Points[0].X,
  230. -this.data.Location.Points[0].Y
  231. );
  232. }
  233. }
  234. } // Function onDraw()
  235. } // Class SSpaceItem