فهرست منبع

配合工具 添加业务空间邻接关系;业务空间场景提出;2.0.522

haojianlong 5 سال پیش
والد
کامیت
6a65770d10
8فایلهای تغییر یافته به همراه491 افزوده شده و 97 حذف شده
  1. 1 1
      package.json
  2. 2 94
      src/DivideFloorScene.ts
  3. 196 2
      src/RelationScene.ts
  4. 114 0
      src/ZoneScene.ts
  5. 2 0
      src/index.ts
  6. 137 0
      src/items/RelationItem.ts
  7. 2 0
      src/types/ItemOrder.ts
  8. 37 0
      src/types/RelationPoint.ts

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/cad-engine",
-    "version": "2.0.496",
+    "version": "2.0.522",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 2 - 94
src/DivideFloorScene.ts

@@ -21,8 +21,6 @@
 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 { HighlightItem } from "./items/HighlightItem";
 import { SMathUtil } from "./utils/SMathUtil";
@@ -37,13 +35,14 @@ import { ShadeItem } from "./items/ShadeItem";
 import { Point } from "./types/Point";
 import { LikeSpaceItem } from "./items/LikeSpaceItem";
 import { Poly } from "./types/Poly";
+import { ZoneScene } from "./ZoneScene";
 
 /**
  * 划分业务空间
  *
  * @author 郝建龙
  */
