浏览代码

修改线条

xushiting 2 年之前
父节点
当前提交
0d7b8eb8b5

+ 10 - 11
src/graphic/Controls/AddLine.js

@@ -10,7 +10,6 @@ export default class AddLine {
   constructor() {
     this.newLine = null;
     this.startInfo = {};
-    this.baseLineId = null;
   }
 
   setPointInfo(pointInfo) {
@@ -58,27 +57,27 @@ export default class AddLine {
       mathUtil.equalPoint(this.startInfo.position, position)
     ) {
       dataService.deleteLine(this.newLine.vectorId);
+    } else if (
+      listenLayer.modifyPoint &&
+      listenLayer.modifyPoint.linkedPointId &&
+      this.newLine.getCategory() != VectorCategory.Line.ArrowLine &&
+      this.newLine.getCategory() != VectorCategory.Line.GuideLine
+    ) {
+      lineService.mergePoint(
+        this.newLine.endId,
+        listenLayer.modifyPoint.linkedPointId
+      );
     }
   }
 
-  setBaseLineId(baseLineId) {
-    this.baseLineId = baseLineId;
-  }
-
-  getBaseLineId() {
-    return this.baseLineId;
-  }
-
   clearVectorData() {
     this.newLine = null;
     this.startInfo = {};
-    this.baseLineId = null;
   }
 
   clear() {
     this.newLine = null;
     this.startInfo = {};
-    this.baseLineId = null;
   }
 }
 

+ 6 - 6
src/graphic/Controls/AddPoint.js

