@rulecad/cad 0.7.56 → 0.7.58

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/beams.mjs CHANGED
@@ -8,19 +8,23 @@
8
8
  // about its own axis, a toward b, right-handed.
9
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
10
  // x1.top@-20, x1.top@50%, x1.top.2@120.
11
+ // "printed": true (or { pose, walls, infill, end, pull }) makes it a printed part (@rulecad/frames printed beams): drawn
12
+ // solid, weighed by the plastic its walls and infill lay, on a plate laid as it prints ("laid": true, which cad plates
13
+ // writes), off the cut list; its findings say how it prints and what stops it.
11
14
  // Its operations ("ops": cut, mitre, tap, access, drill, counterbore, pocket, notch, deburr) are @rulecad/frames': each
12
15
  // is cut into its preview, a mitre into its envelope too, and their findings (beam.op) are the beam's.
13
16
  import * as frames from '@rulecad/frames';
14
17
  import fs from 'node:fs';
18
+ import crypto from 'node:crypto';
15
19
  import path from 'node:path';
16
- import { beamModel, beam, beamAnchor, cutList, beamMarks, beamSheet } from '@rulecad/frames';
20
+ import { beamModel, beam, beamAnchor, cutList, beamMarks, beamSheet, printedBeam, printedInPlace } from '@rulecad/frames';
17
21
  import { frame } from '@rulecad/model-link';
18
22
  import { RULE_DIRS, paths } from './workspace.mjs';
19
23
  import { named } from './parts.mjs';
20
24
  import { referenceBuilt } from './bought.mjs';
21
25
  import { framesContext as contextIn, givenFor } from './frames.mjs';
22
26
 
23
- const KEYS = ['profile', 'length', 'printed', 'material', 'ops'];
27
+ const KEYS = ['profile', 'length', 'printed', 'material', 'ops', 'laid'];
24
28
  const OP_NUMBERS = ['angle', 'depth', 'diameter', 'length', 'radius'];
25
29
  const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
26
30
  const mm = (x) => String(+Number(x).toFixed(2));
@@ -30,8 +34,8 @@ export const framesContext = () => contextIn(RULE_DIRS[0]);
30
34
 
31
35
  /**
32
36
  * 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.
37
+ * distance from from to to. Refused by name: an unknown key, no profile, printed neither true, false nor its options, a
38
+ * length that disagrees with its ends, ends and at both given.
35
39
  * @param {object} it the item @param {(x: any) => number} num the assembly's expressions @param {object} [context] framesContext()'s
36
40
  */
