@rulecad/cad 0.7.48 → 0.7.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/assembly.mjs CHANGED
@@ -16,6 +16,8 @@
16
16
  // { "holes": "pcb.board", "into": "case.body", "depth": "m2.insert_length", "label": "Screws find their inserts" }
17
17
  // The path must be clear for depth mm (it lands in a hole) and solid within "ring" mm of it (default: the hole's
18
18
  // diameter) half way down, so the screw has something to grip. "direction": "up" for screws from below.
19
+ // A screwed joint is a fasten (lib/fasten.mjs): { "screw": "M3 cap", "through": ["bracket"], "into": "base", "at": ["bracket.h1"] }.
20
+ // Its holes are read from the parts as drawn, its screws placed as reference parts, and it holds as a fit that fastens does.
19
21
  import { host, readJson } from './host.mjs';
20
22
  import fs from 'node:fs';
21
23
  import crypto from 'node:crypto';
@@ -29,7 +31,7 @@ import { satisfies } from '@rulecad/versions';
29
31
  import { bounds } from '@rulecad/printcheck';
30
32
  import { closest, closestAt, inside, distanceToFace, overlapAt } from '@rulecad/fit';
31
33
  import { keys as keyCentres, readLayout, hasLayout } from './layout.mjs';
32
- import { DOFS, frame, turn, mul, pathLength, jointValues, placeItems, jointMatrix } from '@rulecad/model-link';
34
+ import { DOFS, frame, turn, mul, inv, pathLength, jointValues, placeItems, jointMatrix } from '@rulecad/model-link';
33
35
  import { gearModel, internalModel, rackModel, mesh as meshOf, phase, rackPhase, contact, wormModel, wormMesh, bevelModel, bevelMesh, compoundEfficiency } from '@rulecad/gears';
34
36
  import { ops as booleans } from '@rulecad/shapes';
35
37
  import { motorBuilt, motorDrives, shaftFits, loadsOf, motorChecks, shaftFit, axisOf } from './motors.mjs';
@@ -44,6 +46,8 @@ import { gripChecks } from './grip.mjs';
44
46
  import { gaitOf, gaitChecks, gaitSequence } from './gait.mjs';
45
47
  import { boughtBuilt, boughtFindings, boughtSets } from './bought.mjs';
46
48
  import { orderChecks } from './order.mjs';
49
+ import { beamBuilt, beamPlace, beamAddress, beamFindings, marksOf } from './beams.mjs';
50
+ let fastening = null; // lib/fasten.mjs, loaded with the first assembly that has a fasten: the rest start as fast as before
47
51
 
48
52
  export const assemblyPath = (ref) => { const [project, name] = String(ref).split('/'); return path.join(paths.project(project || ''), 'assemblies', `${name || ''}.json`); };
49
53
  export const isAssembly = (ref) => String(ref).includes('/') && host.exists(assemblyPath(ref.split('@')[0]));
@@ -107,6 +111,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
107
111
  const built = new Map(); // each object or component is built once per set of values, however many copies are placed
