Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/layerling-mcp-skill/SKILL.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .claude/skills/layerling-mcp-skill/SKILL.md

Large diffs are not rendered by default.

38 changes: 37 additions & 1 deletion apps/web/src/components/LayerlingEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { hingePartScope, hingeWorldParts } from "@/lib/hingeParts";
import { copyViaSelectionField, decodeClipboardPayload, encodeClipboardPayload, LOCAL_CLIPBOARD_LIMIT, newestClipboard, type ClipboardPayload } from "@/lib/clipboardPayload";
import { bentTubeNaturalDimensions, normalizedBentTubeFields } from "@/lib/bentTubeGeometry";
import { GRIDFINITY_SWALLOWTAIL_KEY_THICKNESS, gridfinityHasLabelText, gridfinityOutlineFit, gridfinityOutlineFromLoops, gridfinityOutlineToPlate, gridfinityPlan, gridfinityPlateFlat, gridfinityPlateToWorld, gridfinitySceneWithKeys, gridfinitySwallowtailKeyCount, gridfinitySwallowtailKeyProfile, gridfinitySwallowtailKeys } from "@/lib/gridfinityGeometry";
import { boxGeneratorFieldsOf, boxGeneratorInsideOutline, boxGeneratorMatchingLidPatch, normalizeBoxGenerator } from "@/lib/boxGeneratorGeometry";
import { boxGeneratorFieldsOf, boxGeneratorInsideOutline, boxGeneratorLatchClip, boxGeneratorMatchingLidPatch, boxGeneratorPlan, normalizeBoxGenerator } from "@/lib/boxGeneratorGeometry";
import { DEFAULT_THREAD_PROFILE, defaultThreadHeadHeight, normalizeThreadHeadHeight, threadCollarFields, threadCollarSettings, threadDriveFields, threadDriveSettings, threadNaturalFootprint, threadSettings } from "@/lib/threadGeometry";
import { textOffsetAsFill } from "@/lib/textFillChoice";
import { curvedTextPatch, MAX_TEXT_LETTER_WIDTH, MAX_TEXT_SPACING, MIN_TEXT_LETTER_WIDTH, MIN_TEXT_SPACING } from "@/lib/textGeometry";
Expand Down Expand Up @@ -12549,6 +12549,41 @@ export function LayerlingEditor({
commitShapes([...shapesRef.current, lid], [lid.id], t("status.boxLidMade", { name }));
}, [commitShapes]);

/**
* The clips for a box generator part's latches, laid out in a row in front of it: one copy with the part set to the clip
* for each latch the part has, everything else the part's own, so they fit its pins and the lid's.
*/
const makeBoxLatches = useCallback((boxId: string) => {
const box = shapesRef.current.find((shape) => shape.id === boxId);
if (!box || box.kind !== "boxGenerator") return;
if (box.locked) {
setNotice(t("status.objectLocked"), true);
return;
}
if (historyViewStateRef.current) {
setNotice(t("status.historyViewBlocksEdits"), true);
return;
}
const size = { width: shapeWidth(box), depth: shapeDepth(box), height: box.height };
const fields = boxGeneratorFieldsOf(box);
const count = boxGeneratorPlan(size, fields).latches?.spots.length ?? 0;
if (count === 0) {
setNotice(t("status.boxLatchesNone"), true);
return;
}
const clip = boxGeneratorLatchClip(fields).size;
// In a row in front of the part as it stands, 4 mm apart, upright on its level as they print.
const bounds = boundsForShapes([box]);
const clips = Array.from({ length: count }, (_, index) => {
const name = `${displayShapeName(box)} \u2013 ${t("boxGenerator.partLatch")} ${index + 1}`;
const copy = cloneWorkplaneShapeTreeWithFreshIds(box, "copy");
const x = bounds.minX + clip.width / 2 + index * (clip.width + 4);
const z = bounds.maxZ + 4 + clip.depth / 2;
return canonicalizeShape({ ...copy, boxPart: "latch", ...clip, size: resizedShapeSize(clip.width, clip.depth), name, x, z, elevation: bounds.minY, rotation: 0, rotationX: 0, rotationZ: 0 });
});
commitShapes([...shapesRef.current, ...clips], clips.map((part) => part.id), t("status.boxLatchesMade", { count: String(count) }));
}, [commitShapes]);