37
41
  export function beamOf(it, num, context = framesContext()) {
@@ -39,8 +43,8 @@ export function beamOf(it, num, context = framesContext()) {
39
43
  if (!b || typeof b !== 'object' || Array.isArray(b)) throw new Error(`${what}: beam is { "profile", "length", "material" } (got ${shown(b)})`);
40
44
  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
45
  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}`);
46
+ if (b.printed != null && typeof b.printed !== 'boolean' && (typeof b.printed !== 'object' || Array.isArray(b.printed))) throw new Error(`${what}: beam.printed is true, false, or how it prints: { "pose": "lying", "walls": 3, "infill": 0.4, "end": "insert" } (got ${shown(b.printed)})`);
47
+ if (b.laid != null && (typeof b.laid !== 'boolean' || (b.laid && !b.printed))) throw new Error(`${what}: beam.laid draws a printed beam as it prints: true or false, with printed (got ${shown(b.laid)}${b.printed ? '' : ' on a bought beam'})`);
44
48
  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
49
  // an operation's numbers may be expressions, as a length is
46
50
  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));
@@ -59,7 +63,7 @@ export function beamOf(it, num, context = framesContext()) {
59
63
  const given = givenFor(context, b.profile);
60
64
  let model;
61
65
  try {
62
- model = beamModel(frames.profileModel(b.profile, {}, given), { length, ...(b.material ? { material: b.material } : {}), ...(ops.length ? { ops } : {}), given });
66
+ model = beamModel(frames.profileModel(b.profile, {}, given), { length, ...(b.material ? { material: b.material } : {}), ...(ops.length ? { ops } : {}), ...(b.printed ? { printed: b.printed } : {}), given });
63
67
  } catch (e) { throw new Error(`${what}: ${strip(e)}`); }
64
68
  return { model, length };
65
69
  }
@@ -86,9 +90,10 @@ export function beamPlace(it, num) {
86
90
  */
87
91
  export function beamBuilt(it, num, id, context = framesContext()) {
88
92
  const { model: m, length } = beamOf(it, num, context);
93
+ if (m.printed) return printedBuilt(it, m, id);
89
94
  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)
95
+ const parts = named({ body: beam(m) }, meta), link = named({ body: beam(m, { display: 'link', tracks: true }) }, meta)[0];
96
+ parts[0].collide = link.geometry; // (the overlap check measures the envelope, light, less any V tracks: a V-wheel's rim runs in them, and a rim out of them hits the beam)
92
97
  const anchors = Object.fromEntries(Object.entries(m.anchors).map(([k, a]) => [k, { at: a.origin, axis: a.axis, ref: a.ref }]));
93
98
  const values = { length, width: m.profile.width, height: m.profile.height, area: m.area, ...(m.mass != null ? { mass: m.mass } : {}) };
94
99
  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 }));
@@ -97,6 +102,31 @@ export function beamBuilt(it, num, id, context = framesContext()) {
97
102
  extra: { beam: m, bought: { set: m.profile.name, variant: null, part: 'beam', mass: grams != null ? grams / 1000 : null, length } } });
98
103
  }
99
104
 
105
+ // A printed beam, built: a printed part, solid, in its place (or laid as it prints, for a plate), its part's fill the share
106
+ // of its section the walls and infill lay (cad list weighs it by that), its anchors and figures as a bought beam's
107
+ function printedBuilt(it, m, id) {
108
+ const sec = m.printed.section, laid = !!it.beam.laid, label = `${m.profile.name} x ${mm(m.length)} mm, printed ${m.printed.pose === 'lying' ? 'lying down' : 'standing up'}`;
109
+ const parts = named({ body: laid ? printedBeam(m) : printedInPlace(m) }, { body: { label } }); // (in its place, its ends' inserts or nuts cut in, as a screw into them is checked)
110
+ parts[0].fill = +(sec.plastic / sec.solid.area).toFixed(4);
111
+ if (!laid) parts[0].collide = named({ body: printedInPlace(m, { display: 'link' }) }, { body: { label } })[0].geometry;
112
+ const anchors = laid ? {} : Object.fromEntries(Object.entries(m.anchors).map(([k, a]) => [k, { at: a.origin, axis: a.axis, ref: a.ref }]));
113
+ const values = { length: m.length, width: m.profile.width, height: m.profile.height, grams: m.mass, design: m.printed.design };
114
+ const entries = Object.entries(m.figures).filter(([, f]) => typeof f?.value === 'number').map(([k, f]) => ({ name: `${m.profile.name}.printed.${k}`, value: f.value, unit: f.unit, rule: `The printed beam's ${k}, from its walls and infill`, kind: f.kind, source: f.source, checked: '2026-11-17', set: m.profile.name }));
115
+ const hash = crypto.createHash('sha256').update(JSON.stringify([it.beam, m.name, m.mass, laid])).digest('hex').slice(0, 16);
116
+ const b = { object: { name: m.name, title: label, role: 'part', version: '0.0.0', anchors }, values, entries, deps: [], units: {}, parts, polygons: parts.flatMap((p) => p.polygons), triangles: parts.flatMap((p) => p.triangles), hash };
117
+ return { key: `beam:${id}:${hash}`, objName: `beam:${m.profile.name}:printed`, b, version: '0.0.0', role: 'part', beam: m };
118
+ }
119
+
120
+ /**
121
+ * A printed beam's item as a plate takes it: its numbers worked out (the plate has none of the assembly's values), its
122
+ * length given (the plate places it by at), and laid as it prints.
123
+ * @param {object} it the assembly's item @param {(x: any) => number} num @param {number} length @returns {object} the plate item's beam
124
+ */
125
+ export function laidSpec(it, num, length) {
126
+ const { profile, printed, material, ops } = it.beam;
127
+ return { profile, length, printed, ...(material ? { material } : {}), ...(ops?.length ? { ops: ops.map((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]))) } : {}), laid: true };
128
+ }
129
+
100
130
  /**
101
131
  * 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
132
  * the beam's own frame. Past the beam's end, or a name it does not have: refused by name, with its length.
@@ -108,18 +138,21 @@ export function beamAddress(m, address, what) {
108
138
  return frame(a.origin, a.axis, a.ref);
109
139
  }
110
140
 
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 }));
141
+ /** The assembly's bought beams, nested ones too, as { id, beam } for @rulecad/frames' cut list. @param {object} s a built assembly */
142
+ export const beamsIn = (s) => s.objects.filter((o) => o.beam && !o.beam.printed && !o.unplaced).map((o) => ({ id: o.id, beam: o.beam })); // (a printed beam is printed, not cut)
113
143
 