108
112
  const source = async (it, extra) => {
109
113
  if (it.motor) { const key = JSON.stringify(['motor', it.id, it.motor]); if (!built.has(key)) built.set(key, motorBuilt(it.motor, num, it.id)); return built.get(key); }
114
+ if (it.beam) { const b = beamBuilt(it, num, it.id); if (!built.has(b.key)) built.set(b.key, b); return built.get(b.key); } // (lib/beams.mjs)
110
115
  if (it.bought) {
111
116
  const key = JSON.stringify(['bought', it.id, it.bought, it.variant, it.set]);
112
117
  if (!built.has(key)) built.set(key, boughtSets().get(it.bought) === 'motor' ? motorBuilt({ model: it.bought }, num, it.id) : boughtBuilt(it.bought, it, num, it.id));
@@ -148,7 +153,8 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
148
153
  let builtCount = 0;
149
154
  for (const it of a.items || []) {
150
155
  if (!/^[a-z][\w-]*$/.test(it.id || '')) throw new Error(`each item needs an id (letters, digits, - or _): got ${JSON.stringify(it.id)}`);
151
- if ([it.object, it.assembly, it.motor, it.bought].filter(Boolean).length !== 1) throw new Error(`item ${it.id}: give one of "object", "assembly", "motor" or "bought"`);
156
+ if ([it.object, it.assembly, it.motor, it.bought, it.beam].filter(Boolean).length !== 1) throw new Error(`item ${it.id}: give one of "object", "assembly", "motor", "bought" or "beam"`);
157
+ if (!it.beam && (it.to != null || it.roll != null)) throw new Error(`item ${it.id}: to and roll place a beam by its ends: place ${it.object || it.assembly || it.motor?.model || it.bought} with at and rotate`);
152
158
  // Copies: one, a grid from repeat x/y, or a layout's keys. Each: { id, offset (from at), extra (values to set) }
153
159
  const rx = it.repeat?.x, ry = it.repeat?.y, rl = it.repeat?.layout, copies = [];
154
160
  if (rl) {
@@ -213,11 +219,13 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
213
219
  for (const n of sub.seen) seen.add(n);
214
220
  items.push({ ...it, id, sub, role: 'part' });
215
221
  } else {
216
- objects.push({ id, objName: src.objName, version: src.version, built: src.b, role: src.role, ...(src.set ? { set: src.set } : {}), ...(src.variant ? { variant: src.variant } : {}), ...(src.bought ? { bought: src.bought } : {}), ...(src.motor ? { motor: src.motor } : {}) });
217
- items.push({ ...it, id, objName: src.objName, built: src.b, version: src.version, role: src.role });
222
+ objects.push({ id, objName: src.objName, version: src.version, built: src.b, role: src.role, ...(src.set ? { set: src.set } : {}), ...(src.variant ? { variant: src.variant } : {}), ...(src.bought ? { bought: src.bought } : {}), ...(src.motor ? { motor: src.motor } : {}), ...(src.beam ? { beam: src.beam } : {}) });
223
+ items.push({ ...it, id, objName: src.objName, built: src.b, version: src.version, role: src.role, ...(src.beam ? { beam: src.beam } : {}) });
218
224
  }
219
225
  }
220
- // Every part, with its item where the joints put it at these values (jointValues)
226
+ // Every part, with its item where the joints put it at these values (jointValues); then the hardware of its fasten
227
+ // relations (lib/fasten.mjs), each piece with the item it sits in
228
+ let hardware = [];
221
229
  const partsAt = (worlds) => {
222
230
  const out = [];
223
231
  placed.forEach(([, c], k) => {
@@ -229,26 +237,47 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
229
237
  for (const p of src.sub.parts) {
230
238
  if (p.role === 'support' && a.kind !== 'plate') continue;
231
239
  out.push({ ...p, name: `${id}.${p.name}`, item: id, leaf: `${id}.${p.leaf}`, label: `${id} ${p.label}`,
232
- geometry: transform(m, p.geometry), polygons: move(p.polygons), triangles: move(p.triangles), m: jscad.maths.mat4.multiply(jscad.maths.mat4.create(), m, p.m) });
240
+ geometry: transform(m, p.geometry), polygons: move(p.polygons), triangles: move(p.triangles), ...(p.collide ? { collide: transform(m, p.collide) } : {}), m: jscad.maths.mat4.multiply(jscad.maths.mat4.create(), m, p.m),
241
+ ...(p.hardware ? { moves: id, allow: p.allow.map((l) => `${id}.${l}`), lift: jscad.maths.vec3.transform([0, 0, 0], p.lift, [...m.slice(0, 12), 0, 0, 0, 1]) } : {}) }); // (a component's screws move with it)
233
242
  }
234
243
  } else {
235
244
  for (const p of src.b.parts) {
236
245
  if (p.role === 'support' && a.kind !== 'plate') continue; // supports are snipped off before parts go together
237
- out.push({ name: `${id}.${p.name}`, item: id, leaf: id, object: src.objName, role: src.role === 'reference' ? 'reference' : p.role, label: `${id}: ${p.label}`,
246
+ out.push({ name: `${id}.${p.name}`, item: id, leaf: id, object: src.objName, role: src.role === 'reference' ? 'reference' : p.role, label: `${id}: ${marks.has(id) ? `mark ${marks.get(id)}, ` : ''}${p.label}`,
238
247
  ...(p.filament ? { filament: p.filament } : {}), ...(p.mirror === false ? { mirror: false } : {}), part: p.name,
239
- geometry: transform(m, p.geometry), polygons: move(p.polygons), triangles: move(p.triangles),
248
+ geometry: transform(m, p.geometry), ...(p.collide ? { collide: transform(m, p.collide) } : {}), polygons: move(p.polygons), triangles: move(p.triangles),
240
249
  shape: `${key}:${p.name}`, hash: `${src.b.hash}:${p.name}`, local: p.polygons, localTriangles: p.triangles, m });
241
250
  }
242
251
  }
243
252
  });
253
+ for (const h of hardware) out.push(fastening.hardwarePart(h, toMat4(worlds[h.host])));
244
254
  return out;
245
255
  };
246
256
  for (const x of a.fits || []) for (const p of x.poses || []) if (!motion.poses[p]) throw new Error(`fit ${x.note || x.label || `${x.a} / ${x.b}`}: no pose "${p}" (poses: ${Object.keys(motion.poses).join(', ') || 'none'})`);
257
+ // each beam's mark on the cut list and its sheet (beams that are the same share one), shown in its label
258
+ const marks = marksOf(objects);
259
+ for (const o of objects) if (marks.has(o.id)) o.mark = marks.get(o.id);
247
260
  const pose = opts.pose ?? motion.pose;
248
261
  const jv = jointValues(motion, pose);
249
- parts.push(...partsAt(placeItems(motion, jv)));
262
+ const worlds0 = placeItems(motion, jv);
263
+ parts.push(...partsAt(worlds0));
264
+ // Screwed joints: each screw followed through the parts as they stand, its hardware placed, and the joint counted as a
265
+ // fit that fastens (what holds a part, what the order of assembly and the list read)
266
+ let fastened = null;
267
+ if (a.fasten?.length && a.kind !== 'plate') {
268
+ fastening ||= await import('./fasten.mjs');
269
+ fastened = fastening.fastenOf({ a, project, parts, objects, motion, num }, worlds0, { access: pose === motion.pose });
270
+ hardware = fastened.hardware;
271
+ parts.push(...hardware.map((h) => fastening.hardwarePart(h, toMat4(worlds0[h.host]))));
272
+ fits.push(...fastened.fits.map((x) => ({ ...x, num })));
273
+ }
250
274
  // A fit with * applies to every copy: "key-*.switch.bottom" becomes one fit for key-0-0, key-0-1, …
251
275
  // With * on both sides, each copy is checked against all the others: { "a": "key-*.cap", "b": "key-*.cap" }
276
+ // A beam's address in a fit or an access is read now, so one past the beam's end is refused by name when it is built
277
+ const beamIds = new Set(placed.filter(([it]) => it.beam).map(([, c]) => c.id));
278
+ for (const x of a.fits || []) for (const n of [x.a, x.b, x.access].flat()) {
279
+ if (typeof n === 'string' && beamIds.has(n.split('.')[0]) && n.includes('.') && !/\.body$/.test(n)) motion.address(n, `fit ${x.note || x.label || `${x.a} / ${x.b}`}`);
280
+ }
252
281
  for (let x of a.fits || []) {
253
282
  if (x.seat != null && x.min == null) x = { ...x, min: -1000 }; // a seat presses, so the pair may overlap
254
283
  if (x.holes) x = { ...x, a: x.holes, b: x.into }; // a holes fit: a board's holes (a) over what its screws go into (b)
@@ -271,9 +300,9 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
271
300
  const at = (p) => {
272
301
  if (typeof p === 'string' && others[p]) return others[p];
273
302
  const v = jointValues(motion, p), moved = partsAt(placeItems(motion, v));
274
- return { ...s, parts: moved, pose: typeof p === 'string' ? p : null, jointValues: v, polygons: moved.flatMap((x) => x.polygons), triangles: moved.flatMap((x) => x.triangles) };
303
+ return { ...s, parts: moved, fastened: null, pose: typeof p === 'string' ? p : null, jointValues: v, polygons: moved.flatMap((x) => x.polygons), triangles: moved.flatMap((x) => x.triangles) };
275
304
  };
276
- const s = { a, project, name, items, parts, objects, fits, requires, values, num, seen, motion, wires, task, gait, pose: typeof pose === 'string' ? pose : null, jointValues: jv, at,
305
+ const s = { a, project, name, items, parts, objects, fits, requires, values, num, seen, motion, wires, task, gait, fastened, hardware, pose: typeof pose === 'string' ? pose : null, jointValues: jv, at,
277
306
  polygons: parts.flatMap((p) => p.polygons), triangles: parts.flatMap((p) => p.triangles) };
278
307
  return s;
279
308
  }
@@ -320,30 +349,42 @@ function motionOf(a, placed, num, ref) {
320
349
  // An anchor: { item (index, -1 the world), frame (12 numbers, in the item's own frame) }
321
350
  const anchor = (spec, what) => {
322
351
  if (spec && typeof spec === 'object') return { item: spec.item ? where(spec.item, what) : -1, frame: frameOf(spec, num) };
323
- const bits = String(spec).split('.'), name = bits.pop(), [id, ...inside] = bits;
324
- if (!id || !name) throw new Error(`${what}: name an anchor as <item>.<anchor> (got "${spec}")`);
352
+ const bits = String(spec).split('.'), id = bits[0];
353
+ if (bits.length < 2 || !id || !bits.at(-1)) throw new Error(`${what}: name an anchor as <item>.<anchor> (got "${spec}")`);
325
354
  const k = where(id, what);
326
- let src = placed[k][1].src, pre = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0];
327
- for (const n of inside) { // into a component: its item's place there
328
- const sub = src.sub?.items.find((x) => x.id === n);
329
- if (!sub) throw new Error(`${what}: ${id} has no item "${n}"`);
355
+ let src = placed[k][1].src, pre = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0], i = 1;
356
+ for (; i < bits.length - 1 && !src.beam; i++) { // into a component: its item's place there
357
+ const n = bits[i], sub = src.sub?.items.find((x) => x.id === n);
358
+ if (!sub) throw new Error(`${what}: ${bits.slice(0, i).join('.')} has no item "${n}"`);
330
359
  pre = mul(pre, rows(sub.m));
331
- src = sub.sub ? { sub: sub.sub } : { b: sub.built, objName: sub.objName };
360
+ src = sub.sub ? { sub: sub.sub } : { b: sub.built, objName: sub.objName, beam: sub.beam };
332
361
  }
362
+ // A beam's address, the rest of the name: an end (a, b), an end's bore (a.1), a face with a distance (top.2@120)
363
+ if (src.beam) return { item: k, frame: mul(pre, beamAddress(src.beam, bits.slice(i).join('.'), `${what}: ${bits.slice(0, i).join('.')}`)) };
364
+ const name = bits[i];
333
365
  const anchors = src.b?.object.anchors || {};
334
366
  if (!anchors[name]) throw new Error(`${what}: ${src.objName || id} has no anchor "${name}" (anchors: ${Object.keys(anchors).join(', ') || 'none'})`);
335
367
  return { item: k, frame: mul(pre, frameOf(anchors[name], evalIn(src.b.values, `${src.objName} anchor ${name}`))) };
336
368
  };
337
369
  const joints = [], children = new Set();
338
- for (const j of a.joints || []) {
370
+ // An item at an address ("at": "x1.top@50%") is held there as by a fixed joint: its own origin on the anchor, its z
371
+ // out of the face and its x along the beam toward end b, turned by its rotate in that frame; it moves with the beam
372
+ const atAddress = placed.map(([it]) => it).filter((it, k, all) => typeof it.at === 'string' && all.indexOf(it) === k).map((it) => {
373
+ if (it.repeat) throw new Error(`item ${it.id}: an item at an address ("${it.at}") is one copy: place a repeat with at [x, y, z]`);
374
+ if (it.beam) throw new Error(`item ${it.id}: a beam is placed by its ends (from, to) or at a point [x, y, z], not at an address`);
375
+ return { id: `${it.id}@`, type: 'fixed', parent: it.at, child: { item: it.id, at: [0, 0, 0], ...(it.rotate ? { rotate: it.rotate } : {}) }, at: true };
376
+ });
377
+ for (const j of [...atAddress, ...(a.joints || [])]) {
339
378
  const what = `joint ${j.id}`;
340
- if (!/^[a-z][\w-]*$/.test(j.id || '')) throw new Error(`each joint needs an id (letters, digits, - or _): got ${JSON.stringify(j.id)}`);
379
+ if (!j.at && !/^[a-z][\w-]*$/.test(j.id || '')) throw new Error(`each joint needs an id (letters, digits, - or _): got ${JSON.stringify(j.id)}`);
341
380
  if (!Object.hasOwn(DOFS, j.type)) throw new Error(`${what}: type is one of ${Object.keys(DOFS).join(', ')} (got ${JSON.stringify(j.type)})`);
342
- const p = j.parent == null ? { item: -1, frame: frame([0, 0, 0]) } : anchor(j.parent, what), c = anchor(j.child, what);
381
+ const p = j.parent == null ? { item: -1, frame: frame([0, 0, 0]) } : anchor(j.parent, j.at ? `item ${j.child.item}: at` : what), c = anchor(j.child, what);
382
+ if (j.at) c.frame = inv(c.frame); // (the item turned by its rotate in the anchor's frame: the joint's child anchor is that turn undone)
343
383
  if (c.item < 0) throw new Error(`${what}: its child must be an item`);
344
- if (children.has(c.item)) throw new Error(`${what}: ${placed[c.item][1].id} is already placed by another joint (two joints to one item make a ring: use loops)`);
384
+ if (j.at && p.item === c.item) throw new Error(`item ${j.child.item}: at "${j.parent}" is on the item itself`);
385
+ if (children.has(c.item)) throw new Error(`${what}: ${placed[c.item][1].id} is already placed by ${joints.find((x) => x.child === c.item)?.at ? `its at (${placed[c.item][0].at})` : 'another joint'} (two joints to one item make a ring: use loops)`);
345
386
  const [it] = placed[c.item];
346
- if (it.at || it.rotate || it.repeat) throw new Error(`${what}: ${it.id} is placed by the joint, so it can't have at, rotate or repeat`);
387
+ if (!j.at && (it.at || it.rotate || it.repeat || it.from != null && it.beam)) throw new Error(`${what}: ${it.id} is placed by the joint, so it can't have at, rotate, repeat${it.beam ? ', or from and to' : ''}`);
347
388
  children.add(c.item);
348
389
  const path = j.type === 'path' ? (j.path || []).map((pt) => pt.map(num)) : undefined;
349
390
  if (path && path.length < 2) throw new Error(`${what}: a path joint needs "path": two points or more`);
@@ -356,7 +397,7 @@ function motionOf(a, placed, num, ref) {
356
397
  if (mn > mx) throw new Error(`${what}: min ${mn} is above max ${mx}`);
357
398
  return [mn, mx, val[i] != null ? num(val[i]) : Math.min(mx, Math.max(mn, 0))];
358
399
  });
359
- joints.push({ id: j.id, type: j.type, parent: p.item, child: c.item, a: p.frame, b: c.frame, dofs,
400
+ joints.push({ id: j.id, type: j.type, parent: p.item, child: c.item, a: p.frame, b: c.frame, dofs, ...(j.at ? { at: true } : {}),
360
401
  ...(j.label ? { label: j.label } : {}), ...(path ? { path } : {}), ...(j.cone != null ? { cone: num(j.cone) } : {}),
361
402
  ...(j.follow ? { follow: [j.follow, j.ratio != null ? num(j.ratio) : 1, j.offset != null ? num(j.offset) : 0] } : {}),
362
403
  ...(j.mesh ? { meshSpec: j.mesh } : {}), ...(j.brake ? { brake: j.brake } : {}) });
@@ -368,6 +409,8 @@ function motionOf(a, placed, num, ref) {
368
409
  }
369
410
  const items = placed.map(([it, c], k) => {
370
411
  if (children.has(k)) return [c.id];
412
+ const ends = it.beam ? beamPlace(it, num) : null; // a beam by its ends (lib/beams.mjs)
413
+ if (ends) return [c.id, ...ends];
371
414
  const base = (it.at || [0, 0, 0]).map(num), rot = (it.rotate || [0, 0, 0]).map((r) => num(r) * deg);
372
415
  // A repeated item turns as a whole about its at: each copy's offset turns with it (keys on a tilted plate)
373
416
  return [c.id, ...rows(translate(base, rotate(rot, translate([c.offset[0], c.offset[1], 0], jscad.geometries.geom3.create()))).transforms)];
@@ -385,7 +428,10 @@ function motionOf(a, placed, num, ref) {
385
428
  const marks = placed.flatMap(([, c], k) => Object.entries(c.src?.b?.object.anchors || {}).map(([name, spec]) => {
386
429
  try { return { item: k, id: c.id, name, frame: frameOf(spec, evalIn(c.src.b.values, `${c.src.objName} anchor ${name}`)) }; } catch { return null; }
387
430
  })).filter(Boolean);
388
- return { items, joints, poses, pose: a.pose || Object.keys(poses)[0], loops, ref, marks, meshes, drives, loads, gravity: (a.gravity || [0, 0, -1]).map(num) };
431
+ // address(name): any anchor by name, a beam's addresses too (x1.top@120), as { item, frame }: for fits and the build order
432
+ // Where each screw of a fasten goes, where it says so with anchors: a point on its axis, the anchor's z along it
433
+ const fasten = (a.fasten || []).map((x, i) => (Array.isArray(x.at) ? x.at : []).map((n) => ({ ...anchor(n, `fasten ${i + 1}`), name: typeof n === 'string' ? n : null })));
434
+ return { items, joints, poses, pose: a.pose || Object.keys(poses)[0], loops, ref, marks, meshes, drives, loads, fasten, gravity: (a.gravity || [0, 0, -1]).map(num), address: (n, what = 'address') => anchor(n, what) };
389
435
  }
390
436
 
391
437
  // A pair measured from its drawn teeth (@rulecad/gears contact: backlash, transmission error, interference), kept in
@@ -644,6 +690,14 @@ function gearMeshes(joints, items, num) {
644
690
  }
645
691
 
646
692
  // Where each item's anchors are in a pose: [{ id: 'keyboard@pivot', item, at: [x, y, z] }]
693
+ // Where an address is in the world, at these joint values: { id (its item), at, frame }, or null where it is not an
694
+ // address on a beam (x1.top@120, x1.a.1). A beam's address it does not have is refused by name.
695
+ export function addressAt(s, n, values = s.jointValues) {
696
+ const id = String(n).split('.')[0], it = s.items.find((x) => x.id === id);
697
+ if (!it?.beam || !String(n).includes('.') || !s.motion?.address) return null;
698
+ const r = s.motion.address(n), W = mul(placeItems(s.motion, values)[r.item], r.frame);
699
+ return { id, at: [W[3], W[7], W[11]], frame: W };
700
+ }
647
701
  export function anchorsAt(s, values = s.jointValues) {
648
702
  const worlds = placeItems(s.motion, values);
649
703
  return (s.motion.marks || []).map((m) => { const w = mul(worlds[m.item], m.frame); return { id: `${m.id}@${m.name}`, item: m.id, at: [w[3], w[7], w[11]] }; });
@@ -683,11 +737,12 @@ async function measurer() {
683
737
  const OVERLAPS = paths.cache('overlaps.json');
684
738
  let remembered = null, fresh = 0;
685
739
  function pairOverlap(pa, pb) {
686
- if (!pa.hash || !pb.hash) return overlap(pa.geometry, pb.geometry);
740
+ const solidOf = (p) => p.collide ?? p.geometry; // (a beam by its envelope: lib/beams.mjs)
741
+ if (!pa.hash || !pb.hash) return overlap(solidOf(pa), solidOf(pb));
687
742
  remembered ||= (() => { try { return JSON.parse(host.readText(OVERLAPS)); } catch { return {}; } })();
688
743
  const at = (p) => `${p.hash}@${Array.from(p.m || []).map((x) => Math.round(x * 1e6) / 1e6).join(',')}`;
689
744
  const [x, y] = [at(pa), at(pb)].sort(), k = crypto.createHash('sha1').update(`crossing+${solid ? 'manifold' : 'jscad'}|${x}|${y}`).digest('hex');
690
- if (!(k in remembered)) { remembered[k] = overlap(pa.geometry, pb.geometry); fresh++; }
745
+ if (!(k in remembered)) { remembered[k] = overlap(solidOf(pa), solidOf(pb)); fresh++; }
691
746
  return remembered[k];
692
747
  }
693
748
  function saveOverlaps() {
@@ -695,6 +750,9 @@ function saveOverlaps() {
695
750
  try { host.writeText(OVERLAPS, JSON.stringify(remembered)); fresh = 0; } catch {} // only slower without it
696
751
  }
697
752
 
753
+ // A screw and what it is threaded into (its part, its nut, its insert) share space by design: fasten's hardware says which
754
+ const threaded = (a, b) => !!(a.allow?.includes(b.leaf) || b.allow?.includes(a.leaf));
755
+
698
756
  // checkAssembly(built) -> findings, as @rulecad/printcheck: { level, text, card? } (card: a short line for the mirror)
699
757
  // What a project prints in, for the motors' heat and press-fit checks
700
758
  const materialOf = (project) => { try { return readJson(path.join(paths.project(project), 'project.json')).material; } catch { return null; } };
@@ -721,7 +779,7 @@ export function checkAssembly(s) {
721
779
  }
722
780
  // Overlaps between object instances, inside components too. Bounding boxes first: most pairs can't touch.
723
781
  const named = (p, n) => p.name === n || p.leaf === n || p.item === n || p.name.startsWith(`${n}.`);
724
- const allowed = (a, b) => s.fits.some((x) => x.min != null && x.num(x.min) < 0 && ((named(a, x.a) && named(b, x.b)) || (named(a, x.b) && named(b, x.a))));
782
+ const allowed = (a, b) => threaded(a, b) || s.fits.some((x) => x.min != null && x.num(x.min) < 0 && ((named(a, x.a) && named(b, x.b)) || (named(a, x.b) && named(b, x.a))));
725
783
  const box = new Map(), bx = (p) => box.get(p) || (box.set(p, bounds(p.triangles)), box.get(p));
726
784
  const touch = (a, b) => [0, 1, 2].every((k) => bx(a).lo[k] <= bx(b).hi[k] + 1e-6 && bx(b).lo[k] <= bx(a).hi[k] + 1e-6);
727
785
  const clashes = [];
@@ -738,11 +796,13 @@ export function checkAssembly(s) {
738
796
  // A fit names parts (keyboard, key-0-0.cap), or the faces of an item near one of its anchors (keyboard@pivot, within
739
797
  // "within" mm, 10 by default): the pocket round a pivot, not the whole case
740
798
  const marks = anchorsAt(s), within = (x) => (x.within != null ? x.num(x.within) : 10);
799
+ // A beam's address in a fit (x1.top@120): the faces near that point, as near an anchor
800
+ const addressMark = (n) => { const r = addressAt(s, n); return r && { id: n, item: r.id, at: r.at }; };
741
801
  const near = (p, mark, r) => ({ ...p, polygons: p.polygons.filter((f) => distanceToFace(mark.at, f) <= r) });
742
802
  const pickIn = (n, x) => {
743
803
  if (Array.isArray(n)) return n.flatMap((m) => pickIn(m, x));
744
- if (!n.includes('@')) return s.parts.filter((p) => named(p, n));
745
- const mark = marks.find((m) => m.id === n);
804
+ if (!n.includes('@')) { const ps = s.parts.filter((p) => named(p, n)); if (ps.length) return ps; } // (else a beam's end or face: x1.a, x1.top)
805
+ const mark = marks.find((m) => m.id === n) ?? addressMark(n);
746
806
  if (!mark) return [];
747
807
  return s.parts.filter((p) => named(p, mark.item)).map((p) => near(p, mark, within(x))).filter((p) => p.polygons.length);
748
808
  };
@@ -848,7 +908,7 @@ export function checkAssembly(s) {
848
908
  // nowhere else: a ring gear resting on its case turns with the planets; a pawl resting on its post walks off it.
849
909
  if (s.motion.joints.some((j) => j.type !== 'fixed')) {
850
910
  const ids = s.motion.items.map((x) => x[0]), top = (n) => String(n).split(/[.@]/)[0];
851
- const held = new Set([ids[0], ...s.motion.joints.map((j) => ids[j.child])]), links = s.fits.filter((x) => x.fastens).map((x) => [top(x.a), top(x.b)]);
911
+ const held = new Set([ids[0], ...s.motion.joints.filter((j) => !j.at).map((j) => ids[j.child])]), links = s.fits.filter((x) => x.fastens).map((x) => [top(x.a), top(x.b)]);
852
912
  for (let grew = true; grew;) { grew = false; for (const [a, b] of links) { if (held.has(a) && !held.has(b)) { held.add(b); grew = true; } if (held.has(b) && !held.has(a)) { held.add(a); grew = true; } } }
853
913
  const placed = new Set(s.objects.filter((o) => !o.unplaced && o.role !== 'reference').map((o) => top(o.id)));
854
914
  const loose = ids.filter((id) => !held.has(id) && placed.has(id));
@@ -864,7 +924,9 @@ export function checkAssembly(s) {
864
924
  }
865
925
  }
866
926
  }
927
+ if (s.a.fasten?.length && fastening) fastening.fastenChecks(s, f, { placeItems });
867
928
  boughtFindings(s, f);
929
+ beamFindings(s, f);
868
930
  massFinding(s, f);
869
931
  runningChecks(s, f, { axisOf, placeItems, jointValues, mul });
870
932
  if (s.wires?.length) wireChecks(s, f, { placeItems, jointValues, mul });
@@ -902,7 +964,7 @@ export function loopGaps(s) {
902
964
 
903
965
  // Pairs of parts that overlap, as checkAssembly finds them (fits with a negative min allowed): [[a, b, mm³]]
904
966
  function clashesOf(s, named) {
905
- const allowed = (a, b) => s.fits.some((x) => x.min != null && x.num(x.min) < 0 && ((named(a, x.a) && named(b, x.b)) || (named(a, x.b) && named(b, x.a))));
967
+ const allowed = (a, b) => threaded(a, b) || s.fits.some((x) => x.min != null && x.num(x.min) < 0 && ((named(a, x.a) && named(b, x.b)) || (named(a, x.b) && named(b, x.a))));
906
968
  const boxes = s.parts.map((p) => bounds(p.triangles)), out = [];
907
969
  for (let i = 0; i < s.parts.length; i++) for (let j = i + 1; j < s.parts.length; j++) {
908
970
  const pa = s.parts[i], pb = s.parts[j], A = boxes[i], B = boxes[j];
@@ -963,14 +1025,14 @@ export function motionData(s) {
963
1025
  const named = (p, n) => p.name === n || p.leaf === n || p.item === n || p.name.startsWith(`${n}.`), allow = [];
964
1026
  const loose = s.fits.filter((x) => x.min != null && x.num(x.min) < 0);
965
1027
  s.parts.forEach((pa, i) => s.parts.forEach((pb, j) => {
966
- if (j > i && pa.item !== pb.item && loose.some((x) => (named(pa, x.a) && named(pb, x.b)) || (named(pa, x.b) && named(pb, x.a)))) allow.push([i, j]);
1028
+ if (j > i && pa.item !== pb.item && (threaded(pa, pb) || loose.some((x) => (named(pa, x.a) && named(pb, x.b)) || (named(pa, x.b) && named(pb, x.a))))) allow.push([i, j]);
967
1029
  }));
968
1030
  return { motion: {
969
1031
  items: mo.items.map(([n, ...m]) => [n, ...m.map(r)]),
970
1032
  joints: mo.joints.map(({ id, type, parent, child, a, b, dofs, label, follow, path, cone, step }) => ({ id, type, parent, child, a: a.map(r), b: b.map(r), dofs: dofs.map((d) => d.map(r)),
971
1033
  ...(label ? { label } : {}), ...(follow ? { follow } : {}), ...(path ? { path: path.map((p) => p.map(r)) } : {}), ...(cone != null ? { cone } : {}), ...(step ? { step } : {}) })),
972
1034
  poses: mo.poses, ...(s.pose ? { pose: s.pose } : {}),
973
- part: s.parts.map((p) => names.indexOf(p.item)),
1035
+ part: s.parts.map((p) => names.indexOf(p.moves ?? p.item)), // (a screw moves with the item it sits in)
974
1036
  ...(allow.length ? { allow } : {}),
975
1037
  ...(s.gait ? { sequence: gaitSequence(s) ?? undefined } : {}),
976
1038
  } };
package/lib/beams.mjs ADDED
@@ -0,0 +1,147 @@
1
+ // Beams in assemblies (@rulecad/frames).
2
+ //
3
+ // A beam item is a length of a profile: { "id": "x1", "beam": { "profile": "2020-misumi-hfs5", "length": 300 },
4
+ // "from": [0, 0, 0], "to": [300, 0, 0], "roll": 0 }, or placed with at and rotate as any item is. It is bought, so it is
5
+ // drawn faint (a reference), goes on cad list by profile and length, and is in the overlap check by its envelope.
6
+ // Its frame is the beam's own: end a at z = 0, end b at z = length, top +y, front -x. Placed by its ends, its z runs
7
+ // from to to, and at roll 0 its top faces up (+z), or +y when it stands upright (within 0.1° of z); roll turns it
8
+ // about its own axis, a toward b, right-handed.
9
+ // Its addresses are anchors (lib/assembly.mjs reads them through beamAnchor): x1.a, x1.b, x1.a.1, x1.top, x1.top@120,
10
+ // x1.top@-20, x1.top@50%, x1.top.2@120.
11
+ // Its operations ("ops": cut, mitre, tap, access, drill, counterbore, pocket, notch, deburr) are @rulecad/frames': each
12
+ // is cut into its preview, a mitre into its envelope too, and their findings (beam.op) are the beam's.
13
+ import * as frames from '@rulecad/frames';
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { beamModel, beam, beamAnchor, cutList, beamMarks, beamSheet } from '@rulecad/frames';
17
+ import { frame } from '@rulecad/model-link';
18
+ import { RULE_DIRS, paths } from './workspace.mjs';
19
+ import { named } from './parts.mjs';
20
+ import { referenceBuilt } from './bought.mjs';
21
+ import { framesContext as contextIn, givenFor } from './frames.mjs';
22
+
23
+ const KEYS = ['profile', 'length', 'printed', 'material', 'ops'];
24
+ const OP_NUMBERS = ['angle', 'depth', 'diameter', 'length', 'radius'];
25
+ const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
26
+ const mm = (x) => String(+Number(x).toFixed(2));
27
+ const strip = (e) => String(e?.message ?? e).replace(/^(beamModel|beamAnchor|profileModel|beam): /, '');
28
+ /** This workspace's frames sets (lib/frames.mjs framesContext over its rules/) */
29
+ export const framesContext = () => contextIn(RULE_DIRS[0]);
30
+
31
+ /**
32
+ * The beam an item names, its length worked out: { model, length }. A length may be an expression; left out, it is the
33
+ * distance from from to to. Refused by name: an unknown key, no profile, a printed beam (a later release), a length
34
+ * that disagrees with its ends, ends and at both given.
35
+ * @param {object} it the item @param {(x: any) => number} num the assembly's expressions @param {object} [context] framesContext()'s
36
+ */
37
+ export function beamOf(it, num, context = framesContext()) {
38
+ const what = `item ${it.id}`, b = it.beam;
39
+ if (!b || typeof b !== 'object' || Array.isArray(b)) throw new Error(`${what}: beam is { "profile", "length", "material" } (got ${shown(b)})`);
40
+ for (const k of Object.keys(b)) if (!KEYS.includes(k)) throw new Error(`${what}: a beam has no "${k}": it takes ${KEYS.join(', ')}`);
41
+ if (typeof b.profile !== 'string' || !b.profile) throw new Error(`${what}: beam.profile names a profile, such as 2020-misumi-hfs5 (got ${shown(b.profile)})`);
42
+ if (b.printed != null && typeof b.printed !== 'boolean') throw new Error(`${what}: beam.printed is true or false (got ${shown(b.printed)})`);
43
+ if (b.printed) throw new Error(`${what}: a printed beam ("printed": true) is a later release${b.ops?.length ? ', and its ops become features of the print then' : ''}: leave printed out for a bought beam of ${b.profile}`);
44
+ if (b.ops != null && !Array.isArray(b.ops)) throw new Error(`${what}: beam.ops is a list of operations, [{ "op": "tap", "at": "a" }] (got ${shown(b.ops)})`);
45
+ // an operation's numbers may be expressions, as a length is
46
+ const ops = (b.ops ?? []).map((o) => (o && typeof o === 'object' && !Array.isArray(o) ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, OP_NUMBERS.includes(k) && v != null ? num(v) : k === 'size' && Array.isArray(v) ? v.map(num) : v])) : o));
47
+ if (b.material != null && typeof b.material !== 'string') throw new Error(`${what}: beam.material is a material set's name, such as al6063-t5 (got ${shown(b.material)})`);
48
+ const ends = it.from != null || it.to != null;
49
+ if (ends && (it.from == null || it.to == null)) throw new Error(`${what}: a beam placed by its ends gives both: from (end a) and to (end b)`);
50
+ if (ends && (it.at != null || it.rotate != null)) throw new Error(`${what}: a beam is placed by its ends (from, to, roll) or by at and rotate, not both`);
51
+ if (!ends && it.roll != null) throw new Error(`${what}: roll turns a beam placed by its ends: give from and to, or turn it with rotate`);
52
+ if (ends && it.repeat) throw new Error(`${what}: a beam placed by its ends is one beam: give each its own item, or place it with at and repeat`);
53
+ for (const k of ['from', 'to']) if (ends && !(Array.isArray(it[k]) && it[k].length === 3)) throw new Error(`${what}: ${k} is a point, [x, y, z] (got ${shown(it[k])})`);
54
+ const span = ends ? Math.hypot(...[0, 1, 2].map((i) => num(it.to[i]) - num(it.from[i]))) : null;
55
+ if (b.length == null && span == null) throw new Error(`${what}: give the beam a length, or place it by its ends (from and to) so the length is theirs`);
56
+ const length = b.length != null ? num(b.length) : span;
57
+ if (!(Number.isFinite(length) && length > 0)) throw new Error(`${what}: a beam's length is above 0 mm (got ${shown(b.length ?? length)}${b.length == null ? ': its ends are at one point' : ''})`);
58
+ if (span != null && Math.abs(span - length) > 1e-3) throw new Error(`${what}: its length is ${mm(length)} mm, and its ends are ${mm(span)} mm apart: leave the length out, or move an end`);
59
+ const given = givenFor(context, b.profile);
60
+ let model;
61
+ try {
62
+ model = beamModel(frames.profileModel(b.profile, {}, given), { length, ...(b.material ? { material: b.material } : {}), ...(ops.length ? { ops } : {}), given });
63
+ } catch (e) { throw new Error(`${what}: ${strip(e)}`); }
64
+ return { model, length };
65
+ }
66
+
67
+ /**
68
+ * Where a beam placed by its ends goes: its frame as 12 numbers by rows (z from end a to end b, top up, turned by roll),
69
+ * or null for a beam placed by at and rotate.
70
+ * @param {object} it @param {(x: any) => number} num @returns {number[] | null}
71
+ */
72
+ export function beamPlace(it, num) {
73
+ if (it.from == null) return null;
74
+ const a = it.from.map(num), b = it.to.map(num), z = b.map((v, k) => v - a[k]), l = Math.hypot(...z), u = z.map((v) => v / l);
75
+ const up = Math.abs(u[2]) > Math.cos(0.1 * Math.PI / 180) ? [0, 1, 0] : [0, 0, 1], d = up[0] * u[0] + up[1] * u[1] + up[2] * u[2];
76
+ const yl = up.map((v, k) => v - d * u[k]), n = Math.hypot(...yl), y = yl.map((v) => v / n);
77
+ const x = [y[1] * u[2] - y[2] * u[1], y[2] * u[0] - y[0] * u[2], y[0] * u[1] - y[1] * u[0]]; // y × z
78
+ const r = (it.roll != null ? num(it.roll) : 0) * Math.PI / 180, c = Math.cos(r), s = Math.sin(r);
79
+ return frame(a, u, x.map((v, k) => c * v + s * y[k]));
80
+ }
81
+
82
+ /**
83
+ * An item with "beam", built as a bought reference: its preview solid as the part, its envelope for the overlap check,
84
+ * its named anchors (ends, end bores, faces at mid-length) for joints and fits, and its figures as values (x1.length).
85
+ * @param {object} it @param {(x: any) => number} num @param {string} id
86
+ */
87
+ export function beamBuilt(it, num, id, context = framesContext()) {
88
+ const { model: m, length } = beamOf(it, num, context);
89
+ const meta = { body: { label: `${m.profile.name} x ${mm(length)} mm` } };
90
+ const parts = named({ body: beam(m) }, meta), link = named({ body: beam(m, { display: 'link' }) }, meta)[0];
91
+ parts[0].collide = link.geometry; // (the overlap check measures the envelope: light, and a beam's slots hold nothing else)
92
+ const anchors = Object.fromEntries(Object.entries(m.anchors).map(([k, a]) => [k, { at: a.origin, axis: a.axis, ref: a.ref }]));
93
+ const values = { length, width: m.profile.width, height: m.profile.height, area: m.area, ...(m.mass != null ? { mass: m.mass } : {}) };
94
+ const entries = Object.entries(m.profile.figures).filter(([, f]) => typeof f?.value === 'number').map(([k, f]) => ({ name: `${m.profile.name}.${k}`, value: f.value, unit: f.unit, rule: f.rule, kind: f.kind, source: f.source, checked: f.checked, set: m.profile.name }));
95
+ const grams = m.weight.sheet ?? m.mass; // (weighed by the sheet where it gives a mass per metre: a light section's drawn outline can be 10 to 20% heavy)
96
+ return referenceBuilt({ id, key: 'beam', objName: `beam:${m.profile.name}`, name: m.profile.name, parts, anchors, entries, values,
97
+ extra: { beam: m, bought: { set: m.profile.name, variant: null, part: 'beam', mass: grams != null ? grams / 1000 : null, length } } });
98
+ }
99
+
100
+ /**
101
+ * An anchor on a beam by its address (a, b, a.1, top, top@120, top@-20, top@50%, top.2@120), as a frame of 12 numbers in
102
+ * the beam's own frame. Past the beam's end, or a name it does not have: refused by name, with its length.
103
+ * @param {object} m the beam's model @param {string} address what follows the item's id @param {string} what who asks
104
+ */
105
+ export function beamAddress(m, address, what) {
106
+ let a;
107
+ try { a = beamAnchor(m, address); } catch (e) { throw new Error(`${what}: ${strip(e)}`); }
108
+ return frame(a.origin, a.axis, a.ref);
109
+ }
110
+
111
+ /** The assembly's beams, nested ones too, as { id, beam } for @rulecad/frames' cut list. @param {object} s a built assembly */
112
+ export const beamsIn = (s) => s.objects.filter((o) => o.beam && !o.unplaced).map((o) => ({ id: o.id, beam: o.beam }));
113
+
114
+ /** Each beam's mark: beams that are the same share one (A, B, ...), as the cut list and the sheets name them. @returns {Map<string, string>} item to mark */
115
+ export function marksOf(objects) {
116
+ const list = objects.filter((o) => o.beam && !o.unplaced), out = new Map();
117
+ if (list.length) for (const m of beamMarks(list.map((o) => ({ id: o.id, beam: o.beam })))) for (const id of m.items) out.set(id, m.mark);
118
+ return out;
119
+ }
120
+
121
+ /** The cut list of an assembly's beams (frames' cutList), or null where it has none. @param {object} s a built assembly */
122
+ export function cutListOf(s) { const b = beamsIn(s); return b.length ? cutList(b) : null; }
123
+
124
+ /** The cut list as the list and the build page keep it: no beam models, the numbers and words only. */
125
+ export const cutListData = (c) => c && { marks: c.marks.map(({ beam, ...m }) => m), stock: c.stock, totals: c.totals, rules: Object.fromEntries(Object.entries(c.rules).map(([k, r]) => [k, { value: r.value, unit: r.unit, kind: r.kind }])) };
126
+
127
+ /** The sheet files cad beams writes for an assembly, by mark: exports/<project>/<assembly>.beam-<mark>.svg */
128
+ export const sheetFile = (s, mark) => paths.exports(s.project, `${s.name}.beam-${mark}.svg`);
129
+
130
+ /**
131
+ * One cut-and-drill sheet per mark, written to exports/<project>/<assembly>.beam-<mark>.svg, old sheets of this
132
+ * assembly removed. @param {object} s a built assembly @returns {{ mark: string, file: string, items: string[], scale: number }[]}
133
+ */
134
+ export function writeBeamSheets(s) {
135
+ const c = cutListOf(s), dir = paths.exports(s.project), base = `${s.name}.beam-`;
136
+ if (fs.existsSync(dir)) for (const f of fs.readdirSync(dir)) if (f.startsWith(base) && f.endsWith('.svg')) fs.rmSync(path.join(dir, f));
137
+ if (!c) return [];
138
+ fs.mkdirSync(dir, { recursive: true });
139
+ return c.marks.map((m) => { const sh = beamSheet(m.beam, { mark: m.mark, items: m.items, grams: m.grams }), file = sheetFile(s, m.mark); fs.writeFileSync(file, sh.svg); return { mark: m.mark, file, items: m.items, scale: sh.scale }; });
140
+ }
141
+
142
+ /** Each beam's own findings (its mass beside the sheet's, its length beside the stock's), named by item; and the cut list's (frame.cut). */
143
+ export function beamFindings(s, f) {
144
+ for (const o of s.objects) if (o.beam && !o.unplaced) for (const x of o.beam.findings) f(x.level, `${o.id}: ${x.text}`, null, { code: x.code, ...(x.values ? { values: x.values } : {}), refs: { item: o.id, profile: o.beam.profile.name, length: o.beam.length, ...(x.rule ? { rule: x.rule } : {}) } });
145
+ const c = cutListOf(s);
146
+ if (c) for (const x of c.findings) f(x.level, x.text, null, { code: x.code, ...(x.values ? { values: x.values } : {}), refs: x.refs });
147
+ }
package/lib/bought.mjs CHANGED
@@ -101,5 +101,5 @@ export function boughtBuilt(spec, it, num, id) {
101
101
 
102
102
  // One line in the check for each bought item, so the shopping list and the wiring can read it
103
103
  export function boughtFindings(s, f) {
104
- for (const o of s.objects) if (o.bought) f('info', `${o.id}: ${o.bought.set}${o.bought.variant ? ` (${o.bought.variant})` : ''}, a ${o.bought.part}`, null, { code: 'bought.item', refs: { item: o.id, set: o.bought.set, variant: o.bought.variant, part: o.bought.part } });
104
+ for (const o of s.objects) if (o.bought) f('info', `${o.id}: ${o.bought.set}${o.bought.variant ? ` (${o.bought.variant})` : ''}${o.bought.length != null ? ` x ${Number(o.bought.length.toFixed(2))} mm` : ''}, a ${o.bought.part}`, null, { code: 'bought.item', refs: { item: o.id, set: o.bought.set, variant: o.bought.variant, part: o.bought.part, ...(o.bought.length != null ? { length: o.bought.length } : {}) } });
105
105
  }
package/lib/buildpage.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // What a machine's model link adds to the model, all read from the same assembly the checks read: the task (the pen, the
2
- // plane, the margins' figures), a step file, the wires' routes, and the build page (shopping list, plates, wiring sheet,
3
- // assembly steps, machine settings).
2
+ // plane, the margins' figures), a step file, the wires' routes, and the build page (shopping list with the beams' cut
3
+ // list, each beam's cut-and-drill sheet, plates, wiring sheet, assembly steps, machine settings).
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import { sheetFrame } from '@rulecad/robots';
@@ -10,6 +10,7 @@ import { host } from './host.mjs';
10
10
  import { accuracyOf, sample, chainOf } from './task.mjs';
11
11
  import { machineOf } from './machine.mjs';
12
12
  import { shoppingList } from './list.mjs';
13
+ import { cutListOf, sheetFile } from './beams.mjs';
13
14
  import { wiresFor, wireRoutesOf } from './assembly.mjs';
14
15
  import { orderOf, isBuilt } from './order.mjs';
15
16
  import { platesOf } from './plates.mjs';
@@ -61,7 +62,9 @@ export async function buildData(s) {
61
62
  const plates = await guard(() => platesOf(s).then(({ bed, gap, plates: p, findings }) => ({ bed, gap, plates: p, findings })));
62
63
  const order = isBuilt(s) ? await guard(() => orderOf(s)) : null;
63
64
  const machine = s.task ? await guard(() => machineOf(s)) : null;
64
- return { build: { list, wires, plates, order, machine } };
65
+ // each mark's cut-and-drill sheet, by its file in the exports (cad beams writes them), and whether it is there yet
66
+ const beams = await guard(() => { const c = cutListOf(s); return c ? { sheets: c.marks.map((m) => ({ mark: m.mark, items: m.items, file: ['exports', s.project, path.basename(sheetFile(s, m.mark))].join('/'), written: fs.existsSync(sheetFile(s, m.mark)) })) } : null; });
67
+ return { build: { list, wires, plates, order, machine, beams } };
65
68
  }
66
69
 
67
70
  // The ledger, in the rules sheet's own rows: each prediction the bench can measure, the measurement once it's in