Browse Source

添加图形切割方法

haojianlong 5 years ago
parent
commit
1bffaa410c
7 changed files with 310 additions and 56 deletions
  1. 4 4
      package-lock.json
  2. 2 2
      package.json
  3. 76 0
      src/divideFloorScene.ts
  4. 2 1
      src/index.ts
  5. 49 13
      src/items/DoorItem.ts
  6. 44 36
      src/items/SpaceItem.ts
  7. 133 0
      src/items/UserMark.ts

+ 4 - 4
package-lock.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "cad-engine",
     "name": "cad-engine",
-    "version": "2.0.59",
+    "version": "2.0.99",
     "lockfileVersion": 1,
     "lockfileVersion": 1,
     "requires": true,
     "requires": true,
     "dependencies": {
     "dependencies": {
@@ -30,9 +30,9 @@
             "integrity": "sha512-aXtrgDJIILMIYGbe4Dku/kXll/rZZJ1pOsDeB/Di9qAc6GPUJbxSehyXBTE1ndddYlLN6fw/Y1aUxdqu01IYdQ=="
             "integrity": "sha512-aXtrgDJIILMIYGbe4Dku/kXll/rZZJ1pOsDeB/Di9qAc6GPUJbxSehyXBTE1ndddYlLN6fw/Y1aUxdqu01IYdQ=="
         },
         },
         "@sybotan-web/draw": {
         "@sybotan-web/draw": {
-            "version": "2.1.1",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.1.1.tgz",
-            "integrity": "sha512-N6D7I7KFIqe6wI2sleD5dtMstSwIsazk8sD6dpVe5jYccOFUriCgF6OMk1rhwFarDHUZ7Nt9mFfJNXgif8l15w==",
+            "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==",
             "requires": {
             "requires": {
                 "@sybotan-web/base": "^2.1.1"
                 "@sybotan-web/base": "^2.1.1"
             }
             }

+ 2 - 2
package.json

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

+ 76 - 0
src/divideFloorScene.ts

@@ -0,0 +1,76 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { FloorScene } from "./FloorScene";
+import { MarkerItem } from "./items/MarkItem";
+import { SGraphyLineItem, SMouseEvent } from "@sybotan-web/graphy/lib";
+import { Marker } from "./types/Marker";
+import { SColor, SPoint, SRect } from "@sybotan-web/draw/lib";
+import { UserMark } from "./items/UserMark";
+
+/**
+ * 划分业务空间
+ *
+ * @author 郝建龙
+ */
+export class DivideFloorScene extends FloorScene {
+    /** 是否开启用户标记     */
+    _isMarking: boolean = false;
+    get isMarking(): boolean {
+        return this._isMarking;
+    } // Get isMarking
+    set isMarking(v: boolean) {
+        if (this._isMarking === v) {
+            return;
+        }
+        this._isMarking = v;
+    } // Set isMarking
+
+    /**
+     * 构造函数
+     *
+     * @param   data
+     */
+    constructor() {
+        super();
+    } // Constructor
+
+    /**
+     * 点击事件
+     *
+     * @param   event   保存事件参数
+     * @return  boolean
+     */
+    onMouseDown(event: SMouseEvent): boolean {
+        if (this.isMarking) {
+            if (this.grabItem) {
+                this.grabItem.onMouseDown(event);
+            } else {
+                let point = new SPoint(event.x, event.y);
+                let userM = new UserMark(null, point);
+                this.addItem(userM);
+                this.grabItem = userM;
+            }
+        } else {
+            super.onClick(event);
+        }
+        return false;
+    } // Function onClick
+} // Class DivideFloorScene

+ 2 - 1
src/index.ts

@@ -1,4 +1,5 @@
 import { FloorScene } from "./FloorScene";
 import { FloorScene } from "./FloorScene";
 import { LocationPointScene } from "./LocationPointScene";
 import { LocationPointScene } from "./LocationPointScene";
+import { DivideFloorScene } from "./divideFloorScene";
 
 
-export { FloorScene, LocationPointScene };
+export { FloorScene, LocationPointScene, DivideFloorScene };

+ 49 - 13
src/items/DoorItem.ts

@@ -44,6 +44,7 @@ export class DoorItem extends SGraphyItem {
     /** 旋转结束角度 */
     /** 旋转结束角度 */
     private endAng: number = 0;
     private endAng: number = 0;
 
 
+    // number: number = 0;
     /**
     /**
      * 构造函数
      * 构造函数
      *
      *
@@ -61,31 +62,55 @@ export class DoorItem extends SGraphyItem {
             let p1 = this.pointArr[0];
             let p1 = this.pointArr[0];
             let p2 = this.pointArr[1];
             let p2 = this.pointArr[1];
             let fo = Math.atan(
             let fo = Math.atan(
-                this.data.FaceDirection.Y / this.data.FaceDirection.X
+                -this.data.FaceDirection.Y / this.data.FaceDirection.X
             );
             );
             // 两点间距离
             // 两点间距离
             this.r = Math.sqrt(
             this.r = Math.sqrt(
                 Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)
                 Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)
             );
             );
             // 门朝向角度
             // 门朝向角度
-            if (this.data.FaceDirection.X > 0) {
-                this.ang = fo;
-            } else {
-                this.ang = fo + Math.PI;
-            }
-            // this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
+            this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
             // 旋转点
             // 旋转点
-            if (this.data.HandDirection.X > this.data.HandDirection.Y) {
+            if (
+                Math.abs(this.data.HandDirection.X) >
+                Math.abs(this.data.HandDirection.Y)
+            ) {
+                // this.startAng = 0;
+                // this.endAng = Math.PI / 2;
                 if (this.data.HandDirection.X > 0) {
                 if (this.data.HandDirection.X > 0) {
-                    this.p = p1.x > p2.x ? p1 : p2;
+                    if (p1.x > p2.x) {
+                        this.p = p1;
+                        // this.number = 1; //
+                    } else {
+                        this.p = p2;
+                        // this.number = 2;
+                    }
                 } else {
                 } else {
-                    this.p = p1.x < p2.x ? p1 : p2;
+                    if (p1.x < p2.x) {
+                        this.p = p1;
+                        // this.number = 3; //
+                    } else {
+                        this.p = p2;
+                        // this.number = 4; //
+                    }
                 }
                 }
             } else {
             } else {
                 if (this.data.HandDirection.Y > 0) {
                 if (this.data.HandDirection.Y > 0) {
-                    this.p = p1.y > p2.y ? p1 : p2;
+                    if (p1.y > p2.y) {
+                        this.p = p1;
+                        // this.number = 5; //
+                    } else {
+                        this.p = p2;
+                        // this.number = 6;
+                    }
                 } else {
                 } else {
-                    this.p = p1.y < p2.y ? p1 : p2;
+                    if (p1.y < p2.y) {
+                        this.p = p1;
+                        // this.number = 7;
+                    } else {
+                        this.p = p2;
+                        // this.number = 8;
+                    }
                 }
                 }
             }
             }
         }
         }
@@ -102,10 +127,21 @@ export class DoorItem extends SGraphyItem {
             painter.translate(this.p.x, this.p.y);
             painter.translate(this.p.x, this.p.y);
             painter.rotate(this.ang);
             painter.rotate(this.ang);
             painter.pen.lineWidth = 100;
             painter.pen.lineWidth = 100;
+            // let color = [
+            //     "#42b983", //1
+            //     "#4287b9", //2
+            //     "#9742b9", //3
+            //     "#b94242", //4
+            //     "#ffd945", //5
+            //     "#46ff45", //
+            //     "#45f5ff", //
+            //     "#f3f3f3"
+            // ];
+            // painter.pen.color = new SColor(color[this.number - 1]);
             painter.pen.color = Opt.doorColor;
             painter.pen.color = Opt.doorColor;
             painter.drawLine(0, 0, this.r, 0);
             painter.drawLine(0, 0, this.r, 0);
 
 
-            painter.pen.lineDash = [10, 10];
+            painter.pen.lineDash = [50, 50];
             painter.drawArc(
             painter.drawArc(
                 -this.r,
                 -this.r,
                 -this.r,
                 -this.r,

+ 44 - 36
src/items/SpaceItem.ts

@@ -55,24 +55,26 @@ export class SpaceItem extends SGraphyItem {
             let tempArr = this.data.OutLine;
             let tempArr = this.data.OutLine;
             this.minX = tempArr[0][0].X;
             this.minX = tempArr[0][0].X;
             this.maxX = this.minX;
             this.maxX = this.minX;
-            this.minY = tempArr[0][0].Y;
+            this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
             // 处理轮廓点数组,同时计算最大最小值
             // 处理轮廓点数组,同时计算最大最小值
             this.pointArr = tempArr.map(t => {
             this.pointArr = tempArr.map(t => {
                 let tempArr = t.map(it => {
                 let tempArr = t.map(it => {
-                    if (it.X < this.minX) {
-                        this.minX = it.X;
+                    let x = it.X,
+                        y = -it.Y;
+                    if (x < this.minX) {
+                        this.minX = x;
                     }
                     }
-                    if (it.Y < this.minY) {
-                        this.minY = it.Y;
+                    if (y < this.minY) {
+                        this.minY = y;
                     }
                     }
-                    if (it.X > this.maxX) {
-                        this.maxX = it.X;
+                    if (x > this.maxX) {
+                        this.maxX = x;
                     }
                     }
-                    if (it.Y > this.maxY) {
-                        this.maxY = it.Y;
+                    if (y > this.maxY) {
+                        this.maxY = y;
                     }
                     }
-                    return new SPoint(it.X, -it.Y);
+                    return new SPoint(x, y);
                 });
                 });
                 return tempArr;
                 return tempArr;
             });
             });
@@ -100,37 +102,40 @@ export class SpaceItem extends SGraphyItem {
      * @param y
      * @param y
      */
      */
     contains(x: number, y: number): boolean {
     contains(x: number, y: number): boolean {
-        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++;
+        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;
             }
             }
-            p1 = p2;
+            return nCross % 2 === 1;
         }
         }
-        return nCross % 2 === 1;
+        return false;
     } // Function contains()
     } // Function contains()
 
 
     /**
     /**
@@ -143,6 +148,9 @@ export class SpaceItem extends SGraphyItem {
         if (this.visible) {
         if (this.visible) {
             painter.pen.color = SColor.Transparent;
             painter.pen.color = SColor.Transparent;
             painter.brush.color = Opt.spaceColor;
             painter.brush.color = Opt.spaceColor;
+            // if (this.pointArr.length > 1) {
+            //     painter.brush.color = new SColor("#00ff0080");
+            // }
             painter.pen.lineWidth = 200;
             painter.pen.lineWidth = 200;
             this.pointArr.map(t => {
             this.pointArr.map(t => {
                 painter.drawPolygon(t);
                 painter.drawPolygon(t);

+ 133 - 0
src/items/UserMark.ts

@@ -0,0 +1,133 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    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";
+
+/**
+ * 标志item
+ *
+ * @author  郝建龙
+ */
+export class UserMark extends SGraphyItem {
+    /** 标志宽度 */
+    private width: number = 10;
+    /** 标志高度 */
+    private height: number = 10;
+    //轮廓线坐标
+    outLine: SPoint[] = [];
+    /** 是否闭合 */
+    closeFlag = false;
+    /**
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      标志数据
+     */
+    constructor(parent: SGraphyItem | null, data: SPoint) {
+        super(parent);
+        this.outLine.push(data);
+    } // Constructor
+
+    /**
+     * Item对象边界区域
+     *
+     * @return	SRect
+     */
+    boundingRect(): SRect {
+        return new SRect(0, 0, this.width, this.height);
+    } // Function boundingRect()
+
+    /**
+     * 鼠标按下事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseDown(event: SMouseEvent): boolean {
+        if (!this.closeFlag) {
+            console.log("mouseDown");
+            let newPoint = this.outLine[this.outLine.length - 1];
+            if (
+                newPoint.x == this.outLine[0].x &&
+                newPoint.y == this.outLine[0].y
+            ) {
+                this.closeFlag = true;
+            } else {
+                newPoint = new SPoint(event.x, event.y);
+                console.log(newPoint);
+                this.outLine.push(newPoint);
+            }
+        }
+        return true;
+    } // Function onMouseDown()
+
+    /**
+     * 鼠标移动事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onMouseMove(event: SMouseEvent): boolean {
+        console.log("mouseMove");
+        if (!this.closeFlag) {
+            let first, newLast;
+            if (this.outLine.length > 1) {
+                this.outLine.pop();
+                first = this.outLine[0];
+            }
+            newLast = new SPoint(event.x, event.y);
+            if (this.outLine.length > 2 && first) {
+                if (
+                    event.x + 20 >= first.x &&
+                    event.x - 20 <= first.x &&
+                    event.y + 20 >= first.y &&
+                    event.y - 20 <= first.y
+                ) {
+                    newLast = first;
+                }
+            }
+            this.outLine.push(newLast);
+        }
+        return true;
+    } // Function onMouseMove()
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter       painter对象
+     * @param   rect          绘制区域
+     */
+    onDraw(painter: SPainter, rect?: SRect): void {
+        if (this.visible) {
+            painter.pen.color = new SColor("#00ff00");
+            painter.pen.lineWidth = 2;
+            if (this.closeFlag) {
+                painter.brush.color = new SColor("#00ff00");
+            } else {
+                painter.brush.color = new SColor("#ffffff80");
+            }
+            this.outLine.map(t => {
+                painter.drawRect(t.x - 4, t.y - 4, 8, 8);
+            });
+            painter.drawPolyline(this.outLine);
+        }
+    } // Function onDraw()
+} // Class UserMark