AddPoint.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { dataService } from '../Service/DataService';
  2. import { lineService } from '../Service/LineService';
  3. import { pointService } from '../Service/PointService';
  4. import VectorCategory from '../enum/VectorCategory';
  5. import Point from '../Geometry/Point.js';
  6. import { mathUtil } from '../Util/MathUtil';
  7. import addLine from './AddLine';
  8. import Settings from '../Settings';
  9. import { stateService } from '../Service/StateService';
  10. import LayerEvents from '../enum/LayerEvents';
  11. import VectorType from '../enum/VectorType';
  12. import Constant from '../Constant';
  13. import { listenLayer } from '../ListenLayer';
  14. export default class AddPoint {
  15. constructor() {
  16. this.testPointIds = []; //所有待测点
  17. }
  18. buildPoint(position) {
  19. //只有一个基准点的时候,测量的时候自动选择基准点
  20. if ((Settings.selectLocationMode == Constant.angleLocationMode || Settings.selectLocationMode == Constant.allLocationMode) && Settings.basePointIds.length == 1) {
  21. Settings.selectBasePointId = Settings.basePointIds[0];
  22. }
  23. let newPoint;
  24. if (Settings.selectPointCategory == VectorCategory.Point.BasePoint) {
  25. newPoint = pointService.create(position);
  26. Settings.selectBasePointId = newPoint.vectorId;
  27. } else {
  28. if (Settings.selectBasePointId != null && Settings.selectLocationMode == Constant.angleLocationMode) {
  29. newPoint = pointService.create(position);
  30. this.setLocationByAngle(newPoint.vectorId);
  31. newPoint.setLocationMode(Constant.angleLocationMode);
  32. stateService.setEventName(LayerEvents.AddPoint);
  33. } else if (Settings.selectBasePointId != null && Settings.selectLocationMode == Constant.allLocationMode) {
  34. newPoint = pointService.create(position);
  35. this.setLocationByAll(newPoint.vectorId);
  36. newPoint.setLocationMode(Constant.allLocationMode);
  37. stateService.setEventName(LayerEvents.AddPoint);
  38. } else if (Settings.baseLineId != null && Settings.selectLocationMode == Constant.normalLocationMode) {
  39. newPoint = pointService.create(position);
  40. this.setLocationByNormal(newPoint.vectorId);
  41. newPoint.setLocationMode(Constant.normalLocationMode);
  42. stateService.setEventName(LayerEvents.AddPoint);
  43. } else if (Settings.selectBasePointId == null && (Settings.selectLocationMode == Constant.angleLocationMode || Settings.selectLocationMode == Constant.allLocationMode)) {
  44. return null;
  45. }
  46. if (
  47. newPoint &&
  48. (newPoint.getLocationMode() == Constant.allLocationMode || newPoint.getLocationMode() == Constant.angleLocationMode || newPoint.getLocationMode() == Constant.normalLocationMode) &&
  49. newPoint.getCategory() == VectorCategory.Point.TestPoint
  50. ) {
  51. this.testPointIds.push(newPoint.vectorId);
  52. }
  53. }
  54. listenLayer.clear();
  55. return newPoint;
  56. }
  57. isFocusBasePoint() {
  58. if (Settings.selectBasePointId) {
  59. let point = dataService.getPoint(Settings.selectBasePointId);
  60. if (point.getCategory() == VectorCategory.Point.BasePoint) {
  61. return point;
  62. }
  63. }
  64. return null;
  65. }
  66. //直角定位法
  67. setLocationByAngle(testPointId) {
  68. let basePoint = this.isFocusBasePoint();
  69. if (!basePoint) {
  70. return;
  71. }
  72. let testPoint = dataService.getPoint(testPointId);
  73. if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
  74. return;
  75. }
  76. testPoint.setLinkedBasePointId(basePoint.vectorId);
  77. let lineGeometry = dataService.getLine(Settings.baseLineId);
  78. let startPoint = dataService.getPoint(lineGeometry.startId);
  79. let endPoint = dataService.getPoint(lineGeometry.endId);
  80. let line = mathUtil.createLine1(startPoint, endPoint);
  81. let vLine = mathUtil.getVerticalLine(line, testPoint);
  82. let join = mathUtil.getJoinLinePoint(basePoint, vLine);
  83. join = pointService.create(join);
  84. join.setCategory(VectorCategory.Point.TestBasePoint);
  85. join.setLocationMode(Constant.angleLocationMode);
  86. join.setLinkedBasePointId(basePoint.vectorId);
  87. join.setLinkedTestPointId(testPointId);
  88. let guidePositionLine = lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.GuidePositionLine);
  89. let positionLine = lineService.createByPointId(basePoint.vectorId, join.vectorId, VectorCategory.Line.PositionLine);
  90. guidePositionLine.setLocationMode(Constant.angleLocationMode);
  91. positionLine.setLocationMode(Constant.angleLocationMode);
  92. join.setCategory(VectorCategory.Point.TestBasePoint);
  93. }
  94. //综合定位法
  95. setLocationByAll(testPointId) {
  96. let basePoint = this.isFocusBasePoint();
  97. if (!basePoint) {
  98. return;
  99. }
  100. let testPoint = dataService.getPoint(testPointId);
  101. testPoint.setLinkedBasePointId(basePoint.vectorId);
  102. let lineGeometry = dataService.getLine(Settings.baseLineId);
  103. let startPoint = dataService.getPoint(lineGeometry.startId);
  104. let endPoint = dataService.getPoint(lineGeometry.endId);
  105. let line = mathUtil.createLine1(startPoint, endPoint);
  106. let join = mathUtil.getJoinLinePoint(testPoint, line);
  107. join = pointService.create(join); //经过待测点且与基准线垂直的线段,与基准线的交点
  108. join.setCategory(VectorCategory.Point.TestBasePoint);
  109. join.setLocationMode(Constant.allLocationMode);
  110. join.setLinkedBasePointId(basePoint.vectorId);
  111. join.setLinkedTestPointId(testPointId);
  112. //待测点与基准线的垂直线
  113. lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.PositionLine);
  114. //暂时没有其他待测点
  115. if (this.testPointIds.length == 0) {
  116. //待测点与基准线点的连线
  117. lineService.createByPointId(basePoint.vectorId, testPointId, VectorCategory.Line.PositionLine);
  118. } else {
  119. //取上一个待测点
  120. lineService.createByPointId(this.testPointIds[this.testPointIds.length - 1], testPointId, VectorCategory.Line.PositionLine);
  121. testPoint.setLinkedTestPointId(this.testPointIds[this.testPointIds.length - 1]);
  122. }
  123. }
  124. setLocationByNormal(testPointId) {
  125. let testPoint = dataService.getPoint(testPointId);
  126. if (testPoint.getCategory() != VectorCategory.Point.TestPoint) {
  127. return;
  128. }
  129. if (!Settings.baseLineId) {
  130. return;
  131. }
  132. let lineGeometry = dataService.getLine(Settings.baseLineId);
  133. let startPoint = dataService.getPoint(lineGeometry.startId);
  134. let endPoint = dataService.getPoint(lineGeometry.endId);
  135. let line = mathUtil.createLine1(startPoint, endPoint);
  136. let vLine = mathUtil.getVerticalLine(line, testPoint);
  137. let join = mathUtil.getIntersectionPoint(vLine, line);
  138. join = pointService.create(join);
  139. join.setCategory(VectorCategory.Point.TestBasePoint);
  140. join.setLocationMode(Constant.normalLocationMode);
  141. join.setLinkedTestPointId(testPointId);
  142. lineService.createByPointId(testPointId, join.vectorId, VectorCategory.Line.PositionLine);
  143. }
  144. deleteTestPoints() {
  145. for (let i = 0; i < this.testPointIds.length; ++i) {
  146. pointService.deletePoint(this.testPointIds[i]);
  147. }
  148. this.testPointIds = [];
  149. }
  150. resetTestPoints(){
  151. this.testPointIds = [];
  152. }
  153. }
  154. const addPoint = new AddPoint();
  155. export { addPoint };