114
144
  /** 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
145
  export function marksOf(objects) {
116
- const list = objects.filter((o) => o.beam && !o.unplaced), out = new Map();
146
+ const list = objects.filter((o) => o.beam && !o.beam.printed && !o.unplaced), out = new Map();
117
147
  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
148
  return out;
119
149
  }
120
150
 
121
151
  /** 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; }
152
+ export function cutListOf(s) {
153
+ const b = beamsIn(s), t = s.a?.frame?.cut?.tolerance;
154
+ return b.length ? cutList(b, t != null && Number.isFinite(s.num(t)) && s.num(t) >= 0 ? { tolerance: s.num(t) } : {}) : null; // (the workshop's own tolerance, frame.cut; refused by name in frame.square)
155
+ }
123
156
 
124
157
  /** The cut list as the list and the build page keep it: no beam models, the numbers and words only. */
125
158
  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 }])) };
package/lib/bought.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // Bought parts in assemblies: a bearing, a switch, a driver, a board or a supply named by its rule set, drawn from the
1
+ // Bought parts in assemblies: a bearing, a switch, a driver, a board, a supply or a frame's fitting named by its rule set, drawn from the
2
2
  // set's figures as a faint reference (never on a plate), with anchors from what it is. A motor is the same thing with a
3
3
  // shaft that turns a joint, so its item is built here too (lib/motors.mjs).
4
4
  import crypto from 'node:crypto';
@@ -7,6 +7,7 @@ import jscad from '@jscad/modeling';
7
7
  import { peekRuleSet as loadRuleSet } from './rules.mjs';
8
8
  import { RULE_DIRS } from './workspace.mjs';
9
9
  import { named } from './parts.mjs';
10
+ import { boughtFittingModel, boughtFitting } from '@rulecad/frames';
10
11
 
11
12
  const { cuboid, cylinder, polygon } = jscad.primitives, { translate } = jscad.transforms, { union, subtract } = jscad.booleans, { extrudeRotate } = jscad.extrusions;
12
13
  const SEG = 48;
@@ -47,11 +48,14 @@ const SHAPES = {
47
48
  return { parts: { body, lever: box(w, Math.min(4, d), 0.4, w * 0.1, 0, h + 2) }, anchors: { lever: z([w * 0.6, 0, h + 2]), left: z([-holes, 0, up], [0, 1, 0]), right: z([holes, 0, up], [0, 1, 0]), base: z([0, 0, 0]) } };
48
49
  },
