@rulecad/cad 0.7.53 → 0.7.56

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/sheet.mjs CHANGED
@@ -7,7 +7,9 @@ import path from 'node:path';
7
7
  import zlib from 'node:zlib';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { checkRuleSet } from '@rulecad/variables';
10
+ import { profileModel, slotModel, slotPath, outline, section, profileFindings, slotNutModel, nutFit } from '@rulecad/frames';
10
11
  import { RULE_DIRS } from './workspace.mjs';
12
+ import { schema, validate } from './schema.mjs';
11
13
 
12
14
  const vocabularyFile = fileURLToPath(import.meta.resolve('@rulecad/rules/vocabulary.json'));
13
15
  const readSet = (f) => JSON.parse(fs.readFileSync(f, 'utf8'));
@@ -25,10 +27,61 @@ function fileOf(name) {
25
27
  return file;
26
28
  }
27
29
 
28
- /** Every named set checked (or all of them): [{ name, file, findings }] */
30
+ // What a check notes and never fails on. An alias: a name the vocabulary shares across parts (screw_clearance, which a
31
+ // motor's mount reads) that a set gives to one of its own rules in "interface". A copy: a workspace's own copy of a
32
+ // set the kit has (cad copies a set into rules/ the first time a design uses it), which is used as it is, even after
33
+ // the kit's set gains figures: it is told which, so a design that wants one knows where it went.
34
+ function notesOf(set, file) {
35
+ const notes = [], kitDir = RULE_DIRS.at(-1), name = path.basename(file, '.json');
36
+ for (const [shared, own] of Object.entries(set.interface || {})) if (set.rules?.[own]) notes.push({ level: 'info', code: 'rules.alias', text: `${own} is also read as ${shared}, the vocabulary's name for it`, rule: own, values: { alias: shared } });
37
+ const kitFile = path.join(kitDir, `${name}.json`);
38
+ if (path.dirname(path.resolve(file)) !== path.resolve(kitDir) && fs.existsSync(kitFile) && set.rules && typeof set.rules === 'object') {
39
+ const kit = readSet(kitFile), added = Object.keys(kit.rules || {}).filter((k) => !(k in set.rules));
40
+ if (added.length) notes.push({ level: 'info', code: 'rules.new', text: `your copy is used as it is; the kit's ${name} now also has ${added.length > 8 ? `${added.slice(0, 8).join(', ')} and ${added.length - 8} more (--json lists them)` : added.join(', ')}: copy any you want into rules/${name}.json, or delete it to read the kit's own`, values: { count: added.length }, refs: { rules: added } });
41
+ }
42
+ return notes;
43
+ }
44
+
45
+
46
+ // What a profile's model reads beside its own set: any other set by name (its slot family, a thread, its material),
47
+ // the workspace's first, and a measured outline in outlines/<name>.json beside the set, held to its schema
48
+ function given(name, file, all = allSets()) {
49
+ const load = (n) => (all.has(n) ? readSet(all.get(n)) : undefined), at = path.join(path.dirname(file), 'outlines', `${name}.json`), problems = [];
50
+ let measured;
51
+ if (fs.existsSync(at)) {
52
+ try { measured = readSet(at); problems.push(...validate(measured, schema('outline')).map((x) => `outlines/${name}.json: ${x.path}: ${x.message}`)); } catch (e) { problems.push(`outlines/${name}.json isn't JSON: ${e.message}`); }
53
+ if (problems.length) measured = undefined;
54
+ }
55
+ return { load, ...(measured ? { outline: measured } : {}), problems };
56
+ }
57
+ const own = (e) => e.message.replace(/^\w+: /, ''); // a refusal without the function's name: the set's name follows
58
+
59
+ // A profile, a slot or a slot nut held to sense as well as to the vocabulary: what @rulecad/frames finds in its model
60
+ function partFindings(set, name, file, all) {
61
+ const out = [], say = (level, code, text, extra = {}) => out.push({ level, code, text, ...extra }), g = given(name, file, all);
62
+ for (const p of g.problems) say('fail', 'outline.schema', p);
63
+ try {
64
+ if (set.part === 'profile') out.push(...profileFindings(profileModel(set, {}, g)));
65
+ if (set.part === 'slot') slotModel(set, {}, g);
66
+ if (set.part === 'slot_nut') {
67
+ const r = (k) => set.rules[k]?.value, slot = g.load(String(r('slot')));
68
+ if (slot?.part !== 'slot') say('warn', 'slot_nut.slot', `slot names the slot family it is made for, and there is no slot set "${r('slot')}": its fit is not checked`, { rule: 'slot' });
69
+ else out.push(...nutFit(slotNutModel(set, {}, g), slotModel(slot, {}, g), g));
70
+ if (![...all.values()].some((f) => { const t = readSet(f); return t.part === 'thread' && (t.name === r('thread') || t.rules.thread?.value === r('thread')); })) say('warn', 'slot_nut.thread', `thread ${JSON.stringify(r('thread'))} is no thread set here (M5, or a set's name)`, { rule: 'thread' });
71
+ }
72
+ } catch (e) { say('fail', `${set.part}.model`, own(e)); }
73
+ return out;
74
+ }
75
+
76
+ /** Every named set checked (or all of them): [{ name, file, findings, notes? }]. A finding's level is fail, warn or info;
77
+ * notes: what is said and never fails */
29
78
  export function checkSets(names = []) {
30
79
  const v = vocabulary(), all = allSets();
31
- return (names.length ? names.map((n) => [n, fileOf(n)]) : [...all]).map(([name, file]) => ({ name, file, findings: checkRuleSet(readSet(file), v) }));
80
+ return (names.length ? names.map((n) => [n, fileOf(n)]) : [...all]).map(([name, file]) => {
81
+ const set = readSet(file), findings = checkRuleSet(set, v), notes = notesOf(set, file);
82
+ if (!findings.length && ['profile', 'slot', 'slot_nut'].includes(set.part)) findings.push(...partFindings(set, name, file, all));
83
+ return { name, file, findings, ...(notes.length ? { notes } : {}) };
84
+ });
32
85
  }
