123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { SLineStyle } from '@saga-web/graph/lib'
- import { SPoint, SColor } from '@saga-web/draw/lib'
- import { ItemOrder, SLineItem, SItemStatus } from '@saga-web/big/lib'
- /**
- * 标识对象Item(线类型)
- *
- * * @author 张宇(taohuzy@163.com)
- */
- export class SLineMarkerItem extends SLineItem {
- /**
- * 构造函数
- *
- * @param parent 指向父对象
- * @param data 标识对象数据
- */
- constructor(parent, data) {
- super(parent)
- /** 起始锚点 */
- this.startItem = null
- /** 结束锚点 */
- this.endItem = null
- /** 是否蒙版遮罩 */
- this._maskFlag = false
- this.zOrder = ItemOrder.lineOrder
- this.data = data
- this.id = data.ID
- this.name = data.Name
- this.moveTo(data.Pos.X, data.Pos.Y)
- if (data.Properties && data.Properties.Line) {
- let setPointList
- setPointList = data.Properties.Line.map((i) => {
- return new SPoint(i.X, i.Y)
- })
- this.line = setPointList
- }
- if (data.Properties && data.Properties.LineWidth) {
- this.lineWidth = data.Properties.LineWidth
- }
- if (data.Properties && data.Properties.LineStyle) {
- this.lineStyle = data.Properties.LineStyle
- }
- if (data.Properties && data.Properties.StrokeColor) {
- this.strokeColor = new SColor(data.Properties.StrokeColor)
- }
- } // Constructor
- /** 是否完成绘制 */
- get status() {
- return this._status
- }
- set status(v) {
- this._status = v
- if (v == SItemStatus.Edit) {
- this.zOrder = ItemOrder.markOrder
- } else {
- this.zOrder = ItemOrder.lineOrder
- }
- this.update()
- }
- get maskFlag() {
- return this._maskFlag
- }
- set maskFlag(v) {
- if (v === this._maskFlag) {
- return
- }
- this._maskFlag = v
- this.update()
- }
- /** 接收事件作出修改 */
- changePos() {
- if (this.startItem) {
- // 判断删除equip后,不移动
- if (this.startItem.parent) {
- let scenePoint = this.startItem.boundingRect().center()
- this.line[0] = this.startItem.mapToScene(scenePoint.x, scenePoint.y)
- }
- }
- if (this.endItem) {
- // 删除equip后
- if (this.endItem.parent) {
- let scenePoint = this.endItem.boundingRect().center()
- this.line[1] = this.endItem.mapToScene(scenePoint.x, scenePoint.y)
- }
- }
- }
- toData() {
- this.data.Pos = { X: this.x, Y: this.y }
- this.data.Properties.Line = this.line.map((pos) => {
- return {
- X: pos.x,
- Y: pos.y,
- }
- })
- this.data.Properties.LineWidth = this.lineWidth
- this.data.Properties.StrokeColor = this.strokeColor.value
- this.data.Properties.LineStyle = this.lineStyle
- if (this.startItem && this.startItem.parent) {
- this.data.Properties.StartItemId = this.startItem.id
- }
- if (this.endItem && this.endItem.parent) {
- this.data.Properties.EndItemId = this.endItem.id
- }
- return this.data
- }
- onDraw(painter) {
- if (this.maskFlag && this.status == SItemStatus.Normal) {
- let color = new SColor(this.strokeColor)
- color.alpha = color.alpha / 2
- painter.pen.color = new SColor(this.strokeColor)
- if (this.lineStyle == SLineStyle.Dashed) {
- painter.pen.lineDash = [painter.toPx(this.lineWidth * 3), painter.toPx(this.lineWidth * 7)]
- } else if (this.lineStyle == SLineStyle.Dotted) {
- painter.pen.lineDash = [painter.toPx(this.lineWidth), painter.toPx(this.lineWidth)]
- }
- painter.drawLine(this.line[0], this.line[1])
- } else {
- this.selected = true
- super.onDraw(painter)
- }
- }
- } // Class SLineMarkerItem
|