any2orca 0.6.0 → 0.7.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/CHANGELOG.md +19 -0
- package/README.md +2 -2
- package/dist/errors.d.ts +1 -1
- package/dist/node.js +7 -1
- package/dist/profiles.d.ts +39 -0
- package/dist/profiles.js +63 -0
- package/dist/project.js +9 -0
- 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 +92 -0
- package/dist/sources/prusa/convertSettings.d.ts +2 -0
- package/dist/sources/prusa/convertSettings.js +7 -2
- package/dist/sources/prusa/keyMap.js +3 -2
- package/dist/sources/prusa/modelConfig.d.ts +5 -1
- package/dist/sources/prusa/modelConfig.js +24 -10
- package/dist/sources/prusa/policyB.d.ts +46 -0
- package/dist/sources/prusa/policyB.js +142 -0
- package/dist/sources/prusa/prusa.d.ts +1 -1
- package/dist/sources/prusa/prusa.js +94 -38
- package/dist/sources/reader.d.ts +21 -0
- package/dist/stamp.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# any2orca
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Output-affecting
|
|
6
|
+
|
|
7
|
+
- **A PrusaSlicer conversion carries only the print settings the creator changed.** `any2orca-profiles` now ships Prusa Research's print presets as ten PrusaSlicer releases shipped them, 2.2.0 to 2.9.6 (from the bundle in PrusaSlicer's own repository at each release tag, AGPL-3.0 like that package), with each release's built-in defaults, and the converter compares a PrusaSlicer project's print settings with its named preset from the release that saved the project (the newest at or below it), resolved through the preset's inheritance the way PrusaSlicer resolves it, with the built-in default standing in for a setting the preset leaves alone. Only the settings that differ are carried; Snapmaker's stock stands for the rest, as it does for a Bambu Studio family project, whose own list of changed settings the converter has always used. The report says which preset was compared and how many settings differed. A project on a preset the bundle doesn't have (a user's own, or a name an older PrusaSlicer wrote) is converted as before, every mapped print setting carried, and the report says so. Filament settings are carried whole for every source, as before. Profile sources that don't implement the new optional `readSource` keep the previous behavior, as does a site whose copy of the profile data has no bundles.
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- **A PrusaSlicer project's beds become plates.** PrusaSlicer 2.9 can place objects on several beds, laid out on a grid around the printer's bed; each becomes a plate in the converted file, with its objects and its own pauses and color changes, and the report counts them. An object off every bed stays on plate 1, with a warning. A project saved before 2.9 has one bed and one plate, as before.
|
|
12
|
+
- **A PrusaSlicer project's bed size shows in the inspection.** The printer's bed shape and height are now read into the project (never transferred to the U1 file, which keeps its own), so `inspect()` and the web app's plate view show the source bed, an XL's 360 x 360 mm say, instead of a default. Converted files are unchanged by this.
|
|
13
|
+
|
|
14
|
+
### Fixes
|
|
15
|
+
|
|
16
|
+
- **A crafted PrusaSlicer project can't stall the converter.** Two of the PrusaSlicer reader's parsers (the per-object settings file, the color-change file) scanned the rest of the file again for every block that had no closing tag, so a file built to have hundreds of thousands of them took minutes; both now read the file in one pass, like the model parsers. A regression test holds the time.
|
|
17
|
+
|
|
18
|
+
### Other
|
|
19
|
+
|
|
20
|
+
- Pins any2orca-profiles 0.3.0, which holds the PrusaSlicer presets.
|
|
21
|
+
|
|
3
22
|
## 0.6.0
|
|
4
23
|
|
|
5
24
|
### Output-affecting
|
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ Profiles come from a source you pass in; the library never fetches anything on i
|
|
|
66
66
|
| `dirProfileSource(dir)` from `any2orca/node` | A catalog folder (newer or custom profiles) |
|
|
67
67
|
| `fetchProfileSource(url)` | A copy of `any2orca-profiles/data` served by your site |
|
|
68
68
|
| `memoryProfileSource({ index, profiles })` | Data you already have in memory |
|
|
69
|
-
| Your own `{ readIndex, readProfile }` | Anything else; add `release(path)` to serve older Snapmaker Orca releases |
|
|
69
|
+
| Your own `{ readIndex, readProfile }` | Anything else; add `release(path)` to serve older Snapmaker Orca releases, and `readSource(path)` to serve the PrusaSlicer presets (`sources/prusaslicer/*.json`), without which a PrusaSlicer project has every mapped print setting carried |
|
|
70
70
|
|
|
71
71
|
A catalog holds the profiles of each Snapmaker Orca release any2orca supports, and conversions use the newest unless you pass `snapmakerOrcaVersion`:
|
|
72
72
|
|
|
@@ -125,7 +125,7 @@ A call that fails throws `Any2orcaError`. Its `code` is stable, so a UI can bran
|
|
|
125
125
|
| Code | Meaning |
|
|
126
126
|
|---|---|
|
|
127
127
|
| `invalid_file` | Not a readable 3MF: a damaged zip, missing project files, unsafe entries |
|
|
128
|
-
| `unsupported_slicer` | A readable project from a slicer this doesn't convert (
|
|
128
|
+
| `unsupported_slicer` | A readable project from a slicer this doesn't convert (SuperSlicer, say, or an older AnycubicSlicer, both built on PrusaSlicer); `error.slicer` names it |
|
|
129
129
|
| `too_large` | The project unpacks to more than the size limit (2 GB by default) |
|
|
130
130
|
| `invalid_project` | A readable 3MF whose settings or objects are malformed or over a limit |
|
|
131
131
|
| `profile_not_found` | The profile id isn't in the catalog and wasn't retired |
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What went wrong, as a stable code a UI can branch on:
|
|
3
3
|
* - `invalid_file`: not a readable 3MF (corrupt zip, missing project files, unsafe entries).
|
|
4
|
-
* - `unsupported_slicer`: a readable project from a slicer this doesn't convert (
|
|
4
|
+
* - `unsupported_slicer`: a readable project from a slicer this doesn't convert (SuperSlicer, say, or an older AnycubicSlicer, both built on PrusaSlicer); `slicer` names it.
|
|
5
5
|
* - `too_large`: a project that unpacks to more than the size limit (2 GB by default; `maxUnpackedBytes` changes it).
|
|
6
6
|
* - `invalid_project`: a readable 3MF whose settings or objects are malformed or over a limit.
|
|
7
7
|
* - `profile_not_found`: the requested profile id isn't in the catalog and wasn't retired.
|
package/dist/node.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { readFile, stat } from "node:fs/promises";
|
|
11
11
|
import { createRequire } from "node:module";
|
|
12
12
|
import { dirname, join, resolve } from "node:path";
|
|
13
|
-
import { isReleasePath, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
|
|
13
|
+
import { isReleasePath, isSourcePath, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, MAX_SOURCE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
|
|
14
14
|
async function readCapped(path, maxBytes) {
|
|
15
15
|
let size;
|
|
16
16
|
try {
|
|
@@ -36,6 +36,12 @@ export function dirProfileSource(dir) {
|
|
|
36
36
|
// Ids are validated against the index (lowercase letters, digits, dots
|
|
37
37
|
// and dashes, no slashes) before this is called, so this stays in root.
|
|
38
38
|
readProfile: (id) => readCapped(join(root, "profiles", `${id}.json`), MAX_PROFILE_BYTES),
|
|
39
|
+
// sources/prusaslicer/<Vendor>.json only (checked by the catalog and here), so this stays in root too.
|
|
40
|
+
readSource: (path) => {
|
|
41
|
+
if (!isSourcePath(path))
|
|
42
|
+
throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
|
|
43
|
+
return readCapped(join(root, ...path.split("/")), MAX_SOURCE_BYTES);
|
|
44
|
+
},
|
|
39
45
|
release: (path) => {
|
|
40
46
|
// releases/<digits.digits.digits> only, so this stays in root too.
|
|
41
47
|
if (!isReleasePath(path))
|
package/dist/profiles.d.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import "./zodSetup.js";
|
|
21
21
|
import { z } from "zod";
|
|
22
|
+
import { type PrusaBundle } from "./sources/prusa/bundle.js";
|
|
22
23
|
import { Any2orcaError } from "./errors.js";
|
|
23
24
|
import type { ConvertProfile } from "./engine/runConvertPipeline.js";
|
|
24
25
|
/** Raw access to a catalog. Both methods return parsed JSON; the core validates it. */
|
|
@@ -34,6 +35,13 @@ export interface ProfileSource {
|
|
|
34
35
|
* catalog with one release.
|
|
35
36
|
*/
|
|
36
37
|
release?(path: string): ProfileSource;
|
|
38
|
+
/**
|
|
39
|
+
* One source-slicer data file (`sources/prusaslicer/<Vendor>.json`). Only
|
|
40
|
+
* called with a path the index lists, which passes {@link isSourcePath}.
|
|
41
|
+
* Leave it out for a source without such data: a PrusaSlicer project is
|
|
42
|
+
* then converted with every mapped setting treated as changed.
|
|
43
|
+
*/
|
|
44
|
+
readSource?(path: string): Promise<unknown>;
|
|
37
45
|
}
|
|
38
46
|
/** True for a path a {@link ProfileSource.release} may be asked for. */
|
|
39
47
|
export declare function isReleasePath(path: string): boolean;
|
|
@@ -41,6 +49,11 @@ export declare function isReleasePath(path: string): boolean;
|
|
|
41
49
|
export declare const MAX_INDEX_BYTES: number;
|
|
42
50
|
/** Largest single profile file accepted from any source. A real one is about 100 KB. */
|
|
43
51
|
export declare const MAX_PROFILE_BYTES: number;
|
|
52
|
+
/** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
|
|
53
|
+
export declare const MAX_SOURCE_BYTES: number;
|
|
54
|
+
/** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
|
|
55
|
+
export declare const SOURCE_PATH: RegExp;
|
|
56
|
+
export declare function isSourcePath(path: string): boolean;
|
|
44
57
|
export declare const ProfileIndexSchema: z.ZodObject<{
|
|
45
58
|
schema: z.ZodLiteral<1>;
|
|
46
59
|
dataVersion: z.ZodString;
|
|
@@ -104,6 +117,16 @@ export declare const ProfileIndexSchema: z.ZodObject<{
|
|
|
104
117
|
application: z.ZodString;
|
|
105
118
|
path: z.ZodUnion<readonly [z.ZodLiteral<".">, z.ZodString]>;
|
|
106
119
|
}, z.core.$strip>>>;
|
|
120
|
+
sources: z.ZodOptional<z.ZodObject<{
|
|
121
|
+
prusaslicer: z.ZodArray<z.ZodObject<{
|
|
122
|
+
vendor: z.ZodString;
|
|
123
|
+
name: z.ZodString;
|
|
124
|
+
path: z.ZodString;
|
|
125
|
+
slicerVersion: z.ZodString;
|
|
126
|
+
configVersion: z.ZodString;
|
|
127
|
+
slicerTag: z.ZodString;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
}, z.core.$strip>>;
|
|
107
130
|
}, z.core.$strip>;
|
|
108
131
|
export type ProfileIndex = z.infer<typeof ProfileIndexSchema>;
|
|
109
132
|
export declare const ProfileFileSchema: z.ZodObject<{
|
|
@@ -179,12 +202,26 @@ export declare class ProfileCatalog {
|
|
|
179
202
|
private readonly retired;
|
|
180
203
|
private readonly cache;
|
|
181
204
|
private readonly releaseCatalogs;
|
|
205
|
+
private readonly bundles;
|
|
182
206
|
constructor(index: ProfileIndex, source: ProfileSource);
|
|
183
207
|
/** Every profile, or only one nozzle size's, sorted by nozzle size and then layer height (finest first). */
|
|
184
208
|
list(filter?: {
|
|
185
209
|
nozzleDiameter?: string;
|
|
186
210
|
}): ProfileSummary[];
|
|
187
211
|
get(id: string): ProfileSummary | undefined;
|
|
212
|
+
/** The PrusaSlicer vendor bundles this catalog holds, as the index lists them. */
|
|
213
|
+
prusaBundles(): {
|
|
214
|
+
vendor: string;
|
|
215
|
+
name: string;
|
|
216
|
+
slicerVersion: string;
|
|
217
|
+
configVersion: string;
|
|
218
|
+
slicerTag: string;
|
|
219
|
+
}[];
|
|
220
|
+
/**
|
|
221
|
+
* One PrusaSlicer vendor bundle, loaded and checked once, or null when the
|
|
222
|
+
* catalog doesn't list it or its source can't read source data.
|
|
223
|
+
*/
|
|
224
|
+
prusaBundle(vendor: string, slicerVersion: string): Promise<PrusaBundle | null>;
|
|
188
225
|
/** The live profile that replaced a retired id, if `id` was retired. */
|
|
189
226
|
retiredSuccessor(id: string): RetiredProfile | undefined;
|
|
190
227
|
/** The Snapmaker Orca releases this catalog holds, newest first. The first is the default. */
|
|
@@ -222,6 +259,8 @@ export interface MemoryCatalogData {
|
|
|
222
259
|
index: unknown;
|
|
223
260
|
profiles: Record<string, unknown>;
|
|
224
261
|
releases?: Record<string, MemoryCatalogData>;
|
|
262
|
+
/** Source-slicer data files by their index path (`sources/prusaslicer/<Vendor>.json`). */
|
|
263
|
+
sources?: Record<string, unknown>;
|
|
225
264
|
}
|
|
226
265
|
/** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
|
|
227
266
|
export declare function memoryProfileSource(data: MemoryCatalogData): ProfileSource;
|
package/dist/profiles.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import "./zodSetup.js";
|
|
22
22
|
import { z } from "zod";
|
|
23
|
+
import { PrusaBundleSchema } from "./sources/prusa/bundle.js";
|
|
23
24
|
import { Any2orcaError } from "./errors.js";
|
|
24
25
|
import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
|
|
25
26
|
import { parseTierName } from "./engine/parseTierName.js";
|
|
@@ -34,6 +35,13 @@ export function isReleasePath(path) {
|
|
|
34
35
|
export const MAX_INDEX_BYTES = 1024 * 1024;
|
|
35
36
|
/** Largest single profile file accepted from any source. A real one is about 100 KB. */
|
|
36
37
|
export const MAX_PROFILE_BYTES = 8 * 1024 * 1024;
|
|
38
|
+
/** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
|
|
39
|
+
export const MAX_SOURCE_BYTES = 8 * 1024 * 1024;
|
|
40
|
+
/** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
|
|
41
|
+
export const SOURCE_PATH = /^sources\/prusaslicer\/[A-Za-z0-9]{1,64}-\d+\.\d+\.\d+\.json$/;
|
|
42
|
+
export function isSourcePath(path) {
|
|
43
|
+
return SOURCE_PATH.test(path);
|
|
44
|
+
}
|
|
37
45
|
const ID = z.string().regex(/^[a-z0-9][a-z0-9.-]{0,63}$/, "must be lowercase letters, digits, dots and dashes");
|
|
38
46
|
const VERSION = z.string().regex(/^\d+(\.\d+){1,3}([-+][0-9A-Za-z.-]{1,32})?$/);
|
|
39
47
|
const DIAMETER = z.string().regex(/^\d{1,2}(\.\d{1,3})?$/);
|
|
@@ -105,6 +113,18 @@ export const ProfileIndexSchema = z.object({
|
|
|
105
113
|
.min(1)
|
|
106
114
|
.max(50)
|
|
107
115
|
.optional(),
|
|
116
|
+
/**
|
|
117
|
+
* Source-slicer data the catalog holds, independent of the Snapmaker Orca
|
|
118
|
+
* release: PrusaSlicer's vendor preset bundles (print presets), used to
|
|
119
|
+
* tell what a PrusaSlicer project's creator changed. Absent in older data.
|
|
120
|
+
*/
|
|
121
|
+
sources: z
|
|
122
|
+
.object({
|
|
123
|
+
prusaslicer: z
|
|
124
|
+
.array(z.object({ vendor: z.string().regex(/^[A-Za-z0-9]{1,64}$/), name: NAME, path: z.string().regex(SOURCE_PATH), slicerVersion: VERSION, configVersion: presetText(64), slicerTag: presetText(64) }))
|
|
125
|
+
.max(50),
|
|
126
|
+
})
|
|
127
|
+
.optional(),
|
|
108
128
|
});
|
|
109
129
|
export const ProfileFileSchema = z.object({
|
|
110
130
|
schema: z.literal(1),
|
|
@@ -145,6 +165,7 @@ export class ProfileCatalog {
|
|
|
145
165
|
retired;
|
|
146
166
|
cache = new Map();
|
|
147
167
|
releaseCatalogs = new Map();
|
|
168
|
+
bundles = new Map();
|
|
148
169
|
constructor(index, source) {
|
|
149
170
|
this.index = index;
|
|
150
171
|
this.source = source;
|
|
@@ -200,6 +221,34 @@ export class ProfileCatalog {
|
|
|
200
221
|
const summary = this.byId.get(id);
|
|
201
222
|
return summary ? { ...summary } : undefined;
|
|
202
223
|
}
|
|
224
|
+
/** The PrusaSlicer vendor bundles this catalog holds, as the index lists them. */
|
|
225
|
+
prusaBundles() {
|
|
226
|
+
return (this.index.sources?.prusaslicer ?? []).map(({ vendor, name, slicerVersion, configVersion, slicerTag }) => ({ vendor, name, slicerVersion, configVersion, slicerTag }));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* One PrusaSlicer vendor bundle, loaded and checked once, or null when the
|
|
230
|
+
* catalog doesn't list it or its source can't read source data.
|
|
231
|
+
*/
|
|
232
|
+
prusaBundle(vendor, slicerVersion) {
|
|
233
|
+
const entry = this.index.sources?.prusaslicer.find((b) => b.vendor === vendor && b.slicerVersion === slicerVersion);
|
|
234
|
+
if (!entry || !this.source.readSource || !isSourcePath(entry.path))
|
|
235
|
+
return Promise.resolve(null);
|
|
236
|
+
const cacheKey = `${vendor}-${slicerVersion}`;
|
|
237
|
+
let pending = this.bundles.get(cacheKey);
|
|
238
|
+
if (!pending) {
|
|
239
|
+
const path = entry.path;
|
|
240
|
+
pending = this.source.readSource(path).then((raw) => {
|
|
241
|
+
const parsed = PrusaBundleSchema.safeParse(raw);
|
|
242
|
+
if (!parsed.success)
|
|
243
|
+
throw new ProfileDataError(`Profile catalog's ${path} isn't a vendor bundle: ${describeIssues(parsed.error)}`);
|
|
244
|
+
if (parsed.data.vendor !== vendor || parsed.data.slicer.version !== slicerVersion)
|
|
245
|
+
throw new ProfileDataError(`Profile catalog's ${path} is the bundle for ${parsed.data.vendor} ${parsed.data.slicer.version}, not ${vendor} ${slicerVersion}.`);
|
|
246
|
+
return parsed.data;
|
|
247
|
+
});
|
|
248
|
+
this.bundles.set(cacheKey, pending);
|
|
249
|
+
}
|
|
250
|
+
return pending;
|
|
251
|
+
}
|
|
203
252
|
/** The live profile that replaced a retired id, if `id` was retired. */
|
|
204
253
|
retiredSuccessor(id) {
|
|
205
254
|
if (this.byId.has(id))
|
|
@@ -392,6 +441,11 @@ export function fetchProfileSource(baseUrl, options = {}) {
|
|
|
392
441
|
throw new ProfileDataError(`Not a release folder: ${plainVersion(path)}.`);
|
|
393
442
|
return fetchProfileSource(new URL(`${path}/`, base), options);
|
|
394
443
|
},
|
|
444
|
+
readSource: (path) => {
|
|
445
|
+
if (!isSourcePath(path))
|
|
446
|
+
throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
|
|
447
|
+
return read(path, MAX_SOURCE_BYTES);
|
|
448
|
+
},
|
|
395
449
|
};
|
|
396
450
|
}
|
|
397
451
|
/** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
|
|
@@ -403,6 +457,15 @@ export function memoryProfileSource(data) {
|
|
|
403
457
|
throw new ProfileDataError(`No profile file for id "${id}".`);
|
|
404
458
|
return data.profiles[id];
|
|
405
459
|
},
|
|
460
|
+
...(data.sources
|
|
461
|
+
? {
|
|
462
|
+
readSource: async (path) => {
|
|
463
|
+
if (!isSourcePath(path) || !Object.hasOwn(data.sources, path))
|
|
464
|
+
throw new ProfileDataError(`No source data at ${JSON.stringify(path.slice(0, 60))}.`);
|
|
465
|
+
return data.sources[path];
|
|
466
|
+
},
|
|
467
|
+
}
|
|
468
|
+
: {}),
|
|
406
469
|
release: (path) => {
|
|
407
470
|
if (!isReleasePath(path) || !data.releases || !Object.hasOwn(data.releases, path))
|
|
408
471
|
throw new ProfileDataError(`No catalog data for ${plainVersion(path)}.`);
|
package/dist/project.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* and response pass through JSON, so numbers serialize the same way every
|
|
9
9
|
* time (e.g. -0 becomes 0) and output is reproducible byte for byte.
|
|
10
10
|
*/
|
|
11
|
+
import { applyPolicyB, policyBFallbackNote } from "./sources/prusa/policyB.js";
|
|
11
12
|
import { applyConvertResponse, prepareConvertRequest } from "./archive/zip.js";
|
|
12
13
|
import { unwrapIfBundle } from "./archive/unwrapBundle.js";
|
|
13
14
|
import { detectNozzleDiameter } from "./engine/detectNozzleDiameter.js";
|
|
@@ -203,6 +204,13 @@ export class Project {
|
|
|
203
204
|
const top = await loadCatalog(options.profiles);
|
|
204
205
|
const catalog = options.snapmakerOrcaVersion === undefined ? top : await top.forRelease(options.snapmakerOrcaVersion);
|
|
205
206
|
const routeWarnings = [];
|
|
207
|
+
// A PrusaSlicer project records no list of what its creator changed; with the vendor's presets at hand, the
|
|
208
|
+
// list is the diff against the project's print preset (policy B), as a Bambu Studio family project's own list is.
|
|
209
|
+
let policyB = null;
|
|
210
|
+
if (this.parsed.prusa) {
|
|
211
|
+
policyB = await applyPolicyB(this.parsed.prusa, top, this.request.projectSettings);
|
|
212
|
+
routeWarnings.push(...(policyB ? policyB.notes : [policyBFallbackNote(this.parsed.prusa, top)]));
|
|
213
|
+
}
|
|
206
214
|
let profileId;
|
|
207
215
|
let profileMatch;
|
|
208
216
|
let profileNotes = [];
|
|
@@ -245,6 +253,7 @@ export class Project {
|
|
|
245
253
|
const highFlowHotends = normalizeHighFlowOption(options.highFlowHotends);
|
|
246
254
|
const request = {
|
|
247
255
|
...this.request,
|
|
256
|
+
...(policyB ? { projectSettings: policyB.projectSettings } : {}),
|
|
248
257
|
...(options.filamentComplianceMode ? { filamentComplianceMode: options.filamentComplianceMode } : {}),
|
|
249
258
|
...(highFlowHotends !== false ? { highFlowHotends } : {}),
|
|
250
259
|
...(options.hardenedNozzles === true ? { hardenedNozzles: true } : {}),
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PrusaSlicer 2.9's several beds. The project records no bed for an object:
|
|
3
|
+
* the beds are virtual copies of the printer's bed laid out on a grid around
|
|
4
|
+
* it, and an object is on the first bed (in index order) whose area it
|
|
5
|
+
* touches, as PrusaSlicer decides it on load (`BuildVolume::object_state`
|
|
6
|
+
* with `MultipleBeds::get_bed_translation`). The grid walks outward in square
|
|
7
|
+
* rings: bed 0 at the origin, 1 to its right, 2 above it, 3 diagonally, then
|
|
8
|
+
* the next ring (`BedsGrid::grid_coords_abs2index`). The gap between beds is
|
|
9
|
+
* the smaller of 100 mm and three tenths of the bed's diagonal
|
|
10
|
+
* (`MultipleBeds::bed_gap`). Projects saved before 2.9.0 have one bed.
|
|
11
|
+
*/
|
|
12
|
+
/** PrusaSlicer's `MAX_NUMBER_OF_BEDS`. */
|
|
13
|
+
export declare const MAX_BEDS = 9;
|
|
14
|
+
export interface BedRect {
|
|
15
|
+
minX: number;
|
|
16
|
+
minY: number;
|
|
17
|
+
maxX: number;
|
|
18
|
+
maxY: number;
|
|
19
|
+
}
|
|
20
|
+
/** The printer's bed from `bed_shape` ("0x0,250x0,250x210,0x210"), as its bounding rectangle; null when unreadable. */
|
|
21
|
+
export declare function parseBedShape(value: string | undefined): BedRect | null;
|
|
22
|
+
/** The gap between two beds, in mm. */
|
|
23
|
+
export declare function bedGap(bed: BedRect): number;
|
|
24
|
+
/** Grid coordinates of bed `index` (the first quadrant of PrusaSlicer's grid). */
|
|
25
|
+
export declare function bedGridCoords(index: number): [number, number];
|
|
26
|
+
/** Where bed `index` sits: its translation from the printer's bed, in mm. */
|
|
27
|
+
export declare function bedTranslation(index: number, bed: BedRect): [number, number];
|
|
28
|
+
/**
|
|
29
|
+
* The bed an object is on, by its world bounding box: the first bed whose
|
|
30
|
+
* rectangle the box touches, or null when it touches none (PrusaSlicer leaves
|
|
31
|
+
* such an object on no bed).
|
|
32
|
+
*/
|
|
33
|
+
export declare function bedIndexOf(bbox: readonly [number, number, number, number], bed: BedRect): number | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* PrusaSlicer 2.9's several beds. The project records no bed for an object:
|
|
4
|
+
* the beds are virtual copies of the printer's bed laid out on a grid around
|
|
5
|
+
* it, and an object is on the first bed (in index order) whose area it
|
|
6
|
+
* touches, as PrusaSlicer decides it on load (`BuildVolume::object_state`
|
|
7
|
+
* with `MultipleBeds::get_bed_translation`). The grid walks outward in square
|
|
8
|
+
* rings: bed 0 at the origin, 1 to its right, 2 above it, 3 diagonally, then
|
|
9
|
+
* the next ring (`BedsGrid::grid_coords_abs2index`). The gap between beds is
|
|
10
|
+
* the smaller of 100 mm and three tenths of the bed's diagonal
|
|
11
|
+
* (`MultipleBeds::bed_gap`). Projects saved before 2.9.0 have one bed.
|
|
12
|
+
*/
|
|
13
|
+
/** PrusaSlicer's `MAX_NUMBER_OF_BEDS`. */
|
|
14
|
+
export const MAX_BEDS = 9;
|
|
15
|
+
/** The printer's bed from `bed_shape` ("0x0,250x0,250x210,0x210"), as its bounding rectangle; null when unreadable. */
|
|
16
|
+
export function parseBedShape(value) {
|
|
17
|
+
if (!value)
|
|
18
|
+
return null;
|
|
19
|
+
const points = value.split(",").map((p) => p.trim().split("x").map(Number));
|
|
20
|
+
if (points.length < 3 || points.some((p) => p.length !== 2 || !p.every(Number.isFinite)))
|
|
21
|
+
return null;
|
|
22
|
+
const xs = points.map((p) => p[0]);
|
|
23
|
+
const ys = points.map((p) => p[1]);
|
|
24
|
+
const rect = { minX: Math.min(...xs), minY: Math.min(...ys), maxX: Math.max(...xs), maxY: Math.max(...ys) };
|
|
25
|
+
return rect.maxX > rect.minX && rect.maxY > rect.minY ? rect : null;
|
|
26
|
+
}
|
|
27
|
+
/** The gap between two beds, in mm. */
|
|
28
|
+
export function bedGap(bed) {
|
|
29
|
+
const w = bed.maxX - bed.minX;
|
|
30
|
+
const h = bed.maxY - bed.minY;
|
|
31
|
+
return Math.min(100, Math.hypot(w, h) * 0.3);
|
|
32
|
+
}
|
|
33
|
+
/** Grid coordinates of bed `index` (the first quadrant of PrusaSlicer's grid). */
|
|
34
|
+
export function bedGridCoords(index) {
|
|
35
|
+
if (index <= 0)
|
|
36
|
+
return [0, 0];
|
|
37
|
+
const ring = Math.floor(Math.sqrt(index)) + 1; // the ring whose outer coordinate is ring - 1
|
|
38
|
+
const start = (ring - 1) * (ring - 1);
|
|
39
|
+
const edge = ring - 1;
|
|
40
|
+
if (index === ring * ring - 1)
|
|
41
|
+
return [edge, edge];
|
|
42
|
+
if (index < start + edge)
|
|
43
|
+
return [edge, index - start];
|
|
44
|
+
return [index - start - edge, edge];
|
|
45
|
+
}
|
|
46
|
+
/** Where bed `index` sits: its translation from the printer's bed, in mm. */
|
|
47
|
+
export function bedTranslation(index, bed) {
|
|
48
|
+
const [gx, gy] = bedGridCoords(index);
|
|
49
|
+
const gap = bedGap(bed);
|
|
50
|
+
return [gx * (bed.maxX - bed.minX + gap), gy * (bed.maxY - bed.minY + gap)];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The bed an object is on, by its world bounding box: the first bed whose
|
|
54
|
+
* rectangle the box touches, or null when it touches none (PrusaSlicer leaves
|
|
55
|
+
* such an object on no bed).
|
|
56
|
+
*/
|
|
57
|
+
export function bedIndexOf(bbox, bed) {
|
|
58
|
+
const [minX, maxX, minY, maxY] = bbox;
|
|
59
|
+
for (let index = 0; index < MAX_BEDS; index++) {
|
|
60
|
+
const [tx, ty] = bedTranslation(index, bed);
|
|
61
|
+
const touches = maxX >= bed.minX + tx && minX <= bed.maxX + tx && maxY >= bed.minY + ty && minY <= bed.maxY + ty;
|
|
62
|
+
if (touches)
|
|
63
|
+
return index;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A PrusaSlicer vendor bundle as `any2orca-profiles` ships it
|
|
3
|
+
* (`sources/prusaslicer/<Vendor>.json`): the vendor's print presets as the
|
|
4
|
+
* bundle has them, each with its own keys and its `inherits` list, and the
|
|
5
|
+
* old names `renamed_from` lines map to current ones. Resolving a preset
|
|
6
|
+
* follows PrusaSlicer's own rule (`PresetBundle.cpp`,
|
|
7
|
+
* `flatten_configbundle_hierarchy`): a preset's own keys win, then the last
|
|
8
|
+
* parent listed, down to the first; parents are resolved the same way first.
|
|
9
|
+
*/
|
|
10
|
+
import "../../zodSetup.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
export declare const PrusaBundleSchema: z.ZodObject<{
|
|
13
|
+
schema: z.ZodLiteral<1>;
|
|
14
|
+
vendor: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
configVersion: z.ZodString;
|
|
17
|
+
slicer: z.ZodObject<{
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
version: z.ZodString;
|
|
20
|
+
repository: z.ZodString;
|
|
21
|
+
tag: z.ZodString;
|
|
22
|
+
commit: z.ZodString;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
license: z.ZodString;
|
|
25
|
+
groups: z.ZodArray<z.ZodLiteral<"print">>;
|
|
26
|
+
printerModels: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
27
|
+
name: z.ZodString;
|
|
28
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
presets: z.ZodObject<{
|
|
31
|
+
print: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
32
|
+
inherits: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
+
values: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
34
|
+
}, z.core.$strip>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
renamedFrom: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
37
|
+
defaults: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type PrusaBundle = z.infer<typeof PrusaBundleSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* The print preset's full values, with inheritance applied, or null when the
|
|
42
|
+
* bundle doesn't have it. Abstract presets (names in `*`) resolve too; they're
|
|
43
|
+
* what concrete ones inherit from.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolvePrintPreset(bundle: PrusaBundle, name: string): Record<string, string> | null;
|
|
46
|
+
/**
|
|
47
|
+
* The bundle's name for a preset name a project recorded: the name itself, a
|
|
48
|
+
* current name for one the bundle renamed, or the preset a project-embedded
|
|
49
|
+
* copy was made from. PrusaSlicer names an embedded copy
|
|
50
|
+
* `<file>.3mf (<preset>)`, nested once more at each re-save
|
|
51
|
+
* (`a.3mf (b.3mf (0.20mm QUALITY @MK3))`), so the innermost name is the one.
|
|
52
|
+
*/
|
|
53
|
+
export declare function lookupPrintPresetName(bundle: PrusaBundle, recorded: string): string | null;
|
|
@@ -0,0 +1,92 @@
|
|
|
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 m = /^.+? \((.+)\)$/.exec(inner);
|
|
79
|
+
if (!m)
|
|
80
|
+
break;
|
|
81
|
+
inner = m[1];
|
|
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
|
+
}
|
|
@@ -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;
|
|
@@ -240,9 +240,11 @@ export function convertObjectOverrides(ini, overrides) {
|
|
|
240
240
|
}
|
|
241
241
|
export function convertPrusaSettings(ini) {
|
|
242
242
|
const settings = {};
|
|
243
|
+
const targets = new Map();
|
|
243
244
|
const dropped = [];
|
|
244
245
|
const unknown = [];
|
|
245
246
|
const warnings = [];
|
|
247
|
+
let current = "";
|
|
246
248
|
const write = (target, list) => {
|
|
247
249
|
// Every entry `nil` is PrusaSlicer's "not set" (a filament override left to the printer): nothing to carry.
|
|
248
250
|
if (list.every((entry) => entry === "nil"))
|
|
@@ -255,10 +257,13 @@ export function convertPrusaSettings(ini) {
|
|
|
255
257
|
return;
|
|
256
258
|
}
|
|
257
259
|
const value = shaped(target, list);
|
|
258
|
-
if (value !== null)
|
|
260
|
+
if (value !== null) {
|
|
259
261
|
settings[target] = value;
|
|
262
|
+
targets.set(current, [...(targets.get(current) ?? []), target]);
|
|
263
|
+
}
|
|
260
264
|
};
|
|
261
265
|
for (const [key, value] of ini.settings) {
|
|
266
|
+
current = key;
|
|
262
267
|
const rule = PRUSA_KEY_MAP[key];
|
|
263
268
|
if (!rule) {
|
|
264
269
|
unknown.push(key);
|
|
@@ -321,5 +326,5 @@ export function convertPrusaSettings(ini) {
|
|
|
321
326
|
.filter((k) => SETTINGS_CATALOG[k]?.group === "print")
|
|
322
327
|
.sort();
|
|
323
328
|
settings.different_settings_to_system = [printKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), ""];
|
|
324
|
-
return { settings, dropped, unknown, warnings };
|
|
329
|
+
return { settings, targets, dropped, unknown, warnings };
|
|
325
330
|
}
|
|
@@ -390,10 +390,11 @@ 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,
|
|
@@ -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,44 @@ 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; the volume blocks are cut out first so a volume's keys aren't read
|
|
66
|
+
// as the object's.
|
|
60
67
|
const volumes = [];
|
|
61
|
-
|
|
68
|
+
let ownText = body;
|
|
69
|
+
for (const v of xmlBlocks(body, "volume")) {
|
|
62
70
|
if (volumes.length >= MAX_VOLUMES)
|
|
63
71
|
break;
|
|
64
|
-
const
|
|
72
|
+
const first = /\bfirstid="(\d{1,9})"/.exec(v.attrs)?.[1];
|
|
73
|
+
const last = /\blastid="(\d{1,9})"/.exec(v.attrs)?.[1];
|
|
74
|
+
if (first === undefined || last === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
ownText = ownText.replace(v.body, "");
|
|
77
|
+
const meta = metadata(v.body, "volume");
|
|
65
78
|
volumes.push({
|
|
66
|
-
firstTriangle: int(
|
|
67
|
-
lastTriangle: int(
|
|
79
|
+
firstTriangle: int(first, 0),
|
|
80
|
+
lastTriangle: int(last, 0),
|
|
68
81
|
volumeType: meta.get("volume_type") ?? "ModelPart",
|
|
69
82
|
extruder: int(meta.get("extruder"), 0),
|
|
70
83
|
name: meta.get("name") ?? "",
|
|
71
84
|
settings: new Map([...meta].filter(([k]) => !NOT_SETTINGS.has(k))),
|
|
72
85
|
});
|
|
73
86
|
}
|
|
87
|
+
const own = metadata(ownText, "object");
|
|
74
88
|
objects.push({
|
|
75
|
-
id: int(
|
|
89
|
+
id: int(id, 0),
|
|
76
90
|
name: own.get("name") ?? "",
|
|
77
91
|
extruder: int(own.get("extruder"), 0),
|
|
78
92
|
volumes,
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
type BundleEntry = ReturnType<ProfileCatalog["prusaBundles"]>[number];
|
|
22
|
+
/**
|
|
23
|
+
* The bundles to try for a project, best first: per vendor, the newest whose
|
|
24
|
+
* PrusaSlicer release is at or below the one that saved the project (the
|
|
25
|
+
* presets as that release shipped them), then the newest of all as a fallback
|
|
26
|
+
* for a project from a release older than any pinned. A project of unknown
|
|
27
|
+
* version gets the newest.
|
|
28
|
+
*/
|
|
29
|
+
export declare function bundlesForVersion(bundles: readonly BundleEntry[], version: string | null): BundleEntry[];
|
|
30
|
+
export interface PolicyBApplied {
|
|
31
|
+
/** The project settings with the changed list rewritten to the keys the creator changed. */
|
|
32
|
+
projectSettings: ProjectSettings;
|
|
33
|
+
notes: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Applies policy B to a PrusaSlicer project's converted settings: finds the
|
|
37
|
+
* project's print preset in the catalog's vendor bundles, and rewrites the
|
|
38
|
+
* changed list (`different_settings_to_system`, print entry) to the Snapmaker
|
|
39
|
+
* Orca keys the creator's changed settings map to. Returns null, with the
|
|
40
|
+
* reason as a note, when no bundle has the preset: the list then stays as
|
|
41
|
+
* the reader wrote it (every mapped print setting), which is policy A.
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyPolicyB(prusa: PrusaProjectInfo, catalog: ProfileCatalog, projectSettings: ProjectSettings): Promise<PolicyBApplied | null>;
|
|
44
|
+
/** The note for a project whose print preset no bundle has, so every mapped print setting is carried. */
|
|
45
|
+
export declare function policyBFallbackNote(prusa: PrusaProjectInfo, catalog: ProfileCatalog): string;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
const versionParts = (v) => v.split(".").map(Number);
|
|
64
|
+
const compareVersions = (a, b) => {
|
|
65
|
+
const [x, y] = [versionParts(a), versionParts(b)];
|
|
66
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The bundles to try for a project, best first: per vendor, the newest whose
|
|
70
|
+
* PrusaSlicer release is at or below the one that saved the project (the
|
|
71
|
+
* presets as that release shipped them), then the newest of all as a fallback
|
|
72
|
+
* for a project from a release older than any pinned. A project of unknown
|
|
73
|
+
* version gets the newest.
|
|
74
|
+
*/
|
|
75
|
+
export function bundlesForVersion(bundles, version) {
|
|
76
|
+
const byVendor = new Map();
|
|
77
|
+
for (const b of bundles)
|
|
78
|
+
byVendor.set(b.vendor, [...(byVendor.get(b.vendor) ?? []), b]);
|
|
79
|
+
const ordered = [];
|
|
80
|
+
for (const list of byVendor.values()) {
|
|
81
|
+
const newestFirst = [...list].sort((a, b) => compareVersions(b.slicerVersion, a.slicerVersion));
|
|
82
|
+
const matching = version ? newestFirst.find((b) => compareVersions(b.slicerVersion, version) <= 0) : undefined;
|
|
83
|
+
if (matching)
|
|
84
|
+
ordered.push(matching);
|
|
85
|
+
if (newestFirst[0] && newestFirst[0] !== matching)
|
|
86
|
+
ordered.push(newestFirst[0]);
|
|
87
|
+
}
|
|
88
|
+
return ordered;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Applies policy B to a PrusaSlicer project's converted settings: finds the
|
|
92
|
+
* project's print preset in the catalog's vendor bundles, and rewrites the
|
|
93
|
+
* changed list (`different_settings_to_system`, print entry) to the Snapmaker
|
|
94
|
+
* Orca keys the creator's changed settings map to. Returns null, with the
|
|
95
|
+
* reason as a note, when no bundle has the preset: the list then stays as
|
|
96
|
+
* the reader wrote it (every mapped print setting), which is policy A.
|
|
97
|
+
*/
|
|
98
|
+
export async function applyPolicyB(prusa, catalog, projectSettings) {
|
|
99
|
+
const bundles = catalog.prusaBundles();
|
|
100
|
+
if (bundles.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
// The PrusaSlicer keys that are print settings: those whose Snapmaker Orca keys are in the print group.
|
|
103
|
+
const printKeys = new Set([...prusa.targets].filter(([, targets]) => targets.some((t) => SETTINGS_CATALOG[t]?.group === "print")).map(([key]) => key));
|
|
104
|
+
for (const entry of bundlesForVersion(bundles, prusa.version)) {
|
|
105
|
+
// A bundle that can't be read (a site that copied an older data folder, say) is no reason to fail the conversion:
|
|
106
|
+
// the next bundle is tried, and the fallback carries every mapped print setting, with the note saying so.
|
|
107
|
+
let bundle;
|
|
108
|
+
try {
|
|
109
|
+
bundle = await catalog.prusaBundle(entry.vendor, entry.slicerVersion);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
bundle = null;
|
|
113
|
+
}
|
|
114
|
+
if (!bundle)
|
|
115
|
+
continue;
|
|
116
|
+
const result = changedPrintKeys(bundle, prusa.presets.print, prusa.settings, printKeys);
|
|
117
|
+
if (!result)
|
|
118
|
+
continue;
|
|
119
|
+
const changedTargets = new Set();
|
|
120
|
+
for (const key of result.changedKeys)
|
|
121
|
+
for (const target of prusa.targets.get(key) ?? [])
|
|
122
|
+
if (SETTINGS_CATALOG[target]?.group === "print")
|
|
123
|
+
changedTargets.add(target);
|
|
124
|
+
const list = projectSettings.different_settings_to_system;
|
|
125
|
+
const rest = Array.isArray(list) ? list.slice(1) : [];
|
|
126
|
+
return {
|
|
127
|
+
projectSettings: { ...projectSettings, different_settings_to_system: [[...changedTargets].sort().join(";"), ...rest] },
|
|
128
|
+
notes: [
|
|
129
|
+
` 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; Snapmaker's stock stands for the rest.`,
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/** The note for a project whose print preset no bundle has, so every mapped print setting is carried. */
|
|
136
|
+
export function policyBFallbackNote(prusa, catalog) {
|
|
137
|
+
const bundles = catalog.prusaBundles();
|
|
138
|
+
if (bundles.length === 0)
|
|
139
|
+
return " note: this profile catalog has no PrusaSlicer vendor presets, so every mapped print setting is carried as the creator's.";
|
|
140
|
+
const vendors = [...new Set(bundles.map((b) => b.name))].join(" or ");
|
|
141
|
+
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.`;
|
|
142
|
+
}
|
|
@@ -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;
|
|
@@ -22,7 +22,8 @@ import { parseItemPositions } from "../../archive/parseItemPositions.js";
|
|
|
22
22
|
import { MODEL_SETTINGS_PATH, PROJECT_SETTINGS_PATH, TOP_MODEL_PATH } from "../../archive/paths.js";
|
|
23
23
|
import { xmlBlocks } from "../../archive/xmlBlocks.js";
|
|
24
24
|
import { convertObjectOverrides, convertPrusaSettings } from "./convertSettings.js";
|
|
25
|
-
import { parsePrusaIni } from "./ini.js";
|
|
25
|
+
import { parsePrusaIni, splitStringList } from "./ini.js";
|
|
26
|
+
import { bedIndexOf, parseBedShape } from "./beds.js";
|
|
26
27
|
import { parsePrusaModelConfig } from "./modelConfig.js";
|
|
27
28
|
import { splitMultiPartObjects } from "./splitParts.js";
|
|
28
29
|
const utf8Decoder = new TextDecoder("utf-8");
|
|
@@ -100,43 +101,55 @@ export function adaptPrusaModel(text) {
|
|
|
100
101
|
export function convertCustomGcodes(prusaXml) {
|
|
101
102
|
if (!/<custom_gcodes_per_print_z[\s>]/.test(prusaXml))
|
|
102
103
|
return null;
|
|
103
|
-
|
|
104
|
+
// PrusaSlicer 2.9 writes one block per bed, side by side, each with its bed_idx; older files have one block.
|
|
105
|
+
const plates = [];
|
|
104
106
|
let colorChanges = 0;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
107
|
+
let total = 0;
|
|
108
|
+
// One pass over the blocks (xmlBlocks): a lazy pattern would rescan the file for every opener without a closer.
|
|
109
|
+
for (const block of xmlBlocks(prusaXml, "custom_gcodes_per_print_z")) {
|
|
110
|
+
const bedIndex = Number(/\bbed_idx="(\d{1,2})"/.exec(block.attrs)?.[1] ?? "0");
|
|
111
|
+
const body = block.body;
|
|
112
|
+
const layers = [];
|
|
113
|
+
for (const m of body.matchAll(/<code\s+([^>]*?)\/>/g)) {
|
|
114
|
+
if (total >= MAX_CUSTOM_GCODES)
|
|
115
|
+
break;
|
|
116
|
+
total++;
|
|
117
|
+
const attrs = m[1];
|
|
118
|
+
const attr = (name) => {
|
|
119
|
+
const found = new RegExp(`\\b${name}="([^"]*)"`).exec(attrs);
|
|
120
|
+
return found ? decodeXml(found[1]) : null;
|
|
121
|
+
};
|
|
122
|
+
const printZ = attr("print_z");
|
|
123
|
+
if (printZ === null || !/^\d+(\.\d+)?$/.test(printZ))
|
|
124
|
+
continue;
|
|
125
|
+
const sourceType = attr("type") ?? "";
|
|
126
|
+
if (!/^[0-4]$/.test(sourceType))
|
|
127
|
+
continue;
|
|
128
|
+
const extruder = attr("extruder") ?? "1";
|
|
129
|
+
if (!/^\d{1,3}$/.test(extruder))
|
|
130
|
+
continue;
|
|
131
|
+
const color = (attr("color") ?? "").slice(0, 32);
|
|
132
|
+
let extra = (attr("extra") ?? "").slice(0, 4000);
|
|
133
|
+
// 0 is a color change: a pause (1) in Snapmaker Orca, where the U1 pauses with M600 for the swap.
|
|
134
|
+
let type = sourceType;
|
|
135
|
+
if (sourceType === "0") {
|
|
136
|
+
type = "1";
|
|
137
|
+
extra = color ? `Color change to ${color}` : "Color change";
|
|
138
|
+
colorChanges++;
|
|
139
|
+
}
|
|
140
|
+
// 4 is custom G-code, the only kind whose text is the creator's own.
|
|
141
|
+
const gcode = type === "4" ? (attr("gcode") ?? extra).slice(0, 4000) : type === "2" ? "tool_change" : "";
|
|
142
|
+
layers.push(`<layer top_z="${printZ}" type="${type}" extruder="${extruder}" color="${xmlAttr(color)}" extra="${xmlAttr(extra)}" gcode="${xmlAttr(gcode)}"/>`);
|
|
130
143
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
if (layers.length === 0)
|
|
145
|
+
continue;
|
|
146
|
+
const mode = /<mode\s+value="(SingleExtruder|MultiAsSingle|MultiExtruder)"/.exec(body)?.[1] ?? "SingleExtruder";
|
|
147
|
+
plates.push(["<plate>", `<plate_info id="${bedIndex + 1}"/>`, ...layers, `<mode value="${mode}"/>`, "</plate>"].join("\n"));
|
|
134
148
|
}
|
|
135
|
-
if (
|
|
149
|
+
if (plates.length === 0)
|
|
136
150
|
return null;
|
|
137
|
-
const mode = /<mode\s+value="(SingleExtruder|MultiAsSingle|MultiExtruder)"/.exec(prusaXml)?.[1] ?? "SingleExtruder";
|
|
138
151
|
return {
|
|
139
|
-
xml: ['<?xml version="1.0" encoding="utf-8"?>', "<custom_gcodes_per_layer>",
|
|
152
|
+
xml: ['<?xml version="1.0" encoding="utf-8"?>', "<custom_gcodes_per_layer>", ...plates, "</custom_gcodes_per_layer>", ""].join("\n"),
|
|
140
153
|
colorChanges,
|
|
141
154
|
};
|
|
142
155
|
}
|
|
@@ -174,6 +187,10 @@ export function componentIds(topModelText) {
|
|
|
174
187
|
}
|
|
175
188
|
return out;
|
|
176
189
|
}
|
|
190
|
+
const compareVersions = (a, b) => {
|
|
191
|
+
const [x, y] = [a.split(".").map(Number), b.split(".").map(Number)];
|
|
192
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
193
|
+
};
|
|
177
194
|
/** The filament an object prints with: its own, else its only part's; 0 is the default (filament 1). */
|
|
178
195
|
function objectFilament(object) {
|
|
179
196
|
if (object.extruder > 0)
|
|
@@ -210,9 +227,10 @@ export function partsOf(object, components, split, depth = 0) {
|
|
|
210
227
|
* Bambu's `model_settings.config`: each object with its name, filament and settings, its parts, and one plate holding
|
|
211
228
|
* every instance.
|
|
212
229
|
*/
|
|
213
|
-
export function buildModelSettings(ini, objects, instanceCounts, parts) {
|
|
230
|
+
export function buildModelSettings(ini, objects, instanceCounts, parts, plateOf = () => 1) {
|
|
214
231
|
const lines = ['<?xml version="1.0" encoding="UTF-8"?>', "<config>"];
|
|
215
|
-
|
|
232
|
+
/** Each plate's `<model_instance>` blocks, by plate number. */
|
|
233
|
+
const plates = new Map();
|
|
216
234
|
for (const object of objects) {
|
|
217
235
|
const filament = objectFilament(object);
|
|
218
236
|
const name = object.name || `Object ${object.id}`;
|
|
@@ -233,11 +251,18 @@ export function buildModelSettings(ini, objects, instanceCounts, parts) {
|
|
|
233
251
|
}
|
|
234
252
|
lines.push(" </object>");
|
|
235
253
|
const count = instanceCounts.get(object.id) ?? 1;
|
|
254
|
+
const instances = plates.get(plateOf(object.id)) ?? [];
|
|
236
255
|
for (let i = 0; i < count; i++) {
|
|
237
256
|
instances.push(" <model_instance>", ` <metadata key="object_id" value="${object.id}"/>`, ` <metadata key="instance_id" value="${i}"/>`, ` <metadata key="identify_id" value="${object.id * 100 + i}"/>`, " </model_instance>");
|
|
238
257
|
}
|
|
258
|
+
plates.set(plateOf(object.id), instances);
|
|
259
|
+
}
|
|
260
|
+
// Plates in order, every number up to the highest used, so a plate's number is its position (as the Bambu family's are).
|
|
261
|
+
const highest = Math.max(1, ...plates.keys());
|
|
262
|
+
for (let plate = 1; plate <= highest; plate++) {
|
|
263
|
+
lines.push(" <plate>", ` <metadata key="plater_id" value="${plate}"/>`, ' <metadata key="plater_name" value=""/>', ' <metadata key="locked" value="false"/>', ...(plates.get(plate) ?? []), " </plate>");
|
|
239
264
|
}
|
|
240
|
-
lines.push("
|
|
265
|
+
lines.push("</config>", "");
|
|
241
266
|
return lines.join("\n");
|
|
242
267
|
}
|
|
243
268
|
export const prusaReader = {
|
|
@@ -291,11 +316,30 @@ export const prusaReader = {
|
|
|
291
316
|
// A wrapper object (an older PrusaSlicer's extra instance) has no config entry of its own: the mesh object's serves.
|
|
292
317
|
const configFor = (id) => byId.get(id) ?? components.get(id)?.map((c) => byId.get(c)).find((o) => o !== undefined);
|
|
293
318
|
const partFileCache = new Map();
|
|
319
|
+
// PrusaSlicer 2.9 can place objects on several beds, virtual copies of the printer's bed on a grid; each becomes a
|
|
320
|
+
// plate. An older project has one bed. An object on no bed (off every one) stays on plate 1, with a warning.
|
|
321
|
+
const version = ini.version ? (/^\d+\.\d+\.\d+/.exec(ini.version)?.[0] ?? null) : null;
|
|
322
|
+
const severalBeds = version !== null && compareVersions(version, "2.9.0") >= 0;
|
|
323
|
+
const bed = severalBeds ? parseBedShape(ini.settings.get("bed_shape")) : null;
|
|
324
|
+
const plateOf = new Map();
|
|
294
325
|
const objects = Object.entries(itemPositions).map(([id, fallbackXy]) => {
|
|
295
326
|
const bbox = objectWorldBboxXY(id, modelText, partFileCache, zipEntries);
|
|
296
327
|
const name = configFor(Number(id))?.name;
|
|
297
|
-
|
|
328
|
+
let plate = 1;
|
|
329
|
+
if (bed) {
|
|
330
|
+
const box = bbox ?? [fallbackXy[0], fallbackXy[0], fallbackXy[1], fallbackXy[1]];
|
|
331
|
+
const index = bedIndexOf(box, bed);
|
|
332
|
+
if (index === null)
|
|
333
|
+
warnings.push(` WARN: "${name ?? id}" sits on none of PrusaSlicer's beds (off every bed); it's put on plate 1.`);
|
|
334
|
+
else
|
|
335
|
+
plate = index + 1;
|
|
336
|
+
}
|
|
337
|
+
plateOf.set(Number(id), plate);
|
|
338
|
+
return { id, ...(name ? { name } : {}), plate, ...(bbox ? { bbox } : { bbox: null, fallbackXy }) };
|
|
298
339
|
});
|
|
340
|
+
const plateCount = new Set(plateOf.values()).size;
|
|
341
|
+
if (plateCount > 1)
|
|
342
|
+
warnings.push(` note: the project's ${plateCount} beds become ${plateCount} plates.`);
|
|
299
343
|
// Objects the model file places, in its order; the per-object config may name objects that aren't placed.
|
|
300
344
|
const placed = objects.map((o) => {
|
|
301
345
|
const config = configFor(Number(o.id));
|
|
@@ -309,7 +353,7 @@ export const prusaReader = {
|
|
|
309
353
|
}
|
|
310
354
|
const model = adaptPrusaModel(modelText);
|
|
311
355
|
entries[TOP_MODEL_PATH] = model.text === topModelText ? topModelBytes : utf8Encoder.encode(model.text);
|
|
312
|
-
entries[MODEL_SETTINGS_PATH] = utf8Encoder.encode(buildModelSettings(ini, placed, instanceCounts, (object) => partsOf(object, components, split.parts)));
|
|
356
|
+
entries[MODEL_SETTINGS_PATH] = utf8Encoder.encode(buildModelSettings(ini, placed, instanceCounts, (object) => partsOf(object, components, split.parts), (id) => plateOf.get(id) ?? 1));
|
|
313
357
|
const customGcodeBytes = zipEntries[PRUSA_CUSTOM_GCODE_PATH];
|
|
314
358
|
if (customGcodeBytes && customGcodeBytes.length <= MAX_AUX_BYTES) {
|
|
315
359
|
const orca = convertCustomGcodes(utf8Decoder.decode(customGcodeBytes));
|
|
@@ -329,8 +373,20 @@ export const prusaReader = {
|
|
|
329
373
|
if (zipEntries[PRUSA_LAYER_RANGES_PATH]) {
|
|
330
374
|
warnings.push(" WARN: this project's layer-range settings (settings for a range of heights of an object) aren't carried yet.");
|
|
331
375
|
}
|
|
376
|
+
const printerNotes = ini.settings.get("printer_notes") ?? "";
|
|
332
377
|
return {
|
|
333
378
|
source: "prusaslicer",
|
|
379
|
+
prusa: {
|
|
380
|
+
version,
|
|
381
|
+
settings: ini.settings,
|
|
382
|
+
targets: converted.targets,
|
|
383
|
+
presets: {
|
|
384
|
+
print: ini.settings.get("print_settings_id") ?? "",
|
|
385
|
+
printer: ini.settings.get("printer_settings_id") ?? "",
|
|
386
|
+
filaments: splitStringList(ini.raw.get("filament_settings_id") ?? ""),
|
|
387
|
+
},
|
|
388
|
+
vendorKeyword: /\bPRINTER_VENDOR_([A-Z0-9]{1,20})\b/.exec(printerNotes)?.[1] ?? null,
|
|
389
|
+
},
|
|
334
390
|
zipEntries: entries,
|
|
335
391
|
request: { projectSettings: converted.settings, objects },
|
|
336
392
|
warnings,
|
package/dist/sources/reader.d.ts
CHANGED
|
@@ -12,9 +12,30 @@
|
|
|
12
12
|
import type { ConvertRequest } from "../schema.js";
|
|
13
13
|
/** The slicer family a project came from. */
|
|
14
14
|
export type SourceFormat = "bambu-family" | "prusaslicer";
|
|
15
|
+
/**
|
|
16
|
+
* What a PrusaSlicer project keeps for the step that needs profile data
|
|
17
|
+
* (`convert()`, once the catalog is loaded): the project's settings in
|
|
18
|
+
* PrusaSlicer's own keys and value forms, which Snapmaker Orca keys each
|
|
19
|
+
* wrote, and the preset names it recorded.
|
|
20
|
+
*/
|
|
21
|
+
export interface PrusaProjectInfo {
|
|
22
|
+
/** The PrusaSlicer version that saved the project ("2.9.6"), from the settings file's first line; null when unreadable. */
|
|
23
|
+
version: string | null;
|
|
24
|
+
settings: ReadonlyMap<string, string>;
|
|
25
|
+
targets: ReadonlyMap<string, readonly string[]>;
|
|
26
|
+
presets: {
|
|
27
|
+
print: string;
|
|
28
|
+
printer: string;
|
|
29
|
+
filaments: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
/** The vendor keyword from `printer_notes` ("PRUSA3D"), when the printer profile names one. */
|
|
32
|
+
vendorKeyword: string | null;
|
|
33
|
+
}
|
|
15
34
|
export interface ParsedProject {
|
|
16
35
|
/** Which reader read the file. */
|
|
17
36
|
source: SourceFormat;
|
|
37
|
+
/** Present for a PrusaSlicer project. */
|
|
38
|
+
prusa?: PrusaProjectInfo;
|
|
18
39
|
/** The full decompressed source zip, kept for applyConvertResponse's final reassembly. */
|
|
19
40
|
zipEntries: Record<string, Uint8Array>;
|
|
20
41
|
/** The conversion request payload. */
|
package/dist/stamp.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare const OutputStampSchema: z.ZodObject<{
|
|
|
24
24
|
profileId: z.ZodString;
|
|
25
25
|
source: z.ZodOptional<z.ZodObject<{
|
|
26
26
|
format: z.ZodEnum<{
|
|
27
|
-
"bambu-family": "bambu-family";
|
|
28
27
|
prusaslicer: "prusaslicer";
|
|
28
|
+
"bambu-family": "bambu-family";
|
|
29
29
|
}>;
|
|
30
30
|
slicerVersion: z.ZodOptional<z.ZodString>;
|
|
31
31
|
}, z.core.$strict>>;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.7.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "any2orca",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"outputAffecting": "
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"outputAffecting": "a PrusaSlicer conversion carries only the print settings the creator changed; converted PrusaSlicer files change, Bambu-family files don't",
|
|
5
5
|
"description": "Convert Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer and Flash Studio 3MF projects for the Snapmaker U1 (Snapmaker Orca), entirely on your own machine. Library, CLI and Web Worker in one package.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"3mf",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"docs": "typedoc"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"any2orca-profiles": "0.
|
|
68
|
+
"any2orca-profiles": "0.3.0",
|
|
69
69
|
"fflate": "0.8.3",
|
|
70
70
|
"zod": "4.6.7"
|
|
71
71
|
},
|