Browse Source

修改空间画法 通过path

haojianlong 5 years ago
parent
commit
750e93988c
9 changed files with 271 additions and 63 deletions
  1. 8 8
      package-lock.json
  2. 3 3
      package.json
  3. 12 5
      src/divideFloorScene.ts
  4. 1 1
      src/items/DoorItem.ts
  5. 30 35
      src/items/SpaceItem.ts
  6. 11 10
      src/items/UserMark.ts
  7. 161 0
      src/items/ZoneItem.ts
  8. 1 1
      src/types/Opt.ts
  9. 44 0
      src/types/Zone.ts

+ 8 - 8
package-lock.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.99",
+    "version": "2.0.145",
     "lockfileVersion": 1,
     "requires": true,
     "dependencies": {
@@ -30,20 +30,20 @@
             "integrity": "sha512-aXtrgDJIILMIYGbe4Dku/kXll/rZZJ1pOsDeB/Di9qAc6GPUJbxSehyXBTE1ndddYlLN6fw/Y1aUxdqu01IYdQ=="
         },
         "@sybotan-web/draw": {
-            "version": "2.1.3",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.1.3.tgz",
-            "integrity": "sha512-6e1SPdfJExUQ/zWC6Qd2VLgRqkhHJdVdMq0NGFGoWFcWMAwGfvbdyUn0IyPEAYEWoktkwjMRL7QKWI1EO3u8Dg==",
+            "version": "2.1.28",
+            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.1.28.tgz",
+            "integrity": "sha512-paBmqETMgvqpoy8jgFwcNrKBkQb200U/WLRJMWSh3Es9ImncoqfwGLmD/RovGOEpm5pcv6r+ibOi/Vrmgq8oyA==",
             "requires": {
                 "@sybotan-web/base": "^2.1.1"
             }
         },
         "@sybotan-web/graphy": {
-            "version": "2.1.1",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/graphy/-/graphy-2.1.1.tgz",
-            "integrity": "sha512-x4m88yGu1W+SH16jPOyuLXGWeIdsA9T6oBFD+KHU5dhDg2bBwMt8jI0ltoNKM/oKfWEkK61G56zgZ2rOCK7p7w==",
+            "version": "2.1.5",
+            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/graphy/-/graphy-2.1.5.tgz",
+            "integrity": "sha512-+RG63losDkTHrRkgPl+6jelO4Z3P7nxyTwML3XkgV6c5fcrDcTwrX5qGMaRTtGy804Whic/wlSfrv0Ot0py0GQ==",
             "requires": {
                 "@sybotan-web/base": "^2.1.1",
-                "@sybotan-web/draw": "^2.1.1"
+                "@sybotan-web/draw": "^2.1.10"
             }
         },
         "@types/eslint-visitor-keys": {

+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.143",
+    "version": "2.0.146",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -32,8 +32,8 @@
     },
     "dependencies": {
         "@sybotan-web/base": "2.1.1",
-        "@sybotan-web/draw": "2.1.3",
-        "@sybotan-web/graphy": "2.1.1",
+        "@sybotan-web/draw": "2.1.28",
+        "@sybotan-web/graphy": "2.1.5",
         "axios": "^0.18.0",
         "pako": "^1.0.10"
     }

+ 12 - 5
src/divideFloorScene.ts

@@ -19,9 +19,7 @@
  */
 
 import { FloorScene } from "./FloorScene";
-import { MarkerItem } from "./items/MarkItem";
-import { SGraphyLineItem, SMouseEvent } from "@sybotan-web/graphy/lib";
-import { Marker } from "./types/Marker";
+import { SMouseEvent } from "@sybotan-web/graphy/lib";
 import { SColor, SPoint, SRect } from "@sybotan-web/draw/lib";
 import { UserMark } from "./items/UserMark";
 
@@ -52,6 +50,15 @@ export class DivideFloorScene extends FloorScene {
         super();
     } // Constructor
 
+    /** 清除切割    */
+    clearUserMark(): void {
+        if (this.grabItem) {
+            this.removeItem(this.grabItem);
+            this.grabItem = null;
+            this.isMarking = false;
+        }
+    } // Function clearUserMark()
+
     /**
      * 点击事件
      *
@@ -69,8 +76,8 @@ export class DivideFloorScene extends FloorScene {
                 this.grabItem = userM;
             }
         } else {
-            super.onClick(event);
+            super.onMouseDown(event);
         }
         return false;
-    } // Function onClick
+    } // Function onClick()
 } // Class DivideFloorScene

+ 1 - 1
src/items/DoorItem.ts

@@ -141,7 +141,7 @@ export class DoorItem extends SGraphyItem {
             painter.pen.color = Opt.doorColor;
             painter.drawLine(0, 0, this.r, 0);
 
-            painter.pen.lineDash = [50, 50];
+            painter.pen.lineDash = [50, 100];
             painter.drawArc(
                 -this.r,
                 -this.r,

+ 30 - 35
src/items/SpaceItem.ts

@@ -19,12 +19,12 @@
  */
 
 import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
