MoveLine.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 { movePoint } from "./MovePoint";
  6. import { mathUtil } from "../Util/MathUtil";
  7. import VectorCategory from "../enum/VectorCategory";
  8. export default class MoveLine {
  9. constructor() {}
  10. // moveLine(lineId, dx, dy) {
  11. // dx = dx;
  12. // dy = -dy;
  13. // let line = dataService.getLine(lineId);
  14. // let startPoint = dataService.getPoint(line.startId);
  15. // let endPoint = dataService.getPoint(line.endId);
  16. // //垂直移动
  17. // if (line.getCategory() == VectorCategory.Line.PositionLine && line.getLocationMode() == Constant.angleLocationMode) {
  18. // let point1 = {
  19. // x: startPoint.x + dx,
  20. // y: startPoint.y + dy,
  21. // };
  22. // let point2 = {
  23. // x: endPoint.x + dx,
  24. // y: endPoint.y + dy,
  25. // };
  26. // let lineGeometry = mathUtil.createLine1(point1, point2);
  27. // point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  28. // //startPoint本来是基准点
  29. // if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
  30. // //达到一定距离才能移动
  31. // if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  32. // return false;
  33. // }
  34. // let newStartPoint = pointService.create(point1);
  35. // let extendedPositionLine = lineService.createByPointId(startPoint.vectorId, newStartPoint.vectorId, VectorCategory.Line.ExtendedPositionLine);
  36. // extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  37. // dataService.deletePointParent(startPoint.vectorId, lineId);
  38. // line.startId = newStartPoint.vectorId;
  39. // newStartPoint.setPointParent(line.vectorId, 'start');
  40. // newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  41. // } else {
  42. // startPoint.x = point1.x;
  43. // startPoint.y = point1.y;
  44. // let parents = Object.keys(startPoint.parent);
  45. // let extendedLine = dataService.getLine(parents[0]);
  46. // if (extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine) {
  47. // extendedLine = dataService.getLine(parents[1]);
  48. // }
  49. // if (extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
  50. // //point1是基准点
  51. // point1 = dataService.getPoint(extendedLine.startId);
  52. // point2 = dataService.getPoint(extendedLine.endId);
  53. // if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  54. // dataService.deleteLine(extendedLine.vectorId);
  55. // dataService.deletePoint(extendedLine.endId);
  56. // line.startId = point1.vectorId;
  57. // point1.setPointParent(line.vectorId, 'start');
  58. // lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  59. // }
  60. // }
  61. // }
  62. // point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  63. // endPoint.x = point2.x;
  64. // endPoint.y = point2.y;
  65. // } else {
  66. // //综合定位和垂线定位,拖动基准线更新位置
  67. // if (line.getCategory() == VectorCategory.Line.BaseLine) {
  68. // let points = dataService.vectorData.points;
  69. // for (let key in points) {
  70. // if (points[key].category == VectorCategory.Point.TestPoint && (points[key].locationMode == Constant.allLocationMode || points[key].locationMode == Constant.normalLocationMode)) {
  71. // movePoint.updatePositionByTestPoint(points[key].vectorId);
  72. // }
  73. // }
  74. // }
  75. // startPoint.x += dx;
  76. // startPoint.y += dy;
  77. // endPoint.x += dx;
  78. // endPoint.y += dy;
  79. // }
  80. // return true;
  81. // }
  82. moveLine(lineId, dx, dy) {
  83. dx = dx;
  84. dy = -dy;
  85. let line = dataService.getLine(lineId);
  86. let startPoint = dataService.getPoint(line.startId);
  87. let endPoint = dataService.getPoint(line.endId);
  88. //垂直移动,直角定位法只支持定位线的拖拽
  89. if (
  90. (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint ||
  91. line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) &&
  92. line.getLocationMode() == Constant.angleLocationMode
  93. ) {
  94. let point1 = {
  95. x: startPoint.x + dx,
  96. y: startPoint.y + dy,
  97. };
  98. let point2 = {
  99. x: endPoint.x + dx,
  100. y: endPoint.y + dy,
  101. };
  102. let lineGeometry = mathUtil.createLine1(point1, point2);
  103. point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  104. //startPoint本来是基准点
  105. if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
  106. //达到一定距离才能移动
  107. if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  108. return false;
  109. }
  110. let newStartPoint = pointService.create(point1);
  111. let extendedPositionLine = lineService.createByPointId(
  112. startPoint.vectorId,
  113. newStartPoint.vectorId,
  114. VectorCategory.Line.ExtendedPositionLine
  115. );
  116. extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  117. dataService.deletePointParent(startPoint.vectorId, lineId);
  118. line.startId = newStartPoint.vectorId;
  119. newStartPoint.setPointParent(line.vectorId, "start");
  120. newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  121. } else {
  122. startPoint.x = point1.x;
  123. startPoint.y = point1.y;
  124. let parents = Object.keys(startPoint.parent);
  125. let extendedLine = dataService.getLine(parents[0]);
  126. if (
  127. extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
  128. ) {
  129. extendedLine = dataService.getLine(parents[1]);
  130. }
  131. if (
  132. extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
  133. ) {
  134. //point1是基准点
  135. point1 = dataService.getPoint(extendedLine.startId);
  136. point2 = dataService.getPoint(extendedLine.endId);
  137. if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  138. dataService.deleteLine(extendedLine.vectorId);
  139. dataService.deletePoint(extendedLine.endId);
  140. line.startId = point1.vectorId;
  141. point1.setPointParent(line.vectorId, "start");
  142. lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  143. }
  144. }
  145. }
  146. point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  147. endPoint.x = point2.x;
  148. endPoint.y = point2.y;
  149. } else {
  150. //综合定位和垂线定位,拖动基准线更新位置
  151. //缺
  152. startPoint.x += dx;
  153. startPoint.y += dy;
  154. endPoint.x += dx;
  155. endPoint.y += dy;
  156. }
  157. return true;
  158. }
  159. moveCurveLine(curveLineId, dx, dy) {
  160. dx = dx;
  161. dy = -dy;
  162. let curveLine = dataService.getCurveLine(curveLineId);
  163. let startPoint = dataService.getCurvePoint(curveLine.startId);
  164. let endPoint = dataService.getCurvePoint(curveLine.endId);
  165. startPoint.x += dx;
  166. startPoint.y += dy;
  167. endPoint.x += dx;
  168. endPoint.y += dy;
  169. for (let i = 1; i < curveLine.points.length - 1; ++i) {
  170. curveLine.points[i].x += dx;
  171. curveLine.points[i].y += dy;
  172. }
  173. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  174. }
  175. }
  176. const moveLine = new MoveLine();
  177. export { moveLine };