Browse Source

添加SGraphyCommand命令基类。完善undo操作。

庞利祥 5 years ago
parent
commit
edae6760b4

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

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

+ 5 - 1
saga-web-base/src/index.ts

@@ -1,7 +1,11 @@
 import { SMouseButton } from "./enums/SMouseButton";
-import { STouchState } from "./enums/STouchState"
+import { STouchState } from "./enums/STouchState";
 export { SMouseButton, STouchState };
 
+import { SUndoCommand } from "./undo/SUndoCommand";
+import { SUndoStack } from "./undo/SUndoStack";
+export { SUndoCommand, SUndoStack };
+
 import { SNetUtil } from "./utils/SNetUtil";
 import { SStringBuilder } from "./utils/SStringBuilder";
 import { SStringUtil } from "./utils/SStringUtil";

+ 31 - 2
saga-web-base/src/undo/SUndoCommand.ts

@@ -4,8 +4,37 @@
  * @author  庞利祥(sybotan@126.com)
  */
 export abstract class SUndoCommand {
-    /** 执行undo操作 */
+    /**
+     * 构造函数
+     *
+     * @param   parent      指向父命令
+     */
+    protected constructor(parent: SUndoCommand | null = null) {
+
+    } // Constructor
+
+    /**
+     * undo回调
+     */
     abstract undo(): void;
-    /** 执行redo操作 */
+
+    /**
+     * redo回调
+     */
     abstract redo(): void;
+
+    /**
+     * 合并命令
+     *
+     * @param   command     合并的命令
+     * @return  成功能返回true,否则返回false
+     */
+    abstract mergeWith(command: SUndoCommand): boolean;
+
+    /**
+     * 命令ID。如果命令不能合并,则返回-1。如果支持合并则返回一个正整数。
+     */
+    id(): number {
+        return -1;
+    } // Function id()
 } // Class SUndoCommand

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

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

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graphy",
-    "version": "2.1.28",
+    "version": "2.1.29",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -31,6 +31,6 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "^2.1.56"
+        "@saga-web/draw": "^2.1.58"
     }
 }

+ 16 - 0
saga-web-graphy/src/SGraphyScene.ts

@@ -113,6 +113,22 @@ export class SGraphyScene {
         return rect;
     } // Function selectedItemRect()
 
+    /**
+     * 获得选中的对象列表
+     *
+     * @return  选中对象列表
+     */
+    selectedItems(): SGraphyItem[] {
+        let itemList = Array<SGraphyItem>();
+        for (let item of this.root.children) {
+            // 如果item未被选中,则去选择下一个item
+            if (item.selected) {
+                itemList.push(item);
+            }
+        }
+        return itemList;
+    } // Function selectedItems()
+
     // =================================================================================================================
     // 事件
     /**

+ 45 - 0
saga-web-graphy/src/commands/SGraphyCommand.ts

@@ -0,0 +1,45 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *               iFHS7.
+ *              ;BBMBMBMc                  rZMBMBR              BMB
+ *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
+ *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
+ *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
+ *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
+ *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
+ *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
+ *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
+ *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
+ *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
+ *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
+ *         i0BM: SWKHKGO  MBDv
+ *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2019.  斯伯坦机器人
+ *              ,  XMW  ..
+ *                  r                                                                     All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+import { SUndoCommand } from "@saga-web/base/lib";
+import { SGraphyScene } from "../SGraphyScene";
+
+/**
+ * Graphy命令基类
+ *
+ * @author  庞利祥(sybotan@126.com)
+ */
+export abstract class SGraphyCommand extends SUndoCommand {
+    /** 命令所属的场景类 */
+    scene: SGraphyScene;
+
+    /**
+     * 构造函数
+     *
+     * @param   scene       命令所属的场景类
+     */
+    protected constructor(scene: SGraphyScene) {
+        super();
+        this.scene = scene;
+    } // Constructor
+} // Class SGraphyCommand

+ 2 - 0
saga-web-graphy/src/index.ts

@@ -20,6 +20,8 @@
  *
  * ********************************************************************************************************************
  */
+import { SGraphyCommand } from "./commands/SGraphyCommand";
+export { SGraphyCommand };
 
 import { SGraphyClockItem } from "./items/SGraphyClockItem";
 import { SGraphyLineItem } from "./items/SGraphyLineItem";