any2orca 0.6.0 → 0.7.1
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/CHANGELOG.md +44 -0
- package/README.md +2 -2
- package/dist/archive/lookupFilamentColorName.js +15 -4
- package/dist/archive/objectWorldBboxXY.js +80 -58
- package/dist/archive/parseObjectMetadata.js +33 -9
- package/dist/archive/recenterAssembleItems.js +9 -1
- package/dist/archive/recenterBuildItems.js +9 -1
- package/dist/archive/xmlBlocks.d.ts +52 -3
- package/dist/archive/xmlBlocks.js +106 -4
- package/dist/cli/config.js +32 -2
- package/dist/cli/watchState.js +22 -1
- package/dist/engine/buildFilamentConfigs.js +8 -5
- package/dist/errors.d.ts +1 -1
- package/dist/inspect.d.ts +8 -1
- package/dist/inspect.js +4 -1
- package/dist/node.js +7 -1
- package/dist/profiles.d.ts +39 -0
- package/dist/profiles.js +63 -0
- package/dist/project.js +10 -1
- package/dist/sources/prusa/beds.d.ts +33 -0
- package/dist/sources/prusa/beds.js +66 -0
- package/dist/sources/prusa/bundle.d.ts +53 -0
- package/dist/sources/prusa/bundle.js +106 -0
- package/dist/sources/prusa/convertSettings.d.ts +2 -0
- package/dist/sources/prusa/convertSettings.js +62 -2
- package/dist/sources/prusa/keyMap.js +5 -2
- package/dist/sources/prusa/modelConfig.d.ts +5 -1
- package/dist/sources/prusa/modelConfig.js +27 -10
- package/dist/sources/prusa/policyB.d.ts +56 -0
- package/dist/sources/prusa/policyB.js +161 -0
- package/dist/sources/prusa/prusa.d.ts +1 -1
- package/dist/sources/prusa/prusa.js +102 -36
- package/dist/sources/prusa/splitParts.d.ts +0 -13
- package/dist/sources/prusa/splitParts.js +107 -42
- package/dist/sources/reader.d.ts +26 -0
- package/dist/stamp.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker-entry.js +4 -3
- package/dist/worker.d.ts +7 -2
- package/dist/worker.js +22 -8
- package/package.json +3 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* A PrusaSlicer vendor bundle as `any2orca-profiles` ships it
|
|
4
|
+
* (`sources/prusaslicer/<Vendor>.json`): the vendor's print presets as the
|
|
5
|
+
* bundle has them, each with its own keys and its `inherits` list, and the
|
|
6
|
+
* old names `renamed_from` lines map to current ones. Resolving a preset
|
|
7
|
+
* follows PrusaSlicer's own rule (`PresetBundle.cpp`,
|
|
8
|
+
* `flatten_configbundle_hierarchy`): a preset's own keys win, then the last
|
|
9
|
+
* parent listed, down to the first; parents are resolved the same way first.
|
|
10
|
+
*/
|
|
11
|
+
import "../../zodSetup.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
const PRESET_NAME = z.string().min(1).max(200);
|
|
14
|
+
const KEY = z.string().regex(/^[a-z_0-9 ]{1,80}$/);
|
|
15
|
+
export const PrusaBundleSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
schema: z.literal(1),
|
|
18
|
+
vendor: z.string().regex(/^[A-Za-z0-9]{1,64}$/),
|
|
19
|
+
name: z.string().max(200),
|
|
20
|
+
configVersion: z.string().max(64),
|
|
21
|
+
slicer: z.object({ name: z.string().max(64), version: z.string().regex(/^\d+\.\d+\.\d+$/), repository: z.string().max(200), tag: z.string().max(64), commit: z.string().regex(/^[0-9a-f]{40}$/) }),
|
|
22
|
+
license: z.string().max(64),
|
|
23
|
+
groups: z.array(z.literal("print")).min(1),
|
|
24
|
+
printerModels: z.record(z.string().max(64), z.object({ name: z.string().max(200), variants: z.array(z.string().max(64)).max(100).optional() })),
|
|
25
|
+
presets: z.object({
|
|
26
|
+
print: z.record(PRESET_NAME, z.object({ inherits: z.array(PRESET_NAME).max(20).optional(), values: z.record(KEY, z.string().max(20_000)) })),
|
|
27
|
+
}),
|
|
28
|
+
renamedFrom: z.record(PRESET_NAME, PRESET_NAME),
|
|
29
|
+
/** PrusaSlicer's built-in default for each setting at that release, as INI text: what a project carries for a key no preset sets. */
|
|
30
|
+
defaults: z.record(KEY, z.string().max(20_000)),
|
|
31
|
+
})
|
|
32
|
+
.strict();
|
|
33
|
+
/** Deeper than any real bundle; a cycle or a hostile file stops here. */
|
|
34
|
+
const MAX_DEPTH = 32;
|
|
35
|
+
/**
|
|
36
|
+
* The print preset's full values, with inheritance applied, or null when the
|
|
37
|
+
* bundle doesn't have it. Abstract presets (names in `*`) resolve too; they're
|
|
38
|
+
* what concrete ones inherit from.
|
|
39
|
+
*/
|
|
40
|
+
export function resolvePrintPreset(bundle, name) {
|
|
41
|
+
const resolved = new Map();
|
|
42
|
+
const resolve = (presetName, depth) => {
|
|
43
|
+
if (depth > MAX_DEPTH)
|
|
44
|
+
return null;
|
|
45
|
+
if (resolved.has(presetName))
|
|
46
|
+
return resolved.get(presetName) ?? null;
|
|
47
|
+
const preset = bundle.presets.print[presetName];
|
|
48
|
+
if (!preset)
|
|
49
|
+
return null;
|
|
50
|
+
// Marked before the parents are followed, so a cycle resolves to what's been found so far instead of recursing.
|
|
51
|
+
resolved.set(presetName, null);
|
|
52
|
+
const values = { ...preset.values };
|
|
53
|
+
// Parents in reverse order, each adding only the keys still missing: own keys, then the last parent, down to the first.
|
|
54
|
+
for (const parent of [...(preset.inherits ?? [])].reverse()) {
|
|
55
|
+
const parentValues = resolve(parent, depth + 1);
|
|
56
|
+
if (!parentValues)
|
|
57
|
+
continue;
|
|
58
|
+
for (const [key, value] of Object.entries(parentValues))
|
|
59
|
+
if (!Object.hasOwn(values, key))
|
|
60
|
+
values[key] = value;
|
|
61
|
+
}
|
|
62
|
+
resolved.set(presetName, values);
|
|
63
|
+
return values;
|
|
64
|
+
};
|
|
65
|
+
return resolve(name, 0);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The bundle's name for a preset name a project recorded: the name itself, a
|
|
69
|
+
* current name for one the bundle renamed, or the preset a project-embedded
|
|
70
|
+
* copy was made from. PrusaSlicer names an embedded copy
|
|
71
|
+
* `<file>.3mf (<preset>)`, nested once more at each re-save
|
|
72
|
+
* (`a.3mf (b.3mf (0.20mm QUALITY @MK3))`), so the innermost name is the one.
|
|
73
|
+
*/
|
|
74
|
+
export function lookupPrintPresetName(bundle, recorded) {
|
|
75
|
+
const candidates = [recorded];
|
|
76
|
+
let inner = recorded;
|
|
77
|
+
for (let i = 0; i < 8; i++) {
|
|
78
|
+
const peeled = innerPresetName(inner);
|
|
79
|
+
if (peeled === null)
|
|
80
|
+
break;
|
|
81
|
+
inner = peeled;
|
|
82
|
+
candidates.push(inner);
|
|
83
|
+
}
|
|
84
|
+
for (const candidate of candidates) {
|
|
85
|
+
if (Object.hasOwn(bundle.presets.print, candidate) && !candidate.startsWith("*"))
|
|
86
|
+
return candidate;
|
|
87
|
+
const renamed = bundle.renamedFrom[candidate];
|
|
88
|
+
if (renamed && Object.hasOwn(bundle.presets.print, renamed))
|
|
89
|
+
return renamed;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The name inside one `<file>.3mf (<name>)` layer, or null when `name` isn't
|
|
95
|
+
* one: what `/^.+? \((.+)\)$/` captured, found without that pattern. The
|
|
96
|
+
* pattern rescanned the rest of the name for every " (" in it, and the
|
|
97
|
+
* settings file a name comes from may be 4 MB: 0.3 MB of " (" took 33 seconds.
|
|
98
|
+
*/
|
|
99
|
+
function innerPresetName(name) {
|
|
100
|
+
// `.` in that pattern stopped at a line break, and `$` only matched at the very end.
|
|
101
|
+
if (!name.endsWith(")") || /[\n\r\u2028\u2029]/.test(name))
|
|
102
|
+
return null;
|
|
103
|
+
// `.+?` needs a character before the " (", and `.+` one between it and the final ")".
|
|
104
|
+
const at = name.indexOf(" (", 1);
|
|
105
|
+
return at !== -1 && at + 2 < name.length - 1 ? name.slice(at + 2, name.length - 1) : null;
|
|
106
|
+
}
|
|
@@ -2,6 +2,8 @@ import { type PrusaIni } from "./ini.js";
|
|
|
2
2
|
export type OrcaSettings = Record<string, string | string[]>;
|
|
3
3
|
export interface ConvertedSettings {
|
|
4
4
|
settings: OrcaSettings;
|
|
5
|
+
/** For each PrusaSlicer key that was carried, the Snapmaker Orca keys it wrote. */
|
|
6
|
+
targets: Map<string, string[]>;
|
|
5
7
|
/** Settings with no Snapmaker Orca counterpart, with the reason each wasn't carried. */
|
|
6
8
|
dropped: {
|
|
7
9
|
key: string;
|
|
@@ -52,6 +52,20 @@ const num = (v) => Number.parseFloat(v);
|
|
|
52
52
|
function fmt(n) {
|
|
53
53
|
return Number.isFinite(n) ? String(Number(n.toFixed(4))) : "0";
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Snapmaker Orca's brim type for PrusaSlicer's brim settings. PrusaSlicer's "Brim" checkbox is the brim width: it's
|
|
57
|
+
* checked when the width is above 0, and unchecking it sets the width to 0 (`FrequentlyChangedParameters.cpp`). It
|
|
58
|
+
* prints no brim when the width is 0 or the type is "no brim" (`Brim.cpp`), whatever the type says, so "outer only"
|
|
59
|
+
* with a width of 0 is no brim. Snapmaker Orca draws its brim by type alone, so that state becomes "no_brim"; anything
|
|
60
|
+
* else keeps PrusaSlicer's type, which Snapmaker Orca names the same.
|
|
61
|
+
*/
|
|
62
|
+
function brimType(settings) {
|
|
63
|
+
const width = settings.get("brim_width");
|
|
64
|
+
const type = settings.get("brim_type");
|
|
65
|
+
if (width !== undefined && Number.isFinite(num(width)) && num(width) <= 0)
|
|
66
|
+
return "no_brim";
|
|
67
|
+
return type ?? null;
|
|
68
|
+
}
|
|
55
69
|
/** The value as a list, split the way PrusaSlicer joined it for what the target keeps. */
|
|
56
70
|
function entries(ini, key, target) {
|
|
57
71
|
const raw = ini.raw.get(key);
|
|
@@ -236,13 +250,35 @@ export function convertObjectOverrides(ini, overrides) {
|
|
|
236
250
|
break;
|
|
237
251
|
}
|
|
238
252
|
}
|
|
253
|
+
// An object that turns supports on itself gets the kind and the choices PrusaSlicer shows for it, which would
|
|
254
|
+
// otherwise come from the project's (Snapmaker's stock when the project has supports off).
|
|
255
|
+
if (overrides.get("support_material") === "1") {
|
|
256
|
+
const auto = merged.settings.get("support_material_auto");
|
|
257
|
+
if (auto !== undefined)
|
|
258
|
+
out.support_type ??= TRANSFORMS.supportType({ ini: merged, key: "support_material_auto", value: auto, warnings, dropped })[0];
|
|
259
|
+
const styleRule = PRUSA_KEY_MAP.support_material_style;
|
|
260
|
+
const style = merged.settings.get("support_material_style");
|
|
261
|
+
if (style !== undefined && styleRule?.kind === "choices" && styleRule.values[style] !== undefined)
|
|
262
|
+
out.support_style ??= styleRule.values[style];
|
|
263
|
+
const plateOnly = merged.settings.get("support_material_buildplate_only");
|
|
264
|
+
if (plateOnly !== undefined)
|
|
265
|
+
out.support_on_build_plate_only ??= plateOnly;
|
|
266
|
+
}
|
|
267
|
+
// An object's own brim width or type decides its brim on its own: off where the project's is on, or on where it's off.
|
|
268
|
+
if (overrides.has("brim_width") || overrides.has("brim_type")) {
|
|
269
|
+
const type = brimType(merged.settings);
|
|
270
|
+
if (type !== null)
|
|
271
|
+
out.brim_type = type;
|
|
272
|
+
}
|
|
239
273
|
return out;
|
|
240
274
|
}
|
|
241
275
|
export function convertPrusaSettings(ini) {
|
|
242
276
|
const settings = {};
|
|
277
|
+
const targets = new Map();
|
|
243
278
|
const dropped = [];
|
|
244
279
|
const unknown = [];
|
|
245
280
|
const warnings = [];
|
|
281
|
+
let current = "";
|
|
246
282
|
const write = (target, list) => {
|
|
247
283
|
// Every entry `nil` is PrusaSlicer's "not set" (a filament override left to the printer): nothing to carry.
|
|
248
284
|
if (list.every((entry) => entry === "nil"))
|
|
@@ -255,10 +291,13 @@ export function convertPrusaSettings(ini) {
|
|
|
255
291
|
return;
|
|
256
292
|
}
|
|
257
293
|
const value = shaped(target, list);
|
|
258
|
-
if (value !== null)
|
|
294
|
+
if (value !== null) {
|
|
259
295
|
settings[target] = value;
|
|
296
|
+
targets.set(current, [...(targets.get(current) ?? []), target]);
|
|
297
|
+
}
|
|
260
298
|
};
|
|
261
299
|
for (const [key, value] of ini.settings) {
|
|
300
|
+
current = key;
|
|
262
301
|
const rule = PRUSA_KEY_MAP[key];
|
|
263
302
|
if (!rule) {
|
|
264
303
|
unknown.push(key);
|
|
@@ -297,6 +336,15 @@ export function convertPrusaSettings(ini) {
|
|
|
297
336
|
break;
|
|
298
337
|
}
|
|
299
338
|
}
|
|
339
|
+
// The brim the project prints, from the width (PrusaSlicer's checkbox) as well as the type; also for a project from
|
|
340
|
+
// a PrusaSlicer old enough to have no brim type. Snapmaker Orca's pipeline always carries the source's brim type.
|
|
341
|
+
const brim = brimType(ini.settings);
|
|
342
|
+
if (brim !== null && settings.brim_type !== brim) {
|
|
343
|
+
settings.brim_type = brim;
|
|
344
|
+
const source = ini.settings.has("brim_type") ? "brim_type" : "brim_width";
|
|
345
|
+
if (!targets.get(source)?.includes("brim_type"))
|
|
346
|
+
targets.set(source, [...(targets.get(source) ?? []), "brim_type"]);
|
|
347
|
+
}
|
|
300
348
|
if (ini.version)
|
|
301
349
|
settings.version = ini.version;
|
|
302
350
|
const filamentCount = Array.isArray(settings.filament_colour) ? settings.filament_colour.length : 1;
|
|
@@ -307,6 +355,18 @@ export function convertPrusaSettings(ini) {
|
|
|
307
355
|
settings[key] = Array.from({ length: filamentCount }, () => value[0]);
|
|
308
356
|
}
|
|
309
357
|
}
|
|
358
|
+
// A support or wipe tower filament the project doesn't have (a preset for a five-tool printer on a one-filament
|
|
359
|
+
// project, say) would point Snapmaker Orca at a filament that isn't there, so the stock value stands.
|
|
360
|
+
for (const key of ["support_filament", "support_interface_filament", "wipe_tower_filament"]) {
|
|
361
|
+
const value = settings[key];
|
|
362
|
+
if (typeof value === "string" && Number.parseInt(value, 10) > filamentCount) {
|
|
363
|
+
delete settings[key];
|
|
364
|
+
for (const [source, written] of targets)
|
|
365
|
+
if (written.includes(key))
|
|
366
|
+
targets.set(source, written.filter((t) => t !== key));
|
|
367
|
+
dropped.push({ key, why: `filament ${value} isn't one of the project's ${filamentCount}` });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
310
370
|
// Snapmaker Orca sizes its purge structures by these two arrays and refuses a file whose matrix doesn't fit the
|
|
311
371
|
// filament count. PrusaSlicer has the matrix (n x n) but no vector (2n); the pipeline sizes both from the source's,
|
|
312
372
|
// so the vector is given here. The U1 purges by its own minimum, so only the sizes matter.
|
|
@@ -321,5 +381,5 @@ export function convertPrusaSettings(ini) {
|
|
|
321
381
|
.filter((k) => SETTINGS_CATALOG[k]?.group === "print")
|
|
322
382
|
.sort();
|
|
323
383
|
settings.different_settings_to_system = [printKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), ""];
|
|
324
|
-
return { settings, dropped, unknown, warnings };
|
|
384
|
+
return { settings, targets, dropped, unknown, warnings };
|
|
325
385
|
}
|
|
@@ -390,14 +390,17 @@ export const PRUSA_KEY_MAP = Object.freeze({
|
|
|
390
390
|
printer_notes: same,
|
|
391
391
|
printer_technology: same,
|
|
392
392
|
physical_printer_settings_id: machine,
|
|
393
|
-
|
|
393
|
+
// The printer's own, never transferred (the pipeline blocks them), but the inspection shows the source bed from them.
|
|
394
|
+
bed_shape: rename("printable_area"),
|
|
394
395
|
bed_custom_model: machine,
|
|
395
396
|
bed_custom_texture: machine,
|
|
396
|
-
max_print_height:
|
|
397
|
+
max_print_height: rename("printable_height"),
|
|
397
398
|
max_layer_height: machine,
|
|
398
399
|
min_layer_height: machine,
|
|
399
400
|
duplicate_distance: machine,
|
|
400
401
|
z_offset: machine,
|
|
402
|
+
// PrusaSlicer 2.9.7: scales only the filament statistics it shows and writes, never the extrusion; a printer setting.
|
|
403
|
+
used_filament_compensation: machine,
|
|
401
404
|
nozzle_diameter: same,
|
|
402
405
|
nozzle_high_flow: machine,
|
|
403
406
|
extruder_offset: machine,
|
|
@@ -46,5 +46,9 @@ export interface PrusaObject {
|
|
|
46
46
|
/** Per-object settings besides the ones above, as written (PrusaSlicer keys). */
|
|
47
47
|
settings: Map<string, string>;
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Every object in the config, in file order; an object without a usable id is skipped. The blocks are found in one
|
|
51
|
+
* pass (xmlBlocks): a lazy `<object>[\s\S]*?</object>` pattern rescans the rest of the file for every opener without a
|
|
52
|
+
* closer, which a crafted file turns into minutes.
|
|
53
|
+
*/
|
|
50
54
|
export declare function parsePrusaModelConfig(xml: string): PrusaObject[];
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* that shape is enough; it's untrusted input all the same, so everything is
|
|
26
26
|
* bounded and anything unexpected is skipped, never trusted.
|
|
27
27
|
*/
|
|
28
|
+
import { xmlBlocks } from "../../archive/xmlBlocks.js";
|
|
28
29
|
const MAX_OBJECTS = 10_000;
|
|
29
30
|
const MAX_VOLUMES = 10_000;
|
|
30
31
|
/** Metadata keys that aren't settings: identity and the volume's own bookkeeping. */
|
|
@@ -48,31 +49,47 @@ const int = (s, fallback) => {
|
|
|
48
49
|
const n = Number(s);
|
|
49
50
|
return s !== undefined && /^-?\d{1,9}$/.test(s) ? n : fallback;
|
|
50
51
|
};
|
|
51
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Every object in the config, in file order; an object without a usable id is skipped. The blocks are found in one
|
|
54
|
+
* pass (xmlBlocks): a lazy `<object>[\s\S]*?</object>` pattern rescans the rest of the file for every opener without a
|
|
55
|
+
* closer, which a crafted file turns into minutes.
|
|
56
|
+
*/
|
|
52
57
|
export function parsePrusaModelConfig(xml) {
|
|
53
58
|
const objects = [];
|
|
54
|
-
for (const
|
|
59
|
+
for (const { attrs, body } of xmlBlocks(xml, "object")) {
|
|
55
60
|
if (objects.length >= MAX_OBJECTS)
|
|
56
61
|
break;
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
const id = /^\s*id="(\d{1,9})"/.exec(` ${attrs}`)?.[1] ?? /\bid="(\d{1,9})"/.exec(attrs)?.[1];
|
|
63
|
+
if (!id)
|
|
64
|
+
continue;
|
|
65
|
+
// Object-level metadata sits outside the volumes; each volume's body is cut out, by its position, so a volume's keys
|
|
66
|
+
// aren't read as the object's. (Searching for each body's text instead rebuilt the object's text once per volume.)
|
|
60
67
|
const volumes = [];
|
|
61
|
-
|
|
68
|
+
const ownPieces = [];
|
|
69
|
+
let ownFrom = 0;
|
|
70
|
+
for (const v of xmlBlocks(body, "volume")) {
|
|
62
71
|
if (volumes.length >= MAX_VOLUMES)
|
|
63
72
|
break;
|
|
64
|
-
const
|
|
73
|
+
const first = /\bfirstid="(\d{1,9})"/.exec(v.attrs)?.[1];
|
|
74
|
+
const last = /\blastid="(\d{1,9})"/.exec(v.attrs)?.[1];
|
|
75
|
+
if (first === undefined || last === undefined)
|
|
76
|
+
continue;
|
|
77
|
+
ownPieces.push(body.slice(ownFrom, v.bodyStart));
|
|
78
|
+
ownFrom = v.bodyEnd;
|
|
79
|
+
const meta = metadata(v.body, "volume");
|
|
65
80
|
volumes.push({
|
|
66
|
-
firstTriangle: int(
|
|
67
|
-
lastTriangle: int(
|
|
81
|
+
firstTriangle: int(first, 0),
|
|
82
|
+
lastTriangle: int(last, 0),
|
|
68
83
|
volumeType: meta.get("volume_type") ?? "ModelPart",
|
|
69
84
|
extruder: int(meta.get("extruder"), 0),
|
|
70
85
|
name: meta.get("name") ?? "",
|
|
71
86
|
settings: new Map([...meta].filter(([k]) => !NOT_SETTINGS.has(k))),
|
|
72
87
|
});
|
|
73
88
|
}
|
|
89
|
+
ownPieces.push(body.slice(ownFrom));
|
|
90
|
+
const own = metadata(ownPieces.join(""), "object");
|
|
74
91
|
objects.push({
|
|
75
|
-
id: int(
|
|
92
|
+
id: int(id, 0),
|
|
76
93
|
name: own.get("name") ?? "",
|
|
77
94
|
extruder: int(own.get("extruder"), 0),
|
|
78
95
|
volumes,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ProfileCatalog } from "../../profiles.js";
|
|
2
|
+
import type { ProjectSettings } from "../../schema.js";
|
|
3
|
+
import type { PrusaProjectInfo } from "../reader.js";
|
|
4
|
+
import type { PrusaBundle } from "./bundle.js";
|
|
5
|
+
export interface PolicyBResult {
|
|
6
|
+
/** The bundle's name for the project's print preset, once resolved. */
|
|
7
|
+
presetName: string;
|
|
8
|
+
/** PrusaSlicer keys whose project value differs from the preset's (or that the preset lacks). */
|
|
9
|
+
changedKeys: string[];
|
|
10
|
+
/** Keys compared: the project's print keys that had a rule and a preset value. */
|
|
11
|
+
compared: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The project's changed print keys against the vendor preset, or null when the
|
|
15
|
+
* bundle doesn't have the preset.
|
|
16
|
+
*
|
|
17
|
+
* @param settings the project's settings, PrusaSlicer keys and values as the INI has them
|
|
18
|
+
* @param printKeys the project keys that are print settings (the key map's print-group targets), to compare
|
|
19
|
+
*/
|
|
20
|
+
export declare function changedPrintKeys(bundle: PrusaBundle, recordedPresetName: string, settings: ReadonlyMap<string, string>, printKeys: ReadonlySet<string>): PolicyBResult | null;
|
|
21
|
+
/**
|
|
22
|
+
* PrusaSlicer keys carried as the project has them, whatever its preset says (owner decision 2026-11-05): the Supports
|
|
23
|
+
* menu on PrusaSlicer's sidebar and the filaments supports print from. Left to the comparison, a project that turns
|
|
24
|
+
* supports on got Snapmaker's stock kind of support (tree) instead of the one PrusaSlicer showed (snug, say); an
|
|
25
|
+
* Input Shaper preset's default, "for support enforcers only", became Snapmaker's stock "off", leaving painted
|
|
26
|
+
* enforcers unused; and a soluble-support preset's support filament and zero contact distance became any filament with
|
|
27
|
+
* a gap. The menu's choices (everywhere, build plate only, enforcers only) and the kind of support count only when
|
|
28
|
+
* supports are on; the contact distances only with a support filament of its own.
|
|
29
|
+
*/
|
|
30
|
+
export declare function statedPrintKeys(settings: ReadonlyMap<string, string>): string[];
|
|
31
|
+
type BundleEntry = ReturnType<ProfileCatalog["prusaBundles"]>[number];
|
|
32
|
+
/**
|
|
33
|
+
* The bundles to try for a project, best first: per vendor, the newest whose
|
|
34
|
+
* PrusaSlicer release is at or below the one that saved the project (the
|
|
35
|
+
* presets as that release shipped them), then the newest of all as a fallback
|
|
36
|
+
* for a project from a release older than any pinned. A project of unknown
|
|
37
|
+
* version gets the newest.
|
|
38
|
+
*/
|
|
39
|
+
export declare function bundlesForVersion(bundles: readonly BundleEntry[], version: string | null): BundleEntry[];
|
|
40
|
+
export interface PolicyBApplied {
|
|
41
|
+
/** The project settings with the changed list rewritten to the keys the creator changed. */
|
|
42
|
+
projectSettings: ProjectSettings;
|
|
43
|
+
notes: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Applies policy B to a PrusaSlicer project's converted settings: finds the
|
|
47
|
+
* project's print preset in the catalog's vendor bundles, and rewrites the
|
|
48
|
+
* changed list (`different_settings_to_system`, print entry) to the Snapmaker
|
|
49
|
+
* Orca keys the creator's changed settings map to. Returns null, with the
|
|
50
|
+
* reason as a note, when no bundle has the preset: the list then stays as
|
|
51
|
+
* the reader wrote it (every mapped print setting), which is policy A.
|
|
52
|
+
*/
|
|
53
|
+
export declare function applyPolicyB(prusa: PrusaProjectInfo, catalog: ProfileCatalog, projectSettings: ProjectSettings): Promise<PolicyBApplied | null>;
|
|
54
|
+
/** The note for a project whose print preset no bundle has, so every mapped print setting is carried. */
|
|
55
|
+
export declare function policyBFallbackNote(prusa: PrusaProjectInfo, catalog: ProfileCatalog): string;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Policy B for a PrusaSlicer project: carry only the print settings the
|
|
4
|
+
* creator changed from the vendor's preset, as a Bambu Studio family project's
|
|
5
|
+
* own list of changed settings does. The project's print preset is resolved
|
|
6
|
+
* from the vendor bundle, every key the project has is compared with the
|
|
7
|
+
* preset's value (in PrusaSlicer's own value forms), and the keys that differ,
|
|
8
|
+
* mapped to Snapmaker Orca's, become the changed list the pipeline's gate
|
|
9
|
+
* reads. Keys the preset doesn't have count as changed: transfer is the safe
|
|
10
|
+
* side. Filament values are carried whole, as for every source.
|
|
11
|
+
*/
|
|
12
|
+
import { SETTINGS_CATALOG } from "../../diff/settingsCatalog.js";
|
|
13
|
+
import { lookupPrintPresetName, resolvePrintPreset } from "./bundle.js";
|
|
14
|
+
/** PrusaSlicer keys that identify or describe a preset, never a print setting a creator "changes". */
|
|
15
|
+
const NOT_COMPARED = new Set(["print_settings_id", "inherits", "compatible_printers", "compatible_printers_condition", "renamed_from", "alias", "notes"]);
|
|
16
|
+
const NUMBER = /^-?\d+(\.\d+)?%?$/;
|
|
17
|
+
/** One value in PrusaSlicer's INI, normalized for a comparison: numbers by value, lists entry by entry. */
|
|
18
|
+
function normalize(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (NUMBER.test(trimmed)) {
|
|
21
|
+
const percent = trimmed.endsWith("%");
|
|
22
|
+
return `${Number.parseFloat(trimmed)}${percent ? "%" : ""}`;
|
|
23
|
+
}
|
|
24
|
+
if (trimmed.includes(",") || trimmed.includes(";")) {
|
|
25
|
+
return trimmed
|
|
26
|
+
.split(/[,;]/)
|
|
27
|
+
.map((entry) => normalize(entry))
|
|
28
|
+
.join(",");
|
|
29
|
+
}
|
|
30
|
+
return trimmed.replace(/^"(.*)"$/s, "$1").replace(/\r\n/g, "\n");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The project's changed print keys against the vendor preset, or null when the
|
|
34
|
+
* bundle doesn't have the preset.
|
|
35
|
+
*
|
|
36
|
+
* @param settings the project's settings, PrusaSlicer keys and values as the INI has them
|
|
37
|
+
* @param printKeys the project keys that are print settings (the key map's print-group targets), to compare
|
|
38
|
+
*/
|
|
39
|
+
export function changedPrintKeys(bundle, recordedPresetName, settings, printKeys) {
|
|
40
|
+
const presetName = lookupPrintPresetName(bundle, recordedPresetName);
|
|
41
|
+
if (!presetName)
|
|
42
|
+
return null;
|
|
43
|
+
const preset = resolvePrintPreset(bundle, presetName);
|
|
44
|
+
if (!preset)
|
|
45
|
+
return null;
|
|
46
|
+
const changedKeys = [];
|
|
47
|
+
let compared = 0;
|
|
48
|
+
for (const [key, value] of settings) {
|
|
49
|
+
if (!printKeys.has(key) || NOT_COMPARED.has(key))
|
|
50
|
+
continue;
|
|
51
|
+
// A key no preset in the chain sets has PrusaSlicer's built-in default in a project; that's not a change either.
|
|
52
|
+
const presetValue = preset[key] ?? bundle.defaults[key];
|
|
53
|
+
if (presetValue === undefined) {
|
|
54
|
+
changedKeys.push(key);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
compared++;
|
|
58
|
+
if (normalize(value) !== normalize(presetValue))
|
|
59
|
+
changedKeys.push(key);
|
|
60
|
+
}
|
|
61
|
+
return { presetName, changedKeys: changedKeys.sort(), compared };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* PrusaSlicer keys carried as the project has them, whatever its preset says (owner decision 2026-11-05): the Supports
|
|
65
|
+
* menu on PrusaSlicer's sidebar and the filaments supports print from. Left to the comparison, a project that turns
|
|
66
|
+
* supports on got Snapmaker's stock kind of support (tree) instead of the one PrusaSlicer showed (snug, say); an
|
|
67
|
+
* Input Shaper preset's default, "for support enforcers only", became Snapmaker's stock "off", leaving painted
|
|
68
|
+
* enforcers unused; and a soluble-support preset's support filament and zero contact distance became any filament with
|
|
69
|
+
* a gap. The menu's choices (everywhere, build plate only, enforcers only) and the kind of support count only when
|
|
70
|
+
* supports are on; the contact distances only with a support filament of its own.
|
|
71
|
+
*/
|
|
72
|
+
export function statedPrintKeys(settings) {
|
|
73
|
+
const keys = ["support_material", "support_material_extruder", "support_material_interface_extruder"];
|
|
74
|
+
if (settings.get("support_material") === "1")
|
|
75
|
+
keys.push("support_material_auto", "support_material_buildplate_only", "support_material_style");
|
|
76
|
+
const ownFilament = ["support_material_extruder", "support_material_interface_extruder"].some((key) => Number.parseInt(settings.get(key) ?? "0", 10) > 0);
|
|
77
|
+
if (ownFilament)
|
|
78
|
+
keys.push("support_material_contact_distance", "support_material_bottom_contact_distance");
|
|
79
|
+
return keys.filter((key) => settings.has(key));
|
|
80
|
+
}
|
|
81
|
+
const versionParts = (v) => v.split(".").map(Number);
|
|
82
|
+
const compareVersions = (a, b) => {
|
|
83
|
+
const [x, y] = [versionParts(a), versionParts(b)];
|
|
84
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The bundles to try for a project, best first: per vendor, the newest whose
|
|
88
|
+
* PrusaSlicer release is at or below the one that saved the project (the
|
|
89
|
+
* presets as that release shipped them), then the newest of all as a fallback
|
|
90
|
+
* for a project from a release older than any pinned. A project of unknown
|
|
91
|
+
* version gets the newest.
|
|
92
|
+
*/
|
|
93
|
+
export function bundlesForVersion(bundles, version) {
|
|
94
|
+
const byVendor = new Map();
|
|
95
|
+
for (const b of bundles)
|
|
96
|
+
byVendor.set(b.vendor, [...(byVendor.get(b.vendor) ?? []), b]);
|
|
97
|
+
const ordered = [];
|
|
98
|
+
for (const list of byVendor.values()) {
|
|
99
|
+
const newestFirst = [...list].sort((a, b) => compareVersions(b.slicerVersion, a.slicerVersion));
|
|
100
|
+
const matching = version ? newestFirst.find((b) => compareVersions(b.slicerVersion, version) <= 0) : undefined;
|
|
101
|
+
if (matching)
|
|
102
|
+
ordered.push(matching);
|
|
103
|
+
if (newestFirst[0] && newestFirst[0] !== matching)
|
|
104
|
+
ordered.push(newestFirst[0]);
|
|
105
|
+
}
|
|
106
|
+
return ordered;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Applies policy B to a PrusaSlicer project's converted settings: finds the
|
|
110
|
+
* project's print preset in the catalog's vendor bundles, and rewrites the
|
|
111
|
+
* changed list (`different_settings_to_system`, print entry) to the Snapmaker
|
|
112
|
+
* Orca keys the creator's changed settings map to. Returns null, with the
|
|
113
|
+
* reason as a note, when no bundle has the preset: the list then stays as
|
|
114
|
+
* the reader wrote it (every mapped print setting), which is policy A.
|
|
115
|
+
*/
|
|
116
|
+
export async function applyPolicyB(prusa, catalog, projectSettings) {
|
|
117
|
+
const bundles = catalog.prusaBundles();
|
|
118
|
+
if (bundles.length === 0)
|
|
119
|
+
return null;
|
|
120
|
+
// The PrusaSlicer keys that are print settings: those whose Snapmaker Orca keys are in the print group.
|
|
121
|
+
const printKeys = new Set([...prusa.targets].filter(([, targets]) => targets.some((t) => SETTINGS_CATALOG[t]?.group === "print")).map(([key]) => key));
|
|
122
|
+
for (const entry of bundlesForVersion(bundles, prusa.version)) {
|
|
123
|
+
// A bundle that can't be read (a site that copied an older data folder, say) is no reason to fail the conversion:
|
|
124
|
+
// the next bundle is tried, and the fallback carries every mapped print setting, with the note saying so.
|
|
125
|
+
let bundle;
|
|
126
|
+
try {
|
|
127
|
+
bundle = await catalog.prusaBundle(entry.vendor, entry.slicerVersion);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
bundle = null;
|
|
131
|
+
}
|
|
132
|
+
if (!bundle)
|
|
133
|
+
continue;
|
|
134
|
+
const result = changedPrintKeys(bundle, prusa.presets.print, prusa.settings, printKeys);
|
|
135
|
+
if (!result)
|
|
136
|
+
continue;
|
|
137
|
+
const changedTargets = new Set();
|
|
138
|
+
for (const key of [...result.changedKeys, ...statedPrintKeys(prusa.settings)]) {
|
|
139
|
+
for (const target of prusa.targets.get(key) ?? [])
|
|
140
|
+
if (SETTINGS_CATALOG[target]?.group === "print")
|
|
141
|
+
changedTargets.add(target);
|
|
142
|
+
}
|
|
143
|
+
const list = projectSettings.different_settings_to_system;
|
|
144
|
+
const rest = Array.isArray(list) ? list.slice(1) : [];
|
|
145
|
+
return {
|
|
146
|
+
projectSettings: { ...projectSettings, different_settings_to_system: [[...changedTargets].sort().join(";"), ...rest] },
|
|
147
|
+
notes: [
|
|
148
|
+
` note: print settings compared with PrusaSlicer's "${result.presetName}" (${entry.name}'s presets of PrusaSlicer ${entry.slicerVersion}): ${result.changedKeys.length} of ${result.compared + result.changedKeys.length} differ from the preset, and only those are carried, with the Supports menu and the support filaments as the project has them; Snapmaker's stock stands for the rest.`,
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/** The note for a project whose print preset no bundle has, so every mapped print setting is carried. */
|
|
155
|
+
export function policyBFallbackNote(prusa, catalog) {
|
|
156
|
+
const bundles = catalog.prusaBundles();
|
|
157
|
+
if (bundles.length === 0)
|
|
158
|
+
return " note: this profile catalog has no PrusaSlicer vendor presets, so every mapped print setting is carried as the creator's.";
|
|
159
|
+
const vendors = [...new Set(bundles.map((b) => b.name))].join(" or ");
|
|
160
|
+
return ` note: print preset "${prusa.presets.print.slice(0, 80)}" isn't in ${vendors}'s presets (a user preset, or one this catalog doesn't know), so every mapped print setting is carried as the creator's.`;
|
|
161
|
+
}
|
|
@@ -55,5 +55,5 @@ export declare function partsOf(object: PrusaObject, components: ReadonlyMap<num
|
|
|
55
55
|
* Bambu's `model_settings.config`: each object with its name, filament and settings, its parts, and one plate holding
|
|
56
56
|
* every instance.
|
|
57
57
|
*/
|
|
58
|
-
export declare function buildModelSettings(ini: PrusaIni, objects: readonly PrusaObject[], instanceCounts: ReadonlyMap<number, number>, parts: (object: PrusaObject) => ModelPart[]): string;
|
|
58
|
+
export declare function buildModelSettings(ini: PrusaIni, objects: readonly PrusaObject[], instanceCounts: ReadonlyMap<number, number>, parts: (object: PrusaObject) => ModelPart[], plateOf?: (objectId: number) => number): string;
|
|
59
59
|
export declare const prusaReader: SourceReader;
|