DoorItem.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 { SGraphyItem } from "@saga-web/graphy/lib";
  23. import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  24. /**
  25. * 门item
  26. *
  27. * @author 郝建龙
  28. */
  29. export class DoorItem extends SGraphyItem {
  30. /** 门数据 */
  31. data: Door;
  32. /** 门轮廓线坐标list */
  33. private readonly pointArr: SPoint[] = [];
  34. /** 门长度 */
  35. private r: number = 0;
  36. /** 角度 */
  37. private ang: number = 0;
  38. /** 旋转点 */
  39. private p: SPoint = new SPoint(0, 0);
  40. /** 旋转起始角度 */
  41. private startAng: number = -Math.PI / 2;
  42. /** 旋转结束角度 */
  43. private endAng: number = 0;
  44. // number: number = 0;
  45. /**
  46. * 构造函数
  47. *
  48. * @param parent 指向父对象
  49. * @param data 门数据
  50. */
  51. constructor(parent: SGraphyItem | null, data: Door) {
  52. super(parent);
  53. this.data = data;
  54. if (this.data.OutLine.length) {
  55. this.pointArr = this.data.OutLine[0].map(t => {
  56. return new SPoint(t.X, -t.Y);
  57. });
  58. let p1 = this.pointArr[0];
  59. let p2 = this.pointArr[1];
  60. let fo = Math.atan(
  61. -this.data.FaceDirection.Y / this.data.FaceDirection.X
  62. );
  63. // 两点间距离
  64. this.r = Math.sqrt(
  65. (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)
  66. );
  67. // 门朝向角度
  68. this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
  69. // 旋转点
  70. if (
  71. Math.abs(this.data.HandDirection.X) >
  72. Math.abs(this.data.HandDirection.Y)
  73. ) {
  74. // this.startAng = 0;
  75. // this.endAng = Math.PI / 2;
  76. if (this.data.HandDirection.X > 0) {
  77. if (p1.x > p2.x) {
  78. this.p = p1;
  79. // this.number = 1; //
  80. } else {
  81. this.p = p2;
  82. // this.number = 2;
  83. }
  84. } else {
  85. if (p1.x < p2.x) {
  86. this.p = p1;
  87. // this.number = 3; //
  88. } else {
  89. this.p = p2;
  90. // this.number = 4; //
  91. }
  92. }
  93. } else {
  94. if (this.data.HandDirection.Y > 0) {
  95. if (p1.y > p2.y) {
  96. this.p = p1;
  97. // this.number = 5; //
  98. } else {
  99. this.p = p2;
  100. // this.number = 6;
  101. }
  102. } else {
  103. if (p1.y < p2.y) {
  104. this.p = p1;
  105. // this.number = 7;
  106. } else {
  107. this.p = p2;
  108. // this.number = 8;
  109. }
  110. }
  111. }
  112. }
  113. } // Constructor
  114. /**
  115. * Item绘制操作
  116. *
  117. * @param painter painter对象
  118. * @param rect 绘制区域
  119. */
  120. onDraw(painter: SPainter, rect?: SRect): void {
  121. if (this.visible) {
  122. painter.translate(this.p.x, this.p.y);
  123. painter.rotate(this.ang);
  124. painter.pen.lineWidth = 100;
  125. // let color = [
  126. // "#42b983", //1
  127. // "#4287b9", //2
  128. // "#9742b9", //3
  129. // "#b94242", //4
  130. // "#ffd945", //5
  131. // "#46ff45", //
  132. // "#45f5ff", //
  133. // "#f3f3f3"
  134. // ];
  135. // painter.pen.color = new SColor(color[this.number - 1]);
  136. painter.pen.color = Opt.doorColor;
  137. painter.drawLine(0, 0, this.r, 0);
  138. painter.pen.lineDash = [50, 100];
  139. // painter.drawArc(
  140. // -this.r,
  141. // -this.r,
  142. // this.r * 2,
  143. // this.r * 2,
  144. // this.startAng,
  145. // this.endAng
  146. // );
  147. }
  148. } // Function onDraw()
  149. } // Class DoorItem