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"; export default class MovePoint { constructor() {} movePoint(position, pointId) { let point = dataService.getPoint(pointId); point.x = position.x; point.y = position.y; if (point.getCategory() == VectorCategory.Point.TestPoint) { this.updatePositionByTestPoint(pointId); } else if (point.getCategory() == VectorCategory.Point.BasePoint) { this.updateBasePoint(pointId); } else { let parent = point.getParent(); for (let key in parent) { let line = dataService.getLine(key); line.setValue(null); //拖拽的点是基准线 if (line.category == VectorCategory.Line.BaseLine) { let points = dataService.getPoints(); for (let key in points) { let testPoint = dataService.getPoint(key); if (testPoint.category == VectorCategory.Point.TestPoint) { this.updatePositionByTestPoint(key); } } } } } } 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 && // category != VectorCategory.Point.TestPoint // ) { // pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId); // Settings.selectBasePointId = null; // } else if (category == VectorCategory.Point.BasePoint) { // Settings.selectBasePointId = pointId; // } else { // Settings.selectBasePointId = null; // } // } 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 && category != VectorCategory.Point.TestPoint ) { pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId); Settings.selectBasePointId = 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.getLinkedTestPointId() == testPointId && 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(basePointId) { let points = dataService.getPoints(); for (let key in points) { let point = dataService.getPoint(key); if ( point.getCategory() == VectorCategory.Point.TestPoint && point.getLinkedBasePointId() == basePointId ) { this.updatePositionByTestPoint(key); } } } /*****************************************************************************曲线上的点********************************************************************************/ moveCurvePoint(position, curvePointId) { let curvePoint = dataService.getCurvePoint(curvePointId); curvePoint.setPosition(position); } } const movePoint = new MovePoint(); export { movePoint };