TipelineItem.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { SPolylineItem, ItemOrder, SItemStatus } from '@saga-web/big/lib'
  2. import { SPainter, SColor } from '@saga-web/draw'
  3. import { SAnchorItem, SGraphItem } from '@saga-web/graph/lib'
  4. import { Relation } from '../types/Relation'
  5. import { SPoint } from '@saga-web/draw/lib'
  6. import { Point } from '@saga-web/big/lib/types/Point'
  7. /**
  8. * 管道item
  9. *
  10. * */
  11. export class TipelineItem extends SPolylineItem {
  12. /** 起始锚点 */
  13. startAnchor: SAnchorItem | null = null
  14. /** 结束锚点 */
  15. endAnchor: SAnchorItem | null = null
  16. /** 对应的图例ID */
  17. _graphElementId: string = ''
  18. get graphElementId(): string {
  19. return this._graphElementId
  20. }
  21. set graphElementId(v: string) {
  22. this._graphElementId = v
  23. if (this.data) {
  24. this.data.GraphElementId = this._graphElementId
  25. }
  26. }
  27. /** 关联节点1ID */
  28. _node1Id: string = ''
  29. get node1Id(): string {
  30. return this._node1Id
  31. }
  32. set node1Id(v: string) {
  33. this._node1Id = v
  34. if (this.data) {
  35. this.data.Node1ID = this._node1Id
  36. }
  37. }
  38. /** 关联节点2ID */
  39. _node2Id: string = ''
  40. get node2Id(): string {
  41. return this._node2Id
  42. }
  43. set node2Id(v: string) {
  44. this._node2Id = v
  45. if (this.data) {
  46. this.data.Node2ID = this._node2Id
  47. }
  48. }
  49. /** 关联锚点1ID */
  50. _anchor1ID: string = ''
  51. get anchor1ID(): string {
  52. return this._anchor1ID
  53. }
  54. set anchor1ID(v: string) {
  55. this._anchor1ID = v
  56. if (this.data) {
  57. this.data.Anchor1ID = this._anchor1ID
  58. }
  59. }
  60. /** 关联锚点2ID */
  61. _anchor2ID: string = ''
  62. get anchor2ID(): string {
  63. return this._anchor2ID
  64. }
  65. set anchor2ID(v: string) {
  66. this._anchor2ID = v
  67. if (this.data) {
  68. this.data.Anchor2ID = this._anchor2ID
  69. }
  70. }
  71. /** 是否蒙版遮罩 */
  72. _maskFlag: boolean = false
  73. get maskFlag(): boolean {
  74. return this._maskFlag
  75. }
  76. set maskFlag(v: boolean) {
  77. if (v === this._maskFlag) {
  78. return
  79. }
  80. this._maskFlag = v
  81. this.update()
  82. }
  83. /** 数据存储 */
  84. data: Relation | null = null
  85. /** 接收事件作出修改 */
  86. changePos() {
  87. if (this.startAnchor) {
  88. // 判断删除equip后,不移动
  89. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  90. this.pointList[0] = this.startAnchor.mapToScene(0, 0)
  91. }
  92. }
  93. if (this.endAnchor) {
  94. // 删除equip后
  95. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  96. this.pointList[this.pointList.length - 1] = this.endAnchor.mapToScene(0, 0)
  97. }
  98. }
  99. }
  100. constructor(parent: SGraphItem | null, data: Relation) {
  101. super(parent, [])
  102. this.zOrder = ItemOrder.polylineOrder
  103. this.pointList = data.PointList.map((item) => {
  104. return new SPoint(item.X, item.Y)
  105. })
  106. this.data = data
  107. this.name = data.Name
  108. this.id = data.ID
  109. if (data.GraphElementId) {
  110. this._graphElementId = data.GraphElementId
  111. }
  112. if (data.Node1ID) {
  113. this._node1Id = data.Node1ID
  114. }
  115. if (data.Node2ID) {
  116. this._node2Id = data.Node2ID
  117. }
  118. if (data.Anchor1ID) {
  119. this._anchor1ID = data.Anchor1ID
  120. }
  121. if (data.Anchor2ID) {
  122. this._anchor2ID = data.Anchor2ID
  123. }
  124. if (data.Properties && data.Properties.Color) {
  125. this.strokeColor = new SColor(data.Properties.Color)
  126. }
  127. // if(data.Properties && data.Properties.LineDash){
  128. // this.LineDash = data.Properties.LineDash
  129. // }
  130. if (data.Properties && data.Properties.LineWidth) {
  131. this.lineWidth = data.Properties.LineWidth
  132. }
  133. }
  134. /** 获取data数据 */
  135. toData(): Relation | null {
  136. let pointList: Point[] = this.pointList.map((item) => {
  137. return {
  138. X: item.x,
  139. Y: item.y,
  140. }
  141. })
  142. if (this.data) {
  143. this.data.Name = this.name;
  144. this.data.PointList = pointList
  145. this.data.Properties.LineWidth = this.lineWidth
  146. // this.data.Properties.LineDash = this.LineDash;
  147. this.data.Properties.Color = this.strokeColor.value
  148. }
  149. return this.data
  150. }
  151. onDraw(painter: SPainter) {
  152. if (this.maskFlag && this.status == SItemStatus.Normal) {
  153. let color = new SColor(this.strokeColor)
  154. color.alpha = color.alpha / 2
  155. painter.pen.color = color
  156. painter.drawPolyline(this.pointList)
  157. } else {
  158. this.selected = true
  159. super.onDraw(painter)
  160. }
  161. }
  162. }