SWallItem.ts 5.2 KB

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