MovePoint.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import { dataService } from "../Service/DataService";
  2. import { pointService } from "../Service/PointService";
  3. import Settings from "../Settings";
  4. import Constant from "../Constant";
  5. import VectorCategory from "../enum/VectorCategory";
  6. import { listenLayer } from "../ListenLayer";
  7. import { uiService } from "../Service/UIService";
  8. import { mathUtil } from "../Util/MathUtil";
  9. import { moveText } from "./MoveText";
  10. import { locationModeControl } from "./LocationModeControl";
  11. export default class MovePoint {
  12. constructor() {}
  13. movePoint(position, pointId) {
  14. let point = dataService.getPoint(pointId);
  15. if (point.getCategory() == VectorCategory.Point.BasePoint) {
  16. this.updateBasePoint(position, pointId);
  17. } else if (point.getCategory() == VectorCategory.Point.FixPoint) {
  18. this.updateFixPoint(position, pointId);
  19. } else {
  20. point.x = position.x;
  21. point.y = position.y;
  22. let parent = point.getParent();
  23. for (let key in parent) {
  24. let line = dataService.getLine(key);
  25. if (line.getCategory() == VectorCategory.Line.BaseLine) {
  26. if (uiService.getSelectLocationMode() == Constant.angleLocationMode) {
  27. locationModeControl.setAngle();
  28. }
  29. } else {
  30. line.setValue(null);
  31. }
  32. }
  33. }
  34. }
  35. finish(pointId) {
  36. if (
  37. pointId &&
  38. listenLayer.modifyPoint &&
  39. listenLayer.modifyPoint.linkedPointId
  40. ) {
  41. let linkedPoint = dataService.getPoint(
  42. listenLayer.modifyPoint.linkedPointId
  43. );
  44. const category = linkedPoint.getCategory();
  45. if (
  46. category != VectorCategory.Point.BasePoint &&
  47. category != VectorCategory.Point.TestBasePoint
  48. ) {
  49. pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId);
  50. uiService.setSelectBasePointId(null);
  51. } else {
  52. let point = dataService.getPoint(pointId);
  53. const parent = point.getParent();
  54. for (let key in parent) {
  55. let line = dataService.getLine(key);
  56. let startPoint = dataService.getPoint(line.startId);
  57. let endPoint = dataService.getPoint(line.endId);
  58. if (mathUtil.getDistance(startPoint, endPoint) == 0) {
  59. pointService.deletePoint(pointId);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. //待测基准点,待测点与基准线相交的点
  66. getTestBasePoint(basePointId, testPointId, locationMode) {
  67. let points = dataService.getPoints();
  68. for (let key in points) {
  69. const point = dataService.getPoint(key);
  70. if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
  71. if (
  72. point.getLinkedBasePointId() == basePointId &&
  73. point.getLocationMode() == locationMode
  74. ) {
  75. return point;
  76. }
  77. }
  78. }
  79. return null;
  80. }
  81. updatePositionByTestPoint(pointId) {
  82. let point = dataService.getPoint(pointId);
  83. let locationMode = point.getLocationMode();
  84. if (locationMode == Constant.angleLocationMode) {
  85. this.updateTestPointByAngle(pointId);
  86. } else if (locationMode == Constant.allLocationMode) {
  87. this.updateTestPointByAll(pointId);
  88. } else if (locationMode == Constant.normalLocationMode) {
  89. this.updateTestPointByNormal(pointId);
  90. }
  91. }
  92. //更新待测点(直角定位法)
  93. // updateTestPointByAngle(testPointId) {
  94. // let testPoint = dataService.getPoint(testPointId);
  95. // let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  96. // let lineGeometry = dataService.getLine(Settings.baseLineId);
  97. // let startPoint = dataService.getPoint(lineGeometry.startId);
  98. // let endPoint = dataService.getPoint(lineGeometry.endId);
  99. // let line = mathUtil.createLine1(startPoint, endPoint);
  100. // let vLine = mathUtil.getVerticalLine(line, testPoint);
  101. // let join = mathUtil.getJoinLinePoint(basePoint, vLine);
  102. // let testBasePoint = this.getTestBasePoint(
  103. // basePoint.vectorId,
  104. // testPointId,
  105. // Constant.angleLocationMode
  106. // );
  107. // mathUtil.clonePoint(testBasePoint, join);
  108. // }
  109. updateTestPointByAngle(testPointId) {
  110. let testPoint = dataService.getPoint(testPointId);
  111. //let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  112. let parent = testPoint.getParent();
  113. let guidePositionLine = dataService.getLine(Object.keys(parent)[0]);
  114. let otherPointId = null;
  115. if (guidePositionLine.startId == testPointId) {
  116. otherPointId = guidePositionLine.endId;
  117. } else if (guidePositionLine.endId == testPointId) {
  118. otherPointId = guidePositionLine.startId;
  119. }
  120. let otherPoint = dataService.getPoint(otherPointId);
  121. parent = otherPoint.getParent();
  122. for (let key in parent) {
  123. if (key == guidePositionLine.vectorId) {
  124. continue;
  125. } else {
  126. let positionLine = dataService.getLine(key);
  127. let startPoint = dataService.getPoint(positionLine.startId);
  128. let endPoint = dataService.getPoint(positionLine.endId);
  129. let positionLineGeometry = mathUtil.createLine1(startPoint, endPoint);
  130. if (!positionLineGeometry) {
  131. let lineGeometry = dataService.getLine(Settings.baseLineId);
  132. let baseStartPoint = dataService.getPoint(lineGeometry.startId);
  133. let baseEndPoint = dataService.getPoint(lineGeometry.endId);
  134. let baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
  135. positionLineGeometry = mathUtil.createLine3(baseLine, testPoint);
  136. }
  137. let join = mathUtil.getJoinLinePoint(testPoint, positionLineGeometry);
  138. mathUtil.clonePoint(otherPoint, join);
  139. // if (
  140. // mathUtil.getDistance(startPoint, endPoint) < Constant.minAdsorbPix
  141. // ) {
  142. // pointService.deletePoint(positionLine.startId);
  143. // }
  144. break;
  145. }
  146. }
  147. }
  148. //更新待测点(综合定位法)
  149. updateTestPointByAll(testPointId) {
  150. let testPoint = dataService.getPoint(testPointId);
  151. let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  152. let lineGeometry = dataService.getLine(Settings.baseLineId);
  153. let startPoint = dataService.getPoint(lineGeometry.startId);
  154. let endPoint = dataService.getPoint(lineGeometry.endId);
  155. let line = mathUtil.createLine1(startPoint, endPoint);
  156. let join = mathUtil.getJoinLinePoint(testPoint, line);
  157. let testBasePoint = this.getTestBasePoint(
  158. basePoint.vectorId,
  159. testPointId,
  160. Constant.allLocationMode
  161. );
  162. mathUtil.clonePoint(testBasePoint, join);
  163. }
  164. //更新待测点(自由定位法)
  165. updateTestPointByNormal(testPointId) {
  166. let testPoint = dataService.getPoint(testPointId);
  167. let lineGeometry = dataService.getLine(Settings.baseLineId);
  168. let startPoint = dataService.getPoint(lineGeometry.startId);
  169. let endPoint = dataService.getPoint(lineGeometry.endId);
  170. let line = mathUtil.createLine1(startPoint, endPoint);
  171. let join = mathUtil.getJoinLinePoint(testPoint, line);
  172. let testBasePoint = this.getTestBasePoint(
  173. null,
  174. testPointId,
  175. Constant.normalLocationMode
  176. );
  177. mathUtil.clonePoint(testBasePoint, join);
  178. }
  179. updateBasePoint(position, basePointId) {
  180. let lineGeometry = dataService.getLine(Settings.baseLineId);
  181. let startPoint = dataService.getPoint(lineGeometry.startId);
  182. let endPoint = dataService.getPoint(lineGeometry.endId);
  183. lineGeometry = mathUtil.createLine1(startPoint, endPoint);
  184. let basePoint = dataService.getPoint(basePointId);
  185. let parent = basePoint.getParent();
  186. for (let key in parent) {
  187. let line = dataService.getLine(key);
  188. if (line.getCategory() == VectorCategory.Line.LocationLineByBasePoint) {
  189. let otherPointId = line.getOtherPointId(basePointId);
  190. let otherPoint = dataService.getPoint(otherPointId);
  191. let otherLine = mathUtil.getLineForPoint(lineGeometry, otherPoint);
  192. line = mathUtil.createLine3(lineGeometry, position);
  193. let join = mathUtil.getIntersectionPoint(line, otherLine);
  194. mathUtil.clonePoint(otherPoint, join);
  195. mathUtil.clonePoint(basePoint, position);
  196. } else if (
  197. line.getCategory() == VectorCategory.Line.ExtendedPositionLine
  198. ) {
  199. let otherPointId = line.getOtherPointId(basePointId);
  200. let otherPoint = dataService.getPoint(otherPointId);
  201. let otherLine = mathUtil.createLine3(lineGeometry, otherPoint);
  202. let join = mathUtil.getJoinLinePoint(position, otherLine);
  203. mathUtil.clonePoint(otherPoint, join);
  204. mathUtil.clonePoint(basePoint, position);
  205. }
  206. }
  207. }
  208. updateFixPoint(position, fixPointId) {
  209. let fixPoint = dataService.getPoint(fixPointId);
  210. let basePoint = dataService.getPoint(fixPoint.linkedBasePointId);
  211. let baseLine = dataService.getLine(Settings.baseLineId);
  212. let startPoint = dataService.getPoint(baseLine.startId);
  213. let endPoint = dataService.getPoint(baseLine.endId);
  214. let baseLineGeometry = mathUtil.createLine1(startPoint, endPoint);
  215. let vLine = mathUtil.getVerticalLine(baseLineGeometry, position);
  216. let join = mathUtil.getIntersectionPoint(baseLineGeometry, vLine);
  217. let parent = fixPoint.getParent();
  218. for (let key in parent) {
  219. let line = dataService.getLine(key);
  220. if (line.getCategory() == VectorCategory.Line.LocationLineByFixPoint) {
  221. let otherPointId = line.getOtherPointId(fixPointId);
  222. let otherPoint = dataService.getPoint(otherPointId);
  223. mathUtil.clonePoint(otherPoint, join);
  224. moveText.moveFullText(position, fixPoint.linkedTextId);
  225. } else if (line.getCategory() == VectorCategory.Line.GuideLocationLine) {
  226. let otherPointId = line.getOtherPointId(fixPointId);
  227. let otherPoint = dataService.getPoint(otherPointId);
  228. let line2 = mathUtil.createLine3(baseLineGeometry, otherPoint);
  229. join = mathUtil.getIntersectionPoint(line2, vLine);
  230. mathUtil.clonePoint(otherPoint, join);
  231. } else if (
  232. line.getCategory() == VectorCategory.Line.ExtendedPositionLine
  233. ) {
  234. let otherPointId = line.getOtherPointId(fixPointId);
  235. let otherPoint = dataService.getPoint(otherPointId);
  236. let line2 = mathUtil.createLine3(baseLineGeometry, fixPoint);
  237. join = mathUtil.getJoinLinePoint(otherPoint, line2);
  238. mathUtil.clonePoint(otherPoint, join);
  239. }
  240. }
  241. mathUtil.clonePoint(fixPoint, position);
  242. }
  243. /*****************************************************************************曲线上的点********************************************************************************/
  244. moveCurvePoint(position, curvePointId) {
  245. let curvePoint = dataService.getCurvePoint(curvePointId);
  246. let curveLine = dataService.getCurveLine(curvePoint.getParent());
  247. curvePoint.setPosition(position);
  248. curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
  249. }
  250. }
  251. const movePoint = new MovePoint();
  252. export { movePoint };