xushiting 2 năm trước cách đây
mục cha
commit
b7d36d1527

+ 24 - 67
src/graphic/Controls/AddPoint.js

@@ -17,18 +17,34 @@ export default class AddPoint {
   }
 
   buildPoint(position) {
-    const newPoint = pointService.create(position);
-    if (newPoint.getCategory() == VectorCategory.Point.BasePoint) {
+    let newPoint;
+    if (Settings.pointCategory == VectorCategory.Point.BasePoint) {
+      newPoint = pointService.create(position);
       Settings.selectBasePointId = newPoint.vectorId;
     } else {
-      if (Settings.locationMode == Constant.angleLocationMode) {
+      if (
+        Settings.selectBasePointId != null &&
+        Settings.locationMode == Constant.angleLocationMode
+      ) {
+        newPoint = pointService.create(position);
         this.setLocationByAngle(newPoint.vectorId);
-      } else if (Settings.locationMode == Constant.allLocationMode) {
+        newPoint.setLocationMode(Constant.angleLocationMode);
+      } else if (
+        Settings.selectBasePointId != null &&
+        Settings.locationMode == Constant.allLocationMode
+      ) {
+        newPoint = pointService.create(position);
         this.setLocationByAll(newPoint.vectorId);
+        newPoint.setLocationMode(Constant.allLocationMode);
       } else if (Settings.locationMode == Constant.normalLocationMode) {
+        newPoint = pointService.create(position);
         this.setLocationByNormal(newPoint.vectorId);
+        newPoint.setLocationMode(Constant.normalLocationMode);
       }
-      if (newPoint.getCategory() == VectorCategory.Point.TestPoint) {
+      if (
+        newPoint &&
+        newPoint.getCategory() == VectorCategory.Point.TestPoint
+      ) {
         this.testPointIds.push(newPoint.vectorId);
       }
     }
@@ -50,10 +66,8 @@ export default class AddPoint {
   setLocationByAngle(testPointId) {
     let basePoint = this.isFocusBasePoint();
     if (!basePoint) {
-      console.error("没有基准点");
       return;
     }
-    console.error("选中基准点:" + basePoint.vectorId);
     let testPoint = dataService.getPoint(testPointId);
     if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
       return;
@@ -67,6 +81,7 @@ export default class AddPoint {
     let join = mathUtil.getJoinLinePoint(basePoint, vLine);
     join = pointService.create(join);
     join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLocationMode(Constant.angleLocationMode);
     join.setLinkedBasePointId(basePoint.vectorId);
     join.setLinkedTestPointId(testPointId);
     lineService.createByPointId(
@@ -82,38 +97,6 @@ export default class AddPoint {
     );
   }
 
-  //待测基准点,待测点与基准线相交的点
-  getTestBasePoint(basePointId, testPointId) {
-    let points = dataService.getPoints();
-    for (let key in points) {
-      const point = dataService.getPoint(key);
-      if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
-        if (
-          point.getLinkedBasePointId() == basePointId &&
-          point.getLinkedTestPointId() == testPointId
-        ) {
-          return point;
-        }
-      }
-    }
-    return null;
-  }
-
-  //更新待测点(直角定位法)
-  updateTestPointByAngle(testPointId, newPosition) {
-    let testPoint = dataService.getPoint(testPointId);
-    mathUtil.clonePoint(testPoint, newPosition);
-    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(Settings.baseLineId);
-    let startPoint = dataService.getPoint(lineGeometry.startId);
-    let endPoint = dataService.getPoint(lineGeometry.endId);
-    let line = mathUtil.createLine1(startPoint, endPoint);
-    let vLine = mathUtil.getVerticalLine(line, testPoint);
-    let join = mathUtil.getJoinLinePoint(basePoint, vLine);
-    let testBasePoint = this.getTestBasePoint(basePoint.vectorId, testPointId);
-    mathUtil.clonePoint(testBasePoint, join);
-  }
-
   //综合定位法
   setLocationByAll(testPointId) {
     let basePoint = this.isFocusBasePoint();
@@ -130,6 +113,7 @@ export default class AddPoint {
     let join = mathUtil.getJoinLinePoint(testPoint, line);
     join = pointService.create(join); //经过待测点且与基准线垂直的线段,与基准线的交点
     join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLocationMode(Constant.allLocationMode);
     join.setLinkedBasePointId(basePoint.vectorId);
     join.setLinkedTestPointId(testPointId);
     //待测点与基准线的垂直线
@@ -159,20 +143,6 @@ export default class AddPoint {
     }
   }
 
-  //更新待测点(综合定位法)
-  updateTestPointByAll(testPointId, newPosition) {
-    let testPoint = dataService.getPoint(testPointId);
-    mathUtil.clonePoint(testPoint, newPosition);
-    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(Settings.baseLineId);
-    let startPoint = dataService.getPoint(lineGeometry.startId);
-    let endPoint = dataService.getPoint(lineGeometry.endId);
-    let line = mathUtil.createLine1(startPoint, endPoint);
-    let join = getJoinLinePoint(testPoint, line);
-    let testBasePoint = this.getTestBasePoint(basePoint.vectorId, testPointId);
-    mathUtil.clonePoint(testBasePoint, join);
-  }
-
   setLocationByNormal(testPointId) {
     let testPoint = dataService.getPoint(testPointId);
     if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
@@ -186,6 +156,7 @@ export default class AddPoint {
     let join = mathUtil.getIntersectionPoint(vLine, line);
     join = pointService.create(join);
     join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLocationMode(Constant.normalLocationMode);
     join.setLinkedTestPointId(testPointId);
     lineService.createByPointId(
       testPointId,
@@ -193,20 +164,6 @@ export default class AddPoint {
       VectorCategory.Line.PositionLine
     );
   }
-
-  //更新待测点(自由定位法)
-  updateTestPointByNormal(testPointId, newPosition) {
-    let testPoint = dataService.getPoint(testPointId);
-    mathUtil.clonePoint(testPoint, newPosition);
-    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
-    let lineGeometry = dataService.getLine(Settings.baseLineId);
-    let startPoint = dataService.getPoint(lineGeometry.startId);
-    let endPoint = dataService.getPoint(lineGeometry.endId);
-    let line = mathUtil.createLine1(startPoint, endPoint);
-    let join = getJoinLinePoint(testPoint, line);
-    let testBasePoint = this.getTestBasePoint(basePoint.vectorId, testPointId);
-    mathUtil.clonePoint(testBasePoint, join);
-  }
 }
 
 const addPoint = new AddPoint();

+ 88 - 55
src/graphic/Controls/MovePoint.js

@@ -1,8 +1,11 @@
 import { dataService } from "../Service/DataService";
 import { pointService } from "../Service/PointService";
 import Settings from "../Settings";
+import Constant from "../Constant";
 import VectorCategory from "../enum/VectorCategory";
 import { listenLayer } from "../ListenLayer";
+import { uiService } from "../Service/UIService";
+import { mathUtil } from "../Util/MathUtil";
 
 export default class MovePoint {
   constructor() {}
@@ -11,6 +14,11 @@ export default class MovePoint {
     let point = dataService.getPoint(pointId);
     point.x = position.x;
     point.y = position.y;
+    if (point.getCategory() == VectorCategory.Point.TestPoint) {
+      this.updatePositionByTestPoint(pointId);
+    } else if (point.getCategory() == VectorCategory.Point.BasePoint) {
+      this.updateBasePoint(pointId);
+    }
   }
 
   finish(pointId) {
@@ -29,80 +37,105 @@ export default class MovePoint {
         category != VectorCategory.Point.TestPoint
       ) {
         pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId);
+        Settings.selectBasePointId = null;
       } else if (category == VectorCategory.Point.BasePoint) {
         Settings.selectBasePointId = pointId;
+      } else {
+        Settings.selectBasePointId = null;
+      }
+    }
+  }
+
+  //待测基准点,待测点与基准线相交的点
+  getTestBasePoint(basePointId, testPointId, locationMode) {
+    let points = dataService.getPoints();
+    for (let key in points) {
+      const point = dataService.getPoint(key);
+      if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
+        if (
+          point.getLinkedBasePointId() == basePointId &&
+          point.getLinkedTestPointId() == testPointId &&
+          point.getLocationMode() == locationMode
+        ) {
+          return point;
+        }
       }
     }
+    return null;
   }
 
-  //直角定位法
-  //movePointForLocationByAngle(testPointId, basePointId) {
-  movePointByAngleLocation(pointId) {
-    if (testPointId == null || basePointId == null) {
-      return null;
+  updatePositionByTestPoint(pointId) {
+    let point = dataService.getPoint(pointId);
+    let locationMode = point.getLocationMode();
+    if (locationMode == Constant.angleLocationMode) {
+      this.updateTestPointByAngle(pointId);
+    } else if (locationMode == Constant.allLocationMode) {
+      this.updateTestPointByAll(pointId);
+    } else if (locationMode == Constant.normalLocationMode) {
+      this.updateTestPointByNormal(pointId);
     }
+  }
+
+  //更新待测点(直角定位法)
+  updateTestPointByAngle(testPointId) {
     let testPoint = dataService.getPoint(testPointId);
-    let basePoint = dataService.getPoint(basePointId);
+    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
     let lineGeometry = dataService.getLine(Settings.baseLineId);
     let startPoint = dataService.getPoint(lineGeometry.startId);
     let endPoint = dataService.getPoint(lineGeometry.endId);
     let line = mathUtil.createLine1(startPoint, endPoint);
-    let vLine1 = mathUtil.getVerticalLine(line, testPoint);
-    let join = mathUtil.getJoinLinePoint(basePoint, vLine1);
-    join = pointService.create(join);
-
-    lineService.createByPointId(
+    let vLine = mathUtil.getVerticalLine(line, testPoint);
+    let join = mathUtil.getJoinLinePoint(basePoint, vLine);
+    let testBasePoint = this.getTestBasePoint(
+      basePoint.vectorId,
       testPointId,
-      join.vectorId,
-      VectorCategory.Line.PositionLine
+      Constant.angleLocationMode
     );
+    mathUtil.clonePoint(testBasePoint, join);
+  }
 
-    lineService.createByPointId(
-      basePointId,
-      join.vectorId,
-      VectorCategory.Line.PositionLine
+  //更新待测点(综合定位法)
+  updateTestPointByAll(testPointId) {
+    let testPoint = dataService.getPoint(testPointId);
+    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
+    let startPoint = dataService.getPoint(lineGeometry.startId);
+    let endPoint = dataService.getPoint(lineGeometry.endId);
+    let line = mathUtil.createLine1(startPoint, endPoint);
+    let join = mathUtil.getJoinLinePoint(testPoint, line);
+    let testBasePoint = this.getTestBasePoint(
+      basePoint.vectorId,
+      testPointId,
+      Constant.allLocationMode
     );
+    mathUtil.clonePoint(testBasePoint, join);
   }
 
-  //综合定位法
-  movePointForLocationByFull(testPointId1, testPointId2, basePointId) {
-    if (testPointId1 == null || basePointId == null) {
-      return null;
-    } else {
-      let testPoint1 = dataService.getPoint(testPointId1);
-      let lineGeometry = dataService.getLine(Settings.baseLineId);
-      let startPoint = dataService.getPoint(lineGeometry.startId);
-      let endPoint = dataService.getPoint(lineGeometry.endId);
-      let line = mathUtil.createLine1(startPoint, endPoint);
-      if (testPointId2 == null) {
-        let join = mathUtil.getJoinLinePoint(testPoint1, line);
-        join = pointService.create(join);
-        lineService.createByPointId(
-          testPointId1,
-          join.vectorId,
-          VectorCategory.Line.PositionLine
-        );
-
-        lineService.createByPointId(
-          basePointId,
-          testPointId1,
-          VectorCategory.Line.PositionLine
-        );
-      } else {
-        let testPoint2 = dataService.getPoint(testPointId2);
-        let join = mathUtil.getJoinLinePoint(testPoint2, line);
-        join = pointService.create(join);
-        lineService.createByPointId(
-          testPointId2,
-          join.vectorId,
-          VectorCategory.Line.PositionLine
-        );
+  //更新待测点(自由定位法)
+  updateTestPointByNormal(testPointId) {
+    let testPoint = dataService.getPoint(testPointId);
+    let lineGeometry = dataService.getLine(Settings.baseLineId);
+    let startPoint = dataService.getPoint(lineGeometry.startId);
+    let endPoint = dataService.getPoint(lineGeometry.endId);
+    let line = mathUtil.createLine1(startPoint, endPoint);
+    let join = mathUtil.getJoinLinePoint(testPoint, line);
+    let testBasePoint = this.getTestBasePoint(
+      null,
+      testPointId,
+      Constant.normalLocationMode
+    );
+    mathUtil.clonePoint(testBasePoint, join);
+  }
 
-        lineService.createByPointId(
-          testPointId2,
-          testPointId1,
-          VectorCategory.Line.PositionLine
-        );
+  updateBasePoint(basePointId) {
+    let points = dataService.getPoints();
+    for (let key in points) {
+      let point = dataService.getPoint(key);
+      if (
+        point.getCategory() == VectorCategory.Point.TestPoint &&
+        point.getLinkedBasePointId() == basePointId
+      ) {
+        this.updatePositionByTestPoint(key);
       }
     }
   }

+ 9 - 0
src/graphic/Geometry/Point.js

@@ -11,6 +11,7 @@ export default class Point extends Geometry {
     this.parent = {};
     this.linkedBasePointId = null; //关联基准点
     this.linkedTestPointId = null; //关联待测点
+    this.locationMode = null; //如果该点是待测点,采用的定位法是哪种
     this.category = Settings.pointCategory;
     this.geoType = VectorType.Point;
     this.setId(vectorId);
@@ -51,4 +52,12 @@ export default class Point extends Geometry {
       this.category = value;
     }
   }
+
+  setLocationMode(value) {
+    this.locationMode = value;
+  }
+
+  getLocationMode() {
+    return this.locationMode;
+  }
 }

+ 4 - 0
src/graphic/History/HistoryUtil.js

@@ -20,6 +20,7 @@ export default class HistoryUtil {
       point1.y == point2.y &&
       JSON.stringify(point1.parent) == JSON.stringify(point2.parent) &&
       point1.category == point2.category &&
+      point1.locationMode == point2.locationMode &&
       point1.linkedBasePointId == point2.linkedBasePointId &&
       point1.linkedTestPointId == point2.linkedTestPointId
     ) {
@@ -166,6 +167,7 @@ export default class HistoryUtil {
     pointInfo.vectorId = point1.vectorId;
     pointInfo.position = { x: point2.x, y: point2.y };
     pointInfo.parent = JSON.parse(JSON.stringify(point2.parent));
+    pointInfo.locationMode = point2.locationMode;
     pointInfo.linkedBasePointId = point2.linkedBasePointId;
     pointInfo.linkedTestPointId = point2.linkedTestPointId;
     pointInfo.category = point2.category;
@@ -292,6 +294,7 @@ export default class HistoryUtil {
     mathUtil.clonePoint(data, point);
     data.parent = JSON.parse(JSON.stringify(point.parent));
     data.category = point.category;
+    data.locationMode = point.locationMode;
     data.linkedBasePointId = point.linkedBasePointId;
     data.linkedTestPointId = point.linkedTestPointId;
     data.type = point.geoType;
@@ -419,6 +422,7 @@ export default class HistoryUtil {
     mathUtil.clonePoint(point, pointInfo.position);
     point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
     point.category = pointInfo.category;
+    point.locationMode = pointInfo.locationMode;
     point.linkedBasePointId = pointInfo.linkedBasePointId;
     point.linkedTestPointId = pointInfo.linkedTestPointId;
     return point;

+ 16 - 9
src/graphic/Layer.js

@@ -140,11 +140,14 @@ export default class Layer {
       case LayerEvents.AddPoint:
         stateService.setEventName(LayerEvents.MovePoint);
         const newPoint = addPoint.buildPoint(position);
-        stateService.setSelectItem(
-          newPoint.vectorId,
-          VectorType.Point,
-          SelectState.Select
-        );
+        if (newPoint) {
+          stateService.setSelectItem(
+            newPoint.vectorId,
+            VectorType.Point,
+            SelectState.Select
+          );
+        }
+
         break;
       case LayerEvents.AddCircle:
         stateService.setEventName(LayerEvents.AddingCircle);
@@ -238,16 +241,18 @@ export default class Layer {
       x: position.x,
       y: position.y,
     };
+    const eventName = stateService.getEventName();
     if (
       Math.abs(X - this.startX) > minDragDis ||
       Math.abs(Y - this.startY) > minDragDis
     ) {
       // 是否拖拽了
       this.dragging = true;
+      if (eventName != null) {
+        stateService.clearFocusItem();
+        this.uiControl.focusVector = null;
+      }
     }
-
-    const eventName = stateService.getEventName();
-
     // 是否需要重绘
     let needAutoRedraw = false;
     let point = null;
@@ -819,7 +824,9 @@ export default class Layer {
         break;
       case LayerEvents.MovePoint:
         needAutoRedraw = true;
-        movePoint.finish(draggingItem.vectorId);
+        if (draggingItem && draggingItem.vectorId) {
+          movePoint.finish(draggingItem.vectorId);
+        }
         this.history.save();
         break;
       case LayerEvents.MoveCircle:

+ 10 - 0
src/graphic/ListenLayer.js

@@ -10,6 +10,7 @@ import { elementService } from "./Service/ElementService";
 import { coordinate } from "./Coordinate";
 import { draw } from "./Renderer/Draw.js";
 import { edgeService } from "./Service/EdgeService";
+import VectorCategory from "./enum/VectorCategory";
 
 export default class ListenLayer {
   constructor() {
@@ -100,6 +101,9 @@ export default class ListenLayer {
         continue;
       }
       const point = dataService.getPoint(pointId);
+      if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
+        continue;
+      }
       const distance = mathUtil.getDistance(position, point);
       if (distance < Constant.minAdsorbPix) {
         if (pointInfo.pointId == null) {
@@ -163,6 +167,12 @@ export default class ListenLayer {
         continue;
       }
       const line = dataService.getLine(lineId);
+      if (
+        line.getCategory() == VectorCategory.Line.PositionLine ||
+        line.getCategory() == VectorCategory.Line.BaseLine
+      ) {
+        continue;
+      }
       let startPoint = dataService.getPoint(line.startId);
       let endPoint = dataService.getPoint(line.endId);
       const comLine = mathUtil.createLine1(startPoint, endPoint);

+ 4 - 0
src/graphic/Service/UIService.js

@@ -150,6 +150,10 @@ export default class UIService {
     Settings.locationMode = value;
   }
 
+  getLocationMode() {
+    return Settings.locationMode;
+  }
+
   //如果position在屏幕左上角,返回的就朝向右下角,如果是右下角,则返回的是左上角。其他情况以此类推
   getNewPositionForPop(position) {
     const offset = 50;