Browse Source

折线,多边形,直线 shift垂直水平绘制

haojianlong 5 years ago
parent
commit
99424239ec

+ 1 - 1
saga-web-base/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/base",
-    "version": "2.1.24",
+    "version": "2.1.25",
     "description": "上格云Web基础库。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 3 - 0
saga-web-base/src/SMouseEvent.ts

@@ -28,6 +28,8 @@ export class SMouseEvent {
     altKey: boolean;
     /** 是否按下ctrl键 */
     ctrlKey: boolean;
+    /** 是否按下shiftKey键 */
+    shiftKey: boolean;
     /** 鼠标按键 */
     buttons: number;
     /** 变换矩阵 */
@@ -49,6 +51,7 @@ export class SMouseEvent {
         this.offsetY = event.offsetY;
         this.altKey = event.altKey;
         this.ctrlKey = event.ctrlKey;
+        this.shiftKey = event.shiftKey;
         this.buttons = event.buttons;
         if (event instanceof SMouseEvent) {
             this.x = event.x;

+ 2 - 2
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.97",
+    "version": "1.0.103",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.118"
+        "@saga-web/graph": "2.1.120"
     }
 }

+ 34 - 0
saga-web-big/src/items/SLineItem.ts

@@ -199,6 +199,9 @@ export class SLineItem extends SGraphItem {
     onMouseDown(event: SMouseEvent): boolean {
         this.curIndex = -1;
         this.curPoint = null;
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         if (event.buttons == SMouseButton.LeftButton) {
             if (this.status == SItemStatus.Normal) {
                 return super.onMouseDown(event);
@@ -249,6 +252,9 @@ export class SLineItem extends SGraphItem {
      * @return  是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         if (this.status == SItemStatus.Create) {
             if (this.line[0] instanceof SPoint) {
                 this.line[1] = new SPoint(event.x, event.y);
@@ -317,6 +323,34 @@ export class SLineItem extends SGraphItem {
     } // Function moveToOrigin()
 
     /**
+     * shift垂直水平创建或编辑
+     *
+     * @param   event   事件
+     * */
+    compare(event: SMouseEvent): SMouseEvent {
+        if (this.line.length) {
+            let last = new SPoint(event.x, event.y);
+            if (this.status == SItemStatus.Create) {
+                last = this.line[0];
+            } else if (this.status == SItemStatus.Edit) {
+                if (this.curIndex == 1) {
+                    last = this.line[0];
+                } else if (this.curIndex == 0) {
+                    last = this.line[1];
+                }
+            }
+            const dx = Math.abs(event.x - last.x);
+            const dy = Math.abs(event.y - last.y);
+            if (dy > dx) {
+                event.x = last.x;
+            } else {
+                event.y = last.y;
+            }
+        }
+        return event;
+    } // Function compare()
+
+    /**
      * 判断点是否在区域内
      *
      * @param   x

+ 32 - 0
saga-web-big/src/items/SPolygonItem.ts

@@ -553,6 +553,9 @@ export class SPolygonItem extends SGraphItem {
      * @return	boolean
      */
     onMouseDown(event: SMouseEvent): boolean {
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         // 如果状态为编辑状态则添加点
         if (this.status == SItemStatus.Create) {
             // 新增顶点
@@ -615,6 +618,9 @@ export class SPolygonItem extends SGraphItem {
      */
 
     onMouseMove(event: SMouseEvent): boolean {
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         if (this.status == SItemStatus.Create) {
             this.lastPoint = new SPoint();
             this.lastPoint.x = event.x;
@@ -635,6 +641,32 @@ export class SPolygonItem extends SGraphItem {
     } // Function onMouseMove()
 
     /**
+     * shift垂直水平创建或编辑
+     *
+     * @param   event   事件
+     * */
+    compare(event: SMouseEvent): SMouseEvent {
+        if (this.pointList.length) {
+            let last = new SPoint(event.x, event.y);
+            if (this.status == SItemStatus.Create) {
+                last = this.pointList[this.pointList.length - 1];
+            } else if (this.status == SItemStatus.Edit) {
+                if (this.curIndex > 1) {
+                    last = this.pointList[this.curIndex - 1];
+                }
+            }
+            const dx = Math.abs(event.x - last.x);
+            const dy = Math.abs(event.y - last.y);
+            if (dy > dx) {
+                event.x = last.x;
+            } else {
+                event.y = last.y;
+            }
+        }
+        return event;
+    } // Function compare()
+
+    /**
      * 鼠标抬起事件
      *
      * @param	event         事件参数

+ 32 - 0
saga-web-big/src/items/SPolylineItem.ts

@@ -169,6 +169,9 @@ export class SPolylineItem extends SGraphItem {
     onMouseDown(event: SMouseEvent): boolean {
         this.curIndex = -1;
         this.curPoint = null;
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         if (event.buttons == 1) {
             if (this.status == SItemStatus.Create) {
                 this.addPoint(new SPoint(event.x, event.y));
@@ -200,6 +203,9 @@ export class SPolylineItem extends SGraphItem {
      * @return  boolean 是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
+        if (event.shiftKey) {
+            event = this.compare(event);
+        }
         if (this.status == SItemStatus.Create) {
             if (this.lastPoint) {
                 this.lastPoint.x = event.x;
@@ -371,6 +377,32 @@ export class SPolylineItem extends SGraphItem {
     } // Function findAddPos()
 
     /**
+     * shift垂直水平创建或编辑
+     *
+     * @param   event   事件
+     * */
+    compare(event: SMouseEvent): SMouseEvent {
+        if (this.pointList.length) {
+            let last = new SPoint(event.x, event.y);
+            if (this.status == SItemStatus.Create) {
+                last = this.pointList[this.pointList.length - 1];
+            } else if (this.status == SItemStatus.Edit) {
+                if (this.curIndex > 1) {
+                    last = this.pointList[this.curIndex - 1];
+                }
+            }
+            const dx = Math.abs(event.x - last.x);
+            const dy = Math.abs(event.y - last.y);
+            if (dy > dx) {
+                event.x = last.x;
+            } else {
+                event.y = last.y;
+            }
+        }
+        return event;
+    } // Function compare()
+
+    /**
      * 记录相关动作并推入栈中
      *
      * @param	SGraphCommand   相关命令类

+ 2 - 2
saga-web-draw/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/draw",
-    "version": "2.1.105",
+    "version": "2.1.106",
     "description": "上格云绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -33,7 +33,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/base": "^2.1.24"
+        "@saga-web/base": "^2.1.25"
     },
     "jest": {
         "setupFiles": [

+ 2 - 2
saga-web-fengmap/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/feng-map",
-    "version": "1.0.31",
+    "version": "1.0.35",
     "description": "上格云Web平面图。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -33,7 +33,7 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/big": "1.0.97",
+        "@saga-web/big": "1.0.101",
         "axios": "^0.18.0"
     }
 }

+ 2 - 2
saga-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.118",
+    "version": "2.1.120",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "2.1.105",
+        "@saga-web/draw": "2.1.106",
         "@types/uuid": "^8.0.0"
     }
 }