SWindowItem.ts 2.3 KB

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