Explorar el Código

折线增加undo/redo; item层级新增

haojianlong hace 5 años
padre
commit
6bde10e5f7

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

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

+ 10 - 0
saga-web-big/src/config/ItemOrder.ts

@@ -40,6 +40,16 @@ export class ItemOrder {
     static doorOrder = 24;
     /** 窗户层级 */
     static windowOrder = 28;
+    /** 多边形层级 */
+    static polygonOrder = 40;
+    /** 直线层级 */
+    static lineOrder = 50;
+    /** 折线层级 */
+    static polylineOrder = 60;
+    /** 图片层级 */
+    static imageOrder = 70;
+    /** 文本层级 */
+    static textOrder = 80;
     /** 位置标签对象层级 */
     static markOrder = 99;
     /** 遮罩层级    */

+ 25 - 13
saga-web-big/src/items/SPolylineItem.ts

@@ -5,7 +5,8 @@ import { SMathUtil } from "../utils/SMathUtil";
 import {
     SGraphItem,
     SGraphPointListDelete,
-    SGraphPointListInsert, SGraphPointListUpdate
+    SGraphPointListInsert,
+    SGraphPointListUpdate
 } from "@saga-web/graph/lib";
 
 /**
@@ -128,9 +129,9 @@ export class SPolylineItem extends SGraphItem {
     } // Function canHandle()
 
     /**
-     * 添加点至数组中
+     * 根据索引删除点
      *
-     * @param   index   添加到的索引
+     * @param   index   删除点
      * */
     private delPoint(index: number): void {
         if (this.canHandle(index) && this.pointList.length > 2) {
@@ -138,12 +139,14 @@ export class SPolylineItem extends SGraphItem {
                 this.pointList[this.curIndex].x,
                 this.pointList[this.curIndex].y
             );
-            this.pointList.splice(index, 0);
+            this.pointList.splice(index, 1);
             this.recordAction(SGraphPointListDelete, [
                 this.pointList,
                 p,
                 index
             ]);
+            this.curIndex = -1;
+            this.curPoint = null;
             this.update();
         }
     } // Function delPoint
@@ -170,9 +173,7 @@ export class SPolylineItem extends SGraphItem {
                 }
                 // 删除点
                 if (event.altKey && this.canHandle(this.curIndex)) {
-                    this.pointList.splice(this.curIndex, 1);
-                    this.curIndex = -1;
-                    this.curPoint = null;
+                    this.delPoint(this.curIndex);
                 }
                 this.update();
                 return true;
@@ -246,14 +247,10 @@ export class SPolylineItem extends SGraphItem {
     onDoubleClick(event: SMouseEvent): boolean {
         if (this.status == SItemStatus.Normal) {
             this.status = SItemStatus.Edit;
-            if (this.scene) {
-                this.scene.grabItem = this;
-            }
+            this.grabItem(this);
         } else if (this.status == SItemStatus.Edit) {
             this.status = SItemStatus.Normal;
-            if (this.scene) {
-                this.scene.grabItem = null;
-            }
+            this.releaseItem();
         } else if (this.status == SItemStatus.Create) {
             this.status = SItemStatus.Edit;
         }
@@ -269,6 +266,7 @@ export class SPolylineItem extends SGraphItem {
     onKeyUp(event: KeyboardEvent): void {
         if (event.keyCode == 13) {
             this.status = SItemStatus.Normal;
+            this.releaseItem();
         }
     } // Function onKeyUp()
 
@@ -392,6 +390,20 @@ export class SPolylineItem extends SGraphItem {
     } // Function redo()
 
     /**
+     * 取消操作执行
+     *
+     * */
+    cancelOperate(): void {
+        if (this.status == SItemStatus.Create) {
+            this.parent = null;
+            this.releaseItem();
+        } else if (this.status == SItemStatus.Edit) {
+            this.status = SItemStatus.Normal;
+            this.releaseItem();
+        }
+    } // Function cancelOperate()
+
+    /**
      * Item绘制操作
      *
      * @param   painter painter对象

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.69",
+    "version": "2.1.70",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 2 - 2
saga-web-graph/src/SGraphItem.ts

@@ -560,7 +560,7 @@ export class SGraphItem extends SObject {
      *
      * @param   item    被锁定的item
      */
-    private grabItem(item: SGraphItem): void {
+    protected grabItem(item: SGraphItem): void {
         if (this.scene != null) {
             this.scene.grabItem = item;
         }
@@ -569,7 +569,7 @@ export class SGraphItem extends SObject {
     /**
      * 释放被锁定的item
      */
-    private releaseItem(): void {
+    protected releaseItem(): void {
         if (this.scene != null) {
             this.scene.grabItem = null;
         }