DoorItem.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 { Door } from "../types/Door";
  21. import { Opt } from "../types/Opt";
  22. import { SGraphItem } from "@saga-web/graph/lib";
  23. import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  24. import { SMathUtil } from "../utils/SMathUtil";
  25. import { ItemOrder } from "../types/ItemOrder";
  26. /**
  27. * 门item
  28. *
  29. * @author 郝建龙
  30. */
  31. export class DoorItem extends SGraphItem {
  32. /** 门数据 */
  33. data: Door;
  34. /** 门轮廓线坐标list */
  35. private readonly pointArr: SPoint[] = [];
  36. /** 门长度 */
  37. private readonly r: number = 0;
  38. /** 角度 */
  39. private readonly ang: number = 0;
  40. /** 旋转点 */
  41. private readonly p: SPoint = new SPoint(0, 0);
  42. /** 旋转起始角度,结束角度+Math.PI/2 */
  43. private readonly startAng: number = -Math.PI / 2;
  44. /** X坐标最小值 */
  45. private minX = Number.MAX_SAFE_INTEGER;
  46. /** X坐标最大值 */
  47. private maxX = Number.MIN_SAFE_INTEGER;
  48. /** Y坐标最小值 */
  49. private minY = Number.MAX_SAFE_INTEGER;
  50. /** Y坐标最大值 */
  51. private maxY = Number.MIN_SAFE_INTEGER;
  52. /**
  53. * 构造函数
  54. *
  55. * @param parent 指向父对象
  56. * @param data 门数据
  57. */
  58. constructor(parent: SGraphItem | null, data: Door) {
  59. super(parent);
  60. this.data = data;
  61. this.zOrder = ItemOrder.doorOrder;
  62. if (this.data.OutLine.length) {
  63. this.pointArr = this.data.OutLine[0].map(
  64. (t): SPoint => {
  65. let x = t.X,
  66. y = -t.Y;
  67. if (x < this.minX) {
  68. this.minX = x;
  69. }
  70. if (y < this.minY) {
  71. this.minY = y;
  72. }
  73. if (x > this.maxX) {
  74. this.maxX = x;
  75. }
  76. if (y > this.maxY) {
  77. this.maxY = y;
  78. }
  79. return new SPoint(t.X, -t.Y);
  80. }
  81. );
  82. // let p1 = this.pointArr[0],
  83. // p2 = this.pointArr[1];
  84. // // 旋转点
  85. // this.p = p1;
  86. // const HX = (this.data.HandDirection.X = Number(
  87. // this.data.HandDirection.X.toFixed()
  88. // ));
  89. // const HY = (this.data.HandDirection.Y = Number(
  90. // this.data.HandDirection.Y.toFixed()
  91. // ));
  92. // const FX = (this.data.FaceDirection.X = Number(
  93. // this.data.FaceDirection.X.toFixed()
  94. // ));
  95. // const FY = (this.data.FaceDirection.Y = Number(
  96. // this.data.FaceDirection.Y.toFixed()
  97. // ));
  98. // // 向量点乘 => x1 * x2 + y1 * y2,大于0同向
  99. // let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY;
  100. // if (dotProduct > 0) {
  101. // this.p = p2;
  102. // p2 = p1;
  103. // p1 = this.p;
  104. // }
  105. // // 两点间距离
  106. // this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
  107. // // 门朝向角度
  108. // let fo = Math.atan(-FY / FX);
  109. // this.ang = FX > 0 ? fo : fo + Math.PI;
  110. // // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针
  111. // let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX;
  112. // if (direction > 0) {
  113. // this.startAng = 0;
  114. // }
  115. }
  116. } // Constructor
  117. /**
  118. * Item对象边界区域
  119. *
  120. * @return SRect
  121. */
  122. boundingRect(): SRect {
  123. return new SRect(
  124. this.minX,
  125. this.minY,
  126. this.maxX - this.minX,
  127. this.maxY - this.minY
  128. );
  129. } // Function boundingRect()
  130. /**
  131. * Item绘制操作
  132. *
  133. * @param painter painter对象
  134. */
  135. onDraw(painter: SPainter): void {
  136. // painter.translate(this.p.x, this.p.y);
  137. // painter.rotate(this.ang);
  138. // painter.pen.lineWidth = 100;
  139. // painter.pen.color = Opt.doorColor;
  140. // painter.drawLine(0, 0, this.r, 0);
  141. // painter.pen.lineDash = [50, 100];
  142. // painter.pen.lineWidth = 50;
  143. // painter.drawArc(
  144. // -this.r,
  145. // -this.r,
  146. // this.r * 2,
  147. // this.r * 2,
  148. // this.startAng,
  149. // this.startAng + Math.PI / 2
  150. // );
  151. painter.pen.lineWidth = this.data.Thick || 100;
  152. painter.pen.color = Opt.doorColor;
  153. painter.drawLine(this.pointArr[0], this.pointArr[1]);
  154. } // Function onDraw()
  155. } // Class DoorItem