Преглед изворни кода

添加 空间click事件 获取选中的空间

haojianlong пре 5 година
родитељ
комит
da3a5f1576
7 измењених фајлова са 131 додато и 49 уклоњено
  1. 8 8
      package-lock.json
  2. 3 3
      package.json
  3. 28 2
      src/FloorScene.ts
  4. 43 0
      src/divideFloorScene.ts
  5. 0 1
      src/items/SceneMarkItem.ts
  6. 18 5
      src/items/SpaceItem.ts
  7. 31 30
      src/items/ZoneItem.ts

+ 8 - 8
package-lock.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.191",
+    "version": "2.0.206",
     "lockfileVersion": 1,
     "requires": true,
     "dependencies": {
@@ -30,20 +30,20 @@
             "integrity": "sha512-sBFWAn/cqOT9P4r+CSgj381QbLp9XavDkKNRRm9iQZbMv2+/AkYcXcmDhI7wJIJNwz8kR6wjRvMBeUEpFIvqnA=="
         },
         "@sybotan-web/draw": {
-            "version": "2.1.47",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.1.47.tgz",
-            "integrity": "sha512-YnSczTJg2pNmGTHqkfC6LXdZiNavHUhFjfi2sYDqWpNcKQPTBmG9p9Rkf0ldyi2HvShAID/H0eSCOQB6UpmxSA==",
+            "version": "2.1.52",
+            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.1.52.tgz",
+            "integrity": "sha512-opzaLit9BcYFrf4kMyyR104UQnnQlMFjPeVLX00vTs/Ks2ip+Xr24cSTGXXuoM7PfqiPdvVsGB60LNmkQ1PHIA==",
             "requires": {
                 "@sybotan-web/base": "^2.1.2"
             }
         },
         "@sybotan-web/graphy": {
-            "version": "2.1.13",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/graphy/-/graphy-2.1.13.tgz",
-            "integrity": "sha512-yb230gF0BsTx86ZmZf3w0plHVNwghABwK6h1F2Sh+UwlAjzSVqk8YHQ8YMcQPPpc+lCY3NDsBJlDMY0hIZkTJQ==",
+            "version": "2.1.16",
+            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/graphy/-/graphy-2.1.16.tgz",
+            "integrity": "sha512-3U8JwV1U+2BRPqtVyUVl0sON13CaeKpwgqmemCILQ1z1XtCySVUNCQD+GNMoMbiH7dWGlEe4LMJeA5EyoYV76g==",
             "requires": {
                 "@sybotan-web/base": "^2.1.2",
-                "@sybotan-web/draw": "^2.1.39"
+                "@sybotan-web/draw": "^2.1.51"
             }
         },
         "@types/eslint-visitor-keys": {

+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.196",
+    "version": "2.0.211",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -32,8 +32,8 @@
     },
     "dependencies": {
         "@sybotan-web/base": "2.1.2",
-        "@sybotan-web/draw": "2.1.47",
-        "@sybotan-web/graphy": "2.1.13",
+        "@sybotan-web/draw": "2.1.52",
+        "@sybotan-web/graphy": "2.1.16",
         "axios": "^0.18.0",
         "pako": "^1.0.10"
     }

+ 28 - 2
src/FloorScene.ts

@@ -206,8 +206,8 @@ export class FloorScene extends SGraphyScene {
                 //解压数据
                 let base64Data = btoa(binaryString);
                 let unGzipData = that.unzipBase64(base64Data);
-                that.data = unGzipData.EntityList[0].Elements;
-                resolve(unGzipData);
+                that.data = unGzipData.entityList[0].Elements;
+                resolve(that.data);
             };
         });
     } // Function unzip
@@ -388,4 +388,30 @@ export class FloorScene extends SGraphyScene {
         let binaryString = pako.gzip(escape(str), { to: "string" });
         return binaryString;
     } // Function zip
+
+    /**
+     *  获取选中空间的列表
+     *
+     *  @return  被选中的空间列表
+     */
+    getSelectedSpaces(): SpaceItem[] {
+        let arr: SpaceItem[] = [];
+        this.spaceList.map(sp => {
+            if (sp.selectable) {
+                arr.push(sp);
+            }
+        });
+        return arr;
+    } // Function getSelectedSpaces
+
+    /**
+     *  清除选中的空间
+     *
+     */
+    clearSelectedSpaces(): void {
+        this.spaceList.map(sp => {
+            sp.selectable = false;
+            return sp;
+        });
+    } // Function clearSelectedSpaces
 } // Class FloorScene

+ 43 - 0
src/divideFloorScene.ts

@@ -22,6 +22,8 @@ import { FloorScene } from "./FloorScene";
 import { SMouseEvent } from "@sybotan-web/graphy/lib";
 import { SColor, SPoint, SRect } from "@sybotan-web/draw/lib";
 import { SceneMarkItem } from "./items/SceneMarkItem";