const makeSwallowtailKeys = useCallback(async (plateId: string) => {
const fail = (message: string) => {
setNotice(message, true);
Expand Down Expand Up @@ -19329,6 +19364,7 @@ export function LayerlingEditor({
onSurfaceRegionLasso={surfaceRegionLasso}
onVaseAccessories={selectedShapes.length === 1 && selectedShape?.kind === "vase" && !bodyLocked(selectedShape) ? () => layOutVaseAccessories(selectedShape.id) : undefined}
onMakeBoxLid={selectedShapes.length === 1 && selectedShape?.kind === "boxGenerator" && !historyViewState ? () => makeBoxLid(selectedShape.id) : undefined}
onMakeBoxLatches={selectedShapes.length === 1 && selectedShape?.kind === "boxGenerator" && !historyViewState ? () => makeBoxLatches(selectedShape.id) : undefined}
onGridfinityKeys={selectedShapes.length === 1 && selectedShape?.kind === "gridfinity" && selectedShape.gridfinitySwallowtail === true && !historyViewState ? () => void makeSwallowtailKeys(selectedShape.id) : undefined}
onLayerText={selectedShapes.length === 1 && offersTextLayers(selectedShape) ? layerSelectedText : undefined}
onTextTags={selectedShapes.length === 1 && offersTextLayers(selectedShape) ? makeTextTags : undefined}
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/WorkplaneViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ type WorkplaneViewportProps = {
/** Lays the selected Swallowtail baseplate's keys out in front of it (#1061). */
onGridfinityKeys?: () => void;
onMakeBoxLid?: () => void;
onMakeBoxLatches?: () => void;
onLayerText?: (patch: TextLayerPatch) => void;
onTextTags?: (names: string[], gap: number) => void;
/** Several lines of text under one another, one text each (#1207). */
Expand Down Expand Up @@ -1657,6 +1658,7 @@ export function WorkplaneViewport({
onVaseAccessories,
onGridfinityKeys,
onMakeBoxLid,
onMakeBoxLatches,
onLayerText,
onTextTags,
onTextBlock,
Expand Down Expand Up @@ -9491,6 +9493,7 @@ export function WorkplaneViewport({
onVaseAccessories={onVaseAccessories}
onGridfinityKeys={onGridfinityKeys}
onMakeBoxLid={onMakeBoxLid}
onMakeBoxLatches={onMakeBoxLatches}
onLayerText={onLayerText}
onTextTags={onTextTags}
onTextBlock={onTextBlock}
Expand Down
98 changes: 87 additions & 11 deletions apps/web/src/components/workplane/ShapeInspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,18 @@ import { DEFAULT_DRILL_POINT_ANGLE, DRILL_POINT_ANGLES, MAX_DRILL_POINT_ANGLE, M
import { MAX_TEARDROP_TIP_ANGLE, MIN_TEARDROP_TIP_ANGLE, normalizeTeardropTipAngle, teardropHeightForTipAngle, teardropTipAngle } from "@/lib/teardropGeometry";
import { MAX_PORT_CLEARANCE, maxPortCorner, normalizePortClearance, normalizePortCorner, PORT_PRESET_ORDER, PORT_PRESETS, portPresetFor, portPresetSize, type PortPreset } from "@/lib/portGeometry";
import {
DEFAULT_BOX_GENERATOR_DEPTH,
DEFAULT_BOX_GENERATOR_HEIGHT,
DEFAULT_BOX_GENERATOR_WIDTH,
MAX_BOX_GENERATOR_COMPARTMENTS,
MAX_BOX_GENERATOR_FIT,
MAX_BOX_GENERATOR_LATCHES,
MAX_BOX_GENERATOR_LATCH_GRIP,
MAX_BOX_GENERATOR_LATCH_WIDTH,
MIN_BOX_GENERATOR_LATCH_GRIP,
MIN_BOX_GENERATOR_LATCH_WIDTH,
boxGeneratorLatchHeight,
boxGeneratorMatchingLidPatch,
MAX_BOX_GENERATOR_STACK_HEIGHT,
MIN_BOX_GENERATOR_STACK_HEIGHT,
MAX_BOX_GENERATOR_SIDES,
Expand All @@ -224,6 +234,7 @@ import {
boxGeneratorMatchingLidSize,
normalizeBoxGenerator,
normalizeBoxGeneratorLidStyle,
normalizeBoxGeneratorLatchSides,
normalizeBoxGeneratorShape,
} from "@/lib/boxGeneratorGeometry";
import { MAX_DOVETAIL_CLEARANCE, maxDovetailNeckWidth, normalizeDovetailClearance, normalizeDovetailNeckWidth } from "@/lib/dovetailGeometry";
Expand Down Expand Up @@ -2653,16 +2664,30 @@ function getShapePropertiesWithAppLimits(shape: WorkplaneShape, onUpdate: ShapeI
: platePlan.plate
? t("boxGenerator.plateHint", { cells: String(platePlan.plate.cells.length), floor: plainNumber(platePlan.floorTop), box: t("prop.boxGridfinity") })
: t(platePlan.issues.some((issue) => issue.code === "plateTooLow") ? "boxGenerator.plateTooLow" : "boxGenerator.plateNoCell");
const properties: ShapePropertyConfig[] = [
{
type: "select",
id: "boxPart",
label: t("prop.boxPart"),
value: box.boxPart,
options: [{ value: "box", label: t("boxGenerator.partBox") }, { value: "lid", label: t("boxGenerator.partLid") }],
hint: t(box.boxPart === "box" ? "boxGenerator.partBoxHint" : "boxGenerator.partLidHint"),
onChange: (value) => onUpdate({ boxPart: value === "lid" ? "lid" : "box" }),
const partSelect: ShapePropertyConfig = {
type: "select",
id: "boxPart",
label: t("prop.boxPart"),
value: box.boxPart,
options: [{ value: "box", label: t("boxGenerator.partBox") }, { value: "lid", label: t("boxGenerator.partLid") }, { value: "latch", label: t("boxGenerator.partLatch") }],
hint: t(box.boxPart === "box" ? "boxGenerator.partBoxHint" : box.boxPart === "lid" ? "boxGenerator.partLidHint" : "boxGenerator.partLatchHint"),
// The clip takes its size from its latch settings; a box or lid made from a clip starts at the generator's own size.
onChange: (value) => {
const part = value === "lid" || value === "latch" ? value : "box";
if (part === box.boxPart) return;
if (box.boxPart === "latch") {
const height = part === "lid" ? boxGeneratorMatchingLidPatch({ width: DEFAULT_BOX_GENERATOR_WIDTH, depth: DEFAULT_BOX_GENERATOR_DEPTH, height: DEFAULT_BOX_GENERATOR_HEIGHT }, shape).height : DEFAULT_BOX_GENERATOR_HEIGHT;
onUpdate({ boxPart: part, width: DEFAULT_BOX_GENERATOR_WIDTH, depth: DEFAULT_BOX_GENERATOR_DEPTH, height, size: resizedShapeSize(DEFAULT_BOX_GENERATOR_WIDTH, DEFAULT_BOX_GENERATOR_DEPTH) });
}
else onUpdate({ boxPart: part });
},
};
const latchWidth: ShapePropertyConfig = { id: "boxLatchWidth", label: t("prop.boxLatchWidth"), value: box.boxLatchWidth, min: MIN_BOX_GENERATOR_LATCH_WIDTH, max: MAX_BOX_GENERATOR_LATCH_WIDTH, step: 0.5, onChange: (value) => onUpdate({ boxLatchWidth: value }) };
const latchGrip: ShapePropertyConfig = { id: "boxLatchGrip", label: t("prop.boxLatchGrip"), value: box.boxLatchGrip, min: MIN_BOX_GENERATOR_LATCH_GRIP, max: MAX_BOX_GENERATOR_LATCH_GRIP, step: 0.05, hint: t("boxGenerator.latchGripHint"), onChange: (value) => onUpdate({ boxLatchGrip: value }) };
// The clip: its size comes from the latch settings alone, so only those are offered.
if (box.boxPart === "latch") return [partSelect, latchWidth, latchGrip];
const properties: ShapePropertyConfig[] = [
partSelect,
{
type: "select",
id: "boxShape",
Expand Down Expand Up @@ -2763,7 +2788,38 @@ function getShapePropertiesWithAppLimits(shape: WorkplaneShape, onUpdate: ShapeI
hint: t(box.boxLidStyle === "overlap" ? "boxGenerator.lidOverlapHint" : box.boxLidStyle === "plug" ? "boxGenerator.lidPlugHint" : "boxGenerator.lidRestOnHint"),
onChange: (value) => onUpdate({ boxLidStyle: normalizeBoxGeneratorLidStyle(value) }),
});
if (box.boxPart === "lid" && (box.boxLidStyle === "overlap" || box.boxLidStyle === "plug" || (box.boxLidStyle === "restOn" && box.boxStackable))) {
// Latches: a pin with two cheeks on box and lid, and a clip that snaps over both (part Clip).
const latchIssue = issues.find((issue) => issue.code.startsWith("latch"));
const latchCount = box.boxLatches > 0 ? boxGeneratorPlan({ width, depth, height: shape.height }, shape).latches?.spots.length ?? 0 : 0;
properties.push({
id: "boxLatches",
label: t("prop.boxLatches"),
value: box.boxLatches,
min: 0,
max: MAX_BOX_GENERATOR_LATCHES,
step: 1,
hint: latchIssue
? t(LATCH_ISSUE_KEYS[latchIssue.code as keyof typeof LATCH_ISSUE_KEYS], { height: plainNumber(boxGeneratorLatchHeight(box)) })
: box.boxLatches > 0
? t("boxGenerator.latchHint", { count: String(latchCount) })
: undefined,
onChange: (value) => onUpdate({ boxLatches: Math.round(value) || undefined }),
});
if (box.boxLatches > 0) {
properties.push(
{
type: "select",
id: "boxLatchSides",
label: t("prop.boxLatchSides"),
value: box.boxLatchSides,
options: [{ value: "frontBack", label: t("boxGenerator.latchFrontBack") }, { value: "leftRight", label: t("boxGenerator.latchLeftRight") }, { value: "all", label: t("boxGenerator.latchAll") }],
onChange: (value) => onUpdate({ boxLatchSides: normalizeBoxGeneratorLatchSides(value) }),
},
latchWidth,
latchGrip,
);
}
if (box.boxPart === "lid" && (box.boxLidStyle === "overlap" || box.boxLidStyle === "plug" || (box.boxLidStyle === "restOn" && (box.boxStackable || box.boxLatches > 0)))) {
properties.push({ id: "boxLidPlate", label: t("prop.boxLidPlate"), value: box.boxLidPlate, min: MIN_BOX_GENERATOR_WALL, max: Math.max(MIN_BOX_GENERATOR_WALL, shape.height - 0.5), step: 0.1, onChange: (value) => onUpdate({ boxLidPlate: value }) });
}
if (box.boxLidStyle === "overlap" || (box.boxPart === "lid" && box.boxLidStyle === "plug") || (box.boxStackable && (box.boxPart === "box" || box.boxLidStyle === "restOn"))) {
Expand Down Expand Up @@ -4578,6 +4634,15 @@ function getShapeProperties(shape: WorkplaneShape, onUpdate: ShapeInspectorUpdat
*/
const SliderSnapContext = createContext(0);

/** The panel's text for each reason a box generator's latches cannot be made. */
const LATCH_ISSUE_KEYS = {
latchLidStyle: "boxGenerator.issueLatchLidStyle",
latchOutline: "boxGenerator.issueLatchOutline",
latchNoRoom: "boxGenerator.issueLatchNoRoom",
latchLow: "boxGenerator.issueLatchLow",
latchCurved: "boxGenerator.issueLatchCurved",
} as const;

export function ShapeInspector({
shape,
snap,
Expand Down Expand Up @@ -4608,6 +4673,7 @@ export function ShapeInspector({
onVaseAccessories,
onGridfinityKeys,
onMakeBoxLid,
onMakeBoxLatches,
onLayerText,
onTextTags,
onTextBlock,
Expand Down Expand Up @@ -4668,6 +4734,7 @@ export function ShapeInspector({
onGridfinityKeys?: () => void;
/** A box generator box: lays out a matching lid beside it, with the box's own outline, wall, play and stacking. */
onMakeBoxLid?: () => void;
onMakeBoxLatches?: () => void;
/** Splits a text into layers, or builds a layered text again with new words, font or layers (#215). */
onLayerText?: (patch: TextLayerPatch) => void;
/** One tag like this text or stack per name, laid out in rows (#215). */
Expand Down Expand Up @@ -5650,7 +5717,7 @@ export function ShapeInspector({
) : null}
</>
) : null}
{shape.kind === "boxGenerator" && shape.boxPart !== "lid" && onMakeBoxLid ? (
{shape.kind === "boxGenerator" && shape.boxPart !== "lid" && shape.boxPart !== "latch" && onMakeBoxLid ? (
<>
<p className="cylinder-wrap-hint">{t("inspector.boxMakeLidHint")}</p>
<button className="inspector-action-button" type="button" disabled={frozen} onClick={onMakeBoxLid}>
Expand All @@ -5659,6 +5726,15 @@ export function ShapeInspector({
</button>
</>
) : null}
{shape.kind === "boxGenerator" && shape.boxPart !== "latch" && (shape.boxLatches ?? 0) > 0 && onMakeBoxLatches ? (
<>
<p className="cylinder-wrap-hint">{t("inspector.boxMakeLatchesHint")}</p>
<button className="inspector-action-button" type="button" disabled={frozen} onClick={onMakeBoxLatches}>
<Plus size={17} strokeWidth={2.5} />
<span>{t("inspector.boxMakeLatches")}</span>
</button>
</>
) : null}
{onShapeDefaultsChange && propertyDefaults ? (
<div className="property-defaults-actions">
<button type="button" disabled={frozen || sameDefaults} title={t("inspector.saveDefaultsHint")} onClick={() => onShapeDefaultsChange(shape.kind, defaultsToSave)}>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/workplane/viewportShapeObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export function tapeShapeTopologyKey(shape: WorkplaneShape): string {
dovetailNeckWidth: shape.dovetailNeckWidth,
dovetailClearance: shape.dovetailClearance,
...boxGeneratorFieldsOf(shape),
boxKernel: shape.boxGridfinityPlate ? manifoldRevision() : undefined,
boxKernel: shape.boxGridfinityPlate || (shape.boxLatches ?? 0) > 0 ? manifoldRevision() : undefined,
loftBottomOutline: shape.loftBottomOutline,
loftTopOutline: shape.loftTopOutline,
loftBottomWidth: shape.loftBottomWidth,
Expand Down Expand Up @@ -917,7 +917,7 @@ export function shapeGeometrySignature(shape: WorkplaneShape): string {
dovetailNeckWidth: shape.dovetailNeckWidth,
dovetailClearance: shape.dovetailClearance,
...boxGeneratorFieldsOf(shape),
boxKernel: shape.boxGridfinityPlate ? manifoldRevision() : undefined,
boxKernel: shape.boxGridfinityPlate || (shape.boxLatches ?? 0) > 0 ? manifoldRevision() : undefined,
loftBottomOutline: shape.loftBottomOutline,
loftTopOutline: shape.loftTopOutline,
loftBottomWidth: shape.loftBottomWidth,
Expand Down
Loading
Loading