49
50
  board(v, set) {
50
- const w = v.body_width, d = v.body_depth, t = 1.6;
51
+ const w = v.body_width, d = v.body_depth, t = v.board_thickness ?? 1.6;
51
52
  const axes = [...new Set(Object.keys(set.rules).map((k) => /^step_pin_(\w+)$/.exec(k)?.[1]).filter(Boolean))].map((a) => a.toUpperCase());
52
53
  // Where a board's axis connectors are along its edge is for routing a wire, no closer than that
53
54
  const sockets = Object.fromEntries(axes.map((a, i) => [a, z([-w / 2 + ((i + 0.5) * w) / axes.length, d / 2, t], [0, 1, 0])]));
54
- return { parts: { body: box(w, d, t) }, anchors: { centre: z([0, 0, t / 2]), top: z([0, 0, t]), bottom: z([0, 0, 0]), ...sockets } };
55
+ // its mounting holes, where its set gives them, drawn through it so a screw's clearance is measured in them
56
+ const flat = set.rules.mount_holes?.value, holes = Array.isArray(flat) && v.mount_hole_diameter ? Array.from({ length: Math.floor(flat.length / 2) }, (_, i) => [flat[2 * i], flat[2 * i + 1]]) : [];
57
+ const body = holes.length ? subtract(box(w, d, t), ...holes.map(([x, y]) => translate([x, y, t / 2], cylinder({ radius: v.mount_hole_diameter / 2, height: t + 2, segments: 32 })))) : box(w, d, t);
58
+ return { parts: { body }, anchors: { centre: z([0, 0, t / 2]), top: z([0, 0, t]), bottom: z([0, 0, 0]), ...sockets } };
55
59
  },
