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

添加标签右键事件响应

haojianlong преди 5 години
родител
ревизия
f00c2d22e2
променени са 7 файла, в които са добавени 74 реда и са изтрити 72 реда
  1. 1 1
      package-lock.json
  2. 3 3
      package.json
  3. 28 14
      src/LocationPointScene.ts
  4. 28 51
      src/items/DoorItem.ts
  5. 11 0
      src/items/MarkItem.ts
  6. 1 1
      src/items/SpaceItem.ts
  7. 2 2
      src/types/Marker.ts

+ 1 - 1
package-lock.json

@@ -1,6 +1,6 @@
 {
     "name": "cad-engine",
-    "version": "2.0.251",
+    "version": "2.0.252",
     "lockfileVersion": 1,
     "requires": true,
     "dependencies": {

+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
-    "name": "cad-engine",
-    "version": "2.0.252",
+    "name": "@saga-web/cad-engine",
+    "version": "2.0.268",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -17,7 +17,7 @@
     "author": "郝建龙 (1061851420@qq.com)",
     "license": "ISC",
     "publishConfig": {
-        "registry": "http://dev.dp.sagacloud.cn:8082/repository/npm-host/"
+        "registry": "http://dev.dp.sagacloud.cn:8082/repository/npm-hosted/"
     },
     "devDependencies": {
         "@typescript-eslint/eslint-plugin": "^1.12.0",

+ 28 - 14
src/LocationPointScene.ts

@@ -30,8 +30,22 @@ import { SMouseEvent } from "@saga-web/base/lib";
  */
 export class LocationPointScene extends FloorScene {
     /** 标志list    */
-    markerList: Marker[] = [];
-
+    markerList: MarkerItem[] = [];
+    /** 标志是否可选  */
+    _isMarkSelectable: boolean = true;
+    get isMarkSelectable(): boolean {
+        return this._isMarkSelectable;
+    } // Get isMarkSelectable
+    set isMarkSelectable(v: boolean) {
+        if (this._isMarkSelectable === v) {
+            return;
+        }
+        this._isMarkSelectable = v;
+        this.markerList.map((t: MarkerItem) => {
+            t.selectable = this._isMarkSelectable;
+            return t;
+        });
+    } // Set isMarkSelectable
     /**
      * 构造函数
      *
@@ -58,23 +72,23 @@ export class LocationPointScene extends FloorScene {
      * @param   marker  标志对象
      */
     addMarker(marker: Marker) {
-        let flag = new MarkerItem(null, marker);
-        flag.moveTo(marker.X, marker.Y);
-        flag.zOrder = 9999999;
-        this.markerList.push(marker);
-        flag.connect("click", this, this.markerClick);
-        this.addItem(flag);
+        let mark = new MarkerItem(null, marker);
+        mark.moveTo(marker.X, marker.Y);
+        mark.zOrder = 99999;
+        mark.selectable = this.isMarkSelectable;
+        this.markerList.push(mark);
+        this.addItem(mark);
     } // Function addMarker()
 
     /**
      * 标志的点击事件
      *
-     * @param   item    点击的旗子item
-     * @param   event   点击的事件
+     * @param   _this    接收者
+     * @param   fn       处理函数
      */
-    markerClick(item: MarkerItem, event: SMouseEvent) {
-        console.log(this.data);
-        console.log(arguments);
-        alert(1);
+    markerClick(_this: any, fn: Function) {
+        this.markerList.map(m => {
+            m.connect("click", _this, fn);
+        });
     } // Function markerClick()
 } // Class LocationPointScene

+ 28 - 51
src/items/DoorItem.ts

@@ -34,17 +34,14 @@ export class DoorItem extends SGraphyItem {
     /** 门轮廓线坐标list  */
     private readonly pointArr: SPoint[] = [];
     /** 门长度 */
-    private r: number = 0;
+    private readonly r: number = 0;
     /** 角度  */
-    private ang: number = 0;
+    private readonly ang: number = 0;
     /** 旋转点 */
     private p: SPoint = new SPoint(0, 0);
-    /** 旋转起始角度 */
+    /** 旋转起始角度,结束角度+Math.PI/2 */
     private startAng: number = -Math.PI / 2;
-    /** 旋转结束角度 */
-    private endAng: number = 0;
 
-    // number: number = 0;
     /**
      * 构造函数
      *
@@ -59,8 +56,23 @@ export class DoorItem extends SGraphyItem {
                 return new SPoint(t.X, -t.Y);
             });
 
-            let p1 = this.pointArr[0];
-            let p2 = this.pointArr[1];
+            let p1, p2;
+            if (this.pointArr[0].x < this.pointArr[1].x) {
+                p1 = this.pointArr[0];
+                p2 = this.pointArr[1];
+            } else if (this.pointArr[0].x == this.pointArr[1].x) {
+                if (this.pointArr[0].y <= this.pointArr[1].y) {
+                    p1 = this.pointArr[0];
+                    p2 = this.pointArr[1];
+                } else {
+                    p1 = this.pointArr[1];
+                    p2 = this.pointArr[0];
+                }
+            } else {
+                p1 = this.pointArr[1];
+                p2 = this.pointArr[0];
+            }
+
             let fo = Math.atan(
                 -this.data.FaceDirection.Y / this.data.FaceDirection.X
             );
@@ -71,45 +83,22 @@ export class DoorItem extends SGraphyItem {
             // 门朝向角度
             this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
             // 旋转点
+            this.p = p1;
             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 (p1.x > p2.x) {
-                        this.p = p1;
-                        // this.number = 1; //
-                    } else {
-                        this.p = p2;
-                        // this.number = 2;
-                    }
-                } else {
-                    if (p1.x < p2.x) {
-                        this.p = p1;
-                        // this.number = 3; //
-                    } else {
-                        this.p = p2;
-                        // this.number = 4; //
+                    this.p = p2;
+                    if (this.data.FaceDirection.X > 0) {
+                        this.startAng = 0;
                     }
                 }
             } else {
                 if (this.data.HandDirection.Y > 0) {
-                    if (p1.y > p2.y) {
-                        this.p = p1;
-                        // this.number = 5; //
-                    } else {
-                        this.p = p2;
-                        // this.number = 6;
-                    }
-                } else {
-                    if (p1.y < p2.y) {
-                        this.p = p1;
-                        // this.number = 7;
-                    } else {
-                        this.p = p2;
-                        // this.number = 8;
+                    this.p = p2;
+                    if (this.data.FaceDirection.X > 0) {
+                        this.startAng = 0;
                     }
                 }
             }
@@ -127,20 +116,8 @@ export class DoorItem extends SGraphyItem {
             painter.translate(this.p.x, this.p.y);
             painter.rotate(this.ang);
             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.drawLine(0, 0, this.r, 0);
-
             painter.pen.lineDash = [50, 100];
             // painter.drawArc(
             //     -this.r,
@@ -148,7 +125,7 @@ export class DoorItem extends SGraphyItem {
             //     this.r * 2,
             //     this.r * 2,
             //     this.startAng,
-            //     this.endAng
+            //     this.startAng + Math.PI / 2
             // );
         }
     } // Function onDraw()

+ 11 - 0
src/items/MarkItem.ts

@@ -77,6 +77,17 @@ export class MarkerItem extends SGraphyItem {
     } // Function onClick()
 
     /**
+     * 鼠标右键事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onContextMenu(event: SMouseEvent): boolean {
+        this.$emit("click", event);
+        return true;
+    } // Function onContextMenu()
+
+    /**
      * Item绘制操作
      *
      * @param   painter       painter对象

+ 1 - 1
src/items/SpaceItem.ts

@@ -115,8 +115,8 @@ export class SpaceItem extends SGraphyItem {
     onClick(event: SMouseEvent): boolean {
         if (this.selectable) {
             this.selected = !this.selected;
-            this.$emit("click", event);
         }
+        this.$emit("click", event);
         return true;
     } // Function onClick()
 

+ 2 - 2
src/types/Marker.ts

@@ -25,9 +25,9 @@
  */
 export interface Marker {
     /** 标记的id  */
-    Id: string;
+    Id?: string;
     /** 标记的名称  */
-    Name: string;
+    Name?: string;
     /** X坐标 */
     X: number;
     /** Y坐标 */