SBaseArrowPolyEdit.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2016-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SMathUtil } from "@persagy-web/graph/lib/utils/SMathUtil";
  27. import { SColor, SLine, SPainter, SPoint } from '@persagy-web/draw/lib';
  28. import { SBaseLineEdit } from '../../edit';
  29. import { SItemStatus } from '@persagy-web/big/lib';
  30. import { Marker } from '..';
  31. import { SGraphItem } from '@persagy-web/graph/lib';
  32. /**
  33. * 箭头编辑(多边形)
  34. *
  35. * @author 韩耀龙 <han_yao_long@163.com>
  36. */
  37. export class SBaseArrowPolyEdit extends SBaseLineEdit {
  38. /** 多边形数组 */
  39. pointList: SPoint[] = [];
  40. /** 绘制时需要旋转的角度 */
  41. private _ang: number = 0;
  42. /** 箭头中间粗细 */
  43. arrowWidth: number = 8;
  44. /** 是否为单向箭头 是-只绘制末端箭头 */
  45. _isSingle: boolean = true;
  46. get isSingle(): boolean {
  47. return this._isSingle;
  48. } // Get isSingle
  49. set isSingle(v: boolean) {
  50. this._isSingle = v;
  51. this.update();
  52. } // Set isSingle
  53. /** 多边形填充色 */
  54. private _polyFillColor: SColor = SColor.White;
  55. get polyFillColor(): SColor {
  56. return this._polyFillColor;
  57. } // Get polyFillColor
  58. set polyFillColor(v: SColor) {
  59. this._polyFillColor = v;
  60. this.update();
  61. } // Set polyFillColor
  62. /**
  63. * 构造函数
  64. *
  65. * @param parent 父级
  66. * @param data 坐标集合|第一个点坐标
  67. */
  68. constructor(parent: SGraphItem | null, data: Marker) {
  69. super(parent, data);
  70. this.pointChange();
  71. } // Constructor
  72. /**
  73. * 根据两个顶点生成多边形数组
  74. */
  75. pointChange(): void {
  76. if (this.line.length > 1) {
  77. const line = new SLine(this.line[0], this.line[1]);
  78. const dis = SMathUtil.pointDistance(
  79. this.line[0].x,
  80. this.line[0].y,
  81. this.line[1].x,
  82. this.line[1].y
  83. );
  84. if (line.dx != 0) {
  85. const tempFo = Math.atan(line.dy / line.dx);
  86. this._ang = line.dx > 0 ? tempFo : tempFo + Math.PI;
  87. } else {
  88. this._ang = line.dy > 0 ? Math.PI / 2 : (3 * Math.PI) / 2;
  89. }
  90. if (this.isSingle) {
  91. this.pointList = [
  92. new SPoint(0, this.arrowWidth / 2),
  93. new SPoint(dis - this.arrowWidth, this.arrowWidth / 2),
  94. new SPoint(dis - this.arrowWidth, this.arrowWidth),
  95. new SPoint(dis, 0),
  96. new SPoint(dis - this.arrowWidth, -this.arrowWidth),
  97. new SPoint(dis - this.arrowWidth, -this.arrowWidth / 2),
  98. new SPoint(0, -this.arrowWidth / 2)
  99. ];
  100. } else {
  101. this.pointList = [
  102. new SPoint(0, 0),
  103. new SPoint(this.arrowWidth, this.arrowWidth),
  104. new SPoint(this.arrowWidth, this.arrowWidth / 2),
  105. new SPoint(dis - this.arrowWidth, this.arrowWidth / 2),
  106. new SPoint(dis - this.arrowWidth, this.arrowWidth),
  107. new SPoint(dis, 0),
  108. new SPoint(dis - this.arrowWidth, -this.arrowWidth),
  109. new SPoint(dis - this.arrowWidth, -this.arrowWidth / 2),
  110. new SPoint(this.arrowWidth, -this.arrowWidth / 2),
  111. new SPoint(this.arrowWidth, -this.arrowWidth)
  112. ];
  113. }
  114. }
  115. } // Function pointChange()
  116. /**
  117. * 绘制
  118. *
  119. * @param painter 绘制对象
  120. */
  121. onDraw(painter: SPainter): void {
  122. if (this.line.length) {
  123. painter.save();
  124. const lw = painter.toPx(this.lineWidth);
  125. painter.pen.lineWidth = lw;
  126. this.sceneDis = painter.toPx(this.dis);
  127. painter.translate(this.line[0].x, this.line[0].y);
  128. painter.rotate((this._ang * 180) / Math.PI);
  129. painter.pen.color = this.strokeColor;
  130. painter.brush.color = this.polyFillColor;
  131. if (this.selected && this.status == SItemStatus.Normal) {
  132. painter.pen.lineWidth = 2 * lw;
  133. painter.shadow.shadowBlur = 10;
  134. painter.shadow.shadowColor = new SColor(`#00000033`);
  135. painter.shadow.shadowOffsetX = 5;
  136. painter.shadow.shadowOffsetY = 5;
  137. }
  138. painter.drawPolygon(this.pointList);
  139. painter.restore();
  140. if (
  141. this.status == SItemStatus.Edit ||
  142. this.status == SItemStatus.Create
  143. ) {
  144. this.line.forEach((p, i) => {
  145. painter.brush.color = this.fillColor;
  146. if (i == this.curIndex) {
  147. painter.brush.color = this.activeFillColor;
  148. }
  149. painter.drawCircle(p.x, p.y, painter.toPx(5));
  150. });
  151. }
  152. }
  153. } // Function onDraw()
  154. }