123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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 };
|