Parcourir la source

新增commond命令

YaolongHan il y a 4 ans
Parent
commit
185adc0cf3

+ 2 - 0
src/components/baseEditer.vue

@@ -364,6 +364,8 @@ export default {
           this.scene.addItem(t);
           this.scene.Nodes.push(t);
         });
+        // undo/redo事件
+        this.scene.AddListCommand(parserData.zoneLegendList)
       });
       // 设备图例样式对象
       bus.$on("setLenged", obj => {

+ 42 - 18
src/components/mapClass/EditScence.ts

@@ -1,7 +1,11 @@
 import { SMouseEvent, SUndoStack } from "@saga-web/base";
 import { SGraphScene, SGraphLayoutType, SAnchorItem } from '@saga-web/graph/lib';
 import { SFloorParser, SLineItem, SPolylineItem, SItemStatus, ItemOrder, STooltipItem, ItemColor } from "@saga-web/big";
-import { SGraphItem, SLineStyle,SGraphPropertyCommand, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
+import { SGraphItem, SLineStyle, SGraphPropertyCommand, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
+import {SGraphAddListCommand} from "./SGraphAddListCommand"
+import {SGraphDeleteCommand} from "./SGraphDeleteCommand"
+import {SGraphDeleteListCommand} from "./SGraphDeleteListCommand"
+
 import { SZoneLegendItem } from "@/lib/items/SZoneLegendItem";
 import { SSCPZZoneLegendItem } from "@/lib/items/SSCPZZoneLegendItem";
 import { SFHFQZoneLegendItem } from "@/lib/items/SFHFQZoneLegendItem";
@@ -184,7 +188,6 @@ export class EditScence extends SGraphScene {
             clickItem.connect('onMove', item, item.changePos);
         }
         this.scenceUpdate(this);
-        // item.connect("onMove", this, this.onItemMove.bind(this));
         return true
     }
 
@@ -243,7 +246,7 @@ export class EditScence extends SGraphScene {
         // 起始锚点
         item.startAnchor = anc;
         if (anc) {
-            anc.parent?.connect('changePos', item, item.changePos)
+            anc.parent ?.connect('changePos', item, item.changePos)
             item.anchor1ID = anc.id;
             item.node1Id = anc.parent.id;
         }
@@ -425,7 +428,7 @@ export class EditScence extends SGraphScene {
      */
     addIconItem(event: SMouseEvent): void {
         //获取信息工程化相关参数
-        const InfoSystemId = this._legend.InfoSystemId ? this._legend.InfoSystemId  :'';
+        const InfoSystemId = this._legend.InfoSystemId ? this._legend.InfoSystemId : '';
         const LegendData: Legend = {
             ID: uuid(),
             Name: this._legend.Name,
@@ -447,7 +450,7 @@ export class EditScence extends SGraphScene {
                 font: 12,    //font
                 color: '',  //字体颜色
                 GraphCategoryId: this._legend.GraphCategoryId,
-                InfoSystemId:InfoSystemId   //信息工程话分类ID分类
+                InfoSystemId: InfoSystemId   //信息工程话分类ID分类
             },
         }
         const item = new SImageLegendItem(null, LegendData);
@@ -617,7 +620,7 @@ export class EditScence extends SGraphScene {
     upadataImageUrl(url: string): void {
         if (this.focusItem) {
             const newMsg = '/serve/topology-wanda/Picture/query/' + url;
-            const oldMsg =  this.focusItem.url;
+            const oldMsg = this.focusItem.url;
             this.focusItem.url = newMsg;
             this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "url", oldMsg, newMsg));
         }
@@ -638,7 +641,7 @@ export class EditScence extends SGraphScene {
                 borderStyle = SLineStyle.Soild;
             }
             const newMsg = borderStyle;
-            const oldMsg =  this.focusItem.lineStyle;
+            const oldMsg = this.focusItem.lineStyle;
             this.focusItem.lineStyle = borderStyle;
             this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "lineStyle", oldMsg, newMsg));
         }
@@ -651,7 +654,7 @@ export class EditScence extends SGraphScene {
     upadataLengedName(val: string): void {
         if (this.focusItem && this.focusItem.data) {
             const newMsg = val;
-            const oldMsg =  this.focusItem.text;
+            const oldMsg = this.focusItem.text;
             this.focusItem.text = val;
             this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "text", oldMsg, newMsg));
             this.scenceUpdate(this);
@@ -665,7 +668,7 @@ export class EditScence extends SGraphScene {
     upadatImageNum(num: number): void {
         if (this.focusItem && this.focusItem.num) {
             const newMsg = num;
-            const oldMsg =  this.focusItem.num;
+            const oldMsg = this.focusItem.num;
             this.focusItem.num = num;
             this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
         }
@@ -677,8 +680,8 @@ export class EditScence extends SGraphScene {
      */
     upadatfillColor(fillColor: string): void {
         if (this.focusItem && this.focusItem.fillColor) {
-            const newMsg =  new SColor(fillColor);
-            const oldMsg =  this.focusItem.fillColor;
+            const newMsg = new SColor(fillColor);
+            const oldMsg = this.focusItem.fillColor;
             this.focusItem.fillColor = new SColor(fillColor);
             this.undoStack.push(new SGraphPropertyCommand(this, this.focusItem, "num", oldMsg, newMsg));
         }
@@ -701,7 +704,7 @@ export class EditScence extends SGraphScene {
         if (this.focusItem) {
             this.focusItem.data.AttachObjectIds = AttachObjectIds;
             // 重新选中focusitem
-            const item =  this.focusItem;
+            const item = this.focusItem;
             this.selectContainer.clear();
             this.selectContainer.toggleItem(item)
         }
@@ -720,6 +723,7 @@ export class EditScence extends SGraphScene {
             ) {
                 this.focusItem.deletePoint(this.focusItem.curIndex);
             } else {
+                this.undoStack.push(new SGraphDeleteCommand(this, this.focusItem));
                 this.removeItem(this.focusItem);
                 let a = -1
                 this.Nodes.forEach((item: any, index: number) => {
@@ -759,6 +763,7 @@ export class EditScence extends SGraphScene {
             if (!this.focusItemList) {
                 return
             }
+            this.undoStack.push(new SGraphDeleteListCommand(this,this.focusItemList))
             this.focusItemList.forEach((focusItem) => {
                 this.removeItem(focusItem);
                 let a = -1
@@ -841,28 +846,39 @@ export class EditScence extends SGraphScene {
      * 执行取消操作
      */
     redo(): void {
-        console.log('afdafsdaf',this.grabItem)
-        this.undoStack.undo();
+        if (this.grabItem && this.grabItem.redo) {
+            this.grabItem.redo()
+        } else {
+            this.undoStack.redo();
+        }
+
     }
 
     /**
     * 执行重做操作执行
     */
     undo(): void {
-        this.undoStack.redo();
+        if (this.grabItem && this.grabItem.undo) {
+            this.grabItem.undo()
+        } else {
+            this.undoStack.undo();
+        }
     }
     /**
      * 完成事件创建的回调函数
      */
     finishCreated(item: any) {
+        let arrList = []
+        if(this.cmd == 'baseLine'){
+            arrList = this.Markers
+        }
         this.cmd = 'choice';
         this.selectContainer.clear()
         this.selectContainer.toggleItem(item)
-        setTimeout(()=>{
+        setTimeout(() => {
             this.focusItem = item;
         })
-        // 做相应得redo/undo处理
-        this.undoStack.push(new SGraphAddCommand(this, item));
+        this.undoStack.push(new SGraphAddCommand(this, item,arrList));
     }
     ////////////////////////
     //  以下为鼠标键盘操作事件
@@ -1338,4 +1354,12 @@ export class EditScence extends SGraphScene {
             Line: Line
         };
     } // Function absorbSpaceLine()
+
+    /**
+     *  添加多个item命令
+     *  @param  focusItemList       鼠标事件对象
+     */
+    AddListCommand (focusItemList:any[]):void{
+        this.undoStack.push(new SGraphAddListCommand(this,focusItemList));
+    }
 }

+ 53 - 0
src/components/mapClass/SGraphAddListCommand.ts

@@ -0,0 +1,53 @@
+import { SGraphCommand } from "@saga-web/graph/lib/commands/SGraphCommand";
+import { SGraphItem } from "@saga-web/graph/lib/SGraphItem";
+import { SGraphScene } from "@saga-web/graph/lib/SGraphScene";
+import { SUndoCommand } from "@saga-web/base/lib";
+/**
+ * 添加多个item命令
+ *
+ * @author  han_yao_long
+ * */
+
+export class SGraphAddListCommand extends SGraphCommand {
+    /** 命令item对象    */
+    itemList: SGraphItem[];
+    /** 命令item的父类   */
+    parent: SGraphItem | null;
+    constructor(scene: SGraphScene, itemList: SGraphItem[]) {
+        super(scene);
+        this.itemList = itemList;
+        this.parent = itemList[0].parent;
+    }
+    /**
+   * 合并命令
+   *
+   * @return  boolean 是否已执行合并
+   * */
+    mergeWith(command: SUndoCommand): boolean {
+        return false;
+    } // Function mergeWith()
+
+    /**
+     * 重做
+     *
+     * */
+    redo(): void {
+        this.itemList.map((item) => {
+            item.parent = this.parent;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function redo()
+
+    /**
+     * 撤销
+     *
+     * */
+    undo(): void {
+        this.itemList.map((item) => {
+            item.parent = null;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function undo()
+}

+ 58 - 0
src/components/mapClass/SGraphDeleteCommand.ts

@@ -0,0 +1,58 @@
+
+import { SGraphCommand } from "@saga-web/graph/lib/commands/SGraphCommand";
+import { SGraphItem } from "@saga-web/graph/lib/SGraphItem";
+import { SGraphScene } from "@saga-web/graph/lib/SGraphScene";
+import { SUndoCommand } from "@saga-web/base/lib";
+
+/**
+ * 添加item命令
+ *
+ * @author  hanyaolong
+ * */
+export class SGraphDeleteCommand extends SGraphCommand {
+    /** 命令item对象    */
+    item: SGraphItem;
+    /** 命令item的父类   */
+    parent: SGraphItem | null;
+
+    /**
+     * 构造函数
+     *
+     * @param   scene   item所在场景
+     * @param   item    命令item对象
+     * */
+    constructor(scene: SGraphScene, item: SGraphItem) {
+        super(scene);
+        this.item = item;
+        this.parent = item.parent;
+    } // Constructor
+
+    /**
+     * 合并命令
+     *
+     * @return  boolean 是否已执行合并
+     * */
+    mergeWith(command: SUndoCommand): boolean {
+        return false;
+    } // Function mergeWith()
+
+    /**
+     * 重做
+     *
+     * */
+    undo(): void {
+        this.item.parent = this.parent;
+        // @ts-ignore
+        this.parent.update();
+    } // Function redo()
+
+    /**
+     * 撤销
+     *
+     * */
+    redo(): void {
+        this.item.parent = null;
+        // @ts-ignore
+        this.parent.update();
+    } // Function undo()
+} // Class SGraphAddCommand

+ 53 - 0
src/components/mapClass/SGraphDeleteListCommand.ts

@@ -0,0 +1,53 @@
+import { SGraphCommand } from "@saga-web/graph/lib/commands/SGraphCommand";
+import { SGraphItem } from "@saga-web/graph/lib/SGraphItem";
+import { SGraphScene } from "@saga-web/graph/lib/SGraphScene";
+import { SUndoCommand } from "@saga-web/base/lib";
+/**
+ * 多个item命令
+ *
+ * @author  han_yao_long
+ * */
+
+export class SGraphDeleteListCommand extends SGraphCommand {
+    /** 命令item对象    */
+    itemList: SGraphItem[];
+    /** 命令item的父类   */
+    parent: SGraphItem | null;
+    constructor(scene: SGraphScene, itemList: SGraphItem[]) {
+        super(scene);
+        this.itemList = itemList;
+        this.parent = itemList[0].parent;
+    }
+    /**
+   * 合并命令
+   *
+   * @return  boolean 是否已执行合并
+   * */
+    mergeWith(command: SUndoCommand): boolean {
+        return false;
+    } // Function mergeWith()
+
+    /**
+     * 重做
+     *
+     * */
+    undo(): void {
+        this.itemList.map((item) => {
+            item.parent = this.parent;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function redo()
+
+    /**
+     * 撤销
+     *
+     * */
+    redo(): void {
+        this.itemList.map((item) => {
+            item.parent = null;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function undo()
+}