any2orca 0.4.1 → 0.6.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 +17 -0
- package/README.md +1 -1
- package/dist/archive/objectWorldBboxXY.js +3 -2
- package/dist/archive/zip.d.ts +10 -13
- package/dist/archive/zip.js +17 -75
- package/dist/inspect.d.ts +1 -7
- package/dist/inspect.js +9 -3
- package/dist/project.js +4 -0
- package/dist/sources/bambuFamily.d.ts +2 -0
- package/dist/sources/bambuFamily.js +82 -0
- package/dist/sources/index.d.ts +6 -0
- package/dist/sources/index.js +9 -0
- package/dist/sources/prusa/convertSettings.d.ts +20 -0
- package/dist/sources/prusa/convertSettings.js +325 -0
- package/dist/sources/prusa/ini.d.ts +41 -0
- package/dist/sources/prusa/ini.js +106 -0
- package/dist/sources/prusa/keyMap.d.ts +56 -0
- package/dist/sources/prusa/keyMap.js +483 -0
- package/dist/sources/prusa/modelConfig.d.ts +50 -0
- package/dist/sources/prusa/modelConfig.js +83 -0
- package/dist/sources/prusa/prusa.d.ts +59 -0
- package/dist/sources/prusa/prusa.js +340 -0
- package/dist/sources/prusa/splitParts.d.ts +25 -0
- package/dist/sources/prusa/splitParts.js +77 -0
- package/dist/sources/reader.d.ts +42 -0
- package/dist/sources/reader.js +1 -0
- package/dist/stamp.d.ts +7 -0
- package/dist/stamp.js +12 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Applies the key map to a PrusaSlicer project's settings, giving the settings
|
|
4
|
+
* in Snapmaker Orca's keys and value shapes: a single value is a string, a
|
|
5
|
+
* per-filament or per-extruder value is an array of strings, as the Bambu
|
|
6
|
+
* Studio family writes `project_settings.config`. Everything the pipeline does
|
|
7
|
+
* after this (the U1 profile, the filament slots, the machine limits) is the
|
|
8
|
+
* same as for a Bambu-family project.
|
|
9
|
+
*
|
|
10
|
+
* The policy is "transfer everything mapped": PrusaSlicer records no list of
|
|
11
|
+
* what the creator changed, so every mapped print setting is marked as
|
|
12
|
+
* changed, and the pipeline's own rules decide what the U1 keeps.
|
|
13
|
+
*/
|
|
14
|
+
import { SETTINGS_CATALOG } from "../../diff/settingsCatalog.js";
|
|
15
|
+
import { splitNumberList, splitStringList } from "./ini.js";
|
|
16
|
+
import { PRUSA_KEY_MAP } from "./keyMap.js";
|
|
17
|
+
/** Keys a project carries that aren't in a preset, so the catalog doesn't list them; whether each is a list. */
|
|
18
|
+
const PROJECT_STATE_VECTORS = {
|
|
19
|
+
print_settings_id: false,
|
|
20
|
+
printer_settings_id: false,
|
|
21
|
+
filament_settings_id: true,
|
|
22
|
+
wipe_tower_x: true,
|
|
23
|
+
wipe_tower_y: true,
|
|
24
|
+
flush_volumes_matrix: true,
|
|
25
|
+
filament_load_time: true,
|
|
26
|
+
filament_unload_time: true,
|
|
27
|
+
filament_z_hop_types: true,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Whether the key is written as a list: a filament or machine setting Snapmaker Orca keeps per filament or per
|
|
31
|
+
* extruder. A print setting is written as one value, as the Bambu Studio family writes it, even where Snapmaker
|
|
32
|
+
* Orca's U1 profile keeps a pair (one per hotend type): the pipeline spreads one value over the pair.
|
|
33
|
+
*/
|
|
34
|
+
function isVector(key) {
|
|
35
|
+
const info = SETTINGS_CATALOG[key];
|
|
36
|
+
if (info?.type)
|
|
37
|
+
return info.type.endsWith("s") && info.group !== "print";
|
|
38
|
+
return PROJECT_STATE_VECTORS[key] ?? false;
|
|
39
|
+
}
|
|
40
|
+
function valueShape(target) {
|
|
41
|
+
const type = SETTINGS_CATALOG[target]?.type;
|
|
42
|
+
if (type === "coStrings" || target === "filament_settings_id")
|
|
43
|
+
return "strings";
|
|
44
|
+
// One text, commas and all: a note, a preset name, a choice.
|
|
45
|
+
if (type === "coString" || type === "coEnum" || (type === undefined && PROJECT_STATE_VECTORS[target] === false))
|
|
46
|
+
return "text";
|
|
47
|
+
return "numbers";
|
|
48
|
+
}
|
|
49
|
+
const isPercent = (v) => v.trim().endsWith("%");
|
|
50
|
+
const num = (v) => Number.parseFloat(v);
|
|
51
|
+
/** A number as Snapmaker Orca writes one: up to four decimals, no trailing zeros. */
|
|
52
|
+
function fmt(n) {
|
|
53
|
+
return Number.isFinite(n) ? String(Number(n.toFixed(4))) : "0";
|
|
54
|
+
}
|
|
55
|
+
/** The value as a list, split the way PrusaSlicer joined it for what the target keeps. */
|
|
56
|
+
function entries(ini, key, target) {
|
|
57
|
+
const raw = ini.raw.get(key);
|
|
58
|
+
const value = ini.settings.get(key);
|
|
59
|
+
if (raw === undefined || value === undefined)
|
|
60
|
+
return [];
|
|
61
|
+
switch (valueShape(target)) {
|
|
62
|
+
case "strings":
|
|
63
|
+
return splitStringList(raw);
|
|
64
|
+
case "text":
|
|
65
|
+
return [value];
|
|
66
|
+
default:
|
|
67
|
+
return splitNumberList(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** The first entry of a value PrusaSlicer may keep per extruder. */
|
|
71
|
+
function first(ini, key) {
|
|
72
|
+
const value = ini.settings.get(key);
|
|
73
|
+
if (value === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
return splitNumberList(value)[0];
|
|
76
|
+
}
|
|
77
|
+
/** `value` resolved against `base` when it's a percentage, else as is. */
|
|
78
|
+
function percentOf(value, base) {
|
|
79
|
+
if (!isPercent(value))
|
|
80
|
+
return value;
|
|
81
|
+
if (base === undefined || !Number.isFinite(base))
|
|
82
|
+
return null;
|
|
83
|
+
return fmt((num(value) / 100) * base);
|
|
84
|
+
}
|
|
85
|
+
/** A PrusaSlicer speed resolved to a number, following its percent-of chain. */
|
|
86
|
+
function resolvedSpeed(ini, key) {
|
|
87
|
+
const value = first(ini, key);
|
|
88
|
+
if (value === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
if (!isPercent(value))
|
|
91
|
+
return num(value);
|
|
92
|
+
const base = {
|
|
93
|
+
external_perimeter_speed: "perimeter_speed",
|
|
94
|
+
solid_infill_speed: "infill_speed",
|
|
95
|
+
top_solid_infill_speed: "solid_infill_speed",
|
|
96
|
+
support_material_interface_speed: "support_material_speed",
|
|
97
|
+
first_layer_speed: "perimeter_speed",
|
|
98
|
+
first_layer_infill_speed: "first_layer_speed",
|
|
99
|
+
};
|
|
100
|
+
const baseKey = base[key];
|
|
101
|
+
if (!baseKey)
|
|
102
|
+
return undefined;
|
|
103
|
+
const baseValue = resolvedSpeed(ini, baseKey);
|
|
104
|
+
return baseValue === undefined ? undefined : (num(value) / 100) * baseValue;
|
|
105
|
+
}
|
|
106
|
+
const percentOfSpeed = (baseKey) => ({ ini, key, value, warnings }) => {
|
|
107
|
+
if (!isPercent(value))
|
|
108
|
+
return [value];
|
|
109
|
+
const resolved = resolvedSpeed(ini, key);
|
|
110
|
+
if (resolved === undefined) {
|
|
111
|
+
warnings.push(` WARN: ${key} is ${value} of ${baseKey}, which isn't a number this project can resolve, so Snapmaker's stock value is used.`);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return [fmt(resolved)];
|
|
115
|
+
};
|
|
116
|
+
const TRANSFORMS = {
|
|
117
|
+
arcFitting: ({ value }) => [value === "disabled" ? "0" : "1"],
|
|
118
|
+
filamentColour: ({ ini, warnings }) => {
|
|
119
|
+
const colors = entries(ini, "filament_colour", "filament_colour");
|
|
120
|
+
const extruderColors = entries(ini, "extruder_colour", "extruder_colour");
|
|
121
|
+
let fromExtruders = 0;
|
|
122
|
+
const out = colors.map((color, i) => {
|
|
123
|
+
const extruder = extruderColors[i] ?? "";
|
|
124
|
+
if (/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(extruder) && extruder.toUpperCase() !== color.toUpperCase()) {
|
|
125
|
+
fromExtruders++;
|
|
126
|
+
return extruder;
|
|
127
|
+
}
|
|
128
|
+
return color;
|
|
129
|
+
});
|
|
130
|
+
if (fromExtruders > 0)
|
|
131
|
+
warnings.push(` note: ${fromExtruders} filament color(s) taken from the printer's extruder colors, which are what PrusaSlicer shows for this project.`);
|
|
132
|
+
return out;
|
|
133
|
+
},
|
|
134
|
+
filamentZHopTypes: ({ ini, key }) => entries(ini, key, "filament_z_hop_types").map((entry) => (entry === "nil" ? "nil" : entry === "1" ? "Slope Lift" : "Normal Lift")),
|
|
135
|
+
filamentType: ({ ini }) => entries(ini, "filament_type", "filament_type").map((type) => ({ PET: "PETG", NYLON: "PA" })[type] ?? type),
|
|
136
|
+
firstLayerHeight: ({ ini, value }) => {
|
|
137
|
+
const layer = ini.settings.get("layer_height");
|
|
138
|
+
const resolved = percentOf(value, layer === undefined ? undefined : num(layer));
|
|
139
|
+
return resolved === null ? null : [resolved];
|
|
140
|
+
},
|
|
141
|
+
gapFillTarget: ({ value }) => [value === "0" ? "nowhere" : "everywhere"],
|
|
142
|
+
infillCombination: ({ ini }) => [ini.settings.get("automatic_infill_combination") === "1" || num(ini.settings.get("infill_every_layers") ?? "1") > 1 ? "1" : "0"],
|
|
143
|
+
invertBool: ({ value }) => [value === "1" ? "0" : "1"],
|
|
144
|
+
ironingType: ({ ini, value }) => [ini.settings.get("ironing") === "1" ? value : "no ironing"],
|
|
145
|
+
onlyOneWallTop: ({ value }) => [value === "none" ? "0" : "1"],
|
|
146
|
+
percentComplement: ({ ini, key }) => entries(ini, key, "filament_shrink").map((entry) => `${fmt(100 - num(entry))}%`),
|
|
147
|
+
percentOfFirstLayerSpeed: percentOfSpeed("first_layer_speed"),
|
|
148
|
+
percentOfInfillSpeed: percentOfSpeed("infill_speed"),
|
|
149
|
+
percentOfPerimeterSpeed: percentOfSpeed("perimeter_speed"),
|
|
150
|
+
percentOfSolidInfillSpeed: percentOfSpeed("solid_infill_speed"),
|
|
151
|
+
percentOfSupportSpeed: percentOfSpeed("support_material_speed"),
|
|
152
|
+
percentOnly: ({ key, value, warnings }) => {
|
|
153
|
+
if (isPercent(value))
|
|
154
|
+
return [value];
|
|
155
|
+
warnings.push(` WARN: ${key} is ${value} mm, and Snapmaker Orca keeps it as a percentage of the line width, so Snapmaker's stock value is used.`);
|
|
156
|
+
return null;
|
|
157
|
+
},
|
|
158
|
+
printSequence: ({ value }) => [value === "1" ? "by object" : "by layer"],
|
|
159
|
+
// PrusaSlicer's "a solid layer every N layers" is Orca's "insert solid layers: N"; 0 is off, so nothing to carry.
|
|
160
|
+
solidEveryLayers: ({ value }) => (num(value) > 0 ? [String(Math.trunc(num(value)))] : null),
|
|
161
|
+
supportBottomZ: ({ ini, value }) => [value === "0" ? (ini.settings.get("support_material_contact_distance") ?? value) : value],
|
|
162
|
+
supportThreshold: ({ key, value, dropped }) => {
|
|
163
|
+
if (value !== "0")
|
|
164
|
+
return [value];
|
|
165
|
+
dropped.push({ key, why: "automatic overhang detection has no Snapmaker Orca counterpart" });
|
|
166
|
+
return null;
|
|
167
|
+
},
|
|
168
|
+
supportType: ({ ini, value }) => {
|
|
169
|
+
const tree = ini.settings.get("support_material_style") === "organic";
|
|
170
|
+
return [`${tree ? "tree" : "normal"}(${value === "1" ? "auto" : "manual"})`];
|
|
171
|
+
},
|
|
172
|
+
supportXySpacing: ({ ini, value, warnings }) => {
|
|
173
|
+
if (!isPercent(value))
|
|
174
|
+
return [value];
|
|
175
|
+
const width = ["external_perimeter_extrusion_width", "extrusion_width", "nozzle_diameter"].map((k) => num(first(ini, k) ?? "")).find((n) => n > 0);
|
|
176
|
+
if (width === undefined) {
|
|
177
|
+
warnings.push(` WARN: support_material_xy_spacing is ${value} of a line width this project doesn't give, so Snapmaker's stock value is used.`);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return [fmt((num(value) / 100) * width)];
|
|
181
|
+
},
|
|
182
|
+
// Only the clockwise choice is a change from Orca's automatic direction.
|
|
183
|
+
wallDirection: ({ value }) => (value === "1" ? ["cw"] : null),
|
|
184
|
+
wallSequence: ({ value }) => [value === "1" ? "outer wall/inner wall" : "inner wall/outer wall"],
|
|
185
|
+
zHopTypes: ({ ini, key }) => entries(ini, key, "z_hop_types").map((entry) => (entry === "1" ? "Slope Lift" : "Normal Lift")),
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* The value shaped for `target`: a list for a per-filament or per-extruder key; otherwise one value, or the list
|
|
189
|
+
* when PrusaSlicer kept several that differ (the pipeline picks or warns, as it does for a Bambu-family project).
|
|
190
|
+
*/
|
|
191
|
+
function shaped(target, list) {
|
|
192
|
+
if (list.length === 0)
|
|
193
|
+
return null;
|
|
194
|
+
if (isVector(target))
|
|
195
|
+
return list;
|
|
196
|
+
return list.every((entry) => entry === list[0]) ? list[0] : list;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* An object's or a volume's own settings (PrusaSlicer keys, from the model config) in Snapmaker Orca's keys, one
|
|
200
|
+
* value each, for `model_settings.config`. A transform that reads other settings sees the project's, with the
|
|
201
|
+
* object's own over them. Keys with no single-value counterpart (filament settings, dropped keys) aren't carried.
|
|
202
|
+
*/
|
|
203
|
+
export function convertObjectOverrides(ini, overrides) {
|
|
204
|
+
const merged = { ...ini, settings: new Map([...ini.settings, ...overrides]), raw: new Map([...ini.raw, ...overrides]) };
|
|
205
|
+
const out = {};
|
|
206
|
+
const warnings = [];
|
|
207
|
+
const dropped = [];
|
|
208
|
+
for (const [key, value] of overrides) {
|
|
209
|
+
const rule = PRUSA_KEY_MAP[key];
|
|
210
|
+
if (!rule)
|
|
211
|
+
continue;
|
|
212
|
+
const put = (target, list) => {
|
|
213
|
+
if (!list || list.length === 0 || SETTINGS_CATALOG[target]?.group === "filament")
|
|
214
|
+
return;
|
|
215
|
+
out[target] = list[0];
|
|
216
|
+
};
|
|
217
|
+
switch (rule.kind) {
|
|
218
|
+
case "same":
|
|
219
|
+
put(key, [value]);
|
|
220
|
+
break;
|
|
221
|
+
case "rename":
|
|
222
|
+
for (const target of typeof rule.to === "string" ? [rule.to] : rule.to)
|
|
223
|
+
put(target, [value]);
|
|
224
|
+
break;
|
|
225
|
+
case "choices":
|
|
226
|
+
if (rule.values[value] !== undefined)
|
|
227
|
+
put(rule.to, [rule.values[value]]);
|
|
228
|
+
break;
|
|
229
|
+
case "transform": {
|
|
230
|
+
const list = TRANSFORMS[rule.via]({ ini: merged, key, value, warnings, dropped });
|
|
231
|
+
for (const target of typeof rule.to === "string" ? [rule.to] : rule.to)
|
|
232
|
+
put(target, list);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
default:
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
export function convertPrusaSettings(ini) {
|
|
242
|
+
const settings = {};
|
|
243
|
+
const dropped = [];
|
|
244
|
+
const unknown = [];
|
|
245
|
+
const warnings = [];
|
|
246
|
+
const write = (target, list) => {
|
|
247
|
+
// Every entry `nil` is PrusaSlicer's "not set" (a filament override left to the printer): nothing to carry.
|
|
248
|
+
if (list.every((entry) => entry === "nil"))
|
|
249
|
+
return;
|
|
250
|
+
// A value under Snapmaker Orca's minimum: PrusaSlicer's 0 for "automatic" on a speed it requires to be 1 or
|
|
251
|
+
// more, say. Snapmaker Orca refuses the whole file for it, so the stock value stands.
|
|
252
|
+
const min = SETTINGS_CATALOG[target]?.min;
|
|
253
|
+
if (min !== null && min !== undefined && list.some((entry) => /^-?\d+(\.\d+)?$/.test(entry) && Number(entry) < min)) {
|
|
254
|
+
dropped.push({ key: target, why: `${list.join(",")} is below Snapmaker Orca's minimum of ${min}` });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const value = shaped(target, list);
|
|
258
|
+
if (value !== null)
|
|
259
|
+
settings[target] = value;
|
|
260
|
+
};
|
|
261
|
+
for (const [key, value] of ini.settings) {
|
|
262
|
+
const rule = PRUSA_KEY_MAP[key];
|
|
263
|
+
if (!rule) {
|
|
264
|
+
unknown.push(key);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
switch (rule.kind) {
|
|
268
|
+
case "same":
|
|
269
|
+
write(key, entries(ini, key, key));
|
|
270
|
+
break;
|
|
271
|
+
case "rename":
|
|
272
|
+
for (const target of typeof rule.to === "string" ? [rule.to] : rule.to)
|
|
273
|
+
write(target, entries(ini, key, target));
|
|
274
|
+
break;
|
|
275
|
+
case "choices": {
|
|
276
|
+
const mapped = rule.values[value];
|
|
277
|
+
if (mapped === undefined) {
|
|
278
|
+
warnings.push(` WARN: ${key} "${value.slice(0, 40)}" has no Snapmaker Orca counterpart, so Snapmaker's stock value is used.`);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
write(rule.to, [mapped]);
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "transform": {
|
|
286
|
+
const list = TRANSFORMS[rule.via]({ ini, key, value, warnings, dropped });
|
|
287
|
+
if (list)
|
|
288
|
+
for (const target of typeof rule.to === "string" ? [rule.to] : rule.to)
|
|
289
|
+
write(target, list);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case "drop":
|
|
293
|
+
dropped.push({ key, why: rule.why });
|
|
294
|
+
break;
|
|
295
|
+
case "machine":
|
|
296
|
+
case "handled":
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (ini.version)
|
|
301
|
+
settings.version = ini.version;
|
|
302
|
+
const filamentCount = Array.isArray(settings.filament_colour) ? settings.filament_colour.length : 1;
|
|
303
|
+
// A filament setting PrusaSlicer keeps once for every filament (its vendor, say) is one value per filament in
|
|
304
|
+
// Snapmaker Orca; the pipeline takes a short list as missing values, so it's spread here.
|
|
305
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
306
|
+
if (SETTINGS_CATALOG[key]?.group === "filament" && Array.isArray(value) && value.length === 1 && filamentCount > 1) {
|
|
307
|
+
settings[key] = Array.from({ length: filamentCount }, () => value[0]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Snapmaker Orca sizes its purge structures by these two arrays and refuses a file whose matrix doesn't fit the
|
|
311
|
+
// filament count. PrusaSlicer has the matrix (n x n) but no vector (2n); the pipeline sizes both from the source's,
|
|
312
|
+
// so the vector is given here. The U1 purges by its own minimum, so only the sizes matter.
|
|
313
|
+
if (!Array.isArray(settings.flush_volumes_matrix))
|
|
314
|
+
settings.flush_volumes_matrix = Array.from({ length: filamentCount * filamentCount }, () => "0");
|
|
315
|
+
settings.flush_volumes_vector = Array.from({ length: filamentCount * 2 }, () => "140");
|
|
316
|
+
// Policy: every mapped print setting counts as changed by the creator, so the print entry lists them all. The
|
|
317
|
+
// filament entries (one per filament) and the printer entry stay empty: the pipeline overlays filament values whole,
|
|
318
|
+
// and the printer's settings (retraction, purge moves, limits) are the U1's own, as they are for a Bambu-family
|
|
319
|
+
// project, whose list never names them either. Snapmaker Orca itself takes them from its printer preset on load.
|
|
320
|
+
const printKeys = Object.keys(settings)
|
|
321
|
+
.filter((k) => SETTINGS_CATALOG[k]?.group === "print")
|
|
322
|
+
.sort();
|
|
323
|
+
settings.different_settings_to_system = [printKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), ""];
|
|
324
|
+
return { settings, dropped, unknown, warnings };
|
|
325
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads `Metadata/Slic3r_PE.config`, where PrusaSlicer and the slicers built
|
|
3
|
+
* on it keep a project's print, filament and printer settings: one key per
|
|
4
|
+
* line in G-code-comment form, `; key = value`, after a first line naming
|
|
5
|
+
* the slicer (`; generated by PrusaSlicer 2.9.6 on 2026-10-31 at 07:34:25 UTC`).
|
|
6
|
+
*
|
|
7
|
+
* Values are kept as strings, unescaped the way PrusaSlicer's own reader
|
|
8
|
+
* does it: every value may hold C-style escapes (`\n` in a G-code block,
|
|
9
|
+
* `\"` and `\\`), and a value that needed it was written in double quotes.
|
|
10
|
+
* A list of numbers (one per extruder) is joined with commas; a list of
|
|
11
|
+
* strings (preset names, colors) with semicolons, each element quoted when it
|
|
12
|
+
* needs to be. The key map knows which keys are lists of which kind.
|
|
13
|
+
*
|
|
14
|
+
* The file is untrusted: lines are capped, a repeated key keeps its last
|
|
15
|
+
* value (as PrusaSlicer does), and anything that isn't `; key = value` is
|
|
16
|
+
* ignored rather than refused.
|
|
17
|
+
*/
|
|
18
|
+
export interface PrusaIni {
|
|
19
|
+
/** The slicer named on the first line, e.g. "PrusaSlicer", or null when the line doesn't say. */
|
|
20
|
+
slicer: string | null;
|
|
21
|
+
/** Its version as written, e.g. "2.9.6" or "2.7.0+win64", or null. */
|
|
22
|
+
version: string | null;
|
|
23
|
+
/** Every `; key = value` line, unescaped, last value wins. */
|
|
24
|
+
settings: Map<string, string>;
|
|
25
|
+
/** The same values as written, for `splitStringList`. */
|
|
26
|
+
raw: Map<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export declare function parsePrusaIni(text: string): PrusaIni;
|
|
29
|
+
/**
|
|
30
|
+
* One value as PrusaSlicer wrote it: C-style escapes undone (`\n`, `\r`, `\"`, `\\`), and surrounding double
|
|
31
|
+
* quotes, if any, removed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function unescapeValue(value: string): string;
|
|
34
|
+
/** A list of numbers, one per extruder: PrusaSlicer joins them with commas. */
|
|
35
|
+
export declare function splitNumberList(value: string): string[];
|
|
36
|
+
/**
|
|
37
|
+
* A list of strings, one per extruder (preset names, colors, G-code blocks): PrusaSlicer joins them with
|
|
38
|
+
* semicolons and quotes any element that holds a semicolon, a quote, a backslash or a newline. The raw value
|
|
39
|
+
* must be split before unescaping, so pass the line's value, not `settings.get()`'s unescaped one.
|
|
40
|
+
*/
|
|
41
|
+
export declare function splitStringList(raw: string): string[];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Reads `Metadata/Slic3r_PE.config`, where PrusaSlicer and the slicers built
|
|
4
|
+
* on it keep a project's print, filament and printer settings: one key per
|
|
5
|
+
* line in G-code-comment form, `; key = value`, after a first line naming
|
|
6
|
+
* the slicer (`; generated by PrusaSlicer 2.9.6 on 2026-10-31 at 07:34:25 UTC`).
|
|
7
|
+
*
|
|
8
|
+
* Values are kept as strings, unescaped the way PrusaSlicer's own reader
|
|
9
|
+
* does it: every value may hold C-style escapes (`\n` in a G-code block,
|
|
10
|
+
* `\"` and `\\`), and a value that needed it was written in double quotes.
|
|
11
|
+
* A list of numbers (one per extruder) is joined with commas; a list of
|
|
12
|
+
* strings (preset names, colors) with semicolons, each element quoted when it
|
|
13
|
+
* needs to be. The key map knows which keys are lists of which kind.
|
|
14
|
+
*
|
|
15
|
+
* The file is untrusted: lines are capped, a repeated key keeps its last
|
|
16
|
+
* value (as PrusaSlicer does), and anything that isn't `; key = value` is
|
|
17
|
+
* ignored rather than refused.
|
|
18
|
+
*/
|
|
19
|
+
/** The most lines read; a real config has a few hundred. */
|
|
20
|
+
const MAX_LINES = 5000;
|
|
21
|
+
/** A key is a plain identifier; anything else isn't a setting line. */
|
|
22
|
+
const KEY = /^[a-z][a-z0-9_]{0,99}$/;
|
|
23
|
+
const GENERATED_BY = /^; generated by ([A-Za-z][A-Za-z0-9]{1,30}(?: [A-Za-z][A-Za-z0-9]{1,30})?) v?(\d[\w.+-]{0,40})/;
|
|
24
|
+
export function parsePrusaIni(text) {
|
|
25
|
+
const settings = new Map();
|
|
26
|
+
const raw = new Map();
|
|
27
|
+
let slicer = null;
|
|
28
|
+
let version = null;
|
|
29
|
+
const lines = text.split(/\r?\n/, MAX_LINES);
|
|
30
|
+
const first = GENERATED_BY.exec(lines[0] ?? "");
|
|
31
|
+
if (first) {
|
|
32
|
+
slicer = first[1];
|
|
33
|
+
version = first[2];
|
|
34
|
+
}
|
|
35
|
+
for (const line of lines) {
|
|
36
|
+
if (!line.startsWith("; "))
|
|
37
|
+
continue;
|
|
38
|
+
const eq = line.indexOf(" = ");
|
|
39
|
+
if (eq < 0)
|
|
40
|
+
continue;
|
|
41
|
+
const key = line.slice(2, eq);
|
|
42
|
+
if (!KEY.test(key))
|
|
43
|
+
continue;
|
|
44
|
+
raw.set(key, line.slice(eq + 3));
|
|
45
|
+
settings.set(key, unescapeValue(line.slice(eq + 3)));
|
|
46
|
+
}
|
|
47
|
+
return { slicer, version, settings, raw };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One value as PrusaSlicer wrote it: C-style escapes undone (`\n`, `\r`, `\"`, `\\`), and surrounding double
|
|
51
|
+
* quotes, if any, removed.
|
|
52
|
+
*/
|
|
53
|
+
export function unescapeValue(value) {
|
|
54
|
+
const inner = value.length >= 2 && value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
|
|
55
|
+
let out = "";
|
|
56
|
+
for (let i = 0; i < inner.length; i++) {
|
|
57
|
+
const c = inner[i];
|
|
58
|
+
if (c !== "\\" || i === inner.length - 1) {
|
|
59
|
+
out += c;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const next = inner[++i];
|
|
63
|
+
out += next === "n" ? "\n" : next === "r" ? "\r" : next;
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** A list of numbers, one per extruder: PrusaSlicer joins them with commas. */
|
|
68
|
+
export function splitNumberList(value) {
|
|
69
|
+
return value.split(",");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A list of strings, one per extruder (preset names, colors, G-code blocks): PrusaSlicer joins them with
|
|
73
|
+
* semicolons and quotes any element that holds a semicolon, a quote, a backslash or a newline. The raw value
|
|
74
|
+
* must be split before unescaping, so pass the line's value, not `settings.get()`'s unescaped one.
|
|
75
|
+
*/
|
|
76
|
+
export function splitStringList(raw) {
|
|
77
|
+
const out = [];
|
|
78
|
+
let current = "";
|
|
79
|
+
let quoted = false;
|
|
80
|
+
for (let i = 0; i < raw.length; i++) {
|
|
81
|
+
const c = raw[i];
|
|
82
|
+
if (quoted) {
|
|
83
|
+
if (c === "\\" && i < raw.length - 1) {
|
|
84
|
+
current += c + raw[++i];
|
|
85
|
+
}
|
|
86
|
+
else if (c === '"') {
|
|
87
|
+
quoted = false;
|
|
88
|
+
current += c;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
current += c;
|
|
92
|
+
}
|
|
93
|
+
else if (c === '"') {
|
|
94
|
+
quoted = true;
|
|
95
|
+
current += c;
|
|
96
|
+
}
|
|
97
|
+
else if (c === ";") {
|
|
98
|
+
out.push(current);
|
|
99
|
+
current = "";
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
current += c;
|
|
103
|
+
}
|
|
104
|
+
out.push(current);
|
|
105
|
+
return out.map(unescapeValue);
|
|
106
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How each PrusaSlicer setting key becomes a Snapmaker Orca one. The table is
|
|
3
|
+
* the decision record: every key a PrusaSlicer project can carry has a rule,
|
|
4
|
+
* and a key without one is a failing test, not a silent passthrough (see
|
|
5
|
+
* keyMap.test.ts, which also checks every target against the settings
|
|
6
|
+
* catalog). The rules are written as pairs so the other direction can reuse
|
|
7
|
+
* the table later.
|
|
8
|
+
*
|
|
9
|
+
* Both slicers descend from Slic3r, so about a third of the keys share a name
|
|
10
|
+
* and a value form. The rest were renamed when Bambu Studio took the Slic3r
|
|
11
|
+
* settings over ("perimeters" became "wall_loops"), changed their value set,
|
|
12
|
+
* or exist on one side only.
|
|
13
|
+
*
|
|
14
|
+
* - `same`: the same key and value form on both sides.
|
|
15
|
+
* - `rename`: a different key, the same value form; `to` may name several
|
|
16
|
+
* keys when Snapmaker Orca keeps one PrusaSlicer value in several places
|
|
17
|
+
* (the bed temperature, which Orca keeps per plate type).
|
|
18
|
+
* - `choices`: a renamed key with a fixed set of values, each mapped; a value
|
|
19
|
+
* not in the map isn't carried, with a warning.
|
|
20
|
+
* - `transform`: a value that needs computing (a percentage resolved to a
|
|
21
|
+
* number, a flag folded into a mode), by name; the code is in
|
|
22
|
+
* convertSettings.ts.
|
|
23
|
+
* - `drop`: no counterpart; reported, so the creator's settings that can't
|
|
24
|
+
* be carried are named.
|
|
25
|
+
* - `machine`: the printer's own (bed shape, G-code, motion limits, host):
|
|
26
|
+
* the U1 profile's values stand, so it's left behind without a report.
|
|
27
|
+
* - `handled`: read by another part of the reader (the color changes, the
|
|
28
|
+
* filament colors), not by the settings map.
|
|
29
|
+
*/
|
|
30
|
+
export type PrusaTransform = "arcFitting" | "filamentColour" | "filamentZHopTypes" | "filamentType" | "firstLayerHeight" | "gapFillTarget" | "infillCombination" | "invertBool" | "ironingType" | "onlyOneWallTop" | "percentComplement" | "percentOfFirstLayerSpeed" | "percentOfInfillSpeed" | "percentOfPerimeterSpeed" | "percentOfSolidInfillSpeed" | "percentOfSupportSpeed" | "percentOnly" | "printSequence" | "solidEveryLayers" | "supportBottomZ" | "supportThreshold" | "supportType" | "supportXySpacing" | "wallDirection" | "wallSequence" | "zHopTypes";
|
|
31
|
+
export type PrusaKeyRule = {
|
|
32
|
+
readonly kind: "same";
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "rename";
|
|
35
|
+
readonly to: string | readonly string[];
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: "choices";
|
|
38
|
+
readonly to: string;
|
|
39
|
+
readonly values: Readonly<Record<string, string>>;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "transform";
|
|
42
|
+
readonly to: string | readonly string[];
|
|
43
|
+
readonly via: PrusaTransform;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "drop";
|
|
46
|
+
readonly why: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "machine";
|
|
49
|
+
} | {
|
|
50
|
+
readonly kind: "handled";
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Every key, in PrusaSlicer's own groups: print, filament, printer, then the
|
|
54
|
+
* keys only older PrusaSlicer versions wrote.
|
|
55
|
+
*/
|
|
56
|
+
export declare const PRUSA_KEY_MAP: Readonly<Record<string, PrusaKeyRule>>;
|