-export class DivideFloorScene extends FloorScene {
+export class DivideFloorScene extends ZoneScene {
     /** 是否开启用户标记     */
     _isMarking: boolean = false;
     get isMarking(): boolean {
@@ -57,8 +56,6 @@ export class DivideFloorScene extends FloorScene {
     } // Set isMarking
     /** 蒙版item  */
     sceneMark: SceneMarkItem | null = null;
-    /** 业务空间list   */
-    zoneList: ZoneItem[] = [];
     /** 遮罩List  */
     shadeList: ShadeItem[] = [];
     /** 划分item  */
@@ -69,26 +66,6 @@ export class DivideFloorScene extends FloorScene {
     highLight: HighlightItem | null = null;
     /** 是否开启切分  */
     isCutting: boolean = false;
-    /** 业务空间是否可选    */
-    _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): ZoneItem => {
-                t.selectable = this._isZoneSelectable;
-                if (!t.selectable) {
-                    t.selected = false;
-                }
-                return t;
-            }
-        );
-    } // Set isZoneSelectable
 
     /** 是否开启吸附  */
     private _isAbsorbing: boolean = false;
@@ -111,14 +88,6 @@ export class DivideFloorScene extends FloorScene {
     } // Set isRectSelection
 
     /**
-     * 构造函数
-     *
-     */
-    constructor() {
-        super();
-    } // Constructor
-
-    /**
      * 添加轮廓线
      *
      * @param   data
@@ -396,67 +365,6 @@ export class DivideFloorScene extends FloorScene {
     } // Function click()
 
     /**
-     *  添加业务空间到scene 中
-     *
-     *  @param  zone   业务空间list
-     */
-    addZoneList(zone: Zone[]): void {
-        zone.forEach((t): void => {
-            this.addZone(t);
-        });
-    } // Function addZoneList()
-
-    /**
-     *  添加业务空间到scene 中
-     *
-     *  @param  zone   业务空间
-     */
-    addZone(zone: Zone): void {
-        let item = new ZoneItem(null, zone);
-        item.selectable = this.isZoneSelectable;
-        this.zoneList.push(item);
-        this.addItem(item);
-    } // Function addZone()
-
-    /**
-     *  清空选中的业务空间
-     *
-     */
-    clearZoneSelection(): void {
-        this.zoneList.map(
-            (t): ZoneItem => {
-                t.selected = false;
-                return t;
-            }
-        );
-    } // Function clearZoneSelection()
-
-    /**
-     * 删除所有业务空间
-     */
-    removeAllZone(): void {
-        if (this.zoneList.length) {
-            this.zoneList.forEach((t): void => {
-                this.removeItem(t);
-            });
-            this.zoneList = [];
-        }
-    } // Function removeAllZone()
-
-    /**
-     * 获取选中的业务空间
-     */
-    getSelectedZone(): ZoneItem[] {
-        let arr: ZoneItem[] = [];
-        this.zoneList.forEach((t): void => {
-            if (t.selected) {
-                arr.push(t);
-            }
-        });
-        return arr;
-    } // Function getSelectedZone()
-
-    /**
      *  吸附空间
      *
      *  @param  event   鼠标事件对象

+ 196 - 2
src/RelationScene.ts

@@ -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

+ 114 - 0
src/ZoneScene.ts

@@ -0,0 +1,114 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { FloorScene } from "./FloorScene";
+import { ZoneItem } from "./items/ZoneItem";
+import { Zone } from "./types/Zone";
+
+/**
+ * 业务空间
+ *
+ * @author 郝建龙
+ */
+export class ZoneScene extends FloorScene {
+    /** 业务空间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): ZoneItem => {
+                t.selectable = this._isZoneSelectable;
+                if (!t.selectable) {
+                    t.selected = false;
+                }
+                return t;
+            }
+        );
+    } // Set isZoneSelectable
+
+    /**
+     *  添加业务空间到scene 中
+     *
+     *  @param  zone   业务空间list
+     */
+    addZoneList(zone: Zone[]): void {
+        zone.forEach((t): void => {
+            this.addZone(t);
+        });
+    } // Function addZoneList()
+
+    /**
+     *  添加业务空间到scene 中
+     *
+     *  @param  zone   业务空间
+     */
+    addZone(zone: Zone): void {
+        let item = new ZoneItem(null, zone);
+        item.selectable = this.isZoneSelectable;
+        this.zoneList.push(item);
+        this.addItem(item);
+    } // Function addZone()
+
+    /**
+     *  清空选中的业务空间
+     *
+     */
+    clearZoneSelection(): void {
+        this.zoneList.map(
+            (t): ZoneItem => {
+                t.selected = false;
+                return t;
+            }
+        );
+    } // Function clearZoneSelection()
+
+    /**
+     * 删除所有业务空间
+     */
+    removeAllZone(): void {
+        if (this.zoneList.length) {
+            this.zoneList.forEach((t): void => {
+                this.removeItem(t);
+            });
+            this.zoneList = [];
+        }
+    } // Function removeAllZone()
+
+    /**
+     * 获取选中的业务空间
+     */
+    getSelectedZone(): ZoneItem[] {
+        let arr: ZoneItem[] = [];
+        this.zoneList.forEach((t): void => {
+            if (t.selected) {
+                arr.push(t);
+            }
+        });
+        return arr;
+    } // Function getSelectedZone()
+} // Class ZoneScene

+ 2 - 0
src/index.ts

@@ -16,9 +16,11 @@ import { ShadeItem } from "./items/ShadeItem";
 import { RectSelectItem } from "./items/RectSelectItem";
 import { LikeSpaceItem } from "./items/LikeSpaceItem";
 import { RelationScene } from "./RelationScene";
+import { ZoneScene } from "./ZoneScene";
 
 export {
     FloorScene,
+    ZoneScene,
     LocationPointScene,
     DivideFloorScene,
     FloorView,

+ 137 - 0
src/items/RelationItem.ts

@@ -0,0 +1,137 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { Opt } from "../types/Opt";
+import { SGraphyItem } from "@saga-web/graphy/lib";
+import { SColor, SPainter, SPoint } from "@saga-web/draw/lib";
+import { SMouseEvent } from "@saga-web/base/lib";
+import { ItemOrder } from "../types/ItemOrder";
+import { ZoneItem } from "./ZoneItem";
+import { RelationPoint } from "../types/RelationPoint";
+
+/**
+ * 蒙版item
+ *
+ * @author  郝建龙
+ */
+export class RelationItem extends SGraphyItem {
+    /** 是否闭合    */
+    closeFlag = false;
+    /** 起点  */
+    readonly startPoint = new SPoint();
+    /** 起始业务空间  */
+    startZone: string = "";
+    /** 鼠标移动点  */
+    readonly lastPoint = new SPoint();
+    /** 结束业务空间  */
+    endZone: string = "";
+    /** 点坐标 */
+    outLine: SPoint[] = [];
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data
+     */
+    constructor(parent: SGraphyItem | null, data: SPoint); // Constructor
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      蒙版轮廓线数据
+     */
+    constructor(parent: SGraphyItem | null, data: RelationPoint); // Constructor
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data
+     */
+    constructor(parent: SGraphyItem | null, data: SPoint | RelationPoint) {
+        super(parent);
+        if (data instanceof SPoint) {
+            this.startPoint = data;
+            this.lastPoint.x = data.x;
+            this.lastPoint.y = data.y;
+        } else {
+            this.startZone = data.SpaceIdOne;
+            this.endZone = data.SpaceIdTwo;
+            this.startPoint = data.LocationOne;
+            this.lastPoint = data.LocationTwo;
+            this.closeFlag = true;
+        }
+        this.outLine.push(this.startPoint, this.lastPoint);
+        this.zOrder = ItemOrder.RelationOrder;
+    } // Constructor
+
+    /**
+     * 鼠标按下事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseDown(event: SMouseEvent): boolean {
+        if (!this.closeFlag && event.buttons == 1) {
+            this.closeFlag = true;
+            this.outLine.push(this.lastPoint);
+            if (this.scene) {
+                // @ts-ignore
+                this.scene.curRelate = null;
+            }
+        }
+        return true;
+    } // Function onMouseDown()
+
+    /**
+     * 鼠标移动事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseMove(event: SMouseEvent): boolean {
+        if (!this.closeFlag) {
+            this.lastPoint.x = event.x;
+            this.lastPoint.y = event.y;
+        }
+        return true;
+    } // Function onMouseMove()
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter       painter对象
+     */
+    onDraw(painter: SPainter): void {
+        painter.pen.color = SColor.Red;
+        painter.brush.color = SColor.Red;
+        painter.pen.lineWidth = painter.toPx(5);
+        painter.drawLine(this.startPoint, this.lastPoint);
+        painter.pen.color = SColor.Transparent;
+        painter.drawCircle(
+            this.startPoint.x,
+            this.startPoint.y,
+            painter.toPx(8)
+        );
+        painter.drawCircle(this.lastPoint.x, this.lastPoint.y, painter.toPx(8));
+    } // Function onDraw()
+} // Class RelationItem

+ 2 - 0
src/types/ItemOrder.ts

@@ -48,6 +48,8 @@ export class ItemOrder {
     static rectSelectOrder = 999;
     /** 高亮对象层级 */
     static highLightOrder = 9999;
+    /** 业务空间关系点位层级 */
+    static RelationOrder = 9999;
     /** 蒙版层级 */
     static sceneMarkOrder = Number.MAX_SAFE_INTEGER;
 } // Interface ItemOrder

+ 37 - 0
src/types/RelationPoint.ts

@@ -0,0 +1,37 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { SPoint } from "@saga-web/draw/lib";
+
+/**
+ * 空间关系点接口
+ *
+ * @author  郝建龙
+ */
+export interface RelationPoint {
+    /** 位置1  */
+    LocationOne: SPoint;
+    /** 位置2    */
+    LocationTwo: SPoint;
+    /** 业务空间1  */
+    SpaceIdOne: string;
+    /** 业务空间2  */
+    SpaceIdTwo: string;
+} // interface RelationPoint