MoveLine.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. export default class MoveLine {
  10. constructor() {}
  11. // moveLine(lineId, dx, dy) {
  12. // dx = dx;
  13. // dy = -dy;
  14. // let line = dataService.getLine(lineId);
  15. // let startPoint = dataService.getPoint(line.startId);
  16. // let endPoint = dataService.getPoint(line.endId);
  17. // //垂直移动
  18. // if (line.getCategory() == VectorCategory.Line.PositionLine && line.getLocationMode() == Constant.angleLocationMode) {
  19. // let point1 = {
  20. // x: startPoint.x + dx,
  21. // y: startPoint.y + dy,
  22. // };
  23. // let point2 = {
  24. // x: endPoint.x + dx,
  25. // y: endPoint.y + dy,
  26. // };
  27. // let lineGeometry = mathUtil.createLine1(point1, point2);
  28. // point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  29. // //startPoint本来是基准点
  30. // if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
  31. // //达到一定距离才能移动
  32. // if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  33. // return false;
  34. // }
  35. // let newStartPoint = pointService.create(point1);
  36. // let extendedPositionLine = lineService.createByPointId(startPoint.vectorId, newStartPoint.vectorId, VectorCategory.Line.ExtendedPositionLine);
  37. // extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  38. // dataService.deletePointParent(startPoint.vectorId, lineId);
  39. // line.startId = newStartPoint.vectorId;
  40. // newStartPoint.setPointParent(line.vectorId, 'start');
  41. // newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  42. // } else {
  43. // startPoint.x = point1.x;
  44. // startPoint.y = point1.y;
  45. // let parents = Object.keys(startPoint.parent);
  46. // let extendedLine = dataService.getLine(parents[0]);
  47. // if (extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine) {
  48. // extendedLine = dataService.getLine(parents[1]);
  49. // }
  50. // if (extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine) {
  51. // //point1是基准点
  52. // point1 = dataService.getPoint(extendedLine.startId);
  53. // point2 = dataService.getPoint(extendedLine.endId);
  54. // if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  55. // dataService.deleteLine(extendedLine.vectorId);
  56. // dataService.deletePoint(extendedLine.endId);
  57. // line.startId = point1.vectorId;
  58. // point1.setPointParent(line.vectorId, 'start');
  59. // lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  60. // }
  61. // }
  62. // }
  63. // point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  64. // endPoint.x = point2.x;
  65. // endPoint.y = point2.y;
  66. // } else {
  67. // //综合定位和垂线定位,拖动基准线更新位置
  68. // if (line.getCategory() == VectorCategory.Line.BaseLine) {
  69. // let points = dataService.vectorData.points;
  70. // for (let key in points) {
  71. // if (points[key].category == VectorCategory.Point.TestPoint && (points[key].locationMode == Constant.allLocationMode || points[key].locationMode == Constant.normalLocationMode)) {
  72. // movePoint.updatePositionByTestPoint(points[key].vectorId);
  73. // }
  74. // }
  75. // }
  76. // startPoint.x += dx;
  77. // startPoint.y += dy;
  78. // endPoint.x += dx;
  79. // endPoint.y += dy;
  80. // }
  81. // return true;
  82. // }
  83. moveLine(lineId, dx, dy) {
  84. dx = dx;
  85. dy = -dy;
  86. let line = dataService.getLine(lineId);
  87. let startPoint = dataService.getPoint(line.startId);
  88. let endPoint = dataService.getPoint(line.endId);
  89. let baseLine = dataService.getLine(Settings.baseLineId);
  90. let baseStartPoint = dataService.getPoint(baseLine.startId);
  91. let baseEndPoint = dataService.getPoint(baseLine.endId);
  92. baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
  93. //垂直移动,直角定位法只支持定位线的拖拽
  94. if (
  95. line.getCategory() == VectorCategory.Line.LocationLineByBasePoint &&
  96. line.getLocationMode() == Constant.angleLocationMode
  97. ) {
  98. let point1 = {
  99. x: startPoint.x + dx,
  100. y: startPoint.y + dy,
  101. };
  102. let point2 = {
  103. x: endPoint.x + dx,
  104. y: endPoint.y + dy,
  105. };
  106. let lineGeometry = mathUtil.createLine1(point1, point2);
  107. point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  108. //startPoint本来是基准点
  109. if (startPoint.getCategory() == VectorCategory.Point.BasePoint) {
  110. //达到一定距离才能移动
  111. if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  112. return false;
  113. }
  114. let newStartPoint = pointService.create(point1);
  115. let extendedPositionLine = lineService.createByPointId(
  116. startPoint.vectorId,
  117. newStartPoint.vectorId,
  118. VectorCategory.Line.ExtendedPositionLine
  119. );
  120. extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  121. dataService.deletePointParent(startPoint.vectorId, lineId);
  122. line.startId = newStartPoint.vectorId;
  123. newStartPoint.setPointParent(line.vectorId, "start");
  124. newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  125. } else {
  126. startPoint.x = point1.x;
  127. startPoint.y = point1.y;
  128. let parents = Object.keys(startPoint.parent);
  129. let extendedLine = dataService.getLine(parents[0]);
  130. if (
  131. extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
  132. ) {
  133. extendedLine = dataService.getLine(parents[1]);
  134. }
  135. if (
  136. extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
  137. ) {
  138. //point1是基准点
  139. point1 = dataService.getPoint(extendedLine.startId);
  140. point2 = dataService.getPoint(extendedLine.endId);
  141. if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  142. dataService.deleteLine(extendedLine.vectorId);
  143. dataService.deletePoint(extendedLine.endId);
  144. line.startId = point1.vectorId;
  145. point1.setPointParent(line.vectorId, "start");
  146. lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  147. }
  148. }
  149. }
  150. point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  151. endPoint.x = point2.x;
  152. endPoint.y = point2.y;
  153. } else if (
  154. line.getCategory() == VectorCategory.Line.LocationLineByFixPoint &&
  155. line.getLocationMode() == Constant.angleLocationMode
  156. ) {
  157. let point1 = {
  158. x: startPoint.x + dx,
  159. y: startPoint.y + dy,
  160. };
  161. let point2 = {
  162. x: endPoint.x + dx,
  163. y: endPoint.y + dy,
  164. };
  165. let lineGeometry = mathUtil.createLine1(point1, point2);
  166. point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  167. if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
  168. //达到一定距离才能移动
  169. if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  170. return false;
  171. }
  172. let newStartPoint = pointService.create(point1);
  173. let extendedPositionLine = lineService.createByPointId(
  174. startPoint.vectorId,
  175. newStartPoint.vectorId,
  176. VectorCategory.Line.ExtendedPositionLine
  177. );
  178. extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  179. dataService.deletePointParent(startPoint.vectorId, lineId);
  180. line.startId = newStartPoint.vectorId;
  181. newStartPoint.setPointParent(line.vectorId, "start");
  182. newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  183. let join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
  184. mathUtil.clonePoint(endPoint, join);
  185. } else {
  186. let extendedPositionLine = mathUtil.createLine3(baseLine, startPoint);
  187. let join = mathUtil.getIntersectionPoint(
  188. lineGeometry,
  189. extendedPositionLine
  190. );
  191. mathUtil.clonePoint(startPoint, join);
  192. join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
  193. mathUtil.clonePoint(endPoint, join);
  194. let parent = startPoint.getParent();
  195. for (let key in parent) {
  196. if (key == lineId) {
  197. continue;
  198. } else {
  199. extendedPositionLine = dataService.getLine(key);
  200. }
  201. }
  202. startPoint = dataService.getPoint(extendedPositionLine.startId);
  203. if (mathUtil.getDistance(point1, startPoint) < Constant.minAdsorbPix) {
  204. let otherPointId = extendedPositionLine.getOtherPointId(
  205. startPoint.vectorId
  206. );
  207. let otherPoint = dataService.getPoint(otherPointId);
  208. if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
  209. dataService.deleteLine(extendedPositionLine.vectorId);
  210. dataService.deletePoint(otherPoint.vectorId);
  211. line.startId = startPoint.vectorId;
  212. }
  213. join = mathUtil.getJoinLinePoint(startPoint, baseLine);
  214. mathUtil.clonePoint(endPoint, join);
  215. }
  216. }
  217. } else {
  218. //综合定位和垂线定位,拖动基准线更新位置
  219. //缺
  220. startPoint.x += dx;
  221. startPoint.y += dy;
  222. endPoint.x += dx;
  223. endPoint.y += dy;
  224. }
  225. return true;
  226. }
  227. moveCurveLine(curveLineId, dx, dy) {
  228. dx = dx;
  229. dy = -dy;
  230. let curveLine = dataService.getCurveLine(curveLineId);
  231. let startPoint = dataService.getCurvePoint(curveLine.startId);
  232. let endPoint = dataService.getCurvePoint(curveLine.endId);
  233. startPoint.x += dx;
  234. startPoint.y += dy;
  235. endPoint.x += dx;
  236. endPoint.y += dy;
  237. for (let i = 1; i < curveLine.points.length - 1; ++i) {
  238. curveLine.points[i].x += dx;
  239. curveLine.points[i].y += dy;
  240. }
  241. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  242. }
  243. }
  244. const moveLine = new MoveLine();
  245. export { moveLine };