SBaseArrowPolyEdit.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. * 构造函数
  55. *
  56. * @param parent 父级
  57. * @param data 坐标集合|第一个点坐标
  58. */
  59. constructor(parent: SGraphItem | null, data: Marker): void {
  60. super(parent, data);
  61. this.pointChange();
  62. }
  63. /**
  64. * 根据两个顶点生成多边形数组
  65. */
  66. pointChange(): void {
  67. if (this.line.length > 1) {
  68. const line = new SLine(this.line[0], this.line[1]);
  69. const dis = SMathUtil.pointDistance(
  70. this.line[0].x,
  71. this.line[0].y,
  72. this.line[1].x,
  73. this.line[1].y
  74. );
  75. if (line.dx != 0) {
  76. const tempFo = Math.atan(line.dy / line.dx);
  77. this._ang = line.dx > 0 ? tempFo : tempFo + Math.PI;
  78. } else {
  79. this._ang = line.dy > 0 ? Math.PI / 2 : (3 * Math.PI) / 2;
  80. }
  81. if (this.isSingle) {
  82. this.pointList = [
  83. new SPoint(0, this.arrowWidth / 2),
  84. new SPoint(dis - this.arrowWidth, this.arrowWidth / 2),
  85. new SPoint(dis - this.arrowWidth, this.arrowWidth),
  86. new SPoint(dis, 0),
  87. new SPoint(dis - this.arrowWidth, -this.arrowWidth),
  88. new SPoint(dis - this.arrowWidth, -this.arrowWidth / 2),
  89. new SPoint(0, -this.arrowWidth / 2)
  90. ];
  91. } else {
  92. this.pointList = [
  93. new SPoint(0, 0),
  94. new SPoint(this.arrowWidth, this.arrowWidth),
  95. new SPoint(this.arrowWidth, this.arrowWidth / 2),
  96. new SPoint(dis - this.arrowWidth, this.arrowWidth / 2),
  97. new SPoint(dis - this.arrowWidth, this.arrowWidth),
  98. new SPoint(dis, 0),
  99. new SPoint(dis - this.arrowWidth, -this.arrowWidth),
  100. new SPoint(dis - this.arrowWidth, -this.arrowWidth / 2),
  101. new SPoint(this.arrowWidth, -this.arrowWidth / 2),
  102. new SPoint(this.arrowWidth, -this.arrowWidth)
  103. ];
  104. }
  105. }
  106. }
  107. /**
  108. * 绘制
  109. *
  110. * @param painter 绘制对象
  111. */
  112. onDraw(painter: SPainter): void {
  113. if (this.line.length) {
  114. painter.save();
  115. const lw = painter.toPx(this.lineWidth);
  116. painter.pen.lineWidth = lw;
  117. this.sceneDis = painter.toPx(this.dis);
  118. painter.translate(this.line[0].x, this.line[0].y);
  119. painter.rotate((this._ang * 180) / Math.PI);
  120. painter.pen.color = this.strokeColor;
  121. painter.brush.color = this.fillColor;
  122. if (this.selected && this.status == SItemStatus.Normal) {
  123. painter.pen.lineWidth = 2 * lw;
  124. painter.shadow.shadowBlur = 10;
  125. painter.shadow.shadowColor = new SColor(`#00000033`);
  126. painter.shadow.shadowOffsetX = 5;
  127. painter.shadow.shadowOffsetY = 5;
  128. }
  129. painter.drawPolygon(this.pointList);
  130. painter.restore();
  131. if (
  132. this.status == SItemStatus.Edit ||
  133. this.status == SItemStatus.Create
  134. ) {
  135. this.line.forEach((p, i) => {
  136. painter.brush.color = this.fillColor;
  137. if (i == this.curIndex) {
  138. painter.brush.color = this.activeFillColor;
  139. }
  140. painter.drawCircle(p.x, p.y, painter.toPx(5));
  141. });
  142. }
  143. }
  144. }
  145. }