SWallItem.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {SPainter, SPath, SPoint, SRect} from "@persagy-web/draw/lib";
  2. import { SGraphItem } from "@persagy-web/graph/lib";
  3. import { Wall } from "@persagy-web/big/lib/types/floor/Wall";
  4. import { ItemColor, ItemOrder } from "@persagy-web/big/lib";
  5. /**
  6. * 墙item
  7. *
  8. * @author 郝建龙
  9. */
  10. export class SWallItem extends SGraphItem {
  11. /** 墙数据 */
  12. data: Wall;
  13. /** X坐标最小值 */
  14. private minX = Number.MAX_SAFE_INTEGER;
  15. /** X坐标最大值 */
  16. private maxX = Number.MIN_SAFE_INTEGER;
  17. /** Y坐标最小值 */
  18. private minY = Number.MAX_SAFE_INTEGER;
  19. /** Y坐标最大值 */
  20. private maxY = Number.MIN_SAFE_INTEGER;
  21. /** 墙轮廓线坐标list */
  22. private readonly pointArr: SPoint[][] = [];
  23. /** path对象 */
  24. private path = new SPath();
  25. /**
  26. * 构造函数
  27. *
  28. * @param parent 指向父对象
  29. * @param data 墙数据
  30. */
  31. constructor(parent: SGraphItem | null, data: Wall) {
  32. super(parent);
  33. this.data = data;
  34. this.zOrder = ItemOrder.wallOrder;
  35. let tempArr = this.data.OutLine;
  36. if (tempArr && tempArr.length) {
  37. this.minX = tempArr[0][0].X;
  38. this.maxX = this.minX;
  39. this.minY = -tempArr[0][0].Y;
  40. this.maxY = this.minY;
  41. tempArr.forEach((t): void => {
  42. const temp = t.map(
  43. (it): SPoint => {
  44. let x = it.X,
  45. y = -it.Y;
  46. if (x < this.minX) {
  47. this.minX = x;
  48. }
  49. if (y < this.minY) {
  50. this.minY = y;
  51. }
  52. if (x > this.maxX) {
  53. this.maxX = x;
  54. }
  55. if (y > this.maxY) {
  56. this.maxY = y;
  57. }
  58. return new SPoint(x, y);
  59. }
  60. );
  61. this.path.polygon(temp);
  62. });
  63. }
  64. } // Constructor
  65. /**
  66. * Item对象边界区域
  67. *
  68. * @return SRect
  69. */
  70. boundingRect(): SRect {
  71. return new SRect(
  72. this.minX,
  73. this.minY,
  74. this.maxX - this.minX,
  75. this.maxY - this.minY
  76. );
  77. } // Function boundingRect()
  78. /**
  79. * Item绘制操作
  80. *
  81. * @param painter painter对象
  82. */
  83. onDraw(painter: SPainter): void {
  84. painter.pen.color = ItemColor.wallColor;
  85. painter.pen.lineWidth = painter.toPx(1);
  86. painter.brush.color = ItemColor.wallColor;
  87. painter.drawPath(this.path);
  88. } // Function onDraw()
  89. } // Class SWallItem