SLineMarkerItem.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.markOrder
  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 && data.Properties.Line) {
  56. let setPointList: SPoint[]
  57. setPointList = data.Properties.Line.map((i) => {
  58. return new SPoint(i.X, i.Y)
  59. })
  60. this.line = setPointList
  61. }
  62. if (data.Properties && data.Properties.LineWidth) {
  63. this.lineWidth = data.Properties.LineWidth
  64. }
  65. if (data.Properties && data.Properties.LineStyle) {
  66. this.lineStyle = data.Properties.LineStyle
  67. }
  68. if (data.Properties && data.Properties.StrokeColor) {
  69. this.strokeColor = new SColor(data.Properties.StrokeColor)
  70. }
  71. } // Constructor
  72. /** 接收事件作出修改 */
  73. changePos() {
  74. if (this.startItem) {
  75. // 判断删除equip后,不移动
  76. if (this.startItem.parent) {
  77. let scenePoint: SPoint = this.startItem.boundingRect().center()
  78. this.line[0] = this.startItem.mapToScene(scenePoint.x, scenePoint.y)
  79. }
  80. }
  81. if (this.endItem) {
  82. // 删除equip后
  83. if (this.endItem.parent) {
  84. let scenePoint: SPoint = this.endItem.boundingRect().center()
  85. this.line[1] = this.endItem.mapToScene(scenePoint.x, scenePoint.y)
  86. }
  87. }
  88. }
  89. toData(): Marker {
  90. this.data.Pos = { X: this.x, Y: this.y }
  91. this.data.Properties.Line = this.line.map((pos) => {
  92. return {
  93. X: pos.x,
  94. Y: pos.y,
  95. }
  96. })
  97. this.data.Properties.LineWidth = this.lineWidth
  98. this.data.Properties.StrokeColor = this.strokeColor.value
  99. this.data.Properties.LineStyle = this.lineStyle
  100. if (this.startItem && this.startItem.parent) {
  101. this.data.Properties.StartItemId = this.startItem.id
  102. }
  103. if (this.endItem && this.endItem.parent) {
  104. this.data.Properties.EndItemId = this.endItem.id
  105. }
  106. return this.data
  107. }
  108. onDraw(painter: SPainter) {
  109. if (this.maskFlag && this.status == SItemStatus.Normal) {
  110. let color = new SColor(this.strokeColor)
  111. color.alpha = color.alpha / 2
  112. painter.pen.color = new SColor(this.strokeColor)
  113. if (this.lineStyle == SLineStyle.Dashed) {
  114. painter.pen.lineDash = [painter.toPx(this.lineWidth * 3), painter.toPx(this.lineWidth * 7)]
  115. } else if (this.lineStyle == SLineStyle.Dotted) {
  116. painter.pen.lineDash = [painter.toPx(this.lineWidth), painter.toPx(this.lineWidth)]
  117. }
  118. painter.drawLine(this.line[0], this.line[1])
  119. } else {
  120. this.selected = true
  121. super.onDraw(painter)
  122. }
  123. }
  124. } // Class SLineMarkerItem