33
86
 
34
87
  // ---------- a dimension drawing ----------
@@ -36,7 +89,7 @@ const fig = (x) => String(+Number(x).toFixed(2));
36
89
  const INK = '#1a1a1a', THIN = '#666', FILL = '#eceae4', METAL = '#c4c8cc';
37
90
 
38
91
  /** @param {string} name the rule set's name @returns {string} an SVG drawing of what it says the part mounts by */
39
- export function drawSet(name) { return drawing(readSet(fileOf(name)), vocabulary()); }
92
+ export function drawSet(name) { const file = fileOf(name); return drawing(readSet(file), vocabulary(), given(name, file)); }
40
93
 
41
94
  // The drawing's marks, in sheet units: each adds to out, and span is a dimension with its extension lines, ticks and figure
42
95
  function pen() {
@@ -257,7 +310,97 @@ function threadDrawing(set) {
257
310
  return sheet(set, pens, Math.max(W, 620), yNotes + notes.length * 17 - 50);
258
311
  }
259
312
 
260
- export function drawing(set, vocab) {
313
+ // ---------- profiles, slots and slot nuts ----------
314
+ const pathOf = (loops, X, Y) => loops.map((l) => `M ${l.map(([x, y]) => `${fig(X(x))} ${fig(Y(y))}`).join(' L ')} Z`).join(' ');
315
+ const sig = (x, n = 4) => String(+Number(x).toPrecision(n));
316
+
317
+ // A profile's section to scale, with what a sheet's drawing dimensions (size, slot, bore, corner), and under it the
318
+ // sheet's section figures beside what the drawn outline comes to
319
+ function profileDrawing(set, g) {
320
+ const m = profileModel(set, {}, g), o = outline(m), s = section(m), W = m.width, H = m.height;
321
+ const S = Math.min(18, 380 / Math.max(W, H)), sheetW = Math.max(W * S + 330, 640), cx = 130 + (W * S) / 2, cy = 110 + (H * S) / 2, X = (x) => cx + x * S, Y = (y) => cy - y * S;
322
+ const pens = pen(), { out, line, text, span } = pens;
323
+ out.push(`<path d="${pathOf(o.loops, X, Y)}" fill="${METAL}" fill-rule="evenodd" stroke="${INK}" stroke-width="1.2" stroke-linejoin="round"/>`);
324
+ line(X(-W / 2) - 10, Y(0), X(W / 2) + 10, Y(0), THIN, 0.5, '8 3 2 3'); line(X(0), Y(H / 2) - 10, X(0), Y(-H / 2) + 10, THIN, 0.5, '8 3 2 3');
325
+ span(X(-W / 2), Y(-H / 2) + 6, X(W / 2), Y(-H / 2) + 6, fig(W), 22);
326
+ span(X(-W / 2) - 6, Y(H / 2), X(-W / 2) - 6, Y(-H / 2), fig(H), -22);
327
+ // the slot nearest the top right: its opening and cavity above, its lip and depth at the side
328
+ const face = ['top', 'back', 'bottom', 'front'].find((f) => m.faces[f].some((p) => p.slot)), notes = [];
329
+ if (face && !o.measured) {
330
+ const p = m.faces[face].filter((q) => q.slot).at(-1), sl = m.slots[p.slot], top = face === 'top' || face === 'bottom', sign = face === 'top' || face === 'back' ? 1 : -1;
331
+ if (top) {
332
+ const y0 = Y(p.at[1]) - sign * 6, d = -sign * 14;
333
+ span(X(p.at[0] - sl.mouth / 2), y0, X(p.at[0] + sl.mouth / 2), y0, fig(sl.mouth), d);
334
+ span(X(p.at[0] - sl.cavityWidth / 2), y0 - sign * 24, X(p.at[0] + sl.cavityWidth / 2), y0 - sign * 24, fig(sl.cavityWidth), d);
335
+ const x0 = X(W / 2) + 6;
336
+ span(x0, Y(p.at[1]), x0, Y(p.at[1] - sign * sl.lip), fig(sl.lip), 16);
337
+ span(x0 + 44, Y(p.at[1]), x0 + 44, Y(p.at[1] - sign * sl.cavityDepth), fig(sl.cavityDepth), 16);
338
+ } else {
339
+ const x0 = X(p.at[0]) + sign * 6, d = sign * 14;
340
+ span(x0, Y(p.at[1] + sl.mouth / 2), x0, Y(p.at[1] - sl.mouth / 2), fig(sl.mouth), d);
341
+ span(x0 + sign * 30, Y(p.at[1] + sl.cavityWidth / 2), x0 + sign * 30, Y(p.at[1] - sl.cavityWidth / 2), fig(sl.cavityWidth), d);
342
+ const y0 = Y(-H / 2) + 6;
343
+ span(X(p.at[0]), y0 + 40, X(p.at[0] - sign * sl.lip), y0 + 40, fig(sl.lip), 14);
344
+ span(X(p.at[0]), y0 + 70, X(p.at[0] - sign * sl.cavityDepth), y0 + 70, fig(sl.cavityDepth), 14);
345
+ }
346
+ const families = [...new Set(Object.values(m.faces).flat().map((q) => q.slot ?? 'closed'))];
347
+ notes.push(`slot: ${families.join(', ')}${families.length > 1 ? ` (${['top', 'bottom', 'front', 'back'].map((f) => `${f} ${m.faces[f].map((q) => q.slot ?? 'closed').join(' | ')}`).join('; ')})` : ''}: ${fig(sl.mouth)} wide, ${fig(sl.cavityWidth)} under lips ${fig(sl.lip)} thick, ${fig(sl.cavityDepth)} deep, floor ${fig(sl.floorWidth)}`);
348
+ }
349
+ if (o.measured) notes.push(`drawn from its outline: ${esc(o.source)}`);
350
+ const kinds = ['cell', 'given', 'corner'].map((w) => m.bores.filter((b) => b.where === w)).filter((l) => l.length);
351
+ for (const list of kinds) notes.push(`${list.length} × ${list[0].where === 'corner' ? 'corner hole' : 'bore'} Ø${fig(list[0].diameter)}${list[0].thread ? `, taps ${esc(list[0].thread)}${list[0].tapDrill ? ` (tap drill Ø${fig(list[0].tapDrill)})` : ''}` : ''}`);
352
+ if (m.bores.length) { const b = m.bores.find((q) => q.where !== 'corner') ?? m.bores[0], a = X(b.at[0]) + (b.diameter / 2) * S * 0.7, c = Y(b.at[1]) + (b.diameter / 2) * S * 0.7; line(a, c, a + 26, c + 26, THIN, 0.8); text(a + 30, c + 34, `Ø${fig(b.diameter)}`, 'start'); }
353
+ if (m.cornerRadius) text(X(W / 2) + 8, Y(H / 2) - 8, `R${fig(m.cornerRadius)}`, 'start', 11);
354
+ if (m.wall) notes.push(`wall ${fig(m.wall)}`);
355
+ if (m.hollows.length) notes.push(`${m.hollows.length} × corner hollow ${fig(m.hollows[0].width)} square`);
356
+ if (m.chambers.length) notes.push(`${m.chambers.length} × hollow between cells, ${fig(m.chambers[0].width)} wide`);
357
+ notes.push(`${m.family}${m.cells[0] * m.cells[1] > 1 ? `, ${m.cells[0]} × ${m.cells[1]} cells of ${fig(m.pitch[0])}${m.absent?.length ? ` with ${m.absent.length} not there` : ''}` : ''}${m.material ? `, ${m.material.alloy ? `${esc(m.material.alloy)} (${m.material.name})` : m.material.name}` : ''}`);
358
+ if (m.supply.lengths.length || m.supply.cutMax) notes.push([m.supply.lengths.length ? `sold as ${m.supply.lengths.map(fig).join(', ')}` : '', m.supply.cutMax ? `cut ${fig(m.supply.cutMin ?? 0)} to ${fig(m.supply.cutMax)}${m.supply.cutTolerance != null ? ` ±${fig(m.supply.cutTolerance)}` : ''}` : '', m.supply.straightness != null ? `straight within ${fig(m.supply.straightness)} mm/m` : '', m.supply.twist != null ? `twist within ${fig(m.supply.twist)}°/m` : ''].filter(Boolean).join('; '));
359
+ // the table: what the sheet says, what the outline comes to
360
+ const rows = [['area, mm²', 'area', s.area], ['second moment about x, mm⁴', 'inertiaX', s.inertiaX], ['second moment about y, mm⁴', 'inertiaY', s.inertiaY], ['torsion constant, mm⁴', 'torsion', s.torsion], ['mass, kg/m', 'massPerMetre', s.massPerMetre]];
361
+ const ty = Y(-H / 2) + 120, tx = 40, col = [0, 230, 330, 440];
362
+ ['', 'sheet', o.measured ? 'measured' : 'drawn', 'difference'].forEach((t, i) => text(tx + col[i], ty, t, i ? 'end' : 'start', 11));
363
+ line(tx, ty + 6, tx + 450, ty + 6, THIN, 0.6);
364
+ rows.forEach(([label, k, got], i) => { const y = ty + 24 + i * 18, c = s.sheet[k]; text(tx, y, label, 'start', 11); text(tx + col[1], y, m.sheet[k] != null ? sig(m.sheet[k]) : 'not given', 'end', 11); text(tx + col[2], y, got != null ? sig(got) : 'no material', 'end', 11); text(tx + col[3], y, c ? `${c.difference >= 0 ? '+' : ''}${(c.difference * 100).toFixed(1)}%` : '', 'end', 11); });
365
+ const ny = ty + 24 + rows.length * 18 + 14;
366
+ notes.forEach((t, i) => text(tx, ny + i * 17, t, 'start', 11));
367
+ return sheet(set, pens, sheetW, ny + notes.length * 17 - 44);
368
+ }
369
+
370
+ // A slot cut into a block of metal, every figure of its family dimensioned
371
+ function slotDrawing(set, g) {
372
+ const sl = slotModel(set, {}, g), block = sl.cavityWidth + 8, deep = sl.cavityDepth + 4, S = Math.min(30, 380 / block), W = block * S + 300, x0 = 110 + (block * S) / 2, y0 = 110, X = (u) => x0 + u * S, Y = (v) => y0 + v * S;
373
+ const pens = pen(), { out, line, text, span } = pens, pts = [[-block / 2, 0], ...slotPath(sl), [block / 2, 0], [block / 2, deep], [-block / 2, deep]];
374
+ out.push(`<path d="M ${pts.map(([u, v]) => `${fig(X(u))} ${fig(Y(v))}`).join(' L ')} Z" fill="${METAL}" stroke="${INK}" stroke-width="1.2" stroke-linejoin="round"/>`);
375
+ line(X(0), Y(0) - 14, X(0), Y(deep) + 10, THIN, 0.5, '8 3 2 3');
376
+ span(X(-sl.opening / 2), Y(0) - 6, X(sl.opening / 2), Y(0) - 6, fig(sl.opening), -14);
377
+ if (sl.trackWidth) span(X(-sl.trackWidth / 2), Y(0) - 34, X(sl.trackWidth / 2), Y(0) - 34, `track ${fig(sl.trackWidth)}`, -14);
378
+ span(X(-sl.cavityWidth / 2), Y(deep) + 6, X(sl.cavityWidth / 2), Y(deep) + 6, fig(sl.cavityWidth), 16);
379
+ if (sl.floorWidth < sl.cavityWidth) span(X(-sl.floorWidth / 2), Y(deep) + 46, X(sl.floorWidth / 2), Y(deep) + 46, `floor ${fig(sl.floorWidth)}`, 16);
380
+ span(X(block / 2) + 6, Y(0), X(block / 2) + 6, Y(sl.lip), fig(sl.lip), 16);
381
+ span(X(block / 2) + 56, Y(0), X(block / 2) + 56, Y(sl.cavityDepth), fig(sl.cavityDepth), 16);
382
+ const notes = [`opening ${fig(sl.opening)}, lip ${fig(sl.lip)}${sl.lipAngle ? ` sloping ${fig(sl.lipAngle)}°` : ''}, ${fig(sl.cavityWidth)} wide under the lips, ${fig(sl.cavityDepth)} deep`, sl.floorWidth < sl.cavityWidth ? `walls straight to ${fig(sl.straight)} below the face, then flanks at ${fig(sl.flankAngle)}° to a floor of ${fig(sl.floorWidth)}` : 'straight walls', sl.trackWidth ? `V mouth ${fig(sl.trackWidth)} across at ${fig(sl.trackAngle)}°` : '', `takes the nuts of ${esc(sl.nutFamily)}`].filter(Boolean);
383
+ const ny = Y(deep) + 110; notes.forEach((t, i) => text(40, ny + i * 17, t, 'start', 11));
384
+ return sheet(set, pens, Math.max(W, 620), ny + notes.length * 17 - 44);
385
+ }
386
+
387
+ // A slot nut from above and from the side
388
+ function nutDrawing(set) {
389
+ const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0), says = (k) => String(set.rules[k]?.value ?? ''), L = n('length'), w = n('width'), h = n('height'), d = parseFloat(says('thread').replace(/^[^0-9]*/, '')) || 0;
390
+ const S = Math.min(24, 260 / Math.max(L, w, 1)), pens = pen(), { line, circle, rect, text, span } = pens, x0 = 90, y0 = 100;
391
+ rect(x0, y0, L * S, w * S, METAL); if (d) circle(x0 + (L * S) / 2, y0 + (w * S) / 2, (d / 2) * S, '#fff');
392
+ span(x0, y0 + w * S + 6, x0 + L * S, y0 + w * S + 6, fig(L), 16); span(x0 + L * S + 6, y0, x0 + L * S + 6, y0 + w * S, fig(w), 16);
393
+ const y1 = y0 + w * S + 80; rect(x0, y1, L * S, h * S, METAL); span(x0 + L * S + 6, y1, x0 + L * S + 6, y1 + h * S, fig(h), 16);
394
+ line(x0 + (L * S) / 2, y0 - 10, x0 + (L * S) / 2, y1 + h * S + 10, THIN, 0.5, '8 3 2 3');
395
+ const ny = y1 + h * S + 50; [`${esc(says('nut_kind'))} nut, ${esc(says('thread'))}, for ${esc(says('slot'))}`, says('nut_entry') === 'end' ? 'goes in from an open end of the slot' : 'goes in anywhere along the slot'].forEach((t, i) => text(40, ny + i * 17, t, 'start', 11));
396
+ return sheet(set, pens, Math.max(L * S + 260, 520), ny - 10);
397
+ }
398
+ const esc = (t) => String(t).replace(/&/g, '&amp;').replace(/</g, '&lt;');
399
+
400
+ export function drawing(set, vocab, g = { load: () => undefined, problems: [] }) {
401
+ if (set.part === 'profile') return profileDrawing(set, g);
402
+ if (set.part === 'slot') return slotDrawing(set, g);
403
+ if (set.part === 'slot_nut') return nutDrawing(set);
261
404
  if (set.part === 'thread') return threadDrawing(set);
262
405
  if (set.part === 'bearing') return bearingDrawing(set);
263
406
  if (set.part === 'driver') return driverDrawing(set);
@@ -339,6 +482,19 @@ export function pdfText(file) {
339
482
  return lines;
340
483
  }
341
484
 
485
+ /**
486
+ * A set with every field the vocabulary gives a part (profile, slot, slot_nut), each a starting value marked estimate,
487
+ * for a person to fill from the maker's sheet. @param {string} part @param {string} name @returns {object | null} null for a part with no draft
488
+ */
489
+ export function draftPart(part, name) {
490
+ const v = vocabulary(), fields = v.drafts?.[part];
491
+ if (!fields) return null;
492
+ const stamp = new Date().toISOString().slice(0, 10), rules = {};
493
+ for (const [k, value] of Object.entries(fields)) rules[k] = { value, ...(v.fields[k]?.unit != null ? { unit: v.fields[k].unit } : {}), rule: `DRAFT, not read from a sheet yet: ${v.fields[k]?.says ?? k}`, kind: 'estimate', source: 'DRAFT: give the sheet, its page and the date you read it', checked: stamp };
494
+ return { _doc: `A draft ${part.replace('_', ' ')}: every field the vocabulary has for one, each with a starting value. Put in the figures from the maker's sheet, with the sheet and its page as the source and today's date, and change each kind to spec as you go. Delete what the sheet has no figure for (cad rules check says which a ${part.replace('_', ' ')} needs). Then cad rules check ${name}, and cad rules draw ${name} to hold against the sheet's drawing.`, name, part, rules };
495
+ }
496
+ export const draftParts = () => Object.keys(vocabulary().drafts || {});
497
+
342
498
  /** Every figure a datasheet's text gives, as a rule set of estimates for a person to name and check. @returns {{ set: object, found: number }} */
343
499
  export function draftSet(name, file) {
344
500
  if (!fs.existsSync(file)) throw new Error(`no file ${file}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.53",
3
+ "version": "0.7.56",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,6 +30,7 @@
30
30
  "schemas",
31
31
  "templates",
32
32
  "README.md",
33
+ "CHANGELOG.md",
33
34
  "TUTORIAL.md",
34
35
  "EXAMPLES.md",
35
36
  "LICENSE",
@@ -63,17 +64,18 @@
63
64
  "@rulecad/fit": "^0.4.0",
64
65
  "@rulecad/model-link": "^0.3.2",
65
66
  "@rulecad/versions": "^0.1.6",
66
- "@rulecad/shapes": "^0.4.4",
67
- "@rulecad/rules": "^0.3.12",
67
+ "@rulecad/shapes": "^0.4.5",
68
+ "@rulecad/rules": "^0.3.15",
68
69
  "@jscad/modeling": "^2.12.0",
69
70
  "three": "^0.186.1",
70
71
  "@rulecad/fea": "^0.2.1",
71
72
  "@rulecad/topopt": "^0.3.0",
72
73
  "@rulecad/flexures": "^0.5.0",
73
74
  "@rulecad/gears": "^0.3.2",
74
- "@rulecad/motors": "^0.1.4",
75
- "@rulecad/fixings": "^0.1.3",
76
- "@rulecad/robots": "^0.1.1"
75
+ "@rulecad/motors": "^0.1.6",
76
+ "@rulecad/fixings": "^0.1.4",
77
+ "@rulecad/robots": "^0.1.1",
78
+ "@rulecad/frames": "^0.1.7"
77
79
  },
78
80
  "peerDependencies": {
79
81
  "@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
@@ -17,7 +17,7 @@
17
17
  "requires": { "type": "object", "additionalProperties": { "type": "string" }, "description": "object → semver range" },
18
18
  "items": { "type": "array", "items": { "$ref": "#/$defs/item" } },
19
19
  "fits": { "type": "array", "items": { "$ref": "#/$defs/fit" } },
20
- "fasten": { "type": "array", "description": "Screwed joints: each names its screw, the parts it passes through in order, and the part it ends in. The holes are read from the parts as drawn and each screw followed along one axis; a fasten holds its parts as a fit that fastens does, and lines their holes up as a holes fit does", "items": { "$ref": "#/$defs/fasten" } },
20
+ "fasten": { "type": "array", "description": "Screwed joints: each names its screw, the parts it passes through in order, and the part it ends in. The holes are read from the parts as drawn and each screw followed along one axis; a fasten holds its parts as a fit that fastens does, lines their holes up as a holes fit does, and puts its screws on the shopping list. Draw the holes with v.fixings, and name the screw with no length: the check chooses one", "items": { "$ref": "#/$defs/fasten" }, "defaultSnippets": [{ "label": "fasten", "description": "A screwed joint", "body": [{ "screw": "${1:M3 cap}", "through": ["${2:bracket}"], "into": "${3:base}", "at": ["${4:bracket.h1}", "${5:bracket.h2}"] }] }] },
21
21
  "joints": { "type": "array", "items": { "$ref": "#/$defs/joint" } },
22
22
  "loops": { "type": "array", "items": { "$ref": "#/$defs/loop" } },
23
23
  "planetary": { "type": "array", "items": { "$ref": "#/$defs/planetary" } },
@@ -47,10 +47,13 @@
47
47
  "bought": { "type": "string", "description": "A part from a rule set (\"608\", \"drv8825\"): bought, not printed; drawn faint from its figures, with anchors from what it is" },
48
48
  "variant": { "type": "string" },
49
49
  "set": { "type": "object" },
50
- "at": { "$ref": "#/$defs/vec3" },
50
+ "beam": { "type": "object", "required": ["profile"], "additionalProperties": false, "description": "A length of a profile from @rulecad/frames: bought and cut to length, faint in previews; placed by its ends (from, to, roll) or by at and rotate", "properties": { "profile": { "type": "string", "description": "A profile's name: 2020-misumi-hfs5, profile-4040-item-8, or a set in this workspace's rules/" }, "length": { "$ref": "#/$defs/expr", "description": "mm from end a to end b; may be left out when from and to are both given" }, "printed": { "type": "boolean", "description": "A printed beam (a later release): a bought one is false, the default" }, "material": { "type": "string", "description": "A material set in place of the profile's alloy: al6063-t5, or a plastic" }, "ops": { "type": "array", "items": { "$ref": "#/$defs/beamOp" }, "description": "Operations on the beam, each a line on its sheet and a cut in its solid, placed by an address on the beam and dimensioned from end a" } } },
51
+ "at": { "anyOf": [{ "$ref": "#/$defs/vec3" }, { "$ref": "#/$defs/address" }] },
51
52
  "rotate": { "$ref": "#/$defs/vec3" },
53
+ "to": { "$ref": "#/$defs/vec3", "description": "A beam's end b, with from its end a" },
54
+ "roll": { "$ref": "#/$defs/expr", "description": "Degrees a beam placed by its ends turns about its own axis, a toward b; at 0 its top faces up (+z), or +y when it stands upright" },
52
55
  "place": {},
53
- "from": {},
56
+ "from": { "description": "For a beam: its end a, [x, y, z]. For an object: inputs worked out from items built before it, { input: expression }" },
54
57
  "repeat": {
55
58
  "type": "object",
56
59
  "additionalProperties": false,
@@ -69,7 +72,7 @@
69
72
  },
70
73
  "fit": {
71
74
  "type": "object",
72
- "required": ["a", "b"],
75
+ "anyOf": [{ "required": ["a", "b"] }, { "required": ["holes", "into"] }],
73
76
  "additionalProperties": false,
74
77
  "properties": {
75
78
  "a": { "$ref": "#/$defs/names" },
@@ -78,8 +81,8 @@
78
81
  "radius": { "$ref": "#/$defs/expr", "description": "With engage: how near the joint's axis to look (mm, default 10)" },
79
82
  "shaft": { "anyOf": [{ "type": "boolean" }, { "enum": ["slide", "press"] }], "description": "a or b is a motor, and the other takes its shaft: reads the bore from the part as drawn" },
80
83
  "seat": { "anyOf": [{ "type": "boolean" }, { "enum": ["press", "slip"] }, { "type": "number" }], "description": "a or b is a bought bearing, and the other its printed seat: reads the pocket as drawn against the bearing's rules and the printer's fit (fit.seat)" },
81
- "fastens": { "type": "boolean", "description": "a and b are fastened together (pins, screws, a press): what holds a part that has no joint" },
82
- "fastener": { "type": "string", "description": "What does the fastening (an M3 × 12 screw): named on the shopping list and the assembly step" },
84
+ "fastens": { "type": "boolean", "description": "a and b are fastened together (pins, a press, a clip): what holds a part that has no joint. Where screws hold them, use a fasten instead: it knows the screw, checks its holes and lists it" },
85
+ "fastener": { "type": "string", "description": "What does the fastening, by hand (two push pins): named on the shopping list and the assembly step. A screw is a fasten's, which chooses its length and counts it" },
83
86
  "count": { "$ref": "#/$defs/expr", "description": "With fastener: how many" },
84
87
  "access": { "type": "string", "description": "<item>.<anchor>: where the screw's tool comes from, its z axis pointing out along the screw. Whatever stands on that line goes on after the screw; if nothing can, assembly.order says so" },
85
88
  "min": { "$ref": "#/$defs/expr" },
@@ -87,18 +90,41 @@
87
90
  "note": { "type": "string" },
88
91
  "label": { "type": "string" },
89
92
  "poses": { "type": "array", "items": { "type": "string" } },
90
- "holes": { "type": "boolean" },
91
- "depth": { "$ref": "#/$defs/expr" },
92
- "direction": { "enum": ["up", "down"] },
93
- "ring": { "$ref": "#/$defs/expr" },
94
- "into": { "type": "string" },
93
+ "holes": { "type": "string", "description": "A holes fit: a circuit board's part (pcb.board) whose mounting holes are followed down into the part named by into. Where the board is screwed there, a fasten with \"holes\" says it and knows the screw: cad check suggests it, cad add fasten --from-fits writes it" },
94
+ "depth": { "$ref": "#/$defs/expr", "description": "With holes: how far each screw's path must be clear (mm)" },
95
+ "direction": { "enum": ["up", "down"], "description": "With holes: up for screws from below" },
96
+ "ring": { "$ref": "#/$defs/expr", "description": "With holes: how far round each screw there must be material (mm, default the hole's diameter)" },
97
+ "into": { "type": "string", "description": "With holes: the part the screws go into" },
95
98
  "within": { "$ref": "#/$defs/expr", "description": "With an anchor name (item@anchor): only faces this close to it (mm, default 10)" }
96
99
  }
97
100
  },
101
+ "beamAddress": { "type": "string", "pattern": "^([ab](\\.\\d+)?|(top|bottom|front|back)(\\.\\d+)?(@-?\\d+(\\.\\d+)?%?)?)$", "description": "An address on a beam, without its item: an end (a, b), an end's bore (a.1), or a face's place with a distance from end a (top@120), from end b (top@-20) or a share of the length (top@50%), the second place of a face top.2@120" },
102
+ "beamOp": { "type": "object", "required": ["op", "at"], "additionalProperties": false, "description": "An operation on a beam (@rulecad/frames OPS): each takes only its own keys, and is refused by name otherwise", "properties": {
103
+ "op": { "enum": ["cut", "mitre", "tap", "access", "drill", "counterbore", "pocket", "notch", "deburr"], "description": "cut: square to length; mitre: an end at an angle about a named face; tap: a thread in an end bore; access: a hole across, in line with a slot, for a key; drill: through one wall or right through, plain or tapped; counterbore: a seat for a head; pocket: milled by outline; notch: a slot's lips cut away; deburr: named so the sheet asks for it" },
104
+ "at": { "$ref": "#/$defs/beamAddress" },
105
+ "thread": { "type": "string", "description": "A thread by name (M5): sizes the hole, the tap or the seat through @rulecad/fixings" },
106
+ "kind": { "enum": ["clearance", "close", "loose", "tap"], "description": "A drilled hole's kind" },
107
+ "head": { "type": "string", "description": "A counterbore's head: cap, button, hex or pan" },
108
+ "diameter": { "$ref": "#/$defs/expr", "description": "mm, in place of a thread's figure" },
109
+ "depth": { "$ref": "#/$defs/expr", "description": "mm from the face or the end" },
110
+ "through": { "enum": ["wall", "beam"], "description": "A drilled hole through one wall (the default) or right through the beam" },
111
+ "angle": { "$ref": "#/$defs/expr", "description": "A mitre's angle from square, degrees" },
112
+ "about": { "enum": ["top", "bottom", "front", "back"], "description": "The face a mitre's angle is seen on" },
113
+ "long": { "enum": ["top", "bottom", "front", "back"], "description": "The side a mitred beam's length is measured on" },
114
+ "size": { "type": "array", "items": { "$ref": "#/$defs/expr" }, "minItems": 2, "maxItems": 2, "description": "A pocket's [along, across], mm" },
115
+ "outline": { "type": "array", "items": { "type": "array", "items": { "type": "number" }, "minItems": 2, "maxItems": 2 }, "minItems": 3, "description": "A pocket's outline, points [along, across] about the address" },
116
+ "radius": { "$ref": "#/$defs/expr", "description": "A pocket's corner radius, mm" },
117
+ "length": { "$ref": "#/$defs/expr", "description": "A notch's length along the beam, mm" } } },
118
+ "address": { "type": "string", "pattern": "^[a-z][\\w-]*(\\.[\\w-]+)+(@-?\\d+(\\.\\d+)?%?)?$", "description": "An anchor by name, <item>.<anchor>; on a beam an end (x1.a, x1.b), an end bore (x1.a.1), or a face with a distance from end a (x1.top@120), from end b (x1.top@-20) or a share of the length (x1.top@50%), the second slot of a face x1.top.2@120" },
98
119
  "fasten": {
99
120
  "type": "object",
121
+ "description": "A screwed joint: the screw by thread and head, the parts it passes in order, the part it ends in, and where the screws go (at, an anchor each, or holes, a part's own holes)",
100
122
  "required": ["screw", "through", "into"],
101
123
  "additionalProperties": false,
124
+ "defaultSnippets": [
125
+ { "label": "screws at anchors", "body": { "screw": "${1:M3 cap}", "through": ["${2:bracket}"], "into": "${3:base}", "at": ["${4:bracket.h1}", "${5:bracket.h2}"] } },
126
+ { "label": "screws in a part's own holes", "body": { "screw": "${1:M3 cap}", "through": ["${2:lid}"], "into": "${3:box}", "holes": "${4:lid.body}" } }
127
+ ],
102
128
  "properties": {
103
129
  "screw": { "type": "string", "description": "The screw, by its thread and head: M3 cap, M4 button, M3x12 countersunk, 6-32 UNC cap (the names @rulecad/fixings reads). With no length in the name, the shortest sold length that fits is chosen" },
104
130
  "through": { "type": "array", "items": { "type": "string" }, "description": "The parts the screw passes through, in order from under its head: items (bracket) or item.part (bracket.body). Each needs a clearance hole for the thread" },
@@ -13,7 +13,7 @@
13
13
  "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+" },
14
14
  "description": { "type": "string" },
15
15
  "note": { "type": "string" },
16
- "uses": { "type": "array", "items": { "type": "string" }, "description": "Rule sets (x1c, m3) and other objects (project/object, optionally @version)" },
16
+ "uses": { "type": "array", "items": { "type": "string" }, "description": "Rule sets (x1c, m3) and other objects (project/object, optionally @version). A screw's holes need none listed: v.fixings reads the thread's set, the printer and the material itself" },
17
17
  "material": { "type": "string" },
18
18
  "orientation": { "type": "string", "description": "How it sits on the bed, and anything the printer or the person assembling it should know" },
19
19
  "role": { "enum": ["part", "reference", "board"], "description": "reference: drawn faint and never printed (a switch, a tablet); board: a circuit board" },
@@ -48,7 +48,7 @@
48
48
  "required": ["value"],
49
49
  "additionalProperties": false,
50
50
  "properties": {
51
- "value": { "description": "A number, an expression (x1c.line * 3), or for typed variables a name or text", "type": ["number", "string", "boolean", "array", "object"] },
51
+ "value": { "description": "A number, an expression (x1c.line * 3), or for typed variables a name or text. A hole for a screw, a nut or an insert is no typed number: draw it with v.fixings in the .js (v.fixings.hole('M3', { kind: 'pilot' })), and say how parts screw together with a fasten in the assembly", "type": ["number", "string", "boolean", "array", "object"] },
52
52
  "unit": { "type": "string" },
53
53
  "rule": { "type": "string", "description": "Why the value is what it is" },
54
54
  "label": { "type": "string" },
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://jonibach.github.io/rulecad/schemas/outline.schema.json",
4
+ "title": "rulecad section outline",
5
+ "description": "A profile's measured section as closed loops, kept beside its rule set as rules/outlines/<set name>.json. The outside of the metal and each hole are loops of [x, y] points in mm, x across and y up, with the middle of the section's envelope at the origin. It says what it was measured from and under what licence: the kit draws its own outlines, so a maker's model is measured in your own workspace and its shape is never copied into the kit.",
6
+ "type": "object",
7
+ "required": ["source", "licence", "loops"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "$schema": { "type": "string" },
11
+ "_doc": { "type": "string" },
12
+ "name": { "type": "string", "description": "The rule set it belongs to" },
13
+ "unit": { "type": "string", "enum": ["mm"], "description": "Always mm" },
14
+ "source": { "type": "string", "description": "What it was measured from: a model's file and where that came from, or a bar and how it was measured" },
15
+ "licence": { "type": "string", "description": "The terms the source came with" },
16
+ "checked": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "The date it was measured, YYYY-MM-DD" },
17
+ "loops": {
18
+ "type": "array",
19
+ "minItems": 1,
20
+ "description": "Closed loops, the last point joining the first. Either way round: a loop inside an odd number of others is a hole",
21
+ "items": { "type": "array", "minItems": 3, "items": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "type": "number" } } }
22
+ }
23
+ }
24
+ }