@rulecad/cad 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +24 -10
- package/CHANGELOG.md +404 -0
- package/EXAMPLES.md +40 -38
- package/README.md +193 -67
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2250 -512
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1847 -434
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/design.mjs +649 -121
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +899 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2702 -507
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +100 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +81 -17
- package/lib/framesize.mjs +792 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +123 -21
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +438 -68
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +326 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +579 -130
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +417 -94
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1021 -213
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +3 -1
- package/lib/optimise.mjs +978 -283
- package/lib/order.mjs +519 -112
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +78 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +15 -5
- package/lib/sandbox-hooks.mjs +77 -19
- package/lib/sandbox-run.mjs +117 -18
- package/lib/sandbox.mjs +509 -60
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +851 -178
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +111 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +197 -12
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
package/lib/sheet.mjs
CHANGED
|
@@ -7,22 +7,39 @@ import path from 'node:path';
|
|
|
7
7
|
import zlib from 'node:zlib';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { checkRuleSet } from '@rulecad/variables';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
profileModel,
|
|
12
|
+
slotModel,
|
|
13
|
+
slotPath,
|
|
14
|
+
outline,
|
|
15
|
+
section,
|
|
16
|
+
profileFindings,
|
|
17
|
+
slotNutModel,
|
|
18
|
+
nutFit,
|
|
19
|
+
} from '@rulecad/frames';
|
|
11
20
|
import { RULE_DIRS } from './workspace.mjs';
|
|
21
|
+
import { readJson } from './host.mjs';
|
|
12
22
|
import { schema, validate } from './schema.mjs';
|
|
13
23
|
|
|
14
24
|
const vocabularyFile = fileURLToPath(import.meta.resolve('@rulecad/rules/vocabulary.json'));
|
|
15
|
-
const readSet = (f) =>
|
|
25
|
+
const readSet = (f) => readJson(f); // (a set linked in from outside the workspace is refused: host.mjs)
|
|
16
26
|
export const vocabulary = () => readSet(vocabularyFile);
|
|
17
27
|
|
|
18
28
|
// Every set by name, a workspace's own copy before the published one
|
|
19
29
|
function allSets() {
|
|
20
30
|
const found = new Map();
|
|
21
|
-
for (const d of RULE_DIRS)
|
|
31
|
+
for (const d of RULE_DIRS)
|
|
32
|
+
if (fs.existsSync(d))
|
|
33
|
+
for (const f of fs.readdirSync(d).sort())
|
|
34
|
+
if (f.endsWith('.json') && !['package.json', 'vocabulary.json'].includes(f)) {
|
|
35
|
+
const n = f.slice(0, -5);
|
|
36
|
+
if (!found.has(n)) found.set(n, path.join(d, f));
|
|
37
|
+
}
|
|
22
38
|
return found;
|
|
23
39
|
}
|
|
24
40
|
function fileOf(name) {
|
|
25
|
-
const all = allSets(),
|
|
41
|
+
const all = allSets(),
|
|
42
|
+
file = all.get(name);
|
|
26
43
|
if (!file) throw new Error(`no rule set "${name}" (there are: ${[...all.keys()].join(', ')})`);
|
|
27
44
|
return file;
|
|
28
45
|
}
|
|
@@ -32,24 +49,55 @@ function fileOf(name) {
|
|
|
32
49
|
// set the kit has (cad copies a set into rules/ the first time a design uses it), which is used as it is, even after
|
|
33
50
|
// the kit's set gains figures: it is told which, so a design that wants one knows where it went.
|
|
34
51
|
function notesOf(set, file) {
|
|
35
|
-
const notes = [],
|
|
36
|
-
|
|
52
|
+
const notes = [],
|
|
53
|
+
kitDir = RULE_DIRS.at(-1),
|
|
54
|
+
name = path.basename(file, '.json');
|
|
55
|
+
for (const [shared, own] of Object.entries(set.interface || {}))
|
|
56
|
+
if (set.rules?.[own])
|
|
57
|
+
notes.push({
|
|
58
|
+
level: 'info',
|
|
59
|
+
code: 'rules.alias',
|
|
60
|
+
text: `${own} is also read as ${shared}, the vocabulary's name for it`,
|
|
61
|
+
rule: own,
|
|
62
|
+
values: { alias: shared },
|
|
63
|
+
});
|
|
37
64
|
const kitFile = path.join(kitDir, `${name}.json`);
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
if (
|
|
66
|
+
path.dirname(path.resolve(file)) !== path.resolve(kitDir) &&
|
|
67
|
+
fs.existsSync(kitFile) &&
|
|
68
|
+
set.rules &&
|
|
69
|
+
typeof set.rules === 'object'
|
|
70
|
+
) {
|
|
71
|
+
const kit = readSet(kitFile),
|
|
72
|
+
added = Object.keys(kit.rules || {}).filter((k) => !(k in set.rules));
|
|
73
|
+
if (added.length)
|
|
74
|
+
notes.push({
|
|
75
|
+
level: 'info',
|
|
76
|
+
code: 'rules.new',
|
|
77
|
+
text: `your copy is used as it is; the kit's ${name} now also has ${added.length > 8 ? `${added.slice(0, 8).join(', ')} and ${added.length - 8} more (--json lists them)` : added.join(', ')}: copy any you want into rules/${name}.json, or delete it to read the kit's own`,
|
|
78
|
+
values: { count: added.length },
|
|
79
|
+
refs: { rules: added },
|
|
80
|
+
});
|
|
41
81
|
}
|
|
42
82
|
return notes;
|
|
43
83
|
}
|
|
44
84
|
|
|
45
|
-
|
|
46
85
|
// What a profile's model reads beside its own set: any other set by name (its slot family, a thread, its material),
|
|
47
86
|
// the workspace's first, and a measured outline in outlines/<name>.json beside the set, held to its schema
|
|
48
87
|
function given(name, file, all = allSets()) {
|
|
49
|
-
const load = (n) => (all.has(n) ? readSet(all.get(n)) : undefined),
|
|
88
|
+
const load = (n) => (all.has(n) ? readSet(all.get(n)) : undefined),
|
|
89
|
+
at = path.join(path.dirname(file), 'outlines', `${name}.json`),
|
|
90
|
+
problems = [];
|
|
50
91
|
let measured;
|
|
51
92
|
if (fs.existsSync(at)) {
|
|
52
|
-
try {
|
|
93
|
+
try {
|
|
94
|
+
measured = readSet(at);
|
|
95
|
+
problems.push(
|
|
96
|
+
...validate(measured, schema('outline')).map((x) => `outlines/${name}.json: ${x.path}: ${x.message}`),
|
|
97
|
+
);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
problems.push(`outlines/${name}.json isn't JSON: ${e.message}`);
|
|
100
|
+
}
|
|
53
101
|
if (problems.length) measured = undefined;
|
|
54
102
|
}
|
|
55
103
|
return { load, ...(measured ? { outline: measured } : {}), problems };
|
|
@@ -58,18 +106,40 @@ const own = (e) => e.message.replace(/^\w+: /, ''); // a refusal without the fun
|
|
|
58
106
|
|
|
59
107
|
// A profile, a slot or a slot nut held to sense as well as to the vocabulary: what @rulecad/frames finds in its model
|
|
60
108
|
function partFindings(set, name, file, all) {
|
|
61
|
-
const out = [],
|
|
109
|
+
const out = [],
|
|
110
|
+
say = (level, code, text, extra = {}) => out.push({ level, code, text, ...extra }),
|
|
111
|
+
g = given(name, file, all);
|
|
62
112
|
for (const p of g.problems) say('fail', 'outline.schema', p);
|
|
63
113
|
try {
|
|
64
114
|
if (set.part === 'profile') out.push(...profileFindings(profileModel(set, {}, g)));
|
|
65
115
|
if (set.part === 'slot') slotModel(set, {}, g);
|
|
66
116
|
if (set.part === 'slot_nut') {
|
|
67
|
-
const r = (k) => set.rules[k]?.value,
|
|
68
|
-
|
|
117
|
+
const r = (k) => set.rules[k]?.value,
|
|
118
|
+
slot = g.load(String(r('slot')));
|
|
119
|
+
if (slot?.part !== 'slot')
|
|
120
|
+
say(
|
|
121
|
+
'warn',
|
|
122
|
+
'slot_nut.slot',
|
|
123
|
+
`slot names the slot family it is made for, and there is no slot set "${r('slot')}": its fit is not checked`,
|
|
124
|
+
{ rule: 'slot' },
|
|
125
|
+
);
|
|
69
126
|
else out.push(...nutFit(slotNutModel(set, {}, g), slotModel(slot, {}, g), g));
|
|
70
|
-
if (
|
|
127
|
+
if (
|
|
128
|
+
![...all.values()].some((f) => {
|
|
129
|
+
const t = readSet(f);
|
|
130
|
+
return t.part === 'thread' && (t.name === r('thread') || t.rules.thread?.value === r('thread'));
|
|
131
|
+
})
|
|
132
|
+
)
|
|
133
|
+
say(
|
|
134
|
+
'warn',
|
|
135
|
+
'slot_nut.thread',
|
|
136
|
+
`thread ${JSON.stringify(r('thread'))} is no thread set here (M5, or a set's name)`,
|
|
137
|
+
{ rule: 'thread' },
|
|
138
|
+
);
|
|
71
139
|
}
|
|
72
|
-
} catch (e) {
|
|
140
|
+
} catch (e) {
|
|
141
|
+
say('fail', `${set.part}.model`, own(e));
|
|
142
|
+
}
|
|
73
143
|
return out;
|
|
74
144
|
}
|
|
75
145
|
|
|
@@ -77,21 +147,37 @@ function partFindings(set, name, file, all) {
|
|
|
77
147
|
// (its rule is the field's own sentence, which stays), and cad rules draft from a PDF writes each figure's rule
|
|
78
148
|
// "DRAFT: name and check me" while its kind is estimate. A set that still has one checks and draws as it stands, so it
|
|
79
149
|
// is said by name until each is filled (a source of its own, or a rule of its own and kind spec) or deleted
|
|
80
|
-
const isDraft = (r) =>
|
|
150
|
+
const isDraft = (r) =>
|
|
151
|
+
/^DRAFT\b/.test(String(r.source ?? '')) || (/^DRAFT\b/.test(String(r.rule ?? '')) && r.kind === 'estimate');
|
|
81
152
|
function draftLeft(set) {
|
|
82
|
-
const left = Object.entries(set.rules && typeof set.rules === 'object' ? set.rules : {})
|
|
153
|
+
const left = Object.entries(set.rules && typeof set.rules === 'object' ? set.rules : {})
|
|
154
|
+
.filter(([, r]) => r && typeof r === 'object' && isDraft(r))
|
|
155
|
+
.map(([k]) => k);
|
|
83
156
|
if (!left.length) return [];
|
|
84
|
-
const n = Object.keys(set.rules).length,
|
|
85
|
-
|
|
157
|
+
const n = Object.keys(set.rules).length,
|
|
158
|
+
named = left.length > 8 ? `${left.slice(0, 8).join(', ')} and ${left.length - 8} more` : left.join(', ');
|
|
159
|
+
return [
|
|
160
|
+
{
|
|
161
|
+
level: 'warn',
|
|
162
|
+
code: 'rules.draft',
|
|
163
|
+
text: `${left.length} of its ${n} figures are still the draft's, not read from a sheet: ${named}. Fill each from the maker's sheet (its value, the sheet and page as its source, the date) or delete it`,
|
|
164
|
+
values: { count: left.length, total: n },
|
|
165
|
+
refs: { rules: left },
|
|
166
|
+
},
|
|
167
|
+
];
|
|
86
168
|
}
|
|
87
169
|
|
|
88
170
|
/** Every named set checked (or all of them): [{ name, file, findings, notes? }]. A finding's level is fail, warn or info;
|
|
89
171
|
* notes: what is said and never fails */
|
|
90
172
|
export function checkSets(names = []) {
|
|
91
|
-
const v = vocabulary(),
|
|
173
|
+
const v = vocabulary(),
|
|
174
|
+
all = allSets();
|
|
92
175
|
return (names.length ? names.map((n) => [n, fileOf(n)]) : [...all]).map(([name, file]) => {
|
|
93
|
-
const set = readSet(file),
|
|
94
|
-
|
|
176
|
+
const set = readSet(file),
|
|
177
|
+
findings = checkRuleSet(set, v),
|
|
178
|
+
notes = notesOf(set, file);
|
|
179
|
+
if (!findings.length && ['profile', 'slot', 'slot_nut'].includes(set.part))
|
|
180
|
+
findings.push(...partFindings(set, name, file, all));
|
|
95
181
|
findings.push(...draftLeft(set));
|
|
96
182
|
return { name, file, findings, ...(notes.length ? { notes } : {}) };
|
|
97
183
|
});
|
|
@@ -99,23 +185,49 @@ export function checkSets(names = []) {
|
|
|
99
185
|
|
|
100
186
|
// ---------- a dimension drawing ----------
|
|
101
187
|
const fig = (x) => String(+Number(x).toFixed(2));
|
|
102
|
-
const INK = '#1a1a1a',
|
|
188
|
+
const INK = '#1a1a1a',
|
|
189
|
+
THIN = '#666',
|
|
190
|
+
FILL = '#eceae4',
|
|
191
|
+
METAL = '#c4c8cc';
|
|
103
192
|
|
|
104
193
|
/** @param {string} name the rule set's name @returns {string} an SVG drawing of what it says the part mounts by */
|
|
105
|
-
export function drawSet(name) {
|
|
194
|
+
export function drawSet(name) {
|
|
195
|
+
const file = fileOf(name);
|
|
196
|
+
return drawing(readSet(file), vocabulary(), given(name, file));
|
|
197
|
+
}
|
|
106
198
|
|
|
107
199
|
// The drawing's marks, in sheet units: each adds to out, and span is a dimension with its extension lines, ticks and figure
|
|
108
200
|
function pen() {
|
|
109
201
|
const out = [];
|
|
110
|
-
const line = (a, b, c, e, s = INK, sw = 1.2, dash = '') =>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
202
|
+
const line = (a, b, c, e, s = INK, sw = 1.2, dash = '') =>
|
|
203
|
+
out.push(
|
|
204
|
+
`<line x1="${fig(a)}" y1="${fig(b)}" x2="${fig(c)}" y2="${fig(e)}" stroke="${s}" stroke-width="${sw}"${dash ? ` stroke-dasharray="${dash}"` : ''}/>`,
|
|
205
|
+
);
|
|
206
|
+
const circle = (x, y, r, fill = 'none', s = INK) =>
|
|
207
|
+
out.push(`<circle cx="${fig(x)}" cy="${fig(y)}" r="${fig(r)}" fill="${fill}" stroke="${s}" stroke-width="1.2"/>`);
|
|
208
|
+
const rect = (x, y, a, b, fill = FILL) =>
|
|
209
|
+
out.push(
|
|
210
|
+
`<rect x="${fig(x)}" y="${fig(y)}" width="${fig(a)}" height="${fig(b)}" fill="${fill}" stroke="${INK}" stroke-width="1.2"/>`,
|
|
211
|
+
);
|
|
212
|
+
const text = (x, y, t, a = 'middle', z = 12) =>
|
|
213
|
+
out.push(
|
|
214
|
+
`<text x="${fig(x)}" y="${fig(y)}" text-anchor="${a}" font-size="${z}" font-family="system-ui, sans-serif" fill="${INK}">${t}</text>`,
|
|
215
|
+
);
|
|
216
|
+
const span = (x1, y1, x2, y2, t, across_ = 14) => {
|
|
217
|
+
// a dimension: extension lines, a line with its ticks, the figure
|
|
218
|
+
const horizontal = Math.abs(y2 - y1) < 1e-6,
|
|
219
|
+
ox = horizontal ? 0 : across_,
|
|
220
|
+
oy = horizontal ? across_ : 0;
|
|
221
|
+
line(x1, y1, x1 + ox, y1 + oy, THIN, 0.6);
|
|
222
|
+
line(x2, y2, x2 + ox, y2 + oy, THIN, 0.6);
|
|
223
|
+
line(x1 + ox, y1 + oy, x2 + ox, y2 + oy, THIN, 0.8);
|
|
224
|
+
for (const [a, b] of [
|
|
225
|
+
[x1 + ox, y1 + oy],
|
|
226
|
+
[x2 + ox, y2 + oy],
|
|
227
|
+
])
|
|
228
|
+
line(a - 3, b + 3, a + 3, b - 3, THIN, 0.8);
|
|
229
|
+
if (horizontal) text((x1 + x2) / 2, y1 + oy + (across_ > 0 ? 13 : -4), t);
|
|
230
|
+
else text(x1 + ox + (across_ > 0 ? 4 : -4), (y1 + y2) / 2 + 4, t, across_ > 0 ? 'start' : 'end');
|
|
119
231
|
};
|
|
120
232
|
return { out, line, circle, rect, text, span };
|
|
121
233
|
}
|
|
@@ -124,23 +236,47 @@ function pen() {
|
|
|
124
236
|
function sheet(set, { out, text }, W, H) {
|
|
125
237
|
const kinds = Object.values(set.rules).reduce((m, r) => ({ ...m, [r.kind]: (m[r.kind] || 0) + 1 }), {});
|
|
126
238
|
text(20, 26, set.name, 'start', 16);
|
|
127
|
-
text(
|
|
239
|
+
text(
|
|
240
|
+
20,
|
|
241
|
+
44,
|
|
242
|
+
`all in mm. ${Object.entries(kinds)
|
|
243
|
+
.map(([k, c]) => `${c} ${k}`)
|
|
244
|
+
.join(', ')}: compare it with the datasheet`,
|
|
245
|
+
'start',
|
|
246
|
+
11,
|
|
247
|
+
);
|
|
128
248
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${fig(W)} ${fig(H + 60)}" width="${fig(W)}" height="${fig(H + 60)}"><rect width="100%" height="100%" fill="#fff"/>${out.join('')}</svg>\n`;
|
|
129
249
|
}
|
|
130
250
|
|
|
131
251
|
// A bearing from its end and in section: bore, outer diameter, width, and the flange or the thrust washers where it has them
|
|
132
252
|
function bearingDrawing(set) {
|
|
133
|
-
const n = (k) => set.rules[k]?.value ?? 0,
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
253
|
+
const n = (k) => set.rules[k]?.value ?? 0,
|
|
254
|
+
thrust = set.rules.type?.value === 'thrust';
|
|
255
|
+
const d = n('bore'),
|
|
256
|
+
D = n('outer_diameter'),
|
|
257
|
+
B = n('width'),
|
|
258
|
+
F = n('flange_diameter'),
|
|
259
|
+
Fw = n('flange_width'),
|
|
260
|
+
d1 = n('shaft_washer_diameter'),
|
|
261
|
+
D1 = n('housing_washer_bore');
|
|
262
|
+
const R = Math.max(D, F) / 2,
|
|
263
|
+
S = Math.max(4, Math.min(20, 90 / R)),
|
|
264
|
+
W = 2 * R * S + B * S + 330,
|
|
265
|
+
H = 2 * R * S + 170;
|
|
266
|
+
const cx = R * S + 70,
|
|
267
|
+
cy = H / 2 + 22,
|
|
268
|
+
sx = cx + R * S + 120,
|
|
269
|
+
top = cy - R * S,
|
|
270
|
+
bottom = cy + R * S;
|
|
271
|
+
const pens = pen(),
|
|
272
|
+
{ line, circle, rect, text, span } = pens;
|
|
138
273
|
// ---- from the end ----
|
|
139
274
|
if (F) circle(cx, cy, (F / 2) * S, '#f6f4ee');
|
|
140
275
|
circle(cx, cy, (D / 2) * S, FILL);
|
|
141
276
|
if (D1) circle(cx, cy, (D1 / 2) * S, 'none', THIN);
|
|
142
277
|
circle(cx, cy, (d / 2) * S, '#fff');
|
|
143
|
-
line(cx - R * S - 8, cy, cx + R * S + 8, cy, THIN, 0.5, '8 3 2 3');
|
|
278
|
+
line(cx - R * S - 8, cy, cx + R * S + 8, cy, THIN, 0.5, '8 3 2 3');
|
|
279
|
+
line(cx, cy - R * S - 8, cx, cy + R * S + 8, THIN, 0.5, '8 3 2 3');
|
|
144
280
|
span(cx - (D / 2) * S, bottom + 6, cx + (D / 2) * S, bottom + 6, `Ø${fig(D)}`, 18);
|
|
145
281
|
span(cx - (d / 2) * S, top - 6, cx + (d / 2) * S, top - 6, `bore Ø${fig(d)}`, -14);
|
|
146
282
|
if (F) text(cx, bottom + 66, `flange Ø${fig(F)}, ${fig(Fw)} thick`);
|
|
@@ -148,23 +284,45 @@ function bearingDrawing(set) {
|
|
|
148
284
|
// ---- the section, axis along the sheet ----
|
|
149
285
|
for (const side of [-1, 1]) {
|
|
150
286
|
const y = (a, b) => (side < 0 ? [cy - b * S, (b - a) * S] : [cy + a * S, (b - a) * S]);
|
|
151
|
-
const [ry, rh] = y(d / 2, D / 2);
|
|
152
|
-
|
|
287
|
+
const [ry, rh] = y(d / 2, D / 2);
|
|
288
|
+
rect(sx, ry, B * S, rh);
|
|
289
|
+
if (F) {
|
|
290
|
+
const [fy, fh] = y(D / 2, F / 2);
|
|
291
|
+
rect(sx, fy, Fw * S, fh, '#ddd9cf');
|
|
292
|
+
}
|
|
153
293
|
if (thrust) line(sx + (B * S) / 2, ry, sx + (B * S) / 2, ry + rh, THIN, 0.8, '4 3');
|
|
154
294
|
}
|
|
155
295
|
line(sx - 12, cy, sx + B * S + 12, cy, THIN, 0.5, '8 3 2 3');
|
|
156
296
|
span(sx, bottom + 6, sx + B * S, bottom + 6, `${fig(B)}`, 18);
|
|
157
297
|
span(sx + B * S + 6, cy - (D / 2) * S, sx + B * S + 6, cy + (D / 2) * S, `Ø${fig(D)}`, 30);
|
|
158
298
|
text(sx + (B * S) / 2, top - 22, `chamfer ${fig(n('chamfer'))}`, 'middle', 11);
|
|
159
|
-
text(
|
|
299
|
+
text(
|
|
300
|
+
cx,
|
|
301
|
+
bottom + 86,
|
|
302
|
+
`${set.rules.type?.value || 'bearing'}: ${fig(n('dynamic_rating'))} N dynamic, ${fig(n('static_rating'))} N static${set.rules.radial_play ? `, ${set.rules.radial_play.value}` : ''}`,
|
|
303
|
+
'middle',
|
|
304
|
+
11,
|
|
305
|
+
);
|
|
160
306
|
return sheet(set, pens, W, H);
|
|
161
307
|
}
|
|
162
308
|
|
|
163
309
|
// A driver module from above: the board and its two header rows, at their spacing
|
|
164
310
|
function driverDrawing(set) {
|
|
165
|
-
const n = (k) => set.rules[k]?.value ?? 0,
|
|
166
|
-
|
|
167
|
-
|
|
311
|
+
const n = (k) => set.rules[k]?.value ?? 0,
|
|
312
|
+
w = n('body_width'),
|
|
313
|
+
d = n('body_depth'),
|
|
314
|
+
pitch = n('pin_pitch'),
|
|
315
|
+
row = n('row_spacing'),
|
|
316
|
+
count = n('pin_count') / 2;
|
|
317
|
+
const S = 16,
|
|
318
|
+
W = w * S + 260,
|
|
319
|
+
H = d * S + 170,
|
|
320
|
+
cx = W / 2,
|
|
321
|
+
cy = H / 2 + 22,
|
|
322
|
+
X = (x) => cx + x * S,
|
|
323
|
+
Y = (y) => cy - y * S;
|
|
324
|
+
const pens = pen(),
|
|
325
|
+
{ line, circle, rect, text, span } = pens;
|
|
168
326
|
rect(X(-w / 2), Y(d / 2), w * S, d * S);
|
|
169
327
|
const pins = Array.from({ length: count }, (_, i) => (i - (count - 1) / 2) * pitch);
|
|
170
328
|
for (const y of [-row / 2, row / 2]) for (const x of pins) circle(X(x), Y(y), (pitch / 3.2) * S, METAL);
|
|
@@ -180,22 +338,45 @@ function driverDrawing(set) {
|
|
|
180
338
|
|
|
181
339
|
// A round part from its end and along its axis: linear bearings, nuts, couplers, pulleys, idlers, rods. Each says what it has: flange, hole circle, a dashed pitch circle, the bores of a coupler
|
|
182
340
|
function roundDrawing(set, { D, d = 0, L, bores, flange, circle: holeCircle, pitchD, notes = [] }) {
|
|
183
|
-
const R = Math.max(D, flange?.D ?? 0) / 2,
|
|
184
|
-
|
|
185
|
-
|
|
341
|
+
const R = Math.max(D, flange?.D ?? 0) / 2,
|
|
342
|
+
S = Math.max(3, Math.min(14, 90 / R)),
|
|
343
|
+
W = 2 * R * S + L * S + 340,
|
|
344
|
+
H = 2 * R * S + 190;
|
|
345
|
+
const cx = R * S + 70,
|
|
346
|
+
cy = H / 2 + 22,
|
|
347
|
+
sx = cx + R * S + 120,
|
|
348
|
+
top = cy - R * S,
|
|
349
|
+
bottom = cy + R * S;
|
|
350
|
+
const pens = pen(),
|
|
351
|
+
{ line, circle, rect, text, span } = pens;
|
|
186
352
|
// ---- from the end ----
|
|
187
353
|
if (flange) circle(cx, cy, (flange.D / 2) * S, '#f6f4ee');
|
|
188
354
|
circle(cx, cy, (D / 2) * S, FILL);
|
|
189
355
|
if (pitchD) circle(cx, cy, (pitchD / 2) * S, 'none', THIN);
|
|
190
356
|
if (d) circle(cx, cy, (d / 2) * S, '#fff');
|
|
191
|
-
if (holeCircle)
|
|
192
|
-
|
|
357
|
+
if (holeCircle)
|
|
358
|
+
for (let i = 0; i < holeCircle.count; i++) {
|
|
359
|
+
const a = (2 * Math.PI * i) / holeCircle.count;
|
|
360
|
+
circle(
|
|
361
|
+
cx + (holeCircle.D / 2) * Math.cos(a) * S,
|
|
362
|
+
cy + (holeCircle.D / 2) * Math.sin(a) * S,
|
|
363
|
+
(holeCircle.hole / 2) * S,
|
|
364
|
+
'#fff',
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
line(cx - R * S - 8, cy, cx + R * S + 8, cy, THIN, 0.5, '8 3 2 3');
|
|
368
|
+
line(cx, cy - R * S - 8, cx, cy + R * S + 8, THIN, 0.5, '8 3 2 3');
|
|
193
369
|
span(cx - R * S, bottom + 6, cx + R * S, bottom + 6, `Ø${fig(flange?.D ?? D)}`, 18);
|
|
194
370
|
if (d) span(cx - (d / 2) * S, top - 6, cx + (d / 2) * S, top - 6, `bore Ø${fig(d)}`, -14);
|
|
195
371
|
// ---- along the axis ----
|
|
196
|
-
const ring = (x, len, a, b, fill = FILL) => {
|
|
197
|
-
|
|
198
|
-
|
|
372
|
+
const ring = (x, len, a, b, fill = FILL) => {
|
|
373
|
+
for (const side of [-1, 1])
|
|
374
|
+
rect(x, side < 0 ? cy - (b / 2) * S : cy + (a / 2) * S, len * S, ((b - a) / 2) * S, fill);
|
|
375
|
+
};
|
|
376
|
+
if (bores) {
|
|
377
|
+
ring(sx, L / 2, bores[0], D);
|
|
378
|
+
ring(sx + (L / 2) * S, L / 2, bores[1], D);
|
|
379
|
+
} else if (d) ring(sx, L, d, D);
|
|
199
380
|
else rect(sx, cy - (D / 2) * S, L * S, D * S, METAL);
|
|
200
381
|
if (flange) ring(sx + flange.at * S, flange.w, d, flange.D, '#ddd9cf');
|
|
201
382
|
line(sx - 12, cy, sx + L * S + 12, cy, THIN, 0.5, '8 3 2 3');
|
|
@@ -207,34 +388,85 @@ function roundDrawing(set, { D, d = 0, L, bores, flange, circle: holeCircle, pit
|
|
|
207
388
|
|
|
208
389
|
// A lead screw from the side: the crest and root, the starts' flanks, and pitch against lead
|
|
209
390
|
function leadScrewDrawing(set) {
|
|
210
|
-
const n = (k) => set.rules[k]?.value ?? 0,
|
|
211
|
-
|
|
212
|
-
|
|
391
|
+
const n = (k) => set.rules[k]?.value ?? 0,
|
|
392
|
+
D = n('diameter'),
|
|
393
|
+
root = n('root_diameter'),
|
|
394
|
+
P = n('pitch'),
|
|
395
|
+
lead = n('lead'),
|
|
396
|
+
starts = n('starts') || 1;
|
|
397
|
+
const L = Math.max(3 * lead, 20),
|
|
398
|
+
S = Math.min(14, 420 / L),
|
|
399
|
+
W = L * S + 240,
|
|
400
|
+
H = D * S + 200,
|
|
401
|
+
x0 = 110,
|
|
402
|
+
cy = H / 2 + 12;
|
|
403
|
+
const pens = pen(),
|
|
404
|
+
{ line, rect, text, span } = pens;
|
|
213
405
|
rect(x0, cy - (D / 2) * S, L * S, D * S, METAL);
|
|
214
|
-
for (const side of [-1, 1])
|
|
406
|
+
for (const side of [-1, 1])
|
|
407
|
+
line(x0, cy + side * (root / 2) * S, x0 + L * S, cy + side * (root / 2) * S, THIN, 0.6, '4 3');
|
|
215
408
|
const lean = (D * S * Math.tan((n('helix_angle') * Math.PI) / 180)) / 2;
|
|
216
|
-
for (let i = 0; i * P <= L + 1e-9; i++) {
|
|
409
|
+
for (let i = 0; i * P <= L + 1e-9; i++) {
|
|
410
|
+
const x = x0 + i * P * S;
|
|
411
|
+
if (x - lean >= x0 && x + lean <= x0 + L * S)
|
|
412
|
+
line(
|
|
413
|
+
x - lean,
|
|
414
|
+
cy + (D / 2) * S,
|
|
415
|
+
x + lean,
|
|
416
|
+
cy - (D / 2) * S,
|
|
417
|
+
i % starts === 0 ? INK : THIN,
|
|
418
|
+
i % starts === 0 ? 1.6 : 0.7,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
217
421
|
line(x0 - 12, cy, x0 + L * S + 12, cy, THIN, 0.5, '8 3 2 3');
|
|
218
|
-
const below = cy + (D / 2) * S + 6,
|
|
422
|
+
const below = cy + (D / 2) * S + 6,
|
|
423
|
+
above = cy - (D / 2) * S - 6;
|
|
219
424
|
span(x0, below, x0 + P * S, below, `pitch ${fig(P)}`, 18);
|
|
220
425
|
span(x0, below, x0 + lead * S, below, `lead ${fig(lead)}`, 44);
|
|
221
426
|
span(x0 + L * S + 6, cy - (D / 2) * S, x0 + L * S + 6, cy + (D / 2) * S, `Ø${fig(D)}`, 30);
|
|
222
427
|
span(x0 - 6, cy - (root / 2) * S, x0 - 6, cy + (root / 2) * S, `root Ø${fig(root)}`, -18);
|
|
223
|
-
text(
|
|
428
|
+
text(
|
|
429
|
+
x0 + (L * S) / 2,
|
|
430
|
+
above - 8,
|
|
431
|
+
`${set.rules.thread?.value ?? ''}, ${fig(starts)} start${starts > 1 ? 's' : ''}, helix ${fig(n('helix_angle'))}°`,
|
|
432
|
+
'middle',
|
|
433
|
+
12,
|
|
434
|
+
);
|
|
224
435
|
text(x0 + (L * S) / 2, below + 72, 'each dark line one start, repeating at the lead', 'middle', 11);
|
|
225
436
|
return sheet(set, pens, W, H);
|
|
226
437
|
}
|
|
227
438
|
|
|
228
439
|
// A short length of belt, teeth along it
|
|
229
440
|
function beltDrawing(set) {
|
|
230
|
-
const n = (k) => set.rules[k]?.value ?? 0,
|
|
231
|
-
|
|
441
|
+
const n = (k) => set.rules[k]?.value ?? 0,
|
|
442
|
+
P = n('pitch'),
|
|
443
|
+
w = n('width'),
|
|
444
|
+
L = P * 8,
|
|
445
|
+
S = 12,
|
|
446
|
+
W = L * S + 220,
|
|
447
|
+
H = w * S + 190,
|
|
448
|
+
x0 = 90,
|
|
449
|
+
cy = H / 2 + 10;
|
|
450
|
+
const pens = pen(),
|
|
451
|
+
{ line, rect, text, span } = pens;
|
|
232
452
|
rect(x0, cy - (w / 2) * S, L * S, w * S);
|
|
233
453
|
for (let i = 0; i <= 8; i++) line(x0 + i * P * S, cy - (w / 2) * S, x0 + i * P * S, cy + (w / 2) * S, THIN, 0.7);
|
|
234
454
|
span(x0, cy + (w / 2) * S + 6, x0 + P * S, cy + (w / 2) * S + 6, `pitch ${fig(P)}`, 18);
|
|
235
455
|
span(x0 + L * S + 6, cy - (w / 2) * S, x0 + L * S + 6, cy + (w / 2) * S, `${fig(w)}`, 18);
|
|
236
|
-
text(
|
|
237
|
-
|
|
456
|
+
text(
|
|
457
|
+
x0 + (L * S) / 2,
|
|
458
|
+
cy + (w / 2) * S + 66,
|
|
459
|
+
`${fig(n('stiffness'))} N per unit strain, pitch line ${n('pitch_line_offset')} beyond the teeth`,
|
|
460
|
+
'middle',
|
|
461
|
+
11,
|
|
462
|
+
);
|
|
463
|
+
text(
|
|
464
|
+
x0 + (L * S) / 2,
|
|
465
|
+
cy + (w / 2) * S + 84,
|
|
466
|
+
`rated ${fig(n('rated_tension'))} N, breaks at ${fig(n('breaking_strength'))} N`,
|
|
467
|
+
'middle',
|
|
468
|
+
11,
|
|
469
|
+
);
|
|
238
470
|
return sheet(set, pens, W, H);
|
|
239
471
|
}
|
|
240
472
|
|
|
@@ -242,53 +474,177 @@ function beltDrawing(set) {
|
|
|
242
474
|
// every one dimensioned from the set's own figures, to hold against the standard's table. Seats are level across the
|
|
243
475
|
// row: a head stands above the line, a countersunk head sits under it, and a length runs from that line to the tip.
|
|
244
476
|
function threadDrawing(set) {
|
|
245
|
-
const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0),
|
|
246
|
-
|
|
477
|
+
const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0),
|
|
478
|
+
has = (k) => n(k) > 0,
|
|
479
|
+
says = (k) => String(set.rules[k]?.value ?? '');
|
|
480
|
+
const d = n('major_diameter'),
|
|
481
|
+
P = n('pitch'),
|
|
482
|
+
lengths = Array.isArray(set.rules.lengths?.value) ? set.rules.lengths.value : [];
|
|
247
483
|
const L = lengths.find((l) => l >= 2.5 * d) ?? lengths.at(-1) ?? 3 * d; // a length it is sold in, near three diameters
|
|
248
484
|
const heads = [
|
|
249
485
|
has('head') && { name: 'socket cap', form: 'cap', D: n('head'), k: n('head_height'), key: n('head_key') },
|
|
250
|
-
has('button_head') && {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
486
|
+
has('button_head') && {
|
|
487
|
+
name: 'button',
|
|
488
|
+
form: 'button',
|
|
489
|
+
D: n('button_head'),
|
|
490
|
+
k: n('button_head_height'),
|
|
491
|
+
key: n('button_key'),
|
|
492
|
+
},
|
|
493
|
+
has('countersunk_head') && {
|
|
494
|
+
name: `countersunk ${fig(n('countersunk_angle'))}°`,
|
|
495
|
+
form: 'countersunk',
|
|
496
|
+
D: n('countersunk_head'),
|
|
497
|
+
k:
|
|
498
|
+
n('countersunk_head_height') ||
|
|
499
|
+
(n('countersunk_head') - d) / 2 / Math.tan((n('countersunk_angle') * Math.PI) / 360),
|
|
500
|
+
key: n('countersunk_key'),
|
|
501
|
+
},
|
|
502
|
+
has('hex_head_flats') && {
|
|
503
|
+
name: 'hexagon',
|
|
504
|
+
form: 'hex',
|
|
505
|
+
D: n('hex_head_flats'),
|
|
506
|
+
k: n('hex_head_height'),
|
|
507
|
+
note: 'across flats',
|
|
508
|
+
},
|
|
509
|
+
has('pan_head') && {
|
|
510
|
+
name: 'pan',
|
|
511
|
+
form: 'pan',
|
|
512
|
+
D: n('pan_head'),
|
|
513
|
+
k: n('pan_head_height'),
|
|
514
|
+
note: says('pan_head_drive'),
|
|
515
|
+
},
|
|
254
516
|
].filter(Boolean);
|
|
255
517
|
if (!heads.length) heads.push({ name: 'thread', form: 'stud', D: d, k: 0 });
|
|
256
518
|
const nuts = [
|
|
257
519
|
has('nut_flats') && { name: 'hexagon nut', s: n('nut_flats'), m: n('nut_height'), sides: 6 },
|
|
258
520
|
has('square_nut_flats') && { name: 'square nut', s: n('square_nut_flats'), m: n('square_nut_height'), sides: 4 },
|
|
259
|
-
has('lock_nut_height') && {
|
|
260
|
-
|
|
521
|
+
has('lock_nut_height') && {
|
|
522
|
+
name: 'lock nut',
|
|
523
|
+
s: n('lock_nut_flats') || n('nut_flats'),
|
|
524
|
+
m: n('lock_nut_height'),
|
|
525
|
+
sides: 6,
|
|
526
|
+
},
|
|
527
|
+
has('washer_diameter') && {
|
|
528
|
+
name: 'washer',
|
|
529
|
+
s: n('washer_diameter'),
|
|
530
|
+
m: n('washer_thickness'),
|
|
531
|
+
bore: n('washer_bore'),
|
|
532
|
+
},
|
|
261
533
|
].filter(Boolean);
|
|
262
|
-
const holes = [
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
534
|
+
const holes = [
|
|
535
|
+
['tap drill', 'tap_drill'],
|
|
536
|
+
['close', 'clearance_close'],
|
|
537
|
+
['normal', 'clearance'],
|
|
538
|
+
['loose', 'clearance_loose'],
|
|
539
|
+
['pilot in plastic', 'pilot'],
|
|
540
|
+
['insert hole', 'insert_hole'],
|
|
541
|
+
]
|
|
542
|
+
.filter(([, k]) => has(k))
|
|
543
|
+
.map(([name, k]) => ({
|
|
544
|
+
name,
|
|
545
|
+
D: n(k),
|
|
546
|
+
ring:
|
|
547
|
+
k === 'insert_hole'
|
|
548
|
+
? n('insert_diameter')
|
|
549
|
+
: k === 'pilot'
|
|
550
|
+
? n('pilot_boss')
|
|
551
|
+
: k.startsWith('clearance')
|
|
552
|
+
? d
|
|
553
|
+
: 0,
|
|
554
|
+
})); // (dashed round a hole: an insert's knurls, a pilot's boss; grey inside one: the thread passing through)
|
|
555
|
+
const widest = Math.max(
|
|
556
|
+
d,
|
|
557
|
+
...heads.map((h) => h.D),
|
|
558
|
+
...nuts.map((x) => x.s),
|
|
559
|
+
...holes.map((h) => Math.max(h.D, h.ring)),
|
|
560
|
+
),
|
|
561
|
+
S = Math.max(3, Math.min(16, 90 / widest));
|
|
562
|
+
const col = widest * S + 84,
|
|
563
|
+
count = Math.max(heads.length, nuts.length, 3),
|
|
564
|
+
X = (i) => 60 + col * (i + 0.5);
|
|
565
|
+
const big = Math.max(0, ...holes.map((h) => Math.max(h.D, h.ring))) * S,
|
|
566
|
+
holeCol = Math.max(big + 64, Math.min(col, (count * col) / Math.max(holes.length, 1))),
|
|
567
|
+
HX = (i) => 60 + holeCol * (i + 0.5); // (holes are small: their row is spaced closer, so six fit under four screws)
|
|
266
568
|
const W = Math.max(count * col, holes.length * holeCol) + 80;
|
|
267
|
-
const pens = pen(),
|
|
569
|
+
const pens = pen(),
|
|
570
|
+
{ out, line, circle, rect, text, span } = pens,
|
|
571
|
+
poly = (pts, fill = FILL) =>
|
|
572
|
+
out.push(
|
|
573
|
+
`<polygon points="${pts.map(([a, b]) => `${fig(a)},${fig(b)}`).join(' ')}" fill="${fill}" stroke="${INK}" stroke-width="1.2"/>`,
|
|
574
|
+
);
|
|
268
575
|
// ---- the screws, from the side ----
|
|
269
|
-
const maxK = Math.max(...heads.map((h) => (h.form === 'countersunk' ? 0 : h.k))),
|
|
576
|
+
const maxK = Math.max(...heads.map((h) => (h.form === 'countersunk' ? 0 : h.k))),
|
|
577
|
+
yFace = 92 + maxK * S,
|
|
578
|
+
yTip = yFace + L * S,
|
|
579
|
+
root = (has('root_diameter') ? (d - n('root_diameter')) / 2 : 0.6134 * P) * S; // (its root where the set gives one; else an external thread is 0.6134 of its pitch deep: ISO 68-1)
|
|
270
580
|
heads.forEach((h, i) => {
|
|
271
|
-
const cx = X(i),
|
|
581
|
+
const cx = X(i),
|
|
582
|
+
r = (h.D / 2) * S,
|
|
583
|
+
kS = h.k * S,
|
|
584
|
+
sunk = h.form === 'countersunk',
|
|
585
|
+
top = sunk ? yFace : yFace - kS,
|
|
586
|
+
under = sunk ? yFace + kS : yFace;
|
|
272
587
|
rect(cx - (d / 2) * S, under, d * S, yTip - under, METAL);
|
|
273
|
-
for (const side of [-1, 1])
|
|
588
|
+
for (const side of [-1, 1])
|
|
589
|
+
line(cx + side * ((d / 2) * S - root), under + 2, cx + side * ((d / 2) * S - root), yTip, THIN, 0.6, '4 3');
|
|
274
590
|
if (h.form === 'cap' || h.form === 'hex') rect(cx - r, top, 2 * r, kS, METAL);
|
|
275
|
-
if (h.form === 'pan')
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
591
|
+
if (h.form === 'pan')
|
|
592
|
+
out.push(
|
|
593
|
+
`<rect x="${fig(cx - r)}" y="${fig(top)}" width="${fig(2 * r)}" height="${fig(kS)}" rx="${fig(Math.min(kS, r) * 0.45)}" fill="${METAL}" stroke="${INK}" stroke-width="1.2"/>`,
|
|
594
|
+
);
|
|
595
|
+
if (h.form === 'button') {
|
|
596
|
+
const R = (r * r + kS * kS) / (2 * kS);
|
|
597
|
+
out.push(
|
|
598
|
+
`<path d="M ${fig(cx - r)} ${fig(yFace)} A ${fig(R)} ${fig(R)} 0 0 1 ${fig(cx + r)} ${fig(yFace)} Z" fill="${METAL}" stroke="${INK}" stroke-width="1.2"/>`,
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
if (sunk)
|
|
602
|
+
poly(
|
|
603
|
+
[
|
|
604
|
+
[cx - r, top],
|
|
605
|
+
[cx + r, top],
|
|
606
|
+
[cx + (d / 2) * S, under],
|
|
607
|
+
[cx - (d / 2) * S, under],
|
|
608
|
+
],
|
|
609
|
+
METAL,
|
|
610
|
+
);
|
|
611
|
+
if (h.key) {
|
|
612
|
+
const kw = (h.key / 2) * S,
|
|
613
|
+
deep = Math.min(kS * 0.6, h.key * S);
|
|
614
|
+
for (const side of [-1, 1]) line(cx + side * kw, top, cx + side * kw, top + deep, THIN, 0.7, '3 2');
|
|
615
|
+
line(cx - kw, top + deep, cx + kw, top + deep, THIN, 0.7, '3 2');
|
|
616
|
+
}
|
|
279
617
|
if (h.form !== 'stud') span(cx - r, top - 6, cx + r, top - 6, `${h.form === 'hex' ? '' : 'Ø'}${fig(h.D)}`, -14);
|
|
280
618
|
if (h.k) span(cx + r + 6, top, cx + r + 6, top + kS, fig(h.k), 12);
|
|
281
|
-
if (i === 0) {
|
|
619
|
+
if (i === 0) {
|
|
620
|
+
span(cx - (d / 2) * S, yTip + 6, cx + (d / 2) * S, yTip + 6, `Ø${fig(d)}`, 14);
|
|
621
|
+
span(cx - Math.max(r, (d / 2) * S) - 6, yFace, cx - Math.max(r, (d / 2) * S) - 6, yTip, fig(L), -14);
|
|
622
|
+
}
|
|
282
623
|
text(cx, yTip + 58, h.name);
|
|
283
624
|
const under2 = [h.key ? `key ${fig(h.key)}` : '', h.note || ''].filter(Boolean).join(', ');
|
|
284
625
|
if (under2) text(cx, yTip + 74, under2, 'middle', 11);
|
|
285
626
|
});
|
|
286
627
|
line(40, yFace, W - 40, yFace, THIN, 0.5, '8 3 2 3');
|
|
287
628
|
// ---- nuts and the washer: from above, then from the side ----
|
|
288
|
-
const tall = Math.max(0, ...nuts.map((x) => (x.sides === 6 ? x.s * 2 / Math.sqrt(3) : x.s))) * S,
|
|
629
|
+
const tall = Math.max(0, ...nuts.map((x) => (x.sides === 6 ? (x.s * 2) / Math.sqrt(3) : x.s))) * S,
|
|
630
|
+
yPlan = yTip + 104 + tall / 2,
|
|
631
|
+
ySide = yPlan + tall / 2 + 48,
|
|
632
|
+
maxM = Math.max(0, ...nuts.map((x) => x.m)) * S;
|
|
289
633
|
nuts.forEach((x, i) => {
|
|
290
|
-
const cx = X(i),
|
|
291
|
-
|
|
634
|
+
const cx = X(i),
|
|
635
|
+
r = (x.s / 2) * S,
|
|
636
|
+
across = x.sides === 6 ? (x.s * S) / Math.sqrt(3) : r;
|
|
637
|
+
if (x.sides === 6)
|
|
638
|
+
poly(
|
|
639
|
+
[
|
|
640
|
+
[r, across / 2],
|
|
641
|
+
[0, across],
|
|
642
|
+
[-r, across / 2],
|
|
643
|
+
[-r, -across / 2],
|
|
644
|
+
[0, -across],
|
|
645
|
+
[r, -across / 2],
|
|
646
|
+
].map(([a, b]) => [cx + a, yPlan + b]),
|
|
647
|
+
);
|
|
292
648
|
else if (x.sides === 4) rect(cx - r, yPlan - r, 2 * r, 2 * r);
|
|
293
649
|
else circle(cx, yPlan, r, FILL);
|
|
294
650
|
circle(cx, yPlan, ((x.bore || d) / 2) * S, '#fff');
|
|
@@ -304,9 +660,15 @@ function threadDrawing(set) {
|
|
|
304
660
|
const yHole = (nuts.length ? ySide + maxM + 62 : yTip + 104) + big / 2;
|
|
305
661
|
holes.forEach((h, i) => {
|
|
306
662
|
const cx = HX(i);
|
|
307
|
-
if (h.ring > h.D)
|
|
663
|
+
if (h.ring > h.D)
|
|
664
|
+
out.push(
|
|
665
|
+
`<circle cx="${fig(cx)}" cy="${fig(yHole)}" r="${fig((h.ring / 2) * S)}" fill="none" stroke="${THIN}" stroke-width="0.8" stroke-dasharray="4 3"/>`,
|
|
666
|
+
);
|
|
308
667
|
circle(cx, yHole, (h.D / 2) * S, '#fff');
|
|
309
|
-
if (h.ring && h.ring < h.D)
|
|
668
|
+
if (h.ring && h.ring < h.D)
|
|
669
|
+
out.push(
|
|
670
|
+
`<circle cx="${fig(cx)}" cy="${fig(yHole)}" r="${fig((h.ring / 2) * S)}" fill="${METAL}" stroke="${THIN}" stroke-width="0.8"/>`,
|
|
671
|
+
);
|
|
310
672
|
span(cx - (h.D / 2) * S, yHole + big / 2 + 4, cx + (h.D / 2) * S, yHole + big / 2 + 4, `Ø${fig(h.D)}`, 14);
|
|
311
673
|
text(cx, yHole + big / 2 + 50, h.name);
|
|
312
674
|
});
|
|
@@ -314,67 +676,155 @@ function threadDrawing(set) {
|
|
|
314
676
|
const notes = [
|
|
315
677
|
`${says('thread')}, ${says('thread_form')}: pitch ${fig(P)}${has('pitch_fine') ? `, fine ${fig(n('pitch_fine'))}` : ''}${has('set_screw_key') ? `, set screw key ${fig(n('set_screw_key'))}` : ''}${says('thread_form') === 'unified' ? ' (divide by 25.4 for the inch table)' : ''}`,
|
|
316
678
|
lengths.length ? `socket cap lengths: ${lengths.map(fig).join(', ')}` : '',
|
|
317
|
-
has('proof_stress')
|
|
318
|
-
|
|
319
|
-
|
|
679
|
+
has('proof_stress')
|
|
680
|
+
? `${has('property_class') ? `class ${fig(n('property_class'))}: ` : ''}proof stress ${fig(n('proof_stress'))} MPa${has('stainless_proof_stress') ? `; ${says('stainless_class')}: ${fig(n('stainless_proof_stress'))} MPa` : ''}`
|
|
681
|
+
: '',
|
|
682
|
+
has('insert_hole')
|
|
683
|
+
? `insert${has('insert_diameter') ? ` Ø${fig(n('insert_diameter'))}` : ''}${has('insert_length') ? ` × ${fig(n('insert_length'))} long` : ''} (dashed) in a Ø${fig(n('insert_hole'))} hole${has('insert_taper') ? `, tapered ${fig(n('insert_taper'))}°` : ''}${has('insert_wall') ? `, ${fig(n('insert_wall'))} of wall round it at least` : ''}`
|
|
684
|
+
: '',
|
|
685
|
+
has('pilot')
|
|
686
|
+
? `pilot Ø${fig(n('pilot'))}${has('pilot_depth') ? `, ${fig(n('pilot_depth'))} deep at least` : ''}${has('pilot_boss') ? `, in a boss of Ø${fig(n('pilot_boss'))} at least (dashed)` : ''}: a starting figure, your printer's measured one comes first`
|
|
687
|
+
: '',
|
|
320
688
|
].filter(Boolean);
|
|
321
|
-
const yNotes =
|
|
689
|
+
const yNotes = holes.length ? yHole + big / 2 + 80 : nuts.length ? ySide + maxM + 66 : yTip + 104;
|
|
322
690
|
notes.forEach((t, i) => text(40, yNotes + i * 17, t, 'start', 11));
|
|
323
691
|
return sheet(set, pens, Math.max(W, 620), yNotes + notes.length * 17 - 50);
|
|
324
692
|
}
|
|
325
693
|
|
|
326
694
|
// ---------- profiles, slots and slot nuts ----------
|
|
327
|
-
const pathOf = (loops, X, Y) =>
|
|
695
|
+
const pathOf = (loops, X, Y) =>
|
|
696
|
+
loops.map((l) => `M ${l.map(([x, y]) => `${fig(X(x))} ${fig(Y(y))}`).join(' L ')} Z`).join(' ');
|
|
328
697
|
const sig = (x, n = 4) => String(+Number(x).toPrecision(n));
|
|
329
698
|
|
|
330
699
|
// A profile's section to scale, with what a sheet's drawing dimensions (size, slot, bore, corner), and under it the
|
|
331
700
|
// sheet's section figures beside what the drawn outline comes to
|
|
332
701
|
function profileDrawing(set, g) {
|
|
333
|
-
const m = profileModel(set, {}, g),
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
702
|
+
const m = profileModel(set, {}, g),
|
|
703
|
+
o = outline(m),
|
|
704
|
+
s = section(m),
|
|
705
|
+
W = m.width,
|
|
706
|
+
H = m.height;
|
|
707
|
+
const S = Math.min(18, 380 / Math.max(W, H)),
|
|
708
|
+
sheetW = Math.max(W * S + 330, 640),
|
|
709
|
+
cx = 130 + (W * S) / 2,
|
|
710
|
+
cy = 110 + (H * S) / 2,
|
|
711
|
+
X = (x) => cx + x * S,
|
|
712
|
+
Y = (y) => cy - y * S;
|
|
713
|
+
const pens = pen(),
|
|
714
|
+
{ out, line, text, span } = pens;
|
|
715
|
+
out.push(
|
|
716
|
+
`<path d="${pathOf(o.loops, X, Y)}" fill="${METAL}" fill-rule="evenodd" stroke="${INK}" stroke-width="1.2" stroke-linejoin="round"/>`,
|
|
717
|
+
);
|
|
718
|
+
line(X(-W / 2) - 10, Y(0), X(W / 2) + 10, Y(0), THIN, 0.5, '8 3 2 3');
|
|
719
|
+
line(X(0), Y(H / 2) - 10, X(0), Y(-H / 2) + 10, THIN, 0.5, '8 3 2 3');
|
|
338
720
|
span(X(-W / 2), Y(-H / 2) + 6, X(W / 2), Y(-H / 2) + 6, fig(W), 22);
|
|
339
721
|
span(X(-W / 2) - 6, Y(H / 2), X(-W / 2) - 6, Y(-H / 2), fig(H), -22);
|
|
340
722
|
// the slot nearest the top right: its opening and cavity above, its lip and depth at the side
|
|
341
|
-
const face = ['top', 'back', 'bottom', 'front'].find((f) => m.faces[f].some((p) => p.slot)),
|
|
723
|
+
const face = ['top', 'back', 'bottom', 'front'].find((f) => m.faces[f].some((p) => p.slot)),
|
|
724
|
+
notes = [];
|
|
342
725
|
if (face && !o.measured) {
|
|
343
|
-
const p = m.faces[face].filter((q) => q.slot).at(-1),
|
|
726
|
+
const p = m.faces[face].filter((q) => q.slot).at(-1),
|
|
727
|
+
sl = m.slots[p.slot],
|
|
728
|
+
top = face === 'top' || face === 'bottom',
|
|
729
|
+
sign = face === 'top' || face === 'back' ? 1 : -1;
|
|
344
730
|
if (top) {
|
|
345
|
-
const y0 = Y(p.at[1]) - sign * 6,
|
|
731
|
+
const y0 = Y(p.at[1]) - sign * 6,
|
|
732
|
+
d = -sign * 14;
|
|
346
733
|
span(X(p.at[0] - sl.mouth / 2), y0, X(p.at[0] + sl.mouth / 2), y0, fig(sl.mouth), d);
|
|
347
|
-
span(
|
|
734
|
+
span(
|
|
735
|
+
X(p.at[0] - sl.cavityWidth / 2),
|
|
736
|
+
y0 - sign * 24,
|
|
737
|
+
X(p.at[0] + sl.cavityWidth / 2),
|
|
738
|
+
y0 - sign * 24,
|
|
739
|
+
fig(sl.cavityWidth),
|
|
740
|
+
d,
|
|
741
|
+
);
|
|
348
742
|
const x0 = X(W / 2) + 6;
|
|
349
743
|
span(x0, Y(p.at[1]), x0, Y(p.at[1] - sign * sl.lip), fig(sl.lip), 16);
|
|
350
744
|
span(x0 + 44, Y(p.at[1]), x0 + 44, Y(p.at[1] - sign * sl.cavityDepth), fig(sl.cavityDepth), 16);
|
|
351
745
|
} else {
|
|
352
|
-
const x0 = X(p.at[0]) + sign * 6,
|
|
746
|
+
const x0 = X(p.at[0]) + sign * 6,
|
|
747
|
+
d = sign * 14;
|
|
353
748
|
span(x0, Y(p.at[1] + sl.mouth / 2), x0, Y(p.at[1] - sl.mouth / 2), fig(sl.mouth), d);
|
|
354
|
-
span(
|
|
749
|
+
span(
|
|
750
|
+
x0 + sign * 30,
|
|
751
|
+
Y(p.at[1] + sl.cavityWidth / 2),
|
|
752
|
+
x0 + sign * 30,
|
|
753
|
+
Y(p.at[1] - sl.cavityWidth / 2),
|
|
754
|
+
fig(sl.cavityWidth),
|
|
755
|
+
d,
|
|
756
|
+
);
|
|
355
757
|
const y0 = Y(-H / 2) + 6;
|
|
356
758
|
span(X(p.at[0]), y0 + 40, X(p.at[0] - sign * sl.lip), y0 + 40, fig(sl.lip), 14);
|
|
357
759
|
span(X(p.at[0]), y0 + 70, X(p.at[0] - sign * sl.cavityDepth), y0 + 70, fig(sl.cavityDepth), 14);
|
|
358
760
|
}
|
|
359
|
-
const families = [
|
|
360
|
-
|
|
761
|
+
const families = [
|
|
762
|
+
...new Set(
|
|
763
|
+
Object.values(m.faces)
|
|
764
|
+
.flat()
|
|
765
|
+
.map((q) => q.slot ?? 'closed'),
|
|
766
|
+
),
|
|
767
|
+
];
|
|
768
|
+
notes.push(
|
|
769
|
+
`slot: ${families.join(', ')}${families.length > 1 ? ` (${['top', 'bottom', 'front', 'back'].map((f) => `${f} ${m.faces[f].map((q) => q.slot ?? 'closed').join(' | ')}`).join('; ')})` : ''}: ${fig(sl.mouth)} wide, ${fig(sl.cavityWidth)} under lips ${fig(sl.lip)} thick, ${fig(sl.cavityDepth)} deep, floor ${fig(sl.floorWidth)}`,
|
|
770
|
+
);
|
|
361
771
|
}
|
|
362
772
|
if (o.measured) notes.push(`drawn from its outline: ${esc(o.source)}`);
|
|
363
773
|
const kinds = ['cell', 'given', 'corner'].map((w) => m.bores.filter((b) => b.where === w)).filter((l) => l.length);
|
|
364
|
-
for (const list of kinds)
|
|
365
|
-
|
|
774
|
+
for (const list of kinds)
|
|
775
|
+
notes.push(
|
|
776
|
+
`${list.length} × ${list[0].where === 'corner' ? 'corner hole' : 'bore'} Ø${fig(list[0].diameter)}${list[0].thread ? `, taps ${esc(list[0].thread)}${list[0].tapDrill ? ` (tap drill Ø${fig(list[0].tapDrill)})` : ''}` : ''}`,
|
|
777
|
+
);
|
|
778
|
+
if (m.bores.length) {
|
|
779
|
+
const b = m.bores.find((q) => q.where !== 'corner') ?? m.bores[0],
|
|
780
|
+
a = X(b.at[0]) + (b.diameter / 2) * S * 0.7,
|
|
781
|
+
c = Y(b.at[1]) + (b.diameter / 2) * S * 0.7;
|
|
782
|
+
line(a, c, a + 26, c + 26, THIN, 0.8);
|
|
783
|
+
text(a + 30, c + 34, `Ø${fig(b.diameter)}`, 'start');
|
|
784
|
+
}
|
|
366
785
|
if (m.cornerRadius) text(X(W / 2) + 8, Y(H / 2) - 8, `R${fig(m.cornerRadius)}`, 'start', 11);
|
|
367
786
|
if (m.wall) notes.push(`wall ${fig(m.wall)}`);
|
|
368
787
|
if (m.hollows.length) notes.push(`${m.hollows.length} × corner hollow ${fig(m.hollows[0].width)} square`);
|
|
369
788
|
if (m.chambers.length) notes.push(`${m.chambers.length} × hollow between cells, ${fig(m.chambers[0].width)} wide`);
|
|
370
|
-
notes.push(
|
|
371
|
-
|
|
789
|
+
notes.push(
|
|
790
|
+
`${m.family}${m.cells[0] * m.cells[1] > 1 ? `, ${m.cells[0]} × ${m.cells[1]} cells of ${fig(m.pitch[0])}${m.absent?.length ? ` with ${m.absent.length} not there` : ''}` : ''}${m.material ? `, ${m.material.alloy ? `${esc(m.material.alloy)} (${m.material.name})` : m.material.name}` : ''}`,
|
|
791
|
+
);
|
|
792
|
+
if (m.supply.lengths.length || m.supply.cutMax)
|
|
793
|
+
notes.push(
|
|
794
|
+
[
|
|
795
|
+
m.supply.lengths.length ? `sold as ${m.supply.lengths.map(fig).join(', ')}` : '',
|
|
796
|
+
m.supply.cutMax
|
|
797
|
+
? `cut ${fig(m.supply.cutMin ?? 0)} to ${fig(m.supply.cutMax)}${m.supply.cutTolerance != null ? ` ±${fig(m.supply.cutTolerance)}` : ''}`
|
|
798
|
+
: '',
|
|
799
|
+
m.supply.straightness != null ? `straight within ${fig(m.supply.straightness)} mm/m` : '',
|
|
800
|
+
m.supply.twist != null ? `twist within ${fig(m.supply.twist)}°/m` : '',
|
|
801
|
+
]
|
|
802
|
+
.filter(Boolean)
|
|
803
|
+
.join('; '),
|
|
804
|
+
);
|
|
372
805
|
// the table: what the sheet says, what the outline comes to
|
|
373
|
-
const rows = [
|
|
374
|
-
|
|
375
|
-
|
|
806
|
+
const rows = [
|
|
807
|
+
['area, mm²', 'area', s.area],
|
|
808
|
+
['second moment about x, mm⁴', 'inertiaX', s.inertiaX],
|
|
809
|
+
['second moment about y, mm⁴', 'inertiaY', s.inertiaY],
|
|
810
|
+
['torsion constant, mm⁴', 'torsion', s.torsion],
|
|
811
|
+
['mass, kg/m', 'massPerMetre', s.massPerMetre],
|
|
812
|
+
];
|
|
813
|
+
const ty = Y(-H / 2) + 120,
|
|
814
|
+
tx = 40,
|
|
815
|
+
col = [0, 230, 330, 440];
|
|
816
|
+
['', 'sheet', o.measured ? 'measured' : 'drawn', 'difference'].forEach((t, i) =>
|
|
817
|
+
text(tx + col[i], ty, t, i ? 'end' : 'start', 11),
|
|
818
|
+
);
|
|
376
819
|
line(tx, ty + 6, tx + 450, ty + 6, THIN, 0.6);
|
|
377
|
-
rows.forEach(([label, k, got], i) => {
|
|
820
|
+
rows.forEach(([label, k, got], i) => {
|
|
821
|
+
const y = ty + 24 + i * 18,
|
|
822
|
+
c = s.sheet[k];
|
|
823
|
+
text(tx, y, label, 'start', 11);
|
|
824
|
+
text(tx + col[1], y, m.sheet[k] != null ? sig(m.sheet[k]) : 'not given', 'end', 11);
|
|
825
|
+
text(tx + col[2], y, got != null ? sig(got) : 'no material', 'end', 11);
|
|
826
|
+
text(tx + col[3], y, c ? `${c.difference >= 0 ? '+' : ''}${(c.difference * 100).toFixed(1)}%` : '', 'end', 11);
|
|
827
|
+
});
|
|
378
828
|
const ny = ty + 24 + rows.length * 18 + 14;
|
|
379
829
|
notes.forEach((t, i) => text(tx, ny + i * 17, t, 'start', 11));
|
|
380
830
|
return sheet(set, pens, sheetW, ny + notes.length * 17 - 44);
|
|
@@ -382,30 +832,69 @@ function profileDrawing(set, g) {
|
|
|
382
832
|
|
|
383
833
|
// A slot cut into a block of metal, every figure of its family dimensioned
|
|
384
834
|
function slotDrawing(set, g) {
|
|
385
|
-
const sl = slotModel(set, {}, g),
|
|
386
|
-
|
|
387
|
-
|
|
835
|
+
const sl = slotModel(set, {}, g),
|
|
836
|
+
block = sl.cavityWidth + 8,
|
|
837
|
+
deep = sl.cavityDepth + 4,
|
|
838
|
+
S = Math.min(30, 380 / block),
|
|
839
|
+
W = block * S + 300,
|
|
840
|
+
x0 = 110 + (block * S) / 2,
|
|
841
|
+
y0 = 110,
|
|
842
|
+
X = (u) => x0 + u * S,
|
|
843
|
+
Y = (v) => y0 + v * S;
|
|
844
|
+
const pens = pen(),
|
|
845
|
+
{ out, line, text, span } = pens,
|
|
846
|
+
pts = [[-block / 2, 0], ...slotPath(sl), [block / 2, 0], [block / 2, deep], [-block / 2, deep]];
|
|
847
|
+
out.push(
|
|
848
|
+
`<path d="M ${pts.map(([u, v]) => `${fig(X(u))} ${fig(Y(v))}`).join(' L ')} Z" fill="${METAL}" stroke="${INK}" stroke-width="1.2" stroke-linejoin="round"/>`,
|
|
849
|
+
);
|
|
388
850
|
line(X(0), Y(0) - 14, X(0), Y(deep) + 10, THIN, 0.5, '8 3 2 3');
|
|
389
851
|
span(X(-sl.opening / 2), Y(0) - 6, X(sl.opening / 2), Y(0) - 6, fig(sl.opening), -14);
|
|
390
|
-
if (sl.trackWidth)
|
|
852
|
+
if (sl.trackWidth)
|
|
853
|
+
span(X(-sl.trackWidth / 2), Y(0) - 34, X(sl.trackWidth / 2), Y(0) - 34, `track ${fig(sl.trackWidth)}`, -14);
|
|
391
854
|
span(X(-sl.cavityWidth / 2), Y(deep) + 6, X(sl.cavityWidth / 2), Y(deep) + 6, fig(sl.cavityWidth), 16);
|
|
392
|
-
if (sl.floorWidth < sl.cavityWidth)
|
|
855
|
+
if (sl.floorWidth < sl.cavityWidth)
|
|
856
|
+
span(X(-sl.floorWidth / 2), Y(deep) + 46, X(sl.floorWidth / 2), Y(deep) + 46, `floor ${fig(sl.floorWidth)}`, 16);
|
|
393
857
|
span(X(block / 2) + 6, Y(0), X(block / 2) + 6, Y(sl.lip), fig(sl.lip), 16);
|
|
394
858
|
span(X(block / 2) + 56, Y(0), X(block / 2) + 56, Y(sl.cavityDepth), fig(sl.cavityDepth), 16);
|
|
395
|
-
const notes = [
|
|
396
|
-
|
|
859
|
+
const notes = [
|
|
860
|
+
`opening ${fig(sl.opening)}, lip ${fig(sl.lip)}${sl.lipAngle ? ` sloping ${fig(sl.lipAngle)}°` : ''}, ${fig(sl.cavityWidth)} wide under the lips, ${fig(sl.cavityDepth)} deep`,
|
|
861
|
+
sl.floorWidth < sl.cavityWidth
|
|
862
|
+
? `walls straight to ${fig(sl.straight)} below the face, then flanks at ${fig(sl.flankAngle)}° to a floor of ${fig(sl.floorWidth)}`
|
|
863
|
+
: 'straight walls',
|
|
864
|
+
sl.trackWidth ? `V mouth ${fig(sl.trackWidth)} across at ${fig(sl.trackAngle)}°` : '',
|
|
865
|
+
`takes the nuts of ${esc(sl.nutFamily)}`,
|
|
866
|
+
].filter(Boolean);
|
|
867
|
+
const ny = Y(deep) + 110;
|
|
868
|
+
notes.forEach((t, i) => text(40, ny + i * 17, t, 'start', 11));
|
|
397
869
|
return sheet(set, pens, Math.max(W, 620), ny + notes.length * 17 - 44);
|
|
398
870
|
}
|
|
399
871
|
|
|
400
872
|
// A slot nut from above and from the side
|
|
401
873
|
function nutDrawing(set) {
|
|
402
|
-
const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0),
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
874
|
+
const n = (k) => (typeof set.rules[k]?.value === 'number' ? set.rules[k].value : 0),
|
|
875
|
+
says = (k) => String(set.rules[k]?.value ?? ''),
|
|
876
|
+
L = n('length'),
|
|
877
|
+
w = n('width'),
|
|
878
|
+
h = n('height'),
|
|
879
|
+
d = parseFloat(says('thread').replace(/^[^0-9]*/, '')) || 0;
|
|
880
|
+
const S = Math.min(24, 260 / Math.max(L, w, 1)),
|
|
881
|
+
pens = pen(),
|
|
882
|
+
{ line, circle, rect, text, span } = pens,
|
|
883
|
+
x0 = 90,
|
|
884
|
+
y0 = 100;
|
|
885
|
+
rect(x0, y0, L * S, w * S, METAL);
|
|
886
|
+
if (d) circle(x0 + (L * S) / 2, y0 + (w * S) / 2, (d / 2) * S, '#fff');
|
|
887
|
+
span(x0, y0 + w * S + 6, x0 + L * S, y0 + w * S + 6, fig(L), 16);
|
|
888
|
+
span(x0 + L * S + 6, y0, x0 + L * S + 6, y0 + w * S, fig(w), 16);
|
|
889
|
+
const y1 = y0 + w * S + 80;
|
|
890
|
+
rect(x0, y1, L * S, h * S, METAL);
|
|
891
|
+
span(x0 + L * S + 6, y1, x0 + L * S + 6, y1 + h * S, fig(h), 16);
|
|
407
892
|
line(x0 + (L * S) / 2, y0 - 10, x0 + (L * S) / 2, y1 + h * S + 10, THIN, 0.5, '8 3 2 3');
|
|
408
|
-
const ny = y1 + h * S + 50;
|
|
893
|
+
const ny = y1 + h * S + 50;
|
|
894
|
+
[
|
|
895
|
+
`${esc(says('nut_kind'))} nut, ${esc(says('thread'))}, for ${esc(says('slot'))}`,
|
|
896
|
+
says('nut_entry') === 'end' ? 'goes in from an open end of the slot' : 'goes in anywhere along the slot',
|
|
897
|
+
].forEach((t, i) => text(40, ny + i * 17, t, 'start', 11));
|
|
409
898
|
return sheet(set, pens, Math.max(L * S + 260, 520), ny - 10);
|
|
410
899
|
}
|
|
411
900
|
const esc = (t) => String(t).replace(/&/g, '&').replace(/</g, '<');
|
|
@@ -420,75 +909,223 @@ export function drawing(set, vocab, g = { load: () => undefined, problems: [] })
|
|
|
420
909
|
const v = (k) => set.rules[k]?.value ?? 0;
|
|
421
910
|
if (set.part === 'leadscrew') return leadScrewDrawing(set);
|
|
422
911
|
if (set.part === 'belt') return beltDrawing(set);
|
|
423
|
-
if (set.part === 'linear_bearing')
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
912
|
+
if (set.part === 'linear_bearing')
|
|
913
|
+
return roundDrawing(set, {
|
|
914
|
+
D: v('outer_diameter'),
|
|
915
|
+
d: v('bore'),
|
|
916
|
+
L: v('length'),
|
|
917
|
+
notes: [`linear bearing: ${fig(v('dynamic_rating'))} N dynamic, ${fig(v('static_rating'))} N static`],
|
|
918
|
+
});
|
|
919
|
+
if (set.part === 'nut') {
|
|
920
|
+
return roundDrawing(set, {
|
|
921
|
+
D: v('body_diameter'),
|
|
922
|
+
d: v('diameter'),
|
|
923
|
+
L: v('length'),
|
|
924
|
+
flange: { D: v('flange_diameter'), w: v('flange_width'), at: v('flange_offset') },
|
|
925
|
+
circle: { D: v('hole_circle'), count: v('hole_count'), hole: v('mount_hole_diameter') || 3.5 },
|
|
926
|
+
notes: [
|
|
927
|
+
`${set.rules.thread?.value ?? ''}, ${set.rules.material?.value ?? ''}, lead ${fig(v('lead'))}`,
|
|
928
|
+
`${fig(v('hole_count'))} × Ø${fig(v('mount_hole_diameter'))} on Ø${fig(v('hole_circle'))}`,
|
|
929
|
+
],
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
if (set.part === 'coupler')
|
|
933
|
+
return roundDrawing(set, {
|
|
934
|
+
D: v('outer_diameter'),
|
|
935
|
+
L: v('length'),
|
|
936
|
+
bores: [v('bore_a'), v('bore_b')],
|
|
937
|
+
d: 0,
|
|
938
|
+
notes: [`bores Ø${fig(v('bore_a'))} and Ø${fig(v('bore_b'))}`, String(set.rules.style?.value ?? '')],
|
|
939
|
+
});
|
|
940
|
+
if (set.part === 'pulley' || set.part === 'idler')
|
|
941
|
+
return roundDrawing(set, {
|
|
942
|
+
D: v('outer_diameter'),
|
|
943
|
+
d: v('bore'),
|
|
944
|
+
L: v('body_width'),
|
|
945
|
+
pitchD: v('pitch_diameter'),
|
|
946
|
+
notes: [
|
|
947
|
+
set.part === 'pulley'
|
|
948
|
+
? `${fig(v('teeth'))} teeth, pitch circle Ø${fig(v('pitch_diameter'))} (thin), across the teeth Ø${fig(v('tooth_diameter'))}`
|
|
949
|
+
: `${set.rules.toothed?.value === 'yes' ? `${fig(v('teeth'))} teeth` : 'smooth'}, for ${fig(v('belt_width'))} mm belt`,
|
|
950
|
+
set.part === 'pulley' ? `for ${fig(v('belt_width'))} mm belt` : '',
|
|
951
|
+
],
|
|
952
|
+
});
|
|
953
|
+
if (set.part === 'rod')
|
|
954
|
+
return roundDrawing(set, {
|
|
955
|
+
D: v('diameter'),
|
|
956
|
+
L: 40,
|
|
957
|
+
notes: [`${String(set.rules.tolerance?.value ?? '')}; ${String(set.rules.hardness?.value ?? '')}`],
|
|
958
|
+
});
|
|
959
|
+
const get = (k) => {
|
|
960
|
+
const r = set.rules[set.interface?.[k] ?? k];
|
|
961
|
+
return r?.value;
|
|
962
|
+
},
|
|
963
|
+
n = (k, d = 0) => {
|
|
964
|
+
const x = get(k);
|
|
965
|
+
return typeof x === 'number' ? x : d;
|
|
966
|
+
};
|
|
967
|
+
if (!set.part && !Object.keys(set.interface || {}).some((k) => k.startsWith('body_')))
|
|
968
|
+
throw new Error(
|
|
969
|
+
`rule set "${set.name}" doesn't say what shape it is (no body_ names in it, or "part", or "interface"): there's nothing to draw`,
|
|
970
|
+
);
|
|
971
|
+
const shape = get('body_shape') ?? 'box',
|
|
972
|
+
round = shape === 'round',
|
|
973
|
+
w = round ? n('body_diameter') : n('body_width'),
|
|
974
|
+
d = round ? w : shape === 'square' ? w : n('body_depth', n('body_width'));
|
|
975
|
+
const tabs = n('mount_tab_length'),
|
|
976
|
+
off = n('boss_offset'),
|
|
977
|
+
cx = tabs ? -off : 0,
|
|
978
|
+
cy = tabs ? 0 : -off; // the body's centre, from the shaft
|
|
979
|
+
const spacing = n('mount_hole_spacing'),
|
|
980
|
+
pattern = get('mount_pattern'),
|
|
981
|
+
hole = n('mount_hole_diameter') || parseFloat(String(get('mount_hole_thread') ?? '').slice(1)) || 2;
|
|
982
|
+
const holes = !spacing
|
|
983
|
+
? []
|
|
984
|
+
: pattern === 'square'
|
|
985
|
+
? [
|
|
986
|
+
[-1, -1],
|
|
987
|
+
[1, -1],
|
|
988
|
+
[1, 1],
|
|
989
|
+
[-1, 1],
|
|
990
|
+
].map(([a, b]) => [cx + (a * spacing) / 2, cy + (b * spacing) / 2])
|
|
991
|
+
: [
|
|
992
|
+
[cx - spacing / 2, cy],
|
|
993
|
+
[cx + spacing / 2, cy],
|
|
994
|
+
];
|
|
995
|
+
const earR = n('mount_ear_radius'),
|
|
996
|
+
reach = Math.max(w / 2, d / 2, spacing / 2 + (earR || hole), tabs / 2) + 2,
|
|
997
|
+
shaftD = n('shaft_diameter'),
|
|
998
|
+
bossD = n('boss_diameter');
|
|
999
|
+
const L = n('body_length'),
|
|
1000
|
+
top = n('body_top'),
|
|
1001
|
+
bossH = n('boss_height'),
|
|
1002
|
+
shaftL = n('shaft_length'),
|
|
1003
|
+
flat = n('shaft_flat_length'),
|
|
1004
|
+
flats = n('shaft_flats'),
|
|
1005
|
+
across = n('shaft_flat_across');
|
|
436
1006
|
// scaled so a small part fills the sheet as a large one does
|
|
437
|
-
const scale = 300 / (2 * reach + Math.max(L + top, shaftL + L, 10)) / 1.4,
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
const
|
|
1007
|
+
const scale = 300 / (2 * reach + Math.max(L + top, shaftL + L, 10)) / 1.4,
|
|
1008
|
+
S = Math.max(3, Math.min(12, scale));
|
|
1009
|
+
const W = 2 * reach * S + (L + Math.max(shaftL, top + bossH) + 8) * S + 200,
|
|
1010
|
+
H = Math.max(2 * reach * S + 150, 280);
|
|
1011
|
+
const fx = reach * S + 70,
|
|
1012
|
+
fy = H / 2 + 8,
|
|
1013
|
+
X = (x) => fx + x * S,
|
|
1014
|
+
Y = (y) => fy - y * S; // the face view, shaft at the origin
|
|
1015
|
+
const sx = fx + reach * S + 90 + L * S,
|
|
1016
|
+
SX = (z) => sx + z * S,
|
|
1017
|
+
SY = (y) => fy - y * S; // the side view: z along the sheet, the mounting face at z = 0
|
|
1018
|
+
const pens = pen(),
|
|
1019
|
+
{ out, line, circle, rect, text, span } = pens;
|
|
442
1020
|
// ---- the face, from the shaft's end ----
|
|
443
1021
|
if (tabs) rect(X(cx - tabs / 2), Y(cy + d / 2), tabs * S, d * S, '#f6f4ee');
|
|
444
1022
|
for (const [hx, hy] of earR ? holes : []) circle(X(hx), Y(hy), earR * S, '#f6f4ee');
|
|
445
|
-
if (shape === 'square') {
|
|
446
|
-
|
|
1023
|
+
if (shape === 'square') {
|
|
1024
|
+
const c = n('body_corner'),
|
|
1025
|
+
h = w / 2;
|
|
1026
|
+
const p = [
|
|
1027
|
+
[-h + c, -h],
|
|
1028
|
+
[h - c, -h],
|
|
1029
|
+
[h, -h + c],
|
|
1030
|
+
[h, h - c],
|
|
1031
|
+
[h - c, h],
|
|
1032
|
+
[-h + c, h],
|
|
1033
|
+
[-h, h - c],
|
|
1034
|
+
[-h, -h + c],
|
|
1035
|
+
]
|
|
1036
|
+
.map(([a, b]) => `${fig(X(cx + a))},${fig(Y(cy + b))}`)
|
|
1037
|
+
.join(' ');
|
|
1038
|
+
out.push(`<polygon points="${p}" fill="${FILL}" stroke="${INK}" stroke-width="1.2"/>`);
|
|
1039
|
+
} else if (round) circle(X(cx), Y(cy), (w / 2) * S, FILL);
|
|
1040
|
+
else rect(X(cx - w / 2), Y(cy + d / 2), w * S, d * S);
|
|
447
1041
|
if (bossD) circle(X(0), Y(0), (bossD / 2) * S, '#ddd9cf');
|
|
448
1042
|
if (shaftD) circle(X(0), Y(0), (shaftD / 2) * S, METAL);
|
|
449
|
-
if (flats && across) {
|
|
1043
|
+
if (flats && across) {
|
|
1044
|
+
const a = flats === 2 ? across / 2 : across - shaftD / 2,
|
|
1045
|
+
c = Math.sqrt(Math.max(0, (shaftD / 2) ** 2 - a ** 2));
|
|
1046
|
+
line(X(-c), Y(a), X(c), Y(a), INK, 1.4);
|
|
1047
|
+
if (flats === 2) line(X(-c), Y(-a), X(c), Y(-a), INK, 1.4);
|
|
1048
|
+
}
|
|
450
1049
|
for (const [hx, hy] of holes) circle(X(hx), Y(hy), (hole / 2) * S, '#fff');
|
|
451
|
-
line(X(-reach), Y(0), X(reach), Y(0), THIN, 0.5, '8 3 2 3');
|
|
452
|
-
|
|
1050
|
+
line(X(-reach), Y(0), X(reach), Y(0), THIN, 0.5, '8 3 2 3');
|
|
1051
|
+
line(X(0), Y(-reach), X(0), Y(reach), THIN, 0.5, '8 3 2 3');
|
|
1052
|
+
const bottom = Y(Math.min(cy - d / 2, -reach + 2)),
|
|
1053
|
+
topY = Y(Math.max(cy + d / 2, 0));
|
|
453
1054
|
if (!round && !tabs) span(X(cx - w / 2), bottom, X(cx + w / 2), bottom, `${fig(w)}`, 18);
|
|
454
1055
|
if (round) span(X(cx - w / 2), bottom, X(cx + w / 2), bottom, `Ø${fig(w)}`, 18);
|
|
455
1056
|
if (tabs) span(X(cx - tabs / 2), bottom, X(cx + tabs / 2), bottom, `tabs ${fig(tabs)}`, 18);
|
|
456
1057
|
if (spacing) span(X(holes[0][0]), bottom, X(holes[1][0]), bottom, `holes ${fig(spacing)}`, 40);
|
|
457
1058
|
if (bossD) span(X(-bossD / 2), topY, X(bossD / 2), topY, `boss Ø${fig(bossD)}`, -14);
|
|
458
|
-
if (off) {
|
|
459
|
-
|
|
1059
|
+
if (off) {
|
|
1060
|
+
text(X(reach), Y(reach) + 2, `shaft ${fig(off)} from centre`, 'end');
|
|
1061
|
+
}
|
|
1062
|
+
const thread = get('mount_hole_thread'),
|
|
1063
|
+
holeNote = thread
|
|
1064
|
+
? `${holes.length} × ${thread}${n('mount_hole_depth') ? `, ${fig(n('mount_hole_depth'))} deep` : ''}`
|
|
1065
|
+
: hole
|
|
1066
|
+
? `${holes.length} × Ø${fig(hole)}`
|
|
1067
|
+
: '';
|
|
460
1068
|
if (holeNote) text(fx, bottom + 78, holeNote);
|
|
461
1069
|
// ---- the side, shaft to the right ----
|
|
462
1070
|
const halfH = (d / 2) * S;
|
|
463
1071
|
if (L) rect(SX(-L), SY(cy + d / 2), L * S, d * S);
|
|
464
1072
|
if (top) rect(SX(0), SY(cy + d / 2), top * S, d * S);
|
|
465
|
-
const bossAt = top;
|
|
1073
|
+
const bossAt = top;
|
|
1074
|
+
if (bossH) rect(SX(bossAt), SY(bossD / 2), bossH * S, bossD * S, '#ddd9cf');
|
|
466
1075
|
if (shaftL) rect(SX(bossAt), SY(shaftD / 2), (shaftL + (top ? bossH : 0)) * S, shaftD * S, METAL);
|
|
467
|
-
if (flat) {
|
|
1076
|
+
if (flat) {
|
|
1077
|
+
const tip = bossAt + (top ? bossH : 0) + shaftL;
|
|
1078
|
+
const a = flats === 2 ? across / 2 : across - shaftD / 2;
|
|
1079
|
+
line(SX(tip - flat), SY(a), SX(tip), SY(a), INK, 1.2);
|
|
1080
|
+
if (flats === 2) line(SX(tip - flat), SY(-a), SX(tip), SY(-a), INK, 1.2);
|
|
1081
|
+
}
|
|
468
1082
|
line(SX(0), SY(reach), SX(0), SY(-reach), THIN, 0.6, '4 3');
|
|
469
1083
|
text(SX(0), SY(reach) - 6, 'mounting face', 'middle', 10);
|
|
470
1084
|
const under = SY(cy - d / 2) + halfH * 0 + 6;
|
|
471
1085
|
if (L) span(SX(-L), under, SX(0), under, `${fig(L)}`, 14);
|
|
472
|
-
if (shaftL)
|
|
473
|
-
|
|
1086
|
+
if (shaftL)
|
|
1087
|
+
span(SX(top + (top ? bossH : 0)), under, SX(top + (top ? bossH : 0) + shaftL), under, `shaft ${fig(shaftL)}`, 36);
|
|
1088
|
+
if (flat)
|
|
1089
|
+
span(
|
|
1090
|
+
SX(top + (top ? bossH : 0) + shaftL - flat),
|
|
1091
|
+
SY(shaftD / 2) - 4,
|
|
1092
|
+
SX(top + (top ? bossH : 0) + shaftL),
|
|
1093
|
+
SY(shaftD / 2) - 4,
|
|
1094
|
+
`flat ${fig(flat)}`,
|
|
1095
|
+
-14,
|
|
1096
|
+
);
|
|
474
1097
|
if (bossH) text(SX(bossAt + bossH / 2), under + 74, `boss ${fig(bossH)} high`, 'middle', 11);
|
|
475
1098
|
return sheet(set, pens, W, H);
|
|
476
1099
|
}
|
|
477
1100
|
|
|
478
1101
|
// ---------- a draft from a datasheet's text ----------
|
|
479
|
-
const UNITS =
|
|
1102
|
+
const UNITS =
|
|
1103
|
+
/(-?\d+(?:\.\d+)?)\s*(mm|N\s?m|N\.m|Ncm|N\.cm|kg\s?cm|kgf?\.?cm|V|A|mH|Ω|ohm|rpm|RPM|Hz|g|kg|°)(?![a-zA-Z])/g;
|
|
480
1104
|
// Text drawn in a PDF: its streams unpacked, then the strings shown with Tj and TJ. A datasheet that is a picture has none.
|
|
481
1105
|
export function pdfText(file) {
|
|
482
|
-
const raw = fs.readFileSync(file),
|
|
1106
|
+
const raw = fs.readFileSync(file),
|
|
1107
|
+
latin = raw.toString('latin1'),
|
|
1108
|
+
lines = [];
|
|
483
1109
|
for (const m of latin.matchAll(/stream\r?\n/g)) {
|
|
484
|
-
const start = m.index + m[0].length,
|
|
1110
|
+
const start = m.index + m[0].length,
|
|
1111
|
+
end = latin.indexOf('endstream', start);
|
|
485
1112
|
if (end < 0) continue;
|
|
486
1113
|
const body = raw.subarray(start, end);
|
|
487
|
-
let s;
|
|
1114
|
+
let s;
|
|
1115
|
+
try {
|
|
1116
|
+
s = zlib.inflateSync(body).toString('latin1');
|
|
1117
|
+
} catch {
|
|
1118
|
+
s = body.toString('latin1');
|
|
1119
|
+
}
|
|
488
1120
|
if (!/\b(Tj|TJ)\b/.test(s)) continue;
|
|
489
1121
|
for (const block of s.matchAll(/BT([\s\S]*?)ET/g)) {
|
|
490
|
-
const words = [...block[1].matchAll(/\[((?:[^\]\\]|\\.)*)\]\s*TJ|\(((?:[^()\\]|\\.)*)\)\s*Tj/g)].map((x) =>
|
|
491
|
-
|
|
1122
|
+
const words = [...block[1].matchAll(/\[((?:[^\]\\]|\\.)*)\]\s*TJ|\(((?:[^()\\]|\\.)*)\)\s*Tj/g)].map((x) =>
|
|
1123
|
+
x[1] != null ? [...x[1].matchAll(/\(((?:[^()\\]|\\.)*)\)/g)].map((y) => y[1]).join('') : x[2],
|
|
1124
|
+
);
|
|
1125
|
+
const t = words
|
|
1126
|
+
.join(' ')
|
|
1127
|
+
.replace(/\\([()\\])/g, '$1')
|
|
1128
|
+
.trim();
|
|
492
1129
|
if (t) lines.push(t);
|
|
493
1130
|
}
|
|
494
1131
|
}
|
|
@@ -500,23 +1137,59 @@ export function pdfText(file) {
|
|
|
500
1137
|
* for a person to fill from the maker's sheet. @param {string} part @param {string} name @returns {object | null} null for a part with no draft
|
|
501
1138
|
*/
|
|
502
1139
|
export function draftPart(part, name) {
|
|
503
|
-
const v = vocabulary(),
|
|
1140
|
+
const v = vocabulary(),
|
|
1141
|
+
fields = v.drafts?.[part];
|
|
504
1142
|
if (!fields) return null;
|
|
505
|
-
const stamp = new Date().toISOString().slice(0, 10),
|
|
506
|
-
|
|
507
|
-
|
|
1143
|
+
const stamp = new Date().toISOString().slice(0, 10),
|
|
1144
|
+
rules = {};
|
|
1145
|
+
for (const [k, value] of Object.entries(fields))
|
|
1146
|
+
rules[k] = {
|
|
1147
|
+
value,
|
|
1148
|
+
...(v.fields[k]?.unit != null ? { unit: v.fields[k].unit } : {}),
|
|
1149
|
+
rule: sentence(v.fields[k]?.says ?? k),
|
|
1150
|
+
kind: 'estimate',
|
|
1151
|
+
source: 'DRAFT, not read from a sheet yet: give the sheet, its page and the date you read it',
|
|
1152
|
+
checked: stamp,
|
|
1153
|
+
};
|
|
1154
|
+
return {
|
|
1155
|
+
_doc: `A draft ${part.replace('_', ' ')}: every field the vocabulary has for one, each with a starting value. Put in the figures from the maker's sheet, with the sheet and its page as the source and today's date, and change each kind to spec as you go. Delete what the sheet has no figure for (cad rules check says which a ${part.replace('_', ' ')} needs). Then cad rules check ${name}, and cad rules draw ${name} to hold against the sheet's drawing.`,
|
|
1156
|
+
name,
|
|
1157
|
+
part,
|
|
1158
|
+
rules,
|
|
1159
|
+
};
|
|
508
1160
|
}
|
|
509
|
-
const sentence = (t) => {
|
|
1161
|
+
const sentence = (t) => {
|
|
1162
|
+
const x = String(t).trim();
|
|
1163
|
+
return x ? x[0].toUpperCase() + x.slice(1) : x;
|
|
1164
|
+
};
|
|
510
1165
|
export const draftParts = () => Object.keys(vocabulary().drafts || {});
|
|
511
1166
|
|
|
512
1167
|
/** Every figure a datasheet's text gives, as a rule set of estimates for a person to name and check. @returns {{ set: object, found: number }} */
|
|
513
1168
|
export function draftSet(name, file) {
|
|
514
1169
|
if (!fs.existsSync(file)) throw new Error(`no file ${file}`);
|
|
515
|
-
const lines = pdfText(file),
|
|
1170
|
+
const lines = pdfText(file),
|
|
1171
|
+
rules = {},
|
|
1172
|
+
stamp = new Date().toISOString().slice(0, 10),
|
|
1173
|
+
source = path.basename(file);
|
|
516
1174
|
let i = 0;
|
|
517
|
-
for (const line of lines)
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
1175
|
+
for (const line of lines)
|
|
1176
|
+
for (const m of line.matchAll(UNITS)) {
|
|
1177
|
+
i += 1;
|
|
1178
|
+
rules[`figure_${String(i).padStart(3, '0')}`] = {
|
|
1179
|
+
value: Number(m[1]),
|
|
1180
|
+
unit: m[2],
|
|
1181
|
+
rule: `DRAFT: name and check me. From: "${line.slice(0, 120)}"`,
|
|
1182
|
+
kind: 'estimate',
|
|
1183
|
+
source,
|
|
1184
|
+
checked: stamp,
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
return {
|
|
1188
|
+
set: {
|
|
1189
|
+
_doc: `A draft from ${source}: rename each figure from vocabulary.json, delete the ones you don't want, and only then change its kind to spec.`,
|
|
1190
|
+
name,
|
|
1191
|
+
rules,
|
|
1192
|
+
},
|
|
1193
|
+
found: i,
|
|
1194
|
+
};
|
|
522
1195
|
}
|