MoveLine.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import Constant from "../Constant";
  2. import { dataService } from "../Service/DataService";
  3. import { lineService } from "../Service/LineService";
  4. import { pointService } from "../Service/PointService";
  5. import { mathUtil } from "../Util/MathUtil";
  6. import VectorCategory from "../enum/VectorCategory";
  7. export default class MoveLine {
  8. constructor() {}
  9. moveLine(lineId, dx, dy) {
  10. dx = dx;
  11. dy = -dy;
  12. let line = dataService.getLine(lineId);
  13. let startPoint = dataService.getPoint(line.startId);
  14. let endPoint = dataService.getPoint(line.endId);
  15. //垂直移动
  16. if (
  17. line.getCategory() == VectorCategory.Line.PositionLine &&
  18. line.getLocationMode() == Constant.angleLocationMode
  19. ) {
  20. let point1 = {
  21. x: startPoint.x + dx,
  22. y: startPoint.y + dy,
  23. };
  24. let point2 = {
  25. x: endPoint.x + dx,
  26. y: endPoint.y + dy,
  27. };
  28. let lineGeometry = mathUtil.createLine1(point1, point2);
  29. point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  30. //startPoint本来是基准点
  31. if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
  32. //达到一定距离才能移动
  33. if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  34. return false;
  35. }
  36. let newStartPoint = pointService.create(point1);
  37. lineService.createByPointId(
  38. startPoint.vectorId,
  39. newStartPoint.vectorId,
  40. VectorCategory.Line.ExtendedPositionLine
  41. );
  42. dataService.deletePointParent(startPoint.vectorId, lineId);
  43. line.startId = newStartPoint.vectorId;
  44. newStartPoint.setPointParent(line.vectorId, "start");
  45. } else {
  46. startPoint.x = point1.x;
  47. startPoint.y = point1.y;
  48. let parents = Object.keys(startPoint.parent);
  49. let extendedLine = dataService.getLine(parents[0]);
  50. if (
  51. extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
  52. ) {
  53. extendedLine = dataService.getLine(parents[1]);
  54. }
  55. if (
  56. extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
  57. ) {
  58. //point1是基准点
  59. point1 = dataService.getPoint(extendedLine.startId);
  60. point2 = dataService.getPoint(extendedLine.endId);
  61. if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  62. dataService.deleteLine(extendedLine.vectorId);
  63. dataService.deletePoint(extendedLine.endId);
  64. line.startId = point1.vectorId;
  65. point1.setPointParent(line.vectorId, "start");
  66. lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  67. }
  68. }
  69. }
  70. point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  71. endPoint.x = point2.x;
  72. endPoint.y = point2.y;
  73. } else {
  74. startPoint.x += dx;
  75. startPoint.y += dy;
  76. endPoint.x += dx;
  77. endPoint.y += dy;
  78. }
  79. return true;
  80. }
  81. moveCurveLine(curveLineId, dx, dy) {
  82. dx = dx;
  83. dy = -dy;
  84. let curveLine = dataService.getCurveLine(curveLineId);
  85. let startPoint = dataService.getCurvePoint(curveLine.startId);
  86. let endPoint = dataService.getCurvePoint(curveLine.endId);
  87. startPoint.x += dx;
  88. startPoint.y += dy;
  89. endPoint.x += dx;
  90. endPoint.y += dy;
  91. for (let i = 1; i < curveLine.points.length - 1; ++i) {
  92. curveLine.points[i].x += dx;
  93. curveLine.points[i].y += dy;
  94. }
  95. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  96. }
  97. }
  98. const moveLine = new MoveLine();
  99. export { moveLine };