56
60
  driver(v) {
57
61
  const w = v.body_width, d = v.body_depth, t = 1.6, row = v.row_spacing / 2, pins = v.pin_count / 2, pitch = v.pin_pitch, run = pitch * (pins - 1), pin = 0.64, drop = 8;
@@ -64,6 +68,14 @@ const SHAPES = {
64
68
  return { parts: { body: extrudeRotate({ segments: SEG }, polygon({ points: [[r + c, 0], [R - c, 0], [R, c], [R, L - c], [R - c, L], [r + c, L], [r, L - c], [r, c]] })) }, anchors: { bore: z([0, 0, L / 2]), face: z([0, 0, 0]), top: z([0, 0, L]) } };
65
69
  },
66
70
  rod(v) { return { parts: { body: translate([0, 0, v.length / 2], cylinder({ radius: v.diameter / 2, height: v.length, segments: SEG })) }, anchors: { bottom: z([0, 0, 0]), top: z([0, 0, v.length]) } }; },
71
+ // a bought fitting for a frame (@rulecad/frames' bought.mjs): drawn in the printed fittings' frames, an anchor on
72
+ // each screw's axis at its head's seat (b1, b2 .. into b; a1 .. into a); one that lies in the slots (an inner or an
73
+ // anchor connector) is inside the beams by design, so the overlap check leaves it out
74
+ fitting(v, set) {
75
+ const m = boughtFittingModel({ name: set.name, part: 'fitting', rules: set.rules }), count = { a: 0, b: 0 };
76
+ const anchors = Object.fromEntries(m.screws.map((q) => [`${q.leg}${++count[q.leg]}`, z(q.at, q.axis.map((c) => (c ? -c : 0)))]));
77
+ return { parts: { body: boughtFitting(m, { pose: 'fit' }) }, anchors: { origin: z([0, 0, 0]), ...anchors }, inside: ['hidden', 'anchor'].includes(m.fitting), model: m };
78
+ },
67
79
  supply(v) {
68
80
  const w = v.body_width, d = v.body_depth, h = v.body_length;
69
81
  return { parts: { body: box(w, d, h) }, anchors: { base: z([0, 0, 0]), top: z([0, 0, h]), terminals: z([0, -d / 2, h / 2], [0, -1, 0]) } };
@@ -78,7 +90,8 @@ export function boughtModel(name, variant) {
78
90
  if (variant != null) {
79
91
  const vs = set.variants || {};
80
92
  if (!vs[variant]) throw new Error(`${name} has no variant "${variant}" (${Object.keys(vs).join(', ') || 'none'})`);
81
- rules = { ...set.rules, ...Object.fromEntries(Object.entries(vs[variant].values ?? {}).map(([k, value]) => [k, { ...set.rules[k], value, kind: vs[variant].kind ?? set.rules[k]?.kind, source: vs[variant].source ?? set.rules[k]?.source }])) };
93
+ // (its values take the variant's kind and source; its rules, where it has them, are whole rules with their own)
94
+ rules = { ...set.rules, ...Object.fromEntries(Object.entries(vs[variant].values ?? {}).map(([k, value]) => [k, { ...set.rules[k], value, kind: vs[variant].kind ?? set.rules[k]?.kind, source: vs[variant].source ?? set.rules[k]?.source }])), ...(vs[variant].rules ?? {}) };
82
95
  }
83
96
  return { name, part: set.part, variant: variant ?? null, rules };
84
97
  }
@@ -95,11 +108,34 @@ export function boughtBuilt(spec, it, num, id) {
95
108
  const missing = Object.entries(shape.anchors).filter(([, a]) => a.at.some((c) => !Number.isFinite(c))).map(([k]) => k);
96
109
  if (missing.length) throw new Error(`item ${id}: ${spec}: its rules don't place the anchors ${missing.join(', ')}`);
97
110
  const parts = named(shape.parts, Object.fromEntries(Object.keys(shape.parts).map((k) => [k, { label: `${m.name} ${k}` }])));
111
+ if (shape.inside) parts[0].collide = jscad.geometries.geom3.create(); // (in the slots, inside the beams by design)
98
112
  const entries = Object.entries(m.rules).map(([k, r]) => ({ name: `${m.name}.${k}`, value: r.value, unit: r.unit, rule: r.rule, kind: r.kind, source: r.source, checked: r.checked, set: m.name }));
99
- return referenceBuilt({ id, key: 'bought', objName: `bought:${m.name}`, name: m.name, parts, anchors: shape.anchors, entries, values, extra: { bought: { set: m.name, variant: m.variant, part: m.part, mass: values.mass ?? null } } });
113
+ return referenceBuilt({ id, key: 'bought', objName: `bought:${m.name}`, name: m.name, parts, anchors: shape.anchors, entries, values, extra: { bought: { set: m.name, variant: m.variant, part: m.part, mass: values.mass ?? null, mount: mountOf(m), ...(m.rules.cost ? { cost: { value: m.rules.cost.value, unit: m.rules.cost.unit } } : {}), ...(shape.model ? { fitting: shape.model } : {}) } } });
114
+ }
115
+
116
+ /**
117
+ * A bought part's mounting holes from its rules (mount_holes: x then y for each), as a printed mount and the fasten checks read them: { holes ([[x, y], ...]), thread,
118
+ * reach, diameter, thickness, face }, or null where its set gives none. A thread means tapped holes (a supply's), a
119
+ * diameter plain ones (a board's). @param {{ name: string, part: string, rules: object }} m boughtModel's
120
+ */
121
+ export function mountOf(m) {
122
+ const r = m.rules, flat = r.mount_holes?.value; // (x then y for each hole, as the vocabulary keeps a list)
123
+ if (!Array.isArray(flat) || !flat.length || flat.length % 2) return null;
124
+ const holes = Array.from({ length: flat.length / 2 }, (_, i) => [flat[2 * i], flat[2 * i + 1]]);
125
+ return { set: m.name, holes, thread: typeof r.mount_hole_thread?.value === 'string' ? r.mount_hole_thread.value : null, reach: r.mount_hole_reach?.value ?? null, diameter: r.mount_hole_diameter?.value ?? null,
126
+ thickness: m.part === 'board' ? r.board_thickness?.value ?? 1.6 : null, body: [r.body_width?.value, r.body_depth?.value], height: m.part === 'board' ? r.board_thickness?.value ?? 1.6 : r.body_length?.value ?? null, kind: r.mount_holes.kind, source: r.mount_holes.source };
100
127
  }
101
128
 
102
129
  // One line in the check for each bought item, so the shopping list and the wiring can read it
103
130
  export function boughtFindings(s, f) {
131
+ // a frame's bought fitting placed at a beam's address (an end cap at x1.a, a foot, a hinge on a face): does it fit
132
+ // that beam's profile (its size, its slot family, a foot's stem against the end's bore)
133
+ const items = new Map((s.a?.items ?? []).map((it) => [it.id, it]));
134
+ for (const o of s.objects) if (o.bought?.fitting && !o.unplaced && items.get(o.id)?.join == null) {
135
+ const at = items.get(o.id)?.at, beam = typeof at === 'string' ? s.objects.find((x) => x.id === at.trim().split('.')[0])?.beam : null;
136
+ if (!beam) continue;
137
+ for (const x of boughtFittingModel(o.bought.fitting.set, { profile: beam.profile, ...(s.frames ? { given: s.frames } : {}) }).findings.filter((y) => y.code === 'fitting.fit'))
138
+ f(x.level, `${o.id}: ${x.text}`, x.level === 'fail' ? `${o.id}: fit` : null, { code: x.code, ...(x.values ? { values: x.values } : {}), refs: { item: o.id, beam: beam.name, ...x.refs } });
139
+ }
104
140
  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
141
  }
package/lib/buildpage.mjs CHANGED
@@ -1,6 +1,7 @@
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
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).
3
+ // list, each beam's cut-and-drill sheet, plates, wiring sheet, assembly steps, a frame's build from bars to square,
4
+ // machine settings).
4
5
  import fs from 'node:fs';
5
6
  import path from 'node:path';
6
7
  import { sheetFrame } from '@rulecad/robots';
@@ -13,6 +14,8 @@ import { shoppingList } from './list.mjs';
13
14
  import { cutListOf, sheetFile } from './beams.mjs';
14
15
  import { wiresFor, wireRoutesOf } from './assembly.mjs';
15
16
  import { orderOf, isBuilt } from './order.mjs';
17
+ import { withPreload } from './slotnuts.mjs';
18
+ import { frameBuild } from './framebuild.mjs';
16
19
  import { platesOf } from './plates.mjs';
17
20
  import { wiringSheet } from './wires.mjs';
18
21
  import { readLedger } from './measured.mjs';
@@ -60,11 +63,13 @@ export async function buildData(s) {
60
63
  const list = await guard(() => shoppingList(s));
61
64
  const wires = await guard(() => (s.wires?.length ? wiresFor(s).map(({ route, ...w }) => w) : null));
62
65
  const plates = await guard(() => platesOf(s).then(({ bed, gap, plates: p, findings }) => ({ bed, gap, plates: p, findings })));
63
- const order = isBuilt(s) ? await guard(() => orderOf(s)) : null;
66
+ const order = isBuilt(s) ? await guard(() => withPreload(s, orderOf(s))) : null; // (with the slot nuts to load before a join closes their slot)
64
67
  const machine = s.task ? await guard(() => machineOf(s)) : null;
65
68
  // each mark's cut-and-drill sheet, by its file in the exports (cad beams writes them), and whether it is there yet
66
69
  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 } };
