SWallItem.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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) 2016-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SPainter, SPath2D, SPoint, SRect } from "@persagy-web/draw";
  27. import { Wall } from "../../types/floor/Wall";
  28. import { ItemOrder, ItemColor } from "../..";
  29. import { SGraphItem } from "@persagy-web/graph";
  30. /**
  31. * 墙item
  32. *
  33. * @author 郝建龙
  34. */
  35. export class SWallItem extends SGraphItem {
  36. /** 墙数据 */
  37. data: Wall;
  38. /** X坐标最小值 */
  39. private minX = Number.MAX_SAFE_INTEGER;
  40. /** X坐标最大值 */
  41. private maxX = Number.MIN_SAFE_INTEGER;
  42. /** Y坐标最小值 */
  43. private minY = Number.MAX_SAFE_INTEGER;
  44. /** Y坐标最大值 */
  45. private maxY = Number.MIN_SAFE_INTEGER;
  46. /** 墙轮廓线坐标list */
  47. private readonly pointArr: SPoint[][] = [];
  48. /** 墙内轮廓线坐标list */
  49. private readonly holesArr: SPoint[][] = [];
  50. /** path对象 */
  51. private path = new SPath2D();
  52. /**
  53. * 构造函数
  54. *
  55. * @param parent 指向父对象
  56. * @param data 墙数据
  57. */
  58. constructor(parent: SGraphItem | null, data: Wall) {
  59. super(parent);
  60. this.data = data;
  61. this.zOrder = ItemOrder.wallOrder;
  62. let tempArr = this.data.OutLine;
  63. let holes = data.Holes;
  64. if (tempArr && tempArr.length) {
  65. this.minX = tempArr[0][0].X;
  66. this.maxX = this.minX;
  67. this.minY = -tempArr[0][0].Y;
  68. this.maxY = this.minY;
  69. this.pointArr = [];
  70. let WLine = tempArr[0].map(
  71. (it): SPoint => {
  72. let x = it.X,
  73. y = -it.Y;
  74. if (x < this.minX) {
  75. this.minX = x;
  76. }
  77. if (y < this.minY) {
  78. this.minY = y;
  79. }
  80. if (x > this.maxX) {
  81. this.maxX = x;
  82. }
  83. if (y > this.maxY) {
  84. this.maxY = y;
  85. }
  86. return new SPoint(x, y);
  87. }
  88. );
  89. // 外轮廓
  90. this.path.polygon(WLine);
  91. // 外轮廓
  92. this.pointArr.push(WLine);
  93. // 内轮廓
  94. if (holes && holes.length) {
  95. this.holesArr = holes.map(t => {
  96. let temp = t.map(
  97. (it): SPoint => {
  98. let x = it.X,
  99. y = -it.Y;
  100. if (x < this.minX) {
  101. this.minX = x;
  102. }
  103. if (y < this.minY) {
  104. this.minY = y;
  105. }
  106. if (x > this.maxX) {
  107. this.maxX = x;
  108. }
  109. if (y > this.maxY) {
  110. this.maxY = y;
  111. }
  112. return new SPoint(x, y);
  113. }
  114. );
  115. this.path.polygon(temp);
  116. return temp;
  117. });
  118. }
  119. }
  120. } // Constructor
  121. /**
  122. * Item对象边界区域
  123. *
  124. * @return SRect
  125. */
  126. boundingRect(): SRect {
  127. return new SRect(
  128. this.minX,
  129. this.minY,
  130. this.maxX - this.minX,
  131. this.maxY - this.minY
  132. );
  133. } // Function boundingRect()
  134. /**
  135. * Item绘制操作
  136. *
  137. * @param painter painter对象
  138. */
  139. onDraw(painter: SPainter): void {
  140. painter.pen.color = ItemColor.wallColor;
  141. painter.pen.lineWidth = painter.toPx(1);
  142. painter.brush.color = ItemColor.wallColor;
  143. painter.drawPath(this.path);
  144. } // Function onDraw()
  145. } // Class SWallItem