123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import Constant from "../Constant";
- import { dataService } from "../Service/DataService";
- import { lineService } from "../Service/LineService";
- import { pointService } from "../Service/PointService";
- import { mathUtil } from "../Util/MathUtil";
- import VectorCategory from "../enum/VectorCategory";
- 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);
- //垂直移动
- if (
- line.getCategory() == VectorCategory.Line.PositionLine &&
- 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);
- lineService.createByPointId(
- startPoint.vectorId,
- newStartPoint.vectorId,
- VectorCategory.Line.ExtendedPositionLine
- );
- dataService.deletePointParent(startPoint.vectorId, lineId);
- line.startId = newStartPoint.vectorId;
- newStartPoint.setPointParent(line.vectorId, "start");
- } 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 {
- startPoint.x += dx;
- startPoint.y += dy;
- endPoint.x += dx;
- endPoint.y += dy;
- }
- 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 };
|