xushiting 2 years ago
parent
commit
fa5ca325c9

+ 1 - 0
src/graphic/Controls/AddLine.js

@@ -4,6 +4,7 @@ import { listenLayer } from "../ListenLayer";
 import VectorCategory from "../enum/VectorCategory";
 import Point from "../Geometry/Point.js";
 import { mathUtil } from "../Util/MathUtil";
+import Settings from "../Settings";
 
 export default class AddLine {
   constructor() {

+ 16 - 4
src/graphic/Controls/AddPoint.js

@@ -5,9 +5,21 @@ import VectorCategory from "../enum/VectorCategory";
 import Point from "../Geometry/Point.js";
 import { mathUtil } from "../Util/MathUtil";
 import addLine from "./AddLine";
+import Settings from "../Settings";
 
 export default class AddPoint {
-  constructor() {}
+  constructor() {
+    this.basePointIds = [];
+  }
+
+  buildPoint(position) {
+    const newPoint = pointService.create(position);
+    if (newPoint.getCategory() == VectorCategory.Point.BasePoint) {
+      this.basePointIds.push(newPoint.vectorId);
+    }
+    listenLayer.clear();
+    return newPoint;
+  }
 
   //直角定位法
   setLocationByAngle(testPointId, basePointId) {
@@ -22,7 +34,7 @@ export default class AddPoint {
     let line = mathUtil.createLine1(startPoint, endPoint);
     let vLine1 = mathUtil.getVerticalLine(line, testPoint);
     let join = mathUtil.getJoinLinePoint(basePoint, vLine1);
-    join = pointService.create(join, VectorCategory.Point.TestBasePoint);
+    join = pointService.create(join);
 
     lineService.createByPointId(
       testPointId,
@@ -49,7 +61,7 @@ export default class AddPoint {
       let line = mathUtil.createLine1(startPoint, endPoint);
       if (testPointId2 == null) {
         let join = mathUtil.getJoinLinePoint(testPoint1, line);
-        join = pointService.create(join, VectorCategory.Point.TestBasePoint);
+        join = pointService.create(join);
         lineService.createByPointId(
           testPointId1,
           join.vectorId,
@@ -64,7 +76,7 @@ export default class AddPoint {
       } else {
         let testPoint2 = dataService.getPoint(testPointId2);
         let join = mathUtil.getJoinLinePoint(testPoint2, line);
-        join = pointService.create(join, VectorCategory.Point.TestBasePoint);
+        join = pointService.create(join);
         lineService.createByPointId(
           testPointId2,
           join.vectorId,

+ 0 - 6
src/graphic/Controls/MoveLine.js

@@ -3,12 +3,6 @@ import { dataService } from "../Service/DataService";
 export default class MoveLine {
   constructor() {}
 
-  movePoint(position, pointId) {
-    let point = dataService.getPoint(pointId);
-    point.x = position.x;
-    point.y = position.y;
-  }
-
   moveLine(lineId, dx, dy) {
     dx = dx;
     dy = -dy;

+ 86 - 0
src/graphic/Controls/MovePoint.js

@@ -0,0 +1,86 @@
+import { dataService } from "../Service/DataService";
+
+export default class MovePoint {
+  constructor() {}
+
+  movePoint(position, pointId) {
+    let point = dataService.getPoint(pointId);
+    point.x = position.x;
+    point.y = position.y;
+  }
+
+  //直角定位法
+  //movePointForLocationByAngle(testPointId, basePointId) {
+  movePointByAngleLocation(pointId) {
+    if (testPointId == null || basePointId == null) {
+      return null;
+    }
+    let testPoint = dataService.getPoint(testPointId);
+    let basePoint = dataService.getPoint(basePointId);
+    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);
+    join = pointService.create(join);
+
+    lineService.createByPointId(
+      testPointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
+
+    lineService.createByPointId(
+      basePointId,
+      join.vectorId,
+      VectorCategory.Line.PositionLine
+    );
+  }
+
+  //综合定位法
+  movePointForLocationByFull(testPointId1, testPointId2, basePointId) {
+    if (testPointId1 == null || basePointId == null) {
+      return null;
+    } 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(
+          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
+        );
+
+        lineService.createByPointId(
+          testPointId2,
+          testPointId1,
+          VectorCategory.Line.PositionLine
+        );
+      }
+    }
+  }
+}
+
+const movePoint = new MovePoint();
+export { movePoint };

+ 3 - 0
src/graphic/Controls/UIControl.js

@@ -53,6 +53,7 @@ export default class UIControl {
   }
 
   clearUI() {
+    this.currentUI = null;
     this.selectUI = null;
   }
 
@@ -76,6 +77,8 @@ export default class UIControl {
           stateService.setEventName(LayerEvents.AddCurveRoad);
         } else if (uiService.isBelongLine(selectUI)) {
           stateService.setEventName(LayerEvents.AddLine);
+        } else if (uiService.isBelongPoint(selectUI)) {
+          stateService.setEventName(LayerEvents.AddPoint);
         } else if (selectUI == UIEvents.Circle) {
           stateService.setEventName(LayerEvents.AddCircle);
         } else if (selectUI == UIEvents.Text) {

+ 4 - 10
src/graphic/History/History.js

@@ -119,11 +119,8 @@ export default class History {
       if (item.handle == HistoryEvents.AddPoint) {
         dataService.deletePoint(item.point.id);
       } else if (item.handle == HistoryEvents.DeletePoint) {
-        let point = pointService.create(
-          item.point,
-          item.category,
-          item.point.id
-        );
+        let point = pointService.create(item.point, item.point.id);
+        point.setCategory(item.category);
         point.parent = JSON.parse(JSON.stringify(item.point.parent));
       } else if (item.handle == HistoryEvents.ModifyPoint) {
         const prePoint = item.prePoint;
@@ -324,11 +321,8 @@ export default class History {
     for (let i = 0; i < itemForPoints.length; ++i) {
       const item = itemForPoints[i];
       if (item.handle == HistoryEvents.AddPoint) {
-        let newPoint = pointService.create(
-          item.point,
-          item.category,
-          item.point.id
-        );
+        let newPoint = pointService.create(item.point, item.point.id);
+        newPoint.setCategory(item.category);
         historyUtil.assignPointFromPoint(newPoint, item.point);
       } else if (item.handle == HistoryEvents.DeletePoint) {
         dataService.deletePoint(item.point.id);

+ 28 - 3
src/graphic/Layer.js

@@ -11,12 +11,14 @@ import { moveSVG } from "./Controls/MoveSVG";
 import { moveMagnifier } from "./Controls/MoveMagnifier";
 import { addRoad } from "./Controls/AddRoad";
 import { addLine } from "./Controls/AddLine";
+import { addPoint } from "./Controls/AddPoint";
 import { addCircle } from "./Controls/AddCircle";
 import { addText } from "./Controls/AddText";
 import { addMagnifier } from "./Controls/AddMagnifier";
 import { addSVG } from "./Controls/AddSVG";
 import { moveRoad } from "./Controls/MoveRoad";
 import { moveLine } from "./Controls/MoveLine";
+import { movePoint } from "./Controls/MovePoint";
 import { moveCircle } from "./Controls/MoveCircle";
 import { coordinate } from "./Coordinate";
 import Render from "./Renderer/Render";
@@ -34,6 +36,7 @@ import { edgeService } from "./Service/EdgeService";
 import { roadPointService } from "./Service/RoadPointService";
 import { curveRoadService } from "./Service/CurveRoadService";
 import VectorCategory from "./enum/VectorCategory";
+import Settings from "./Settings";
 
 const minDragDis = 10;
 const minZoom = 20;
@@ -114,8 +117,6 @@ export default class Layer {
     // 右键
     if (e.button == 2) {
       this.stopAddVector();
-      this.uiControl.currentUI = null;
-      this.renderer.autoRedraw();
       return;
     }
     this.dragging = false;
@@ -136,6 +137,15 @@ export default class Layer {
         stateService.setEventName(LayerEvents.AddingLine);
         addLine.setNewLinePoint(position);
         break;
+      case LayerEvents.AddPoint:
+        stateService.setEventName(LayerEvents.MovePoint);
+        const newPoint = addPoint.buildPoint(position);
+        stateService.setSelectItem(
+          newPoint.vectorId,
+          VectorType.Point,
+          SelectState.Select
+        );
+        break;
       case LayerEvents.AddCircle:
         stateService.setEventName(LayerEvents.AddingCircle);
         addCircle.setCenter(position);
@@ -361,6 +371,7 @@ export default class Layer {
         elementService.setPoint(position);
         if (addLine.newLine == null) {
           addLine.buildLine(position);
+          this.updateBaseLine();
         } else {
           addLine.updateLine(position);
         }
@@ -568,7 +579,7 @@ export default class Layer {
               y: listenLayer.modifyPoint.y,
             };
           }
-          moveLine.movePoint(position, draggingItem.vectorId);
+          movePoint.movePoint(position, draggingItem.vectorId);
           needAutoRedraw = true;
         }
         break;
@@ -1096,5 +1107,19 @@ export default class Layer {
     addLine.clear(); //之前会保留category
     this.uiControl.clearUI();
     elementService.hideAll();
+    this.renderer.autoRedraw();
+  }
+
+  //更新定位信息
+  updateForLocation() {
+    if (
+      addLine.newLine &&
+      addLine.newLine.getCategory() == VectorCategory.Line.BaseLine
+    ) {
+      Settings.baseLineId = addLine.newLine.vectorId;
+      this.uiControl.graphicStateUI.canAngleLocationMode = true;
+      this.uiControl.graphicStateUI.canAllLocationMode = true;
+      this.uiControl.graphicState.existsBaseLine = true;
+    }
   }
 }

+ 1 - 2
src/graphic/Service/PointService.js

@@ -6,9 +6,8 @@ import { mathUtil } from "../Util/MathUtil.js";
 export default class PointService {
   constructor() {}
 
-  create(position, categoryType, vectorId) {
+  create(position, vectorId) {
     let point = new Point(position, vectorId);
-    point.setCategory(categoryType);
     dataService.addPoint(point);
     return point;
   }

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

@@ -73,6 +73,9 @@ export default class UIService {
     } else if (ui == UIEvents.Line) {
       this.setLineCategory(VectorCategory.Line.NormalLine);
       return true;
+    } else if (ui == UIEvents.BaseLine) {
+      this.setLineCategory(VectorCategory.Line.BaseLine);
+      return true;
     }
     return false;
   }

+ 1 - 0
src/graphic/Settings.js

@@ -20,5 +20,6 @@ const Settings = {
   lineCategory: VectorCategory.Line.NormalLine,
   pointCategory: VectorCategory.Point.NormalPoint,
   locationMode: Constant.angleLocationMode,
+  baseLineId: null, //基准线id,有且只有一条
 };
 export default Settings;

+ 3 - 0
src/graphic/enum/LayerEvents.js

@@ -14,6 +14,9 @@ const LayerEvents = {
   AddLine: "addLine",
   AddingLine: "addingLine",
   MoveLine: "moveLine",
+
+  AddPoint: "addPoint",
+  AddingPoint: "addingPoint",
   MovePoint: "movePoint",
 
   AddCircle: "addCircle",