MoveLine.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. extendedPositionLine.setLinkedBasePointId(line.getLinkedBasePointId());
  122. extendedPositionLine.setLinkedFixPointId(line.getLinkedFixPointId());
  123. dataService.deletePointParent(startPoint.vectorId, lineId);
  124. line.startId = newStartPoint.vectorId;
  125. newStartPoint.setPointParent(line.vectorId, "start");
  126. newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  127. } else {
  128. startPoint.x = point1.x;
  129. startPoint.y = point1.y;
  130. let parents = Object.keys(startPoint.parent);
  131. let extendedLine = dataService.getLine(parents[0]);
  132. if (
  133. extendedLine.getCategory() != VectorCategory.Line.ExtendedPositionLine
  134. ) {
  135. extendedLine = dataService.getLine(parents[1]);
  136. }
  137. if (
  138. extendedLine.getCategory() == VectorCategory.Line.ExtendedPositionLine
  139. ) {
  140. //point1是基准点
  141. point1 = dataService.getPoint(extendedLine.startId);
  142. point2 = dataService.getPoint(extendedLine.endId);
  143. if (mathUtil.getDistance(point1, point2) < Constant.minAdsorbPix) {
  144. dataService.deleteLine(extendedLine.vectorId);
  145. dataService.deletePoint(extendedLine.endId);
  146. line.startId = point1.vectorId;
  147. point1.setPointParent(line.vectorId, "start");
  148. lineGeometry = mathUtil.createLine3(lineGeometry, point1);
  149. }
  150. }
  151. }
  152. point2 = mathUtil.getJoinLinePoint(endPoint, lineGeometry);
  153. endPoint.x = point2.x;
  154. endPoint.y = point2.y;
  155. } else if (
  156. line.getCategory() == VectorCategory.Line.LocationLineByFixPoint &&
  157. line.getLocationMode() == Constant.angleLocationMode
  158. ) {
  159. let point1 = {
  160. x: startPoint.x + dx,
  161. y: startPoint.y + dy,
  162. };
  163. let point2 = {
  164. x: endPoint.x + dx,
  165. y: endPoint.y + dy,
  166. };
  167. let lineGeometry = mathUtil.createLine1(point1, point2);
  168. point1 = mathUtil.getJoinLinePoint(startPoint, lineGeometry);
  169. if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
  170. //达到一定距离才能移动
  171. if (mathUtil.getDistance(startPoint, point1) < Constant.minAdsorbPix) {
  172. return false;
  173. }
  174. let newStartPoint = pointService.create(point1);
  175. let extendedPositionLine = lineService.createByPointId(
  176. startPoint.vectorId,
  177. newStartPoint.vectorId,
  178. VectorCategory.Line.ExtendedPositionLine
  179. );
  180. extendedPositionLine.setLocationMode(Constant.angleLocationMode);
  181. extendedPositionLine.setLinkedBasePointId(line.getLinkedBasePointId());
  182. extendedPositionLine.setLinkedFixPointId(line.getLinkedFixPointId());
  183. dataService.deletePointParent(startPoint.vectorId, lineId);
  184. line.startId = newStartPoint.vectorId;
  185. newStartPoint.setPointParent(line.vectorId, "start");
  186. newStartPoint.setCategory(VectorCategory.Point.TestBasePoint);
  187. let join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
  188. mathUtil.clonePoint(endPoint, join);
  189. } else {
  190. let extendedPositionLine = mathUtil.createLine3(baseLine, startPoint);
  191. let join = mathUtil.getIntersectionPoint(
  192. lineGeometry,
  193. extendedPositionLine
  194. );
  195. mathUtil.clonePoint(startPoint, join);
  196. join = mathUtil.getIntersectionPoint(lineGeometry, baseLine);
  197. mathUtil.clonePoint(endPoint, join);
  198. let parent = startPoint.getParent();
  199. for (let key in parent) {
  200. if (key == lineId) {
  201. continue;
  202. } else {
  203. extendedPositionLine = dataService.getLine(key);
  204. }
  205. }
  206. startPoint = dataService.getPoint(extendedPositionLine.startId);
  207. if (mathUtil.getDistance(point1, startPoint) < Constant.minAdsorbPix) {
  208. let otherPointId = extendedPositionLine.getOtherPointId(
  209. startPoint.vectorId
  210. );
  211. let otherPoint = dataService.getPoint(otherPointId);
  212. if (startPoint.getCategory() == VectorCategory.Point.FixPoint) {
  213. dataService.deleteLine(extendedPositionLine.vectorId);
  214. dataService.deletePoint(otherPoint.vectorId);
  215. line.startId = startPoint.vectorId;
  216. }
  217. join = mathUtil.getJoinLinePoint(startPoint, baseLine);
  218. mathUtil.clonePoint(endPoint, join);
  219. }
  220. }
  221. } else {
  222. //综合定位和垂线定位,拖动基准线更新位置
  223. //缺
  224. startPoint.x += dx;
  225. startPoint.y += dy;
  226. endPoint.x += dx;
  227. endPoint.y += dy;
  228. }
  229. return true;
  230. }
  231. moveCurveLine(curveLineId, dx, dy) {
  232. dx = dx;
  233. dy = -dy;
  234. let curveLine = dataService.getCurveLine(curveLineId);
  235. let startPoint = dataService.getCurvePoint(curveLine.startId);
  236. let endPoint = dataService.getCurvePoint(curveLine.endId);
  237. startPoint.x += dx;
  238. startPoint.y += dy;
  239. endPoint.x += dx;
  240. endPoint.y += dy;
  241. for (let i = 1; i < curveLine.points.length - 1; ++i) {
  242. curveLine.points[i].x += dx;
  243. curveLine.points[i].y += dy;
  244. }
  245. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  246. }
  247. }
  248. const moveLine = new MoveLine();
  249. export { moveLine };