Browse Source

开始支持曲线

xushiting 2 years ago
parent
commit
b5f0a2c5c4

File diff suppressed because it is too large
+ 1 - 1
server/test/SS-t-P1d6CwREny2/attach/sceneStore


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

@@ -72,6 +72,37 @@ export default class AddLine {
       }
     }
   }
+
+  buildCurveLine(position) {
+    if (
+      this.newLine == null &&
+      !mathUtil.equalPoint(this.startInfo.position, position)
+    ) {
+      this.newLine = lineService.createCurveLine(
+        this.startInfo.position,
+        position
+      );
+    }
+  }
+
+  updateCurveLine(position) {
+    if (
+      this.newLine != null &&
+      !mathUtil.equalPoint(this.startInfo.position, position)
+    ) {
+      let curvePoint = dataService.getCurvePoint(this.newLine.endId);
+      curvePoint.setPosition(position);
+    }
+  }
+
+  finishCurveLine(position) {
+    if (this.newLine != null) {
+      if (mathUtil.equalPoint(this.startInfo.position, position)) {
+        dataService.deleteCurveLine(this.newLine.vectorId);
+      }
+    }
+  }
+
   clearVectorData() {
     this.newLine = null;
     this.startInfo = {};

+ 2 - 2
src/graphic/Geometry/CurveLine.js

@@ -4,11 +4,11 @@ import Geometry from "./Geometry";
 import Constant from "../Constant.js";
 
 export default class CurveLine extends Geometry {
-  constructor(points, vectorId) {
+  constructor(startId, endId, vectorId) {
     super();
     this.startId = startId;
     this.endId = endId;
-    this.points = points;
+    this.points = null;
     this.geoType = VectorType.CurveLine;
     this.setId(vectorId);
   }

+ 34 - 1
src/graphic/Layer.js

@@ -139,7 +139,7 @@ export default class Layer {
         addLine.setNewLinePoint(position);
         break;
       case LayerEvents.AddCurveLine:
-        stateService.setEventName(LayerEvents.AddCurveLine);
+        stateService.setEventName(LayerEvents.AddingCurveLine);
         addLine.setNewLinePoint(position);
         break;
       case LayerEvents.AddPoint:
@@ -406,6 +406,32 @@ export default class Layer {
           addLine.updateLine(position);
         }
         break;
+      case LayerEvents.AddingCurveLine:
+        needAutoRedraw = true;
+        let exceptCurveLineId = null;
+        let exceptCurvePointId = null;
+        if (addLine.newLine != null) {
+          exceptCurveLineId = addLine.newLine.vectorId;
+          exceptCurvePointId = addLine.newLine.endId;
+        }
+        listenLayer.start(position, {
+          exceptCurveLineId: exceptCurveLineId,
+          exceptCurvePointId: exceptCurvePointId,
+        });
+        if (listenLayer.modifyPoint) {
+          position = {
+            x: listenLayer.modifyPoint.x,
+            y: listenLayer.modifyPoint.y,
+          };
+        }
+        elementService.execute(addLine.startInfo.position, position);
+        elementService.setPoint(position);
+        if (addLine.newLine == null) {
+          addLine.buildCurveLine(position);
+        } else {
+          addLine.updateCurveLine(position);
+        }
+        break;
       case LayerEvents.AddingCircle:
         needAutoRedraw = true;
         let exceptCircleId = null;
@@ -790,6 +816,13 @@ export default class Layer {
         this.history.save();
         elementService.hideAll();
         break;
+      case LayerEvents.AddingCurveLine:
+        needAutoRedraw = true;
+        addLine.finishCurveLine(position);
+        addLine.clearVectorData();
+        this.history.save();
+        elementService.hideAll();
+        break;
       case LayerEvents.AddingCircle:
         needAutoRedraw = true;
         addCircle.finish(position);

+ 130 - 2
src/graphic/ListenLayer.js

@@ -23,6 +23,8 @@ export default class ListenLayer {
    * @param exceptVectorIds:{
           exceptPointId,
           exceptLineId,
+          exceptCurvePointId,
+          exceptCurveLineId,
           exceptRoadPointId,
           exceptRoadIds,
           exceptCurveRoadPointId,
@@ -63,8 +65,14 @@ export default class ListenLayer {
       position,
       exceptVectorIds.exceptLineId
     );
-    selectInfo.curveLineInfo = {};
-    selectInfo.curvePointInfo = {};
+    selectInfo.curvePointInfo = this.isSelectCurvePoint(
+      position,
+      exceptVectorIds.exceptCurvePointId
+    );
+    selectInfo.curveLineInfo = this.isSelectCurveLine(
+      position,
+      exceptVectorIds.exceptCurveLineId
+    );
     selectInfo.circleInfo = this.isSelectCircle(
       position,
       exceptVectorIds.exceptCircleId
@@ -87,6 +95,126 @@ export default class ListenLayer {
     return flag;
   }
 
+  isSelectCurvePoint(position, exceptCurvePointId) {
+    let curvePointInfo = {
+      curvePointId: null,
+      type: null,
+      distance: null,
+    };
+
+    let seqInfo = {};
+    const curvePoints = dataService.getCurvePoints();
+    for (const curvePointId in curvePoints) {
+      if (curvePointId == exceptCurvePointId) {
+        continue;
+      }
+      const curvePoint = dataService.getCurvePoint(curvePointId);
+      const distance = mathUtil.getDistance(position, curvePoint);
+      if (distance < Constant.minAdsorbPix) {
+        if (curvePointInfo.curvePointId == null) {
+          curvePointInfo = {
+            curvePointId: curvePointId,
+            type: VectorType.CurvePoint,
+            distance: distance,
+          };
+        } else {
+          if (distance < curvePointInfo.distance) {
+            curvePointInfo = {
+              curvePointId: curvePointId,
+              type: VectorType.CurvePoint,
+              distance: distance,
+            };
+          }
+        }
+      } else {
+        if (Math.abs(position.x - curvePoint.x) < Constant.minAdsorbPix) {
+          seqInfo.linkedCurvePointIdX = curvePointId;
+          seqInfo.x = curvePoint.x;
+        }
+        if (Math.abs(position.y - curvePoint.y) < Constant.minAdsorbPix) {
+          seqInfo.linkedPointIdY = curvePointId;
+          seqInfo.y = curvePoint.y;
+        }
+      }
+    }
+
+    if (curvePointInfo.curvePointId) {
+      curvePointInfo.linkedCurvePointId = curvePointInfo.curvePointId;
+      const linkedCurvePoint = dataService.getCurvePoint(
+        curvePointInfo.curvePointId
+      );
+      curvePointInfo.x = linkedCurvePoint.x;
+      curvePointInfo.y = linkedCurvePoint.y;
+    } else {
+      if (seqInfo.hasOwnProperty("linkedCurvePointIdX")) {
+        curvePointInfo.linkedCurvePointIdX = seqInfo.linkedCurvePointIdX;
+        curvePointInfo.x = seqInfo.x;
+      }
+      if (seqInfo.hasOwnProperty("linkedCurvePointIdY")) {
+        curvePointInfo.linkedCurvePointIdY = seqInfo.linkedCurvePointIdY;
+        curvePointInfo.y = seqInfo.y;
+      }
+      if (
+        curvePointInfo.hasOwnProperty("y") &&
+        !curvePointInfo.hasOwnProperty("x")
+      ) {
+        curvePointInfo.x = position.x;
+      }
+      if (
+        curvePointInfo.hasOwnProperty("x") &&
+        !curvePointInfo.hasOwnProperty("y")
+      ) {
+        curvePointInfo.y = position.y;
+      }
+    }
+    return curvePointInfo;
+  }
+
+  isSelectCurveLine(position, exceptCurveLineIds) {
+    let curveLineInfo = {
+      curveLineId: null,
+      type: null,
+      distance: null,
+    };
+    const curveLines = dataService.getCurveLines();
+    for (const curveLineId in curveLines) {
+      if (
+        exceptCurveLineIds &&
+        exceptCurveLineIds.hasOwnProperty(curveLineId)
+      ) {
+        continue;
+      }
+      const curveLine = dataService.getCurveLine(curveLineId);
+      let startPoint = dataService.getCurvePoint(curveLine.startId);
+      let endPoint = dataService.getCurvePoint(curveLine.endId);
+      const comLine = mathUtil.createLine1(startPoint, endPoint);
+      const join = mathUtil.getJoinLinePoint(position, comLine);
+      const distance = mathUtil.getDistance(position, join);
+      if (!mathUtil.isContainForSegment(join, startPoint, endPoint)) {
+        continue;
+      }
+      if (distance < Constant.minAdsorbPix / 2) {
+        curveLineInfo = {
+          curveLineId: curveLineId,
+          type: VectorType.CurveLine,
+          distance: distance,
+        };
+      }
+    }
+
+    if (curveLineInfo.curveLineId) {
+      const linkedLine = dataService.getLine(lineInfo.curveLineId);
+      let startPoint = dataService.getCurvePoint(linkedLine.startId);
+      let endPoint = dataService.getCurvePoint(linkedLine.endId);
+      const linkedComLine = mathUtil.createLine1(startPoint, endPoint);
+      const linkedPosition = mathUtil.getJoinLinePoint(position, linkedComLine);
+      curveLineInfo.x = linkedPosition.x;
+      curveLineInfo.y = linkedPosition.y;
+      return curveLineInfo;
+    }
+    return curveLineInfo;
+  }
+
   isSelectPoint(position, exceptPointId) {
     let pointInfo = {
       pointId: null,

+ 3 - 0
src/graphic/Renderer/Render.js

@@ -42,6 +42,9 @@ export default class Render {
       case VectorType.Line:
         draw.drawLine(vector); //需要修改,有几种情况:测量,校准,基准
         break;
+      case VectorType.CurveLine:
+        //draw.drawCurveLine(vector);
+        break;
       case VectorType.Text:
         draw.drawText(vector, styleType, flag);
         break;

+ 7 - 0
src/graphic/Service/DataService.js

@@ -75,6 +75,8 @@ export class DataService {
     this.vectorData.curvelines = {};
     //线段(完全或者直线)上的端点
     this.vectorData.points = {};
+    this.vectorData.curvePoints = {};
+
     this.vectorData.circles = {};
     //基准点
     this.vectorData.basePointIds = [];
@@ -235,6 +237,10 @@ export class DataService {
     }
   }
 
+  deleteCurveLine(curveLineId) {
+    delete this.vectorData.curvelines[curveLineId];
+  }
+
   /**
    * 对弯路的操作
    */
@@ -561,6 +567,7 @@ export class DataService {
     this.vectorData.curvelines = {};
     //线段(完全或者直线)上的端点
     this.vectorData.points = {};
+    this.vectorData.curvePoints = {};
     this.vectorData.circles = {};
     //基准点
     this.vectorData.basePointIds = [];

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

@@ -1,6 +1,9 @@
 import Point from "../Geometry/Point.js";
 import Line from "../Geometry/Line.js";
+import CurvePoint from "../Geometry/CurvePoint.js";
+import CurveLine from "../Geometry/CurveLine.js";
 import { dataService } from "./DataService.js";
+import { curvePointService } from "./CurvePointService.js";
 import VectorCategory from "../enum/VectorCategory.js";
 import { mathUtil } from "../Util/MathUtil.js";
 import { uiService } from "./UIService.js";
@@ -85,6 +88,39 @@ export default class LineService {
     }
     return null;
   }
+
+  /******************************************************************************曲线**************************************************************************************/
+  createCurveLine(startPosition, endPosition, vectorId) {
+    if (
+      !startPosition ||
+      !endPosition ||
+      mathUtil.equalPoint(startPosition, endPosition)
+    ) {
+      return null;
+    }
+    let startPoint = curvePointService.create(startPosition);
+    let endPoint = curvePointService.create(endPosition);
+    let curveLine = new CurveLine(
+      startPoint.vectorId,
+      endPoint.vectorId,
+      vectorId
+    );
+
+    startPoint.setPointParent(curveLine.vectorId, "start");
+    endPoint.setPointParent(curveLine.vectorId, "end");
+    let midPoint = curvePointService.create({
+      x: (startPoint.x + endPoint.x) / 2,
+      y: (startPoint.y + endPoint.y) / 2,
+    });
+
+    curveLine.points = [];
+    curveLine.points.push(startPoint);
+    curveLine.points.push(midPoint);
+    curveLine.points.push(endPoint);
+
+    dataService.addCurveLine(curveLine);
+    return curveLine;
+  }
 }
 
 const lineService = new LineService();