Explorar o código

undo redo部分功能失效

YaolongHan %!s(int64=4) %!d(string=hai) anos
pai
achega
31576044c4
Modificáronse 1 ficheiros con 38 adicións e 34 borrados
  1. 38 34
      src/components/mapClass/EditScence.ts

+ 38 - 34
src/components/mapClass/EditScence.ts

@@ -106,7 +106,6 @@ export class EditScence extends SGraphScene {
         ItemColor.virtualWallColor = new SColor("#d4d4d4")
         ItemColor.selectColor = new SColor("#f0f0f0")
         ItemColor.spaceBorderColor = new SColor("#d4d4d4");
-        console.log('isMac', this.isMac)
     }
     /** 绘制图例样式 */
     _legend: any | null = null;
@@ -263,7 +262,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;
         }
@@ -406,6 +405,7 @@ export class EditScence extends SGraphScene {
         this.Markers.push(item);
         this.grabItem == null;
         this.focusItem = item;
+        this.undoStack.push(new SGraphAddCommand(this, item));
         this.finishCreated(item);
         this.scenceUpdate(this);
     }
@@ -442,6 +442,7 @@ export class EditScence extends SGraphScene {
         this.focusItem = item;
         this.cmd = 'choice';
         this.finishCreated(item);
+        this.undoStack.push(new SGraphAddCommand(this, item));
         this.scenceUpdate(this);
     }
 
@@ -489,6 +490,7 @@ export class EditScence extends SGraphScene {
         this.grabItem = null;
         this.focusItem = item;
         this.finishCreated(item);
+        this.undoStack.push(new SGraphAddCommand(this, item));
         this.scenceUpdate(this);
         if (event.ctrlKey) {
             this.cmd = cmd;
@@ -960,6 +962,7 @@ export class EditScence extends SGraphScene {
         } else {
             this.undoStack.redo();
             this.scenceUpdate(this);
+            // console.log(this.undoStack.command(this.undoStack.index))
         }
 
     }
@@ -971,6 +974,7 @@ export class EditScence extends SGraphScene {
         if (this.grabItem && this.grabItem.undo) {
             this.grabItem.undo()
         } else {
+            // console.log(this.undoStack.command(this.undoStack.index))
             this.undoStack.undo();
             this.scenceUpdate(this);
         }
@@ -1234,18 +1238,18 @@ export class EditScence extends SGraphScene {
         // 不需要复制区域
         parserData.zoneLegendList.forEach(t => {
             // if (t instanceof SCustomLegendItem) {
-                if (this.view) {
-                    t.pos.x += 10 / this.view.scale
-                    t.pos.y += 10 / this.view.scale
-                }
-                t.moveable = true;
-                this.addItem(t)
-                this.Nodes.push(t);
-                this.selectContainer.toggleItem(t);
-                graphItemList.push(t)
+            if (this.view) {
+                t.pos.x += 10 / this.view.scale
+                t.pos.y += 10 / this.view.scale
+            }
+            t.moveable = true;
+            this.addItem(t)
+            this.Nodes.push(t);
+            this.selectContainer.toggleItem(t);
+            graphItemList.push(t)
             // }
-         // 加到node
-         // 加命令
+            // 加到node
+            // 加命令
         })
         parserData.imageLegendList.forEach(t => {
             if (this.view) {
@@ -1324,18 +1328,18 @@ export class EditScence extends SGraphScene {
             // 不需要复制区域
             parserData.zoneLegendList.forEach(t => {
                 // if (t instanceof SCustomLegendItem) {
-                    if (this.view) {
-                        t.pos.x += 10 / this.view.scale
-                        t.pos.y += 10 / this.view.scale
-                    }
-                    t.moveable = true;
-                    this.addItem(t)
-                    this.Nodes.push(t);
-                    this.selectContainer.toggleItem(t);
-                    graphItemList.push(t)
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Nodes.push(t);
+                this.selectContainer.toggleItem(t);
+                graphItemList.push(t)
                 // }
-             // 加到node
-             // 加命令
+                // 加到node
+                // 加命令
             })
             parserData.imageLegendList.forEach(t => {
                 if (this.view) {
@@ -1395,7 +1399,7 @@ export class EditScence extends SGraphScene {
             })
             this.scenceUpdate(this);
             if (graphItemList.length) {
-                this.AddListCommand(graphItemList)
+                this.AddListCommand(graphItemList);
             }
         } catch (e) {
             console.log(e);
@@ -1404,15 +1408,15 @@ export class EditScence extends SGraphScene {
 
     /** 同类选中    */
     selectSimilar() {
-        let typeList = [...new Set(this.selectContainer.itemList.map(item => {return item.data.GraphElementId}).filter(d => {return d}))];
+        let typeList = [...new Set(this.selectContainer.itemList.map(item => { return item.data.GraphElementId }).filter(d => { return d }))];
         this.selectContainer.clear();
         this.Nodes.forEach(item => {
-            if(typeList.indexOf(item.data.GraphElementId) != -1)
-            this.selectContainer.toggleItem(item);
+            if (typeList.indexOf(item.data.GraphElementId) != -1)
+                this.selectContainer.toggleItem(item);
         });
         this.Relations.forEach(item => {
-            if(typeList.indexOf(item.data.GraphElementId) != -1)
-            this.selectContainer.toggleItem(item);
+            if (typeList.indexOf(item.data.GraphElementId) != -1)
+                this.selectContainer.toggleItem(item);
         });
         document.getElementById(`canvas`).focus();
     }
@@ -1474,7 +1478,7 @@ export class EditScence extends SGraphScene {
                 if (this.grabItem.status == SItemStatus.Create) {
                     if (this.grabItem.pointList.length) {
                         this.grabItem.endAnchor = anc;
-                        anc.parent ?.connect('changePos', this.grabItem, this.grabItem.changePos)
+                        anc.parent?.connect('changePos', this.grabItem, this.grabItem.changePos)
                     }
                     this.grabItem.anchor2ID = anc.id
                     this.grabItem.node2Id = anc.parent.id
@@ -1568,7 +1572,7 @@ export class EditScence extends SGraphScene {
                 if (this.grabItem.status == SItemStatus.Create) {
                     // 点击在item内、创建状态且端点列表不为空时将直线结束端点和item绑定
                     if (this.grabItem.line.length) {
-                        if (this.grabItem.startItem ?.id == item.id) {
+                        if (this.grabItem.startItem?.id == item.id) {
                             this.grabItem.endItem = null;
                         } else {
                             this.grabItem.endItem = item;
@@ -1582,7 +1586,7 @@ export class EditScence extends SGraphScene {
                     // 点击在item内、编辑状态且点击的为结束端点时
                     if (this.grabItem.curIndex == 1) {
                         // 直线关联的起始item是直线结束端点所在的item时,不吸附在点击item中心并将直线关联的结束item置为null
-                        if (this.grabItem.startItem ?.id == item.id) {
+                        if (this.grabItem.startItem?.id == item.id) {
                             this.grabItem.endItem = null;
                         } else {// 反正吸附,关联
                             this.grabItem.endItem = item;
@@ -1590,7 +1594,7 @@ export class EditScence extends SGraphScene {
                             item.connect('onMove', this.grabItem, this.grabItem.changePos);
                         }
                     } else if (this.grabItem.curIndex == 0) {
-                        if (this.grabItem.endItem ?.id == item.id) {
+                        if (this.grabItem.endItem?.id == item.id) {
                             this.grabItem.startItem = null;
                         } else {
                             this.grabItem.startItem = item;