Преглед на файлове

更新绘制空间,墙画法,二维数组

haojianlong преди 5 години
родител
ревизия
dc278abff2
променени са 9 файла, в които са добавени 79 реда и са изтрити 53 реда
  1. 13 13
      package-lock.json
  2. 4 4
      package.json
  3. 3 2
      src/items/ColumnItem.ts
  4. 16 4
      src/items/DoorItem.ts
  5. 28 22
      src/items/SpaceItem.ts
  6. 2 1
      src/items/VirtualWallItem.ts
  7. 11 5
      src/items/WallItem.ts
  8. 1 1
      src/items/WindowItem.ts
  9. 1 1
      src/types/Opt.ts

+ 13 - 13
package-lock.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.46",
+    "version": "2.0.59",
     "lockfileVersion": 1,
     "requires": true,
     "dependencies": {
@@ -25,25 +25,25 @@
             }
         },
         "@sybotan-web/base": {
-            "version": "2.0.54",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/base/-/base-2.0.54.tgz",
-            "integrity": "sha512-cYHF8tm/uIwMHRKGp+whO6/juVCyarNqrUq4nsHL22iV8pFOe5lDI8duc4Glg9Ar5dLdzNOdTIoYilmctJOOhQ=="
+            "version": "2.1.1",
+            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/base/-/base-2.1.1.tgz",
+            "integrity": "sha512-aXtrgDJIILMIYGbe4Dku/kXll/rZZJ1pOsDeB/Di9qAc6GPUJbxSehyXBTE1ndddYlLN6fw/Y1aUxdqu01IYdQ=="
         },
         "@sybotan-web/draw": {
-            "version": "2.0.128",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/draw/-/draw-2.0.128.tgz",
-            "integrity": "sha512-ok8iRMQclXRCIKKgHcUjyT0Q1jRU4qkcAdqIYztd5ucYrkrFGctnf+8QJtkt8Oj9Y3Sz/7ZDZvX6LcrkgRSqbw==",
+            "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==",
             "requires": {
-                "@sybotan-web/base": "^2.0.54"
+                "@sybotan-web/base": "^2.1.1"
             }
         },
         "@sybotan-web/graphy": {
-            "version": "2.0.93",
-            "resolved": "http://dev.dp.sagacloud.cn:8082/repository/npm-saga/@sybotan-web/graphy/-/graphy-2.0.93.tgz",
-            "integrity": "sha512-USIDTKv2fQCtc7mkt56jDCs/688xYIxhgGRc4beh37+q+bUP5HOR6JU7UpBnmeV6+2rFm45Gqeo6UjKwptnkOg==",
+            "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==",
             "requires": {
-                "@sybotan-web/base": "^2.0.54",
-                "@sybotan-web/draw": "^2.0.117"
+                "@sybotan-web/base": "^2.1.1",
+                "@sybotan-web/draw": "^2.1.1"
             }
         },
         "@types/eslint-visitor-keys": {

+ 4 - 4
package.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.47",
+    "version": "2.0.69",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -31,9 +31,9 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@sybotan-web/base": "2.0.54",
-        "@sybotan-web/draw": "2.0.128",
-        "@sybotan-web/graphy": "2.0.93",
+        "@sybotan-web/base": "2.1.1",
+        "@sybotan-web/draw": "2.1.1",
+        "@sybotan-web/graphy": "2.1.1",
         "axios": "^0.18.0",
         "pako": "^1.0.10"
     }

+ 3 - 2
src/items/ColumnItem.ts

@@ -45,7 +45,7 @@ export class ColumnItem extends SGraphyItem {
         this.data = data;
         if (this.data.OutLine.length) {
             this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+                return new SPoint(t.X, -t.Y);
             });
         }
     } // Constructor
