@rulecad/cad 0.7.47 → 0.7.53
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 +20 -6
- package/EXAMPLES.md +347 -1
- package/README.md +61 -3
- package/bin/cad.mjs +19 -8
- package/lib/assembly.mjs +34 -10
- package/lib/design.mjs +44 -12
- package/lib/edit.mjs +12 -4
- package/lib/fasten.mjs +824 -0
- package/lib/fixings.mjs +42 -0
- package/lib/links.mjs +2 -1
- package/lib/list.mjs +27 -8
- package/lib/measured.mjs +49 -8
- package/lib/motors.mjs +48 -7
- package/lib/order.mjs +19 -5
- package/lib/preview/page.html +4 -2
- package/lib/preview.mjs +3 -2
- package/lib/sandbox-hooks.mjs +2 -2
- package/lib/sandbox-run.mjs +5 -3
- package/lib/sandbox.mjs +7 -5
- package/lib/sheet.mjs +86 -0
- package/package.json +5 -4
- package/schemas/assembly.schema.json +18 -0
- package/schemas/rules.schema.json +2 -2
package/lib/sheet.mjs
CHANGED
|
@@ -172,7 +172,93 @@ function beltDrawing(set) {
|
|
|
172
172
|
return sheet(set, pens, W, H);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
// A thread set: the screw in each head form it has, its nuts and washer from above and from the side, and its holes,
|
|
176
|
+
// every one dimensioned from the set's own figures, to hold against the standard's table. Seats are level across the
|
|
177
|
+
// row: a head stands above the line, a countersunk head sits under it, and a length runs from that line to the tip.
|
|
178
|
+
function threadDrawing(set) {
|
|
179
|
+
const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0), has = (k) => n(k) > 0, says = (k) => String(set.rules[k]?.value ?? '');
|
|
180
|
+
const d = n('major_diameter'), P = n('pitch'), lengths = Array.isArray(set.rules.lengths?.value) ? set.rules.lengths.value : [];
|
|
181
|
+
const L = lengths.find((l) => l >= 2.5 * d) ?? lengths.at(-1) ?? 3 * d; // a length it is sold in, near three diameters
|
|
182
|
+
const heads = [
|
|
183
|
+
has('head') && { name: 'socket cap', form: 'cap', D: n('head'), k: n('head_height'), key: n('head_key') },
|
|
184
|
+
has('button_head') && { name: 'button', form: 'button', D: n('button_head'), k: n('button_head_height'), key: n('button_key') },
|
|
185
|
+
has('countersunk_head') && { name: `countersunk ${fig(n('countersunk_angle'))}°`, form: 'countersunk', D: n('countersunk_head'), k: n('countersunk_head_height') || (n('countersunk_head') - d) / 2 / Math.tan((n('countersunk_angle') * Math.PI) / 360), key: n('countersunk_key') },
|
|
186
|
+
has('hex_head_flats') && { name: 'hexagon', form: 'hex', D: n('hex_head_flats'), k: n('hex_head_height'), note: 'across flats' },
|
|
187
|
+
has('pan_head') && { name: 'pan', form: 'pan', D: n('pan_head'), k: n('pan_head_height'), note: says('pan_head_drive') },
|
|
188
|
+
].filter(Boolean);
|
|
189
|
+
if (!heads.length) heads.push({ name: 'thread', form: 'stud', D: d, k: 0 });
|
|
190
|
+
const nuts = [
|
|
191
|
+
has('nut_flats') && { name: 'hexagon nut', s: n('nut_flats'), m: n('nut_height'), sides: 6 },
|
|
192
|
+
has('square_nut_flats') && { name: 'square nut', s: n('square_nut_flats'), m: n('square_nut_height'), sides: 4 },
|
|
193
|
+
has('lock_nut_height') && { name: 'lock nut', s: n('lock_nut_flats') || n('nut_flats'), m: n('lock_nut_height'), sides: 6 },
|
|
194
|
+
has('washer_diameter') && { name: 'washer', s: n('washer_diameter'), m: n('washer_thickness'), bore: n('washer_bore') },
|
|
195
|
+
].filter(Boolean);
|
|
196
|
+
const holes = [['tap drill', 'tap_drill'], ['close', 'clearance_close'], ['normal', 'clearance'], ['loose', 'clearance_loose'], ['pilot in plastic', 'pilot'], ['insert hole', 'insert_hole']].filter(([, k]) => has(k)).map(([name, k]) => ({ name, D: n(k), ring: k === 'insert_hole' ? n('insert_diameter') : k === 'pilot' ? n('pilot_boss') : k.startsWith('clearance') ? d : 0 })); // (dashed round a hole: an insert's knurls, a pilot's boss; grey inside one: the thread passing through)
|
|
197
|
+
const widest = Math.max(d, ...heads.map((h) => h.D), ...nuts.map((x) => x.s), ...holes.map((h) => Math.max(h.D, h.ring))), S = Math.max(3, Math.min(16, 90 / widest));
|
|
198
|
+
const col = widest * S + 84, count = Math.max(heads.length, nuts.length, 3), X = (i) => 60 + col * (i + 0.5);
|
|
199
|
+
const big = Math.max(0, ...holes.map((h) => Math.max(h.D, h.ring))) * S, holeCol = Math.max(big + 64, Math.min(col, (count * col) / Math.max(holes.length, 1))), HX = (i) => 60 + holeCol * (i + 0.5); // (holes are small: their row is spaced closer, so six fit under four screws)
|
|
200
|
+
const W = Math.max(count * col, holes.length * holeCol) + 80;
|
|
201
|
+
const pens = pen(), { out, line, circle, rect, text, span } = pens, poly = (pts, fill = FILL) => out.push(`<polygon points="${pts.map(([a, b]) => `${fig(a)},${fig(b)}`).join(' ')}" fill="${fill}" stroke="${INK}" stroke-width="1.2"/>`);
|
|
202
|
+
// ---- the screws, from the side ----
|
|
203
|
+
const maxK = Math.max(...heads.map((h) => (h.form === 'countersunk' ? 0 : h.k))), yFace = 92 + maxK * S, yTip = yFace + L * S, root = (has('root_diameter') ? (d - n('root_diameter')) / 2 : 0.6134 * P) * S; // (its root where the set gives one; else an external thread is 0.6134 of its pitch deep: ISO 68-1)
|
|
204
|
+
heads.forEach((h, i) => {
|
|
205
|
+
const cx = X(i), r = (h.D / 2) * S, kS = h.k * S, sunk = h.form === 'countersunk', top = sunk ? yFace : yFace - kS, under = sunk ? yFace + kS : yFace;
|
|
206
|
+
rect(cx - (d / 2) * S, under, d * S, yTip - under, METAL);
|
|
207
|
+
for (const side of [-1, 1]) line(cx + side * ((d / 2) * S - root), under + 2, cx + side * ((d / 2) * S - root), yTip, THIN, 0.6, '4 3');
|
|
208
|
+
if (h.form === 'cap' || h.form === 'hex') rect(cx - r, top, 2 * r, kS, METAL);
|
|
209
|
+
if (h.form === 'pan') out.push(`<rect x="${fig(cx - r)}" y="${fig(top)}" width="${fig(2 * r)}" height="${fig(kS)}" rx="${fig(Math.min(kS, r) * 0.45)}" fill="${METAL}" stroke="${INK}" stroke-width="1.2"/>`);
|
|
210
|
+
if (h.form === 'button') { const R = (r * r + kS * kS) / (2 * kS); out.push(`<path d="M ${fig(cx - r)} ${fig(yFace)} A ${fig(R)} ${fig(R)} 0 0 1 ${fig(cx + r)} ${fig(yFace)} Z" fill="${METAL}" stroke="${INK}" stroke-width="1.2"/>`); }
|
|
211
|
+
if (sunk) poly([[cx - r, top], [cx + r, top], [cx + (d / 2) * S, under], [cx - (d / 2) * S, under]], METAL);
|
|
212
|
+
if (h.key) { const kw = (h.key / 2) * S, deep = Math.min(kS * 0.6, h.key * S); for (const side of [-1, 1]) line(cx + side * kw, top, cx + side * kw, top + deep, THIN, 0.7, '3 2'); line(cx - kw, top + deep, cx + kw, top + deep, THIN, 0.7, '3 2'); }
|
|
213
|
+
if (h.form !== 'stud') span(cx - r, top - 6, cx + r, top - 6, `${h.form === 'hex' ? '' : 'Ø'}${fig(h.D)}`, -14);
|
|
214
|
+
if (h.k) span(cx + r + 6, top, cx + r + 6, top + kS, fig(h.k), 12);
|
|
215
|
+
if (i === 0) { span(cx - (d / 2) * S, yTip + 6, cx + (d / 2) * S, yTip + 6, `Ø${fig(d)}`, 14); span(cx - Math.max(r, (d / 2) * S) - 6, yFace, cx - Math.max(r, (d / 2) * S) - 6, yTip, fig(L), -14); }
|
|
216
|
+
text(cx, yTip + 58, h.name);
|
|
217
|
+
const under2 = [h.key ? `key ${fig(h.key)}` : '', h.note || ''].filter(Boolean).join(', ');
|
|
218
|
+
if (under2) text(cx, yTip + 74, under2, 'middle', 11);
|
|
219
|
+
});
|
|
220
|
+
line(40, yFace, W - 40, yFace, THIN, 0.5, '8 3 2 3');
|
|
221
|
+
// ---- nuts and the washer: from above, then from the side ----
|
|
222
|
+
const tall = Math.max(0, ...nuts.map((x) => (x.sides === 6 ? x.s * 2 / Math.sqrt(3) : x.s))) * S, yPlan = yTip + 104 + tall / 2, ySide = yPlan + tall / 2 + 48, maxM = Math.max(0, ...nuts.map((x) => x.m)) * S;
|
|
223
|
+
nuts.forEach((x, i) => {
|
|
224
|
+
const cx = X(i), r = (x.s / 2) * S, across = x.sides === 6 ? x.s * S / Math.sqrt(3) : r;
|
|
225
|
+
if (x.sides === 6) poly([[r, across / 2], [0, across], [-r, across / 2], [-r, -across / 2], [0, -across], [r, -across / 2]].map(([a, b]) => [cx + a, yPlan + b]));
|
|
226
|
+
else if (x.sides === 4) rect(cx - r, yPlan - r, 2 * r, 2 * r);
|
|
227
|
+
else circle(cx, yPlan, r, FILL);
|
|
228
|
+
circle(cx, yPlan, ((x.bore || d) / 2) * S, '#fff');
|
|
229
|
+
span(cx - r, yPlan + tall / 2 + 4, cx + r, yPlan + tall / 2 + 4, `${x.sides ? '' : 'Ø'}${fig(x.s)}`, 14);
|
|
230
|
+
const half = x.sides === 6 ? across : r;
|
|
231
|
+
rect(cx - half, ySide, 2 * half, x.m * S, METAL);
|
|
232
|
+
span(cx + half + 6, ySide, cx + half + 6, ySide + x.m * S, fig(x.m), 12);
|
|
233
|
+
text(cx, ySide + maxM + 20, x.name);
|
|
234
|
+
if (x.bore) text(cx, ySide + maxM + 36, `hole Ø${fig(x.bore)}`, 'middle', 11);
|
|
235
|
+
else if (x.sides) text(cx, ySide + maxM + 36, 'across flats', 'middle', 11);
|
|
236
|
+
});
|
|
237
|
+
// ---- the holes ----
|
|
238
|
+
const yHole = (nuts.length ? ySide + maxM + 62 : yTip + 104) + big / 2;
|
|
239
|
+
holes.forEach((h, i) => {
|
|
240
|
+
const cx = HX(i);
|
|
241
|
+
if (h.ring > h.D) out.push(`<circle cx="${fig(cx)}" cy="${fig(yHole)}" r="${fig((h.ring / 2) * S)}" fill="none" stroke="${THIN}" stroke-width="0.8" stroke-dasharray="4 3"/>`);
|
|
242
|
+
circle(cx, yHole, (h.D / 2) * S, '#fff');
|
|
243
|
+
if (h.ring && h.ring < h.D) out.push(`<circle cx="${fig(cx)}" cy="${fig(yHole)}" r="${fig((h.ring / 2) * S)}" fill="${METAL}" stroke="${THIN}" stroke-width="0.8"/>`);
|
|
244
|
+
span(cx - (h.D / 2) * S, yHole + big / 2 + 4, cx + (h.D / 2) * S, yHole + big / 2 + 4, `Ø${fig(h.D)}`, 14);
|
|
245
|
+
text(cx, yHole + big / 2 + 50, h.name);
|
|
246
|
+
});
|
|
247
|
+
// ---- what a drawing can't show ----
|
|
248
|
+
const notes = [
|
|
249
|
+
`${says('thread')}, ${says('thread_form')}: pitch ${fig(P)}${has('pitch_fine') ? `, fine ${fig(n('pitch_fine'))}` : ''}${has('set_screw_key') ? `, set screw key ${fig(n('set_screw_key'))}` : ''}${says('thread_form') === 'unified' ? ' (divide by 25.4 for the inch table)' : ''}`,
|
|
250
|
+
lengths.length ? `socket cap lengths: ${lengths.map(fig).join(', ')}` : '',
|
|
251
|
+
has('proof_stress') ? `${has('property_class') ? `class ${fig(n('property_class'))}: ` : ''}proof stress ${fig(n('proof_stress'))} MPa${has('stainless_proof_stress') ? `; ${says('stainless_class')}: ${fig(n('stainless_proof_stress'))} MPa` : ''}` : '',
|
|
252
|
+
has('insert_hole') ? `insert${has('insert_diameter') ? ` Ø${fig(n('insert_diameter'))}` : ''}${has('insert_length') ? ` × ${fig(n('insert_length'))} long` : ''} (dashed) in a Ø${fig(n('insert_hole'))} hole${has('insert_taper') ? `, tapered ${fig(n('insert_taper'))}°` : ''}${has('insert_wall') ? `, ${fig(n('insert_wall'))} of wall round it at least` : ''}` : '',
|
|
253
|
+
has('pilot') ? `pilot Ø${fig(n('pilot'))}${has('pilot_depth') ? `, ${fig(n('pilot_depth'))} deep at least` : ''}${has('pilot_boss') ? `, in a boss of Ø${fig(n('pilot_boss'))} at least (dashed)` : ''}: a starting figure, your printer's measured one comes first` : '',
|
|
254
|
+
].filter(Boolean);
|
|
255
|
+
const yNotes = (holes.length ? yHole + big / 2 + 80 : nuts.length ? ySide + maxM + 66 : yTip + 104);
|
|
256
|
+
notes.forEach((t, i) => text(40, yNotes + i * 17, t, 'start', 11));
|
|
257
|
+
return sheet(set, pens, Math.max(W, 620), yNotes + notes.length * 17 - 50);
|
|
258
|
+
}
|
|
259
|
+
|
|
175
260
|
export function drawing(set, vocab) {
|
|
261
|
+
if (set.part === 'thread') return threadDrawing(set);
|
|
176
262
|
if (set.part === 'bearing') return bearingDrawing(set);
|
|
177
263
|
if (set.part === 'driver') return driverDrawing(set);
|
|
178
264
|
const v = (k) => set.rules[k]?.value ?? 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.53",
|
|
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": {
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"url": "https://github.com/JoniBach/rulecad/issues"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@rulecad/variables": "^0.3.
|
|
60
|
+
"@rulecad/variables": "^0.3.4",
|
|
61
61
|
"@rulecad/keyboard-layout": "^0.1.2",
|
|
62
62
|
"@rulecad/printcheck": "^0.3.0",
|
|
63
63
|
"@rulecad/fit": "^0.4.0",
|
|
64
64
|
"@rulecad/model-link": "^0.3.2",
|
|
65
|
-
"@rulecad/versions": "^0.1.
|
|
65
|
+
"@rulecad/versions": "^0.1.6",
|
|
66
66
|
"@rulecad/shapes": "^0.4.4",
|
|
67
|
-
"@rulecad/rules": "^0.3.
|
|
67
|
+
"@rulecad/rules": "^0.3.12",
|
|
68
68
|
"@jscad/modeling": "^2.12.0",
|
|
69
69
|
"three": "^0.186.1",
|
|
70
70
|
"@rulecad/fea": "^0.2.1",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"@rulecad/flexures": "^0.5.0",
|
|
73
73
|
"@rulecad/gears": "^0.3.2",
|
|
74
74
|
"@rulecad/motors": "^0.1.4",
|
|
75
|
+
"@rulecad/fixings": "^0.1.3",
|
|
75
76
|
"@rulecad/robots": "^0.1.1"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
@@ -17,6 +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
21
|
"joints": { "type": "array", "items": { "$ref": "#/$defs/joint" } },
|
|
21
22
|
"loops": { "type": "array", "items": { "$ref": "#/$defs/loop" } },
|
|
22
23
|
"planetary": { "type": "array", "items": { "$ref": "#/$defs/planetary" } },
|
|
@@ -94,6 +95,23 @@
|
|
|
94
95
|
"within": { "$ref": "#/$defs/expr", "description": "With an anchor name (item@anchor): only faces this close to it (mm, default 10)" }
|
|
95
96
|
}
|
|
96
97
|
},
|
|
98
|
+
"fasten": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"required": ["screw", "through", "into"],
|
|
101
|
+
"additionalProperties": false,
|
|
102
|
+
"properties": {
|
|
103
|
+
"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
|
+
"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" },
|
|
105
|
+
"into": { "type": "string", "description": "The part the screw ends in: a pilot, a tapped or printed thread, an insert's hole or a nut's seat there, or a clearance hole with nut" },
|
|
106
|
+
"at": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/anchorRef" }, "description": "One screw at each anchor: a point on its axis (bracket.h1), the anchor's axis along the screw" },
|
|
107
|
+
"holes": { "type": "string", "description": "In place of at: a part whose holes are the screws' places, found in the part as drawn (a circuit board: its mounting holes)" },
|
|
108
|
+
"nut": { "anyOf": [{ "type": "boolean" }, { "type": "string" }], "description": "What holds the screw where the part it ends in does not: true or hex, square, lock. It sits on that part's far face, or in a nut's seat drawn there" },
|
|
109
|
+
"washer": { "type": "boolean", "description": "A plain washer under the head" },
|
|
110
|
+
"length": { "$ref": "#/$defs/expr", "description": "The screw's length in mm, where the name gives none: checked for reaching, bottoming out and standing proud" },
|
|
111
|
+
"torque": { "$ref": "#/$defs/expr", "description": "The tightening torque, N m: the pressure under the head is then held against the material it sits on (fasten.seat)" },
|
|
112
|
+
"note": { "type": "string" }
|
|
113
|
+
}
|
|
114
|
+
},
|
|
97
115
|
"anchorRef": {
|
|
98
116
|
"anyOf": [
|
|
99
117
|
{ "type": "string", "description": "item.anchor" },
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"description": { "type": "string" },
|
|
14
14
|
"licence": { "type": "string" },
|
|
15
15
|
"private": { "type": "boolean" },
|
|
16
|
-
"part": { "type": "string", "description": "What sort of part it describes (motor): its names come from vocabulary.json, and cad rules check holds it to them" },
|
|
16
|
+
"part": { "type": "string", "description": "What sort of part it describes (motor, bearing, thread): its names come from vocabulary.json, and cad rules check holds it to them" },
|
|
17
17
|
"interface": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Which rule is which shared name in vocabulary.json, for a set that keeps its own names" },
|
|
18
18
|
"variants": { "type": "object", "description": "A maker's part numbers for this part, each the rules that differ: { \"17HS4401\": { \"kind\", \"source\", \"values\": { \"body_length\": 40 } } }" },
|
|
19
19
|
"footprints": { "type": "object" },
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"required": ["value"],
|
|
26
26
|
"additionalProperties": false,
|
|
27
27
|
"properties": {
|
|
28
|
-
"value": { "type": ["number", "string"] },
|
|
28
|
+
"value": { "type": ["number", "string", "array"], "minItems": 1, "items": { "type": ["number", "string"] }, "description": "A number, an expression, text, or a list of numbers or expressions in the rule's one unit (the lengths a screw is sold in)" },
|
|
29
29
|
"unit": { "type": "string" },
|
|
30
30
|
"rule": { "type": "string" },
|
|
31
31
|
"kind": { "type": "string", "description": "How far to trust it, most to least: measured, spec, community, default, derived, estimate" },
|