@rulecad/cad 0.7.55 → 0.7.57
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 +73 -7
- package/CHANGELOG.md +149 -0
- package/EXAMPLES.md +942 -268
- package/README.md +366 -16
- package/TUTORIAL.md +27 -15
- package/bin/cad.mjs +54 -14
- package/lib/assembly.mjs +75 -16
- package/lib/beams.mjs +2 -2
- package/lib/bought.mjs +41 -5
- package/lib/buildpage.mjs +8 -3
- package/lib/design.mjs +6 -4
- package/lib/edit.mjs +36 -5
- package/lib/fasten.mjs +322 -55
- package/lib/fittings.mjs +271 -0
- package/lib/framebuild.mjs +407 -0
- package/lib/frames.mjs +4 -3
- package/lib/guides.mjs +354 -0
- package/lib/jigs.mjs +237 -0
- package/lib/joins.mjs +259 -0
- package/lib/jsonedit.mjs +19 -0
- package/lib/list.mjs +24 -8
- package/lib/loads.mjs +9 -2
- package/lib/measured.mjs +64 -17
- package/lib/motors.mjs +28 -13
- package/lib/order.mjs +23 -12
- package/lib/panels.mjs +220 -0
- package/lib/plates.mjs +11 -4
- package/lib/schema.mjs +3 -2
- package/lib/services.mjs +132 -0
- package/lib/sheet.mjs +20 -3
- package/lib/slotnuts.mjs +159 -0
- package/lib/task.mjs +4 -2
- package/lib/wires.mjs +2 -1
- package/package.json +8 -7
- package/schemas/assembly.schema.json +41 -14
- package/schemas/object.schema.json +2 -2
package/TUTORIAL.md
CHANGED
|
@@ -73,7 +73,7 @@ npx cad new home/hook
|
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
That makes `projects/home/objects/hook.json` and `hook.js` from a template. Replace the `.json` with the hook's
|
|
76
|
-
variables. The screw's
|
|
76
|
+
variables. The screw's hole comes from the shape below, which asks `v.fixings` for it by the screw's thread:
|
|
77
77
|
|
|
78
78
|
```json projects/home/objects/hook.json
|
|
79
79
|
{
|
|
@@ -81,33 +81,37 @@ variables. The screw's sizes come from the `m4` rule set, which is copied into `
|
|
|
81
81
|
"name": "hook",
|
|
82
82
|
"title": "Wall hook",
|
|
83
83
|
"version": "0.1.0",
|
|
84
|
-
"uses": ["x1c"
|
|
84
|
+
"uses": ["x1c"],
|
|
85
85
|
"material": "PETG",
|
|
86
86
|
"orientation": "On its side, so the layers run along the arm and it can't snap off across them.",
|
|
87
87
|
"variables": {
|
|
88
88
|
"width": { "value": 20, "unit": "mm", "rule": "Wide enough for a coat's loop", "label": "Width", "show": true, "tweak": { "min": 10, "max": 60 } },
|
|
89
89
|
"plate": { "value": 50, "unit": "mm", "rule": "The back plate: room for a screw above the arm", "label": "Plate", "show": true },
|
|
90
90
|
"reach": { "value": 30, "unit": "mm", "rule": "How far the arm stands out from the wall", "label": "Reach", "show": true, "tweak": { "min": 15, "max": 60 } },
|
|
91
|
-
"thick": { "value": "x1c.line * 10", "unit": "mm", "rule": "Ten print lines: stiff enough for a coat" }
|
|
92
|
-
"hole": { "value": "m4.clearance + x1c.hole_comp", "unit": "mm", "rule": "An M4 screw's clearance hole, widened for how holes print", "interface": true }
|
|
91
|
+
"thick": { "value": "x1c.line * 10", "unit": "mm", "rule": "Ten print lines: stiff enough for a coat" }
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
```
|
|
96
95
|
|
|
97
96
|
Then the shape. `main(v)` gets the variables as `v`, with the rule sets (`v.x1c.line`), print-aware shapes
|
|
98
|
-
(`v.shapes`) and booleans (`v.ops`). Z is up and the bed is z = 0: draw the
|
|
97
|
+
(`v.shapes`), screws, nuts and inserts (`v.fixings`) and booleans (`v.ops`). Z is up and the bed is z = 0: draw the
|
|
98
|
+
part the way it will print.
|
|
99
|
+
|
|
100
|
+
`v.fixings.hole('M4', ...)` is a clearance hole for an M4 screw, sized from the `m4` rule set: 4.5 mm, the normal
|
|
101
|
+
clearance ISO 273 gives, plus the printer's `x1c.hole_comp` (0.1 mm), since a printed hole comes out small. Lying on
|
|
102
|
+
its side, it is drawn as a teardrop, so its roof needs no support. The check says what it was drawn to.
|
|
99
103
|
|
|
100
104
|
```js projects/home/objects/hook.js
|
|
101
|
-
// A wall hook: a back plate with a screw
|
|
105
|
+
// A wall hook: a back plate with a hole for an M4 screw, and an arm. It lies on its side to print (z is its width).
|
|
102
106
|
import jscad from '@jscad/modeling'
|
|
103
107
|
const { cuboid } = jscad.primitives
|
|
104
108
|
|
|
105
109
|
export function main (v) {
|
|
106
110
|
const plate = cuboid({ size: [v.plate, v.thick, v.width], center: [0, v.thick / 2, v.width / 2] })
|
|
107
111
|
const arm = cuboid({ size: [v.thick, v.reach, v.width], center: [(v.thick - v.plate) / 2, v.thick + v.reach / 2, v.width / 2] })
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
const screw = v.
|
|
112
|
+
// the screw's hole across the part as it prints, from the plate's face out through its back: v.fixings sizes it
|
|
113
|
+
// from the thread's rule set and draws it as a teardrop, so its roof needs no support
|
|
114
|
+
const screw = v.fixings.hole('M4', { depth: v.thick, at: [v.plate / 2 / 2, v.thick, v.width / 2], into: '-y' })
|
|
111
115
|
return v.ops.subtract(v.ops.union(plate, arm), screw)
|
|
112
116
|
}
|
|
113
117
|
```
|
|
@@ -129,7 +133,8 @@ The check names mistakes rather than drawing something else. The ones everyone m
|
|
|
129
133
|
|---|---|
|
|
130
134
|
| a number in the `.js`: `v.plate / 4` | `numbers in hook.js that should be variables: line 10: 4` |
|
|
131
135
|
| a variable that isn't there: `v.thik` | `v.thik: the design has no variable "thik" (did you mean "thick"?)` |
|
|
132
|
-
| a rule that isn't there: `
|
|
136
|
+
| a rule that isn't there: `x1c.lien` | `"x1c.lien": no rule "lien" in x1c (hook.json: variables.thick.value)` |
|
|
137
|
+
| a thread that isn't there: `v.fixings.hole('M44', ...)` | `fixingModel: no thread "M44" (did you mean M4?)`, with the threads there are |
|
|
133
138
|
| a misspelt key in the `.json`: `"lable"` | `variables.thick.lable: not allowed here (did you mean "label"?)` |
|
|
134
139
|
| nothing returned from `main` | `main() returned no shape: return a JSCAD solid, or named parts` |
|
|
135
140
|
|
|
@@ -153,7 +158,6 @@ npx cad new home/screw
|
|
|
153
158
|
"version": "0.1.0",
|
|
154
159
|
"role": "reference",
|
|
155
160
|
"variables": {
|
|
156
|
-
"d": { "value": 4, "unit": "mm", "rule": "An M4 screw's thread", "interface": true },
|
|
157
161
|
"length": { "value": 16, "unit": "mm", "rule": "Long enough to go through the plate into a wall plug" },
|
|
158
162
|
"sides": { "value": 32, "rule": "Sides drawn round the shank" }
|
|
159
163
|
}
|
|
@@ -161,11 +165,13 @@ npx cad new home/screw
|
|
|
161
165
|
```
|
|
162
166
|
|
|
163
167
|
```js projects/home/objects/screw.js
|
|
164
|
-
// An M4 screw's shank, lying along y: something the hook fits, not something to print.
|
|
168
|
+
// An M4 screw's shank, lying along y: something the hook fits, not something to print. Its diameter is the thread's
|
|
169
|
+
// own, from the same rule set as the hook's hole.
|
|
165
170
|
import jscad from '@jscad/modeling'
|
|
166
171
|
|
|
167
172
|
export function main (v) {
|
|
168
|
-
|
|
173
|
+
const thread = v.fixings.fixingModel('M4')
|
|
174
|
+
return jscad.transforms.rotateX(Math.PI / 2, jscad.primitives.cylinder({ radius: thread.major / 2, height: v.length, segments: v.sides }))
|
|
169
175
|
}
|
|
170
176
|
```
|
|
171
177
|
|
|
@@ -199,8 +205,12 @@ Hook on its screw (fit: hook 0.1.0, screw 0.1.0)
|
|
|
199
205
|
✓ The screw in its hole: closest gap 0.295 mm
|
|
200
206
|
```
|
|
201
207
|
|
|
202
|
-
|
|
203
|
-
shape from them, and a check against the thing it meets.
|
|
208
|
+
Ask `v.fixings` for an M3 hole in the hook and the check fails with the number: the M4 screw overlaps it. That is
|
|
209
|
+
the loop: rules, a shape from them, and a check against the thing it meets.
|
|
210
|
+
|
|
211
|
+
A screw that holds printed parts to each other gets more than a fit: a `fasten` says which parts it passes through
|
|
212
|
+
and what it ends in, and the check chooses its length, finds its holes, and puts it on the shopping list. The worked
|
|
213
|
+
examples screw a board into its case with one (chapter 6) and explain it in full in chapter 15.
|
|
204
214
|
|
|
205
215
|
## 7. Share it
|
|
206
216
|
|
|
@@ -224,3 +234,5 @@ commands to run, tested the same way as this page. Each is also a section of [th
|
|
|
224
234
|
- **Optimised parts**: the stiffest layout for a load, and an analysis of what you drew.
|
|
225
235
|
- **Boards**: circuit boards from the same rules as the case around them.
|
|
226
236
|
- **Mechanisms printed flat**: springs, catches and triggers in one print, checked through their whole cycle.
|
|
237
|
+
- **Frames**: beams of an aluminium profile placed by their ends, joined, with feet and a motor-driven axis, cut,
|
|
238
|
+
drilled and printed on one plate (chapter 16).
|
package/bin/cad.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { schemaFindings } from '../lib/schema.mjs';
|
|
|
20
20
|
import { readJson } from '../lib/host.mjs';
|
|
21
21
|
import { optimised, readProblem, analysePart, picture, problemFile } from '../lib/optimise.mjs';
|
|
22
22
|
import { evaluate } from '../lib/rules.mjs';
|
|
23
|
-
import { setVariables, addToAssembly, parseValue } from '../lib/edit.mjs';
|
|
23
|
+
import { setVariables, addToAssembly, fastenFromFitsEdit, parseValue } from '../lib/edit.mjs';
|
|
24
24
|
import { setAt } from '../lib/jsonedit.mjs';
|
|
25
25
|
import { threemf, slotOf } from '../lib/threemf.mjs';
|
|
26
26
|
import { liveView } from '../lib/live.mjs';
|
|
@@ -47,7 +47,8 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
47
47
|
cad agents AGENTS.md: how an AI agent should design in this workspace
|
|
48
48
|
cad trust allow what this workspace's cad.config.json asks (no sandbox, its own targets)
|
|
49
49
|
cad rules <project>/<object> every variable: value, the rule behind it, its source
|
|
50
|
-
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]
|
|
50
|
+
cad rules check [set …] rule sets held to what makes them traceable (exit 1 on a failure) [--json]; notes,
|
|
51
|
+
never failures: an alias in "interface", and what the kit's set has that your copy lacks
|
|
51
52
|
cad rules draw <set> a dimension drawing of what a set says a part mounts by, <set>.svg, to compare with its datasheet [--out file]
|
|
52
53
|
cad rules draft <name> --from <file.pdf> the figures in a datasheet's text, into rules/<name>.json for you to name and check (all kind estimate)
|
|
53
54
|
cad rules draft profile|slot|slot_nut <name> every field a beam's profile, a slot family or a slot nut has, to fill from its sheet
|
|
@@ -57,6 +58,10 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
57
58
|
cad add fasten <project>/<assembly> --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2
|
|
58
59
|
a screwed joint (or --holes bracket.body for the part's own holes) [--nut [hex|square|lock]]
|
|
59
60
|
[--washer] [--length 12] [--torque 0.5] [--note …]
|
|
61
|
+
cad add fasten <project>/<assembly> --from-fits a fasten in place of a holes fit and a fit that fastens the same parts
|
|
62
|
+
(the screw read from them, or --screw "M2 cap")
|
|
63
|
+
cad add join <project>/<assembly> --kind blind --a y1.a --b x1.back@120 two beams joined: the end of a against b's face
|
|
64
|
+
[--screw "M5 button"] [--fitting printed|<bought set>] [--note …]
|
|
60
65
|
cad why <project>/<object>.<name> what a value reads, down to the rules and their sources [--json] [--depth N]
|
|
61
66
|
cad check <project>/<object> raw numbers in the design, then printability (exit 1 on a failure) [--json: findings as data]
|
|
62
67
|
cad preview <project>/<object> six views as a PNG in .preview/ (prints the path); an assembly with a motor also gets
|
|
@@ -90,10 +95,12 @@ const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
|
|
|
90
95
|
cad machine <project>/<assembly> the machine as plain data: axes, steps, limits, homing, the task, in exports/
|
|
91
96
|
cad plot <project>/<assembly> <drawing.svg> plans a drawing on the machine: a step file in exports/, an animation in
|
|
92
97
|
.preview/, and any stroke refused [--calibrate: the calibration drawing] [--tol 0.1] [--json]
|
|
93
|
-
cad order <project>/<assembly> the order it goes together in, each step with its fasteners [--preview: an exploded picture of each step in .preview/]
|
|
98
|
+
cad order <project>/<assembly> the order it goes together in, each step with its fasteners; a frame from bars to square: cut, drill, sides built flat, nuts to load, joins with their torque, diagonals [--preview: an exploded picture of each step in .preview/]
|
|
94
99
|
cad plates <project>/<assembly> every printed part on beds, by filament, spaced by the first-layer rule: written as plate assemblies and checked; a changed part re-packs only its plate [--gap mm] [--json]
|
|
95
100
|
cad list <project>/<assembly> what it takes to build: bought parts by set, the beams' cut list and bars to buy, every screw, nut and insert in packs, wire, printed parts in grams
|
|
96
101
|
cad beams <project>/<assembly> a cut-and-drill sheet for each mark of beam (beams that are the same share one), to scale, written to exports/ [--json]
|
|
102
|
+
--jigs: the jigs its beams take, as a plate in exports/ (a drill guide per distinct hole across a beam, a tap
|
|
103
|
+
guide per tapped end, a cut-length stop per length, a squaring corner per square join), each marked with its beam [--preview]
|
|
97
104
|
cad wires <project>/<assembly> the wiring sheet: each wire's length, gauge and ends, written to exports/ [--out wiring.md]
|
|
98
105
|
cad measured <project>/<assembly> <name>=<value> … a measurement, where the estimate was: a rule (x1c.press=0.08) or a
|
|
99
106
|
check's prediction (task.accuracy=0.8): says what moved, and keeps a ledger of predicted
|
|
@@ -136,18 +143,19 @@ const COMMANDS = ['new', 'import-kle', 'clone', 'agents', 'trust', 'rules', 'val
|
|
|
136
143
|
const OPTIONS = ['table', 'calibrate', 'check', 'turns', 'preview', 'gap', 'no-steps', 'all', 'along', 'at', 'bump', 'depth', 'dry-run', 'explode', 'force', 'fresh', 'json', 'licence', 'license', 'long', 'm', 'material', 'md', 'name', 'new',
|
|
137
144
|
'no-models', 'no-pictures', 'no-rules', 'note', 'open', 'part', 'place', 'pose', 'profile', 'progress', 'push', 'result', 'rules', 'samples', 'set', 'short', 'source', 'steps',
|
|
138
145
|
'sweep', 'tol', 'trailer', 'ttl', 'version', 'watch', 'line',
|
|
139
|
-
'unit', 'rule', 'label', 'from', 'out', // cad set, cad rules
|
|
146
|
+
'unit', 'rule', 'label', 'from', 'out', 'jigs', // cad set, cad rules, cad beams
|
|
140
147
|
'a', 'b', 'min', 'max', 'poses', 'id', 'type', 'parent', 'child', 'follow', 'value', 'ratio', 'object', 'assembly', 'variant', 'rotate', 'to', 'roll', // cad add
|
|
141
|
-
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque'
|
|
148
|
+
'screw', 'through', 'into', 'holes', 'nut', 'washer', 'length', 'torque', 'from-fits', // cad add fasten
|
|
149
|
+
'kind', 'fitting']; // cad add join
|
|
142
150
|
// What a command takes, where that isn't <project>/<object>
|
|
143
|
-
const USAGE = { add: 'fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
151
|
+
const USAGE = { add: 'fit|joint|item|beam|loop|pose|fasten|join <project>/<assembly> --key value …', why: '<project>/<object>.<variable>', set: '<project>/<object> name=value …',
|
|
144
152
|
optimise: '<project>/<problem>', optimize: '<project>/<problem>', history: '<project>[/<object>]', release: '<project>[/<object>] -m "what changed"',
|
|
145
153
|
diff: '<project>/<object> <from> [<to>]', compare: '<project>/<object> <a> <b>', match: '<project>/<object> <model.stl|model.3mf>', clone: '<board.kicad_pcb | GitHub link> <name>' };
|
|
146
154
|
|
|
147
155
|
const args = process.argv.slice(2);
|
|
148
156
|
// Options that stand alone. Every other takes the value after it: --name value, or -m for one-letter names
|
|
149
157
|
// (--sweep, --watch and --nut take one or not).
|
|
150
|
-
const FLAGS = ['table', 'calibrate', 'check', 'preview', 'no-steps', 'all', 'dry-run', 'explode', 'force', 'fresh', 'json', 'long', 'md', 'new', 'no-models', 'no-pictures', 'no-rules', 'open', 'progress', 'push', 'short', 'washer'];
|
|
158
|
+
const FLAGS = ['table', 'calibrate', 'check', 'preview', 'no-steps', 'all', 'dry-run', 'explode', 'force', 'fresh', 'json', 'long', 'md', 'new', 'no-models', 'no-pictures', 'no-rules', 'open', 'progress', 'push', 'short', 'washer', 'from-fits', 'jigs'];
|
|
151
159
|
const opt = (k) => {
|
|
152
160
|
const i = args.findIndex((a) => a === `--${k}` || (k.length === 1 && a === `-${k}`));
|
|
153
161
|
if (i < 0) return undefined;
|
|
@@ -349,9 +357,15 @@ function ruleSheets(what, names) {
|
|
|
349
357
|
if (what === 'check') {
|
|
350
358
|
// a set fails on a finding of level fail; a warning or a note is said and the set still passes
|
|
351
359
|
const results = checkSets(names), fails = (r) => r.findings.filter((x) => x.level === 'fail').length, bad = results.filter(fails), noted = results.filter((r) => r.findings.length && !fails(r));
|
|
352
|
-
if (opt('json')) console.log(JSON.stringify(results.map((r) => ({ name: r.name, findings: r.findings })), null, 2));
|
|
360
|
+
if (opt('json')) console.log(JSON.stringify(results.map((r) => ({ name: r.name, findings: r.findings, ...(r.notes ? { notes: r.notes } : {}) })), null, 2));
|
|
353
361
|
else {
|
|
354
362
|
for (const r of results.filter((x) => x.findings.length)) { console.log(`${r.name}: ${fails(r) ? `${fails(r)} to fix` : `passes, ${r.findings.length} to know`}`); for (const x of r.findings) console.log(` ${{ fail: 'FAIL', warn: 'WARN', info: 'NOTE' }[x.level] ?? 'FAIL'} ${x.text} (${x.code})`); }
|
|
363
|
+
// notes never fail: an alias names one line per set, what a copy lacks of the kit's set says it whole
|
|
364
|
+
for (const r of results.filter((x) => x.notes)) {
|
|
365
|
+
const alias = r.notes.filter((x) => x.code === 'rules.alias'), rest = r.notes.filter((x) => x.code !== 'rules.alias');
|
|
366
|
+
if (alias.length) console.log(`${r.name}: NOTE ${alias.map((x) => `${x.rule} is also read as ${x.values.alias}`).join(', ')} (rules.alias)`);
|
|
367
|
+
for (const x of rest) console.log(`${r.name}: NOTE ${x.text} (${x.code})`);
|
|
368
|
+
}
|
|
355
369
|
console.log(`${results.length - bad.length} of ${results.length} rule sets pass${noted.length ? ` (${noted.length} with something to know)` : ''}`);
|
|
356
370
|
}
|
|
357
371
|
process.exitCode = bad.length ? 1 : 0;
|
|
@@ -593,7 +607,7 @@ async function editVariables(ref) {
|
|
|
593
607
|
console.log(`set ${r.changed.join(', ')} in ${path.relative(WS, r.file)}`);
|
|
594
608
|
}
|
|
595
609
|
|
|
596
|
-
// cad add fit|joint|item|loop|pose|fasten <project>/<assembly> --key value …: add to an assembly, keeping its layout
|
|
610
|
+
// cad add fit|joint|item|loop|pose|fasten|join <project>/<assembly> --key value …: add to an assembly, keeping its layout
|
|
597
611
|
async function editAssembly(what, ref) {
|
|
598
612
|
const list = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => parseValue(x.trim())) : undefined);
|
|
599
613
|
const pick = (keys) => Object.fromEntries(keys.map((k) => [k, typeof opt(k) === 'string' ? parseValue(opt(k)) : undefined]).filter(([, v]) => v !== undefined));
|
|
@@ -609,15 +623,23 @@ async function editAssembly(what, ref) {
|
|
|
609
623
|
} else if (what === 'item') entry = { ...text(['id', 'object', 'assembly', 'variant']), ...at(), ...(list('rotate') ? { rotate: list('rotate') } : {}),
|
|
610
624
|
...(typeof opt('set') === 'string' ? { set: Object.fromEntries(sets() && Object.entries(sets()).map(([k, v]) => [k, parseValue(v)])) } : {}) };
|
|
611
625
|
else if (what === 'loop') entry = text(['a', 'b', 'label']);
|
|
626
|
+
else if (what === 'fasten' && opt('from-fits')) { // a holes fit and a fit that fastens, put as one fasten
|
|
627
|
+
const s = await buildAssembly(ref), { fastenFromFits } = await import('../lib/fasten.mjs');
|
|
628
|
+
const r = fastenFromFitsEdit(ref, fastenFromFits(s), { screw: typeof opt('screw') === 'string' ? opt('screw') : undefined });
|
|
629
|
+
if (opt('json')) return console.log(JSON.stringify(r));
|
|
630
|
+
for (const x of r.added) console.log(`added a fasten to ${path.relative(WS, r.file)} in place of its holes fit and its fit that fastens: ${JSON.stringify(x)}`);
|
|
631
|
+
return console.log(`check its screws: cad check ${ref}`);
|
|
632
|
+
}
|
|
612
633
|
else if (what === 'fasten') { // --screw "M3 cap" --through bracket --into base --at bracket.h1,bracket.h2 | --holes bracket.body [--nut [hex] --washer --length 12 --torque 0.5 --note …]
|
|
613
634
|
const names = (k) => (typeof opt(k) === 'string' ? opt(k).split(',').map((x) => x.trim()).filter(Boolean) : undefined);
|
|
614
635
|
entry = { ...text(['screw']), through: names('through') ?? [], ...text(['into']), ...(names('at') ? { at: names('at') } : {}), ...text(['holes']), ...(opt('nut') ? { nut: opt('nut') === true ? true : String(opt('nut')) } : {}), ...(opt('washer') ? { washer: true } : {}), ...pick(['length', 'torque']), ...text(['note']) };
|
|
615
636
|
}
|
|
637
|
+
else if (what === 'join') entry = text(['kind', 'a', 'b', 'fitting', 'screw', 'note']);
|
|
616
638
|
else if (what === 'pose') {
|
|
617
639
|
const pairs = positional().slice(3);
|
|
618
640
|
if (typeof opt('name') !== 'string' || !pairs.length) throw new Error('usage: cad add pose <project>/<assembly> --name open hinge=90 [joint=value …]');
|
|
619
641
|
entry = { name: opt('name'), values: Object.fromEntries(pairs.map((p) => { const [k, v] = p.split('='); return [k.trim(), v.includes(',') ? v.split(',').map(parseValue) : parseValue(v)]; })) };
|
|
620
|
-
} else throw new Error('usage: cad add fit|joint|item|beam|loop|pose|fasten <project>/<assembly> --key value …');
|
|
642
|
+
} else throw new Error('usage: cad add fit|joint|item|beam|loop|pose|fasten|join <project>/<assembly> --key value …');
|
|
621
643
|
const r = addToAssembly(ref, what === 'beam' ? 'item' : what, entry);
|
|
622
644
|
if (opt('json')) return console.log(JSON.stringify({ ...r, added: entry }));
|
|
623
645
|
console.log(`added ${/^[aeiou]/.test(what) ? "an" : "a"} ${what} to ${path.relative(WS, r.file)}`);
|
|
@@ -1006,10 +1028,13 @@ async function platesCommand(what, ref) {
|
|
|
1006
1028
|
if (!isAssembly(ref)) throw new Error(`cad ${what} works on an assembly (<project>/<assembly>), and there is no "${ref}"`);
|
|
1007
1029
|
const s = await buildAssembly(ref);
|
|
1008
1030
|
if (what === 'order') {
|
|
1009
|
-
const { orderOf, orderText, stepPictures } = await import('../lib/order.mjs'), r = orderOf(s);
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
if (r.stuck)
|
|
1031
|
+
const { orderOf, orderText, stepPictures } = await import('../lib/order.mjs'), { withPreload } = await import('../lib/slotnuts.mjs'), r = withPreload(s, orderOf(s));
|
|
1032
|
+
// a frame (beams with joins): from bars to a square frame, its sides built flat, nuts loaded before the join that would shut them in
|
|
1033
|
+
const frame = s.joins?.length ? (await import('../lib/framebuild.mjs')) : null, fb = frame ? frame.frameBuild(s) : null;
|
|
1034
|
+
if (opt('json')) { console.log(JSON.stringify(fb ? { ...r, frame: fb } : r, null, 2)); if (r.stuck || fb?.stuck) process.exitCode = 1; return; }
|
|
1035
|
+
console.log(fb ? frame.frameBuildText(ref, fb) : orderText(ref, r));
|
|
1036
|
+
if (r.stuck || fb?.stuck) { process.exitCode = 1; return; }
|
|
1037
|
+
if (opt('preview') && fb) { for (const { n, parts } of frame.frameStepPictures(s, fb)) { const st = fb.steps[n - 1], out = paths.preview(s.project, `${s.name}-step-${String(n).padStart(2, '0')}.png`); await preview(parts, { title: `${s.a.title || s.name}: step ${n} of ${fb.steps.length}`, meta: st.text, out }); console.log(path.relative(WS, out)); } return; } // (numbered as the frame's build is)
|
|
1013
1038
|
if (opt('preview')) { const pics = stepPictures(s, r); for (const [i, parts] of pics.entries()) { const st = r.steps[i], out = paths.preview(s.project, `${s.name}-step-${String(st.n).padStart(2, '0')}.png`); await preview(parts, { title: `${s.a.title || s.name}: step ${st.n} of ${r.steps.length}`, meta: st.text, out }); console.log(path.relative(WS, out)); } }
|
|
1014
1039
|
return;
|
|
1015
1040
|
}
|
|
@@ -1034,6 +1059,21 @@ async function listCommand(what, ref) {
|
|
|
1034
1059
|
const { shoppingList, listText } = await import('../lib/list.mjs'), l = shoppingList(s);
|
|
1035
1060
|
return console.log(opt('json') ? JSON.stringify(l, null, 2) : listText(ref, l));
|
|
1036
1061
|
}
|
|
1062
|
+
if (what === 'beams' && opt('jigs')) {
|
|
1063
|
+
const { writeJigs, jigsText } = await import('../lib/jigs.mjs'), r = await writeJigs(s), rel = (f) => path.relative(WS, f);
|
|
1064
|
+
const shown = { ...r, plates: r.plates.map((p) => ({ ...p, file: rel(p.file) })) };
|
|
1065
|
+
if (opt('preview') && r.parts.length) {
|
|
1066
|
+
const out = paths.preview(s.project, `${s.name}-jigs.png`);
|
|
1067
|
+
await preview(r.parts.flatMap((o) => o.parts.map((p) => ({ name: p.name, label: p.name, role: 'part', triangles: p.triangles }))), { title: `${s.a.title || s.name}: jigs`, meta: `${r.jigs.length} jigs on ${r.plates.length} plate${r.plates.length === 1 ? '' : 's'}`, out });
|
|
1068
|
+
shown.preview = rel(out);
|
|
1069
|
+
}
|
|
1070
|
+
delete shown.parts;
|
|
1071
|
+
process.exitCode = r.findings.some((f) => f.level === 'fail') ? 1 : 0;
|
|
1072
|
+
if (opt('json')) return console.log(JSON.stringify(shown, null, 2));
|
|
1073
|
+
console.log(jigsText(ref, shown));
|
|
1074
|
+
if (shown.preview) say(shown.preview);
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1037
1077
|
if (what === 'beams') {
|
|
1038
1078
|
const { writeBeamSheets } = await import('../lib/beams.mjs'), sheets = writeBeamSheets(s);
|
|
1039
1079
|
if (opt('json')) return console.log(JSON.stringify(sheets.map((x) => ({ ...x, file: path.relative(WS, x.file) })), null, 2));
|
package/lib/assembly.mjs
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
// diameter) half way down, so the screw has something to grip. "direction": "up" for screws from below.
|
|
19
19
|
// A screwed joint is a fasten (lib/fasten.mjs): { "screw": "M3 cap", "through": ["bracket"], "into": "base", "at": ["bracket.h1"] }.
|
|
20
20
|
// Its holes are read from the parts as drawn, its screws placed as reference parts, and it holds as a fit that fastens does.
|
|
21
|
+
// Beams are held to each other by joins (lib/joins.mjs): { "kind": "blind", "a": "y1.a", "b": "x1.back@120" }. Each puts
|
|
22
|
+
// its operations on both beams and its screws into fasten before anything is built, and is checked once it is.
|
|
21
23
|
import { host, readJson } from './host.mjs';
|
|
22
24
|
import fs from 'node:fs';
|
|
23
25
|
import crypto from 'node:crypto';
|
|
@@ -41,12 +43,19 @@ import { wiresOf, wireChecks, wireRows, wireTubes, wireRoutes } from './wires.mj
|
|
|
41
43
|
import { printedParts } from './list.mjs';
|
|
42
44
|
import { taskOf, taskChecks } from './task.mjs';
|
|
43
45
|
import { powerChecks } from './power.mjs';
|
|
44
|
-
import { loadChecks } from './loads.mjs';
|
|
46
|
+
import { loadChecks, beyond } from './loads.mjs';
|
|
45
47
|
import { gripChecks } from './grip.mjs';
|
|
46
48
|
import { gaitOf, gaitChecks, gaitSequence } from './gait.mjs';
|
|
47
49
|
import { boughtBuilt, boughtFindings, boughtSets } from './bought.mjs';
|
|
48
50
|
import { orderChecks } from './order.mjs';
|
|
49
|
-
import { beamBuilt, beamPlace, beamAddress, beamFindings, marksOf } from './beams.mjs';
|
|
51
|
+
import { beamBuilt, beamPlace, beamAddress, beamFindings, marksOf, framesContext } from './beams.mjs';
|
|
52
|
+
import { fittingBuilt, fittingFindings, plasticOf } from './fittings.mjs';
|
|
53
|
+
import { expandJoins, joinChecks } from './joins.mjs';
|
|
54
|
+
import { expandPanels, panelBuilt, panelFindings, PANEL_CHECK } from './panels.mjs';
|
|
55
|
+
import { expandServices, serviceFindings } from './services.mjs';
|
|
56
|
+
import { expandGuides, guideBuilt, guideFindings } from './guides.mjs';
|
|
57
|
+
import { slotNutChecks } from './slotnuts.mjs';
|
|
58
|
+
import { frameSquareChecks, frameBuild } from './framebuild.mjs';
|
|
50
59
|
let fastening = null; // lib/fasten.mjs, loaded with the first assembly that has a fasten: the rest start as fast as before
|
|
51
60
|
|
|
52
61
|
export const assemblyPath = (ref) => { const [project, name] = String(ref).split('/'); return path.join(paths.project(project || ''), 'assemblies', `${name || ''}.json`); };
|
|
@@ -79,7 +88,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
79
88
|
const outer = overrides;
|
|
80
89
|
const [project, name] = ref.split('/');
|
|
81
90
|
if (stack.includes(ref)) throw new Error(`assembly ${ref} contains itself (${[...stack, ref].join(' → ')})`);
|
|
82
|
-
|
|
91
|
+
let a = readJson(assemblyPath(ref));
|
|
83
92
|
// A pose may set items' variables as well as joints ("cocked": { "run": -30, "action.travel": 25 }): a flexure bent
|
|
84
93
|
// as the pose bends it, while the part itself is printed as drawn. The pose being built sets them on its items.
|
|
85
94
|
const itemSets = (name) => { const out = {}; for (const [k, v] of Object.entries(a.poses?.[name] || {})) if (k.includes('.')) { const [item, ...rest] = k.split('.'); (out[item] ||= {})[rest.join('.')] = v; } return out; };
|
|
@@ -104,6 +113,18 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
104
113
|
return v;
|
|
105
114
|
};
|
|
106
115
|
const num = (x) => evaluate(x, lookup);
|
|
116
|
+
// Joins between beams (lib/joins.mjs): their operations go on the beams and their screws into fasten before anything is built
|
|
117
|
+
let joins = [];
|
|
118
|
+
if (a.joins != null) ({ a, joins } = expandJoins(a, num, undefined, plasticOf(project)));
|
|
119
|
+
// Panels (lib/panels.mjs): each placed on its bay, its clips or a door's hinges, handle and catch added with their fastens
|
|
120
|
+
let panels = [];
|
|
121
|
+
if ((a.items || []).some((it) => it?.panel)) ({ a, panels } = expandPanels(a, num, undefined, plasticOf(project)));
|
|
122
|
+
// Services (lib/services.mjs): a bought board or supply on its printed mount, a wire's run along a slot held by clips
|
|
123
|
+
let mounts = [], runs = [];
|
|
124
|
+
if ((a.items || []).some((it) => it?.mount != null) || (a.wires || []).some((w) => (w?.via ?? []).some((v) => v && typeof v === 'object'))) ({ a, mounts, runs } = expandServices(a, num, undefined, plasticOf(project)));
|
|
125
|
+
// Guides (lib/guides.mjs): a rail on a beam's face, its screws into the slot, each carriage on its own sliding joint
|
|
126
|
+
let guides = [];
|
|
127
|
+
if (a.guides != null) ({ a, guides } = expandGuides(a, num, undefined, plasticOf(project)));
|
|
107
128
|
const { translate, rotate, transform } = jscad.transforms, deg = Math.PI / 180;
|
|
108
129
|
|
|
109
130
|
const items = [], parts = [], objects = [], fits = [], requires = [];
|
|
@@ -112,6 +133,9 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
112
133
|
const source = async (it, extra) => {
|
|
113
134
|
if (it.motor) { const key = JSON.stringify(['motor', it.id, it.motor]); if (!built.has(key)) built.set(key, motorBuilt(it.motor, num, it.id)); return built.get(key); }
|
|
114
135
|
if (it.beam) { const b = beamBuilt(it, num, it.id); if (!built.has(b.key)) built.set(b.key, b); return built.get(b.key); } // (lib/beams.mjs)
|
|
136
|
+
if (it.fitting) { const b = await fittingBuilt(it, it.id, framesContext(), plasticOf(project)); if (!built.has(b.key)) built.set(b.key, b); return built.get(b.key); } // (lib/fittings.mjs)
|
|
137
|
+
if (it.panel) { const b = await panelBuilt(it, it.id); if (!built.has(b.key)) built.set(b.key, b); return built.get(b.key); } // (lib/panels.mjs)
|
|
138
|
+
if (it._guide) { const b = guideBuilt(it, it.id); if (!built.has(b.key)) built.set(b.key, b); return built.get(b.key); } // (lib/guides.mjs)
|
|
115
139
|
if (it.bought) {
|
|
116
140
|
const key = JSON.stringify(['bought', it.id, it.bought, it.variant, it.set]);
|
|
117
141
|
if (!built.has(key)) built.set(key, boughtSets().get(it.bought) === 'motor' ? motorBuilt({ model: it.bought }, num, it.id) : boughtBuilt(it.bought, it, num, it.id));
|
|
@@ -153,7 +177,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
153
177
|
let builtCount = 0;
|
|
154
178
|
for (const it of a.items || []) {
|
|
155
179
|
if (!/^[a-z][\w-]*$/.test(it.id || '')) throw new Error(`each item needs an id (letters, digits, - or _): got ${JSON.stringify(it.id)}`);
|
|
156
|
-
if ([it.object, it.assembly, it.motor, it.bought, it.beam].filter(Boolean).length !== 1) throw new Error(`item ${it.id}: give one of "object", "assembly", "motor", "bought" or "
|
|
180
|
+
if ([it.object, it.assembly, it.motor, it.bought, it.beam, it.fitting, it.panel].filter(Boolean).length !== 1) throw new Error(`item ${it.id}: give one of "object", "assembly", "motor", "bought", "beam", "fitting" or "panel"`);
|
|
157
181
|
if (!it.beam && (it.to != null || it.roll != null)) throw new Error(`item ${it.id}: to and roll place a beam by its ends: place ${it.object || it.assembly || it.motor?.model || it.bought} with at and rotate`);
|
|
158
182
|
// Copies: one, a grid from repeat x/y, or a layout's keys. Each: { id, offset (from at), extra (values to set) }
|
|
159
183
|
const rx = it.repeat?.x, ry = it.repeat?.y, rl = it.repeat?.layout, copies = [];
|
|
@@ -219,7 +243,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
219
243
|
for (const n of sub.seen) seen.add(n);
|
|
220
244
|
items.push({ ...it, id, sub, role: 'part' });
|
|
221
245
|
} else {
|
|
222
|
-
objects.push({ id, objName: src.objName, version: src.version, built: src.b, role: src.role, ...(src.set ? { set: src.set } : {}), ...(src.variant ? { variant: src.variant } : {}), ...(src.bought ? { bought: src.bought } : {}), ...(src.motor ? { motor: src.motor } : {}), ...(src.beam ? { beam: src.beam } : {}) });
|
|
246
|
+
objects.push({ id, objName: src.objName, version: src.version, built: src.b, role: src.role, ...(src.set ? { set: src.set } : {}), ...(src.variant ? { variant: src.variant } : {}), ...(src.bought ? { bought: src.bought } : {}), ...(src.motor ? { motor: src.motor } : {}), ...(src.beam ? { beam: src.beam } : {}), ...(src.fitting ? { fitting: src.fitting } : {}), ...(src.panel ? { panel: src.panel } : {}) });
|
|
223
247
|
items.push({ ...it, id, objName: src.objName, built: src.b, version: src.version, role: src.role, ...(src.beam ? { beam: src.beam } : {}) });
|
|
224
248
|
}
|
|
225
249
|
}
|
|
@@ -264,6 +288,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
264
288
|
// Screwed joints: each screw followed through the parts as they stand, its hardware placed, and the joint counted as a
|
|
265
289
|
// fit that fastens (what holds a part, what the order of assembly and the list read)
|
|
266
290
|
let fastened = null;
|
|
291
|
+
if (a.fits?.some((x) => x.holes)) fastening ||= await import('./fasten.mjs'); // (a holes fit with a fit that fastens: the fasten that says both is suggested)
|
|
267
292
|
if (a.fasten?.length && a.kind !== 'plate') {
|
|
268
293
|
fastening ||= await import('./fasten.mjs');
|
|
269
294
|
fastened = fastening.fastenOf({ a, project, parts, objects, motion, num }, worlds0, { access: pose === motion.pose });
|
|
@@ -302,7 +327,7 @@ export async function buildAssembly(ref, stack = [], overrides = {}, opts = {})
|
|
|
302
327
|
const v = jointValues(motion, p), moved = partsAt(placeItems(motion, v));
|
|
303
328
|
return { ...s, parts: moved, fastened: null, pose: typeof p === 'string' ? p : null, jointValues: v, polygons: moved.flatMap((x) => x.polygons), triangles: moved.flatMap((x) => x.triangles) };
|
|
304
329
|
};
|
|
305
|
-
const s = { a, project, name, items, parts, objects, fits, requires, values, num, seen, motion, wires, task, gait, fastened, hardware, pose: typeof pose === 'string' ? pose : null, jointValues: jv, at,
|
|
330
|
+
const s = { a, project, name, items, parts, objects, fits, requires, values, num, seen, motion, wires, task, gait, fastened, hardware, joins, panels, mounts, runs, guides, pose: typeof pose === 'string' ? pose : null, jointValues: jv, at,
|
|
306
331
|
polygons: parts.flatMap((p) => p.polygons), triangles: parts.flatMap((p) => p.triangles) };
|
|
307
332
|
return s;
|
|
308
333
|
}
|
|
@@ -741,7 +766,7 @@ function pairOverlap(pa, pb) {
|
|
|
741
766
|
if (!pa.hash || !pb.hash) return overlap(solidOf(pa), solidOf(pb));
|
|
742
767
|
remembered ||= (() => { try { return JSON.parse(host.readText(OVERLAPS)); } catch { return {}; } })();
|
|
743
768
|
const at = (p) => `${p.hash}@${Array.from(p.m || []).map((x) => Math.round(x * 1e6) / 1e6).join(',')}`;
|
|
744
|
-
const [x, y] = [at(pa), at(pb)].sort(), k = crypto.createHash('sha1').update(`crossing+${solid ? 'manifold' : 'jscad'}|${x}|${y}`).digest('hex');
|
|
769
|
+
const [x, y] = [at(pa), at(pb)].sort(), k = crypto.createHash('sha1').update(`crossing+tracks+${solid ? 'manifold' : 'jscad'}|${x}|${y}`).digest('hex');
|
|
745
770
|
if (!(k in remembered)) { remembered[k] = overlap(solidOf(pa), solidOf(pb)); fresh++; }
|
|
746
771
|
return remembered[k];
|
|
747
772
|
}
|
|
@@ -766,6 +791,8 @@ function massFinding(s, f) {
|
|
|
766
791
|
}
|
|
767
792
|
|
|
768
793
|
export function checkAssembly(s) {
|
|
794
|
+
// the screws found in this pose (at(pose) leaves them to be found again): the fasten and slot nut checks read the same
|
|
795
|
+
if (!s.fastened && s.a.fasten?.length && fastening) s = { ...s, fastened: fastening.fastenOf(s, placeItems(s.motion, s.jointValues)) };
|
|
769
796
|
const out = [], f = (level, text, card, extra) => out.push({ level, text, ...(card && { card }), ...extra }), mm = (n) => `${Number(n.toFixed(3))}`;
|
|
770
797
|
// Versions: every pin, from this assembly and its components, against every copy of that object
|
|
771
798
|
const pins = new Map();
|
|
@@ -908,12 +935,28 @@ export function checkAssembly(s) {
|
|
|
908
935
|
// nowhere else: a ring gear resting on its case turns with the planets; a pawl resting on its post walks off it.
|
|
909
936
|
if (s.motion.joints.some((j) => j.type !== 'fixed')) {
|
|
910
937
|
const ids = s.motion.items.map((x) => x[0]), top = (n) => String(n).split(/[.@]/)[0];
|
|
911
|
-
|
|
938
|
+
// (a beam placed by its ends is the frame, held where it is drawn: what is screwed to it is held by it)
|
|
939
|
+
const held = new Set([ids[0], ...s.motion.joints.filter((j) => !j.at).map((j) => ids[j.child]), ...s.items.filter((it) => it.beam && it.from != null).map((it) => it.id)]), links = s.fits.filter((x) => x.fastens).map((x) => [top(x.a), top(x.b)]);
|
|
912
940
|
for (let grew = true; grew;) { grew = false; for (const [a, b] of links) { if (held.has(a) && !held.has(b)) { held.add(b); grew = true; } if (held.has(b) && !held.has(a)) { held.add(a); grew = true; } } }
|
|
913
941
|
const placed = new Set(s.objects.filter((o) => !o.unplaced && o.role !== 'reference').map((o) => top(o.id)));
|
|
914
942
|
const loose = ids.filter((id) => !held.has(id) && placed.has(id));
|
|
915
943
|
if (loose.length) f('warn', `${loose.join(', ')} ${loose.length > 1 ? 'are' : 'is'} placed, but nothing holds ${loose.length > 1 ? 'them' : 'it'}: give ${loose.length > 1 ? 'each' : 'it'} a joint, or fasten it to what it sits on (pins, screws, a press) and say so with a fit that "fastens"`, `${loose.length} loose`, { code: 'assembly.loose', refs: { items: loose } });
|
|
916
944
|
else f('pass', `every part turns or slides on a joint, or is fastened to the ${ids[0]}`, null, { code: 'assembly.held' });
|
|
945
|
+
// A fit that fastens holds two items as one, but only a joint or an anchor moves them: one fastened to a part a
|
|
946
|
+
// joint moves, and placed where it stands, stays behind in every pose and is left out of what that joint carries
|
|
947
|
+
// (one also fastened to what stays, as a servo to its stand with its arm fastened to the horn, is held there)
|
|
948
|
+
const moving = s.motion.joints.filter((j) => !j.at && j.type !== 'fixed'), across = (a, b) => moving.find((jj) => beyond(s.motion, jj, ids.indexOf(a)) !== beyond(s.motion, jj, ids.indexOf(b)));
|
|
949
|
+
const still = new Set([ids[0], ...s.motion.joints.filter((j) => !j.at).map((j) => ids[j.child]), ...s.items.filter((it) => it.beam && it.from != null).map((it) => it.id)]), same = links.filter(([a, b]) => ids.includes(a) && ids.includes(b) && !across(a, b));
|
|
950
|
+
for (let grew = true; grew;) { grew = false; for (const [a, b] of same) { if (still.has(a) && !still.has(b)) { still.add(b); grew = true; } if (still.has(b) && !still.has(a)) { still.add(a); grew = true; } } }
|
|
951
|
+
for (const x of s.fits.filter((q) => q.fastens)) {
|
|
952
|
+
const [a, b] = [top(x.a), top(x.b)], ia = ids.indexOf(a), ib = ids.indexOf(b);
|
|
953
|
+
if (ia < 0 || ib < 0) continue;
|
|
954
|
+
const j = across(a, b);
|
|
955
|
+
if (!j || (still.has(a) && still.has(b))) continue;
|
|
956
|
+
const [mover, left] = beyond(s.motion, j, ia) ? [a, b] : [b, a];
|
|
957
|
+
f('warn', `${left} is fastened to ${mover} (a fit that fastens), but only ${mover} moves on ${j.id}: ${left} is placed where it stands, so it stays there in every pose and its mass is left out of what ${j.id} carries (joint.moment). Place ${left} on ${mover} by an anchor or an address ("at": "${mover}.<anchor>")`,
|
|
958
|
+
`${left}: left behind by ${j.id}`, { code: 'assembly.fastened', refs: { items: [left, mover], joint: j.id } });
|
|
959
|
+
}
|
|
917
960
|
}
|
|
918
961
|
// Gears: each mesh's centre distance and contact ratio, said between the two axes (the rest by --sweep)
|
|
919
962
|
for (const g of s.motion.meshes || []) {
|
|
@@ -925,8 +968,20 @@ export function checkAssembly(s) {
|
|
|
925
968
|
}
|
|
926
969
|
}
|
|
927
970
|
if (s.a.fasten?.length && fastening) fastening.fastenChecks(s, f, { placeItems });
|
|
971
|
+
// A holes fit and a fit that fastens the same two items: one fasten says both, and knows the screw
|
|
972
|
+
if (fastening) for (const g of fastening.fastenFromFits(s)) {
|
|
973
|
+
f('info', `${g.label} and the fit that fastens ${g.pair[0]} to ${g.pair[1]} are one screwed joint: a fasten says both and knows the screw (its holes, length, thread engaged, the seat under its head and the key that turns it). In place of the two, add to "fasten": ${JSON.stringify(g.fasten)}${g.screw ? '' : ' (with the screw it takes: no thread was found in the fits or the holes)'}, or run cad add fasten ${s.project}/${s.name} --from-fits`,
|
|
974
|
+
null, { code: 'fasten.suggest', refs: { fits: [g.holes, g.fastens], items: g.pair, paste: g.fasten } });
|
|
975
|
+
}
|
|
928
976
|
boughtFindings(s, f);
|
|
929
977
|
beamFindings(s, f);
|
|
978
|
+
fittingFindings(s, f);
|
|
979
|
+
panelFindings(s, f);
|
|
980
|
+
serviceFindings(s, f);
|
|
981
|
+
guideFindings(s, f);
|
|
982
|
+
joinChecks(s, f);
|
|
983
|
+
slotNutChecks(s, f);
|
|
984
|
+
frameSquareChecks(s, f);
|
|
930
985
|
massFinding(s, f);
|
|
931
986
|
runningChecks(s, f, { axisOf, placeItems, jointValues, mul });
|
|
932
987
|
if (s.wires?.length) wireChecks(s, f, { placeItems, jointValues, mul });
|
|
@@ -936,7 +991,7 @@ export function checkAssembly(s) {
|
|
|
936
991
|
gripChecks(s, f);
|
|
937
992
|
gaitChecks(s, f, { jointValues, placeItems, sweepOne: (v) => clashesOf(s.at(v), named) });
|
|
938
993
|
taskChecks(s, f);
|
|
939
|
-
orderChecks(s, f);
|
|
994
|
+
orderChecks(s, f, { frame: frameBuild });
|
|
940
995
|
// Plates print everything: no references
|
|
941
996
|
if (s.a.kind === 'plate') {
|
|
942
997
|
const refs = s.objects.filter((o) => o.role === 'reference' && !o.unplaced); // an unplaced item only lends its numbers
|
|
@@ -986,20 +1041,24 @@ export function sweep(s, { joint, steps = 24, progress } = {}) {
|
|
|
986
1041
|
for (const j of free) j.dofs.forEach(([lo, hi], d) => {
|
|
987
1042
|
const unit = DOFS[j.type][d] === 'angle' ? '°' : ' mm', name = `${j.id}${j.dofs.length > 1 ? ` ${'xyz'[d] && j.type === 'ball' ? 'xyz'[d] : DOFS[j.type][d]}` : ''}`;
|
|
988
1043
|
const bad = []; // [value, what]
|
|
989
|
-
|
|
990
|
-
|
|
1044
|
+
// a door with its latch shut: also tried just off shut, finer than a step, so a hit within the first degree is seen
|
|
1045
|
+
const held = (s.panels ?? []).find((p) => p.latch && p.joint === j.id && DOFS[j.type][d] === 'angle'), probe = held ? Math.min(PANEL_CHECK.latch_probe.value, (hi - lo) / steps) : 0;
|
|
1046
|
+
const values = [...Array(steps + 1).keys()].map((i) => lo + ((hi - lo) * i) / steps);
|
|
1047
|
+
if (probe > 0 && probe < (hi - lo) / steps) values.splice(1, 0, lo + probe);
|
|
1048
|
+
for (const [i, v] of values.entries()) {
|
|
1049
|
+
const set = { ...base, [j.id]: base[j.id].map((x, k) => (k === d ? v : x)) };
|
|
991
1050
|
const t = s.at(Object.fromEntries(Object.entries(set).filter(([id]) => !s.motion.joints.find((x) => x.id === id).follow)));
|
|
992
1051
|
const what = [...clashesOf(t, isNamed).map(([a, b]) => `${a} hits ${b}`), ...loopGaps(t).filter((l) => !l.ok).map((l) => `${l.label} apart by ${mm(l.gap)} mm`)];
|
|
993
1052
|
if (what.length) bad.push([v, what]);
|
|
994
|
-
progress?.({ stage: 'sweep', joint: j.id, step: i, steps });
|
|
1053
|
+
progress?.({ stage: 'sweep', joint: j.id, step: Math.min(i, steps), steps });
|
|
995
1054
|
}
|
|
996
1055
|
const ranges = []; // runs of steps in a row that collide
|
|
997
1056
|
for (const [v, what] of bad) { const r = ranges[ranges.length - 1]; if (r && Math.abs(v - r.to - (hi - lo) / steps) < 1e-9) { r.to = v; r.what = [...new Set([...r.what, ...what])]; } else ranges.push({ from: v, to: v, what }); }
|
|
998
|
-
const span = `${mm(lo)} to ${mm(hi)}${unit}
|
|
999
|
-
if (!ranges.length) f('pass', `sweep ${name}, ${span} in ${steps} steps: nothing collides`, `${name}: clear ${span}`, { code: 'sweep', values: { from: lo, to: hi, steps }, refs: { joint: name, collisions: [] } });
|
|
1000
|
-
else f('fail', `sweep ${name}, ${span} in ${steps} steps: ${ranges.map((r) => `${r.from === r.to ? `at ${mm(r.from)}` : `${mm(r.from)} to ${mm(r.to)}`}${unit.trim()}: ${r.what.slice(0, 3).join('; ')}${r.what.length > 3 ? `; and ${r.what.length - 3} more` : ''}`).join(' | ')}`,
|
|
1057
|
+
const span = `${mm(lo)} to ${mm(hi)}${unit}`, note = held ? ` (${held.latch} shut over ${held.id}: also tried ${mm(probe)}${unit} off shut)` : '';
|
|
1058
|
+
if (!ranges.length) f('pass', `sweep ${name}, ${span} in ${steps} steps${note}: nothing collides`, `${name}: clear ${span}`, { code: 'sweep', values: { from: lo, to: hi, steps, ...(held ? { probe } : {}) }, refs: { joint: name, collisions: [], ...(held ? { latch: held.latch } : {}) } });
|
|
1059
|
+
else f('fail', `sweep ${name}, ${span} in ${steps} steps${note}: ${ranges.map((r) => `${r.from === r.to ? `at ${mm(r.from)}` : `${mm(r.from)} to ${mm(r.to)}`}${unit.trim()}: ${r.what.slice(0, 3).join('; ')}${r.what.length > 3 ? `; and ${r.what.length - 3} more` : ''}`).join(' | ')}`,
|
|
1001
1060
|
`${name}: collides ${ranges.map((r) => (r.from === r.to ? mm(r.from) : `${mm(r.from)}-${mm(r.to)}`)).join(', ')}${unit.trim()}`,
|
|
1002
|
-
{ code: 'sweep', values: { from: lo, to: hi, steps }, refs: { joint: name, collisions: ranges.map((r) => ({ from: r.from, to: r.to, what: r.what })) } });
|
|
1061
|
+
{ code: 'sweep', values: { from: lo, to: hi, steps, ...(held ? { probe } : {}) }, refs: { joint: name, ...(held ? { latch: held.latch } : {}), collisions: ranges.map((r) => ({ from: r.from, to: r.to, what: r.what })) } });
|
|
1003
1062
|
});
|
|
1004
1063
|
saveOverlaps();
|
|
1005
1064
|
return out;
|
package/lib/beams.mjs
CHANGED
|
@@ -87,8 +87,8 @@ export function beamPlace(it, num) {
|
|
|
87
87
|
export function beamBuilt(it, num, id, context = framesContext()) {
|
|
88
88
|
const { model: m, length } = beamOf(it, num, context);
|
|
89
89
|
const meta = { body: { label: `${m.profile.name} x ${mm(length)} mm` } };
|
|
90
|
-
const parts = named({ body: beam(m) }, meta), link = named({ body: beam(m, { display: 'link' }) }, meta)[0];
|
|
91
|
-
parts[0].collide = link.geometry; // (the overlap check measures the envelope
|
|
90
|
+
const parts = named({ body: beam(m) }, meta), link = named({ body: beam(m, { display: 'link', tracks: true }) }, meta)[0];
|
|
91
|
+
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
92
|
const anchors = Object.fromEntries(Object.entries(m.anchors).map(([k, a]) => [k, { at: a.origin, axis: a.axis, ref: a.ref }]));
|
|
93
93
|
const values = { length, width: m.profile.width, height: m.profile.height, area: m.area, ...(m.mass != null ? { mass: m.mass } : {}) };
|
|
94
94
|
const entries = Object.entries(m.profile.figures).filter(([, f]) => typeof f?.value === 'number').map(([k, f]) => ({ name: `${m.profile.name}.${k}`, value: f.value, unit: f.unit, rule: f.rule, kind: f.kind, source: f.source, checked: f.checked, set: m.profile.name }));
|