SSpaceItems.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. SPoint,
  30. SPolygonUtil,
  31. SRect,
  32. STextAlign
  33. } from "@persagy-web/draw";
  34. import { Space } from "../../types/floor/Space";
  35. import { ItemOrder, ItemColor } from "../..";
  36. import { SGraphItem } from "@persagy-web/graph";
  37. /**
  38. * 模型空间 item
  39. *
  40. * @author 郝建龙 <haojianlong@sagacloud.cn>
  41. * @deprecated 万达
  42. */
  43. export class SSpaceItems 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 SPath2D();
  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 event 事件参数
  162. // * @return boolean
  163. // */
  164. // onMouseDown(event: SMouseEvent): boolean {
  165. // console.log("spaceDown");
  166. // this.$emit("click", event);
  167. // return true;
  168. // } // Function onMouseDown()
  169. // /**
  170. // * 鼠标移动事件
  171. // *
  172. // * @param event 事件参数
  173. // */
  174. // onMouseMove(event: SMouseEvent): boolean {
  175. // return false;
  176. // } // Function onMouseMove()
  177. // /**
  178. // * 鼠标抬起事件
  179. // *
  180. // * @param event 事件参数
  181. // * @return boolean
  182. // */
  183. // onMouseUp(event: SMouseEvent): boolean {
  184. // console.log("spaceUp");
  185. // return false;
  186. // } // Function onClick()
  187. /**
  188. * 判断点是否在区域内
  189. *
  190. * @param x
  191. * @param y
  192. */
  193. contains(x: number, y: number): boolean {
  194. let arr = this.pointArr;
  195. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  196. return false;
  197. }
  198. for (let i = 1; i < arr.length; i++) {
  199. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  200. return false;
  201. }
  202. }
  203. return true;
  204. } // Function contains()
  205. /**
  206. * Item绘制操作
  207. *
  208. * @param painter painter对象
  209. */
  210. onDraw(painter: SPainter): void {
  211. painter.pen.color = ItemColor.spaceBorderColor;
  212. if (this.selected) {
  213. painter.brush.color = ItemColor.selectColor;
  214. } else if (this.highLightFlag) {
  215. painter.brush.color = ItemColor.spaceHighColor;
  216. } else {
  217. painter.brush.color = ItemColor.spaceColor;
  218. }
  219. painter.pen.lineWidth = painter.toPx(1);
  220. // painter.drawPath(this.path);
  221. if (this.pointArr.length) {
  222. painter.drawPolygon(this.pointArr[0]);
  223. }
  224. if (this.showBaseName) {
  225. if (this.name && this.name != "null") {
  226. painter.brush.color = new SColor(this.nameColor);
  227. if (this.nameTransform) {
  228. painter.font.size = this.nameSize;
  229. } else {
  230. painter.font.size = painter.toPx(this.nameSize);
  231. }
  232. // painter.font.size = 500;
  233. painter.font.textAlign = STextAlign.Center;
  234. painter.drawText(
  235. this.name,
  236. this.data.Location.Points[0].X,
  237. -this.data.Location.Points[0].Y
  238. );
  239. }
  240. }
  241. } // Function onDraw()
  242. } // Class SSpaceItem