MoveLine.js 7.5 KB

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