123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- import { dataService } from "../Service/DataService";
- import { pointService } from "../Service/PointService";
- import Settings from "../Settings";
- import Constant from "../Constant";
- import VectorCategory from "../enum/VectorCategory";
- import { listenLayer } from "../ListenLayer";
- import { uiService } from "../Service/UIService";
- import { mathUtil } from "../Util/MathUtil";
- import { moveText } from "./MoveText";
- import { locationModeControl } from "./LocationModeControl";
- export default class MovePoint {
- constructor() {}
- movePoint(position, pointId) {
- let point = dataService.getPoint(pointId);
- if (point.getCategory() == VectorCategory.Point.BasePoint) {
- this.updateBasePoint(position, pointId);
- } else if (point.getCategory() == VectorCategory.Point.FixPoint) {
- this.updateFixPoint(position, pointId);
- } else {
- point.x = position.x;
- point.y = position.y;
- let parent = point.getParent();
- for (let key in parent) {
- let line = dataService.getLine(key);
- if (line.getCategory() == VectorCategory.Line.BaseLine) {
- if (uiService.getSelectLocationMode() == Constant.angleLocationMode) {
- locationModeControl.setAngle();
- }
- } else {
- line.setValue(null);
- }
- }
- }
- }
- finish(pointId) {
- if (
- pointId &&
- listenLayer.modifyPoint &&
- listenLayer.modifyPoint.linkedPointId
- ) {
- let linkedPoint = dataService.getPoint(
- listenLayer.modifyPoint.linkedPointId
- );
- const category = linkedPoint.getCategory();
- if (
- category != VectorCategory.Point.BasePoint &&
- category != VectorCategory.Point.TestBasePoint
- ) {
- pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId);
- uiService.setSelectBasePointId(null);
- } else {
- let point = dataService.getPoint(pointId);
- const parent = point.getParent();
- for (let key in parent) {
- let line = dataService.getLine(key);
- let startPoint = dataService.getPoint(line.startId);
- let endPoint = dataService.getPoint(line.endId);
- if (mathUtil.getDistance(startPoint, endPoint) == 0) {
- pointService.deletePoint(pointId);
- }
- }
- }
- }
- }
- //待测基准点,待测点与基准线相交的点
- getTestBasePoint(basePointId, testPointId, locationMode) {
- 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.getLocationMode() == locationMode
- ) {
- return point;
- }
- }
- }
- return null;
- }
- updatePositionByTestPoint(pointId) {
- let point = dataService.getPoint(pointId);
- let locationMode = point.getLocationMode();
- if (locationMode == Constant.angleLocationMode) {
- this.updateTestPointByAngle(pointId);
- } else if (locationMode == Constant.allLocationMode) {
- this.updateTestPointByAll(pointId);
- } else if (locationMode == Constant.normalLocationMode) {
- this.updateTestPointByNormal(pointId);
- }
- }
- //更新待测点(直角定位法)
- // updateTestPointByAngle(testPointId) {
- // let testPoint = dataService.getPoint(testPointId);
- // 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,
- // Constant.angleLocationMode
- // );
- // mathUtil.clonePoint(testBasePoint, join);
- // }
- updateTestPointByAngle(testPointId) {
- let testPoint = dataService.getPoint(testPointId);
- //let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
- let parent = testPoint.getParent();
- let guidePositionLine = dataService.getLine(Object.keys(parent)[0]);
- let otherPointId = null;
- if (guidePositionLine.startId == testPointId) {
- otherPointId = guidePositionLine.endId;
- } else if (guidePositionLine.endId == testPointId) {
- otherPointId = guidePositionLine.startId;
- }
- let otherPoint = dataService.getPoint(otherPointId);
- parent = otherPoint.getParent();
- for (let key in parent) {
- if (key == guidePositionLine.vectorId) {
- continue;
- } else {
- let positionLine = dataService.getLine(key);
- let startPoint = dataService.getPoint(positionLine.startId);
- let endPoint = dataService.getPoint(positionLine.endId);
- let positionLineGeometry = mathUtil.createLine1(startPoint, endPoint);
- if (!positionLineGeometry) {
- let lineGeometry = dataService.getLine(Settings.baseLineId);
- let baseStartPoint = dataService.getPoint(lineGeometry.startId);
- let baseEndPoint = dataService.getPoint(lineGeometry.endId);
- let baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
- positionLineGeometry = mathUtil.createLine3(baseLine, testPoint);
- }
- let join = mathUtil.getJoinLinePoint(testPoint, positionLineGeometry);
- mathUtil.clonePoint(otherPoint, join);
- // if (
- // mathUtil.getDistance(startPoint, endPoint) < Constant.minAdsorbPix
- // ) {
- // pointService.deletePoint(positionLine.startId);
- // }
- break;
- }
- }
- }
- //更新待测点(综合定位法)
- updateTestPointByAll(testPointId) {
- let testPoint = dataService.getPoint(testPointId);
- 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 = mathUtil.getJoinLinePoint(testPoint, line);
- let testBasePoint = this.getTestBasePoint(
- basePoint.vectorId,
- testPointId,
- Constant.allLocationMode
- );
- mathUtil.clonePoint(testBasePoint, join);
- }
- //更新待测点(自由定位法)
- updateTestPointByNormal(testPointId) {
- let testPoint = dataService.getPoint(testPointId);
- 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);
- let testBasePoint = this.getTestBasePoint(
- null,
- testPointId,
- Constant.normalLocationMode
- );
- mathUtil.clonePoint(testBasePoint, join);
- }
- updateBasePoint(position, basePointId) {
- let lineGeometry = dataService.getLine(Settings.baseLineId);
- let startPoint = dataService.getPoint(lineGeometry.startId);
- let endPoint = dataService.getPoint(lineGeometry.endId);
- lineGeometry = mathUtil.createLine1(startPoint, endPoint);
- let basePoint = dataService.getPoint(basePointId);
- let parent = basePoint.getParent();
- for (let key in parent) {
- let line = dataService.getLine(key);
- if (line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) {
- let otherPointId = line.getOtherPointId(basePointId);
- let otherPoint = dataService.getPoint(otherPointId);
- let otherLine = mathUtil.getLineForPoint(lineGeometry, otherPoint);
- line = mathUtil.createLine3(lineGeometry, position);
- let join = mathUtil.getIntersectionPoint(line, otherLine);
- mathUtil.clonePoint(otherPoint, join);
- mathUtil.clonePoint(basePoint, position);
- } else if (
- line.getCategory() == VectorCategory.Line.ExtendedPositionLine
- ) {
- let otherPointId = line.getOtherPointId(basePointId);
- let otherPoint = dataService.getPoint(otherPointId);
- let otherLine = mathUtil.createLine3(lineGeometry, otherPoint);
- let join = mathUtil.getJoinLinePoint(position, otherLine);
- mathUtil.clonePoint(otherPoint, join);
- mathUtil.clonePoint(basePoint, position);
- }
- }
- }
- updateFixPoint(position, fixPointId) {
- let fixPoint = dataService.getPoint(fixPointId);
- let basePoint = dataService.getPoint(fixPoint.linkedBasePointId);
- let baseLine = dataService.getLine(Settings.baseLineId);
- let startPoint = dataService.getPoint(baseLine.startId);
- let endPoint = dataService.getPoint(baseLine.endId);
- let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
- let vLine = mathUtil.getVerticalLine(baseLineGeometry, position);
- let join = mathUtil.getIntersectionPoint(baseLineGeometry, vLine);
- let parent = fixPoint.getParent();
- for (let key in parent) {
- let line = dataService.getLine(key);
- if (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint) {
- let otherPointId = line.getOtherPointId(fixPointId);
- let otherPoint = dataService.getPoint(otherPointId);
- mathUtil.clonePoint(otherPoint, join);
- moveText.moveFullText(position, fixPoint.linkedTextId);
- } else if (line.getCategory() == VectorCategory.Line.GuideLocationLine) {
- let otherPointId = line.getOtherPointId(fixPointId);
- let otherPoint = dataService.getPoint(otherPointId);
- let line2 = mathUtil.createLine3(baseLineGeometry, otherPoint);
- join = mathUtil.getIntersectionPoint(line2, vLine);
- mathUtil.clonePoint(otherPoint, join);
- } else if (
- line.getCategory() == VectorCategory.Line.ExtendedPositionLine
- ) {
- let otherPointId = line.getOtherPointId(fixPointId);
- let otherPoint = dataService.getPoint(otherPointId);
- let line2 = mathUtil.createLine3(baseLineGeometry, fixPoint);
- join = mathUtil.getJoinLinePoint(otherPoint, line2);
- mathUtil.clonePoint(otherPoint, join);
- }
- }
- mathUtil.clonePoint(fixPoint, position);
- }
- /*****************************************************************************曲线上的点********************************************************************************/
- moveCurvePoint(position, curvePointId) {
- let curvePoint = dataService.getCurvePoint(curvePointId);
- let curveLine = dataService.getCurveLine(curvePoint.getParent());
- curvePoint.setPosition(position);
- curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
- }
- }
- const movePoint = new MovePoint();
- export { movePoint };
|