SLineMarkerItem.js 4.0 KB

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