Browse Source

更新门画法,及编辑器bug

haojianlong 4 years ago
parent
commit
421fefb896

+ 2 - 2
persagy-web-big-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big-edit",
-    "version": "2.2.23",
+    "version": "2.2.24",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/edit": "2.2.21",
+        "@persagy-web/edit": "2.2.23",
         "@types/uuid": "^8.0.0",
         "crypto-js": "^4.0.0",
         "axios": "^0.20.0"

+ 1 - 1
persagy-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big",
-    "version": "2.2.47",
+    "version": "2.2.48",
     "description": "博锐尚格建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 42 - 41
persagy-web-big/src/items/floor/SDoorItem.ts

@@ -97,41 +97,41 @@ export class SDoorItem extends SGraphItem {
                 }
             );
 
-            let p1 = this.pointArr[0];
-            let p2 = this.pointArr[1];
-            // 旋转点
-            this.p = p1;
-            const HX = (this.data.HandDirection.X = Number(
-                this.data.HandDirection.X.toFixed()
-            ));
-            const HY = (this.data.HandDirection.Y = Number(
-                this.data.HandDirection.Y.toFixed()
-            ));
-            const FX = (this.data.FaceDirection.X = Number(
-                this.data.FaceDirection.X.toFixed()
-            ));
-            const FY = (this.data.FaceDirection.Y = Number(
-                this.data.FaceDirection.Y.toFixed()
-            ));
-            // 向量点乘 => x1 * x2 + y1 * y2,大于0同向
-            let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY;
-            // 如果同向
-            if (dotProduct > 0) {
-                this.p = p2;
-                p2 = p1;
-                p1 = this.p;
-            }
-            // 两点间距离
-            this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
-            // 门朝向角度
-            let fo = Math.atan(-FY / FX);
-            this.ang = FX > 0 ? fo : fo + Math.PI;
-            // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针
-            let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX;
-            // 如果逆时针
-            if (direction > 0) {
-                this.startAng = 0;
-            }
+            // let p1 = this.pointArr[0];
+            // let p2 = this.pointArr[1];
+            // // 旋转点
+            // this.p = p1;
+            // const HX = (this.data.HandDirection.X = Number(
+            //     this.data.HandDirection.X.toFixed()
+            // ));
+            // const HY = (this.data.HandDirection.Y = Number(
+            //     this.data.HandDirection.Y.toFixed()
+            // ));
+            // const FX = (this.data.FaceDirection.X = Number(
+            //     this.data.FaceDirection.X.toFixed()
+            // ));
+            // const FY = (this.data.FaceDirection.Y = Number(
+            //     this.data.FaceDirection.Y.toFixed()
+            // ));
+            // // 向量点乘 => x1 * x2 + y1 * y2,大于0同向
+            // let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY;
+            // // 如果同向
+            // if (dotProduct > 0) {
+            //     this.p = p2;
+            //     p2 = p1;
+            //     p1 = this.p;
+            // }
+            // // 两点间距离
+            // this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
+            // // 门朝向角度
+            // let fo = Math.atan(-FY / FX);
+            // this.ang = FX > 0 ? fo : fo + Math.PI;
+            // // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针
+            // let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX;
+            // // 如果逆时针
+            // if (direction > 0) {
+            //     this.startAng = 0;
+            // }
         }
     }
 
@@ -150,13 +150,14 @@ export class SDoorItem extends SGraphItem {
      * @param painter   绘制对象
      */
     onDraw(painter: SPainter): void {
-        painter.translate(this.p.x, this.p.y);
-        painter.rotate((this.ang * 180) / Math.PI);
-        painter.pen.lineWidth = 100;
+        // painter.translate(this.p.x, this.p.y);
+        // painter.rotate((this.ang * 180) / Math.PI);
+        painter.pen.lineWidth = this.data.Thick || 100;
         painter.pen.color = ItemColor.doorColor;
-        painter.drawLine(0, 0, this.r, 0);
-        painter.pen.lineDash = [50, 100];
-        painter.pen.lineWidth = painter.toPx(1);
+        // painter.drawLine(0, 0, this.r, 0);
+        painter.drawLine(this.pointArr[0], this.pointArr[1]);
+        // painter.pen.lineDash = [50, 100];
+        // painter.pen.lineWidth = painter.toPx(1);
         // painter.drawArc(
         //     -this.r,
         //     -this.r,

+ 2 - 2
persagy-web-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/edit",
-    "version": "2.2.22",
+    "version": "2.2.23",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/big": "2.2.46",
+        "@persagy-web/big": "2.2.48",
         "@types/uuid": "^8.0.0"
     }
 }

+ 64 - 54
persagy-web-edit/src/items/SBaseIconTextEdit.ts

@@ -24,10 +24,7 @@
  * *********************************************************************************************************************
  */
 
