xushiting 2 years ago
parent
commit
c38603a93e

+ 17 - 7
src/graphic/Controls/AddCircle.js

@@ -4,8 +4,8 @@ import { listenLayer } from "../ListenLayer";
 
 
 export default class AddCircle {
 export default class AddCircle {
   constructor() {
   constructor() {
+    this.newCircle = null;
     this.center = null;
     this.center = null;
-    this.radius = null;
   }
   }
 
 
   setCenter(value) {
   setCenter(value) {
@@ -13,18 +13,28 @@ export default class AddCircle {
     mathUtil.clonePoint(this.center, value);
     mathUtil.clonePoint(this.center, value);
   }
   }
 
 
-  setRadius(value) {
-    this.radius = value;
+  buildCircle(position) {
+    if (this.newCircle == null && !mathUtil.equalPoint(this.center, position)) {
+      const radius = mathUtil.getDistance(this.center, position);
+      this.newCircle = circleService.create(this.center, radius);
+    }
   }
   }
 
 
-  buildCircle() {
-    circleService.create(this.center, this.radius);
-    listenLayer.clear();
+  updateCircle(position) {
+    if (this.newCircle != null && !mathUtil.equalPoint(this.center, position)) {
+      this.newCircle.setRadius(mathUtil.getDistance(this.center, position));
+    }
+  }
+
+  finish(position) {
+    if (this.newCircle != null && mathUtil.equalPoint(this.center, position)) {
+      dataService.deleteLine(this.newLine.vectorId);
+    }
   }
   }
 
 
   clear() {
   clear() {
+    this.newCircle = null;
     this.center = null;
     this.center = null;
-    this.radius = null;
   }
   }
 }
 }
 
 

+ 48 - 44
src/graphic/Controls/AddLine.js

@@ -7,60 +7,62 @@ import { mathUtil } from "../Util/MathUtil";
 
 
 export default class AddLine {
 export default class AddLine {
   constructor() {
   constructor() {
+    this.newLine = null;
     this.startInfo = {};
     this.startInfo = {};
-    this.endInfo = {};
     this.baseLineId = null;
     this.baseLineId = null;
     this.category = VectorCategory.Line.NormalLine;
     this.category = VectorCategory.Line.NormalLine;
   }
   }
 
 
-  setPointInfo(dir, pointInfo) {
-    if (dir == "start") {
-      this.startInfo = {
-        position: {
-          x: pointInfo.x,
-          y: pointInfo.y,
-        },
-        linkedPointId: pointInfo.linkedPointId,
-        lineId: pointInfo.lineId,
-      };
-    } else if (dir == "end") {
-      this.endInfo = {
-        position: {
-          x: pointInfo.x,
-          y: pointInfo.y,
-        },
-        linkedPointId: pointInfo.linkedPointId,
-        lineId: pointInfo.lineId,
-      };
+  setPointInfo(pointInfo) {
+    this.startInfo = {
+      position: {
+        x: pointInfo.x,
+        y: pointInfo.y,
+      },
+      linkedPointId: pointInfo.linkedPointId,
+      lineId: pointInfo.lineId,
+    };
+  }
+
+  setNewLinePoint(position) {
+    if (listenLayer.modifyPoint) {
+      this.setPointInfo(listenLayer.modifyPoint);
+    } else {
+      this.setPointInfo(position);
+    }
+    return true;
+  }
+
+  buildLine(position) {
+    if (
+      this.newLine == null &&
+      !mathUtil.equalPoint(this.startInfo.position, position)
+    ) {
+      this.newLine = lineService.create(
+        this.startInfo.position,
+        position,
+        this.category
+      );
     }
     }
   }
   }
 
 
-  setNewLinePoint(dir, position) {
-    if (dir == "start") {
-      if (listenLayer.modifyPoint) {
-        this.setPointInfo(dir, listenLayer.modifyPoint);
-      } else {
-        this.setPointInfo(dir, position);
-      }
-      return true;
-    } else if (dir == "end") {
-      if (listenLayer.modifyPoint) {
-        this.setPointInfo(dir, listenLayer.modifyPoint);
-      } else {
-        this.setPointInfo(dir, position);
-      }
-      return true;
+  updateLine(position) {
+    if (
+      this.newLine != null &&
+      !mathUtil.equalPoint(this.startInfo.position, position)
+    ) {
+      let point = dataService.getPoint(this.newLine.endId);
+      point.setPosition(position);
     }
     }
-    return false;
   }
   }
 
 
-  buildLine() {
-    lineService.create(
-      this.startInfo.position,
-      this.endInfo.position,
-      this.category
-    );
-    listenLayer.clear();
+  finish(position) {
+    if (
+      this.newLine != null &&
+      mathUtil.equalPoint(this.startInfo.position, position)
+    ) {
+      dataService.deleteLine(this.newLine.vectorId);
+    }
   }
   }
 
 
   setCategory(value) {
   setCategory(value) {
@@ -76,8 +78,10 @@ export default class AddLine {
   }
   }
 
 
   clear() {
   clear() {
+    this.newLine = null;
     this.startInfo = {};
     this.startInfo = {};
-    this.endInfo = {};
+    this.baseLineId = null;
+    this.category = VectorCategory.Line.NormalLine;
   }
   }
 }
 }
 
 

+ 2 - 12
src/graphic/Controls/UIControl.js

@@ -143,11 +143,7 @@ export default class UIControl {
 
 
     const historyState = historyService.getHistoryState();
     const historyState = historyService.getHistoryState();
     this.graphicStateUI.canRevoke = historyState.pre;
     this.graphicStateUI.canRevoke = historyState.pre;
-    // if (historyState.pre) {
-    //     this.layer.$xui.toolbar.recall = true
-    // } else {
-    //     this.layer.$xui.toolbar.recall = false
-    // }
+    this.graphicStateUI.canRecovery = true;
 
 
     this.layer.stopAddVector();
     this.layer.stopAddVector();
     this.layer.renderer.autoRedraw();
     this.layer.renderer.autoRedraw();
@@ -161,12 +157,7 @@ export default class UIControl {
     const historyState = historyService.getHistoryState();
     const historyState = historyService.getHistoryState();
     this.graphicStateUI.canRecovery = historyState.next;
     this.graphicStateUI.canRecovery = historyState.next;
     this.graphicStateUI.canRevoke = true;
     this.graphicStateUI.canRevoke = true;
-    // if (historyState.next) {
-    //   this.layer.$xui.toolbar.recover = true;
-    // } else {
-    //   this.layer.$xui.toolbar.recover = false;
-    // }
-    // this.layer.$xui.toolbar.recall = true;
+
     this.layer.stopAddVector();
     this.layer.stopAddVector();
     this.layer.renderer.autoRedraw();
     this.layer.renderer.autoRedraw();
     this.layer.recoveryHistory();
     this.layer.recoveryHistory();
@@ -174,7 +165,6 @@ export default class UIControl {
 
 
   menu_backgroundImg(value) {
   menu_backgroundImg(value) {
     //
     //
-    this.graphicStateUI.canRevoke = !value;
   }
   }
 
 
   menu_clear() {
   menu_clear() {

+ 26 - 7
src/graphic/Layer.js

@@ -119,7 +119,7 @@ export default class Layer {
         break;
         break;
       case LayerEvents.AddLine:
       case LayerEvents.AddLine:
         stateService.setEventName(LayerEvents.AddingLine);
         stateService.setEventName(LayerEvents.AddingLine);
-        addLine.setNewLinePoint("start", position);
+        addLine.setNewLinePoint(position);
         break;
         break;
       case LayerEvents.AddCircle:
       case LayerEvents.AddCircle:
         stateService.setEventName(LayerEvents.AddingCircle);
         stateService.setEventName(LayerEvents.AddingCircle);
@@ -296,7 +296,13 @@ export default class Layer {
         break;
         break;
       case LayerEvents.AddingLine:
       case LayerEvents.AddingLine:
         needAutoRedraw = true;
         needAutoRedraw = true;
-        listenLayer.start(position);
+        let exceptLineId = null;
+        if (addLine.newLine != null) {
+          exceptLineId = addLine.newLine.vectorId;
+        }
+        listenLayer.start(position, {
+          exceptLineId: exceptLineId,
+        });
         if (listenLayer.modifyPoint) {
         if (listenLayer.modifyPoint) {
           position = {
           position = {
             x: listenLayer.modifyPoint.x,
             x: listenLayer.modifyPoint.x,
@@ -308,11 +314,20 @@ export default class Layer {
         elementService.setNewLine(addLine.startInfo.position, position);
         elementService.setNewLine(addLine.startInfo.position, position);
         elementService.setNewLineCategory(VectorCategory.Line.NormalLine);
         elementService.setNewLineCategory(VectorCategory.Line.NormalLine);
         elementService.showNewLine();
         elementService.showNewLine();
-        addLine.setNewLinePoint("end", position);
+
+        if (addLine.newLine == null) {
+          addLine.buildLine(position);
+        } else {
+          addLine.updateLine(position);
+        }
         break;
         break;
       case LayerEvents.AddingCircle:
       case LayerEvents.AddingCircle:
         needAutoRedraw = true;
         needAutoRedraw = true;
-        listenLayer.start(position);
+        let exceptCircleId = null;
+        if (addCircle.newCircle != null) {
+          exceptCircleId = addCircle.newCircle.vectorId;
+        }
+        listenLayer.start(position, { exceptCircleId: exceptCircleId });
         if (listenLayer.modifyPoint) {
         if (listenLayer.modifyPoint) {
           position = {
           position = {
             x: listenLayer.modifyPoint.x,
             x: listenLayer.modifyPoint.x,
@@ -321,7 +336,11 @@ export default class Layer {
         }
         }
         elementService.execute(addCircle.center, position);
         elementService.execute(addCircle.center, position);
         elementService.setPoint(position);
         elementService.setPoint(position);
-        addCircle.setRadius(mathUtil.getDistance(addCircle.center, position));
+        if (addCircle.newCircle == null) {
+          addCircle.buildCircle(position);
+        } else {
+          addCircle.updateCircle(position);
+        }
         break;
         break;
       case LayerEvents.MoveRoad:
       case LayerEvents.MoveRoad:
         needAutoRedraw = true;
         needAutoRedraw = true;
@@ -648,14 +667,14 @@ export default class Layer {
         break;
         break;
       case LayerEvents.AddingLine:
       case LayerEvents.AddingLine:
         needAutoRedraw = true;
         needAutoRedraw = true;
-        addLine.buildLine();
+        addLine.finish(position);
         addLine.clear();
         addLine.clear();
         this.history.save();
         this.history.save();
         elementService.hideAll();
         elementService.hideAll();
         break;
         break;
       case LayerEvents.AddingCircle:
       case LayerEvents.AddingCircle:
         needAutoRedraw = true;
         needAutoRedraw = true;
-        addCircle.buildCircle();
+        addCircle.finish(position);
         addCircle.clear();
         addCircle.clear();
         this.history.save();
         this.history.save();
         elementService.hideAll();
         elementService.hideAll();