AddLine.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { dataService } from "../Service/DataService";
  2. import { lineService } from "../Service/LineService";
  3. import { listenLayer } from "../ListenLayer";
  4. import VectorCategory from "../enum/VectorCategory";
  5. import Point from "../Geometry/Point.js";
  6. import { mathUtil } from "../Util/MathUtil";
  7. import Settings from "../Settings";
  8. import { pointService } from "../Service/PointService";
  9. export default class AddLine {
  10. constructor() {
  11. this.newLine = null;
  12. this.startInfo = {};
  13. }
  14. setPointInfo(pointInfo) {
  15. this.startInfo = {
  16. position: {
  17. x: pointInfo.x,
  18. y: pointInfo.y,
  19. },
  20. linkedPointId: pointInfo.linkedPointId,
  21. lineId: pointInfo.lineId,
  22. };
  23. }
  24. setNewLinePoint(position) {
  25. if (listenLayer.modifyPoint) {
  26. this.setPointInfo(listenLayer.modifyPoint);
  27. } else {
  28. this.setPointInfo(position);
  29. }
  30. return true;
  31. }
  32. buildLine(position) {
  33. if (
  34. this.newLine == null &&
  35. !mathUtil.equalPoint(this.startInfo.position, position)
  36. ) {
  37. this.newLine = lineService.create(this.startInfo.position, position);
  38. }
  39. }
  40. updateLine(position) {
  41. if (
  42. this.newLine != null &&
  43. !mathUtil.equalPoint(this.startInfo.position, position)
  44. ) {
  45. let point = dataService.getPoint(this.newLine.endId);
  46. point.setPosition(position);
  47. }
  48. }
  49. finish(position) {
  50. if (this.newLine != null) {
  51. if (mathUtil.equalPoint(this.startInfo.position, position)) {
  52. dataService.deleteLine(this.newLine.vectorId);
  53. } else if (
  54. listenLayer.modifyPoint &&
  55. listenLayer.modifyPoint.linkedPointId &&
  56. this.newLine.getCategory() != VectorCategory.Line.ArrowLine &&
  57. this.newLine.getCategory() != VectorCategory.Line.GuideLine
  58. ) {
  59. pointService.mergePoint(
  60. this.newLine.endId,
  61. listenLayer.modifyPoint.linkedPointId
  62. );
  63. }
  64. if (this.newLine.getCategory() == VectorCategory.Line.BaseLine) {
  65. Settings.baseLineId = this.newLine.vectorId;
  66. }
  67. }
  68. }
  69. clearVectorData() {
  70. this.newLine = null;
  71. this.startInfo = {};
  72. }
  73. clear() {
  74. this.newLine = null;
  75. this.startInfo = {};
  76. }
  77. }
  78. const addLine = new AddLine();
  79. export { addLine };