|
@@ -32,7 +32,8 @@ import { RectSelectItem } from "./items/RectSelectItem";
|
|
|
// @ts-ignore
|
|
|
import { intersect } from "polybooljs";
|
|
|
import { ShadeItem } from "./items/ShadeItem";
|
|
|
-import { SGraphyItem } from "@saga-web/graphy/lib";
|
|
|
+import { Point } from "./types/Point";
|
|
|
+import { LikeSpaceItem } from "./items/LikeSpaceItem";
|
|
|
|
|
|
/**
|
|
|
* 划分业务空间
|
|
@@ -56,10 +57,16 @@ export class DivideFloorScene extends FloorScene {
|
|
|
sceneMark: SceneMarkItem | null = null;
|
|
|
/** 业务空间list */
|
|
|
zoneList: ZoneItem[] = [];
|
|
|
-
|
|
|
/** 遮罩List */
|
|
|
shadeList: ShadeItem[] = [];
|
|
|
-
|
|
|
+ /** 划分item */
|
|
|
+ cutItem: ShadeItem | null = null;
|
|
|
+ /** 类空间itemList */
|
|
|
+ likeSpaceList: LikeSpaceItem[] = [];
|
|
|
+ /** 高亮item */
|
|
|
+ highLight: HighlightItem = new HighlightItem(null);
|
|
|
+ /** 是否开启切分 */
|
|
|
+ isCutting: boolean = false;
|
|
|
/** 业务空间是否可选 */
|
|
|
_isZoneSelectable: boolean = true;
|
|
|
get isZoneSelectable(): boolean {
|
|
@@ -79,8 +86,6 @@ export class DivideFloorScene extends FloorScene {
|
|
|
});
|
|
|
} // Set isZoneSelectable
|
|
|
|
|
|
- /** 高亮item */
|
|
|
- highLight: HighlightItem = new HighlightItem(null);
|
|
|
/** 是否开启吸附 */
|
|
|
private _isAbsorbing: boolean = false;
|
|
|
get isAbsorbing(): boolean {
|
|
@@ -142,6 +147,19 @@ export class DivideFloorScene extends FloorScene {
|
|
|
} // Function clearSceneMark()
|
|
|
|
|
|
/**
|
|
|
+ * 清除划分区域
|
|
|
+ *
|
|
|
+ */
|
|
|
+ clearCut(): void {
|
|
|
+ if (this.cutItem) {
|
|
|
+ this.grabItem = null;
|
|
|
+ this.removeItem(this.cutItem);
|
|
|
+ this.cutItem = null;
|
|
|
+ this.isCutting = false;
|
|
|
+ }
|
|
|
+ } // Function clearCut()
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加所有遮罩层
|
|
|
*
|
|
|
* @param data 遮罩数据
|
|
@@ -170,6 +188,58 @@ export class DivideFloorScene extends FloorScene {
|
|
|
} // Function addShade()
|
|
|
|
|
|
/**
|
|
|
+ * 添加所有类空间item
|
|
|
+ *
|
|
|
+ * @param data 所有数据
|
|
|
+ */
|
|
|
+ addAllLikeSpace(data: Point[][][]): void {
|
|
|
+ if (data.length) {
|
|
|
+ data.map(t => {
|
|
|
+ this.addLikeSpace(t);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } // Function addAllLikeSpace()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加单个类空间item
|
|
|
+ *
|
|
|
+ * @param data 单个类空间item数据
|
|
|
+ */
|
|
|
+ addLikeSpace(data: Point[][]): void {
|
|
|
+ let item = new LikeSpaceItem(null, data);
|
|
|
+ item.selectable = true;
|
|
|
+ item.selected = true;
|
|
|
+ this.likeSpaceList.push(item);
|
|
|
+ this.addItem(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除所有类空间item
|
|
|
+ *
|
|
|
+ */
|
|
|
+ clearLikeSpaces() {
|
|
|
+ if (this.likeSpaceList.length) {
|
|
|
+ this.likeSpaceList.map(t => {
|
|
|
+ this.removeItem(t);
|
|
|
+ });
|
|
|
+ this.likeSpaceList = [];
|
|
|
+ }
|
|
|
+ } // Function clearLikeSpaces()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取选中的类空间
|
|
|
+ */
|
|
|
+ getSelectedLikeSpace(): LikeSpaceItem[] {
|
|
|
+ let arr: LikeSpaceItem[] = [];
|
|
|
+ this.likeSpaceList.map(t => {
|
|
|
+ if (t.selected) {
|
|
|
+ arr.push(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ } // Function getSelectedLikeSpace()
|
|
|
+
|
|
|
+ /**
|
|
|
* 鼠标按下事件
|
|
|
*
|
|
|
* @param event 保存事件参数
|
|
@@ -192,6 +262,21 @@ export class DivideFloorScene extends FloorScene {
|
|
|
this.sceneMark = sceneMark;
|
|
|
this.grabItem = sceneMark;
|
|
|
}
|
|
|
+ } else if (this.isCutting) {
|
|
|
+ // 判断是否开启吸附,并且有吸附的点
|
|
|
+ if (this.isAbsorbing && this.highLight.visible) {
|
|
|
+ event.x = this.highLight.point.x;
|
|
|
+ event.y = this.highLight.point.y;
|
|
|
+ }
|
|
|
+ if (this.cutItem) {
|
|
|
+ this.cutItem.onMouseDown(event);
|
|
|
+ } else {
|
|
|
+ let point = new SPoint(event.x, event.y);
|
|
|
+ let cut = new ShadeItem(null, point);
|
|
|
+ this.addItem(cut);
|
|
|
+ this.cutItem = cut;
|
|
|
+ this.grabItem = cut;
|
|
|
+ }
|
|
|
} else if (this.isRectSelection) {
|
|
|
if (this.rectSelectItem) {
|
|
|
this.isRectSelection = false;
|
|
@@ -221,7 +306,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
if (this.rectSelectItem) {
|
|
|
this.isRectSelection = false;
|
|
|
- this.getIntersect();
|
|
|
+ this.groupSelectSpace();
|
|
|
this.removeItem(this.rectSelectItem);
|
|
|
this.rectSelectItem = null;
|
|
|
}
|
|
@@ -252,7 +337,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
* @param event 保存事件参数
|
|
|
*/
|
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
|
- if (this.isMarking) {
|
|
|
+ if (this.isMarking || this.isCutting) {
|
|
|
if (this.grabItem) {
|
|
|
this.grabItem.onKeyUp(event);
|
|
|
}
|
|
@@ -285,7 +370,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
zone.map(t => {
|
|
|
this.addZone(t);
|
|
|
});
|
|
|
- } // Function addZoneList
|
|
|
+ } // Function addZoneList()
|
|
|
|
|
|
/**
|
|
|
* 添加业务空间到scene 中
|
|
@@ -297,7 +382,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
item.selectable = this.isZoneSelectable;
|
|
|
this.zoneList.push(item);
|
|
|
this.addItem(item);
|
|
|
- } // Function addZone
|
|
|
+ } // Function addZone()
|
|
|
|
|
|
/**
|
|
|
* 清空选中的空间
|
|
@@ -308,7 +393,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
t.selected = false;
|
|
|
return t;
|
|
|
});
|
|
|
- } // Function clearSpaceSelection
|
|
|
+ } // Function clearSpaceSelection()
|
|
|
|
|
|
/**
|
|
|
* 清空选中的业务空间
|
|
@@ -319,7 +404,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
t.selected = false;
|
|
|
return t;
|
|
|
});
|
|
|
- } // Function clearZoneSelection
|
|
|
+ } // Function clearZoneSelection()
|
|
|
|
|
|
/**
|
|
|
* 吸附空间
|
|
@@ -345,7 +430,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
this.highLight.visible = true;
|
|
|
}
|
|
|
}
|
|
|
- } // Function absorbSpace
|
|
|
+ } // Function absorbSpace()
|
|
|
|
|
|
/**
|
|
|
* 点是否在吸附区域内
|
|
@@ -370,7 +455,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
maxY - minY + 2000
|
|
|
);
|
|
|
return rect.contains(p.x, p.y);
|
|
|
- } // Function isPointInAbsorbArea
|
|
|
+ } // Function isPointInAbsorbArea()
|
|
|
|
|
|
/**
|
|
|
* 吸附点
|
|
@@ -413,7 +498,7 @@ export class DivideFloorScene extends FloorScene {
|
|
|
Point: Point
|
|
|
};
|
|
|
return minPoint;
|
|
|
- } // Function absorbPoint
|
|
|
+ } // Function absorbPoint()
|
|
|
|
|
|
/**
|
|
|
* 吸附线
|
|
@@ -458,39 +543,104 @@ export class DivideFloorScene extends FloorScene {
|
|
|
Line: Line
|
|
|
};
|
|
|
return minPointLine;
|
|
|
- } // Function absorbLine
|
|
|
+ } // Function absorbLine()
|
|
|
|
|
|
- /** */
|
|
|
- getIntersect(): void {
|
|
|
- if (this.sceneMark) {
|
|
|
+ /**
|
|
|
+ * 计算绘制区域与选中空间交集
|
|
|
+ *
|
|
|
+ */
|
|
|
+ getIntersect(): SPoint[][] {
|
|
|
+ let arr: SPoint[][] = [];
|
|
|
+ if (this.cutItem) {
|
|
|
let poly2 = {
|
|
|
- regions: [
|
|
|
- // [
|
|
|
- // [
|
|
|
- // this.rectSelectItem.startPoint.x,
|
|
|
- // this.rectSelectItem.startPoint.y
|
|
|
- // ],
|
|
|
- // [
|
|
|
- // this.rectSelectItem.startPoint.x,
|
|
|
- // this.rectSelectItem.endPoint.y
|
|
|
- // ],
|
|
|
- // [
|
|
|
- // this.rectSelectItem.endPoint.x,
|
|
|
- // this.rectSelectItem.endPoint.y
|
|
|
- // ],
|
|
|
- // [
|
|
|
- // this.rectSelectItem.endPoint.x,
|
|
|
- // this.rectSelectItem.startPoint.y
|
|
|
- // ]
|
|
|
- // ]
|
|
|
- ],
|
|
|
+ regions: [],
|
|
|
inverted: false
|
|
|
};
|
|
|
poly2.regions.push(
|
|
|
// @ts-ignore
|
|
|
- SMathUtil.transferToArray(this.sceneMark.outLine)
|
|
|
+ SMathUtil.transferToArray(this.cutItem.outLine)
|
|
|
);
|
|
|
- console.log(poly2);
|
|
|
+ this.spaceList.map(t => {
|
|
|
+ if (t.selected) {
|
|
|
+ let poly1 = {
|
|
|
+ regions: [],
|
|
|
+ inverted: false
|
|
|
+ };
|
|
|
+ // @ts-ignore
|
|
|
+ poly1.regions = t.pointArr.map(item => {
|
|
|
+ return SMathUtil.transferToArray(item);
|
|
|
+ });
|
|
|
+ console.log(poly1);
|
|
|
+ let intersectObj = intersect(poly1, poly2);
|
|
|
+ if (intersectObj.regions.length) {
|
|
|
+ intersectObj.regions.map((t: number[][]) => {
|
|
|
+ arr.push(SMathUtil.transferToSPoint(t));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ } // Function getIntersect()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算绘制区域与选中类空间交集
|
|
|
+ *
|
|
|
+ */
|
|
|
+ getLikeIntersect(): SPoint[][] {
|
|
|
+ let arr: SPoint[][] = [];
|
|
|
+ if (this.cutItem) {
|
|
|
+ let poly2 = {
|
|
|
+ regions: [],
|
|
|
+ inverted: false
|
|
|
+ };
|
|
|
+ poly2.regions.push(
|
|
|
+ // @ts-ignore
|
|
|
+ SMathUtil.transferToArray(this.cutItem.outLine)
|
|
|
+ );
|
|
|
+ this.likeSpaceList.map(t => {
|
|
|
+ if (t.selected) {
|
|
|
+ let poly1 = {
|
|
|
+ regions: [],
|
|
|
+ inverted: false
|
|
|
+ };
|
|
|
+ // @ts-ignore
|
|
|
+ poly1.regions = t.pointArr.map(item => {
|
|
|
+ return SMathUtil.transferToArray(item);
|
|
|
+ });
|
|
|
+ console.log(poly1);
|
|
|
+ let intersectObj = intersect(poly1, poly2);
|
|
|
+ if (intersectObj.regions.length) {
|
|
|
+ intersectObj.regions.map((t: number[][]) => {
|
|
|
+ arr.push(SMathUtil.transferToSPoint(t));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ } // Function getIntersect()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 框选区域,选中与之相交的空间
|
|
|
+ *
|
|
|
+ */
|
|
|
+ groupSelectSpace(): void {
|
|
|
+ if (this.rectSelectItem) {
|
|
|
+ let item = this.rectSelectItem;
|
|
|
+ let poly2 = {
|
|
|
+ regions: [
|
|
|
+ [
|
|
|
+ [item.startPoint.x, item.startPoint.y],
|
|
|
+ [item.startPoint.x, item.endPoint.y],
|
|
|
+ [item.endPoint.x, item.endPoint.y],
|
|
|
+ [item.endPoint.x, item.startPoint.y]
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+ inverted: false
|
|
|
+ };
|
|
|
this.spaceList.map(t => {
|
|
|
let poly1 = {
|
|
|
regions: [],
|
|
@@ -500,14 +650,9 @@ export class DivideFloorScene extends FloorScene {
|
|
|
poly1.regions = t.pointArr.map(item => {
|
|
|
return SMathUtil.transferToArray(item);
|
|
|
});
|
|
|
- console.log(poly1);
|
|
|
let intersectObj = intersect(poly1, poly2);
|
|
|
- if (intersectObj.regions.length) {
|
|
|
- t.selected = true;
|
|
|
- } else {
|
|
|
- t.selected = false;
|
|
|
- }
|
|
|
+ t.selected = intersectObj.regions.length ? true : false;
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
+ } // Function groupSelectSpace()
|
|
|
} // Class DivideFloorScene
|