SLineMarkerItem.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // @ts-nocheck
  2. import { SGraphItem, SLineStyle } from "@saga-web/graph/lib";
  3. import { SPoint, SPainter, SColor, SLineCapStyle } from "@saga-web/draw/lib";
  4. import { ItemOrder, SLineItem, SItemStatus } from '@saga-web/big/lib';
  5. import { Marker } from '../types/Marker';
  6. /**
  7. * 标识对象Item(线类型)
  8. *
  9. * * @author 张宇(taohuzy@163.com)
  10. */
  11. export class SLineMarkerItem extends SLineItem {
  12. /** 起始锚点 */
  13. startItem: SGraphItem | null = null;
  14. /** 结束锚点 */
  15. endItem: SGraphItem | null = null;
  16. /** 标识对象数据 */
  17. data: Marker;
  18. /** 是否完成绘制 */
  19. get status(): SItemStatus {
  20. return this._status;
  21. }
  22. set status(v: SItemStatus) {
  23. this._status = v;
  24. if (v == SItemStatus.Edit) {
  25. this.zOrder = ItemOrder.markOrder;
  26. } else {
  27. this.zOrder = ItemOrder.lineOrder;
  28. }
  29. this.update();
  30. }
  31. /** 是否蒙版遮罩 */
  32. _maskFlag: boolean = false;
  33. get maskFlag(): boolean {
  34. return this._maskFlag;
  35. }
  36. set maskFlag(v: boolean) {
  37. if (v === this._maskFlag) {
  38. return
  39. }
  40. this._maskFlag = v;
  41. this.update()
  42. }
  43. /**
  44. * 构造函数
  45. *
  46. * @param parent 指向父对象
  47. * @param data 标识对象数据
  48. */
  49. constructor(parent: SGraphItem | null, data: Marker) {
  50. super(parent);
  51. this.zOrder = ItemOrder.lineOrder;
  52. this.data = data;
  53. this.id = data.ID;
  54. this.name = data.Name;
  55. this.moveTo(data.Pos.X, data.Pos.Y);
  56. if (data.Properties.Zorder) {
  57. this.zOrder = data.Properties.Zorder;
  58. }
  59. if (data.Properties && data.Properties.Line) {
  60. let setPointList: SPoint[];
  61. setPointList = data.Properties.Line.map(i => {
  62. return new SPoint(i.X, i.Y)
  63. })
  64. this.line = setPointList;
  65. }
  66. if (data.Properties && data.Properties.LineWidth) {
  67. this.lineWidth = data.Properties.LineWidth;
  68. }
  69. if (data.Properties && data.Properties.LineStyle) {
  70. this.lineStyle = data.Properties.LineStyle;
  71. }
  72. if (data.Properties && data.Properties.StrokeColor) {
  73. this.strokeColor = new SColor(data.Properties.StrokeColor);
  74. }
  75. } // Constructor
  76. /** 接收事件作出修改 */
  77. changePos() {
  78. if (this.startItem) {
  79. // 判断删除equip后,不移动
  80. if (this.startItem.parent) {
  81. let scenePoint: SPoint = this.startItem.boundingRect().center();
  82. this.line[0] = this.startItem.mapToScene(scenePoint.x, scenePoint.y);
  83. }
  84. }
  85. if (this.endItem) {
  86. // 删除equip后
  87. if (this.endItem.parent) {
  88. let scenePoint: SPoint = this.endItem.boundingRect().center();
  89. this.line[1] = this.endItem.mapToScene(scenePoint.x, scenePoint.y);
  90. }
  91. }
  92. }
  93. toData(): Marker {
  94. this.data.Pos = { X: this.x, Y: this.y };
  95. this.data.Properties.Line = this.line.map(pos => {
  96. return {
  97. X: pos.x,
  98. Y: pos.y
  99. }
  100. });
  101. this.data.Properties.Zorder = this.zOrder;
  102. this.data.Properties.LineWidth = this.lineWidth;
  103. this.data.Properties.StrokeColor = this.strokeColor.value;
  104. this.data.Properties.LineStyle = this.lineStyle;
  105. if (this.startItem && this.startItem.parent) {
  106. this.data.Properties.StartItemId = this.startItem.id;
  107. }
  108. if (this.endItem && this.endItem.parent) {
  109. this.data.Properties.EndItemId = this.endItem.id;
  110. }
  111. return this.data;
  112. }
  113. onDraw(painter: SPainter) {
  114. if (this.maskFlag && this.status == SItemStatus.Normal) {
  115. let color = new SColor(this.strokeColor);
  116. color.alpha = 100;
  117. painter.pen.color = new SColor(this.strokeColor);
  118. if (this.lineStyle == SLineStyle.Dashed) {
  119. painter.pen.lineDash = [
  120. painter.toPx(this.lineWidth * 3),
  121. painter.toPx(this.lineWidth * 7)
  122. ];
  123. }
  124. else if (this.lineStyle == SLineStyle.Dotted) {
  125. painter.pen.lineDash = [
  126. painter.toPx(this.lineWidth),
  127. painter.toPx(this.lineWidth)
  128. ];
  129. }
  130. painter.drawLine(this.line[0], this.line[1]);
  131. } else {
  132. super.onDraw(painter);
  133. }
  134. }
  135. } // Class SLineMarkerItem