123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import Constant from "../Constant";
- import Settings from "../Settings";
- import { dataService } from "../Service/DataService";
- import { lineService } from "../Service/LineService";
- import { pointService } from "../Service/PointService";
- import { movePoint } from "./MovePoint";
- import { mathUtil } from "../Util/MathUtil";
- import VectorCategory from "../enum/VectorCategory";
- import { locationModeControl } from "./LocationModeControl";
- import { uiService } from "../Service/UIService";
- export default class MoveLine {
- constructor() {}
- moveLine(lineId, dx, dy) {
- dx = dx;
- dy = -dy;
- let line = dataService.getLine(lineId);
- let startPoint = dataService.getPoint(line.startId);
- let endPoint = dataService.getPoint(line.endId);
- let baseLine = dataService.getLine(Settings.baseLineId);
- if (baseLine) {
- let baseStartPoint = dataService.getPoint(baseLine.startId);
- let baseEndPoint = dataService.getPoint(baseLine.endId);
- baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
- }
- //垂直移动,直角定位法只支持定位线的拖拽
- if (
- line.getCategory() == VectorCategory.Line.LocationLineByBasePoint &&
- line.getLocationMode() == Constant.angleLocationMode
- ) {
- let point1 = {
- x: startPoint.x + dx,
- y: startPoint.y + dy,
- };
- let point2 = {
- x: endPoint.x + dx,
- y: endPoint.y + dy,
- };
- let lineGeometry = mathUtil.createLine1(point1, point2);
- point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
- //startPoint本来是基准点
- if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
- //达到一定距离才能移动
- if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
- return false;
- }
- let newStartPoint = pointService.create(point1);
- let extendedPositionLine = lineService.createByPointId(
- startPoint.vectorId,
- newStartPoint.vectorId,
- VectorCategory.Line.ExtendedPositionLine
- );
- extendedPositionLine.setLocationMode(Constant.angleLocationMode);
- extendedPositionLine.setLinkedBasePointId(line.getLinkedBasePointId());
- extendedPositionLine.setLinkedFixPointId(line.getLinkedFixPointId());
- dataService.deletePointParent(startPoint.vectorId, lineId);
- line.startId = newStartPoint.vectorId;
- newStartPoint.setPointParent(line.vectorId, "start");
- newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
- } else {
- startPoint.x = point1.x;
- startPoint.y = point1.y;
- let parents = Object.keys(startPoint.parent);
- let extendedLine = dataService.getLine(parents[0]);
- if (
- extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
- ) {
- extendedLine = dataService.getLine(parents[1]);
- }
- if (
- extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
- ) {
- //point1是基准点
- point1 = dataService.getPoint(extendedLine.startId);
- point2 = dataService.getPoint(extendedLine.endId);
- if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
- dataService.deleteLine(extendedLine.vectorId);
- dataService.deletePoint(extendedLine.endId);
- line.startId = point1.vectorId;
- point1.setPointParent(line.vectorId, "start");
- lineGeometry = mathUtil.createLine3(lineGeometry, point1);
- }
- }
- }
- point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
- endPoint.x = point2.x;
- endPoint.y = point2.y;
- } else if (
- line.getCategory() == VectorCategory.Line.LocationLineByFixPoint &&
- line.getLocationMode() == Constant.angleLocationMode
- ) {
- let point1 = {
- x: startPoint.x + dx,
- y: startPoint.y + dy,
- };
- let point2 = {
- x: endPoint.x + dx,
- y: endPoint.y + dy,
- };
- let lineGeometry = mathUtil.createLine1(point1, point2);
- point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
- if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
- //达到一定距离才能移动
- if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
- return false;
- }
- let newStartPoint = pointService.create(point1);
- let extendedPositionLine = lineService.createByPointId(
- startPoint.vectorId,
- newStartPoint.vectorId,
- VectorCategory.Line.ExtendedPositionLine
- );
- extendedPositionLine.setLocationMode(Constant.angleLocationMode);
- extendedPositionLine.setLinkedBasePointId(line.getLinkedBasePointId());
- extendedPositionLine.setLinkedFixPointId(line.getLinkedFixPointId());
- dataService.deletePointParent(startPoint.vectorId, lineId);
- line.startId = newStartPoint.vectorId;
- newStartPoint.setPointParent(line.vectorId, "start");
- newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
- let join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
- mathUtil.clonePoint(endPoint, join);
- } else {
- let extendedPositionLine = mathUtil.createLine3(baseLine, startPoint);
- let join = mathUtil.getIntersectionPoint(
- lineGeometry,
- extendedPositionLine
- );
- mathUtil.clonePoint(startPoint, join);
- join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
- mathUtil.clonePoint(endPoint, join);
- let parent = startPoint.getParent();
- for (let key in parent) {
- if (key == lineId) {
- continue;
- } else {
- extendedPositionLine = dataService.getLine(key);
- }
- }
- startPoint = dataService.getPoint(extendedPositionLine.startId);
- if (mathUtil.getDistance(point1, startPoint) < Constant.minAdsorbPix) {
- let otherPointId = extendedPositionLine.getOtherPointId(
- startPoint.vectorId
- );
- let otherPoint = dataService.getPoint(otherPointId);
- if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
- dataService.deleteLine(extendedPositionLine.vectorId);
- dataService.deletePoint(otherPoint.vectorId);
- line.startId = startPoint.vectorId;
- startPoint.setPointParent(line.vectorId, "start");
- }
- join = mathUtil.getJoinLinePoint(startPoint, baseLine);
- mathUtil.clonePoint(endPoint, join);
- }
- }
- } else {
- //综合定位和垂线定位,拖动基准线更新位置
- //缺
- startPoint.x += dx;
- startPoint.y += dy;
- endPoint.x += dx;
- endPoint.y += dy;
- if (line.getCategory() == VectorCategory.Line.BaseLine) {
- if (uiService.getSelectLocationMode() == Constant.angleLocationMode) {
- locationModeControl.setAngle();
- }
- }
- }
- return true;
- }
- moveCurveLine(curveLineId, dx, dy) {
- dx = dx;
- dy = -dy;
- let curveLine = dataService.getCurveLine(curveLineId);
- let startPoint = dataService.getCurvePoint(curveLine.startId);
- let endPoint = dataService.getCurvePoint(curveLine.endId);
- startPoint.x += dx;
- startPoint.y += dy;
- endPoint.x += dx;
- endPoint.y += dy;
- for (let i = 1; i < curveLine.points.length - 1; ++i) {
- curveLine.points[i].x += dx;
- curveLine.points[i].y += dy;
- }
- curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
- }
- }
- const moveLine = new MoveLine();
- export { moveLine };
|