/* * ********************************************************************************************************************* * * !! * .F88X * X8888Y * .}888888N; * i888888N; .:! .I$WI: * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8& * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I * +888888N; .8888888Y "&&8Y.}8, * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$* * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~ * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi' * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/ * .:R888888I * .&888888I Copyright (c) 2016-2020. 博锐尚格科技股份有限公司 * ~8888' * .!88~ All rights reserved. * * ********************************************************************************************************************* */ import { SGraphItem, STextItem, SLineStyle, STextOrigin, Point } from "@persagy-web/graph"; import { SColor, SFont, SPainter, SLineCapStyle, SPoint, SPath, SPolygonUtil, SRect } from "@persagy-web/draw"; import { Example } from "../index"; import { SGraphEdit, SBaseTextEdit } from "@persagy-web/edit"; /** * 编辑基础空间类 * * @author 张宇 */ export class SPlanZone extends SGraphEdit { /** X 坐标最小值 */ private minX = Number.MAX_SAFE_INTEGER; /** X 坐标最大值 */ private maxX = Number.MIN_SAFE_INTEGER; /** Y 坐标最小值 */ private minY = Number.MAX_SAFE_INTEGER; /** Y 坐标最大值 */ private maxY = Number.MIN_SAFE_INTEGER; /** 墙轮廓线坐标 list */ private pointList: SPoint[][][] = []; /** path 对象 */ private pathList: SPath[] = []; /** text item */ textItem: SBaseTextEdit = new SBaseTextEdit(this, null); /** 是否可移动 */ set moveable(val: boolean) { return; } /** 设备图例 */ private _legendData: Example | null = null; set legendData(val) { this._legendData = val; this.initData(); } // set legendData() get legendData(): Example | null { return this._legendData; } // get legendData() /** 边框颜色 */ _strokeColor: SColor = SColor.Black; get strokeColor(): SColor { return this._strokeColor; } // Get strokeColor set strokeColor(v: SColor) { this._strokeColor = new SColor(v); this.update(); } // Set strokeColor /** 填充颜色 */ _fillColor: SColor = SColor.Black; get fillColor(): SColor { return this._fillColor; } // Get fillColor set fillColor(v: SColor) { this._fillColor = new SColor(v); this.update(); } // Set fillColor /** 线条样式 */ _lineStyle: SLineStyle = SLineStyle.Solid; get lineStyle(): SLineStyle { return this._lineStyle; } // Get lineStyle set lineStyle(v: SLineStyle) { this._lineStyle = v; this.update(); } // Set lineStyle /** 线条宽度 */ _lineWidth: number = 1; get lineWidth(): number { return this._lineWidth; } // Get lineWidth set lineWidth(v: number) { this._lineWidth = v; this.update(); } // Set lineWidth /** 宽度是否像素 */ widthIsPx: boolean = false; /**文本内容 */ get text(): string { return this.textItem.text; } // Get text set text(v: string) { this.textItem.text = v; this.update(); } // Set text /**文本颜色 */ get color(): SColor { return this.textItem.color; } // Get color set color(v: SColor) { this.textItem.color = v; } // Set color /**文本样式 */ get font(): SFont { return this.textItem.font; } // Get font set font(v: SFont) { this.textItem.font = v; } // Set font /** 是否显示文字 */ _showText: boolean = true; get showText(): boolean { return this._showText; } set showText(v: boolean) { if (v === this._showText) { return; } this._showText = v; if (v) { this.textItem.show(); } else { this.textItem.hide(); } } /** 公式 */ private _formula: string = ""; set formula(val) { this._formula = val; } // set formula() get formula(): string { return this._formula; } // get formula() // 设备附加数据 anotherMsg: string = ""; /** * 构造函数 * * @param parent 指向父对象 * @param data 数据 */ constructor(parent: SGraphItem | null, data: Example) { super(parent); this.textItem.originPosition = STextOrigin.Center; this.textItem.isTransform = false; this.zOrder = 9700; this.selectable = true; this.showSelect = false; this.legendData = data; } // Constructor /** * 设置 legendData 时对 item 做设置 */ initData() { if (!this.legendData) return; this.id = this.legendData.id ? this.legendData.id : ""; this.anotherMsg = this.legendData?.anotherMsg ? this.legendData.anotherMsg : ""; this.textItem.text = this.legendData.localName ? this.legendData.localName : ""; if (this.legendData?.outline?.length && this.legendData.outline[0] && this.legendData.outline[0]?.length) { let tempArr = this.legendData.outline.map((t): Point[][] => { return t.map((it): Point[] => { return it.map( (item): Point => { return { x: item.X, y: -item.Y }; } ); }); }) this.minX = tempArr[0][0][0].x; this.maxX = this.minX; this.minY = tempArr[0][0][0].y; this.maxY = this.minY; this.textItem.moveTo(this.minX, this.minY); // 处理轮廓点数组,同时计算最大最小值 this.pointList = tempArr.map((t): SPoint[][] => { let sPath = new SPath(); let tempArr = t.map((it): SPoint[] => { let array = it.map( (item): SPoint => { let x = item.x, y = item.y; if (x < this.minX) { this.minX = x; } if (y < this.minY) { this.minY = y; } if (x > this.maxX) { this.maxX = x; } if (y > this.maxY) { this.maxY = y; } return new SPoint(x, y); } ); sPath.polygon(array); return array; }); this.pathList.push(sPath); return tempArr; }); } if (this.legendData.textPos?.x && this.legendData.textPos?.y) { this.textItem.moveTo(this.legendData.textPos.x, this.legendData.textPos.y); } } /** * Item 对象边界区域 * * @return 对象边界区域 */ boundingRect(): SRect { return new SRect(this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY); } /** * 判断点是否在区域内 * * @param x 点 x 坐标 * @param y 点 y 坐标 * @return 是否在区域内 */ contains(x: number, y: number): boolean { for (let j = 0; j < this.pointList.length; j++) { let arr = this.pointList[j]; if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) { continue; } if (arr.length == 1) { return true; } let flag = false; for (let i = 1; i < arr.length; i++) { if (SPolygonUtil.pointIn(x, y, arr[i])) { flag = true; break; } } if (flag) { continue; } return true; } return false; } /** * 返回对象储存的相关数据 * * @return 对象储存的相关数据 */ toData(): any { if (this.legendData) { // 位置 const objExtInfo = { id: this.id, textPos: {x: this.textItem.x, y: this.textItem.y}, anotherMsg: this.anotherMsg, }; return objExtInfo; } return new Object(); } /** * Item 绘制操作 * * @param painter 绘制对象 */ onDraw(painter: SPainter) { painter.pen.lineCapStyle = SLineCapStyle.Square; painter.pen.color = this.strokeColor; painter.brush.color = this.fillColor; painter.pen.lineWidth = painter.toPx(this.lineWidth); 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) ]; } // 是否选中 if (this.selected) { painter.shadow.shadowBlur = 10; painter.shadow.shadowColor = new SColor(`#00000033`); painter.shadow.shadowOffsetX = 5; painter.shadow.shadowOffsetY = 5; } else { painter.shadow.shadowColor = SColor.Transparent; } this.pathList.forEach((t): void => { painter.drawPath(t); }); } }