SSpaceItem.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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, SGraphAreaGroupItem } from "@persagy-web/graph";
  38. /**
  39. * 模型空间item
  40. *
  41. * @author 郝建龙
  42. */
  43. export class SSpaceItem extends SGraphAreaGroupItem {
  44. /** 空间所有数据 */
  45. data: Space;
  46. /** 高亮状态 */
  47. private _highLightFlag: boolean = false;
  48. get highLightFlag(): boolean {
  49. return this._highLightFlag;
  50. } // Get highLightFlag
  51. set highLightFlag(value: boolean) {
  52. this._highLightFlag = value;
  53. this.update();
  54. } // Set highLightFlag
  55. /** 是否显示名字 */
  56. private _showBaseName: boolean = false;
  57. get showBaseName(): boolean {
  58. return this._showBaseName;
  59. } // Get showBaseName
  60. set showBaseName(value: boolean) {
  61. this._showBaseName = value;
  62. this.update();
  63. } // Set showBaseName
  64. /** 是否名字大小 */
  65. private _nameSize: number = 10;
  66. get nameSize(): number {
  67. return this._nameSize;
  68. } // Get nameSize
  69. set nameSize(value: number) {
  70. this._nameSize = value;
  71. this.update();
  72. } // Set nameSize
  73. /** 名字是否缩放 */
  74. private _nameTransform: boolean = false;
  75. get nameTransform(): boolean {
  76. return this._nameTransform;
  77. } // Get nameTransform
  78. set nameTransform(value: boolean) {
  79. this._nameTransform = value;
  80. this.update();
  81. } // Set nameTransform
  82. /** 名字颜色 */
  83. private _nameColor: string = "#000000";
  84. get nameColor(): string {
  85. return this._nameColor;
  86. } // Get nameColor
  87. set nameColor(value: string) {
  88. this._nameColor = value;
  89. this.update();
  90. } // Set nameColor
  91. /**
  92. * 构造函数
  93. *
  94. * @param parent 指向父对象
  95. * @param data 空间数据
  96. */
  97. constructor(parent: SGraphItem | null, data: Space) {
  98. super(parent, {
  99. Outline: [
  100. data.OutLine.map(t => {
  101. return t.map(it => {
  102. it.Y = -it.Y;
  103. return it;
  104. });
  105. })
  106. ],
  107. Style: {
  108. Default: {
  109. Stroke: "#2b2b2b",
  110. Fill: "#f1fffd80",
  111. LineWidth: 1,
  112. Effect: {}
  113. },
  114. Selected: {
  115. Stroke: "#2b2b2b",
  116. Fill: "#1abc9c",
  117. LineWidth: 1,
  118. Effect: {}
  119. },
  120. Disabled: {
  121. Stroke: "#2b2b2b",
  122. Fill: "#afafaf",
  123. LineWidth: 1,
  124. Effect: {}
  125. },
  126. Highlight: {
  127. Stroke: "#2b2b2b",
  128. Fill: "#fbb029",
  129. LineWidth: 1,
  130. Effect: {}
  131. }
  132. }
  133. });
  134. this.data = data;
  135. this.zOrder = ItemOrder.spaceOrder;
  136. this.name = data.Name || "";
  137. } // Constructor
  138. /**
  139. * 绘制前设置绘制样式
  140. *
  141. * */
  142. setStyle(): string {
  143. let status = "Default";
  144. if (this.style) {
  145. if (this.highLightFlag) {
  146. status = "Highlight";
  147. } else if (this.enabled) {
  148. if (this.selected) {
  149. status = "Selected";
  150. }
  151. } else {
  152. status = "Disabled";
  153. }
  154. }
  155. return status;
  156. } // Function setStyle()
  157. /**
  158. * Item绘制操作
  159. *
  160. * @param painter painter对象
  161. */
  162. onDraw(painter: SPainter): void {
  163. super.onDraw(painter);
  164. if (this.showBaseName) {
  165. if (this.name && this.name != "null") {
  166. painter.brush.color = new SColor(this.nameColor);
  167. if (this.nameTransform) {
  168. painter.font.size = this.nameSize;
  169. } else {
  170. painter.font.size = painter.toPx(this.nameSize);
  171. }
  172. painter.font.textAlign = STextAlign.Center;
  173. painter.drawText(
  174. this.name,
  175. this.data.Location.Points[0].X,
  176. -this.data.Location.Points[0].Y
  177. );
  178. }
  179. }
  180. } // Function onDraw()
  181. } // Class SSpaceItem