|
@@ -18,13 +18,207 @@
|
|
|
* ********************************************************************************************************************
|
|
|
*/
|
|
|
|
|
|
-import { FloorScene } from "./FloorScene";
|
|
|
+import { ZoneScene } from "./ZoneScene";
|
|
|
+import { RelationItem } from "./items/RelationItem";
|
|
|
+import { SMouseEvent } from "@saga-web/base/lib";
|
|
|
+import { SLine, SPoint } from "@saga-web/draw/lib";
|
|
|
+import { SMathUtil } from "./utils/SMathUtil";
|
|
|
+import { ZoneItem } from "./index";
|
|
|
+import { RelationPoint } from "./types/RelationPoint";
|
|
|
|
|
|
/**
|
|
|
* 空间关系图
|
|
|
*
|
|
|
* @author 郝建龙
|
|
|
*/
|
|
|
-export class RelationScene extends FloorScene {
|
|
|
+export class RelationScene extends ZoneScene {
|
|
|
+ /** 关系点位list */
|
|
|
+ relationList: RelationItem[] = [];
|
|
|
+ /** 创建关系点位标识 */
|
|
|
+ private _createRelateFlag: boolean = false;
|
|
|
+ /** 当前删除的item */
|
|
|
+ private curRemoveItem: RelationItem | null = null;
|
|
|
+ get createRelateFlag(): boolean {
|
|
|
+ return this._createRelateFlag;
|
|
|
+ } // Get createRelateFlag
|
|
|
+ set createRelateFlag(value: boolean) {
|
|
|
+ this._createRelateFlag = value;
|
|
|
+ } // Set createRelateFlag
|
|
|
+ /** 是否开启吸附 */
|
|
|
+ private _isAbsorbing: boolean = false;
|
|
|
+ get isAbsorbing(): boolean {
|
|
|
+ return this._isAbsorbing;
|
|
|
+ } // Get isAbsorbing
|
|
|
+ set isAbsorbing(v: boolean) {
|
|
|
+ this._isAbsorbing = v;
|
|
|
+ } // Set isAbsorbing
|
|
|
+ private _removeRelationFlag: boolean = false;
|
|
|
+ get removeRelationFlag(): boolean {
|
|
|
+ return this._removeRelationFlag;
|
|
|
+ } // Get removeRelationFlag
|
|
|
+ set removeRelationFlag(value: boolean) {
|
|
|
+ this._removeRelationFlag = value;
|
|
|
+ } // Set removeRelationFlag
|
|
|
|
|
|
+ /** 当前关系item */
|
|
|
+ curRelate: RelationItem | null = null;
|
|
|
+ /** 当前业务空间 */
|
|
|
+ curZone: ZoneItem | null = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标按下事件
|
|
|
+ *
|
|
|
+ * @param event 保存事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ if (this.createRelateFlag && event.buttons == 1) {
|
|
|
+ let zone = this.isInZone(event.x, event.y);
|
|
|
+ if (!zone) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (this.isAbsorbing) {
|
|
|
+ event = this.absordPoint(event);
|
|
|
+ }
|
|
|
+ if (this.curRelate) {
|
|
|
+ // @ts-ignore
|
|
|
+ this.curRelate.endZone = zone.data.RoomID;
|
|
|
+ this.curRelate.onMouseDown(event);
|
|
|
+ } else {
|
|
|
+ let p = new SPoint(event.x, event.y);
|
|
|
+ let rela = new RelationItem(null, p);
|
|
|
+ // @ts-ignore
|
|
|
+ rela.startZone = zone.data.RoomID;
|
|
|
+ this.relationList.push(rela);
|
|
|
+ this.curRelate = rela;
|
|
|
+ this.addItem(rela);
|
|
|
+ }
|
|
|
+ } else if (this.removeRelationFlag && event.buttons == 1) {
|
|
|
+ this.removeSingleRelation(event);
|
|
|
+ } else {
|
|
|
+ super.onMouseDown(event);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } // Function onMouseDown()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标抬起事件
|
|
|
+ *
|
|
|
+ * @param event 保存事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseUp(event: SMouseEvent): boolean {
|
|
|
+ super.onMouseUp(event);
|
|
|
+ return false;
|
|
|
+ } // Function onMouseUp()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标移动事件
|
|
|
+ *
|
|
|
+ * @param event 鼠标事件对象
|
|
|
+ */
|
|
|
+ onMouseMove(event: SMouseEvent): boolean {
|
|
|
+ if (this.isAbsorbing) {
|
|
|
+ event = this.absordPoint(event);
|
|
|
+ }
|
|
|
+ if (this.curRelate) {
|
|
|
+ this.curRelate.onMouseMove(event);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ super.onMouseMove(event);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } // Function onMouseMove()
|
|
|
+
|
|
|
+ /** */
|
|
|
+ isInZone(x: number, y: number): ZoneItem | boolean {
|
|
|
+ for (let i = 0; i < this.zoneList.length; i++) {
|
|
|
+ if (this.zoneList[i].contains(x, y)) {
|
|
|
+ return this.zoneList[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 注册鼠标点击事件
|
|
|
+ *
|
|
|
+ * @param _this 接收者
|
|
|
+ * @param fn 处理函数
|
|
|
+ */
|
|
|
+ click(_this: RelationScene, fn: Function): void {
|
|
|
+ this.zoneList.forEach((t): void => {
|
|
|
+ t.connect("click", _this, fn);
|
|
|
+ });
|
|
|
+ } // Function click()
|
|
|
+ /** 吸附 */
|
|
|
+ absordPoint(event: SMouseEvent): SMouseEvent {
|
|
|
+ let len = 20;
|
|
|
+ if (this.view) {
|
|
|
+ len = 20 / this.view.scale;
|
|
|
+ }
|
|
|
+ for (let i = 0; i < this.relationList.length; i++) {
|
|
|
+ for (let j = 0; j < this.relationList[i].outLine.length; j++) {
|
|
|
+ let p1 = this.relationList[i].outLine[j];
|
|
|
+ let minDis = SMathUtil.pointDistance(
|
|
|
+ event.x,
|
|
|
+ event.y,
|
|
|
+ p1.x,
|
|
|
+ p1.y
|
|
|
+ );
|
|
|
+ if (minDis < len) {
|
|
|
+ len = minDis;
|
|
|
+ event.x = p1.x;
|
|
|
+ event.y = p1.y;
|
|
|
+ return event;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return event;
|
|
|
+ } // Function absordPoint()
|
|
|
+
|
|
|
+ /** 删除关系 */
|
|
|
+ removeSingleRelation(event: SMouseEvent) {
|
|
|
+ let len = 20;
|
|
|
+ if (this.view) {
|
|
|
+ len = 20 / this.view.scale;
|
|
|
+ }
|
|
|
+ let point = new SPoint(event.x, event.y);
|
|
|
+ this.curRemoveItem = null;
|
|
|
+ for (let i = 0; i < this.relationList.length; i++) {
|
|
|
+ let curItem = this.relationList[i];
|
|
|
+ let dis = SMathUtil.pointToLine(
|
|
|
+ point,
|
|
|
+ new SLine(curItem.startPoint, curItem.lastPoint)
|
|
|
+ );
|
|
|
+ if (dis.MinDis < len) {
|
|
|
+ this.curRemoveItem = curItem;
|
|
|
+ this.removeItem(curItem);
|
|
|
+ this.relationList.splice(i, 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(this.curRemoveItem);
|
|
|
+ } // Function reRelationItem()
|
|
|
+
|
|
|
+ /** 清除所有关系点位 */
|
|
|
+ removeAllRelation() {
|
|
|
+ this.relationList.forEach((t: RelationItem): void => {
|
|
|
+ this.removeItem(t);
|
|
|
+ });
|
|
|
+ this.relationList = [];
|
|
|
+ } // Function removeAllRelation()
|
|
|
+
|
|
|
+ /** 添加所有关系点位 */
|
|
|
+ addAllRelaPoint(relations: RelationPoint[]) {
|
|
|
+ relations.forEach((t: RelationPoint): void => {
|
|
|
+ this.addRelaPoint(t);
|
|
|
+ });
|
|
|
+ } // Function addAllRelaPoint()
|
|
|
+ /** 添加关系点位*/
|
|
|
+ addRelaPoint(r: RelationPoint) {
|
|
|
+ let item = new RelationItem(null, r);
|
|
|
+ this.relationList.push(item);
|
|
|
+ this.addItem(item);
|
|
|
+ }
|
|
|
} // Class RelationScene
|