@rulecad/cad 0.8.0 → 0.9.0
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/AGENTS.md +24 -10
- package/CHANGELOG.md +404 -0
- package/EXAMPLES.md +40 -38
- package/README.md +193 -67
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2250 -512
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1847 -434
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/design.mjs +649 -121
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +899 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2702 -507
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +100 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +81 -17
- package/lib/framesize.mjs +792 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +123 -21
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +438 -68
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +326 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +579 -130
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +417 -94
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1021 -213
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +3 -1
- package/lib/optimise.mjs +978 -283
- package/lib/order.mjs +519 -112
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +78 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +15 -5
- package/lib/sandbox-hooks.mjs +77 -19
- package/lib/sandbox-run.mjs +117 -18
- package/lib/sandbox.mjs +509 -60
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +851 -178
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +111 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +197 -12
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
package/lib/bought.mjs
CHANGED
|
@@ -6,25 +6,50 @@ import fs from 'node:fs';
|
|
|
6
6
|
import jscad from '@jscad/modeling';
|
|
7
7
|
import { peekRuleSet as loadRuleSet } from './rules.mjs';
|
|
8
8
|
import { RULE_DIRS } from './workspace.mjs';
|
|
9
|
+
import { readJson } from './host.mjs';
|
|
9
10
|
import { named } from './parts.mjs';
|
|
10
11
|
import { boughtFittingModel, boughtFitting } from '@rulecad/frames';
|
|
11
12
|
|
|
12
|
-
const { cuboid, cylinder, polygon } = jscad.primitives,
|
|
13
|
+
const { cuboid, cylinder, polygon } = jscad.primitives,
|
|
14
|
+
{ translate } = jscad.transforms,
|
|
15
|
+
{ union, subtract } = jscad.booleans,
|
|
16
|
+
{ extrudeRotate } = jscad.extrusions;
|
|
13
17
|
const SEG = 48;
|
|
14
18
|
|
|
15
19
|
// Rule sets that are bought parts, for saying what there is
|
|
16
20
|
export function boughtSets() {
|
|
17
21
|
const out = new Map();
|
|
18
|
-
for (const d of RULE_DIRS)
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
for (const d of RULE_DIRS)
|
|
23
|
+
if (fs.existsSync(d))
|
|
24
|
+
for (const f of fs.readdirSync(d)) {
|
|
25
|
+
if (!f.endsWith('.json') || f === 'vocabulary.json' || f === 'package.json') continue;
|
|
26
|
+
try {
|
|
27
|
+
const set = readJson(`${d}/${f}`);
|
|
28
|
+
if (set.part && !out.has(set.name)) out.set(set.name, set.part);
|
|
29
|
+
} catch {
|
|
30
|
+
// (a rule set that can't be read is cad rules check's to name: here it is just not a bought part)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
return out;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
// A reference item the assembly can place, from its parts, anchors and figures: what a motor and any bought part share
|
|
26
37
|
export function referenceBuilt({ id, key, objName, name, parts, anchors, entries, values, extra = {} }) {
|
|
27
|
-
const b = {
|
|
38
|
+
const b = {
|
|
39
|
+
object: { name, title: name, role: 'reference', version: '0.0.0', anchors },
|
|
40
|
+
values,
|
|
41
|
+
entries,
|
|
42
|
+
deps: [],
|
|
43
|
+
units: {},
|
|
44
|
+
parts,
|
|
45
|
+
polygons: parts.flatMap((p) => p.polygons),
|
|
46
|
+
triangles: parts.flatMap((p) => p.triangles),
|
|
47
|
+
hash: crypto
|
|
48
|
+
.createHash('sha256')
|
|
49
|
+
.update(JSON.stringify([values, entries.map((e) => e.name)]))
|
|
50
|
+
.digest('hex')
|
|
51
|
+
.slice(0, 16),
|
|
52
|
+
};
|
|
28
53
|
return { key: `${key}:${id}:${b.hash}`, objName, b, version: '0.0.0', role: 'reference', ...extra };
|
|
29
54
|
}
|
|
30
55
|
|
|
@@ -33,52 +58,185 @@ const box = (w, d, h, x = 0, y = 0, z0 = 0) => translate([x, y, z0 + h / 2], cub
|
|
|
33
58
|
|
|
34
59
|
// What each kind of part looks like, from its figures. Each returns { parts: { name: solid }, anchors }
|
|
35
60
|
const SHAPES = {
|
|
36
|
-
bearing(v
|
|
37
|
-
const r = v.bore / 2,
|
|
38
|
-
|
|
61
|
+
bearing(v) {
|
|
62
|
+
const r = v.bore / 2,
|
|
63
|
+
R = v.outer_diameter / 2,
|
|
64
|
+
w = v.width,
|
|
65
|
+
c = Math.min(v.chamfer ?? 0.2, (R - r) / 4, w / 4);
|
|
66
|
+
const flange = v.flange_diameter ? v.flange_diameter / 2 : 0,
|
|
67
|
+
f = v.flange_width ?? 0;
|
|
39
68
|
const pts = flange
|
|
40
|
-
? [
|
|
41
|
-
|
|
42
|
-
|
|
69
|
+
? [
|
|
70
|
+
[r + c, 0],
|
|
71
|
+
[R - c, 0],
|
|
72
|
+
[R, c],
|
|
73
|
+
[R, w - f],
|
|
74
|
+
[flange, w - f],
|
|
75
|
+
[flange, w],
|
|
76
|
+
[r + c, w],
|
|
77
|
+
[r, w - c],
|
|
78
|
+
[r, c],
|
|
79
|
+
]
|
|
80
|
+
: [
|
|
81
|
+
[r + c, 0],
|
|
82
|
+
[R - c, 0],
|
|
83
|
+
[R, c],
|
|
84
|
+
[R, w - c],
|
|
85
|
+
[R - c, w],
|
|
86
|
+
[r + c, w],
|
|
87
|
+
[r, w - c],
|
|
88
|
+
[r, c],
|
|
89
|
+
];
|
|
90
|
+
return {
|
|
91
|
+
parts: { body: extrudeRotate({ segments: SEG }, polygon({ points: pts })) },
|
|
92
|
+
anchors: { bore: z([0, 0, w / 2]), outer: z([0, 0, w / 2]), face: z([0, 0, 0]), top: z([0, 0, w]) },
|
|
93
|
+
};
|
|
43
94
|
},
|
|
44
95
|
switch(v) {
|
|
45
|
-
const w = v.body_width,
|
|
46
|
-
|
|
96
|
+
const w = v.body_width,
|
|
97
|
+
d = v.body_depth,
|
|
98
|
+
h = v.body_length,
|
|
99
|
+
holes = (v.mount_hole_spacing ?? 0) / 2,
|
|
100
|
+
up = h / 2;
|
|
101
|
+
const pin = (x) =>
|
|
102
|
+
translate(
|
|
103
|
+
[x, 0, up],
|
|
104
|
+
jscad.transforms.rotateX(
|
|
105
|
+
Math.PI / 2,
|
|
106
|
+
cylinder({ radius: (v.mount_hole_diameter ?? 2.4) / 2, height: d + 2, segments: 24 }),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
47
109
|
const body = holes ? subtract(box(w, d, h), pin(-holes), pin(holes)) : box(w, d, h);
|
|
48
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
parts: { body, lever: box(w, Math.min(4, d), 0.4, w * 0.1, 0, h + 2) },
|
|
112
|
+
anchors: {
|
|
113
|
+
lever: z([w * 0.6, 0, h + 2]),
|
|
114
|
+
left: z([-holes, 0, up], [0, 1, 0]),
|
|
115
|
+
right: z([holes, 0, up], [0, 1, 0]),
|
|
116
|
+
base: z([0, 0, 0]),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
49
119
|
},
|
|
50
120
|
board(v, set) {
|
|
51
|
-
const w = v.body_width,
|
|
52
|
-
|
|
121
|
+
const w = v.body_width,
|
|
122
|
+
d = v.body_depth,
|
|
123
|
+
t = v.board_thickness ?? 1.6;
|
|
124
|
+
const axes = [
|
|
125
|
+
...new Set(
|
|
126
|
+
Object.keys(set.rules)
|
|
127
|
+
.map((k) => /^step_pin_(\w+)$/.exec(k)?.[1])
|
|
128
|
+
.filter(Boolean),
|
|
129
|
+
),
|
|
130
|
+
].map((a) => a.toUpperCase());
|
|
53
131
|
// Where a board's axis connectors are along its edge is for routing a wire, no closer than that
|
|
54
|
-
const sockets = Object.fromEntries(
|
|
132
|
+
const sockets = Object.fromEntries(
|
|
133
|
+
axes.map((a, i) => [a, z([-w / 2 + ((i + 0.5) * w) / axes.length, d / 2, t], [0, 1, 0])]),
|
|
134
|
+
);
|
|
55
135
|
// 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,
|
|
57
|
-
|
|
58
|
-
|
|
136
|
+
const flat = set.rules.mount_holes?.value,
|
|
137
|
+
holes =
|
|
138
|
+
Array.isArray(flat) && v.mount_hole_diameter
|
|
139
|
+
? Array.from({ length: Math.floor(flat.length / 2) }, (_, i) => [flat[2 * i], flat[2 * i + 1]])
|
|
140
|
+
: [];
|
|
141
|
+
const body = holes.length
|
|
142
|
+
? subtract(
|
|
143
|
+
box(w, d, t),
|
|
144
|
+
...holes.map(([x, y]) =>
|
|
145
|
+
translate([x, y, t / 2], cylinder({ radius: v.mount_hole_diameter / 2, height: t + 2, segments: 32 })),
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
: box(w, d, t);
|
|
149
|
+
return {
|
|
150
|
+
parts: { body },
|
|
151
|
+
anchors: { centre: z([0, 0, t / 2]), top: z([0, 0, t]), bottom: z([0, 0, 0]), ...sockets },
|
|
152
|
+
};
|
|
59
153
|
},
|
|
60
154
|
driver(v) {
|
|
61
|
-
const w = v.body_width,
|
|
62
|
-
|
|
63
|
-
|
|
155
|
+
const w = v.body_width,
|
|
156
|
+
d = v.body_depth,
|
|
157
|
+
t = 1.6,
|
|
158
|
+
row = v.row_spacing / 2,
|
|
159
|
+
pins = v.pin_count / 2,
|
|
160
|
+
pitch = v.pin_pitch,
|
|
161
|
+
run = pitch * (pins - 1),
|
|
162
|
+
pin = 0.64,
|
|
163
|
+
drop = 8;
|
|
164
|
+
const rows = [-row, row].flatMap((y) =>
|
|
165
|
+
Array.from({ length: pins }, (_, i) => box(pin, pin, drop + t, -run / 2 + i * pitch, y, -drop)),
|
|
166
|
+
);
|
|
167
|
+
return {
|
|
168
|
+
parts: { body: union(box(w, d, t), box(5, 5, 1, 0, 0, t)), pins: union(rows) },
|
|
169
|
+
anchors: { header: z([0, 0, 0]), top: z([0, 0, t]) },
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
encoder(v, set) {
|
|
173
|
+
return SHAPES.board(v, set);
|
|
174
|
+
},
|
|
175
|
+
linear_bearing(v) {
|
|
176
|
+
// bore along z, from z = 0
|
|
177
|
+
const r = v.bore / 2,
|
|
178
|
+
R = v.outer_diameter / 2,
|
|
179
|
+
L = v.length,
|
|
180
|
+
c = 0.3;
|
|
181
|
+
return {
|
|
182
|
+
parts: {
|
|
183
|
+
body: extrudeRotate(
|
|
184
|
+
{ segments: SEG },
|
|
185
|
+
polygon({
|
|
186
|
+
points: [
|
|
187
|
+
[r + c, 0],
|
|
188
|
+
[R - c, 0],
|
|
189
|
+
[R, c],
|
|
190
|
+
[R, L - c],
|
|
191
|
+
[R - c, L],
|
|
192
|
+
[r + c, L],
|
|
193
|
+
[r, L - c],
|
|
194
|
+
[r, c],
|
|
195
|
+
],
|
|
196
|
+
}),
|
|
197
|
+
),
|
|
198
|
+
},
|
|
199
|
+
anchors: { bore: z([0, 0, L / 2]), face: z([0, 0, 0]), top: z([0, 0, L]) },
|
|
200
|
+
};
|
|
64
201
|
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
202
|
+
rod(v) {
|
|
203
|
+
return {
|
|
204
|
+
parts: {
|
|
205
|
+
body: translate([0, 0, v.length / 2], cylinder({ radius: v.diameter / 2, height: v.length, segments: SEG })),
|
|
206
|
+
},
|
|
207
|
+
anchors: { bottom: z([0, 0, 0]), top: z([0, 0, v.length]) },
|
|
208
|
+
};
|
|
69
209
|
},
|
|
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
210
|
// a bought fitting for a frame (@rulecad/frames' bought.mjs): drawn in the printed fittings' frames, an anchor on
|
|
72
211
|
// 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
212
|
// anchor connector) is inside the beams by design, so the overlap check leaves it out
|
|
74
213
|
fitting(v, set) {
|
|
75
|
-
const m = boughtFittingModel({ name: set.name, part: 'fitting', rules: set.rules }),
|
|
76
|
-
|
|
77
|
-
|
|
214
|
+
const m = boughtFittingModel({ name: set.name, part: 'fitting', rules: set.rules }),
|
|
215
|
+
count = { a: 0, b: 0 };
|
|
216
|
+
const anchors = Object.fromEntries(
|
|
217
|
+
m.screws.map((q) => [
|
|
218
|
+
`${q.leg}${++count[q.leg]}`,
|
|
219
|
+
z(
|
|
220
|
+
q.at,
|
|
221
|
+
q.axis.map((c) => (c ? -c : 0)),
|
|
222
|
+
),
|
|
223
|
+
]),
|
|
224
|
+
);
|
|
225
|
+
return {
|
|
226
|
+
parts: { body: boughtFitting(m, { pose: 'fit' }) },
|
|
227
|
+
anchors: { origin: z([0, 0, 0]), ...anchors },
|
|
228
|
+
inside: ['hidden', 'anchor'].includes(m.fitting),
|
|
229
|
+
model: m,
|
|
230
|
+
};
|
|
78
231
|
},
|
|
79
232
|
supply(v) {
|
|
80
|
-
const w = v.body_width,
|
|
81
|
-
|
|
233
|
+
const w = v.body_width,
|
|
234
|
+
d = v.body_depth,
|
|
235
|
+
h = v.body_length;
|
|
236
|
+
return {
|
|
237
|
+
parts: { body: box(w, d, h) },
|
|
238
|
+
anchors: { base: z([0, 0, 0]), top: z([0, 0, h]), terminals: z([0, -d / 2, h / 2], [0, -1, 0]) },
|
|
239
|
+
};
|
|
82
240
|
},
|
|
83
241
|
};
|
|
84
242
|
|
|
@@ -91,7 +249,21 @@ export function boughtModel(name, variant) {
|
|
|
91
249
|
const vs = set.variants || {};
|
|
92
250
|
if (!vs[variant]) throw new Error(`${name} has no variant "${variant}" (${Object.keys(vs).join(', ') || 'none'})`);
|
|
93
251
|
// (its values take the variant's kind and source; its rules, where it has them, are whole rules with their own)
|
|
94
|
-
rules = {
|
|
252
|
+
rules = {
|
|
253
|
+
...set.rules,
|
|
254
|
+
...Object.fromEntries(
|
|
255
|
+
Object.entries(vs[variant].values ?? {}).map(([k, value]) => [
|
|
256
|
+
k,
|
|
257
|
+
{
|
|
258
|
+
...set.rules[k],
|
|
259
|
+
value,
|
|
260
|
+
kind: vs[variant].kind ?? set.rules[k]?.kind,
|
|
261
|
+
source: vs[variant].source ?? set.rules[k]?.source,
|
|
262
|
+
},
|
|
263
|
+
]),
|
|
264
|
+
),
|
|
265
|
+
...(vs[variant].rules ?? {}),
|
|
266
|
+
};
|
|
95
267
|
}
|
|
96
268
|
return { name, part: set.part, variant: variant ?? null, rules };
|
|
97
269
|
}
|
|
@@ -100,17 +272,65 @@ export function boughtModel(name, variant) {
|
|
|
100
272
|
export function boughtBuilt(spec, it, num, id) {
|
|
101
273
|
const m = boughtModel(spec, it.variant);
|
|
102
274
|
// Figures that differ from the set's, by name: a smaller supply, a measured bearing
|
|
103
|
-
for (const [k, x] of Object.entries(it.set || {})) {
|
|
104
|
-
|
|
105
|
-
|
|
275
|
+
for (const [k, x] of Object.entries(it.set || {})) {
|
|
276
|
+
if (!m.rules[k]) throw new Error(`item ${id}: ${spec} has no figure "${k}" (${Object.keys(m.rules).join(', ')})`);
|
|
277
|
+
m.rules = { ...m.rules, [k]: { ...m.rules[k], value: num(x), kind: 'estimate', source: 'set on this item' } };
|
|
278
|
+
}
|
|
279
|
+
if (!SHAPES[m.part])
|
|
280
|
+
throw new Error(
|
|
281
|
+
`item ${id}: ${spec} is a ${m.part}: bought parts are ${Object.keys(SHAPES).join(', ')}, and a motor goes in "motor"`,
|
|
282
|
+
);
|
|
283
|
+
const values = Object.fromEntries(
|
|
284
|
+
Object.entries(m.rules)
|
|
285
|
+
.filter(([, r]) => typeof r.value === 'number')
|
|
286
|
+
.map(([k, r]) => [k, r.value]),
|
|
287
|
+
);
|
|
106
288
|
let shape;
|
|
107
|
-
try {
|
|
108
|
-
|
|
289
|
+
try {
|
|
290
|
+
shape = SHAPES[m.part](values, m);
|
|
291
|
+
} catch (e) {
|
|
292
|
+
throw new Error(`item ${id}: ${spec} doesn't say enough to draw it: ${e.message}`);
|
|
293
|
+
}
|
|
294
|
+
const missing = Object.entries(shape.anchors)
|
|
295
|
+
.filter(([, a]) => a.at.some((c) => !Number.isFinite(c)))
|
|
296
|
+
.map(([k]) => k);
|
|
109
297
|
if (missing.length) throw new Error(`item ${id}: ${spec}: its rules don't place the anchors ${missing.join(', ')}`);
|
|
110
|
-
const parts = named(
|
|
298
|
+
const parts = named(
|
|
299
|
+
shape.parts,
|
|
300
|
+
Object.fromEntries(Object.keys(shape.parts).map((k) => [k, { label: `${m.name} ${k}` }])),
|
|
301
|
+
);
|
|
111
302
|
if (shape.inside) parts[0].collide = jscad.geometries.geom3.create(); // (in the slots, inside the beams by design)
|
|
112
|
-
const entries = Object.entries(m.rules).map(([k, r]) => ({
|
|
113
|
-
|
|
303
|
+
const entries = Object.entries(m.rules).map(([k, r]) => ({
|
|
304
|
+
name: `${m.name}.${k}`,
|
|
305
|
+
value: r.value,
|
|
306
|
+
unit: r.unit,
|
|
307
|
+
rule: r.rule,
|
|
308
|
+
kind: r.kind,
|
|
309
|
+
source: r.source,
|
|
310
|
+
checked: r.checked,
|
|
311
|
+
set: m.name,
|
|
312
|
+
}));
|
|
313
|
+
return referenceBuilt({
|
|
314
|
+
id,
|
|
315
|
+
key: 'bought',
|
|
316
|
+
objName: `bought:${m.name}`,
|
|
317
|
+
name: m.name,
|
|
318
|
+
parts,
|
|
319
|
+
anchors: shape.anchors,
|
|
320
|
+
entries,
|
|
321
|
+
values,
|
|
322
|
+
extra: {
|
|
323
|
+
bought: {
|
|
324
|
+
set: m.name,
|
|
325
|
+
variant: m.variant,
|
|
326
|
+
part: m.part,
|
|
327
|
+
mass: values.mass ?? null,
|
|
328
|
+
mount: mountOf(m),
|
|
329
|
+
...(m.rules.cost ? { cost: { value: m.rules.cost.value, unit: m.rules.cost.unit } } : {}),
|
|
330
|
+
...(shape.model ? { fitting: shape.model } : {}),
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
});
|
|
114
334
|
}
|
|
115
335
|
|
|
116
336
|
/**
|
|
@@ -119,11 +339,22 @@ export function boughtBuilt(spec, it, num, id) {
|
|
|
119
339
|
* diameter plain ones (a board's). @param {{ name: string, part: string, rules: object }} m boughtModel's
|
|
120
340
|
*/
|
|
121
341
|
export function mountOf(m) {
|
|
122
|
-
const r = m.rules,
|
|
342
|
+
const r = m.rules,
|
|
343
|
+
flat = r.mount_holes?.value; // (x then y for each hole, as the vocabulary keeps a list)
|
|
123
344
|
if (!Array.isArray(flat) || !flat.length || flat.length % 2) return null;
|
|
124
345
|
const holes = Array.from({ length: flat.length / 2 }, (_, i) => [flat[2 * i], flat[2 * i + 1]]);
|
|
125
|
-
return {
|
|
126
|
-
|
|
346
|
+
return {
|
|
347
|
+
set: m.name,
|
|
348
|
+
holes,
|
|
349
|
+
thread: typeof r.mount_hole_thread?.value === 'string' ? r.mount_hole_thread.value : null,
|
|
350
|
+
reach: r.mount_hole_reach?.value ?? null,
|
|
351
|
+
diameter: r.mount_hole_diameter?.value ?? null,
|
|
352
|
+
thickness: m.part === 'board' ? (r.board_thickness?.value ?? 1.6) : null,
|
|
353
|
+
body: [r.body_width?.value, r.body_depth?.value],
|
|
354
|
+
height: m.part === 'board' ? (r.board_thickness?.value ?? 1.6) : (r.body_length?.value ?? null),
|
|
355
|
+
kind: r.mount_holes.kind,
|
|
356
|
+
source: r.mount_holes.source,
|
|
357
|
+
};
|
|
127
358
|
}
|
|
128
359
|
|
|
129
360
|
// One line in the check for each bought item, so the shopping list and the wiring can read it
|
|
@@ -131,11 +362,36 @@ export function boughtFindings(s, f) {
|
|
|
131
362
|
// 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
363
|
// that beam's profile (its size, its slot family, a foot's stem against the end's bore)
|
|
133
364
|
const items = new Map((s.a?.items ?? []).map((it) => [it.id, it]));
|
|
134
|
-
for (const o of s.objects)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
365
|
+
for (const o of s.objects)
|
|
366
|
+
if (o.bought?.fitting && !o.unplaced && items.get(o.id)?.join == null) {
|
|
367
|
+
const at = items.get(o.id)?.at,
|
|
368
|
+
beam = typeof at === 'string' ? s.objects.find((x) => x.id === at.trim().split('.')[0])?.beam : null;
|
|
369
|
+
if (!beam) continue;
|
|
370
|
+
for (const x of boughtFittingModel(o.bought.fitting.set, {
|
|
371
|
+
profile: beam.profile,
|
|
372
|
+
...(s.frames ? { given: s.frames } : {}),
|
|
373
|
+
}).findings.filter((y) => y.code === 'fitting.fit'))
|
|
374
|
+
f(x.level, `${o.id}: ${x.text}`, x.level === 'fail' ? `${o.id}: fit` : null, {
|
|
375
|
+
code: x.code,
|
|
376
|
+
...(x.values ? { values: x.values } : {}),
|
|
377
|
+
refs: { item: o.id, beam: beam.name, ...x.refs },
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
for (const o of s.objects)
|
|
381
|
+
if (o.bought)
|
|
382
|
+
f(
|
|
383
|
+
'info',
|
|
384
|
+
`${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}`,
|
|
385
|
+
null,
|
|
386
|
+
{
|
|
387
|
+
code: 'bought.item',
|
|
388
|
+
refs: {
|
|
389
|
+
item: o.id,
|
|
390
|
+
set: o.bought.set,
|
|
391
|
+
variant: o.bought.variant,
|
|
392
|
+
part: o.bought.part,
|
|
393
|
+
...(o.bought.length != null ? { length: o.bought.length } : {}),
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
);
|
|
141
397
|
}
|