SLineMarkerItem.ts 5.0 KB

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