-import { SColor, SPainter, SPoint, SRect } from "@sybotan-web/draw/lib";
+import {SColor, SPainter, SPath2D, SPoint, SRect} from "@sybotan-web/draw/lib";
 import { Space } from "../types/Space";
 import { Opt } from "../types/Opt";
 
 /**
- * 空间item
+ * 模型空间item
  *
  * @author  郝建龙
  */
@@ -41,6 +41,8 @@ export class SpaceItem extends SGraphyItem {
     private minY = 0;
     /** Y坐标最大值  */
     private maxY = 0;
+    /** */
+    private path = new SPath2D();
 
     /**
      * 构造函数
@@ -51,34 +53,32 @@ export class SpaceItem extends SGraphyItem {
     constructor(parent: SGraphyItem | null, data: Space) {
         super(parent);
         this.data = data;
-        if (this.data.OutLine.length) {
-            let tempArr = this.data.OutLine;
-            this.minX = tempArr[0][0].X;
-            this.maxX = this.minX;
-            this.minY = -tempArr[0][0].Y;
-            this.maxY = this.minY;
-            // 处理轮廓点数组,同时计算最大最小值
-            this.pointArr = tempArr.map(t => {
-                let tempArr = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
-                    }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
-                return tempArr;
+        let tempArr = this.data.OutLine;
+        this.minX = tempArr[0][0].X;
+        this.maxX = this.minX;
+        this.minY = -tempArr[0][0].Y;
+        this.maxY = this.minY;
+        this.pointArr = tempArr.map(t => {
+            let temp = t.map(it => {
+                let x = it.X,
+                    y = -it.Y;
+                if (x < this.minX) {
+                    this.minX = x;
+                }
+                if (y < this.minY) {
+                    this.minY = y;
+                }
+                if (x > this.maxX) {
+                    this.maxX = x;
+                }
+                if (y > this.maxY) {
+                    this.maxY = y;
+                }
+                return new SPoint(x, y);
             });
-        }
+            this.path.addPolygon(temp);
+            return temp;
+        });
     } // Constructor
 
     /**
@@ -148,13 +148,8 @@ export class SpaceItem extends SGraphyItem {
         if (this.visible) {
             painter.pen.color = SColor.Transparent;
             painter.brush.color = Opt.spaceColor;
-            // if (this.pointArr.length > 1) {
-            //     painter.brush.color = new SColor("#00ff0080");
-            // }
             painter.pen.lineWidth = 200;
-            this.pointArr.map(t => {
-                painter.drawPolygon(t);
-            });
+            painter.drawPath(this.path);
         }
     } // Function onDraw()
 } // Class SpaceItem

+ 11 - 10
src/items/UserMark.ts

@@ -22,24 +22,25 @@ import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
 import { SColor, SPainter, SPoint, SRect } from "@sybotan-web/draw/lib";
 
 /**
- * 标志item
+ * 用户标记item
  *
  * @author  郝建龙
  */
 export class UserMark extends SGraphyItem {
-    /** 标志宽度 */
-    private width: number = 10;
-    /** 标志高度 */
-    private height: number = 10;
-    //轮廓线坐标
+    /** 标记宽度    */
+    private width: number = 20;
+    /** 标记高度    */
+    private height: number = 20;
+    /** 轮廓线坐标  */
     outLine: SPoint[] = [];
-    /** 是否闭合 */
+    /** 是否闭合    */
     closeFlag = false;
+
     /**
      * 构造函数
      *
      * @param parent    指向父对象
-     * @param data      标数据
+     * @param data      标数据
      */
     constructor(parent: SGraphyItem | null, data: SPoint) {
         super(parent);
@@ -117,10 +118,10 @@ export class UserMark extends SGraphyItem {
      */
     onDraw(painter: SPainter, rect?: SRect): void {
         if (this.visible) {
-            painter.pen.color = new SColor("#00ff00");
+            painter.pen.color = new SColor("#ff0000");
             painter.pen.lineWidth = 2;
             if (this.closeFlag) {
-                painter.brush.color = new SColor("#00ff00");
+                painter.brush.color = new SColor("#ff0000");
             } else {
                 painter.brush.color = new SColor("#ffffff80");
             }

+ 161 - 0
src/items/ZoneItem.ts

@@ -0,0 +1,161 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
+import { SColor, SPainter, SPoint, SRect } from "@sybotan-web/draw/lib";
+import { Space } from "../types/Space";
+import { Opt } from "../types/Opt";
+import { Zone } from "../types/Zone";
+
+/**
+ * 业务空间item
+ *
+ * @author  郝建龙
+ */
+export class ZoneItem extends SGraphyItem {
+    /** 空间所有数据  */
+    data: Zone;
+    /** 空间轮廓线坐标list  */
+    private readonly pointArr: SPoint[][] = [];
+    /** X坐标最小值  */
+    private minX = 0;
+    /** X坐标最大值  */
+    private maxX = 0;
+    /** Y坐标最小值  */
+    private minY = 0;
+    /** Y坐标最大值  */
+    private maxY = 0;
+
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      空间数据
+     */
+    constructor(parent: SGraphyItem | null, data: Space) {
+        super(parent);
+        this.data = data;
+        if (this.data.OutLine.length) {
+            let tempArr = this.data.OutLine;
+            this.minX = tempArr[0][0].X;
+            this.maxX = this.minX;
+            this.minY = -tempArr[0][0].Y;
+            this.maxY = this.minY;
+            // 处理轮廓点数组,同时计算最大最小值
+            this.pointArr = tempArr.map(t => {
+                let tempArr = t.map(it => {
+                    let x = it.X,
+                        y = -it.Y;
+                    if (x < this.minX) {
+                        this.minX = x;
+                    }
+                    if (y < this.minY) {
+                        this.minY = y;
+                    }
+                    if (x > this.maxX) {
+                        this.maxX = x;
+                    }
+                    if (y > this.maxY) {
+                        this.maxY = y;
+                    }
+                    return new SPoint(x, y);
+                });
+                return tempArr;
+            });
+        }
+    } // Constructor
+
+    /**
+     * Item对象边界区域
+     *
+     * @return SRect
+     */
+    boundingRect(): SRect {
+        return new SRect(
+            this.minX,
+            this.minY,
+            this.maxX - this.minX,
+            this.maxY - this.minY
+        );
+    } // Function boundingRect()
+
+    /**
+     * 判断点是否在区域内
+     *
+     * @param x
+     * @param y
+     */
+    contains(x: number, y: number): boolean {
+        if (this.data.OutLine.length) {
+            let nCross = 0,
+                point = [x, y],
+                APoints = this.data.OutLine[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++;
+                            }
+                        }
+                    }
+                }
+                p1 = p2;
+            }
+            return nCross % 2 === 1;
+        }
+        return false;
+    } // Function contains()
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter       painter对象
+     * @param   rect          绘制区域
+     */
+    onDraw(painter: SPainter, rect?: SRect): void {
+        if (this.visible) {
+            painter.pen.color = SColor.Transparent;
+            painter.brush.color = Opt.spaceColor;
+            // if (this.pointArr.length > 1) {
+            //     painter.brush.color = new SColor("#00ff0080");
+            // }
+            painter.pen.lineWidth = 200;
+            this.pointArr.map(t => {
+                painter.drawPolygon(t);
+            });
+        }
+    } // Function onDraw()
+} // Class ZoneItem

+ 1 - 1
src/types/Opt.ts

@@ -33,7 +33,7 @@ export class Opt {
     /** 虚拟墙颜色 */
     static virtualWallColor = SColor.Black;
     /** 空间颜色 */
-    static spaceColor = new SColor("#cbe5ff");
+    static spaceColor = new SColor("#f1fffd");
     /** 门颜色 */
     static doorColor = new SColor("#f5b36f");
     /** 窗户颜色 */

+ 44 - 0
src/types/Zone.ts

@@ -0,0 +1,44 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { Point } from "./Point";
+import { Place } from "./Place";
+
+/**
+ * 空间item接口
+ *
+ * @author  郝建龙
+ */
+export interface Zone {
+    /** 轮廓线段    */
+    BoundarySegments: string[];
+    /** 位置  */
+    Location: Place;
+    /** 模型id(外键)    */
+    ModelId: string;
+    /** 名称  */
+    Name: string;
+    /** 轮廓线  */
+    OutLine: Point[][];
+    /** 对应Revit模型id */
+    SourceId: string;
+    /** 补充信息    */
+    Tag: string;
+} // Interface Space