-import {
-    SAnchorItem,
-    SGraphItem,
-} from "@persagy-web/graph";
+import { SAnchorItem, SGraphItem } from "@persagy-web/graph";
 import { SItemStatus, ItemOrder } from "@persagy-web/big";
 import { SMouseEvent } from "@persagy-web/base";
 import {
@@ -55,7 +52,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
     } // Get data
     set data(v: Marker | null) {
         this._data = v;
-        this.initData()
+        this.initData();
         this.update();
     } // Set data
 
@@ -69,19 +66,19 @@ export class SBaseIconTextEdit extends SGraphEdit {
         if (v == SItemStatus.Normal) {
             this.moveable = true;
             this.textItemList.map(item => {
-                item.moveable = false
+                item.moveable = false;
             });
             this.img.moveable = false;
         } else if (v == SItemStatus.Edit) {
             this.moveable = false;
             this.textItemList.map(item => {
-                item.moveable = true
+                item.moveable = true;
             });
             this.img.moveable = true;
         } else if (v == SItemStatus.Create) {
             this.moveable = true;
             this.textItemList.map(item => {
-                item.moveable = false
+                item.moveable = false;
             });
             this.img.moveable = false;
         }
@@ -104,11 +101,11 @@ export class SBaseIconTextEdit extends SGraphEdit {
         this._showText = v;
         if (v) {
             this.textItemList.map(item => {
-                item.show()
+                item.show();
             });
         } else {
             this.textItemList.map(item => {
-                item.hide()
+                item.hide();
             });
         }
     }
@@ -145,13 +142,13 @@ export class SBaseIconTextEdit extends SGraphEdit {
         if (v) {
             this.cursor = "pointer";
             this.textItemList.map(item => {
-                item.cursor = "pointer"
+                item.cursor = "pointer";
             });
             this.img.cursor = "pointer";
         } else {
             this.cursor = "auto";
             this.textItemList.map(item => {
-                item.cursor = "auto"
+                item.cursor = "auto";
             });
             this.img.cursor = "auto";
         }
@@ -238,7 +235,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
         this._color = v;
         this.textItemList.forEach(item => {
             item.color = v;
-        })
+        });
         this.update();
     }
 
@@ -252,7 +249,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
         this.textItemList.forEach((item: SBaseTextEdit, index: number) => {
             item.font = v;
             // item.moveTo(this.img.width * 0.5, v.size * (index - 0.125 - 0.5 * this.textItemList.length));
-        })
+        });
         this.update();
     } // Set font
 
@@ -270,7 +267,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
      *
      * @param parent  父节点
      * @param data    锚点数据
-    */
+     */
     constructor(parent: SGraphItem | null, data: Marker | null = null) {
         super(parent);
         this.showSelect = false;
@@ -288,9 +285,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
             this.sHeight = this.data.size.height;
         }
         this.img.connect("onMove", this, this.changeAnchorPoint.bind(this));
-        const anchorPoint = [
-            { x: this.img.x, y: this.img.y, id: "" },
-        ];
+        const anchorPoint = [{ x: this.img.x, y: this.img.y, id: "" }];
         this.anchorList = anchorPoint.map(t => {
             let item = new SAnchorItem(this);
             if (t.id) {
@@ -302,7 +297,11 @@ export class SBaseIconTextEdit extends SGraphEdit {
 
         this.showAnchor = false;
         // 对文本数据进行处理
-        if (this.data.style && this.data.style.default && this.data.style.default.textList) {
+        if (
+            this.data.style &&
+            this.data.style.default &&
+            this.data.style.default.textList
+        ) {
             const textList = this.data.style.default.textList;
             if (textList.length) {
                 const textItemList: any[] = [];
@@ -311,31 +310,31 @@ export class SBaseIconTextEdit extends SGraphEdit {
                     obj.propertyData = item;
                     obj.text = item.text;
                     if (item.pos) {
-                        obj.moveTo(item.pos.x, item.pos.x)
+                        obj.moveTo(item.pos.x, item.pos.x);
                     } else {
                         obj.moveTo(
                             this.img.width * 0.5,
-                            -(this.font.size * 1.25 * 0.5) + (index) * 10
+                            -(this.font.size * 1.25 * 0.5) + index * 10
                         );
                     }
                     obj.font.size = item.font;
                     obj.isTransform = false;
                     obj.showSelect = false;
                     obj.color = new SColor(item.color);
-                    obj.connect('textSelect', this, this.textSelectChange)
-                    textItemList.push(obj)
-                })
+                    obj.connect("textSelect", this, this.textSelectChange);
+                    textItemList.push(obj);
+                });
                 this.textItemList = textItemList;
             }
         }
         this.img.url = this.data.style.default.url;
 
         this.x = this.data.pos.x;
-        this.y = this.data.pos.y
+        this.y = this.data.pos.y;
 
         this.moveable = true;
         this.selectable = true;
-    }// Function initData()
+    } // Function initData()
 
     /**
      * 添加文本
@@ -343,8 +342,8 @@ export class SBaseIconTextEdit extends SGraphEdit {
      * @param item 文本图例
      */
     addTextItem(item: SBaseTextEdit) {
-        this.textItemList.push(item)
-    }// Function addTextItem
+        this.textItemList.push(item);
+    } // Function addTextItem
 
     /**
      * 删除文本
@@ -354,9 +353,9 @@ export class SBaseIconTextEdit extends SGraphEdit {
     removeTextItem(index: number) {
         let [delteItem] = this.textItemList.splice(index, 1);
         if (this.scene) {
-            this.scene.removeItem(delteItem)
+            this.scene.removeItem(delteItem);
         }
-    }// Function removeTextItem
+    } // Function removeTextItem
 
     /**
      * 计算并移动锚点的位置
@@ -378,7 +377,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
 
     /**
      * 选中的文本item变化
-    */
+     */
     textSelectChange(item: SBaseTextEdit): void {
         this.curTextItem = item;
     } // Function textSelectChange()
