xushiting 2 anos atrás
pai
commit
60cced76cb

+ 90 - 27
src/graphic/Controls/AddPoint.js

@@ -1,16 +1,16 @@
-import { dataService } from '../Service/DataService';
-import { lineService } from '../Service/LineService';
-import { pointService } from '../Service/PointService';
-import VectorCategory from '../enum/VectorCategory';
-import Point from '../Geometry/Point.js';
-import { mathUtil } from '../Util/MathUtil';
-import addLine from './AddLine';
-import Settings from '../Settings';
-import { stateService } from '../Service/StateService';
-import LayerEvents from '../enum/LayerEvents';
-import VectorType from '../enum/VectorType';
-import Constant from '../Constant';
-import { listenLayer } from '../ListenLayer';
+import { dataService } from "../Service/DataService";
+import { lineService } from "../Service/LineService";
+import { pointService } from "../Service/PointService";
+import VectorCategory from "../enum/VectorCategory";
+import Point from "../Geometry/Point.js";
+import { mathUtil } from "../Util/MathUtil";
+import addLine from "./AddLine";
+import Settings from "../Settings";
+import { stateService } from "../Service/StateService";
+import LayerEvents from "../enum/LayerEvents";
+import VectorType from "../enum/VectorType";
+import Constant from "../Constant";
+import { listenLayer } from "../ListenLayer";
 
 export default class AddPoint {
   constructor() {
@@ -19,7 +19,11 @@ export default class AddPoint {
 
   buildPoint(position) {
     //只有一个基准点的时候,测量的时候自动选择基准点
-    if ((Settings.selectLocationMode == Constant.angleLocationMode || Settings.selectLocationMode == Constant.allLocationMode) && Settings.basePointIds.length == 1) {
+    if (
+      (Settings.selectLocationMode == Constant.angleLocationMode ||
+        Settings.selectLocationMode == Constant.allLocationMode) &&
+      Settings.basePointIds.length == 1
+    ) {
       Settings.selectBasePointId = Settings.basePointIds[0];
     }
     let newPoint;
@@ -27,28 +31,43 @@ export default class AddPoint {
       newPoint = pointService.create(position);
       Settings.selectBasePointId = newPoint.vectorId;
     } else {
-      if (Settings.selectBasePointId != null && Settings.selectLocationMode == Constant.angleLocationMode) {
+      if (
+        Settings.selectBasePointId != null &&
+        Settings.selectLocationMode == Constant.angleLocationMode
+      ) {
         newPoint = pointService.create(position);
         this.setLocationByAngle(newPoint.vectorId);
         newPoint.setLocationMode(Constant.angleLocationMode);
         stateService.setEventName(LayerEvents.AddPoint);
-      } else if (Settings.selectBasePointId != null && Settings.selectLocationMode == Constant.allLocationMode) {
+      } else if (
+        Settings.selectBasePointId != null &&
+        Settings.selectLocationMode == Constant.allLocationMode
+      ) {
         newPoint = pointService.create(position);
         this.setLocationByAll(newPoint.vectorId);
         newPoint.setLocationMode(Constant.allLocationMode);
         stateService.setEventName(LayerEvents.AddPoint);
-      } else if (Settings.baseLineId != null && Settings.selectLocationMode == Constant.normalLocationMode) {
+      } else if (
+        Settings.baseLineId != null &&
+        Settings.selectLocationMode == Constant.normalLocationMode
+      ) {
         newPoint = pointService.create(position);
         this.setLocationByNormal(newPoint.vectorId);
         newPoint.setLocationMode(Constant.normalLocationMode);
 
         stateService.setEventName(LayerEvents.AddPoint);
-      } else if (Settings.selectBasePointId == null && (Settings.selectLocationMode == Constant.angleLocationMode || Settings.selectLocationMode == Constant.allLocationMode)) {
+      } else if (
+        Settings.selectBasePointId == null &&
+        (Settings.selectLocationMode == Constant.angleLocationMode ||
+          Settings.selectLocationMode == Constant.allLocationMode)
+      ) {
         return null;
       }
       if (
         newPoint &&
-        (newPoint.getLocationMode() == Constant.allLocationMode || newPoint.getLocationMode() == Constant.angleLocationMode || newPoint.getLocationMode() == Constant.normalLocationMode) &&
+        (newPoint.getLocationMode() == Constant.allLocationMode ||
+          newPoint.getLocationMode() == Constant.angleLocationMode ||
+          newPoint.getLocationMode() == Constant.normalLocationMode) &&
         newPoint.getCategory() == VectorCategory.Point.TestPoint
       ) {
         this.testPointIds.push(newPoint.vectorId);
@@ -58,6 +77,24 @@ export default class AddPoint {
     return newPoint;
   }
 
+  //添加固定点/基准点
+  buildPoint2(position) {
+    let newPoint = null;
+    if (listenLayer.modifyPoint && listenLayer.modifyPoint.linkedPointId) {
+      return null;
+    }
+    if (Settings.selectPointCategory == VectorCategory.Point.BasePoint) {
+      newPoint = pointService.create(position);
+      Settings.selectBasePointId = newPoint.vectorId;
+      stateService.setEventName(LayerEvents.AddPoint);
+    } else if (Settings.selectPointCategory == VectorCategory.Point.FixPoint) {
+      newPoint = pointService.create(position);
+      stateService.setEventName(LayerEvents.AddPoint);
+    }
+    listenLayer.clear();
+    return newPoint;
+  }
+
   isFocusBasePoint() {
     if (Settings.selectBasePointId) {
       let point = dataService.getPoint(Settings.selectBasePointId);
@@ -90,9 +127,17 @@ export default class AddPoint {
     join.setLocationMode(Constant.angleLocationMode);
     join.setLinkedBasePointId(basePoint.vectorId);
     join.setLinkedTestPointId(testPointId);
-    let guidePositionLine = lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.GuidePositionLine);
+    let guidePositionLine = lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.GuidePositionLine
+    );
 
-    let positionLine = lineService.createByPointId(basePoint.vectorId, join.vectorId, VectorCategory.Line.PositionLine);
+    let positionLine = lineService.createByPointId(
+      basePoint.vectorId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
     guidePositionLine.setLocationMode(Constant.angleLocationMode);
     positionLine.setLocationMode(Constant.angleLocationMode);
     join.setCategory(VectorCategory.Point.TestBasePoint);
@@ -118,15 +163,29 @@ export default class AddPoint {
     join.setLinkedBasePointId(basePoint.vectorId);
     join.setLinkedTestPointId(testPointId);
     //待测点与基准线的垂直线
-    lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.PositionLine);
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
     //暂时没有其他待测点
     if (this.testPointIds.length == 0) {
       //待测点与基准线点的连线
-      lineService.createByPointId(basePoint.vectorId, testPointId, VectorCategory.Line.PositionLine);
+      lineService.createByPointId(
+        basePoint.vectorId,
+        testPointId,
+        VectorCategory.Line.PositionLine
+      );
     } else {
       //取上一个待测点
-      lineService.createByPointId(this.testPointIds[this.testPointIds.length - 1], testPointId, VectorCategory.Line.PositionLine);
-      testPoint.setLinkedTestPointId(this.testPointIds[this.testPointIds.length - 1]);
+      lineService.createByPointId(
+        this.testPointIds[this.testPointIds.length - 1],
+        testPointId,
+        VectorCategory.Line.PositionLine
+      );
+      testPoint.setLinkedTestPointId(
+        this.testPointIds[this.testPointIds.length - 1]
+      );
     }
   }
 
@@ -148,7 +207,11 @@ export default class AddPoint {
     join.setCategory(VectorCategory.Point.TestBasePoint);
     join.setLocationMode(Constant.normalLocationMode);
     join.setLinkedTestPointId(testPointId);
-    lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.PositionLine);
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
   }
 
   deleteTestPoints() {
@@ -158,7 +221,7 @@ export default class AddPoint {
     this.testPointIds = [];
   }
 
-  resetTestPoints(){
+  resetTestPoints() {
     this.testPointIds = [];
   }
 }

+ 85 - 0
src/graphic/Controls/LocationModeControl.js

@@ -0,0 +1,85 @@
+import { mathUtil } from "../Util/MathUtil";
+import { textService } from "../Service/TextService";
+import { listenLayer } from "../ListenLayer";
+import Settings from "../Settings";
+import { dataService } from "../Service/DataService";
+import { lineService } from "../Service/LineService";
+import { pointService } from "../Service/PointService";
+import VectorCategory from "../enum/VectorCategory";
+
+export default class LocationModeControl {
+  constructor() {}
+
+  //设置直角定位法
+  setAngle() {
+    let selectBasePoint = this.isFocusBasePoint();
+    if (selectBasePoint) {
+      let points = dataService.getPoints();
+      for (let i = 0; i < points.length; ++i) {
+        let point = dataService.getPoint(points[i].vectorId);
+        if (point.getCategory() == VectorCategory.Point.fixPoint) {
+          this.setSingleFixPointByAngle(
+            point.vectorId,
+            selectBasePoint.vectorId
+          );
+        }
+      }
+    }
+  }
+
+  //对一个点进行直角定位法
+  //生成两条定位线和一条辅助线
+  setSingleFixPointByAngle(fixPointId, basePointId) {
+    let fixPoint = dataService.getPoint(fixPointId);
+    let basePoint = dataService.getPoint(basePointId);
+    let baseLine = dataService.getLine(Settings.baseLineId);
+    let startPoint = dataService.getPoint(baseLine.startId);
+    let endPoint = dataService.getPoint(baseLine.endId);
+
+    let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
+    let vLine = mathUtil.getVerticalLine(baseLineGeometry, fixPoint);
+    let join = mathUtil.getJoinLinePoint(basePoint, vLine);
+    join = pointService.create(join);
+
+    let locationLineByFixPoint = lineService.createByPointId(
+      fixPointId,
+      join.vectorId,
+      VectorCategory.Line.LocationLineByFixPoint
+    );
+
+    let locationLineByBasePoint = mathUtil.getVerticalLine(vLine, basePoint);
+    join = mathUtil.getIntersectionPoint(locationLineByBasePoint, vLine);
+    join = pointService.create(join);
+    locationLineByBasePoint = lineService.createByPointId(
+      basePointId,
+      join.vectorId,
+      VectorCategory.Line.LocationLineByBasePoint
+    );
+
+    let guideLocationLine = lineService.createByPointId(
+      fixPointId,
+      join.vectorId,
+      VectorCategory.Line.GuideLocationLine
+    );
+  }
+
+  /******************************************************************************************************************************************************/
+
+  //设置综合定位法
+  setAll() {}
+
+  /******************************************************************************************************************************************************/
+
+  isFocusBasePoint() {
+    if (Settings.selectBasePointId) {
+      let point = dataService.getPoint(Settings.selectBasePointId);
+      if (point.getCategory() == VectorCategory.Point.BasePoint) {
+        return point;
+      }
+    }
+    return null;
+  }
+}
+
+const locationModeControl = new LocationModeControl();
+export { locationModeControl };

+ 104 - 22
src/graphic/Controls/MoveLine.js

@@ -1,14 +1,91 @@
-import Constant from '../Constant';
-import { dataService } from '../Service/DataService';
-import { lineService } from '../Service/LineService';
-import { pointService } from '../Service/PointService';
-import { movePoint } from './MovePoint';
-import { mathUtil } from '../Util/MathUtil';
-import VectorCategory from '../enum/VectorCategory';
+import Constant from "../Constant";
+import { dataService } from "../Service/DataService";
+import { lineService } from "../Service/LineService";
+import { pointService } from "../Service/PointService";
+import { movePoint } from "./MovePoint";
+import { mathUtil } from "../Util/MathUtil";
+import VectorCategory from "../enum/VectorCategory";
 
 export default class MoveLine {
   constructor() {}
 
+  // moveLine(lineId, dx, dy) {
+  //   dx = dx;
+  //   dy = -dy;
+  //   let line = dataService.getLine(lineId);
+  //   let startPoint = dataService.getPoint(line.startId);
+  //   let endPoint = dataService.getPoint(line.endId);
+
+  //   //垂直移动
+  //   if (line.getCategory() == VectorCategory.Line.PositionLine && line.getLocationMode() == Constant.angleLocationMode) {
+  //     let point1 = {
+  //       x: startPoint.x + dx,
+  //       y: startPoint.y + dy,
+  //     };
+  //     let point2 = {
+  //       x: endPoint.x + dx,
+  //       y: endPoint.y + dy,
+  //     };
+  //     let lineGeometry = mathUtil.createLine1(point1, point2);
+  //     point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
+  //     //startPoint本来是基准点
+  //     if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
+  //       //达到一定距离才能移动
+  //       if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
+  //         return false;
+  //       }
+  //       let newStartPoint = pointService.create(point1);
+  //       let extendedPositionLine = lineService.createByPointId(startPoint.vectorId, newStartPoint.vectorId, VectorCategory.Line.ExtendedPositionLine);
+  //       extendedPositionLine.setLocationMode(Constant.angleLocationMode);
+  //       dataService.deletePointParent(startPoint.vectorId, lineId);
+  //       line.startId = newStartPoint.vectorId;
+  //       newStartPoint.setPointParent(line.vectorId, 'start');
+  //       newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
+  //     } else {
+  //       startPoint.x = point1.x;
+  //       startPoint.y = point1.y;
+  //       let parents = Object.keys(startPoint.parent);
+  //       let extendedLine = dataService.getLine(parents[0]);
+  //       if (extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine) {
+  //         extendedLine = dataService.getLine(parents[1]);
+  //       }
+  //       if (extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
+  //         //point1是基准点
+  //         point1 = dataService.getPoint(extendedLine.startId);
+  //         point2 = dataService.getPoint(extendedLine.endId);
+  //         if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
+  //           dataService.deleteLine(extendedLine.vectorId);
+  //           dataService.deletePoint(extendedLine.endId);
+
+  //           line.startId = point1.vectorId;
+  //           point1.setPointParent(line.vectorId, 'start');
+
+  //           lineGeometry = mathUtil.createLine3(lineGeometry, point1);
+  //         }
+  //       }
+  //     }
+
+  //     point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
+  //     endPoint.x = point2.x;
+  //     endPoint.y = point2.y;
+  //   } else {
+  //     //综合定位和垂线定位,拖动基准线更新位置
+  //     if (line.getCategory() == VectorCategory.Line.BaseLine) {
+  //       let points = dataService.vectorData.points;
+  //       for (let key in points) {
+  //         if (points[key].category == VectorCategory.Point.TestPoint && (points[key].locationMode == Constant.allLocationMode || points[key].locationMode == Constant.normalLocationMode)) {
+  //           movePoint.updatePositionByTestPoint(points[key].vectorId);
+  //         }
+  //       }
+  //     }
+  //     startPoint.x += dx;
+  //     startPoint.y += dy;
+  //     endPoint.x += dx;
+  //     endPoint.y += dy;
+  //   }
+  //   return true;
+  // }
+
   moveLine(lineId, dx, dy) {
     dx = dx;
     dy = -dy;
@@ -16,8 +93,12 @@ export default class MoveLine {
     let startPoint = dataService.getPoint(line.startId);
     let endPoint = dataService.getPoint(line.endId);
 
-    //垂直移动
-    if (line.getCategory() == VectorCategory.Line.PositionLine && line.getLocationMode() == Constant.angleLocationMode) {
+    //垂直移动,直角定位法只支持定位线的拖拽
+    if (
+      (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint ||
+        line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) &&
+      line.getLocationMode() == Constant.angleLocationMode
+    ) {
       let point1 = {
         x: startPoint.x + dx,
         y: startPoint.y + dy,
@@ -35,21 +116,29 @@ export default class MoveLine {
           return false;
         }
         let newStartPoint = pointService.create(point1);
-        let extendedPositionLine = lineService.createByPointId(startPoint.vectorId, newStartPoint.vectorId, VectorCategory.Line.ExtendedPositionLine);
+        let extendedPositionLine = lineService.createByPointId(
+          startPoint.vectorId,
+          newStartPoint.vectorId,
+          VectorCategory.Line.ExtendedPositionLine
+        );
         extendedPositionLine.setLocationMode(Constant.angleLocationMode);
         dataService.deletePointParent(startPoint.vectorId, lineId);
         line.startId = newStartPoint.vectorId;
-        newStartPoint.setPointParent(line.vectorId, 'start');
+        newStartPoint.setPointParent(line.vectorId, "start");
         newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
       } else {
         startPoint.x = point1.x;
         startPoint.y = point1.y;
         let parents = Object.keys(startPoint.parent);
         let extendedLine = dataService.getLine(parents[0]);
-        if (extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine) {
+        if (
+          extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
+        ) {
           extendedLine = dataService.getLine(parents[1]);
         }
-        if (extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
+        if (
+          extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
+        ) {
           //point1是基准点
           point1 = dataService.getPoint(extendedLine.startId);
           point2 = dataService.getPoint(extendedLine.endId);
@@ -58,7 +147,7 @@ export default class MoveLine {
             dataService.deletePoint(extendedLine.endId);
 
             line.startId = point1.vectorId;
-            point1.setPointParent(line.vectorId, 'start');
+            point1.setPointParent(line.vectorId, "start");
 
             lineGeometry = mathUtil.createLine3(lineGeometry, point1);
           }
@@ -70,14 +159,7 @@ export default class MoveLine {
       endPoint.y = point2.y;
     } else {
       //综合定位和垂线定位,拖动基准线更新位置
-      if (line.getCategory() == VectorCategory.Line.BaseLine) {
-        let points = dataService.vectorData.points;
-        for (let key in points) {
-          if (points[key].category == VectorCategory.Point.TestPoint && (points[key].locationMode == Constant.allLocationMode || points[key].locationMode == Constant.normalLocationMode)) {
-            movePoint.updatePositionByTestPoint(points[key].vectorId);
-          }
-        }
-      }
+      //缺
       startPoint.x += dx;
       startPoint.y += dy;
       endPoint.x += dx;

+ 21 - 2
src/graphic/Layer.js

@@ -5,7 +5,7 @@ import { dataService } from "./Service/DataService";
 import { textService } from "./Service/TextService";
 import { historyService } from "./Service/HistoryService";
 import UIControl from "./Controls/UIControl";
-// import { moveRectangle } from "./Controls/MoveRectangle";
+import { locationModeControl } from "./Controls/LocationModeControl";
 import { moveText } from "./Controls/MoveText";
 import { moveSVG } from "./Controls/MoveSVG";
 import { moveMagnifier } from "./Controls/MoveMagnifier";
@@ -91,6 +91,7 @@ export default class Layer {
     this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
     this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
     this.canvas.addEventListener("resize", this.reSize.bind(this));
+    document.addEventListener("keydown", this.onKeydown.bind(this));
   }
 
   reSize = function () {
@@ -151,7 +152,7 @@ export default class Layer {
       //   break;
       case LayerEvents.AddPoint:
         stateService.setEventName(LayerEvents.MovePoint);
-        const newPoint = addPoint.buildPoint(position);
+        const newPoint = addPoint.buildPoint2(position);
         if (newPoint) {
           stateService.setSelectItem(
             newPoint.vectorId,
@@ -1540,4 +1541,22 @@ export default class Layer {
     }
     elementService.execute(otherPoint, point);
   }
+
+  //测试用
+  onKeydown(e) {
+    let focusItem = stateService.getFocusItem();
+    if (focusItem) {
+      console.log("键盘(foucus有效):" + e.code);
+      //添加固定点
+      if (e.code == "KeyQ") {
+        stateService.setEventName(LayerEvents.AddPoint);
+      }
+      //一键测量
+      if (e.code == "KeyA") {
+        locationModeControl.setAngle();
+        this.renderer.autoRedraw();
+        this.history.save();
+      }
+    }
+  }
 }

+ 8 - 0
src/graphic/enum/VectorCategory.js

@@ -11,6 +11,13 @@ const VectorCategory = {
     PositionLine: "PositionLine", //定位线。基准点与待测点相连的线,或者与待测基准点相连的线
     GuidePositionLine: "GuidePositionLine", //定位辅助线
     ExtendedPositionLine: "ExtendedPositionLine", //定位延长线
+
+    //重做定位
+    GuideLocationLine: "GuideLocationLine", //定位辅助线
+    LocationLineByFixPoint: "LocationLineByFixPoint", //经过固定点的定位线
+    LocationLineByBasePoint: "LocationLineByFixPoint", //经过基础点的定位线
+    LocationLineByFixPointToFixPoint: "LocationLineByFixPointToFixPoint", //经过固定点到固定点的定位线,综合定位法
+    LocationLineByFixPointToBasePoint: "LocationLineByFixPointToBasePoint", //经过固定点到基础点的定位线,综合定位法
   },
   Point: {
     BasePoint: "BasePoint", //基准点
@@ -18,6 +25,7 @@ const VectorCategory = {
     NormalPoint: "NormalPoint", //正常点
     TestBasePoint: "TestBasePoint", //待测基准点,待测点与基准线相交的点
     FixPoint: "FixPoint", //固定点
+    GuidePoint: "GuidePoint", //辅助点,定位法需要
   },
 };
 export default VectorCategory;