123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= 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
|