import { dataService } from "../Service/DataService"; import { lineService } from "../Service/LineService"; import { listenLayer } from "../ListenLayer"; import VectorCategory from "../enum/VectorCategory"; import Point from "../Geometry/Point.js"; import { mathUtil } from "../Util/MathUtil"; import Settings from "../Settings"; import { pointService } from "../Service/PointService"; export default class AddLine { constructor() { this.newLine = null; this.startInfo = {}; } setPointInfo(pointInfo) { this.startInfo = { position: { x: pointInfo.x, y: pointInfo.y, }, linkedPointId: pointInfo.linkedPointId, lineId: pointInfo.lineId, }; } setNewLinePoint(position) { if (listenLayer.modifyPoint) { this.setPointInfo(listenLayer.modifyPoint); } else { this.setPointInfo(position); } return true; } buildLine(position) { if ( this.newLine == null && !mathUtil.equalPoint(this.startInfo.position, position) ) { this.newLine = lineService.create(this.startInfo.position, position); } } updateLine(position) { if ( this.newLine != null && !mathUtil.equalPoint(this.startInfo.position, position) ) { let point = dataService.getPoint(this.newLine.endId); point.setPosition(position); } } finish(position) { if (this.newLine != null) { if (mathUtil.equalPoint(this.startInfo.position, position)) { dataService.deleteLine(this.newLine.vectorId); } else if ( listenLayer.modifyPoint && listenLayer.modifyPoint.linkedPointId && this.newLine.getCategory() != VectorCategory.Line.SingleArrowLine && this.newLine.getCategory() != VectorCategory.Line.DoubleArrowLine && this.newLine.getCategory() != VectorCategory.Line.GuideLine ) { pointService.mergePoint( this.newLine.endId, listenLayer.modifyPoint.linkedPointId ); } if (this.newLine.getCategory() == VectorCategory.Line.BaseLine) { Settings.baseLineId = this.newLine.vectorId; } } } buildCurveLine(position) { if ( this.newLine == null && !mathUtil.equalPoint(this.startInfo.position, position) ) { this.newLine = lineService.createCurveLine( this.startInfo.position, position ); } } updateCurveLine(position) { if ( this.newLine != null && !mathUtil.equalPoint(this.startInfo.position, position) ) { let curvePoint = dataService.getCurvePoint(this.newLine.endId); curvePoint.setPosition(position); } } finishCurveLine(position) { if (this.newLine != null) { if (mathUtil.equalPoint(this.startInfo.position, position)) { dataService.deleteCurveLine(this.newLine.vectorId); } } } clearVectorData() { this.newLine = null; this.startInfo = {}; } clear() { this.newLine = null; this.startInfo = {}; } } const addLine = new AddLine(); export { addLine };