SVirtualWallItem.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { SPainter, SPoint, SRect } from "@persagy-web/draw/lib";
  2. import { SGraphItem } from "@persagy-web/graph/lib";
  3. import {VirtualWall} from "@persagy-web/big/lib/types/floor/VirtualWall";
  4. import {ItemColor, ItemOrder} from "@persagy-web/big/lib";
  5. /**
  6. * 墙item
  7. *
  8. * @author 郝建龙
  9. */
  10. export class SVirtualWallItem extends SGraphItem {
  11. /** 虚拟墙数据 */
  12. data: VirtualWall;
  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. /**
  24. * 构造函数
  25. *
  26. * @param parent 指向父对象
  27. * @param data 虚拟墙数据
  28. */
  29. constructor(parent: SGraphItem | null, data: VirtualWall) {
  30. super(parent);
  31. this.data = data;
  32. this.zOrder = ItemOrder.virtualWallOrder;
  33. let tempArr = this.data.OutLine;
  34. if (tempArr && tempArr.length) {
  35. this.minX = tempArr[0][0].X;
  36. this.maxX = this.minX;
  37. this.minY = -tempArr[0][0].Y;
  38. this.maxY = this.minY;
  39. this.pointArr = tempArr.map((t): SPoint[] => {
  40. return t.map(
  41. (it): SPoint => {
  42. let x = it.X,
  43. y = -it.Y;
  44. if (x < this.minX) {
  45. this.minX = x;
  46. }
  47. if (y < this.minY) {
  48. this.minY = y;
  49. }
  50. if (x > this.maxX) {
  51. this.maxX = x;
  52. }
  53. if (y > this.maxY) {
  54. this.maxY = y;
  55. }
  56. return new SPoint(x, y);
  57. }
  58. );
  59. });
  60. }
  61. } // Constructor
  62. /**
  63. * Item对象边界区域
  64. *
  65. * @return SRect
  66. */
  67. boundingRect(): SRect {
  68. return new SRect(
  69. this.minX,
  70. this.minY,
  71. this.maxX - this.minX,
  72. this.maxY - this.minY
  73. );
  74. } // Function boundingRect()
  75. /**
  76. * Item绘制操作
  77. *
  78. * @param painter painter对象
  79. */
  80. onDraw(painter: SPainter): void {
  81. painter.pen.lineWidth = painter.toPx(1);
  82. painter.pen.color = ItemColor.virtualWallColor;
  83. painter.pen.lineDash = [200, 100];
  84. this.pointArr.forEach((t): void => {
  85. painter.drawPolyline(t);
  86. });
  87. } // Function onDraw()
  88. } // Class SVirtualWallItem