SSpaceItem.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import {
  27. SColor,
  28. SPainter,
  29. SPath,
  30. SPoint,
  31. SPolygonUtil,
  32. SRect,
  33. STextAlign
  34. } from "@persagy-web/draw";
  35. import { Space } from "../../types/floor/Space";
  36. import { ItemOrder, ItemColor } from "../..";
  37. import { SGraphItem } from "@persagy-web/graph";
  38. /**
  39. * 模型空间item
  40. *
  41. * @author 郝建龙
  42. */
  43. export class SSpaceItem extends SGraphItem {
  44. /** 空间所有数据 */
  45. data: Space;
  46. /** 空间轮廓线坐标list */
  47. readonly pointArr: SPoint[][] = [];
  48. /** X坐标最小值 */
  49. minX = Number.MAX_SAFE_INTEGER;
  50. /** X坐标最大值 */
  51. maxX = Number.MIN_SAFE_INTEGER;
  52. /** Y坐标最小值 */
  53. minY = Number.MAX_SAFE_INTEGER;
  54. /** Y坐标最大值 */
  55. maxY = Number.MIN_SAFE_INTEGER;
  56. /** path对象 */
  57. private path = new SPath();
  58. /** 高亮状态 */
  59. private _highLightFlag: boolean = false;
  60. get highLightFlag(): boolean {
  61. return this._highLightFlag;
  62. } // Get highLightFlag
  63. set highLightFlag(value: boolean) {
  64. this._highLightFlag = value;
  65. this.update();
  66. } // Set highLightFlag
  67. /** 是否显示名字 */
  68. private _showBaseName: boolean = false;
  69. get showBaseName(): boolean {
  70. return this._showBaseName;
  71. } // Get showBaseName
  72. set showBaseName(value: boolean) {
  73. this._showBaseName = value;
  74. this.update();
  75. } // Set showBaseName
  76. /** 是否名字大小 */
  77. private _nameSize: number = 10;
  78. get nameSize(): number {
  79. return this._nameSize;
  80. } // Get nameSize
  81. set nameSize(value: number) {
  82. this._nameSize = value;
  83. this.update();
  84. } // Set nameSize
  85. /** 名字是否缩放 */
  86. private _nameTransform: boolean = false;
  87. get nameTransform(): boolean {
  88. return this._nameTransform;
  89. } // Get nameTransform
  90. set nameTransform(value: boolean) {
  91. this._nameTransform = value;
  92. this.update();
  93. } // Set nameTransform
  94. /** 名字颜色 */
  95. private _nameColor: string = "#000000";
  96. get nameColor(): string {
  97. return this._nameColor;
  98. } // Get nameColor
  99. set nameColor(value: string) {
  100. this._nameColor = value;
  101. this.update();
  102. } // Set nameColor
  103. /**
  104. * 构造函数
  105. *
  106. * @param parent 指向父对象
  107. * @param data 空间数据
  108. */
  109. constructor(parent: SGraphItem | null, data: Space) {
  110. super(parent);
  111. this.data = data;
  112. this.zOrder = ItemOrder.spaceOrder;
  113. let tempArr = this.data.OutLine;
  114. this.name = data.Name || "";
  115. if (tempArr && tempArr.length) {
  116. this.minX = tempArr[0][0].X;
  117. this.maxX = this.minX;
  118. this.minY = -tempArr[0][0].Y;
  119. this.maxY = this.minY;
  120. this.pointArr = tempArr.map((t): SPoint[] => {
  121. let temp = t.map(
  122. (it): SPoint => {
  123. let x = it.X,
  124. y = -it.Y;
  125. if (x < this.minX) {
  126. this.minX = x;
  127. }
  128. if (y < this.minY) {
  129. this.minY = y;
  130. }
  131. if (x > this.maxX) {
  132. this.maxX = x;
  133. }
  134. if (y > this.maxY) {
  135. this.maxY = y;
  136. }
  137. return new SPoint(x, y);
  138. }
  139. );
  140. this.path.polygon(temp);
  141. return temp;
  142. });
  143. }
  144. } // Constructor
  145. /**
  146. * Item对象边界区域
  147. *
  148. * @return SRect
  149. */
  150. boundingRect(): SRect {
  151. return new SRect(
  152. this.minX,
  153. this.minY,
  154. this.maxX - this.minX,
  155. this.maxY - this.minY
  156. );
  157. } // Function boundingRect()
  158. /**
  159. * 判断点是否在区域内
  160. *
  161. * @param x
  162. * @param y
  163. */
  164. contains(x: number, y: number): boolean {
  165. let arr = this.pointArr;
  166. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  167. return false;
  168. }
  169. for (let i = 1; i < arr.length; i++) {
  170. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  171. return false;
  172. }
  173. }
  174. return true;
  175. } // Function contains()
  176. /**
  177. * Item绘制操作
  178. *
  179. * @param painter painter对象
  180. */
  181. onDraw(painter: SPainter): void {
  182. painter.pen.color = ItemColor.spaceBorderColor;
  183. if (this.selected) {
  184. painter.brush.color = ItemColor.selectColor;
  185. } else if (this.highLightFlag) {
  186. painter.brush.color = ItemColor.spaceHighColor;
  187. } else {
  188. painter.brush.color = ItemColor.spaceColor;
  189. }
  190. painter.pen.lineWidth = painter.toPx(1);
  191. painter.drawPath(this.path);
  192. if (this.showBaseName) {
  193. if (this.name && this.name != "null") {
  194. painter.brush.color = new SColor(this.nameColor);
  195. if (this.nameTransform) {
  196. painter.font.size = this.nameSize;
  197. } else {
  198. painter.font.size = painter.toPx(this.nameSize);
  199. }
  200. painter.font.textAlign = STextAlign.Center;
  201. painter.drawText(
  202. this.name,
  203. this.data.Location.Points[0].X,
  204. -this.data.Location.Points[0].Y
  205. );
  206. }
  207. }
  208. } // Function onDraw()
  209. } // Class SSpaceItem