MovePoint.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. export default class MovePoint {
  10. constructor() {}
  11. movePoint(position, pointId) {
  12. let point = dataService.getPoint(pointId);
  13. point.x = position.x;
  14. point.y = position.y;
  15. if (point.getCategory() == VectorCategory.Point.TestPoint) {
  16. this.updatePositionByTestPoint(pointId);
  17. } else if (point.getCategory() == VectorCategory.Point.BasePoint) {
  18. this.updateBasePoint(pointId);
  19. } else {
  20. let parent = point.getParent();
  21. for (let key in parent) {
  22. let line = dataService.getLine(key);
  23. line.setValue(null);
  24. //拖拽的点是基准线
  25. if (line.category == VectorCategory.Line.BaseLine) {
  26. let points = dataService.getPoints();
  27. for (let key in points) {
  28. let testPoint = dataService.getPoint(key);
  29. if (testPoint.category == VectorCategory.Point.TestPoint) {
  30. this.updatePositionByTestPoint(key);
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. finish(pointId) {
  38. // if (
  39. // pointId &&
  40. // listenLayer.modifyPoint &&
  41. // listenLayer.modifyPoint.linkedPointId
  42. // ) {
  43. // let linkedPoint = dataService.getPoint(
  44. // listenLayer.modifyPoint.linkedPointId
  45. // );
  46. // const category = linkedPoint.getCategory();
  47. // if (
  48. // category != VectorCategory.Point.BasePoint &&
  49. // category != VectorCategory.Point.TestBasePoint &&
  50. // category != VectorCategory.Point.TestPoint
  51. // ) {
  52. // pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId);
  53. // Settings.selectBasePointId = null;
  54. // } else if (category == VectorCategory.Point.BasePoint) {
  55. // Settings.selectBasePointId = pointId;
  56. // } else {
  57. // Settings.selectBasePointId = null;
  58. // }
  59. // }
  60. if (
  61. pointId &&
  62. listenLayer.modifyPoint &&
  63. listenLayer.modifyPoint.linkedPointId
  64. ) {
  65. let linkedPoint = dataService.getPoint(
  66. listenLayer.modifyPoint.linkedPointId
  67. );
  68. const category = linkedPoint.getCategory();
  69. if (
  70. category != VectorCategory.Point.BasePoint &&
  71. category != VectorCategory.Point.TestBasePoint &&
  72. category != VectorCategory.Point.TestPoint
  73. ) {
  74. pointService.mergePoint(pointId, listenLayer.modifyPoint.linkedPointId);
  75. Settings.selectBasePointId = null;
  76. } else {
  77. let point = dataService.getPoint(pointId);
  78. const parent = point.getParent();
  79. for (let key in parent) {
  80. let line = dataService.getLine(key);
  81. let startPoint = dataService.getPoint(line.startId);
  82. let endPoint = dataService.getPoint(line.endId);
  83. if (mathUtil.getDistance(startPoint, endPoint) == 0) {
  84. pointService.deletePoint(pointId);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. //待测基准点,待测点与基准线相交的点
  91. getTestBasePoint(basePointId, testPointId, locationMode) {
  92. let points = dataService.getPoints();
  93. for (let key in points) {
  94. const point = dataService.getPoint(key);
  95. if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
  96. if (
  97. point.getLinkedBasePointId() == basePointId &&
  98. point.getLinkedTestPointId() == testPointId &&
  99. point.getLocationMode() == locationMode
  100. ) {
  101. return point;
  102. }
  103. }
  104. }
  105. return null;
  106. }
  107. updatePositionByTestPoint(pointId) {
  108. let point = dataService.getPoint(pointId);
  109. let locationMode = point.getLocationMode();
  110. if (locationMode == Constant.angleLocationMode) {
  111. this.updateTestPointByAngle(pointId);
  112. } else if (locationMode == Constant.allLocationMode) {
  113. this.updateTestPointByAll(pointId);
  114. } else if (locationMode == Constant.normalLocationMode) {
  115. this.updateTestPointByNormal(pointId);
  116. }
  117. }
  118. //更新待测点(直角定位法)
  119. // updateTestPointByAngle(testPointId) {
  120. // let testPoint = dataService.getPoint(testPointId);
  121. // let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  122. // let lineGeometry = dataService.getLine(Settings.baseLineId);
  123. // let startPoint = dataService.getPoint(lineGeometry.startId);
  124. // let endPoint = dataService.getPoint(lineGeometry.endId);
  125. // let line = mathUtil.createLine1(startPoint, endPoint);
  126. // let vLine = mathUtil.getVerticalLine(line, testPoint);
  127. // let join = mathUtil.getJoinLinePoint(basePoint, vLine);
  128. // let testBasePoint = this.getTestBasePoint(
  129. // basePoint.vectorId,
  130. // testPointId,
  131. // Constant.angleLocationMode
  132. // );
  133. // mathUtil.clonePoint(testBasePoint, join);
  134. // }
  135. updateTestPointByAngle(testPointId) {
  136. let testPoint = dataService.getPoint(testPointId);
  137. //let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  138. let parent = testPoint.getParent();
  139. let guidePositionLine = dataService.getLine(Object.keys(parent)[0]);
  140. let otherPointId = null;
  141. if (guidePositionLine.startId == testPointId) {
  142. otherPointId = guidePositionLine.endId;
  143. } else if (guidePositionLine.endId == testPointId) {
  144. otherPointId = guidePositionLine.startId;
  145. }
  146. let otherPoint = dataService.getPoint(otherPointId);
  147. parent = otherPoint.getParent();
  148. for (let key in parent) {
  149. if (key == guidePositionLine.vectorId) {
  150. continue;
  151. } else {
  152. let positionLine = dataService.getLine(key);
  153. let startPoint = dataService.getPoint(positionLine.startId);
  154. let endPoint = dataService.getPoint(positionLine.endId);
  155. let positionLineGeometry = mathUtil.createLine1(startPoint, endPoint);
  156. if (!positionLineGeometry) {
  157. let lineGeometry = dataService.getLine(Settings.baseLineId);
  158. let baseStartPoint = dataService.getPoint(lineGeometry.startId);
  159. let baseEndPoint = dataService.getPoint(lineGeometry.endId);
  160. let baseLine = mathUtil.createLine1(baseStartPoint, baseEndPoint);
  161. positionLineGeometry = mathUtil.createLine3(baseLine, testPoint);
  162. }
  163. let join = mathUtil.getJoinLinePoint(testPoint, positionLineGeometry);
  164. mathUtil.clonePoint(otherPoint, join);
  165. // if (
  166. // mathUtil.getDistance(startPoint, endPoint) < Constant.minAdsorbPix
  167. // ) {
  168. // pointService.deletePoint(positionLine.startId);
  169. // }
  170. break;
  171. }
  172. }
  173. }
  174. //更新待测点(综合定位法)
  175. updateTestPointByAll(testPointId) {
  176. let testPoint = dataService.getPoint(testPointId);
  177. let basePoint = dataService.getPoint(testPoint.getLinkedBasePointId());
  178. let lineGeometry = dataService.getLine(Settings.baseLineId);
  179. let startPoint = dataService.getPoint(lineGeometry.startId);
  180. let endPoint = dataService.getPoint(lineGeometry.endId);
  181. let line = mathUtil.createLine1(startPoint, endPoint);
  182. let join = mathUtil.getJoinLinePoint(testPoint, line);
  183. let testBasePoint = this.getTestBasePoint(
  184. basePoint.vectorId,
  185. testPointId,
  186. Constant.allLocationMode
  187. );
  188. mathUtil.clonePoint(testBasePoint, join);
  189. }
  190. //更新待测点(自由定位法)
  191. updateTestPointByNormal(testPointId) {
  192. let testPoint = dataService.getPoint(testPointId);
  193. let lineGeometry = dataService.getLine(Settings.baseLineId);
  194. let startPoint = dataService.getPoint(lineGeometry.startId);
  195. let endPoint = dataService.getPoint(lineGeometry.endId);
  196. let line = mathUtil.createLine1(startPoint, endPoint);
  197. let join = mathUtil.getJoinLinePoint(testPoint, line);
  198. let testBasePoint = this.getTestBasePoint(
  199. null,
  200. testPointId,
  201. Constant.normalLocationMode
  202. );
  203. mathUtil.clonePoint(testBasePoint, join);
  204. }
  205. updateBasePoint(basePointId) {
  206. let points = dataService.getPoints();
  207. for (let key in points) {
  208. let point = dataService.getPoint(key);
  209. if (
  210. point.getCategory() == VectorCategory.Point.TestPoint &&
  211. point.getLinkedBasePointId() == basePointId
  212. ) {
  213. this.updatePositionByTestPoint(key);
  214. }
  215. }
  216. }
  217. /*****************************************************************************曲线上的点********************************************************************************/
  218. moveCurvePoint(position, curvePointId) {
  219. let curvePoint = dataService.getCurvePoint(curvePointId);
  220. curvePoint.setPosition(position);
  221. }
  222. }
  223. const movePoint = new MovePoint();
  224. export { movePoint };