[Constraint 2.0 / B] Allow target=$datum_name syntax #10

Closed
opened 2026-08-03 16:30:10 +00:00 by Mark · 0 comments
Owner

Allow target= to address a datum (depends on sub-issue #A)

Why: today // @sf:place target=motor_mount face=top resolves only to a module/instance name. After datums exist, the user must be able to constrain against a datum — e.g. // @sf:place target=$hinge_axis face=top type=flush means "my part is flush with my face onto the named axis," not "onto another part."

Spec change in src/lib/scad/constraints.ts:

  • Extend the target field on PlaceConstraint, DistanceConstraint, AngleConstraint from string to string with the convention: a leading $ means it's a datum name (lookup in the project manifest's Datum array); otherwise it's a module/instance name as today.
  • Solver resolution: if target starts with $, look up the datum; if not found, error in UI ("Datum '$foo' not declared in any project file").
  • Codegen: emit comment-preserved metadata so a re-export keeps the target binding intact.

Files to change:

  • src/lib/scad/constraints.ts (parse + serialize target= with $ prefix detection)
  • src/lib/scad/solver.ts (datum lookup branch in resolveInstance(), instanceKeyOf())
  • src/lib/scad/constraintCodegen.ts (~30 LOC: pass datum binding through to .scad export)
  • src/components/workbench/ConstraintPanel.tsx (UI selector: "target: [module ▾] [datum ▾]")

Acceptance:

  • Existing target=motor_mount annotations still resolve identically (regression).
  • New target=$hinge_axis resolves and the placeholder pattern in constraintCodegen.ts (line ~75, currently uses a fallback) gets replaced with the datum geometry.
  • Re-export round-trip preserves the $ prefix.

Labels: enhancement


Part of epic #8.

## Allow `target=` to address a datum (depends on sub-issue #A) **Why:** today `// @sf:place target=motor_mount face=top` resolves only to a *module/instance name*. After datums exist, the user must be able to constrain *against* a datum — e.g. `// @sf:place target=$hinge_axis face=top type=flush` means "my part is flush with my face onto the named axis," not "onto another part." **Spec change in `src/lib/scad/constraints.ts`:** - Extend the `target` field on `PlaceConstraint`, `DistanceConstraint`, `AngleConstraint` from `string` to `string` with the convention: a leading `$` means it's a datum name (lookup in the project manifest's `Datum` array); otherwise it's a module/instance name as today. - Solver resolution: if `target` starts with `$`, look up the datum; if not found, error in UI ("Datum '$foo' not declared in any project file"). - Codegen: emit comment-preserved metadata so a re-export keeps the target binding intact. **Files to change:** - `src/lib/scad/constraints.ts` (parse + serialize target= with `$` prefix detection) - `src/lib/scad/solver.ts` (datum lookup branch in `resolveInstance()`, `instanceKeyOf()`) - `src/lib/scad/constraintCodegen.ts` (~30 LOC: pass datum binding through to `.scad` export) - `src/components/workbench/ConstraintPanel.tsx` (UI selector: "target: [module ▾] [datum ▾]") **Acceptance:** - Existing `target=motor_mount` annotations still resolve identically (regression). - New `target=$hinge_axis` resolves and the placeholder pattern in `constraintCodegen.ts` (line ~75, currently uses a fallback) gets replaced with the datum geometry. - Re-export round-trip preserves the `$` prefix. **Labels:** enhancement --- Part of epic #8.
Sign in to join this conversation.
No description provided.