xushiting %!s(int64=2) %!d(string=hai) anos
pai
achega
92c176af27

+ 1 - 0
src/graphic/Constant.js

@@ -38,5 +38,6 @@ const Constant = {
   defaultMidDivideWidth: 5, //隔离带的宽度
   angleLocationMode: "AngleLocationMode", //直角定位
   allLocationMode: "AllLocationMode", //综合定位
+  normalLocationMode: "NormalLocationMode", //自由测量
 };
 export default Constant;

+ 160 - 45
src/graphic/Controls/AddPoint.js

@@ -6,36 +6,68 @@ 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 VectorType from "../enum/VectorType";
+import Constant from "../Constant";
 
 export default class AddPoint {
   constructor() {
-    this.basePointIds = [];
+    this.basePointIds = []; //所有基准点
+    this.testPointIds = []; //所有待测点
   }
 
   buildPoint(position) {
     const newPoint = pointService.create(position);
     if (newPoint.getCategory() == VectorCategory.Point.BasePoint) {
       this.basePointIds.push(newPoint.vectorId);
+    } else {
+      if (Settings.locationMode == Constant.angleLocationMode) {
+        this.setLocationByAngle(newPoint.vectorId);
+      } else if (Settings.locationMode == Constant.allLocationMode) {
+        this.setLocationByAll(newPoint.vectorId);
+      } else if (Settings.locationMode == Constant.normalLocationMode) {
+        this.setLocationByNormal(newPoint.vectorId);
+      }
+      if (newPoint.getCategory() == VectorCategory.Point.TestPoint) {
+        this.testPointIds.push(newPoint.vectorId);
+      }
     }
     listenLayer.clear();
     return newPoint;
   }
 
+  isFocusBasePoint() {
+    let focusItem = stateService.getFocusItem();
+    if (focusItem && focusItem.type == VectorType.Point) {
+      let point = dataService.getPoint(focusItem.vectorId);
+      if (point.getCategory() == VectorCategory.Point.BasePoint) {
+        return point;
+      }
+    }
+    return null;
+  }
+
   //直角定位法
-  setLocationByAngle(testPointId, basePointId) {
-    if (testPointId == null || basePointId == null) {
-      return null;
+  setLocationByAngle(testPointId) {
+    let basePoint = this.isFocusBasePoint();
+    if (!basePoint) {
+      return;
     }
     let testPoint = dataService.getPoint(testPointId);
-    let basePoint = dataService.getPoint(basePointId);
+    if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
+      return;
+    }
+    testPoint.setLinkedBasePointId(basePoint.vectorId);
     let lineGeometry = dataService.getLine(addLine.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);
+    let vLine = mathUtil.getVerticalLine(line, testPoint);
+    let join = mathUtil.getJoinLinePoint(basePoint, vLine);
     join = pointService.create(join);
-
+    join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLinkedBasePointId(basePoint.vectorId);
+    join.setLinkedTestPointId(testPointId);
     lineService.createByPointId(
       testPointId,
       join.vectorId,
@@ -43,53 +75,136 @@ export default class AddPoint {
     );
 
     lineService.createByPointId(
-      basePointId,
+      basePoint.vectorId,
       join.vectorId,
       VectorCategory.Line.PositionLine
     );
   }
 
+  //待测基准点,待测点与基准线相交的点
+  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(addLine.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);
+  }
+
   //综合定位法
-  setLocationByFull(testPointId1, testPointId2, basePointId) {
-    if (testPointId1 == null || basePointId == null) {
-      return null;
+  setLocationByAll(testPointId) {
+    let basePoint = this.isFocusBasePoint();
+    if (!basePoint) {
+      return;
+    }
+
+    let testPoint = dataService.getPoint(testPointId);
+    testPoint.setLinkedBasePointId(basePoint.vectorId);
+    let lineGeometry = dataService.getLine(addLine.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);
+    join = pointService.create(join); //经过待测点且与基准线垂直的线段,与基准线的交点
+    join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLinkedBasePointId(basePoint.vectorId);
+    join.setLinkedTestPointId(testPointId);
+    //待测点与基准线的垂直线
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
+    //暂时没有其他待测点
+    if (this.testPointIds.length == 0) {
+      //待测点与基准线点的连线
+      lineService.createByPointId(
+        basePoint.vectorId,
+        testPointId,
+        VectorCategory.Line.PositionLine
+      );
     } else {
-      let testPoint1 = dataService.getPoint(testPointId1);
-      let lineGeometry = dataService.getLine(addLine.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(
+        this.testPointIds[this.testPointIds.length - 1],
+        testPointId,
+        VectorCategory.Line.PositionLine
+      );
+      testPoint.setLinkedTestPointId(
+        this.testPointIds[this.testPointIds.length - 1]
+      );
+    }
+  }
 
-        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
-        );
+  //更新待测点(综合定位法)
+  updateTestPointByAll(testPointId, newPosition) {
+    let testPoint = dataService.getPoint(testPointId);
+    mathUtil.clonePoint(testPoint, newPosition);
+    let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
+    let lineGeometry = dataService.getLine(addLine.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);
+  }
 
-        lineService.createByPointId(
-          testPointId2,
-          testPointId1,
-          VectorCategory.Line.PositionLine
-        );
-      }
+  setLocationByNormal(testPointId) {
+    let testPoint = dataService.getPoint(testPointId);
+    if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
+      return;
     }
+    let lineGeometry = dataService.getLine(addLine.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.getIntersectionPoint(vLine, line);
+    join = pointService.create(join);
+    join.setCategory(VectorCategory.Point.TestBasePoint);
+    join.setLinkedTestPointId(testPointId);
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      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(addLine.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);
   }
 }
 

+ 45 - 7
src/graphic/Controls/UIControl.js

@@ -8,8 +8,11 @@ import { uiService } from "../Service/UIService.js";
 import { dataService } from "../Service/DataService.js";
 import { historyService } from "../Service/HistoryService.js";
 import { elementService } from "../Service/ElementService";
+import { lineService } from "../Service/LineService.js";
+import { circleService } from "../Service/CircleService.js";
+import { textService } from "../Service/TextService.js";
+import { magnifierService } from "../Service/MagnifierService.js";
 import { mathUtil } from "../Util/MathUtil";
-import { textService } from "../Service/TextService.js/";
 import Constant from "../Constant";
 // import { roomsUtil } from "../Room/RoomsUtil.js";
 import { addRoad } from "../Controls/AddRoad";
@@ -20,7 +23,7 @@ import Message from "@/components/base/components/message/message.vue";
 
 export default class UIControl {
   constructor(layer, newsletter, graphicStateUI) {
-    this._prompts = []
+    this._prompts = [];
     this.layer = layer;
     this.newsletter = newsletter;
     this.graphicStateUI = graphicStateUI;
@@ -102,11 +105,11 @@ export default class UIControl {
     if (item && item.vectorId) {
       switch (action) {
         case GeoActions.CopyAction:
-          await dataService.copyVector(item.vectorId, item.type);
+          await this.copyVector(item.vectorId, item.type);
           needAutoRedraw = true;
           break;
         case GeoActions.DeleteAction:
-          dataService.deleteVector(item.vectorId, item.type);
+          this.deleteVector(item.vectorId, item.type);
           needAutoRedraw = true;
           break;
       }
@@ -118,6 +121,42 @@ export default class UIControl {
     }
   }
 
+  //删除按钮
+  deleteVector(vectorId, geoType) {
+    switch (geoType) {
+      case VectorType.Line:
+        dataService.deleteLine(vectorId);
+        break;
+      case VectorType.Circle:
+        dataService.deleteCircle(vectorId);
+        break;
+      case VectorType.Text:
+        dataService.deleteText(vectorId);
+        break;
+      case VectorType.Magnifier:
+        dataService.deleteMagnifier(vectorId);
+        break;
+    }
+  }
+
+  //复制按钮
+  async copyVector(vectorId, geoType) {
+    switch (geoType) {
+      case VectorType.Line:
+        lineService.copy(vectorId);
+        break;
+      case VectorType.Circle:
+        circleService.copy(vectorId);
+        break;
+      case VectorType.Text:
+        textService.copy(vectorId);
+        break;
+      case VectorType.Magnifier:
+        await magnifierService.copy(vectorId);
+        break;
+    }
+  }
+
   //截图
   async screenShot() {
     let canvas = this.layer.canvas;
@@ -238,14 +277,13 @@ export default class UIControl {
 
   /******************************************************************************************************************************************************************/
 
-
   prompt(msg) {
-    this._prompts.push(Message.success({ msg }))
+    this._prompts.push(Message.success({ msg }));
   }
 
   hidePrompt() {
     for (let prompt of this._prompts) {
-      prompt()
+      prompt();
     }
   }
 }

+ 10 - 0
src/graphic/Geometry/Line.js

@@ -33,4 +33,14 @@ export default class Line extends Geometry {
   setArrowColor(value) {
     this.arrowColor = value;
   }
+
+  getDir(pointId) {
+    if (this.startId == pointId) {
+      return "start";
+    } else if (this.endId == pointId) {
+      return "end";
+    } else {
+      return null;
+    }
+  }
 }

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

@@ -9,6 +9,8 @@ export default class Point extends Geometry {
     this.x = null;
     this.y = null;
     this.parent = {};
+    this.linkedBasePointId = null; //关联基准点
+    this.linkedTestPointId = null; //关联待测点
     this.category = Settings.pointCategory;
     this.geoType = VectorType.Point;
     this.setId(vectorId);
@@ -25,6 +27,22 @@ export default class Point extends Geometry {
     return this.category;
   }
 
+  getLinkedBasePointId() {
+    return this.linkedBasePointId;
+  }
+
+  setLinkedBasePointId(pointId) {
+    this.linkedBasePointId = pointId;
+  }
+
+  setLinkedTestPointId(pointId) {
+    this.linkedTestPointId = pointId;
+  }
+
+  getLinkedTestPointId() {
+    return this.linkedTestPointId;
+  }
+
   //基准点:BasePoint
   setCategory(value) {
     if (!value) {

+ 9 - 1
src/graphic/History/HistoryUtil.js

@@ -19,7 +19,9 @@ export default class HistoryUtil {
       point1.x == point2.x &&
       point1.y == point2.y &&
       JSON.stringify(point1.parent) == JSON.stringify(point2.parent) &&
-      point1.category == point2.category
+      point1.category == point2.category &&
+      point1.linkedBasePointId == point2.linkedBasePointId &&
+      point1.linkedTestPointId == point2.linkedTestPointId
     ) {
       return false;
     } else {
@@ -164,6 +166,8 @@ 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.linkedBasePointId = point2.linkedBasePointId;
+    pointInfo.linkedTestPointId = point2.linkedTestPointId;
     pointInfo.category = point2.category;
     this.setPointInfo(pointInfo);
   }
@@ -288,6 +292,8 @@ export default class HistoryUtil {
     mathUtil.clonePoint(data, point);
     data.parent = JSON.parse(JSON.stringify(point.parent));
     data.category = point.category;
+    data.linkedBasePointId = point.linkedBasePointId;
+    data.linkedTestPointId = point.linkedTestPointId;
     data.type = point.geoType;
     return data;
   }
@@ -413,6 +419,8 @@ export default class HistoryUtil {
     mathUtil.clonePoint(point, pointInfo.position);
     point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
     point.category = pointInfo.category;
+    point.linkedBasePointId = pointInfo.linkedBasePointId;
+    point.linkedTestPointId = pointInfo.linkedTestPointId;
     return point;
   }
 

+ 0 - 1
src/graphic/Layer.js

@@ -371,7 +371,6 @@ export default class Layer {
         elementService.setPoint(position);
         if (addLine.newLine == null) {
           addLine.buildLine(position);
-          this.updateBaseLine();
         } else {
           addLine.updateLine(position);
         }

+ 14 - 41
src/graphic/Service/DataService.js

@@ -2,11 +2,6 @@ import Line from "../Geometry/Line.js";
 import CurveLine from "../Geometry/CurveLine.js";
 import VectorType from "../enum/VectorType.js";
 import { coordinate } from "../Coordinate.js";
-import { lineService } from "./LineService.js";
-import { uiService } from "./UIService.js";
-import { circleService } from "./CircleService.js";
-import { textService } from "./TextService.js";
-import { magnifierService } from "./MagnifierService.js";
 
 export class DataService {
   constructor() {
@@ -137,6 +132,20 @@ 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);
+    }
+    delete endParent[lineId];
+    if (Object.keys(endParent).length == 0) {
+      this.deletePoint(line.endId);
+    }
     delete this.vectorData.lines[lineId];
   }
 
@@ -518,42 +527,6 @@ export class DataService {
     return this.vectorData.svgs;
   }
 
-  //删除按钮
-  deleteVector(vectorId, geoType) {
-    switch (geoType) {
-      case VectorType.Line:
-        this.deleteLine(vectorId);
-        break;
-      case VectorType.Circle:
-        this.deleteCircle(vectorId);
-        break;
-      case VectorType.Text:
-        this.deleteText(vectorId);
-        break;
-      case VectorType.Magnifier:
-        this.deleteMagnifier(vectorId);
-        break;
-    }
-  }
-
-  //复制按钮
-  async copyVector(vectorId, geoType) {
-    switch (geoType) {
-      case VectorType.Line:
-        lineService.copy(vectorId);
-        break;
-      case VectorType.Circle:
-        circleService.copy(vectorId);
-        break;
-      case VectorType.Text:
-        textService.copy(vectorId);
-        break;
-      case VectorType.Magnifier:
-        await magnifierService.copy(vectorId);
-        break;
-    }
-  }
-
   clear() {
     //直路
     this.vectorData.roadPoints = {};

+ 43 - 0
src/graphic/Service/LineService.js

@@ -4,6 +4,7 @@ import { dataService } from "./DataService.js";
 import VectorCategory from "../enum/VectorCategory.js";
 import { mathUtil } from "../Util/MathUtil.js";
 import { uiService } from "./UIService.js";
+import { addLine } from "../Controls/AddLine.js";
 
 export default class LineService {
   constructor() {}
@@ -39,6 +40,27 @@ export default class LineService {
     return line;
   }
 
+  deleteLine(lineId) {
+    let line = dataService.getLine(lineId);
+    //如果是基准线
+    if (line.getCategory() == VectorCategory.Line.BaseLine) {
+      let points = dataService.getPoints();
+      for (let key in points) {
+        let point = dataService.getPoint(key);
+        let category = point.getCategory();
+        if (
+          category == VectorCategory.Point.BasePoint ||
+          category == VectorCategory.Point.TestBasePoint ||
+          category == VectorCategory.Point.TestPoint
+        ) {
+          dataService.deletePoint(key);
+        }
+      }
+      addLine.baseLineId = null;
+    }
+    dataService.deleteLine();
+  }
+
   copy(vectorId) {
     let line = dataService.getLine(vectorId);
     let startPoint = dataService.getPoint(line.startId);
@@ -49,6 +71,27 @@ export default class LineService {
     newLine.setArrowColor(line.arrowColor);
     return newLine;
   }
+
+  //将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)
+  // }
 }
 
 const lineService = new LineService();