+import { ZoneItem } from "./items/ZoneItem";
+import { Zone } from "./types/Zone";
 
 /**
  * 划分业务空间
@@ -41,6 +43,9 @@ export class DivideFloorScene extends FloorScene {
         this._isMarking = v;
     } // Set isMarking
 
+    /** 业务空间list   */
+    zoneList: ZoneItem[] = [];
+
     /**
      * 构造函数
      *
@@ -111,4 +116,42 @@ export class DivideFloorScene extends FloorScene {
             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;
+        this.zoneList.push(item);
+        this.addItem(item);
+    } // Function addZone
 } // Class DivideFloorScene

+ 0 - 1
src/items/SceneMarkItem.ts

@@ -103,7 +103,6 @@ export class SceneMarkItem extends SGraphyItem {
     onMouseMove(event: SMouseEvent): boolean {
         if (!this.closeFlag) {
             this.lastPoint = new SPoint(event.x, event.y);
-            console.log(this.lastPoint);
         }
         return true;
     } // Function onMouseMove()

+ 18 - 5
src/items/SpaceItem.ts

@@ -50,7 +50,8 @@ export class SpaceItem extends SGraphyItem {
     private maxY = 0;
     /** */
     private path = new SPath2D();
-
+    /** */
+    private selectColor = new SColor("#1abc9c");
     /**
      * 构造函数
      *
@@ -105,6 +106,18 @@ export class SpaceItem extends SGraphyItem {
     } // Function boundingRect()
 
     /**
+     * 鼠标单击事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onClick(event: SMouseEvent): boolean {
+        this.selectable = !this.selectable;
+        this.$emit("click", event);
+        return true;
+    } // Function onClick()
+
+    /**
      * 判断点是否在区域内
      *
      * @param x
@@ -115,9 +128,7 @@ export class SpaceItem extends SGraphyItem {
         if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
             return false;
         }
-        if (arr.length == 1) {
-            return true;
-        }
+
         for (let i = 1; i < arr.length; i++) {
             if (SPolygonUtil.pointIn(x, y, arr[i])) {
                 return false;
@@ -134,7 +145,9 @@ export class SpaceItem extends SGraphyItem {
      */
     onDraw(painter: SPainter, rect?: SRect): void {
         painter.pen.color = SColor.Transparent;
-        painter.brush.color = Opt.spaceColor;
+        painter.brush.color = this.selectable
+            ? this.selectColor
+            : Opt.spaceColor;
         painter.pen.lineWidth = 200;
         painter.drawPath(this.path);
 

+ 31 - 30
src/items/ZoneItem.ts

@@ -24,6 +24,7 @@ import {
     SPainter,
     SPath2D,
     SPoint,
+    SPolygonUtil,
     SRect
 } from "@sybotan-web/draw/lib";
 import { Opt } from "../types/Opt";
@@ -109,6 +110,19 @@ export class ZoneItem extends SGraphyItem {
         );
     } // Function boundingRect()
 
+
+    /**
+     * 鼠标单击事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onClick(event: SMouseEvent): boolean {
+        this.selectable = !this.selectable;
+        this.$emit("click", event);
+        return true;
+    } // Function onClick()
+
     /**
      * 判断点是否在区域内
      *
@@ -116,38 +130,25 @@ export class ZoneItem extends SGraphyItem {
      * @param y
      */
     contains(x: number, y: number): boolean {
-        if (this.data.OutLine.length) {
-            let nCross = 0,
-                point = [x, y],
-                APoints = this.data.OutLine[0][0],
-                length = APoints.length,
-                p1,
-                p2,
-                i,
-                xinters;
-            p1 = APoints[0];
-            for (i = 1; i <= length; i++) {
-                p2 = APoints[i % length];
-                if (
-                    point[0] > Math.min(p1.X, p2.X) &&
-                    point[0] <= Math.max(p1.X, p2.X)
-                ) {
-                    if (point[1] <= Math.max(p1.Y, p2.Y)) {
-                        if (p1.X != p2.X) {
-                            //计算位置信息
-                            xinters =
-                                ((point[0] - p1.X) * (p2.Y - p1.Y)) /
-                                    (p2.X - p1.X) +
-                                p1.Y;
-                            if (p1.Y == p2.Y || point[1] <= xinters) {
-                                nCross++;
-                            }
-                        }
-                    }
+        for (let j = 0; j < this.pointArr.length; j++) {
+            let arr = this.pointArr[j];
+            if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
+                continue;
+            }
+            if (arr.length == 1) {
+                return true;
+            }
+            let flag = false;
+            for (let i = 1; i < arr.length; i++) {
+                if (SPolygonUtil.pointIn(x, y, arr[i])) {
+                    flag = true;
+                    break;
                 }
-                p1 = p2;
             }
-            return nCross % 2 === 1;
+            if (flag) {
+                continue;
+            }
+            return true;
         }
         return false;
     } // Function contains()