123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- 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 VectorType from "../enum/VectorType";
- import Constant from "../Constant";
- export default class AddPoint {
- constructor() {
- 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) {
- let basePoint = this.isFocusBasePoint();
- if (!basePoint) {
- return;
- }
- let testPoint = dataService.getPoint(testPointId);
- if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
- return;
- }
- testPoint.setLinkedBasePointId(basePoint.vectorId);
- let lineGeometry = dataService.getLine(Settings.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);
- join = pointService.create(join);
- join.setCategory(VectorCategory.Point.TestBasePoint);
- join.setLinkedBasePointId(basePoint.vectorId);
- join.setLinkedTestPointId(testPointId);
- lineService.createByPointId(
- testPointId,
- join.vectorId,
- VectorCategory.Line.PositionLine
- );
- lineService.createByPointId(
- 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(Settings.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);
- }
- //综合定位法
- setLocationByAll(testPointId) {
- let basePoint = this.isFocusBasePoint();
- if (!basePoint) {
- return;
- }
- let testPoint = dataService.getPoint(testPointId);
- testPoint.setLinkedBasePointId(basePoint.vectorId);
- let lineGeometry = dataService.getLine(Settings.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 {
- //取上一个待测点
- lineService.createByPointId(
- this.testPointIds[this.testPointIds.length - 1],
- testPointId,
- VectorCategory.Line.PositionLine
- );
- testPoint.setLinkedTestPointId(
- this.testPointIds[this.testPointIds.length - 1]
- );
- }
- }
- //更新待测点(综合定位法)
- updateTestPointByAll(testPointId, newPosition) {
- let testPoint = dataService.getPoint(testPointId);
- mathUtil.clonePoint(testPoint, newPosition);
- let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
- let lineGeometry = dataService.getLine(Settings.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);
- }
- setLocationByNormal(testPointId) {
- let testPoint = dataService.getPoint(testPointId);
- if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
- return;
- }
- let lineGeometry = dataService.getLine(Settings.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(Settings.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);
- }
- }
- const addPoint = new AddPoint();
- export { addPoint };
|