70
+ const frame = s.joins?.length ? await guard(() => { const { steps, sides, notFlat, bays, torques, stuck } = frameBuild(s); return { steps, sides: sides.map((x) => ({ beams: x.beams, name: x.name })), notFlat, bays: bays.map((b) => ({ beams: b.beams, name: b.name, width: b.width, height: b.height, diagonal: b.square.diagonal, accept: b.square.accept, rss: b.square.rss, lean: b.square.lean, terms: b.square.terms })), torques, stuck }; }) : null; // (from bars to a square frame)
71
+ // a frame's build is its one sequence, from bars to square with the rest mounted: the assembly order is not shown beside it
72
+ return { build: { list, wires, plates, order: frame && !frame.error ? null : order, machine, beams, ...(frame ? { frame } : {}) } };
68
73
  }
69
74
 
70
75
  // The ledger, in the rules sheet's own rows: each prediction the bench can measure, the measurement once it's in
package/lib/edit.mjs CHANGED
@@ -58,18 +58,18 @@ const assemblyFile = (ref) => {
58
58
  };
59
59
 
60
60
  /**
61
- * Add to an assembly: a fit, a joint, an item, a loop or a fasten (appended to its list), or a pose (by name).
62
- * @param {string} ref project/assembly @param {'fit' | 'joint' | 'item' | 'loop' | 'fasten' | 'pose'} what @param {any} entry (a pose: { name, values })
61
+ * Add to an assembly: a fit, a joint, an item, a loop, a fasten or a join (appended to its list), or a pose (by name).
62
+ * @param {string} ref project/assembly @param {'fit' | 'joint' | 'item' | 'loop' | 'fasten' | 'join' | 'pose'} what @param {any} entry (a pose: { name, values })
63
63
  * @returns {{ file: string }}
64
64
  */