@@ -58,7 +58,7 @@ export default class AddPoint {
       return;
     }
     testPoint.setLinkedBasePointId(basePoint.vectorId);
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -103,7 +103,7 @@ export default class AddPoint {
     let testPoint = dataService.getPoint(testPointId);
     mathUtil.clonePoint(testPoint, newPosition);
     let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -122,7 +122,7 @@ export default class AddPoint {
 
     let testPoint = dataService.getPoint(testPointId);
     testPoint.setLinkedBasePointId(basePoint.vectorId);
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -163,7 +163,7 @@ export default class AddPoint {
     let testPoint = dataService.getPoint(testPointId);
     mathUtil.clonePoint(testPoint, newPosition);
     let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -177,7 +177,7 @@ export default class AddPoint {
     if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
       return;
     }
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -198,7 +198,7 @@ export default class AddPoint {
     let testPoint = dataService.getPoint(testPointId);
     mathUtil.clonePoint(testPoint, newPosition);
     let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);

+ 3 - 3
src/graphic/Controls/MovePoint.js

@@ -1,5 +1,5 @@
 import { dataService } from "../Service/DataService";
-
+import Settings from "../Settings";
 export default class MovePoint {
   constructor() {}
 
@@ -17,7 +17,7 @@ export default class MovePoint {
     }
     let testPoint = dataService.getPoint(testPointId);
     let basePoint = dataService.getPoint(basePointId);
-    let lineGeometry = dataService.getLine(addLine.baseLineId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
@@ -44,7 +44,7 @@ export default class MovePoint {
       return null;
     } else {
       let testPoint1 = dataService.getPoint(testPointId1);
-      let lineGeometry = dataService.getLine(addLine.baseLineId);
+      let lineGeometry = dataService.getLine(Settings.baseLineId);
       let startPoint = dataService.getPoint(lineGeometry.startId);
       let endPoint = dataService.getPoint(lineGeometry.endId);
       let line = mathUtil.createLine1(startPoint, endPoint);

+ 5 - 1
src/graphic/Layer.js

@@ -355,11 +355,14 @@ export default class Layer {
       case LayerEvents.AddingLine:
         needAutoRedraw = true;
         let exceptLineId = null;
+        let exceptPointId = null;
         if (addLine.newLine != null) {
           exceptLineId = addLine.newLine.vectorId;
+          exceptPointId = addLine.newLine.endId;
         }
         listenLayer.start(position, {
           exceptLineId: exceptLineId,
+          exceptPointId: exceptPointId,
         });
         if (listenLayer.modifyPoint) {
           position = {
@@ -751,6 +754,7 @@ export default class Layer {
       case LayerEvents.AddingLine:
         needAutoRedraw = true;
         addLine.finish(position);
+        this.updateForLocation();
         addLine.clearVectorData();
         this.history.save();
         elementService.hideAll();
@@ -1118,7 +1122,7 @@ export default class Layer {
       Settings.baseLineId = addLine.newLine.vectorId;
       this.uiControl.graphicStateUI.canAngleLocationMode = true;
       this.uiControl.graphicStateUI.canAllLocationMode = true;
-      this.uiControl.graphicState.existsBaseLine = true;
+      this.uiControl.graphicStateUI.existsBaseLine = true;
     }
   }
 }

+ 15 - 10
src/graphic/Service/DataService.js

@@ -134,18 +134,23 @@ export class DataService {
   deleteLine(lineId) {
     let line = this.getLine(lineId);
     let start = this.getPoint(line.startId);
-    let startParent = start.getParent();
-    let end = this.getPoint(line.endId);
-    let endParent = end.getParent();
-
-    delete startParent[lineId];
-    if (Object.keys(startParent).length == 0) {
-      this.deletePoint(line.startId);
+    if (start) {
+      let startParent = start.getParent();
+      delete startParent[lineId];
+      if (Object.keys(startParent).length == 0) {
+        this.deletePoint(line.startId);
+      }
     }
-    delete endParent[lineId];
-    if (Object.keys(endParent).length == 0) {
-      this.deletePoint(line.endId);
+
+    let end = this.getPoint(line.endId);
+    if (end) {
+      let endParent = end.getParent();
+      delete endParent[lineId];
+      if (Object.keys(endParent).length == 0) {
+        this.deletePoint(line.endId);
+      }
     }
+
     delete this.vectorData.lines[lineId];
   }
 

+ 21 - 20
src/graphic/Service/LineService.js

@@ -56,7 +56,7 @@ export default class LineService {
           dataService.deletePoint(key);
         }
       }
-      addLine.baseLineId = null;
+      Settings.baseLineId = null;
     }
     dataService.deleteLine();
   }
@@ -73,25 +73,26 @@ export default class LineService {
   }
 
   //将pointId1合并到pointId2
-  // mergePoint(pointId1, pointId2) {
-  //   let point1 = dataService.getPoint(pointId1);
-  //   let parent1 = point1.getParent();
-  //   let point2 = dataService.getPoint(pointId2);
-  //   let parent2 = point2.getParent();
-  //   for (let key in parent1) {
-  //     let line = dataService.getLine(key);
-  //     let dir = line.getDir(pointId1);
-  //     if (dir == "start") {
-  //       line.startId = pointId2;
-  //     } else if (dir == "end") {
-  //       line.endId = pointId2;
-  //     }
-  //     if(parent2.hasOwnProperty(''))
-  //   }
-  //   let point2 = dataService.getPoint(pointId2);
-  //   let parent2 = point2.getParent();
-  //   if(parent2.haso)
-  // }
+  mergePoint(pointId1, pointId2) {
+    if (pointId1 == pointId2) {
+      return;
+    } else if (pointId1 != null && pointId2 != null) {
+      let point1 = dataService.getPoint(pointId1);
+      let parent1 = point1.getParent();
+      let point2 = dataService.getPoint(pointId2);
+      for (let key in parent1) {
+        let line = dataService.getLine(key);
+        let dir = line.getDir(pointId1);
+        if (dir == "start") {
+          line.startId = pointId2;
+        } else if (dir == "end") {
+          line.endId = pointId2;
+        }
+        point2.setPointParent(key, dir);
+      }
+      dataService.deletePoint(pointId1);
+    }
+  }
 }
 
 const lineService = new LineService();