From e84a37e9d1c9998643d06dd9a09f470d17cf85cc Mon Sep 17 00:00:00 2001 From: xiange Date: Fri, 8 Mar 2024 21:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20display=20picked=20points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chili/src/commands/create/arc.ts | 30 +++++------ packages/chili/src/commands/create/box.ts | 9 +++- packages/chili/src/commands/create/circle.ts | 8 ++- packages/chili/src/commands/create/fuse.ts | 1 + packages/chili/src/commands/create/line.ts | 11 +++- packages/chili/src/commands/create/polygon.ts | 9 ++-- packages/chili/src/commands/create/prism.ts | 1 + packages/chili/src/commands/create/rect.ts | 13 ++++- packages/chili/src/commands/modify/array.ts | 4 +- packages/chili/src/commands/modify/mirror.ts | 6 ++- packages/chili/src/commands/modify/move.ts | 6 ++- packages/chili/src/commands/modify/rotate.ts | 21 +++++--- .../chili/src/commands/multistepCommand.ts | 23 ++++++++- packages/chili/src/snap/interfaces.ts | 2 +- .../snapEventHandler/snapAngleEventHandler.ts | 5 +- .../snap/snapEventHandler/snapEventHandler.ts | 50 +++++++++---------- .../snapLengthEventHandler.ts | 9 ++-- .../snapEventHandler/snapPointEventHandler.ts | 5 +- packages/chili/src/snap/snapper.ts | 20 ++++---- packages/chili/src/step/pointStep.ts | 1 - packages/chili/src/step/step.ts | 4 +- 21 files changed, 152 insertions(+), 86 deletions(-) diff --git a/packages/chili/src/commands/create/arc.ts b/packages/chili/src/commands/create/arc.ts index eb0d4fc0..6e8d368f 100644 --- a/packages/chili/src/commands/create/arc.ts +++ b/packages/chili/src/commands/create/arc.ts @@ -1,16 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { - Colors, - GeometryModel, - Plane, - PlaneAngle, - Precision, - ShapeMeshData, - VertexMeshData, - XYZ, - command, -} from "chili-core"; +import { GeometryModel, Plane, PlaneAngle, Precision, ShapeMeshData, XYZ, command } from "chili-core"; import { ArcBody } from "../../bodys/arcBody"; import { Dimension, SnapLengthAtPlaneData } from "../../snap"; import { AngleStep, IStep, LengthAtPlaneStep, PointStep } from "../../step"; @@ -55,14 +45,14 @@ export class Arc extends CreateCommand { private getAngleData = () => { let [center, p1] = [this.stepDatas[0].point!, this.stepDatas[1].point!]; let plane = new Plane(center, this.stepDatas[0].view.workplane.normal, p1.sub(center)); - let points: ShapeMeshData[] = [ - VertexMeshData.from(center, 5, Colors.Red), - VertexMeshData.from(p1, 5, Colors.Red), - ]; + let points: ShapeMeshData[] = [this.previewPoint(center), this.previewPoint(p1)]; this._planeAngle = new PlaneAngle(plane); return { dimension: Dimension.D1D2, - preview: (point: XYZ) => { + preview: (point: XYZ | undefined) => { + if (point === undefined) { + point = p1; + } this._planeAngle!.movePoint(point); let result = [...points]; if (Math.abs(this._planeAngle!.angle) > Precision.Angle) { @@ -92,10 +82,16 @@ export class Arc extends CreateCommand { return new GeometryModel(this.document, `Arc ${Arc.count++}`, body); } - private circlePreview = (point: XYZ) => { + private circlePreview = (point: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) { + return [p1]; + } let start = this.stepDatas[0].point!; let plane = this.stepDatas[0].view.workplane; return [ + p1, + this.previewLine(this.stepDatas[0].point!, point), this.application.shapeFactory .circle(plane.normal, start, this.getDistanceAtPlane(plane, start, point)) .unwrap().mesh.edges!, diff --git a/packages/chili/src/commands/create/box.ts b/packages/chili/src/commands/create/box.ts index 0a80a5fd..ab27cfd7 100644 --- a/packages/chili/src/commands/create/box.ts +++ b/packages/chili/src/commands/create/box.ts @@ -28,9 +28,16 @@ export class Box extends RectCommandBase { }; }; - private previewBox = (end: XYZ) => { + private previewBox = (end: XYZ | undefined) => { + if (!end) { + return this.previewRect(this.stepDatas[1].point); + } + let p1 = this.previewPoint(this.stepDatas[0].point!); + let p2 = this.previewPoint(this.stepDatas[1].point!); let data = this.getRectData(end); return [ + p1, + p2, this.application.shapeFactory .box(data.plane, data.dx, data.dy, this.getHeight(data.plane, end)) .unwrap().mesh.edges!, diff --git a/packages/chili/src/commands/create/circle.ts b/packages/chili/src/commands/create/circle.ts index 7d4fd1c9..58a3e3f4 100644 --- a/packages/chili/src/commands/create/circle.ts +++ b/packages/chili/src/commands/create/circle.ts @@ -43,10 +43,16 @@ export class Circle extends CreateFaceableCommand { return new GeometryModel(this.document, `Circle ${Circle.count++}`, body); } - private circlePreview = (point: XYZ) => { + private circlePreview = (point: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) { + return [p1]; + } let start = this.stepDatas[0].point!; let plane = this.stepDatas[0].view.workplane; return [ + p1, + this.previewLine(this.stepDatas[0].point!, point), this.application.shapeFactory .circle(plane.normal, start, this.getDistanceAtPlane(plane, start, point)) .unwrap().mesh.edges!, diff --git a/packages/chili/src/commands/create/fuse.ts b/packages/chili/src/commands/create/fuse.ts index 3884d054..bb7eda14 100644 --- a/packages/chili/src/commands/create/fuse.ts +++ b/packages/chili/src/commands/create/fuse.ts @@ -37,6 +37,7 @@ export class Fuse extends CreateCommand { point, direction: normal, preview: (p) => { + if (!p) return []; let dist = p.sub(point).dot(normal); if (Math.abs(dist) < Precision.Float) return []; let vec = normal.multiply(dist); diff --git a/packages/chili/src/commands/create/line.ts b/packages/chili/src/commands/create/line.ts index 51d07213..0abf75b5 100644 --- a/packages/chili/src/commands/create/line.ts +++ b/packages/chili/src/commands/create/line.ts @@ -57,7 +57,14 @@ export class Line extends CreateCommand { }; }; - private linePreview = (point: XYZ) => { - return [this.application.shapeFactory.line(this.stepDatas[0].point!, point).unwrap().mesh.edges!]; + private linePreview = (point: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) { + return [p1]; + } + return [ + p1, + this.application.shapeFactory.line(this.stepDatas[0].point!, point).unwrap().mesh.edges!, + ]; }; } diff --git a/packages/chili/src/commands/create/polygon.ts b/packages/chili/src/commands/create/polygon.ts index 5c838331..3c5b6c88 100644 --- a/packages/chili/src/commands/create/polygon.ts +++ b/packages/chili/src/commands/create/polygon.ts @@ -83,11 +83,14 @@ export class Polygon extends CreateFaceableCommand { }; }; - private preview = (point: XYZ): ShapeMeshData[] => { + private preview = (point: XYZ | undefined): ShapeMeshData[] => { + let ps = this.stepDatas.map((data) => this.previewPoint(data.point!)); let edges = new EdgeMeshDataBuilder(); this.stepDatas.forEach((data) => edges.addPosition(data.point!.x, data.point!.y, data.point!.z)); - edges.addPosition(point.x, point.y, point.z); - return [edges.build()]; + if (point) { + edges.addPosition(point.x, point.y, point.z); + } + return [...ps, edges.build()]; }; private validator = (point: XYZ): boolean => { diff --git a/packages/chili/src/commands/create/prism.ts b/packages/chili/src/commands/create/prism.ts index f3ec85f5..f5a4b19c 100644 --- a/packages/chili/src/commands/create/prism.ts +++ b/packages/chili/src/commands/create/prism.ts @@ -37,6 +37,7 @@ export class Prism extends CreateCommand { point, direction: normal, preview: (p) => { + if (!p) return []; let dist = p.sub(point).dot(normal); if (Math.abs(dist) < Precision.Float) return []; let vec = normal.multiply(dist); diff --git a/packages/chili/src/commands/create/rect.ts b/packages/chili/src/commands/create/rect.ts index 15f0f355..86d83416 100644 --- a/packages/chili/src/commands/create/rect.ts +++ b/packages/chili/src/commands/create/rect.ts @@ -50,9 +50,18 @@ export abstract class RectCommandBase extends CreateCommand { return !MathUtils.anyEqualZero(data.dx, data.dy); }; - private previewRect = (end: XYZ) => { + protected previewRect = (end: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (end === undefined) { + return [p1]; + } let data = this.getRectData(end); - return [this.application.shapeFactory.rect(data.plane, data.dx, data.dy).unwrap().mesh.edges!]; + let p2 = this.previewPoint(end); + return [ + p1, + p2, + this.application.shapeFactory.rect(data.plane, data.dx, data.dy).unwrap().mesh.edges!, + ]; }; protected getRectData(point: XYZ): RectData { diff --git a/packages/chili/src/commands/modify/array.ts b/packages/chili/src/commands/modify/array.ts index bc6b7d22..42aee815 100644 --- a/packages/chili/src/commands/modify/array.ts +++ b/packages/chili/src/commands/modify/array.ts @@ -38,7 +38,9 @@ export class Array extends MultistepCommand { }; }; - private movePreview = (point: XYZ) => { + private movePreview = (point: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) return [p1]; let start = this.stepDatas[0].point!; let positions = [...this.positions!]; let { x, y, z } = point.sub(start); diff --git a/packages/chili/src/commands/modify/mirror.ts b/packages/chili/src/commands/modify/mirror.ts index f33dacb7..c37d2b6b 100644 --- a/packages/chili/src/commands/modify/mirror.ts +++ b/packages/chili/src/commands/modify/mirror.ts @@ -40,10 +40,12 @@ export class Mirror extends TransformedCommand { }; }; - private mirrorPreview = (point: XYZ): ShapeMeshData[] => { + private mirrorPreview = (point: XYZ | undefined): ShapeMeshData[] => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) return [p1]; let shape = this.transformPreview(point); let offset = point.sub(this.stepDatas[0].point!).normalize()!.multiply(1e6); let line = this.getTempLineData(this.stepDatas[0].point!.sub(offset), point.add(offset)); - return [shape, line]; + return [p1, shape, line]; }; } diff --git a/packages/chili/src/commands/modify/move.ts b/packages/chili/src/commands/modify/move.ts index d5872234..f77aaf35 100644 --- a/packages/chili/src/commands/modify/move.ts +++ b/packages/chili/src/commands/modify/move.ts @@ -25,10 +25,12 @@ export class Move extends TransformedCommand { }; }; - private movePreview = (point: XYZ) => { + private movePreview = (point: XYZ | undefined) => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) return [p1]; let models = this.transformPreview(point); let line = this.getTempLineData(this.stepDatas[0].point!, point); - return [models, line]; + return [p1, models, line]; }; protected override transfrom(point: XYZ): Matrix4 { diff --git a/packages/chili/src/commands/modify/rotate.ts b/packages/chili/src/commands/modify/rotate.ts index 5ce25279..9244f84b 100644 --- a/packages/chili/src/commands/modify/rotate.ts +++ b/packages/chili/src/commands/modify/rotate.ts @@ -59,11 +59,16 @@ export class Rotate extends TransformedCommand { }; }; - private rotatePreview = (point: XYZ): ShapeMeshData[] => { - let shape = this.transformPreview(point); + private rotatePreview = (point: XYZ | undefined): ShapeMeshData[] => { + let p1 = this.previewPoint(this.stepDatas[0].point!); let l1 = this.getRayData(this.stepDatas[1].point!); - let l2 = this.getRayData(point); - return [shape, l1, l2]; + let result = [p1, l1, this.previewPoint(this.stepDatas[1].point!)]; + if (point) { + let shape = this.transformPreview(point); + let l2 = this.getRayData(point); + result.push(l2, shape); + } + return result; }; private getRayData(end: XYZ) { @@ -72,7 +77,11 @@ export class Rotate extends TransformedCommand { return this.getTempLineData(start, e); } - private linePreview = (point: XYZ): ShapeMeshData[] => { - return [this.getTempLineData(this.stepDatas[0].point!, point)]; + private linePreview = (point: XYZ | undefined): ShapeMeshData[] => { + let p1 = this.previewPoint(this.stepDatas[0].point!); + if (!point) { + return [p1]; + } + return [p1, this.getTempLineData(this.stepDatas[0].point!, point)]; }; } diff --git a/packages/chili/src/commands/multistepCommand.ts b/packages/chili/src/commands/multistepCommand.ts index f5fd60b9..49dd097c 100644 --- a/packages/chili/src/commands/multistepCommand.ts +++ b/packages/chili/src/commands/multistepCommand.ts @@ -1,6 +1,15 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { AsyncController, CancelableCommand, Property } from "chili-core"; +import { + AsyncController, + CancelableCommand, + Config, + EdgeMeshData, + LineType, + Property, + VertexMeshData, + XYZ, +} from "chili-core"; import { SnapedData } from "../snap"; import { IStep } from "../step"; @@ -58,6 +67,18 @@ export abstract class MultistepCommand extends CancelableCommand { this.stepDatas.length = 0; } + protected previewPoint(point: XYZ) { + return VertexMeshData.from( + point, + Config.instance.visual.editVertexSize, + Config.instance.visual.editVertexColor, + ); + } + + protected previewLine(start: XYZ, end: XYZ) { + return EdgeMeshData.from(start, end, Config.instance.visual.temporaryEdgeColor, LineType.Dash); + } + protected abstract getSteps(): IStep[]; protected abstract executeMainTask(): void; diff --git a/packages/chili/src/snap/interfaces.ts b/packages/chili/src/snap/interfaces.ts index 8de006dc..9090439b 100644 --- a/packages/chili/src/snap/interfaces.ts +++ b/packages/chili/src/snap/interfaces.ts @@ -4,7 +4,7 @@ import { IDocument, IModel, IView, ShapeMeshData, VisualShapeData, XYZ } from "c export type SnapValidator = (point: XYZ) => boolean; -export type SnapPreviewer = (point: XYZ) => ShapeMeshData[]; +export type SnapPreviewer = (point: XYZ | undefined) => ShapeMeshData[]; export interface SnapedData { view: IView; diff --git a/packages/chili/src/snap/snapEventHandler/snapAngleEventHandler.ts b/packages/chili/src/snap/snapEventHandler/snapAngleEventHandler.ts index 8570be96..7db09d27 100644 --- a/packages/chili/src/snap/snapEventHandler/snapAngleEventHandler.ts +++ b/packages/chili/src/snap/snapEventHandler/snapAngleEventHandler.ts @@ -1,6 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { AsyncController, Config, IView, Plane, PlaneAngle, XYZ } from "chili-core"; +import { AsyncController, Config, IDocument, IView, Plane, PlaneAngle, XYZ } from "chili-core"; import { SnapedData } from "../interfaces"; import { ObjectSnap } from "../objectSnap"; import { PlaneSnap } from "../planeSnap"; @@ -13,6 +13,7 @@ export class SnapAngleEventHandler extends SnapEventHandler { readonly planeAngle: PlaneAngle; constructor( + document: IDocument, controller: AsyncController, readonly center: () => XYZ, p1: XYZ, @@ -23,7 +24,7 @@ export class SnapAngleEventHandler extends SnapEventHandler { let workplaneSnap = new PlaneSnap(snapPointData.plane, center); let trackingSnap = new TrackingSnap(center, false); let snaps = [objectSnap, trackingSnap, workplaneSnap]; - super(controller, snaps, snapPointData); + super(document, controller, snaps, snapPointData); let xvec = p1.sub(center()).normalize()!; this.plane = new Plane(center(), snapPointData.plane().normal, xvec); this.planeAngle = new PlaneAngle(this.plane); diff --git a/packages/chili/src/snap/snapEventHandler/snapEventHandler.ts b/packages/chili/src/snap/snapEventHandler/snapEventHandler.ts index 383dcbb7..f383d667 100644 --- a/packages/chili/src/snap/snapEventHandler/snapEventHandler.ts +++ b/packages/chili/src/snap/snapEventHandler/snapEventHandler.ts @@ -4,6 +4,7 @@ import { AsyncController, Config, I18nKeys, + IDocument, IEventHandler, IShapeFilter, IView, @@ -19,12 +20,13 @@ import { ISnapper, MouseAndDetected, SnapValidator, SnapedData } from "../interf import { SnapPointData } from "./snapPointEventHandler"; export abstract class SnapEventHandler implements IEventHandler { - private _tempPoint?: [IView, number]; - private _tempShapes?: [IView, number[]]; + private _tempPoint?: number; + private _tempShapes?: number[]; protected _snaped?: SnapedData; private validators: SnapValidator[] = []; constructor( + readonly document: IDocument, readonly controller: AsyncController, readonly snaps: ISnapper[], readonly data: SnapPointData, @@ -33,6 +35,7 @@ export abstract class SnapEventHandler implements IEventHandler { if (data.validators) { this.validators.push(...data.validators); } + this.showTempShape(undefined); controller.onCancelled((s) => { this.cancel(); }); @@ -71,14 +74,14 @@ export abstract class SnapEventHandler implements IEventHandler { } pointerMove(view: IView, event: MouseEvent): void { - this.removeTempObject(view); + this.removeTempObject(); this.setSnaped(view, event); if (this._snaped !== undefined) { - this.showTempShape(this._snaped.point!, view); this.switchSnapedPrompt(this.data.prompt?.(this._snaped) ?? this.snaped?.info); } else { this.clearSnapTip(); } + this.showTempShape(this._snaped?.point); view.viewer.update(); } @@ -158,39 +161,34 @@ export abstract class SnapEventHandler implements IEventHandler { PubSub.default.pub("showFloatTip", MessageType.info, msg); } - private removeTempObject(view: IView) { + private removeTempObject() { this.removeTempShapes(); this.snaps.forEach((x) => x.removeDynamicObject()); } - private showTempShape(point: XYZ, view: IView) { - let data = VertexMeshData.from( - point, - Config.instance.visual.temporaryVertexSize, - Config.instance.visual.temporaryVertexColor, - ); - this._tempPoint = [view, view.viewer.visual.context.displayShapeMesh(data)]; - let shapes = this.data.preview?.(point); - this._tempShapes = shapes - ? [ - view, - shapes.map((shape) => { - return view.viewer.visual.context.displayShapeMesh(shape); - }), - ] - : undefined; + private showTempShape(point: XYZ | undefined) { + if (point) { + let data = VertexMeshData.from( + point, + Config.instance.visual.temporaryVertexSize, + Config.instance.visual.temporaryVertexColor, + ); + this._tempPoint = this.document.visual.context.displayShapeMesh(data); + } + this._tempShapes = this.data.preview?.(point)?.map((shape) => { + return this.document.visual.context.displayShapeMesh(shape); + }); } private removeTempShapes() { - let view = this._tempPoint?.[0] ?? this._tempShapes?.[0]; if (this._tempPoint) { - this._tempPoint[0].viewer.visual.context.removeShapeMesh(this._tempPoint[1]); + this.document.visual.context.removeShapeMesh(this._tempPoint); this._tempPoint = undefined; } - this._tempShapes?.[1].forEach((x) => { - this._tempShapes?.[0].viewer.visual.context.removeShapeMesh(x); + this._tempShapes?.forEach((x) => { + this.document.visual.context.removeShapeMesh(x); }); - view?.viewer.update(); + this.document.visual.viewer.update(); this._tempShapes = undefined; } diff --git a/packages/chili/src/snap/snapEventHandler/snapLengthEventHandler.ts b/packages/chili/src/snap/snapEventHandler/snapLengthEventHandler.ts index cb455d95..19c9a250 100644 --- a/packages/chili/src/snap/snapEventHandler/snapLengthEventHandler.ts +++ b/packages/chili/src/snap/snapEventHandler/snapLengthEventHandler.ts @@ -1,7 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { AsyncController, Config, I18nKeys, IView, Plane, Precision, XYZ } from "chili-core"; - +import { AsyncController, Config, I18nKeys, IDocument, IView, Plane, Precision, XYZ } from "chili-core"; import { AxisSnap } from "../axisSnap"; import { SnapPreviewer, SnapValidator, SnapedData } from "../interfaces"; import { ObjectSnap } from "../objectSnap"; @@ -27,12 +26,13 @@ export interface SnapLengthAtPlaneData { export class SnapLengthAtAxisHandler extends SnapEventHandler { constructor( + document: IDocument, controller: AsyncController, readonly lengthData: SnapLengthAtAxisData, ) { let objectSnap = new ObjectSnap(Config.instance.snapType); let axisSnap = new AxisSnap(lengthData.point, lengthData.direction); - super(controller, [objectSnap, axisSnap], lengthData); + super(document, controller, [objectSnap, axisSnap], lengthData); } protected getPointFromInput(view: IView, text: string): XYZ { @@ -56,13 +56,14 @@ export class SnapLengthAtAxisHandler extends SnapEventHandler { export class SnapLengthAtPlaneHandler extends SnapEventHandler { constructor( + document: IDocument, controller: AsyncController, readonly lengthData: SnapLengthAtPlaneData, ) { let objectSnap = new ObjectSnap(Config.instance.snapType); let trackingSnap = new TrackingSnap(lengthData.point, false); let planeSnap = new PlaneSnap(lengthData.plane, lengthData.point); - super(controller, [objectSnap, trackingSnap, planeSnap], lengthData); + super(document, controller, [objectSnap, trackingSnap, planeSnap], lengthData); } protected getPointFromInput(view: IView, text: string): XYZ { diff --git a/packages/chili/src/snap/snapEventHandler/snapPointEventHandler.ts b/packages/chili/src/snap/snapEventHandler/snapPointEventHandler.ts index 76845b8a..f03d8a36 100644 --- a/packages/chili/src/snap/snapEventHandler/snapPointEventHandler.ts +++ b/packages/chili/src/snap/snapEventHandler/snapPointEventHandler.ts @@ -1,6 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. -import { AsyncController, Config, I18nKeys, IView, Plane, XYZ } from "chili-core"; +import { AsyncController, Config, I18nKeys, IDocument, IView, Plane, XYZ } from "chili-core"; import { Dimension } from "../dimension"; import { SnapPreviewer, SnapValidator, SnapedData } from "../interfaces"; import { ObjectSnap } from "../objectSnap"; @@ -24,6 +24,7 @@ export interface SnapPointData { export class SnapPointEventHandler extends SnapEventHandler { constructor( + document: IDocument, controller: AsyncController, protected pointData: SnapPointData, ) { @@ -33,7 +34,7 @@ export class SnapPointEventHandler extends SnapEventHandler { : new WorkplaneSnap(pointData.refPoint); let trackingSnap = new TrackingSnap(pointData.refPoint, true); let snaps = [objectSnap, trackingSnap, workplaneSnap]; - super(controller, snaps, pointData); + super(document, controller, snaps, pointData); } protected getPointFromInput(view: IView, text: string): XYZ { diff --git a/packages/chili/src/snap/snapper.ts b/packages/chili/src/snap/snapper.ts index 7fc4cf53..a3674875 100644 --- a/packages/chili/src/snap/snapper.ts +++ b/packages/chili/src/snap/snapper.ts @@ -15,14 +15,14 @@ import { } from "./snapEventHandler"; export abstract class Snapper { - protected abstract getEventHandler(controller: AsyncController): SnapEventHandler; + protected abstract getEventHandler(document: IDocument, controller: AsyncController): SnapEventHandler; async snap( document: IDocument, tip: I18nKeys, controller: AsyncController, ): Promise { - let executorHandler = this.getEventHandler(controller); + let executorHandler = this.getEventHandler(document, controller); await document.selection.pickAsync(executorHandler, tip, controller, false, CursorType.Drawing); return controller.result?.status === "success" ? executorHandler.snaped : undefined; } @@ -37,8 +37,8 @@ export class AngleSnapper extends Snapper { super(); } - protected getEventHandler(controller: AsyncController): SnapEventHandler { - return new SnapAngleEventHandler(controller, this.center, this.p1, this.snapPointData); + protected getEventHandler(document: IDocument, controller: AsyncController): SnapEventHandler { + return new SnapAngleEventHandler(document, controller, this.center, this.p1, this.snapPointData); } } @@ -47,8 +47,8 @@ export class PointSnapper extends Snapper { super(); } - protected getEventHandler(controller: AsyncController): SnapEventHandler { - return new SnapPointEventHandler(controller, this.data); + protected getEventHandler(document: IDocument, controller: AsyncController): SnapEventHandler { + return new SnapPointEventHandler(document, controller, this.data); } } @@ -57,8 +57,8 @@ export class LengthAtAxisSnapper extends Snapper { super(); } - protected getEventHandler(controller: AsyncController): SnapEventHandler { - return new SnapLengthAtAxisHandler(controller, this.data); + protected getEventHandler(document: IDocument, controller: AsyncController): SnapEventHandler { + return new SnapLengthAtAxisHandler(document, controller, this.data); } } @@ -67,7 +67,7 @@ export class LengthAtPlaneSnapper extends Snapper { super(); } - protected getEventHandler(controller: AsyncController): SnapEventHandler { - return new SnapLengthAtPlaneHandler(controller, this.data); + protected getEventHandler(document: IDocument, controller: AsyncController): SnapEventHandler { + return new SnapLengthAtPlaneHandler(document, controller, this.data); } } diff --git a/packages/chili/src/step/pointStep.ts b/packages/chili/src/step/pointStep.ts index ade9836d..8c9fd968 100644 --- a/packages/chili/src/step/pointStep.ts +++ b/packages/chili/src/step/pointStep.ts @@ -1,7 +1,6 @@ // Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. import { I18nKeys, Precision, XYZ } from "chili-core"; - import { Dimension, PointSnapper, SnapPointData, Snapper } from "../snap"; import { StepBase } from "./step"; diff --git a/packages/chili/src/step/step.ts b/packages/chili/src/step/step.ts index 4858b9ec..64739b61 100644 --- a/packages/chili/src/step/step.ts +++ b/packages/chili/src/step/step.ts @@ -15,11 +15,11 @@ export interface ValidatorData { export abstract class StepBase implements IStep { constructor( readonly tip: I18nKeys, - readonly handleData: () => D, + readonly handleValidator: () => D, ) {} async execute(document: IDocument, controller: AsyncController): Promise { - let data = this.handleData(); + let data = this.handleValidator(); if (data.validators === undefined) data.validators = []; data.validators.push((point) => this.validator(data, point)); let snapper = this.snapper(data);