65
65
  export function addToAssembly(ref, what, entry) {
66
- const file = assemblyFile(ref), before = fs.readFileSync(file, 'utf8'), list = { fit: 'fits', joint: 'joints', item: 'items', loop: 'loops', fasten: 'fasten' }[what];
66
+ const file = assemblyFile(ref), before = fs.readFileSync(file, 'utf8'), list = { fit: 'fits', joint: 'joints', item: 'items', loop: 'loops', fasten: 'fasten', join: 'joins' }[what];
67
67
  let text = before;
68
68
  if (what === 'pose') {
69
69
  if (getAt(text, ['poses']) === undefined) text = setAt(text, ['poses'], {});
70
70
  text = setAt(text, ['poses', entry.name], entry.values);
71
71
  } else {
72
- if (!list) throw new CadError('edit.what', `can't add a ${what} (fit, joint, item, loop, fasten or pose)`);
72
+ if (!list) throw new CadError('edit.what', `can't add a ${what} (fit, joint, item, loop, fasten, join or pose)`);
73
73
  if (getAt(text, [list]) === undefined) text = setAt(text, [list], []);
74
74
  const ids = (getAt(text, [list]) || []).map((x) => x.id).filter(Boolean);
75
75
  if (entry.id && ids.includes(entry.id)) throw new CadError('edit.duplicate', `${ref} already has a ${what} "${entry.id}"`, { file });
@@ -92,6 +92,12 @@ export function addToAssembly(ref, what, entry) {
92
92
  if ((entry.at == null) === (entry.holes == null)) throw new CadError('edit.incomplete', 'a fasten needs where its screws go: --at bracket.h1,bracket.h2 (an anchor each) or --holes bracket.body (a part whose holes they use), one of the two', { file });
93
93
  for (const n of [...entry.through, entry.into, ...(entry.holes ? [entry.holes] : []), ...(entry.at || []).filter((x) => typeof x === 'string')]) if (!has(n)) throw new CadError('edit.part', `fasten: no item "${String(n).split(/[.@]/)[0]}" in ${ref} (items: ${items.join(', ') || 'none'})`, { file });
94
94
  }
95
+ // a join names a beam's end and a place on another beam: each must be a beam item of the assembly
96
+ if (what === 'join') {
97
+ const beams = (getAt(text, ['items']) || []).filter((x) => x.beam).map((x) => x.id);
98
+ if (!entry.kind || !entry.a || !entry.b) throw new CadError('edit.incomplete', 'a join needs its kind and the two beams: --kind blind --a y1.a --b x1.back@120', { file });
99
+ for (const side of ['a', 'b']) { const id = String(entry[side]).split('.')[0]; if (!beams.includes(id)) throw new CadError('edit.part', `join ${side}: no beam "${id}" in ${ref} (beams: ${beams.join(', ') || 'none'})`, { file }); }
100
+ }
95
101
  text = appendAt(text, [list], entry);
96
102
  }
97
103
  write(file, text, 'assembly');