|
@@ -6,36 +6,68 @@ import Point from "../Geometry/Point.js";
|
|
import { mathUtil } from "../Util/MathUtil";
|
|
import { mathUtil } from "../Util/MathUtil";
|
|
import addLine from "./AddLine";
|
|
import addLine from "./AddLine";
|
|
import Settings from "../Settings";
|
|
import Settings from "../Settings";
|
|
|
|
+import { stateService } from "../Service/StateService";
|
|
|
|
+import VectorType from "../enum/VectorType";
|
|
|
|
+import Constant from "../Constant";
|
|
|
|
|
|
export default class AddPoint {
|
|
export default class AddPoint {
|
|
constructor() {
|
|
constructor() {
|
|
- this.basePointIds = [];
|
|
|
|
|
|
+ this.basePointIds = []; //所有基准点
|
|
|
|
+ this.testPointIds = []; //所有待测点
|
|
}
|
|
}
|
|
|
|
|
|
buildPoint(position) {
|
|
buildPoint(position) {
|
|
const newPoint = pointService.create(position);
|
|
const newPoint = pointService.create(position);
|
|
if (newPoint.getCategory() == VectorCategory.Point.BasePoint) {
|
|
if (newPoint.getCategory() == VectorCategory.Point.BasePoint) {
|
|
this.basePointIds.push(newPoint.vectorId);
|
|
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();
|
|
listenLayer.clear();
|
|
return newPoint;
|
|
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 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 lineGeometry = dataService.getLine(addLine.baseLineId);
|
|
let startPoint = dataService.getPoint(lineGeometry.startId);
|
|
let startPoint = dataService.getPoint(lineGeometry.startId);
|
|
let endPoint = dataService.getPoint(lineGeometry.endId);
|
|
let endPoint = dataService.getPoint(lineGeometry.endId);
|
|
let line = mathUtil.createLine1(startPoint, endPoint);
|
|
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 = pointService.create(join);
|
|
-
|
|
|
|
|
|
+ join.setCategory(VectorCategory.Point.TestBasePoint);
|
|
|
|
+ join.setLinkedBasePointId(basePoint.vectorId);
|
|
|
|
+ join.setLinkedTestPointId(testPointId);
|
|
lineService.createByPointId(
|
|
lineService.createByPointId(
|
|
testPointId,
|
|
testPointId,
|
|
join.vectorId,
|
|
join.vectorId,
|
|
@@ -43,53 +75,136 @@ export default class AddPoint {
|
|
);
|
|
);
|
|
|
|
|
|
lineService.createByPointId(
|
|
lineService.createByPointId(
|
|
- basePointId,
|
|
|
|
|
|
+ basePoint.vectorId,
|
|
join.vectorId,
|
|
join.vectorId,
|
|
VectorCategory.Line.PositionLine
|
|
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 {
|
|
} 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|