@@ -58,7 +58,8 @@ export class ColumnItem extends SGraphyItem {
      */
     onDraw(painter: SPainter, rect?: SRect): void {
         if (this.visible) {
-            painter.pen.color = SColor.Transparent;
+            painter.pen.color = Opt.columnColor;
+            painter.pen.lineWidth = 10;
             painter.brush.color = Opt.columnColor;
             painter.drawPolygon(this.pointArr);
         }

+ 16 - 4
src/items/DoorItem.ts

@@ -55,7 +55,7 @@ export class DoorItem extends SGraphyItem {
         this.data = data;
         if (this.data.OutLine.length) {
             this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+                return new SPoint(t.X, -t.Y);
             });
 
             let p1 = this.pointArr[0];
@@ -68,7 +68,12 @@ export class DoorItem extends SGraphyItem {
                 Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)
             );
             // 门朝向角度
-            this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
+            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;
             // 旋转点
             if (this.data.HandDirection.X > this.data.HandDirection.Y) {
                 if (this.data.HandDirection.X > 0) {
@@ -96,12 +101,19 @@ export class DoorItem extends SGraphyItem {
         if (this.visible) {
             painter.translate(this.p.x, this.p.y);
             painter.rotate(this.ang);
-            painter.pen.lineWidth = 50;
+            painter.pen.lineWidth = 100;
             painter.pen.color = Opt.doorColor;
             painter.drawLine(0, 0, this.r, 0);
 
             painter.pen.lineDash = [10, 10];
-            painter.drawArc(0, 0, this.r, this.r, this.startAng, this.endAng);
+            painter.drawArc(
+                -this.r,
+                -this.r,
+                this.r * 2,
+                this.r * 2,
+                this.startAng,
+                this.endAng
+            );
         }
     } // Function onDraw()
 } // Class DoorItem

+ 28 - 22
src/items/SpaceItem.ts

@@ -32,7 +32,7 @@ export class SpaceItem extends SGraphyItem {
     /** 空间所有数据  */
     data: Space;
     /** 空间轮廓线坐标list  */
-    private readonly pointArr: SPoint[] = [];
+    private readonly pointArr: SPoint[][] = [];
     /** X坐标最小值  */
     private minX = 0;
     /** X坐标最大值  */
@@ -41,6 +41,7 @@ export class SpaceItem extends SGraphyItem {
     private minY = 0;
     /** Y坐标最大值  */
     private maxY = 0;
+
     /**
      * 构造函数
      *
@@ -51,28 +52,31 @@ export class SpaceItem extends SGraphyItem {
         super(parent);
         this.data = data;
         if (this.data.OutLine.length) {
-            this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+            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 => {
+                    if (it.X < this.minX) {
+                        this.minX = it.X;
+                    }
+                    if (it.Y < this.minY) {
+                        this.minY = it.Y;
+                    }
+                    if (it.X > this.maxX) {
+                        this.maxX = it.X;
+                    }
+                    if (it.Y > this.maxY) {
+                        this.maxY = it.Y;
+                    }
+                    return new SPoint(it.X, -it.Y);
+                });
+                return tempArr;
             });
         }
-        this.minX = this.pointArr[0].x;
-        this.maxX = this.minX;
-        this.minY = this.pointArr[0].y;
-        this.maxY = this.minY;
-        for (let i = 1; i < this.pointArr.length; i++) {
-            if (this.pointArr[i].x < this.minX) {
-                this.minX = this.pointArr[i].x;
-            }
-            if (this.pointArr[i].y < this.minY) {
-                this.minY = this.pointArr[i].y;
-            }
-            if (this.pointArr[i].x > this.maxX) {
-                this.maxX = this.pointArr[i].x;
-            }
-            if (this.pointArr[i].y > this.maxY) {
-                this.maxY = this.pointArr[i].y;
-            }
-        }
     } // Constructor
 
     /**
@@ -140,7 +144,9 @@ export class SpaceItem extends SGraphyItem {
             painter.pen.color = SColor.Transparent;
             painter.brush.color = Opt.spaceColor;
             painter.pen.lineWidth = 200;
-            painter.drawPolygon(this.pointArr);
+            this.pointArr.map(t => {
+                painter.drawPolygon(t);
+            });
         }
     } // Function onDraw()
 } // Class SpaceItem

+ 2 - 1
src/items/VirtualWallItem.ts

@@ -45,7 +45,7 @@ export class VirtualWallItem extends SGraphyItem {
         this.data = data;
         if (this.data.OutLine.length) {
             this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+                return new SPoint(t.X, -t.Y);
             });
         }
     } // Constructor
@@ -60,6 +60,7 @@ export class VirtualWallItem extends SGraphyItem {
         if (this.visible) {
             painter.pen.lineWidth = 100;
             painter.pen.color = Opt.virtualWallColor;
+            painter.pen.lineDash = [200, 200];
             painter.drawPolyline(this.pointArr);
         }
     } // Function onDraw()

+ 11 - 5
src/items/WallItem.ts

@@ -22,6 +22,7 @@ import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
 import { SColor, SPainter, SPoint, SRect } from "@sybotan-web/draw/lib";
 import { Wall } from "../types/Wall";
 import { Opt } from "../types/Opt";
+import {Point} from "../types/Point";
 
 /**
  * 墙item
@@ -32,7 +33,7 @@ export class WallItem extends SGraphyItem {
     /** 墙数据 */
     data: Wall;
     /** 墙轮廓线坐标list  */
-    private readonly pointArr: SPoint[] = [];
+    private readonly pointArr: SPoint[][] = [];
 
     /**
      * 构造函数
@@ -44,8 +45,11 @@ export class WallItem extends SGraphyItem {
         super(parent);
         this.data = data;
         if (this.data.OutLine.length) {
-            this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+            this.pointArr = this.data.OutLine.map(t => {
+                let tempArr = t.map(it => {
+                    return new SPoint(it.X, -it.Y);
+                });
+                return tempArr;
             });
         }
     } // Constructor
@@ -59,9 +63,11 @@ export class WallItem extends SGraphyItem {
     onDraw(painter: SPainter, rect?: SRect): void {
         if (this.visible) {
             painter.pen.color = Opt.wallColor;
-            painter.pen.lineWidth = 4;
+            painter.pen.lineWidth = 10;
             painter.brush.color = Opt.wallColor;
-            painter.drawPolygon(this.pointArr);
+            this.pointArr.map(t => {
+                painter.drawPolygon(t);
+            });
         }
     } // Function onDraw()
 } // Class WallItem

+ 1 - 1
src/items/WindowItem.ts

@@ -45,7 +45,7 @@ export class WindowItem extends SGraphyItem {
         this.data = data;
         if (this.data.OutLine.length) {
             this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, t.Y);
+                return new SPoint(t.X, -t.Y);
             });
         }
     } // Constructor

+ 1 - 1
src/types/Opt.ts

@@ -27,7 +27,7 @@ import { SColor } from "@sybotan-web/draw/lib";
  */
 export class Opt {
     /** 墙颜色 */
-    static wallColor = new SColor("#FF000080");
+    static wallColor = new SColor("#FF0000");
     /** 柱子颜色 */
     static columnColor = SColor.Black;
     /** 虚拟墙颜色 */