SLineMarkerItem.ts 4.5 KB

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