Skip to content

Commit

Permalink
🎈 perf: Add more useful prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Nov 17, 2023
1 parent 71edcba commit 47027d2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/chili/src/commands/create/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { GeometryModel, MathUtils, Plane, Property, XYZ, command } from "chili-core";
import { RectBody } from "../../bodys";
import { SnapLengthAtPlaneData } from "../../snap";
import { SnapLengthAtPlaneData, SnapedData } from "../../snap";
import { IStep, LengthAtPlaneStep, PointStep } from "../../step";
import { CreateCommand } from "./createCommand";

Expand Down Expand Up @@ -38,6 +38,10 @@ export abstract class RectCommandBase extends CreateCommand {
preview: this.previewRect,
plane: this.stepDatas[0].view.workplane.translateTo(point),
validators: [this.handleValid],
prompt: (snaped: SnapedData) => {
let data = this.getRectData(snaped.point!);
return `${data.dx.toFixed(2)}, ${data.dy.toFixed(2)}`;
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PlaneSnap } from "../planeSnap";
import { TrackingSnap } from "../tracking";
import { SnapEventHandler } from "./snapEventHandler";
import { SnapPointData } from "./snapPointEventHandler";
import { SnapedData } from "../interfaces";

export class SnapAngleEventHandler extends SnapEventHandler {
readonly plane: Plane;
Expand All @@ -26,12 +27,13 @@ export class SnapAngleEventHandler extends SnapEventHandler {
let xvec = p1.sub(center).normalize()!;
this.plane = new Plane(center, snapPointData.plane.normal, xvec);
this.planeAngle = new PlaneAngle(this.plane);
if (snapPointData.prompt === undefined) snapPointData.prompt = this.snapedInfo;
}

override snapedInfo() {
this.planeAngle.movePoint(this._snaped?.point!);
private snapedInfo = (snaped?: SnapedData) => {
this.planeAngle.movePoint(snaped?.point!);
return `${this.planeAngle.angle.toFixed(2)} °`;
}
};

protected override inputError(text: string) {
let angle = Number.parseFloat(text);
Expand Down
8 changes: 2 additions & 6 deletions packages/chili/src/snap/snapEventHandler/snapEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ export abstract class SnapEventHandler implements IEventHandler {
this.setSnaped(view, event);
if (this._snaped !== undefined) {
this.showTempShape(this._snaped.point!, view);
this.switchSnapedTip(this.snapedInfo());
this.switchSnapedPrompt(this.data.prompt?.(this._snaped) ?? this.snaped?.info);
} else {
this.clearSnapTip();
}
view.viewer.update();
}

snapedInfo() {
return this._snaped?.info;
}

private setSnaped(view: IView, event: MouseEvent) {
if (!this.snapToFeaturePoint(view, event)) {
this._snaped = this.findSnaped(ShapeType.Edge, view, event);
Expand Down Expand Up @@ -154,7 +150,7 @@ export abstract class SnapEventHandler implements IEventHandler {
PubSub.default.pub("clearFloatTip");
}

private switchSnapedTip(msg: string | undefined) {
private switchSnapedPrompt(msg: string | undefined) {
if (msg === undefined) {
this.clearSnapTip();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { AsyncController, Config, I18nKeys, IView, Plane, Precision, XYZ } from "chili-core";

import { AxisSnap } from "../axisSnap";
import { SnapPreviewer, SnapValidator } from "../interfaces";
import { SnapPreviewer, SnapValidator, SnapedData } from "../interfaces";
import { ObjectSnap } from "../objectSnap";
import { PlaneSnap } from "../planeSnap";
import { TrackingSnap } from "../tracking";
Expand All @@ -14,13 +14,15 @@ export interface SnapLengthAtAxisData {
direction: XYZ;
validators?: SnapValidator[];
preview: SnapPreviewer;
prompt?: (snaped: SnapedData) => string;
}

export interface SnapLengthAtPlaneData {
point: XYZ;
plane: Plane;
validators?: SnapValidator[];
preview: SnapPreviewer;
prompt?: (snaped: SnapedData) => string;
}

export class SnapLengthAtAxisHandler extends SnapEventHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { AsyncController, Config, I18nKeys, IView, Plane, XYZ } from "chili-core";
import { Dimension } from "../dimension";
import { SnapPreviewer, SnapValidator } from "../interfaces";
import { SnapPreviewer, SnapValidator, SnapedData } from "../interfaces";
import { ObjectSnap } from "../objectSnap";
import { PlaneSnap, WorkplaneSnap } from "../planeSnap";
import { TrackingSnap } from "../tracking";
Expand All @@ -13,6 +13,7 @@ export interface SnapPointData {
refPoint?: XYZ;
validators?: SnapValidator[];
preview?: SnapPreviewer;
prompt?: (point: SnapedData) => string;
plane?: Plane;
featurePoints?: {
point: XYZ;
Expand Down

0 comments on commit 47027d2

Please sign in to comment.