123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- import { SPolylineItem, ItemOrder, SItemStatus } from '@saga-web/big/lib'
- import { SColor } from '@saga-web/draw'
- import { SPoint } from '@saga-web/draw/lib'
- /**
- * 管道item
- *
- * */
- export class TipelineItem extends SPolylineItem {
- constructor(parent, data) {
- super(parent, [])
- /** 起始锚点 */
- this.startAnchor = null
- /** 结束锚点 */
- this.endAnchor = null
- /** 对应的图例ID */
- this._graphElementId = ''
- /** 关联节点1ID */
- this._node1Id = ''
- /** 关联节点2ID */
- this._node2Id = ''
- /** 关联锚点1ID */
- this._anchor1ID = ''
- /** 关联锚点2ID */
- this._anchor2ID = ''
- /** 是否蒙版遮罩 */
- this._maskFlag = false
- /** 数据存储 */
- this.data = null
- this.zOrder = ItemOrder.polylineOrder
- this.pointList = data.PointList.map((item) => {
- return new SPoint(item.X, item.Y)
- })
- this.data = data
- this.name = data.Name
- this.id = data.ID
- if (data.GraphElementId) {
- this._graphElementId = data.GraphElementId
- }
- if (data.Node1ID) {
- this._node1Id = data.Node1ID
- }
- if (data.Node2ID) {
- this._node2Id = data.Node2ID
- }
- if (data.Anchor1ID) {
- this._anchor1ID = data.Anchor1ID
- }
- if (data.Anchor2ID) {
- this._anchor2ID = data.Anchor2ID
- }
- if (data.Properties && data.Properties.Color) {
- this.strokeColor = new SColor(data.Properties.Color)
- }
- // if(data.Properties && data.Properties.LineDash){
- // this.LineDash = data.Properties.LineDash
- // }
- if (data.Properties && data.Properties.LineWidth) {
- this.lineWidth = data.Properties.LineWidth
- }
- }
- get graphElementId() {
- return this._graphElementId
- }
- set graphElementId(v) {
- this._graphElementId = v
- if (this.data) {
- this.data.GraphElementId = this._graphElementId
- }
- }
- get node1Id() {
- return this._node1Id
- }
- set node1Id(v) {
- this._node1Id = v
- if (this.data) {
- this.data.Node1ID = this._node1Id
- }
- }
- get node2Id() {
- return this._node2Id
- }
- set node2Id(v) {
- this._node2Id = v
- if (this.data) {
- this.data.Node2ID = this._node2Id
- }
- }
- get anchor1ID() {
- return this._anchor1ID
- }
- set anchor1ID(v) {
- this._anchor1ID = v
- if (this.data) {
- this.data.Anchor1ID = this._anchor1ID
- }
- }
- get anchor2ID() {
- return this._anchor2ID
- }
- set anchor2ID(v) {
- this._anchor2ID = v
- if (this.data) {
- this.data.Anchor2ID = this._anchor2ID
- }
- }
- get maskFlag() {
- return this._maskFlag
- }
- set maskFlag(v) {
- if (v === this._maskFlag) {
- return
- }
- this._maskFlag = v
- this.update()
- }
- /** 接收事件作出修改 */
- changePos() {
- if (this.startAnchor) {
- // 判断删除equip后,不移动
- if (this.startAnchor.parent && this.startAnchor.parent.parent) {
- this.pointList[0] = this.startAnchor.mapToScene(0, 0)
- }
- }
- if (this.endAnchor) {
- // 删除equip后
- if (this.endAnchor.parent && this.endAnchor.parent.parent) {
- this.pointList[this.pointList.length - 1] = this.endAnchor.mapToScene(0, 0)
- }
- }
- }
- /** 获取data数据 */
- toData() {
- let pointList = this.pointList.map((item) => {
- return {
- X: item.x,
- Y: item.y,
- }
- })
- if (this.data) {
- this.data.Name = this.name;
- this.data.PointList = pointList
- this.data.Properties.LineWidth = this.lineWidth
- // this.data.Properties.LineDash = this.LineDash;
- this.data.Properties.Color = this.strokeColor.value
- }
- return this.data
- }
- // onDraw(painter: SPainter) {
- // if (this.maskFlag && this.status == SItemStatus.Normal) {
- // let color = new SColor(this.strokeColor)
- // color.alpha = color.alpha / 8
- // painter.pen.color = color
- // if (this.selected) {
- // painter.pen.lineWidth = painter.toPx(this.lineWidth * 2);
- // painter.shadow.shadowBlur = 10;
- // painter.shadow.shadowColor = new SColor(`#00000033`);
- // painter.shadow.shadowOffsetX = 5;
- // painter.shadow.shadowOffsetY = 5;
- // } else {
- // painter.pen.lineWidth = painter.toPx(this.lineWidth);
- // painter.shadow.shadowColor = SColor.Transparent
- // }
- // painter.drawPolyline(this.pointList)
- // painter.pen.color = new SColor('#ffffff80')
- // painter.drawPolyline(this.pointList)
- // } else {
- // super.onDraw(painter)
- // }
- // }
- /**
- * Item绘制框架
- *
- * @param painter painter对象
- * @param rect 绘制区域
- */
- onPaint(painter, rect) {
- super.onPaint(painter, rect);
- if (this.maskFlag && this.status == SItemStatus.Normal) {
- if (this.selected) {
- painter.pen.lineWidth = painter.toPx(this.lineWidth * 2);
- } else {
- painter.pen.lineWidth = painter.toPx(this.lineWidth);
- }
- painter.pen.color = new SColor('#ffffff80')
- painter.drawPolyline(this.pointList)
- }
- } // Function onPaint()
- }
|