/* * ******************************************************************************************************************** * * :*$@@%$*: ;: ;; ;; * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$= * =@* %! @ $= % %@= =%@! %= * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =% * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%* * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$ * $@* ;@@@%=!: *@* * =@$ ;;;!=%@@@@=! =@! * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司 * ;%@@$=$@@%* *@@@$=%@@%; * ::;:: ::;:: All rights reserved. * * ******************************************************************************************************************** */ import { FloorScene } from "./FloorScene"; import { SPoint, SRect } from "@saga-web/draw/lib"; import { SceneMarkItem } from "./items/SceneMarkItem"; import { ZoneItem } from "./items/ZoneItem"; import { Zone } from "./types/Zone"; import { SMouseEvent } from "@saga-web/base/lib"; import { SGraphyItem } from "@saga-web/graphy/lib"; import { HighlightItem } from "./items/HighlightItem"; import { SMathUtil } from "./utils/SMathUtil"; import { MinDis } from "./types/MinDis"; import { PointToLine } from "./types/PointToLine"; /** * 划分业务空间 * * @author 郝建龙 */ export class DivideFloorScene extends FloorScene { /** 是否开启用户标记 */ _isMarking: boolean = false; get isMarking(): boolean { return this._isMarking; } // Get isMarking set isMarking(v: boolean) { if (this._isMarking === v) { return; } this._isMarking = v; } // Set isMarking /** 蒙版item */ sceneMark: SGraphyItem | null = null; /** 业务空间list */ zoneList: ZoneItem[] = []; /** 业务空间是否可选 */ _isZoneSelectable: boolean = true; get isZoneSelectable(): boolean { return this._isZoneSelectable; } // Get isZoneSelectable set isZoneSelectable(v: boolean) { if (this._isZoneSelectable === v) { return; } this._isZoneSelectable = v; this.zoneList.map((t: ZoneItem) => { t.selectable = this._isZoneSelectable; return t; }); } // Set isZoneSelectable /** 高亮item */ hightLight: HighlightItem = new HighlightItem(null, new SPoint(), 0); /** 吸附距离 */ private _absorbLen: number = 1; get absorbLen(): number { return this._absorbLen; } // Get absorbLen set absorbLen(v: number) { this._absorbLen = v; } // Set absorbLen /** * 构造函数 * * @param data */ constructor() { super(); this.addItem(this.hightLight); } // Constructor /** * 添加轮廓线 * * @param data */ addSceneMark(data: SPoint[]): void { if (data.length) { let sceneMark = new SceneMarkItem(null, data); this.addItem(sceneMark); this.sceneMark = sceneMark; } } // Function addSceneMark /** * 清除蒙版 * */ clearSceneMark(): void { if (this.sceneMark) { this.grabItem = null; this.removeItem(this.sceneMark); this.sceneMark = null; this.isMarking = false; } } // Function clearSceneMark() /** * 鼠标按下事件 * * @param event 保存事件参数 * @return boolean */ onMouseDown(event: SMouseEvent): boolean { if (this.isMarking && event.buttons == 1) { if (this.sceneMark) { this.sceneMark.onMouseDown(event); } else { let point = new SPoint(event.x, event.y); let sceneMark = new SceneMarkItem(null, point); this.addItem(sceneMark); this.sceneMark = sceneMark; this.grabItem = sceneMark; } } else { super.onMouseDown(event); } return false; } // Function onMouseDown() /** * 鼠标抬起事件 * * @param event 保存事件参数 * @return boolean */ onMouseUp(event: SMouseEvent): boolean { return false; } // Function onMouseUp() /*** * 键盘按下事件 * * @param event 保存事件参数 */ onKeyUp(event: KeyboardEvent): void { if (this.isMarking) { if (this.grabItem) { this.grabItem.onKeyUp(event); } } else { super.onKeyUp(event); } } // Function onKeyUp() /*** * 注册鼠标点击事件 * * @param _this 接收者 * @param fn 处理函数 */ click(_this: any, fn: Function): void { this.spaceList.map(t => { t.connect("click", _this, fn); }); this.zoneList.map(t => { t.connect("click", _this, fn); }); } // Function click() /** * 添加业务空间到scene 中 * * @param zone 业务空间list */ addZoneList(zone: Zone[]): void { zone.map(t => { this.addZone(t); }); } // Function addZoneList /** * 添加业务空间到scene 中 * * @param zone 业务空间 */ addZone(zone: Zone): void { let item = new ZoneItem(null, zone); item.zOrder = 3; item.selectable = this.isZoneSelectable; this.zoneList.push(item); this.addItem(item); } // Function addZone /** * 清空选中的空间 * */ clearSpaceSelection(): void { this.spaceList.map(t => { t.selected = false; return t; }); } // Function clearSpaceSelection /** * 清空选中的业务空间 * */ clearZoneSelection(): void { this.zoneList.map(t => { t.selected = false; return t; }); } // Function clearZoneSelection /** * 切换业务空间 * */ changeSelectZone(zoneitem: ZoneItem): void { this.zoneList.map(zone => { zone.selected = false; zone.unselectFlag = true; return zone; }); zoneitem.visible = false; } // Function changeSelectZone /** * 吸附空间 * * @param 鼠标事件对象 */ onMouseMove(event: SMouseEvent): boolean { this.hightLight.visible = false; this.absorbSpace(event); return false; } // Function onMouseMove /** * 吸附空间 * * @param 鼠标事件对象 */ absorbSpace(event: SMouseEvent): void { let P = this.absorbPoint(event); if (P.Point) { this.hightLight.distance = P.MinDis; this.hightLight.point = new SPoint(P.Point.X, -P.Point.Y); this.hightLight.visible = true; } else { let L = this.absorbLine(event); if (L.Line) { this.hightLight.distance = L.MinDis; this.hightLight.line = L.Line; this.hightLight.visible = true; } } } // Function absorbSpace /** * 点是否在吸附区域内 * * @param p 要判断的点 * @param minX 空间区域 * @param minY 空间区域 * @param maxX 空间区域 * @param maxY 空间区域 */ isPointInAbsorbArea( p: SPoint, minX: number, maxX: number, minY: number, maxY: number ): boolean { let rect = new SRect( minX - 1000, minY - 1000, maxX - minX + 200, maxY - minY + 2000 ); return rect.contains(p.x, p.y); } // Function isPointInAbsorbArea /** * 吸附点 * * @param 鼠标事件对象 * @return 吸附的点 */ absorbPoint(event: SMouseEvent): MinDis { let minPointDis = Number.MAX_SAFE_INTEGER; let Point; this.spaceList.map(space => { if ( this.isPointInAbsorbArea( new SPoint(event.x, event.y), space.minX, space.maxX, space.minY, space.maxY ) ) { space.data.OutLine.map(item => { let minDis = SMathUtil.getMinDisPoint( new SPoint(event.x, event.y), item ); if ( minDis && minDis.MinDis < 2500 && minDis.MinDis < minPointDis ) { minPointDis = minDis.MinDis; Point = minDis.Point; } }); } }); let minPoint = { MinDis: minPointDis, Point: Point }; return minPoint; } // Function absorbPoint /** * 吸附点 * * @param 鼠标事件对象 * @return 吸附的线 */ absorbLine(event: SMouseEvent): PointToLine { let minPointDis = Number.MAX_SAFE_INTEGER; let Point, Line; this.spaceList.map(space => { if ( this.isPointInAbsorbArea( new SPoint(event.x, event.y), space.minX, space.maxX, space.minY, space.maxY ) ) { space.data.OutLine.map(item => { let minDisLine = SMathUtil.getMinDisLine( new SPoint(event.x, event.y), item ); if ( minDisLine && minDisLine.MinDis < 2500 && minDisLine.MinDis < minPointDis ) { minPointDis = minDisLine.MinDis; Point = minDisLine.Point; Line = minDisLine.Line; } }); } }); let minPointLine = { MinDis: minPointDis, Point: Point, Line: Line }; return minPointLine; } // Function absorbLine } // Class DivideFloorScene