@@ -388,15 +387,31 @@ export class SBaseIconTextEdit extends SGraphEdit {
      *
      * @param event   事件对象
      * @return  是否处理事件
-    */
+     */
     onMouseDown(event: SMouseEvent): boolean {
         this.curTextItem = null;
         if (this.status == SItemStatus.Normal) {
-            super.onMouseDown(event)
+            super.onMouseDown(event);
             return true;
         } else if (this.status == SItemStatus.Edit) {
-            return super.onMouseDown(event);
+            // @ts-ignore
+            const ce = SGraphItem.toChildMouseEvent(this, event);
+            return super.onMouseDown(ce);
+        }
+        return true;
+    }
+
+    /**
+     * 鼠标抬起事件
+     *
+     * @param event   事件对象
+     * @return  是否处理事件
+     */
+    onMouseUp(event: SMouseEvent): boolean {
+        if (this.status == SItemStatus.Edit) {
+            return true;
         }
+        super.onMouseUp(event);
         return true;
     }
 
@@ -405,7 +420,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
      *
      * @param oldSize   改之前的大小
      * @param newSize   改之后大小
-    */
+     */
     onResize(oldSize: SSize, newSize: SSize) {
         // console.log(arguments);
     } // Function onResize()
@@ -415,7 +430,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
      *
      * @param event   鼠标事件
      * @return 是否处理事件
-    */
+     */
     onDoubleClick(event: SMouseEvent): boolean {
         // 如果位show状态 双击改对象则需改为编辑状态
         if (SItemStatus.Normal == this.status) {
@@ -434,7 +449,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
      * 宽高发生变化
      *
      * @return SRect   所有子对象的并集
-    */
+     */
     boundingRect(): SRect {
         let rect = this.img
             .boundingRect()
@@ -442,11 +457,9 @@ export class SBaseIconTextEdit extends SGraphEdit {
         if (this.showText) {
             this.textItemList.forEach(item => {
                 rect = rect.unioned(
-                    item
-                        .boundingRect()
-                        .adjusted(item.pos.x, item.pos.y, 0, 0)
+                    item.boundingRect().adjusted(item.pos.x, item.pos.y, 0, 0)
                 );
-            })
+            });
         }
         return rect.adjusted(-5, -5, 10, 10);
     }
@@ -472,10 +485,10 @@ export class SBaseIconTextEdit extends SGraphEdit {
         if (this.status == SItemStatus.Edit) {
             painter.pen.lineDash = [];
             painter.brush.color = SColor.White;
-            painter.drawCircle(rect.x, rect.y, 5 * lw)
-            painter.drawCircle(rect.right, rect.bottom, 5 * lw)
-            painter.drawCircle(rect.x, rect.bottom, 5 * lw)
-            painter.drawCircle(rect.right, rect.y, 5 * lw)
+            painter.drawCircle(rect.x, rect.y, 5 * lw);
+            painter.drawCircle(rect.right, rect.bottom, 5 * lw);
+            painter.drawCircle(rect.x, rect.bottom, 5 * lw);
+            painter.drawCircle(rect.right, rect.y, 5 * lw);
         }
         if (this.isActive) {
             painter.pen.color = SColor.Transparent;
@@ -513,10 +526,10 @@ export class SBaseIconTextEdit extends SGraphEdit {
     } // Function onDraw()
 
     /**
-    * 返回对象储存的相关数据
-    *
-    * @return 相关数据
-    */
+     * 返回对象储存的相关数据
+     *
+     * @return 相关数据
+     */
     toData(): any {
         if (this.data) {
             if (this.data.size) {
@@ -530,9 +543,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
             this.data.style.default.url = this.img.url;
         }
 
-        const anchorPoint = [
-            { x: this.img.x, y: this.img.y, id: "" },
-        ];
+        const anchorPoint = [{ x: this.img.x, y: this.img.y, id: "" }];
         this.anchorList = anchorPoint.map(t => {
             let item = new SAnchorItem(this);
             if (t.id) {
@@ -546,8 +557,7 @@ export class SBaseIconTextEdit extends SGraphEdit {
         // this.img.url = this.data.style.default.url;
         if (this.data) {
             this.x = this.data.pos.x;
-            this.y = this.data.pos.y
-
+            this.y = this.data.pos.y;
         }
     } // Function toData()
 } // Class SBaseIconTextEdit