@rulecad/cad 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +45 -16
- package/CHANGELOG.md +724 -0
- package/EXAMPLES.md +61 -54
- package/README.md +376 -98
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2664 -541
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1883 -435
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/cache-file.mjs +105 -0
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +871 -147
- package/lib/designshapes.mjs +142 -0
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +922 -192
- package/lib/errors.mjs +16 -3
- package/lib/estimates.mjs +51 -0
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2708 -507
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +721 -122
- package/lib/fixings.mjs +38 -13
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +108 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +86 -18
- package/lib/framesize.mjs +719 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +129 -23
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +439 -69
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +334 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +597 -136
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +1080 -117
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1002 -214
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +18 -1
- package/lib/optimise.mjs +991 -287
- package/lib/order.mjs +515 -114
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +81 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +17 -6
- package/lib/sandbox-hooks.mjs +179 -27
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +122 -25
- package/lib/sandbox.mjs +667 -75
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +963 -179
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +285 -39
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +200 -14
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
package/lib/fittings.mjs
CHANGED
|
@@ -6,33 +6,82 @@
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import crypto from 'node:crypto';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
11
|
import * as frames from '@rulecad/frames';
|
|
10
12
|
const { bracketModel, bracket, plateModel, plate } = frames;
|
|
11
|
-
import {
|
|
13
|
+
import { readJson } from './host.mjs';
|
|
14
|
+
import { writeCacheFile, readCacheJson } from './cache-file.mjs';
|
|
12
15
|
import { paths, RULE_DIRS } from './workspace.mjs';
|
|
13
16
|
import { named } from './parts.mjs';
|
|
17
|
+
import { codeOnly } from './code-text.mjs';
|
|
14
18
|
import { givenFor } from './frames.mjs';
|
|
15
19
|
import { peekRuleSet } from './rules.mjs';
|
|
16
20
|
import { ops as booleans } from '@rulecad/shapes';
|
|
17
21
|
import jscad from '@jscad/modeling';
|
|
18
22
|
|
|
19
|
-
const KEYS = [
|
|
23
|
+
const KEYS = [
|
|
24
|
+
'kind',
|
|
25
|
+
'profile',
|
|
26
|
+
'other',
|
|
27
|
+
'face',
|
|
28
|
+
'otherFace',
|
|
29
|
+
'shape',
|
|
30
|
+
'brace',
|
|
31
|
+
'load',
|
|
32
|
+
'count',
|
|
33
|
+
'thread',
|
|
34
|
+
'head',
|
|
35
|
+
'nut',
|
|
36
|
+
];
|
|
20
37
|
// The printed fittings for panels, doors and beams' ends: each kind's model and solid in @rulecad/frames, whether it
|
|
21
38
|
// is drawn for a profile, and the parts it has (a hinge's two leaves, a levelling foot's body and pad: an item each)
|
|
22
39
|
const MORE = {
|
|
23
|
-
'panel-clip': ['panelClipModel', 'panelClip'],
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
'panel-clip': ['panelClipModel', 'panelClip'],
|
|
41
|
+
'panel-corner': ['panelCornerModel', 'panelCorner'],
|
|
42
|
+
'slot-cover': ['slotCoverModel', 'slotCover'],
|
|
43
|
+
'panel-edge': ['panelEdgeModel', 'panelEdge'],
|
|
44
|
+
'gasket-strip': ['gasketStripModel', 'gasketStrip', { profile: false }],
|
|
45
|
+
hinge: ['hingeModel', 'hinge', { parts: ['frame', 'door'] }],
|
|
46
|
+
handle: ['handleModel', 'handle', { profile: false }],
|
|
47
|
+
latch: ['latchModel', 'latch'],
|
|
48
|
+
'magnet-catch': ['magnetCatchModel', 'magnetCatch'],
|
|
49
|
+
'end-cap': ['endCapModel', 'endCap'],
|
|
50
|
+
foot: ['footModel', 'foot'],
|
|
51
|
+
'levelling-foot': ['levellingFootModel', 'levellingFoot', { parts: ['body', 'pad'] }],
|
|
52
|
+
'castor-plate': ['castorPlateModel', 'castorPlate'],
|
|
53
|
+
'stacking-foot': ['stackingFootModel', 'stackingFoot'],
|
|
54
|
+
'device-mount': ['deviceMountModel', 'deviceMount'],
|
|
55
|
+
'fan-mount': ['fanMountModel', 'fanMount'],
|
|
56
|
+
'drag-chain-end': ['dragChainEndModel', 'dragChainEnd'],
|
|
57
|
+
'din-rail': ['dinRailAdapterModel', 'dinRailAdapter'],
|
|
58
|
+
'cable-clip': ['cableClipModel', 'cableClip'],
|
|
59
|
+
'tie-anchor': ['tieAnchorModel', 'tieAnchor'],
|
|
60
|
+
'spool-holder': ['spoolHolderModel', 'spoolHolder'],
|
|
61
|
+
'rail-jig': ['railJigModel', 'railJig'],
|
|
62
|
+
'wheel-plate': ['wheelsModel', 'wheelPlate'],
|
|
63
|
+
slider: ['sliderModel', 'slider'],
|
|
30
64
|
'nut-carrier': ['carrierModel', 'carrier', { pose: { fit: 'slot', print: 'print' } }],
|
|
31
|
-
'rod-holder': ['rodHolderModel', 'rodHolder'],
|
|
32
|
-
'
|
|
65
|
+
'rod-holder': ['rodHolderModel', 'rodHolder'],
|
|
66
|
+
'rod-carriage': ['rodCarriageModel', 'rodCarriage'],
|
|
67
|
+
'motor-plate': ['motorPlateModel', 'motorPlate'],
|
|
68
|
+
'endstop-mount': ['endstopMountModel', 'endstopMount'],
|
|
69
|
+
'belt-plate': ['beltPlateModel', 'beltPlate'],
|
|
70
|
+
'belt-clamp': ['beltClampModel', 'beltClamp', { profile: false }],
|
|
71
|
+
'belt-idler': ['beltIdlerModel', 'beltIdler'],
|
|
33
72
|
};
|
|
34
73
|
// the kinds whose tongue or stem stands in the slot, inside the beam's envelope: the overlap check measures them without it
|
|
35
|
-
const TONGUED = [
|
|
74
|
+
const TONGUED = [
|
|
75
|
+
'panel-clip',
|
|
76
|
+
'magnet-catch',
|
|
77
|
+
'panel-corner',
|
|
78
|
+
'cable-clip',
|
|
79
|
+
'tie-anchor',
|
|
80
|
+
'spool-holder',
|
|
81
|
+
'rail-jig',
|
|
82
|
+
'slider',
|
|
83
|
+
'end-cap',
|
|
84
|
+
];
|
|
36
85
|
// parts that lie in a slot by design (an in-slot panel edge, a slot cover's strip, a nut carrier): only what stands above the face is
|
|
37
86
|
// measured by the overlap check, as a tongue is left out
|
|
38
87
|
const IN_SLOT = ['panel-edge', 'slot-cover', 'nut-carrier'];
|
|
@@ -41,16 +90,28 @@ export const FITTING_KINDS = ['bracket', 'gusset', 'splice', ...Object.keys(MORE
|
|
|
41
90
|
const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
|
|
42
91
|
const strip = (e) => String(e?.message ?? e).replace(/^(bracketModel|plateModel|bracket|plate): /, '');
|
|
43
92
|
|
|
93
|
+
// The code of @rulecad/fea that frames' fittings are worked out with, as frames finds it, without comments or blank
|
|
94
|
+
// lines: frames keys its results by its own code and fea's exported functions (fittingCode), which it can read in a
|
|
95
|
+
// browser; on disk they are kept by all of fea's code as well, the functions it does not export among them
|
|
96
|
+
const feaCode = (() => {
|
|
97
|
+
const framesDir = path.dirname(fileURLToPath(import.meta.resolve('@rulecad/frames'))),
|
|
98
|
+
entry = createRequire(pathToFileURL(path.join(framesDir, 'package.json')).href).resolve('@rulecad/fea');
|
|
99
|
+
return crypto
|
|
100
|
+
.createHash('sha256')
|
|
101
|
+
.update(codeOnly(fs.readFileSync(entry, 'utf8')))
|
|
102
|
+
.digest('hex');
|
|
103
|
+
})();
|
|
104
|
+
const fittingFile = (key) =>
|
|
105
|
+
paths.cache('fitting', `${crypto.createHash('sha256').update(`${feaCode}\n${key}`).digest('hex').slice(0, 24)}.json`);
|
|
44
106
|
/** The finite elements' results kept on disk, as the motor mount's are: .cache/fitting/<hash>.json (CAD_NO_CACHE skips it). */
|
|
45
107
|
export const fittingCache = {
|
|
46
108
|
get(key) {
|
|
47
109
|
if (process.env.CAD_NO_CACHE) return undefined;
|
|
48
|
-
|
|
49
|
-
try { return host.exists(file) ? JSON.parse(host.readText(file)) : undefined; } catch { return undefined; }
|
|
110
|
+
return readCacheJson(fittingFile(key));
|
|
50
111
|
},
|
|
51
112
|
set(key, v) {
|
|
52
113
|
if (process.env.CAD_NO_CACHE) return;
|
|
53
|
-
|
|
114
|
+
writeCacheFile(fittingFile(key), JSON.stringify(v)); // (one that cannot be written is solved again next time)
|
|
54
115
|
},
|
|
55
116
|
};
|
|
56
117
|
|
|
@@ -62,7 +123,11 @@ export const fittingCache = {
|
|
|
62
123
|
*/
|
|
63
124
|
export function plasticOf(project) {
|
|
64
125
|
let raw;
|
|
65
|
-
try {
|
|
126
|
+
try {
|
|
127
|
+
raw = readJson(path.join(paths.project(project), 'project.json')).material;
|
|
128
|
+
} catch {
|
|
129
|
+
return 'pla';
|
|
130
|
+
}
|
|
66
131
|
return plasticNamed(raw, `project ${project}`);
|
|
67
132
|
}
|
|
68
133
|
|
|
@@ -72,14 +137,27 @@ export function plasticOf(project) {
|
|
|
72
137
|
* @param {any} raw the material as written @param {string} [where] what names it, for the refusal @returns {string | object}
|
|
73
138
|
*/
|
|
74
139
|
export function plasticNamed(raw, where = 'the project') {
|
|
75
|
-
const m = String(raw || 'pla')
|
|
140
|
+
const m = String(raw || 'pla')
|
|
141
|
+
.trim()
|
|
142
|
+
.toLowerCase()
|
|
143
|
+
.split(/\s/)[0];
|
|
76
144
|
if (['pla', 'petg'].includes(m)) return m;
|
|
77
|
-
let set = null;
|
|
145
|
+
let set = null;
|
|
146
|
+
try {
|
|
147
|
+
set = peekRuleSet(m);
|
|
148
|
+
} catch {
|
|
149
|
+
// (no such material rule set: the figures it lacks are named just below)
|
|
150
|
+
}
|
|
78
151
|
const lacks = ['strength', 'modulus', 'density'].filter((k) => !(typeof set?.rules?.[k]?.value === 'number'));
|
|
79
152
|
const have = plastics().join(', ');
|
|
80
|
-
if (set && !lacks.length && rubber(set.rules))
|
|
153
|
+
if (set && !lacks.length && rubber(set.rules))
|
|
154
|
+
throw new Error(
|
|
155
|
+
`${where}: its material is ${JSON.stringify(raw)}, a rubber (its strength over its modulus is ${(set.rules.strength.value / set.rules.modulus.value).toFixed(2)}, a strain far past where its stiffness holds), and printed fittings are sized with sums for a stiff plastic that do not hold for it. Set the material to one of ${have}`,
|
|
156
|
+
);
|
|
81
157
|
if (set && !lacks.length) return set;
|
|
82
|
-
throw new Error(
|
|
158
|
+
throw new Error(
|
|
159
|
+
`${where}: its material is ${JSON.stringify(raw)}, and printed fittings are sized from their plastic's strength, modulus and density: ${set ? `rules/${m}.json gives no ${lacks.join(', ')}` : `the kit and this workspace have rule sets for ${have}, and there is no rules/${m}.json`}. Give rules/${m}.json with all three, or set the material to one of ${have}`,
|
|
160
|
+
);
|
|
83
161
|
}
|
|
84
162
|
|
|
85
163
|
// A rubber (TPU): its strength over its modulus, the strain where a stiff plastic yields, is past 0.5. Its stiffness
|
|
@@ -94,10 +172,21 @@ const rubber = (r) => r.strength.value / r.modulus.value > 0.5;
|
|
|
94
172
|
export function plastics() {
|
|
95
173
|
const out = new Set();
|
|
96
174
|
for (const d of RULE_DIRS) {
|
|
97
|
-
let files = [];
|
|
175
|
+
let files = [];
|
|
176
|
+
try {
|
|
177
|
+
files = fs.readdirSync(d).filter((f) => f.endsWith('.json'));
|
|
178
|
+
} catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
98
181
|
for (const f of files) {
|
|
99
|
-
let r;
|
|
100
|
-
|
|
182
|
+
let r;
|
|
183
|
+
try {
|
|
184
|
+
r = readJson(path.join(d, f)).rules;
|
|
185
|
+
} catch {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (['strength', 'modulus', 'density', 'modulus_z'].every((k) => typeof r?.[k]?.value === 'number') && !rubber(r))
|
|
189
|
+
out.add(f.slice(0, -5));
|
|
101
190
|
}
|
|
102
191
|
}
|
|
103
192
|
return [...out].sort();
|
|
@@ -110,12 +199,21 @@ export function plastics() {
|
|
|
110
199
|
* @param {object} s a built assembly @returns {{ id: string, of: string, fitting: object, grams: number }[]}
|
|
111
200
|
*/
|
|
112
201
|
export function companions(s) {
|
|
113
|
-
const items = s.items ?? [],
|
|
202
|
+
const items = s.items ?? [],
|
|
203
|
+
out = [];
|
|
114
204
|
for (const o of s.objects) {
|
|
115
205
|
if (o.unplaced || o.fitting?.fitting !== 'levelling-foot' || !o.fitting.printed) continue;
|
|
116
206
|
const it = items.find((x) => x.id === o.id);
|
|
117
207
|
if (!it?.fitting || (it.fitting.part ?? 'body') !== 'body') continue;
|
|
118
|
-
if (
|
|
208
|
+
if (
|
|
209
|
+
items.some(
|
|
210
|
+
(x) =>
|
|
211
|
+
x.fitting?.kind === 'levelling-foot' &&
|
|
212
|
+
x.fitting.part === 'pad' &&
|
|
213
|
+
JSON.stringify(x.at) === JSON.stringify(it.at),
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
continue;
|
|
119
217
|
const { pose, ...spec } = it.fitting;
|
|
120
218
|
out.push({ id: `${o.id}-pad`, of: o.id, fitting: { ...spec, part: 'pad' }, grams: o.fitting.padGrams });
|
|
121
219
|
}
|
|
@@ -128,36 +226,88 @@ export function companions(s) {
|
|
|
128
226
|
* @param {object} context framesContext()'s @param {string | object} [material] pla, petg or a material's rule set (plasticOf) @param {string} [what] who asks
|
|
129
227
|
*/
|
|
130
228
|
export function fittingModel(spec, context, material = 'pla', what = 'fitting') {
|
|
131
|
-
if (!spec || typeof spec !== 'object' || Array.isArray(spec))
|
|
132
|
-
|
|
229
|
+
if (!spec || typeof spec !== 'object' || Array.isArray(spec))
|
|
230
|
+
throw new Error(`${what}: fitting is { "kind": "bracket", "profile": "2020-misumi-hfs5" } (got ${shown(spec)})`);
|
|
231
|
+
if (!FITTING_KINDS.includes(spec?.kind))
|
|
232
|
+
throw new Error(`${what}: fitting.kind is one of ${FITTING_KINDS.join(', ')} (got ${shown(spec?.kind)})`);
|
|
133
233
|
if (MORE[spec.kind]) return moreModel(spec, context, material, what);
|
|
134
|
-
for (const k of Object.keys(spec))
|
|
135
|
-
|
|
234
|
+
for (const k of Object.keys(spec))
|
|
235
|
+
if (!KEYS.includes(k)) throw new Error(`${what}: a fitting has no "${k}": it takes ${KEYS.join(', ')}`);
|
|
236
|
+
const given = givenFor(context, spec.profile),
|
|
237
|
+
o = { given, material, cache: fittingCache };
|
|
136
238
|
for (const k of ['thread', 'head', 'nut', 'load']) if (spec[k] != null) o[k] = spec[k];
|
|
137
239
|
try {
|
|
138
|
-
if (spec.kind === 'bracket')
|
|
139
|
-
|
|
140
|
-
|
|
240
|
+
if (spec.kind === 'bracket')
|
|
241
|
+
return bracketModel(spec.profile, {
|
|
242
|
+
...o,
|
|
243
|
+
...(spec.other ? { other: spec.other } : {}),
|
|
244
|
+
...(spec.face ? { face: spec.face } : {}),
|
|
245
|
+
...(spec.otherFace ? { otherFace: spec.otherFace } : {}),
|
|
246
|
+
...(spec.brace != null ? { brace: spec.brace } : {}),
|
|
247
|
+
});
|
|
248
|
+
return plateModel(spec.profile, {
|
|
249
|
+
...o,
|
|
250
|
+
shape: spec.kind === 'splice' ? 'splice' : (spec.shape ?? 'L'),
|
|
251
|
+
...(spec.other ? { other: spec.other } : {}),
|
|
252
|
+
...(spec.face ? { face: spec.face } : {}),
|
|
253
|
+
...(spec.count != null ? { count: spec.count } : {}),
|
|
254
|
+
});
|
|
255
|
+
} catch (e) {
|
|
256
|
+
throw new Error(`${what}: ${strip(e)}`);
|
|
257
|
+
}
|
|
141
258
|
}
|
|
142
259
|
|
|
143
260
|
// A panel's, a door's or an end's fitting: its options are the model's own (refused by name there), its part chosen
|
|
144
261
|
function moreModel(spec, context, material, what) {
|
|
145
|
-
const [model, , o = {}] = MORE[spec.kind],
|
|
262
|
+
const [model, , o = {}] = MORE[spec.kind],
|
|
263
|
+
{ kind, profile, part, ...rest } = spec;
|
|
146
264
|
// (a device mount names its device's rule set, which is read here: its holes come from it)
|
|
147
265
|
if (kind === 'device-mount') {
|
|
148
|
-
if (typeof rest.device !== 'string')
|
|
149
|
-
|
|
266
|
+
if (typeof rest.device !== 'string')
|
|
267
|
+
throw new Error(
|
|
268
|
+
`${what}: a device mount names its device's rule set in "device", as supply-24v (got ${shown(rest.device)})`,
|
|
269
|
+
);
|
|
270
|
+
try {
|
|
271
|
+
rest.device = peekRuleSet(rest.device);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
throw new Error(`${what}: device: ${e.message}`);
|
|
274
|
+
}
|
|
150
275
|
}
|
|
151
|
-
if (o.parts ? part != null && !o.parts.includes(part) : part != null)
|
|
152
|
-
|
|
153
|
-
|
|
276
|
+
if (o.parts ? part != null && !o.parts.includes(part) : part != null)
|
|
277
|
+
throw new Error(
|
|
278
|
+
`${what}: ${o.parts ? `part is ${o.parts.join(' or ')}` : `a ${kind} has one part: leave part out`} (got ${shown(part)})`,
|
|
279
|
+
);
|
|
280
|
+
if (o.profile !== false && typeof profile !== 'string')
|
|
281
|
+
throw new Error(
|
|
282
|
+
`${what}: a ${kind} is drawn for a profile: give "profile", as 2020-misumi-hfs5 (got ${shown(profile)})`,
|
|
283
|
+
);
|
|
284
|
+
if (o.profile === false && profile != null)
|
|
285
|
+
throw new Error(`${what}: a ${kind} is drawn for no profile: leave profile out`);
|
|
154
286
|
// (a gasket strip is PETG, which springs back, unless the item says otherwise; the rest take the project's plastic)
|
|
155
287
|
try {
|
|
156
|
-
const m =
|
|
288
|
+
const m =
|
|
289
|
+
o.profile === false
|
|
290
|
+
? frames[model]({ ...(kind === 'gasket-strip' ? {} : { material }), ...rest })
|
|
291
|
+
: frames[model](profile, { given: givenFor(context, profile), material, ...rest });
|
|
157
292
|
// (a printed carrier in a slot is its own kind of model: named here as a fitting, with the nut or insert it holds to buy)
|
|
158
|
-
if (kind === 'nut-carrier')
|
|
293
|
+
if (kind === 'nut-carrier')
|
|
294
|
+
return {
|
|
295
|
+
...m,
|
|
296
|
+
fitting: 'nut-carrier',
|
|
297
|
+
hardware: [
|
|
298
|
+
{
|
|
299
|
+
kind: m.holds === 'insert' ? 'insert' : 'nut',
|
|
300
|
+
name: `${m.thread} ${m.holds === 'insert' ? 'heat-set insert' : 'hex nut'}`,
|
|
301
|
+
thread: m.thread,
|
|
302
|
+
count: m.count ?? 1,
|
|
303
|
+
why: `held in the carrier, ${m.holds === 'insert' ? 'pressed in from below' : 'slid in from the side'}`,
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
159
307
|
return m;
|
|
160
|
-
} catch (e) {
|
|
308
|
+
} catch (e) {
|
|
309
|
+
throw new Error(`${what}: ${String(e?.message ?? e).replace(/^\w+: /, '')}`);
|
|
310
|
+
}
|
|
161
311
|
}
|
|
162
312
|
|
|
163
313
|
/**
|
|
@@ -168,23 +318,82 @@ function moreModel(spec, context, material, what) {
|
|
|
168
318
|
export async function fittingBuilt(it, id, context, material = 'pla') {
|
|
169
319
|
// "pose": "print" lays it as it prints, for a plate (cad plates writes it so); the model is the same either way
|
|
170
320
|
const { pose = 'fit', ...spec } = it.fitting ?? {};
|
|
171
|
-
if (pose !== 'fit' && pose !== 'print')
|
|
321
|
+
if (pose !== 'fit' && pose !== 'print')
|
|
322
|
+
throw new Error(
|
|
323
|
+
`item ${id}: fitting.pose is fit (in its place, the default) or print (as it prints, for a plate) (got ${shown(pose)})`,
|
|
324
|
+
);
|
|
172
325
|
const m = fittingModel(spec, context, material, `item ${id}`);
|
|
173
326
|
// joined and cut by Manifold where the workspace has it, so the solid is watertight for the overlap check (JSCAD's
|
|
174
327
|
// booleans leave seams that Manifold cannot read, and JSCAD's own intersection then misreads a head in its seat)
|
|
175
|
-
let ops = null;
|
|
328
|
+
let ops = null;
|
|
329
|
+
try {
|
|
330
|
+
ops = await booleans('manifold');
|
|
331
|
+
} catch {
|
|
332
|
+
// (Manifold isn't installed: JSCAD's own booleans cut the fitting)
|
|
333
|
+
}
|
|
176
334
|
if (MORE[it.fitting.kind]) return moreBuilt(it, id, m, ops, pose);
|
|
177
|
-
const draw = (o) => {
|
|
335
|
+
const draw = (o) => {
|
|
336
|
+
const f = m.fitting === 'bracket' ? bracket : plate;
|
|
337
|
+
try {
|
|
338
|
+
return f(m, { ...o, ...(ops ? { ops } : {}) });
|
|
339
|
+
} catch {
|
|
340
|
+
return f(m, o);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
178
343
|
const parts = named({ body: draw({ pose }) }, { body: { label: m.title } });
|
|
179
344
|
// its tongues stand in the slots, inside the beams' envelopes: the overlap check measures the body without them
|
|
180
345
|
if (pose === 'fit') parts[0].collide = named({ body: draw({ pose: 'fit', tongues: false }) }, {})[0].geometry;
|
|
181
346
|
// an anchor on each screw's axis at its head's seat, z out of the fitting toward the head: b1, b2 .. into b; a1 .. into a
|
|
182
|
-
const count = { a: 0, b: 0 },
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
347
|
+
const count = { a: 0, b: 0 },
|
|
348
|
+
anchors = Object.fromEntries(
|
|
349
|
+
m.screws.map((sc) => [
|
|
350
|
+
`${sc.leg}${++count[sc.leg]}`,
|
|
351
|
+
{
|
|
352
|
+
at: m.fitting === 'bracket' ? sc.at : [sc.at[0], sc.at[1], m.thickness],
|
|
353
|
+
axis: sc.axis.map((c) => (c ? -c : 0)),
|
|
354
|
+
},
|
|
355
|
+
]),
|
|
356
|
+
);
|
|
357
|
+
const values = {
|
|
358
|
+
thickness: m.thickness,
|
|
359
|
+
width: m.width,
|
|
360
|
+
grams: m.grams,
|
|
361
|
+
margin: m.margin,
|
|
362
|
+
stiffness: m.stiffness.bending,
|
|
363
|
+
load: m.load.force,
|
|
364
|
+
...(m.leg ? { leg: m.leg } : { arm: m.arm }),
|
|
365
|
+
};
|
|
366
|
+
const entries = Object.entries({
|
|
367
|
+
thickness: ['mm', 'sized from the load'],
|
|
368
|
+
grams: ['g', 'its mass'],
|
|
369
|
+
margin: ['×', 'its strength over the peak stress at the load, by finite elements'],
|
|
370
|
+
stiffness: ['N mm/rad', 'its own bending stiffness about the joint, by finite elements'],
|
|
371
|
+
}).map(([k, [unit, rule]]) => ({
|
|
372
|
+
name: `${m.name}.${k}`,
|
|
373
|
+
value: values[k],
|
|
374
|
+
unit,
|
|
375
|
+
rule: `The printed fitting's ${rule}`,
|
|
376
|
+
kind: 'derived',
|
|
377
|
+
source: '@rulecad/frames fitting.mjs',
|
|
378
|
+
checked: '2026-11-17',
|
|
379
|
+
set: m.name,
|
|
380
|
+
}));
|
|
381
|
+
const hash = crypto
|
|
382
|
+
.createHash('sha256')
|
|
383
|
+
.update(JSON.stringify([it.fitting, material, m.name, m.thickness, m.grams]))
|
|
384
|
+
.digest('hex')
|
|
385
|
+
.slice(0, 16);
|
|
386
|
+
const b = {
|
|
387
|
+
object: { name: m.name, title: m.title, role: 'part', version: '0.0.0', anchors },
|
|
388
|
+
values,
|
|
389
|
+
entries,
|
|
390
|
+
deps: [],
|
|
391
|
+
units: {},
|
|
392
|
+
parts,
|
|
393
|
+
polygons: parts.flatMap((p) => p.polygons),
|
|
394
|
+
triangles: parts.flatMap((p) => p.triangles),
|
|
395
|
+
hash,
|
|
396
|
+
};
|
|
188
397
|
return { key: `fitting:${id}:${hash}`, objName: `fitting:${m.name}`, b, version: '0.0.0', role: 'part', fitting: m };
|
|
189
398
|
}
|
|
190
399
|
|
|
@@ -192,27 +401,77 @@ export async function fittingBuilt(it, id, context, material = 'pla') {
|
|
|
192
401
|
// an anchor on each screw's axis at its head (b1, b2 .. for screws into a slot or a bore; d1, d2 .. for a hinge's
|
|
193
402
|
// door leaf's, through the door); a hinge's door leaf and a levelling foot's pad carry no findings or hardware of their own
|
|
194
403
|
function moreBuilt(it, id, m, ops, pose = 'fit') {
|
|
195
|
-
const [, solid, o = {}] = MORE[it.fitting.kind],
|
|
196
|
-
|
|
404
|
+
const [, solid, o = {}] = MORE[it.fitting.kind],
|
|
405
|
+
part = it.fitting.part ?? o.parts?.[0],
|
|
406
|
+
second = o.parts && part !== o.parts[0];
|
|
407
|
+
const drawn = o.pose?.[pose] ?? pose,
|
|
408
|
+
draw = (x) => {
|
|
409
|
+
const f = (y) => frames[solid](m, { pose: drawn, ...(part ? { part } : {}), ...x, ...y });
|
|
410
|
+
try {
|
|
411
|
+
return f(ops ? { ops } : {});
|
|
412
|
+
} catch {
|
|
413
|
+
return f({});
|
|
414
|
+
}
|
|
415
|
+
};
|
|
197
416
|
const parts = named({ body: draw({}) }, { body: { label: `${m.title}${part ? `, ${part}` : ''}` } });
|
|
198
|
-
if (TONGUED.includes(m.fitting) && pose === 'fit')
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
417
|
+
if (TONGUED.includes(m.fitting) && pose === 'fit')
|
|
418
|
+
parts[0].collide = named({ body: draw({ tongues: false }) }, {})[0].geometry;
|
|
419
|
+
if (IN_SLOT.includes(m.fitting) && pose === 'fit') {
|
|
420
|
+
const { intersect } = jscad.booleans,
|
|
421
|
+
{ cuboid } = jscad.primitives,
|
|
422
|
+
above = intersect(parts[0].geometry, cuboid({ size: [1e4, 1e4, 1e3], center: [0, 0, 500] }));
|
|
423
|
+
parts[0].collide = above;
|
|
424
|
+
}
|
|
425
|
+
const list =
|
|
426
|
+
it.fitting.kind === 'hinge' && part === 'door'
|
|
427
|
+
? m.door.map((q, k) => [`d${k + 1}`, q])
|
|
428
|
+
: (m.screws ?? []).filter((q) => q.into !== 'castor' && q.into !== 'pilot').map((q, k) => [`b${k + 1}`, q]);
|
|
429
|
+
const anchors = {
|
|
430
|
+
...Object.fromEntries(list.map(([n, q]) => [n, { at: q.at, axis: q.axis.map((c) => (c ? -c : 0)) }])),
|
|
431
|
+
...(m.anchors ?? {}),
|
|
432
|
+
}; // (and its own: a mount's device and screws, a clip's cable)
|
|
433
|
+
const values = {
|
|
434
|
+
grams: m.grams,
|
|
435
|
+
...(m.margin != null && Number.isFinite(m.margin) ? { margin: m.margin } : {}),
|
|
436
|
+
...(m.load?.force ? { load: m.load.force } : {}),
|
|
437
|
+
};
|
|
438
|
+
const hash = crypto
|
|
439
|
+
.createHash('sha256')
|
|
440
|
+
.update(JSON.stringify([it.fitting, m.name, m.grams, part]))
|
|
441
|
+
.digest('hex')
|
|
442
|
+
.slice(0, 16);
|
|
443
|
+
const b = {
|
|
444
|
+
object: { name: `${m.name}${part ? `-${part}` : ''}`, title: m.title, role: 'part', version: '0.0.0', anchors },
|
|
445
|
+
values,
|
|
446
|
+
entries: [],
|
|
447
|
+
deps: [],
|
|
448
|
+
units: {},
|
|
449
|
+
parts,
|
|
450
|
+
polygons: parts.flatMap((p) => p.polygons),
|
|
451
|
+
triangles: parts.flatMap((p) => p.triangles),
|
|
452
|
+
hash,
|
|
453
|
+
};
|
|
205
454
|
const model = second ? { ...m, findings: [], hardware: [] } : m;
|
|
206
|
-
return {
|
|
455
|
+
return {
|
|
456
|
+
key: `fitting:${id}:${hash}`,
|
|
457
|
+
objName: `fitting:${m.name}${part ? `-${part}` : ''}`,
|
|
458
|
+
b,
|
|
459
|
+
version: '0.0.0',
|
|
460
|
+
role: 'part',
|
|
461
|
+
fitting: model,
|
|
462
|
+
};
|
|
207
463
|
}
|
|
208
464
|
|
|
209
465
|
// ---------- a join's printed fitting, placed ----------
|
|
210
|
-
const col = (f, k) => [f[k], f[4 + k], f[8 + k]]
|
|
211
|
-
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2],
|
|
466
|
+
const col = (f, k) => [f[k], f[4 + k], f[8 + k]];
|
|
467
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2],
|
|
468
|
+
sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
212
469
|
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
213
|
-
const world = (f, p) =>
|
|
470
|
+
const world = (f, p) =>
|
|
471
|
+
[0, 1, 2].map((k) => f[4 * k] * p[0] + f[4 * k + 1] * p[1] + f[4 * k + 2] * p[2] + f[4 * k + 3]);
|
|
214
472
|
const turn = (f, v) => [0, 1, 2].map((k) => f[4 * k] * v[0] + f[4 * k + 1] * v[1] + f[4 * k + 2] * v[2]);
|
|
215
|
-
const mm = (x) => String(+Number(x).toFixed(2)),
|
|
473
|
+
const mm = (x) => String(+Number(x).toFixed(2)),
|
|
474
|
+
r3 = (x) => +x.toFixed(3);
|
|
216
475
|
// a place's face as slotSide takes it: top, or top.2 where the face has two slots
|
|
217
476
|
const faceOf = (B, place) => (B.places.filter((q) => q.face === place.face).length > 1 ? place.name : place.face);
|
|
218
477
|
|
|
@@ -225,57 +484,172 @@ const faceOf = (B, place) => (B.places.filter((q) => q.face === place.face).leng
|
|
|
225
484
|
* @returns {{ item: object, fasten: object[], model: object, stiffness: object }}
|
|
226
485
|
*/
|
|
227
486
|
export function joinFitting(j, i, { ia, ib, A, B, m, ends, place: placeOf }, num, context, material, ids) {
|
|
228
|
-
const what = `join ${i + 1}`,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
487
|
+
const what = `join ${i + 1}`,
|
|
488
|
+
label = j.note || `${j.kind} join of ${j.a} to ${j.b}`,
|
|
489
|
+
bm = m.fitting?.bought ?? null,
|
|
490
|
+
made = bm ? bm.set : `a printed ${j.kind}`;
|
|
491
|
+
const fa = placeOf(ia, num),
|
|
492
|
+
fb = placeOf(ib, num);
|
|
493
|
+
if (!fa || !fb)
|
|
494
|
+
throw new Error(
|
|
495
|
+
`${what}: ${made} is placed from where the beams are: place ${!fa ? ia.id : ib.id} by its ends (from, to)`,
|
|
496
|
+
);
|
|
497
|
+
const free = (base) => {
|
|
498
|
+
let n = base,
|
|
499
|
+
k = 2;
|
|
500
|
+
while (ids.has(n)) n = `${base}-${k++}`;
|
|
501
|
+
ids.add(n);
|
|
502
|
+
return n;
|
|
503
|
+
};
|
|
232
504
|
// a bought anchor connector: its post along a's axis from b's face, at the place on b the join names
|
|
233
505
|
if (bm && j.kind === 'anchor') {
|
|
234
506
|
const id = free(`${ia.id}-${ib.id}-${j.kind}`);
|
|
235
|
-
return {
|
|
507
|
+
return {
|
|
508
|
+
item: { id, bought: bm.set, at: `${ib.id}.${m.b.place}@${r3(m.b.distance)}`, join: i },
|
|
509
|
+
fasten: [],
|
|
510
|
+
model: bm,
|
|
511
|
+
};
|
|
236
512
|
}
|
|
237
513
|
// its screws, each by the set's thread, length and head, into the set's nut where it names one (a corner bracket's
|
|
238
514
|
// and a plate's); an inner connector's grub screws are part of it
|
|
239
|
-
const boughtFasten = (id, legs) =>
|
|
515
|
+
const boughtFasten = (id, legs) =>
|
|
516
|
+
legs.map(([leg, beam, place]) => ({
|
|
517
|
+
screw: `${bm.thread}${bm.length != null ? `x${bm.length}` : ''} ${bm.head}`,
|
|
518
|
+
through: [id],
|
|
519
|
+
into: `${beam}.${place}`,
|
|
520
|
+
at: bm.screws.filter((q) => q.leg === leg).map((_, k) => `${id}.${leg}${k + 1}`),
|
|
521
|
+
note: `${label}: ${bm.set} into ${beam}`,
|
|
522
|
+
join: i,
|
|
523
|
+
...(bm.nutKind ? { nut: bm.nutKind } : {}),
|
|
524
|
+
}));
|
|
240
525
|
if (j.kind === 'bracket' || j.kind === 'hidden') {
|
|
241
|
-
const bp = B.places.find((q) => q.name === m.b.place),
|
|
242
|
-
|
|
526
|
+
const bp = B.places.find((q) => q.name === m.b.place),
|
|
527
|
+
d = m.b.distance,
|
|
528
|
+
ub = col(fb, 2),
|
|
529
|
+
nb = turn(fb, [...bp.normal, 0]);
|
|
530
|
+
const P = world(fb, [bp.at[0], bp.at[1], d]),
|
|
531
|
+
roomB = B.length - d,
|
|
532
|
+
sign = roomB >= d ? 1 : -1,
|
|
533
|
+
dir = ub.map((c) => c * sign);
|
|
243
534
|
// a's face that looks along b, toward the side with more room; of its slots, the one in the bracket's plane
|
|
244
|
-
const z = cross(dir, nb),
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
535
|
+
const z = cross(dir, nb),
|
|
536
|
+
faces = A.places.filter((q) => q.slot && dot(turn(fa, [...q.normal, 0]), dir) > 1 - 1e-6);
|
|
537
|
+
if (!faces.length)
|
|
538
|
+
throw new Error(
|
|
539
|
+
`${what}: a printed bracket lies on a face of ${ia.id} that looks along ${ib.id}, and none of ${ia.id}'s slotted faces does: turn ${ia.id} with roll so one faces along ${ib.id}`,
|
|
540
|
+
);
|
|
541
|
+
const ap = faces
|
|
542
|
+
.map((q) => ({ q, Q: world(fa, [q.at[0], q.at[1], 0]) }))
|
|
543
|
+
.sort((x, y) => Math.abs(dot(sub(x.Q, P), z)) - Math.abs(dot(sub(y.Q, P), z)))[0];
|
|
544
|
+
const off = dot(sub(ap.Q, P), dir),
|
|
545
|
+
at = d + sign * off,
|
|
546
|
+
spec = {
|
|
547
|
+
kind: 'bracket',
|
|
548
|
+
profile: B.profile.name,
|
|
549
|
+
...(A.profile.name !== B.profile.name ? { other: A.profile.name } : {}),
|
|
550
|
+
face: faceOf(B, bp),
|
|
551
|
+
otherFace: faceOf(A, ap.q),
|
|
552
|
+
...(j.brace != null ? { brace: j.brace } : {}),
|
|
553
|
+
...(j.load != null ? { load: j.load } : {}),
|
|
554
|
+
...(j.nut ? { nut: j.nut } : {}),
|
|
555
|
+
};
|
|
556
|
+
const fm = bm ?? fittingModel(spec, context, material, what),
|
|
557
|
+
room = sign > 0 ? B.length - at : at,
|
|
558
|
+
endA = ends.a.rest[0],
|
|
559
|
+
aRoom = A.length,
|
|
560
|
+
said = bm ? `${bm.set}'s` : "a printed bracket's";
|
|
561
|
+
if (room < fm.leg - 1e-6)
|
|
562
|
+
throw new Error(
|
|
563
|
+
`${what}: ${said} ${mm(fm.leg)} mm leg runs ${mm(fm.leg - room)} mm past ${ib.id}'s end ${sign > 0 ? 'b' : 'a'}: it goes on the side of ${ia.id} with more of ${ib.id}, and there is only ${mm(room)} mm there. A gusset or a blind join will do`,
|
|
564
|
+
);
|
|
565
|
+
if (aRoom < (fm.legA ?? fm.leg) - 1e-6)
|
|
566
|
+
throw new Error(`${what}: ${said} ${mm(fm.legA ?? fm.leg)} mm leg is longer than ${ia.id} (${mm(aRoom)} mm)`);
|
|
251
567
|
const id = free(`${ia.id}-${ib.id}-${bm ? j.kind : 'bracket'}`);
|
|
252
568
|
if (bm) {
|
|
253
|
-
const item = {
|
|
254
|
-
|
|
569
|
+
const item = {
|
|
570
|
+
id,
|
|
571
|
+
bought: bm.set,
|
|
572
|
+
at: `${ib.id}.${bp.name}@${r3(at)}`,
|
|
573
|
+
rotate: sign > 0 ? [90, 0, 0] : [90, 0, 180],
|
|
574
|
+
join: i,
|
|
575
|
+
};
|
|
576
|
+
return {
|
|
577
|
+
item,
|
|
578
|
+
fasten:
|
|
579
|
+
j.kind === 'hidden'
|
|
580
|
+
? []
|
|
581
|
+
: boughtFasten(id, [
|
|
582
|
+
['b', ib.id, bp.name],
|
|
583
|
+
['a', ia.id, ap.q.name],
|
|
584
|
+
]),
|
|
585
|
+
model: bm,
|
|
586
|
+
side: sign > 0 ? 'b' : 'a',
|
|
587
|
+
endA,
|
|
588
|
+
};
|
|
255
589
|
}
|
|
256
|
-
const item = {
|
|
590
|
+
const item = {
|
|
591
|
+
id,
|
|
592
|
+
fitting: spec,
|
|
593
|
+
at: `${ib.id}.${bp.name}@${r3(at)}`,
|
|
594
|
+
rotate: sign > 0 ? [90, 0, 0] : [90, 0, 180],
|
|
595
|
+
join: i,
|
|
596
|
+
};
|
|
257
597
|
const screw = `${fm.thread} ${fm.head}`;
|
|
258
598
|
// (each into the slot nut the bracket was drawn for, so the screw it was thickened for is the one chosen)
|
|
259
|
-
const fasten = [
|
|
260
|
-
{
|
|
599
|
+
const fasten = [
|
|
600
|
+
{
|
|
601
|
+
screw,
|
|
602
|
+
through: [id],
|
|
603
|
+
into: `${ib.id}.${bp.name}`,
|
|
604
|
+
at: [`${id}.b1`],
|
|
605
|
+
note: `${label}: the bracket into ${ib.id}`,
|
|
606
|
+
join: i,
|
|
607
|
+
nut: j.nut ?? fm.screws[0].nutKind,
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
screw,
|
|
611
|
+
through: [id],
|
|
612
|
+
into: `${ia.id}.${ap.q.name}`,
|
|
613
|
+
at: [`${id}.a1`],
|
|
614
|
+
note: `${label}: the bracket into ${ia.id}`,
|
|
615
|
+
join: i,
|
|
616
|
+
nut: j.nut ?? fm.screws[1].nutKind,
|
|
617
|
+
},
|
|
618
|
+
];
|
|
261
619
|
return { item, fasten, model: fm, side: sign > 0 ? 'b' : 'a', endA };
|
|
262
620
|
}
|
|
263
621
|
// a plate (a gusset, or a splice plate): on a face of each beam, the two in one plane. Its frame: x along b away from
|
|
264
622
|
// the joint (a gusset's toward b's end with more room; a splice's into b), y along a away from b (a splice's across),
|
|
265
623
|
// z out of the faces; it sits at an address on b, turned in that frame
|
|
266
|
-
const splice = j.kind === 'splice',
|
|
624
|
+
const splice = j.kind === 'splice',
|
|
625
|
+
ua = col(fa, 2).map((c) => (ends.a.rest[0] === 'a' ? c : -c)),
|
|
626
|
+
ub = col(fb, 2);
|
|
267
627
|
const d = splice ? (m.b.end === 'a' ? 0 : B.length) : m.b.distance;
|
|
268
|
-
let x,
|
|
628
|
+
let x,
|
|
629
|
+
y,
|
|
630
|
+
n,
|
|
631
|
+
shapeAt = null;
|
|
269
632
|
if (splice) {
|
|
270
633
|
x = ub.map((c) => (m.b.end === 'a' ? c : -c));
|
|
271
|
-
const bq = B.places.find(
|
|
272
|
-
|
|
273
|
-
|
|
634
|
+
const bq = B.places.find(
|
|
635
|
+
(q) =>
|
|
636
|
+
q.slot &&
|
|
637
|
+
Math.abs(dot(turn(fb, [...q.normal, 0]), x)) < 1e-6 &&
|
|
638
|
+
A.places.some((r) => r.slot && dot(turn(fa, [...r.normal, 0]), turn(fb, [...q.normal, 0])) > 1 - 1e-6),
|
|
639
|
+
);
|
|
640
|
+
if (!bq)
|
|
641
|
+
throw new Error(
|
|
642
|
+
`${what}: a printed splice plate lies on a slotted face of both beams, in one plane, and ${ia.id} and ${ib.id} share none`,
|
|
643
|
+
);
|
|
644
|
+
n = turn(fb, [...bq.normal, 0]);
|
|
645
|
+
y = cross(n, x);
|
|
274
646
|
} else {
|
|
275
647
|
const half = Math.max(A.profile.width, A.profile.height) / 2;
|
|
276
648
|
const room = { b: B.length - d - half, a: d - half };
|
|
277
649
|
shapeAt = { room };
|
|
278
|
-
x = ub.map((c) => (room.b >= room.a ? c : -c));
|
|
650
|
+
x = ub.map((c) => (room.b >= room.a ? c : -c));
|
|
651
|
+
y = ua;
|
|
652
|
+
n = cross(x, y);
|
|
279
653
|
}
|
|
280
654
|
// a gusset on the other face of b (j.face): the same L turned over its diagonal, its arm drawn for b along a and its
|
|
281
655
|
// arm drawn for a along b, so it lies on the faces looking along -n (a mirror image of the L is itself turned so)
|
|
@@ -284,44 +658,139 @@ export function joinFitting(j, i, { ia, ib, A, B, m, ends, place: placeOf }, num
|
|
|
284
658
|
const want = B.places.find((q) => q.slot && (q.name === j.face || (q.face === j.face && q.name.endsWith('.1'))));
|
|
285
659
|
const along = want ? dot(turn(fb, [...want.normal, 0]), n) : 0;
|
|
286
660
|
if (!want || Math.abs(Math.abs(along) - 1) > 1e-6) {
|
|
287
|
-
const can = B.places
|
|
288
|
-
|
|
661
|
+
const can = B.places
|
|
662
|
+
.filter((q) => q.slot && Math.abs(Math.abs(dot(turn(fb, [...q.normal, 0]), n)) - 1) < 1e-6)
|
|
663
|
+
.map((q) => faceOf(B, q));
|
|
664
|
+
throw new Error(
|
|
665
|
+
`${what}: face is the face of ${ib.id} a printed gusset lies on, square to ${ia.id}: ${[...new Set(can)].join(' or ') || 'none of its slotted faces is'} (got ${JSON.stringify(j.face)})`,
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
if (along < 0) {
|
|
669
|
+
flip = true;
|
|
670
|
+
n = n.map((c) => -c);
|
|
289
671
|
}
|
|
290
|
-
if (along < 0) { flip = true; n = n.map((c) => -c); }
|
|
291
672
|
}
|
|
292
|
-
const bq = B.places.find((q) => q.slot && dot(turn(fb, [...q.normal, 0]), n) > 1 - 1e-6),
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
673
|
+
const bq = B.places.find((q) => q.slot && dot(turn(fb, [...q.normal, 0]), n) > 1 - 1e-6),
|
|
674
|
+
aq = A.places.find((q) => q.slot && dot(turn(fa, [...q.normal, 0]), n) > 1 - 1e-6);
|
|
675
|
+
if (!bq || !aq)
|
|
676
|
+
throw new Error(
|
|
677
|
+
`${what}: a printed ${splice ? 'splice plate' : 'gusset'} lies on a slotted face of both beams that looks the same way, and ${!bq ? ib.id : ia.id} has none that does: turn it with roll`,
|
|
678
|
+
);
|
|
679
|
+
const Pb = world(fb, [bq.at[0], bq.at[1], d]),
|
|
680
|
+
Qa = world(fa, [aq.at[0], aq.at[1], 0]),
|
|
681
|
+
apart = dot(sub(Qa, Pb), n);
|
|
682
|
+
if (Math.abs(apart) > 0.05)
|
|
683
|
+
throw new Error(
|
|
684
|
+
`${what}: a printed ${splice ? 'splice plate' : 'gusset'} lies flat on both beams, and ${ia.id}'s ${aq.face} face stands ${mm(Math.abs(apart))} mm ${apart > 0 ? 'proud of' : 'below'} ${ib.id}'s ${bq.face} face`,
|
|
685
|
+
);
|
|
686
|
+
const spec0 = {
|
|
687
|
+
kind: splice ? 'splice' : 'gusset',
|
|
688
|
+
profile: B.profile.name,
|
|
689
|
+
...(A.profile.name !== B.profile.name ? { other: A.profile.name } : {}),
|
|
690
|
+
face: faceOf(B, bq),
|
|
691
|
+
...(j.load != null ? { load: j.load } : {}),
|
|
692
|
+
...(j.nut ? { nut: j.nut } : {}),
|
|
693
|
+
};
|
|
694
|
+
let fm = bm ?? fittingModel({ ...spec0, ...(splice ? {} : { shape: 'L' }) }, context, material, what),
|
|
695
|
+
shape = bm?.shape ?? 'L';
|
|
298
696
|
if (bm) {
|
|
299
697
|
// a bought plate's shape is its set's: a T needs room along b both sides of a, an L on one
|
|
300
|
-
const { room } = shapeAt ?? { room: { a: Infinity, b: Infinity } },
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
698
|
+
const { room } = shapeAt ?? { room: { a: Infinity, b: Infinity } },
|
|
699
|
+
xs = fm.outline.map((q) => q[0]),
|
|
700
|
+
reach = Math.max(...xs.map(Math.abs));
|
|
701
|
+
if (shape === 'T' && Math.min(room.a, room.b) + A.profile.width / 2 < reach - 1e-6)
|
|
702
|
+
throw new Error(
|
|
703
|
+
`${what}: ${bm.set} is a T, ${mm(2 * reach)} mm along ${ib.id}, and there is ${mm(Math.min(room.a, room.b))} mm on one side of ${ia.id}: an L or a bracket will do`,
|
|
704
|
+
);
|
|
705
|
+
const id = free(`${ia.id}-${ib.id}-${splice ? 'splice' : 'gusset'}`),
|
|
706
|
+
along = dot(x, ub) > 0;
|
|
707
|
+
const item = {
|
|
708
|
+
id,
|
|
709
|
+
bought: bm.set,
|
|
710
|
+
at: `${ib.id}.${bq.name}@${r3(d)}`,
|
|
711
|
+
...(along ? {} : { rotate: [0, 0, 180] }),
|
|
712
|
+
join: i,
|
|
713
|
+
};
|
|
714
|
+
return {
|
|
715
|
+
item,
|
|
716
|
+
fasten: boughtFasten(id, [
|
|
717
|
+
['b', ib.id, bq.name],
|
|
718
|
+
['a', ia.id, aq.name],
|
|
719
|
+
]),
|
|
720
|
+
model: bm,
|
|
721
|
+
};
|
|
305
722
|
}
|
|
306
|
-
if (flip && (A.profile.name !== B.profile.name || aq.slot !== bq.slot))
|
|
723
|
+
if (flip && (A.profile.name !== B.profile.name || aq.slot !== bq.slot))
|
|
724
|
+
throw new Error(
|
|
725
|
+
`${what}: a printed gusset turned onto ${ib.id}'s ${j.face} face puts the arm drawn for ${ib.id}'s slot in ${ia.id}'s, and ${ia.id}'s ${aq.face} face (${aq.slot}) and ${ib.id}'s ${bq.face} face (${bq.slot}) differ: leave face out, or join with a bracket`,
|
|
726
|
+
);
|
|
307
727
|
if (!splice) {
|
|
308
|
-
const reach = fm.width / 2 + fm.arm,
|
|
728
|
+
const reach = fm.width / 2 + fm.arm,
|
|
729
|
+
{ room } = shapeAt;
|
|
309
730
|
const fits = Math.min(room.a, room.b) + fm.width / 2 >= reach;
|
|
310
|
-
if (j.shape === 'T' && flip)
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
731
|
+
if (j.shape === 'T' && flip)
|
|
732
|
+
throw new Error(
|
|
733
|
+
`${what}: shape T: a printed gusset turned onto ${ib.id}'s ${j.face} face is an L only (a T's bar would lie along ${ia.id}): give shape L, or leave face out`,
|
|
734
|
+
);
|
|
735
|
+
if (j.shape === 'T' && !fits)
|
|
736
|
+
throw new Error(
|
|
737
|
+
`${what}: shape T: a printed T gusset's bar runs ${mm(fm.arm)} mm along ${ib.id} on both sides of ${ia.id}, and there is ${mm(Math.min(room.a, room.b))} mm on one side: give shape L, or leave shape out`,
|
|
738
|
+
);
|
|
739
|
+
if (!flip && fits && j.shape !== 'L') {
|
|
740
|
+
shape = 'T';
|
|
741
|
+
fm = fittingModel({ ...spec0, shape }, context, material, what);
|
|
742
|
+
} // (an L only, turned over: a T's bar would lie along a)
|
|
743
|
+
else if (Math.max(room.a, room.b) + fm.width / 2 < reach - 1e-6)
|
|
744
|
+
throw new Error(
|
|
745
|
+
`${what}: a printed gusset's ${mm(fm.arm)} mm arm runs past ${ib.id}'s ends: there is ${mm(Math.max(room.a, room.b))} mm beside ${ia.id}, and it needs ${mm(fm.arm)}. A bracket will do`,
|
|
746
|
+
);
|
|
747
|
+
if (A.length < fm.arm - 1e-6)
|
|
748
|
+
throw new Error(`${what}: a printed gusset's ${mm(fm.arm)} mm arm is longer than ${ia.id} (${mm(A.length)} mm)`);
|
|
749
|
+
} else if (Math.min(A.length, B.length) < fm.arm - 1e-6)
|
|
750
|
+
throw new Error(
|
|
751
|
+
`${what}: a printed splice plate's ${mm(fm.arm)} mm arms are longer than ${A.length < B.length ? ia.id : ib.id}`,
|
|
752
|
+
);
|
|
753
|
+
if (A.profile.name !== B.profile.name && faceOf(A, aq) !== faceOf(B, bq))
|
|
754
|
+
throw new Error(
|
|
755
|
+
`${what}: a printed plate is drawn for one profile's slots, and ${ia.id} (${A.profile.name}) and ${ib.id} (${B.profile.name}) differ: a bracket takes two`,
|
|
756
|
+
);
|
|
757
|
+
const id = free(`${ia.id}-${ib.id}-${splice ? 'splice' : 'gusset'}`),
|
|
758
|
+
along = dot(x, ub) > 0;
|
|
318
759
|
const spec = { ...spec0, ...(splice ? {} : { shape }) };
|
|
319
760
|
// (at b's face's anchor the item's x runs along b and its z out of the face; turned over, its x runs along a: a
|
|
320
761
|
// quarter turn about z, the way that keeps its arm drawn for b along a away from b)
|
|
321
|
-
const item = {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
762
|
+
const item = {
|
|
763
|
+
id,
|
|
764
|
+
fitting: spec,
|
|
765
|
+
at: `${ib.id}.${bq.name}@${r3(d)}`,
|
|
766
|
+
...(flip ? { rotate: [0, 0, along ? -90 : 90] } : along ? {} : { rotate: [0, 0, 180] }),
|
|
767
|
+
join: i,
|
|
768
|
+
};
|
|
769
|
+
const anchorsOf = (leg) =>
|
|
770
|
+
fm.screws
|
|
771
|
+
.map((sc, k) => [sc, k])
|
|
772
|
+
.filter(([sc]) => sc.leg === (flip ? (leg === 'a' ? 'b' : 'a') : leg))
|
|
773
|
+
.map((_, k) => `${id}.${flip ? (leg === 'a' ? 'b' : 'a') : leg}${k + 1}`);
|
|
774
|
+
const fasten = [
|
|
775
|
+
{
|
|
776
|
+
screw: `${fm.thread} ${fm.head}`,
|
|
777
|
+
through: [id],
|
|
778
|
+
into: `${ib.id}.${bq.name}`,
|
|
779
|
+
at: anchorsOf('b'),
|
|
780
|
+
note: `${label}: the ${splice ? 'splice plate' : 'gusset'} into ${ib.id}`,
|
|
781
|
+
join: i,
|
|
782
|
+
nut: j.nut ?? fm.screws[0].nutKind,
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
screw: `${fm.thread} ${fm.head}`,
|
|
786
|
+
through: [id],
|
|
787
|
+
into: `${ia.id}.${aq.name}`,
|
|
788
|
+
at: anchorsOf('a'),
|
|
789
|
+
note: `${label}: the ${splice ? 'splice plate' : 'gusset'} into ${ia.id}`,
|
|
790
|
+
join: i,
|
|
791
|
+
nut: j.nut ?? fm.screws[0].nutKind,
|
|
792
|
+
},
|
|
793
|
+
];
|
|
325
794
|
return { item, fasten, model: fm };
|
|
326
795
|
}
|
|
327
796
|
|
|
@@ -332,9 +801,46 @@ export function joinFitting(j, i, { ia, ib, A, B, m, ends, place: placeOf }, num
|
|
|
332
801
|
* @param {object} k joinStiffness's @param {object} fm the fitting's model
|
|
333
802
|
*/
|
|
334
803
|
export function fittedStiffness(k, fm) {
|
|
335
|
-
const share = k.share ?? { value: 1, kind: 'estimate' },
|
|
336
|
-
|
|
337
|
-
|
|
804
|
+
const share = k.share ?? { value: 1, kind: 'estimate' },
|
|
805
|
+
fe = fm.stiffness.bending,
|
|
806
|
+
bending = fe * share.value;
|
|
807
|
+
return {
|
|
808
|
+
...k,
|
|
809
|
+
bending,
|
|
810
|
+
end: { rx: k.twist, ry: bending, rz: bending },
|
|
811
|
+
measured: { ...(k.measured ?? {}), bending: share.kind === 'measured' ? (share.checked ?? null) : null },
|
|
812
|
+
fitting: {
|
|
813
|
+
name: fm.name,
|
|
814
|
+
bending,
|
|
815
|
+
fe,
|
|
816
|
+
share: share.value,
|
|
817
|
+
shareKind: share.kind,
|
|
818
|
+
linear: fm.stiffness.linear,
|
|
819
|
+
margin: fm.margin,
|
|
820
|
+
grams: fm.grams,
|
|
821
|
+
load: fm.load.force,
|
|
822
|
+
},
|
|
823
|
+
rests: [
|
|
824
|
+
{
|
|
825
|
+
value: fe,
|
|
826
|
+
unit: 'N mm/rad',
|
|
827
|
+
kind: 'derived',
|
|
828
|
+
source: `${fm.name}: by finite elements on the printed fitting as drawn; the slot nuts and lips not in it`,
|
|
829
|
+
},
|
|
830
|
+
...(share.value !== 1 || share.kind === 'measured'
|
|
831
|
+
? [
|
|
832
|
+
{
|
|
833
|
+
value: share.value,
|
|
834
|
+
unit: '',
|
|
835
|
+
kind: share.kind,
|
|
836
|
+
source: share.source,
|
|
837
|
+
...(share.checked ? { checked: share.checked } : {}),
|
|
838
|
+
},
|
|
839
|
+
]
|
|
840
|
+
: []),
|
|
841
|
+
...k.rests.slice(1),
|
|
842
|
+
],
|
|
843
|
+
};
|
|
338
844
|
}
|
|
339
845
|
|
|
340
846
|
/**
|
|
@@ -342,5 +848,98 @@ export function fittedStiffness(k, fm) {
|
|
|
342
848
|
* fitting.stiffness, fitting.mass and the rest), each said of its item. @param {object} s a built assembly @param {Function} f the findings' sink
|
|
343
849
|
*/
|
|
344
850
|
export function fittingFindings(s, f) {
|
|
345
|
-
for (const o of s.objects)
|
|
851
|
+
for (const o of s.objects)
|
|
852
|
+
if (o.fitting && !o.unplaced)
|
|
853
|
+
for (const x of o.fitting.findings) if (!(isFoot(o) && AT_LOAD.includes(x.code))) said(f, o, x);
|
|
854
|
+
}
|
|
855
|
+
const said = (f, o, x, refs = {}) =>
|
|
856
|
+
f(
|
|
857
|
+
x.level,
|
|
858
|
+
`${o.id}: ${x.text}`,
|
|
859
|
+
x.level === 'fail' || x.level === 'warn' ? `${o.id}: ${x.code.split('.')[1]}` : null,
|
|
860
|
+
{
|
|
861
|
+
code: x.code,
|
|
862
|
+
...(x.values ? { values: x.values } : {}),
|
|
863
|
+
refs: { item: o.id, fitting: o.fitting.name, ...(x.refs ?? {}), ...refs },
|
|
864
|
+
},
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
// The printed parts a frame stands on, and their findings that hang on the load they carry: said by footFindings once
|
|
868
|
+
// the frame is solved, at the load the frame puts on each (#378)
|
|
869
|
+
const FEET = ['foot', 'levelling-foot', 'castor-plate', 'stacking-foot'],
|
|
870
|
+
AT_LOAD = ['fitting.margin', 'fitting.seat'];
|
|
871
|
+
const isFoot = (o) => FEET.includes(o.fitting?.fitting);
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Each printed foot's (a foot's, a levelling foot's, a castor plate's or a stacking foot's) fitting.margin, and a castor
|
|
875
|
+
* plate's fitting.seat, judged at the load the frame puts on it: the largest downward reaction at the beam's end it
|
|
876
|
+
* stands under, over the frame's load cases, with the joins' springs and with them rigid (the larger taken). A load
|
|
877
|
+
* given in the item's fitting is kept where it is the larger. Where the frame is not solved, or holds nothing at that
|
|
878
|
+
* end, the part is judged at the load it was drawn for, and a default load is said to be one, not the frame's.
|
|
879
|
+
* @param {object} s a built assembly @param {Function} f the findings' sink
|
|
880
|
+
* @param {{ model: object, results: object[] } | null} frame frameChecks's result: the frame's model and each case's solve
|
|
881
|
+
*/
|
|
882
|
+
export function footFindings(s, f, frame) {
|
|
883
|
+
const items = new Map((s.a.items ?? []).map((it) => [it.id, it]));
|
|
884
|
+
for (const o of s.objects) {
|
|
885
|
+
if (!isFoot(o) || o.unplaced || !o.fitting.findings.some((x) => AT_LOAD.includes(x.code))) continue;
|
|
886
|
+
const it = items.get(o.id),
|
|
887
|
+
m = o.fitting,
|
|
888
|
+
given = it?.fitting?.load != null,
|
|
889
|
+
R = frame && it ? reactionAt(frame, it.at) : null;
|
|
890
|
+
let at, refs;
|
|
891
|
+
if (R && R.force > 0 && (!given || R.force > m.load.force)) {
|
|
892
|
+
const F = +R.force.toFixed(1),
|
|
893
|
+
resize =
|
|
894
|
+
m.fitting === 'castor-plate' && F > m.load.force
|
|
895
|
+
? `; the plate was drawn for ${mm(m.load.force)} N: give its fitting "load": ${Math.ceil(F)} to size it for this`
|
|
896
|
+
: given
|
|
897
|
+
? `, more than the ${mm(m.load.force)} N its fitting gives`
|
|
898
|
+
: '';
|
|
899
|
+
at = frames.footAt(m, F, {
|
|
900
|
+
from: `the frame's largest reaction at ${R.where}${R.cases > 1 ? `, worst ${R.label}, of its ${R.cases} load cases` : ''}${R.rigid ? ', with the joins rigid' : ''}${resize}`,
|
|
901
|
+
});
|
|
902
|
+
refs = { support: R.where, reaction: F };
|
|
903
|
+
} else if (given)
|
|
904
|
+
at = frames.footAt(m, m.load.force, {
|
|
905
|
+
from:
|
|
906
|
+
R && R.force > 0
|
|
907
|
+
? `its fitting's load, more than the frame's reaction of ${mm(R.force)} N`
|
|
908
|
+
: "its fitting's load",
|
|
909
|
+
});
|
|
910
|
+
else
|
|
911
|
+
at = frames.footAt(m, m.load.force, {
|
|
912
|
+
from: `the default ${mm(frames.END_DEFAULTS.load.value)} N for one foot, not the frame's load: ${
|
|
913
|
+
!frame
|
|
914
|
+
? 'no frame is solved here'
|
|
915
|
+
: !R
|
|
916
|
+
? `the frame's solve holds nothing at ${it?.at ?? 'its end'}`
|
|
917
|
+
: 'the frame lifts off it or puts no weight on it in every load case'
|
|
918
|
+
}`,
|
|
919
|
+
});
|
|
920
|
+
for (const x of at.findings) if (AT_LOAD.includes(x.code)) said(f, o, x, refs);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
// The largest downward force the frame puts on a support at a beam's end (as "z1.a"), over its cases: with the joins'
|
|
924
|
+
// springs, or with them rigid where that is more than a hundredth larger. { force, where, label, cases, rigid }, or
|
|
925
|
+
// null where the solve holds nothing there
|
|
926
|
+
function reactionAt({ model: fm, results }, addr) {
|
|
927
|
+
const m = typeof addr === 'string' ? /^([\w-]+)\.([ab])(\.\d+)?$/.exec(addr.trim()) : null,
|
|
928
|
+
b = m && fm.beams.get(m[1]);
|
|
929
|
+
if (!b) return null;
|
|
930
|
+
const node = fm.nodeAt(b, m[2] === 'a' ? 0 : b.L),
|
|
931
|
+
most = (rigid) => {
|
|
932
|
+
let best = null;
|
|
933
|
+
for (const r of results ?? []) {
|
|
934
|
+
const six = (rigid ? r.rigid : r.spring)?.reactions?.[node];
|
|
935
|
+
if (!six) continue;
|
|
936
|
+
const force = -dot(six.slice(0, 3), fm.down); // (the support pushes up on the frame: the foot carries its opposite)
|
|
937
|
+
if (!best || force > best.force) best = { force, where: `${m[1]}.${m[2]}`, label: r.case.label, rigid };
|
|
938
|
+
}
|
|
939
|
+
return best;
|
|
940
|
+
};
|
|
941
|
+
const spring = most(false),
|
|
942
|
+
rigid = most(true),
|
|
943
|
+
best = rigid && (!spring || rigid.force > 1.01 * spring.force) ? rigid : spring;
|
|
944
|
+
return best && { ...best, cases: results.length };
|
|
346
945
|
}
|