AddLine.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.SingleArrowLine &&
  57. this.newLine.getCategory() != VectorCategory.Line.DoubleArrowLine &&
  58. this.newLine.getCategory() != VectorCategory.Line.GuideLine
  59. ) {
  60. pointService.mergePoint(
  61. this.newLine.endId,
  62. listenLayer.modifyPoint.linkedPointId
  63. );
  64. }
  65. if (this.newLine.getCategory() == VectorCategory.Line.BaseLine) {
  66. Settings.baseLineId = this.newLine.vectorId;
  67. }
  68. }
  69. }
  70. buildCurveLine(position) {
  71. if (
  72. this.newLine == null &&
  73. !mathUtil.equalPoint(this.startInfo.position, position)
  74. ) {
  75. this.newLine = lineService.createCurveLine(
  76. this.startInfo.position,
  77. position
  78. );
  79. }
  80. }
  81. updateCurveLine(position) {
  82. if (
  83. this.newLine != null &&
  84. !mathUtil.equalPoint(this.startInfo.position, position)
  85. ) {
  86. let curvePoint = dataService.getCurvePoint(this.newLine.endId);
  87. curvePoint.setPosition(position);
  88. }
  89. }
  90. finishCurveLine(position) {
  91. if (this.newLine != null) {
  92. if (mathUtil.equalPoint(this.startInfo.position, position)) {
  93. dataService.deleteCurveLine(this.newLine.vectorId);
  94. }
  95. }
  96. }
  97. clearVectorData() {
  98. this.newLine = null;
  99. this.startInfo = {};
  100. }
  101. clear() {
  102. this.newLine = null;
  103. this.startInfo = {};
  104. }
  105. }
  106. const addLine = new AddLine();
  107. export { addLine };