any2orca 0.0.1 → 0.1.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 +70 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +96 -3
- package/dist/archive/adaptModelSettings.d.ts +1 -0
- package/dist/archive/adaptModelSettings.js +50 -0
- package/dist/archive/filamentColorNames.d.ts +8 -0
- package/dist/archive/filamentColorNames.js +760 -0
- package/dist/archive/fmtNum.d.ts +14 -0
- package/dist/archive/fmtNum.js +21 -0
- package/dist/archive/internal/escapeRegExp.d.ts +2 -0
- package/dist/archive/internal/escapeRegExp.js +5 -0
- package/dist/archive/lookupFilamentColorName.d.ts +45 -0
- package/dist/archive/lookupFilamentColorName.js +57 -0
- package/dist/archive/objectWorldBboxXY.d.ts +2 -0
- package/dist/archive/objectWorldBboxXY.js +123 -0
- package/dist/archive/parseItemPositions.d.ts +6 -0
- package/dist/archive/parseItemPositions.js +17 -0
- package/dist/archive/parseObjectMetadata.d.ts +10 -0
- package/dist/archive/parseObjectMetadata.js +97 -0
- package/dist/archive/parsePlateAssignments.d.ts +6 -0
- package/dist/archive/parsePlateAssignments.js +18 -0
- package/dist/archive/parseVertices.d.ts +7 -0
- package/dist/archive/parseVertices.js +12 -0
- package/dist/archive/paths.d.ts +5 -0
- package/dist/archive/paths.js +6 -0
- package/dist/archive/recenterAssembleItems.d.ts +9 -0
- package/dist/archive/recenterAssembleItems.js +53 -0
- package/dist/archive/recenterBuildItems.d.ts +15 -0
- package/dist/archive/recenterBuildItems.js +51 -0
- package/dist/archive/safeUnzip.d.ts +26 -0
- package/dist/archive/safeUnzip.js +126 -0
- package/dist/archive/setApplicationMetadata.d.ts +13 -0
- package/dist/archive/setApplicationMetadata.js +18 -0
- package/dist/archive/shouldDropFromBambu.d.ts +29 -0
- package/dist/archive/shouldDropFromBambu.js +39 -0
- package/dist/archive/streamObjectVertices.d.ts +19 -0
- package/dist/archive/streamObjectVertices.js +57 -0
- package/dist/archive/tolerantJsonParse.d.ts +20 -0
- package/dist/archive/tolerantJsonParse.js +71 -0
- package/dist/archive/transform.d.ts +21 -0
- package/dist/archive/transform.js +39 -0
- package/dist/archive/unwrapBundle.d.ts +24 -0
- package/dist/archive/unwrapBundle.js +41 -0
- package/dist/archive/xmlBlocks.d.ts +10 -0
- package/dist/archive/xmlBlocks.js +31 -0
- package/dist/archive/zip.d.ts +29 -0
- package/dist/archive/zip.js +141 -0
- package/dist/cli/archiveMove.d.ts +15 -0
- package/dist/cli/archiveMove.js +41 -0
- package/dist/cli/commands/convert.d.ts +89 -0
- package/dist/cli/commands/convert.js +311 -0
- package/dist/cli/commands/diff.d.ts +21 -0
- package/dist/cli/commands/diff.js +112 -0
- package/dist/cli/commands/presets.d.ts +51 -0
- package/dist/cli/commands/presets.js +280 -0
- package/dist/cli/commands/profiles.d.ts +5 -0
- package/dist/cli/commands/profiles.js +26 -0
- package/dist/cli/commands/telemetry.d.ts +6 -0
- package/dist/cli/commands/telemetry.js +45 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +50 -0
- package/dist/cli/expandWildcards.d.ts +17 -0
- package/dist/cli/expandWildcards.js +81 -0
- package/dist/cli/logger.d.ts +17 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/sameFile.d.ts +9 -0
- package/dist/cli/sameFile.js +40 -0
- package/dist/cli/stats.d.ts +34 -0
- package/dist/cli/stats.js +137 -0
- package/dist/cli/table.d.ts +8 -0
- package/dist/cli/table.js +18 -0
- package/dist/cli/terminalText.d.ts +7 -0
- package/dist/cli/terminalText.js +22 -0
- package/dist/cli/updateCheck.d.ts +14 -0
- package/dist/cli/updateCheck.js +78 -0
- package/dist/cli/watchState.d.ts +18 -0
- package/dist/cli/watchState.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +10 -0
- package/dist/diff/diffSettings.d.ts +81 -0
- package/dist/diff/diffSettings.js +259 -0
- package/dist/diff/reference.d.ts +14 -0
- package/dist/diff/reference.js +22 -0
- package/dist/diff/settingsCatalog.d.ts +28 -0
- package/dist/diff/settingsCatalog.js +605 -0
- package/dist/diff/valueLayout.d.ts +20 -0
- package/dist/diff/valueLayout.js +65 -0
- package/dist/engine/aboveStock.d.ts +20 -0
- package/dist/engine/aboveStock.js +89 -0
- package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
- package/dist/engine/applyFilamentComplianceMode.js +68 -0
- package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
- package/dist/engine/applyFilamentFlowVariants.js +109 -0
- package/dist/engine/applyHighFlowHotends.d.ts +52 -0
- package/dist/engine/applyHighFlowHotends.js +115 -0
- package/dist/engine/applyPresetChanges.d.ts +12 -0
- package/dist/engine/applyPresetChanges.js +23 -0
- package/dist/engine/bedCenter.d.ts +19 -0
- package/dist/engine/bedCenter.js +34 -0
- package/dist/engine/buildFilamentConfigs.d.ts +18 -0
- package/dist/engine/buildFilamentConfigs.js +49 -0
- package/dist/engine/buildProjectSettings.d.ts +24 -0
- package/dist/engine/buildProjectSettings.js +164 -0
- package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
- package/dist/engine/carrySourceLayerHeight.js +41 -0
- package/dist/engine/clampColorPenetration.d.ts +12 -0
- package/dist/engine/clampColorPenetration.js +28 -0
- package/dist/engine/clampToMachineLimits.d.ts +21 -0
- package/dist/engine/clampToMachineLimits.js +84 -0
- package/dist/engine/coerceValue.d.ts +15 -0
- package/dist/engine/coerceValue.js +56 -0
- package/dist/engine/collapseNozzleVariants.d.ts +31 -0
- package/dist/engine/collapseNozzleVariants.js +63 -0
- package/dist/engine/computeShifts.d.ts +12 -0
- package/dist/engine/computeShifts.js +339 -0
- package/dist/engine/constants.d.ts +11 -0
- package/dist/engine/constants.js +12 -0
- package/dist/engine/detectNozzleDiameter.d.ts +15 -0
- package/dist/engine/detectNozzleDiameter.js +29 -0
- package/dist/engine/detectVariantIndex.d.ts +39 -0
- package/dist/engine/detectVariantIndex.js +80 -0
- package/dist/engine/extractFilamentSlots.d.ts +18 -0
- package/dist/engine/extractFilamentSlots.js +88 -0
- package/dist/engine/filamentComplianceNames.d.ts +84 -0
- package/dist/engine/filamentComplianceNames.js +87 -0
- package/dist/engine/filamentVariantLayout.d.ts +29 -0
- package/dist/engine/filamentVariantLayout.js +38 -0
- package/dist/engine/fillFilamentSlots.d.ts +16 -0
- package/dist/engine/fillFilamentSlots.js +26 -0
- package/dist/engine/internal/jsonEqual.d.ts +2 -0
- package/dist/engine/internal/jsonEqual.js +5 -0
- package/dist/engine/parseTierName.d.ts +15 -0
- package/dist/engine/parseTierName.js +21 -0
- package/dist/engine/pickNearestProfile.d.ts +21 -0
- package/dist/engine/pickNearestProfile.js +24 -0
- package/dist/engine/pickProfile.d.ts +49 -0
- package/dist/engine/pickProfile.js +67 -0
- package/dist/engine/policy.d.ts +14 -0
- package/dist/engine/policy.js +266 -0
- package/dist/engine/remapBrimType.d.ts +30 -0
- package/dist/engine/remapBrimType.js +34 -0
- package/dist/engine/reshapeToCount.d.ts +15 -0
- package/dist/engine/reshapeToCount.js +27 -0
- package/dist/engine/resizeFlushVolumes.d.ts +27 -0
- package/dist/engine/resizeFlushVolumes.js +57 -0
- package/dist/engine/resolveMinIfLower.d.ts +21 -0
- package/dist/engine/resolveMinIfLower.js +59 -0
- package/dist/engine/runConvertPipeline.d.ts +79 -0
- package/dist/engine/runConvertPipeline.js +281 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/types.js +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +9 -0
- package/dist/explain/whatChanged.d.ts +102 -0
- package/dist/explain/whatChanged.js +197 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +33 -0
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.js +103 -0
- package/dist/node.d.ts +11 -0
- package/dist/node.js +50 -0
- package/dist/plainText.d.ts +10 -0
- package/dist/plainText.js +14 -0
- package/dist/presets/extractPreset.d.ts +13 -0
- package/dist/presets/extractPreset.js +87 -0
- package/dist/presets/preset.d.ts +124 -0
- package/dist/presets/preset.js +289 -0
- package/dist/presets/presetKeys.d.ts +5 -0
- package/dist/presets/presetKeys.js +42 -0
- package/dist/profiles.d.ts +184 -0
- package/dist/profiles.js +314 -0
- package/dist/project.d.ts +146 -0
- package/dist/project.js +342 -0
- package/dist/schema.d.ts +103 -0
- package/dist/schema.js +87 -0
- package/dist/stamp.d.ts +45 -0
- package/dist/stamp.js +111 -0
- package/dist/telemetry.d.ts +101 -0
- package/dist/telemetry.js +94 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +142 -0
- package/dist/worker.d.ts +86 -0
- package/dist/worker.js +97 -0
- package/dist/workerProtocol.d.ts +91 -0
- package/dist/workerProtocol.js +1 -0
- package/package.json +78 -12
- package/index.js +0 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
export type FilamentSlot = Record<string, unknown>;
|
|
3
|
+
export interface ExtractFilamentSlotsResult {
|
|
4
|
+
/** key -> reshaped array of length filamentCount, for overlaying onto project_settings. `null` if extraction failed. */
|
|
5
|
+
filamentKeyArrays: Record<string, unknown[]> | null;
|
|
6
|
+
/** One dict per filament slot used in the project. Always an array (empty on failure). */
|
|
7
|
+
slots: FilamentSlot[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build a list of per-filament dicts (one per filament slot used in the
|
|
11
|
+
* Bambu project) by reshaping every relevant array key down to the
|
|
12
|
+
* project's actual filament count.
|
|
13
|
+
*
|
|
14
|
+
* @param filamentTemplateKeys keys present in the filament shape template (`filament_settings_1.config`'s keys).
|
|
15
|
+
* @param extraProjectLevelFilamentKeys project-level-only filament array keys not in the shape template.
|
|
16
|
+
* @param filamentKeyBlocklist keys never pulled from Bambu.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractFilamentSlots(bambuSettings: JsonRecord, filamentTemplateKeys: ReadonlySet<string>, extraProjectLevelFilamentKeys: ReadonlySet<string>, filamentKeyBlocklist: ReadonlySet<string>, warnings: string[]): ExtractFilamentSlotsResult;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { FILAMENT_FLOW_VARIANT_KEYS } from "./applyFilamentFlowVariants.js";
|
|
3
|
+
import { detectVariantIndex } from "./detectVariantIndex.js";
|
|
4
|
+
import { filamentVariantLayout } from "./filamentVariantLayout.js";
|
|
5
|
+
import { reshapeToCount } from "./reshapeToCount.js";
|
|
6
|
+
const VARIANT_KEYS = new Set(FILAMENT_FLOW_VARIANT_KEYS);
|
|
7
|
+
/** Up to six setting names, then how many more. */
|
|
8
|
+
function keyList(keys) {
|
|
9
|
+
return keys.length <= 6 ? keys.join(", ") : `${keys.slice(0, 6).join(", ")} and ${keys.length - 6} more`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build a list of per-filament dicts (one per filament slot used in the
|
|
13
|
+
* Bambu project) by reshaping every relevant array key down to the
|
|
14
|
+
* project's actual filament count.
|
|
15
|
+
*
|
|
16
|
+
* @param filamentTemplateKeys keys present in the filament shape template (`filament_settings_1.config`'s keys).
|
|
17
|
+
* @param extraProjectLevelFilamentKeys project-level-only filament array keys not in the shape template.
|
|
18
|
+
* @param filamentKeyBlocklist keys never pulled from Bambu.
|
|
19
|
+
*/
|
|
20
|
+
export function extractFilamentSlots(bambuSettings, filamentTemplateKeys, extraProjectLevelFilamentKeys, filamentKeyBlocklist, warnings) {
|
|
21
|
+
// Settings object keys are the slicer's own config field names (snake_case,
|
|
22
|
+
// e.g. "filament_colour", "printable_area") -- passed through JSON.parse
|
|
23
|
+
// verbatim, never renamed to camelCase.
|
|
24
|
+
const colors = bambuSettings.filament_colour;
|
|
25
|
+
if (!Array.isArray(colors) || colors.length === 0) {
|
|
26
|
+
warnings.push(" WARN: the source file has no filament_colour list, so its filament settings aren't carried over.");
|
|
27
|
+
return { filamentKeyArrays: null, slots: [] };
|
|
28
|
+
}
|
|
29
|
+
const filamentCount = colors.length;
|
|
30
|
+
const keysToPull = [...new Set([...filamentTemplateKeys, ...extraProjectLevelFilamentKeys])]
|
|
31
|
+
.filter((k) => !filamentKeyBlocklist.has(k))
|
|
32
|
+
.sort();
|
|
33
|
+
const variantIndex = detectVariantIndex(bambuSettings) ?? 0;
|
|
34
|
+
// A source saved by an Orca-family slicer says where each filament's standard value sits, even when filaments carry different numbers of values.
|
|
35
|
+
const layout = filamentVariantLayout(bambuSettings, filamentCount);
|
|
36
|
+
const perProjectKeyArrays = {};
|
|
37
|
+
// Stale lists usually affect dozens of settings at once; they're reported as one line per kind, not one per setting.
|
|
38
|
+
const stockUsed = new Map();
|
|
39
|
+
const firstUsed = new Map();
|
|
40
|
+
const note = (groups, length, key) => groups.set(length, [...(groups.get(length) ?? []), key]);
|
|
41
|
+
for (const key of keysToPull) {
|
|
42
|
+
const bval = bambuSettings[key];
|
|
43
|
+
if (!Array.isArray(bval))
|
|
44
|
+
continue;
|
|
45
|
+
// The layout's own bookkeeping; applyFilamentFlowVariants writes it for the target nozzle.
|
|
46
|
+
if (layout && (key === "filament_flow_support" || key === "filament_flow_step_size"))
|
|
47
|
+
continue;
|
|
48
|
+
if (layout && VARIANT_KEYS.has(key) && bval.length === layout.length) {
|
|
49
|
+
perProjectKeyArrays[key] = layout.slots.map((slot) => bval[slot.standard]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Several values per filament are read as one per nozzle variant only when the file names the variants;
|
|
53
|
+
// otherwise the extra values are stale entries, and the first one per filament is used, as the slicer does.
|
|
54
|
+
const variantNames = bambuSettings.filament_extruder_variant;
|
|
55
|
+
const reshaped = bval.length === filamentCount || (Array.isArray(variantNames) && variantNames.length === bval.length)
|
|
56
|
+
? reshapeToCount(bval, filamentCount, variantIndex)
|
|
57
|
+
: bval.length > filamentCount
|
|
58
|
+
? bval.slice(0, filamentCount)
|
|
59
|
+
: null;
|
|
60
|
+
if (reshaped === null) {
|
|
61
|
+
note(stockUsed, bval.length, key);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (bval.length > filamentCount && !(Array.isArray(variantNames) && variantNames.length === bval.length)) {
|
|
65
|
+
note(firstUsed, bval.length, key);
|
|
66
|
+
}
|
|
67
|
+
perProjectKeyArrays[key] = reshaped;
|
|
68
|
+
}
|
|
69
|
+
for (const [length, keys] of stockUsed) {
|
|
70
|
+
warnings.push(keys.length === 1
|
|
71
|
+
? ` WARN: ${keys[0]} has ${length} values for ${filamentCount} filaments in the source file, so Snapmaker's stock value is used for it.`
|
|
72
|
+
: ` WARN: ${keys.length} filament settings have ${length} values for ${filamentCount} filaments in the source file, so Snapmaker's stock values are used for them: ${keyList(keys)}.`);
|
|
73
|
+
}
|
|
74
|
+
for (const [length, keys] of firstUsed) {
|
|
75
|
+
warnings.push(keys.length === 1
|
|
76
|
+
? ` WARN: ${keys[0]} has ${length} values for ${filamentCount} filaments in the source file; the first ${filamentCount} are used.`
|
|
77
|
+
: ` WARN: ${keys.length} filament settings have ${length} values for ${filamentCount} filaments in the source file; the first ${filamentCount} of each are used: ${keyList(keys)}.`);
|
|
78
|
+
}
|
|
79
|
+
const slots = [];
|
|
80
|
+
for (let i = 0; i < filamentCount; i++) {
|
|
81
|
+
const slot = {};
|
|
82
|
+
for (const [key, arr] of Object.entries(perProjectKeyArrays)) {
|
|
83
|
+
slot[key] = arr[i];
|
|
84
|
+
}
|
|
85
|
+
slots.push(slot);
|
|
86
|
+
}
|
|
87
|
+
return { filamentKeyArrays: perProjectKeyArrays, slots };
|
|
88
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filament names for the Snapmaker and Generic naming options, used to
|
|
3
|
+
* satisfy marketplace rules (e.g. Snapmaker Space, Snapmaker's own model
|
|
4
|
+
* platform) that require an uploaded project to declare a Generic or
|
|
5
|
+
* Snapmaker filament rather than a third-party one like Bambu's own.
|
|
6
|
+
*
|
|
7
|
+
* The names are data, not code: the profile catalog's `filamentNames`
|
|
8
|
+
* (any2orca-profiles' data/index.json, generated from the filament presets
|
|
9
|
+
* Snapmaker installs with Snapmaker Orca) lists every preset each printer
|
|
10
|
+
* offers and the product lines that map onto them. This module only matches
|
|
11
|
+
* a source filament to a line and picks that line's preset for the target
|
|
12
|
+
* printer, so every name it returns exists for that nozzle size.
|
|
13
|
+
*
|
|
14
|
+
* Matching is by product line, never by color: a filament's material is its
|
|
15
|
+
* `filament_type`, and its line is the first line for that material whose
|
|
16
|
+
* keywords appear in its name or type ("Bambu PLA Matte" is PLA Matte,
|
|
17
|
+
* "Bambu PLA Basic" is plain PLA, which maps to Snapmaker PLA SnapSpeed).
|
|
18
|
+
*/
|
|
19
|
+
export type FilamentComplianceMode = "generic" | "snapmaker";
|
|
20
|
+
/** One preset a printer offers, with what a project saved with it records. */
|
|
21
|
+
export interface FilamentPresetEntry {
|
|
22
|
+
/** The preset family, its name without the " @printer" part, e.g. "Snapmaker PLA Matte". */
|
|
23
|
+
family: string;
|
|
24
|
+
/** What Snapmaker Orca writes as this preset's `filament_ids` entry. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** What Snapmaker Orca writes as this preset's `filament_vendor` entry. */
|
|
27
|
+
vendor: string;
|
|
28
|
+
}
|
|
29
|
+
/** A product line and the preset family each naming option maps it to (null: no such preset). */
|
|
30
|
+
export interface FilamentLine {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
materials: string[];
|
|
34
|
+
keywords: string[];
|
|
35
|
+
snapmaker: string | null;
|
|
36
|
+
generic: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** The profile catalog's `filamentNames`. */
|
|
39
|
+
export interface FilamentNameTable {
|
|
40
|
+
profileSet: {
|
|
41
|
+
repository: string;
|
|
42
|
+
version: string;
|
|
43
|
+
commit: string;
|
|
44
|
+
};
|
|
45
|
+
/** Source `filament_type` values read as another material, e.g. "PA6-CF" as "PA-CF". */
|
|
46
|
+
materialAliases: Record<string, string>;
|
|
47
|
+
lines: FilamentLine[];
|
|
48
|
+
/** Per printer id: every filament preset it offers, by name. */
|
|
49
|
+
printers: Record<string, {
|
|
50
|
+
nozzleDiameter: string;
|
|
51
|
+
presets: Record<string, FilamentPresetEntry>;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export interface FilamentNameResult {
|
|
55
|
+
/**
|
|
56
|
+
* - "renamed": named after the line's preset for the chosen option.
|
|
57
|
+
* - "kept": already the name of a preset of the chosen kind for this
|
|
58
|
+
* printer (e.g. a file saved in Snapmaker Orca), so the creator's
|
|
59
|
+
* choice stays; its id and vendor are still written as that preset's.
|
|
60
|
+
* - "generic": the Snapmaker option, but Snapmaker makes no preset for
|
|
61
|
+
* this line at this nozzle size, so the Generic one is used.
|
|
62
|
+
* - "unchanged": no preset of either kind fits (an unknown material, or
|
|
63
|
+
* none at this nozzle size); the creator's name stays.
|
|
64
|
+
*/
|
|
65
|
+
outcome: "renamed" | "kept" | "generic" | "unchanged";
|
|
66
|
+
/** The preset written; absent when unchanged. */
|
|
67
|
+
preset?: {
|
|
68
|
+
name: string;
|
|
69
|
+
id: string;
|
|
70
|
+
vendor: string;
|
|
71
|
+
};
|
|
72
|
+
/** The product line matched, or null when the material has no line. */
|
|
73
|
+
line: {
|
|
74
|
+
id: string;
|
|
75
|
+
label: string;
|
|
76
|
+
} | null;
|
|
77
|
+
}
|
|
78
|
+
/** The product line a source filament belongs to, or null when its material has none. */
|
|
79
|
+
export declare function matchFilamentLine(table: FilamentNameTable, filamentType: string, filamentSettingsId: string): FilamentLine | null;
|
|
80
|
+
/**
|
|
81
|
+
* The name, id and vendor one filament gets under a naming option for the
|
|
82
|
+
* target printer. Never returns a name the printer doesn't offer.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveFilamentName(table: FilamentNameTable, printerId: string, filamentType: string, filamentSettingsId: string, mode: FilamentComplianceMode): FilamentNameResult;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Filament names for the Snapmaker and Generic naming options, used to
|
|
4
|
+
* satisfy marketplace rules (e.g. Snapmaker Space, Snapmaker's own model
|
|
5
|
+
* platform) that require an uploaded project to declare a Generic or
|
|
6
|
+
* Snapmaker filament rather than a third-party one like Bambu's own.
|
|
7
|
+
*
|
|
8
|
+
* The names are data, not code: the profile catalog's `filamentNames`
|
|
9
|
+
* (any2orca-profiles' data/index.json, generated from the filament presets
|
|
10
|
+
* Snapmaker installs with Snapmaker Orca) lists every preset each printer
|
|
11
|
+
* offers and the product lines that map onto them. This module only matches
|
|
12
|
+
* a source filament to a line and picks that line's preset for the target
|
|
13
|
+
* printer, so every name it returns exists for that nozzle size.
|
|
14
|
+
*
|
|
15
|
+
* Matching is by product line, never by color: a filament's material is its
|
|
16
|
+
* `filament_type`, and its line is the first line for that material whose
|
|
17
|
+
* keywords appear in its name or type ("Bambu PLA Matte" is PLA Matte,
|
|
18
|
+
* "Bambu PLA Basic" is plain PLA, which maps to Snapmaker PLA SnapSpeed).
|
|
19
|
+
*/
|
|
20
|
+
function tokens(text) {
|
|
21
|
+
return text.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
function containsKeyword(haystack, keyword) {
|
|
24
|
+
const needle = tokens(keyword);
|
|
25
|
+
if (needle.length === 0)
|
|
26
|
+
return false;
|
|
27
|
+
for (let i = 0; i + needle.length <= haystack.length; i++) {
|
|
28
|
+
if (needle.every((t, j) => haystack[i + j] === t))
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The part of a `filament_settings_id` that names the filament: without the
|
|
35
|
+
* " @printer..." part, and without a "(project.3mf)" tag the slicer appends
|
|
36
|
+
* to presets it imported from a project, whose file name says nothing about
|
|
37
|
+
* the material.
|
|
38
|
+
*/
|
|
39
|
+
function filamentNamePart(filamentSettingsId) {
|
|
40
|
+
const withoutProjectTags = filamentSettingsId.replace(/\([^()]*\.3mf\)/gi, " ");
|
|
41
|
+
const at = withoutProjectTags.indexOf(" @");
|
|
42
|
+
return at >= 0 ? withoutProjectTags.slice(0, at) : withoutProjectTags;
|
|
43
|
+
}
|
|
44
|
+
/** The product line a source filament belongs to, or null when its material has none. */
|
|
45
|
+
export function matchFilamentLine(table, filamentType, filamentSettingsId) {
|
|
46
|
+
const type = filamentType.trim().toUpperCase();
|
|
47
|
+
const material = Object.hasOwn(table.materialAliases, type) ? table.materialAliases[type] : type;
|
|
48
|
+
const words = tokens(`${filamentType} ${filamentNamePart(filamentSettingsId)}`);
|
|
49
|
+
for (const line of table.lines) {
|
|
50
|
+
if (!line.materials.includes(material))
|
|
51
|
+
continue;
|
|
52
|
+
if (line.keywords.length === 0 || line.keywords.some((k) => containsKeyword(words, k)))
|
|
53
|
+
return line;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The name, id and vendor one filament gets under a naming option for the
|
|
59
|
+
* target printer. Never returns a name the printer doesn't offer.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveFilamentName(table, printerId, filamentType, filamentSettingsId, mode) {
|
|
62
|
+
const printer = Object.hasOwn(table.printers, printerId) ? table.printers[printerId] : undefined;
|
|
63
|
+
const line = matchFilamentLine(table, filamentType, filamentSettingsId);
|
|
64
|
+
const lineRef = line ? { id: line.id, label: line.label } : null;
|
|
65
|
+
if (!printer)
|
|
66
|
+
return { outcome: "unchanged", line: lineRef };
|
|
67
|
+
const presetOf = (name) => {
|
|
68
|
+
const entry = printer.presets[name];
|
|
69
|
+
return { name, id: entry.id, vendor: entry.vendor };
|
|
70
|
+
};
|
|
71
|
+
const current = filamentSettingsId.trim();
|
|
72
|
+
const currentEntry = Object.hasOwn(printer.presets, current) ? printer.presets[current] : undefined;
|
|
73
|
+
if (currentEntry && currentEntry.vendor.toLowerCase() === mode)
|
|
74
|
+
return { outcome: "kept", preset: presetOf(current), line: lineRef };
|
|
75
|
+
if (!line)
|
|
76
|
+
return { outcome: "unchanged", line: null };
|
|
77
|
+
const byFamily = (family) => (family === null ? undefined : Object.keys(printer.presets).find((name) => printer.presets[name].family === family));
|
|
78
|
+
if (mode === "snapmaker") {
|
|
79
|
+
const snapmaker = byFamily(line.snapmaker);
|
|
80
|
+
if (snapmaker)
|
|
81
|
+
return { outcome: "renamed", preset: presetOf(snapmaker), line: lineRef };
|
|
82
|
+
}
|
|
83
|
+
const generic = byFamily(line.generic);
|
|
84
|
+
if (generic)
|
|
85
|
+
return { outcome: mode === "snapmaker" ? "generic" : "renamed", preset: presetOf(generic), line: lineRef };
|
|
86
|
+
return { outcome: "unchanged", line: lineRef };
|
|
87
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/** Where one filament's values sit in a per-variant array of an Orca-layout source. */
|
|
3
|
+
export interface FilamentVariantPositions {
|
|
4
|
+
/** Index of the filament's standard value. */
|
|
5
|
+
standard: number;
|
|
6
|
+
/** Index of its high-flow value, or null when the filament has none. */
|
|
7
|
+
highFlow: number | null;
|
|
8
|
+
}
|
|
9
|
+
export interface FilamentVariantLayout {
|
|
10
|
+
/** How many entries a per-variant filament setting has in this source. */
|
|
11
|
+
length: number;
|
|
12
|
+
/** One entry per filament slot, in slot order. */
|
|
13
|
+
slots: FilamentVariantPositions[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* How a source saved by Snapmaker Orca (or another Orca-family slicer)
|
|
17
|
+
* lays out its per-variant filament settings, or null for any other
|
|
18
|
+
* source.
|
|
19
|
+
*
|
|
20
|
+
* Snapmaker Orca 2.4 stores each per-variant filament setting (see
|
|
21
|
+
* FILAMENT_FLOW_VARIANT_KEYS) as one flat array: each filament's values in
|
|
22
|
+
* turn, `filament_flow_step_size[i]` of them, tagged by the matching
|
|
23
|
+
* entries of `filament_flow_support` ("standard", "high_flow"). Filaments
|
|
24
|
+
* in one file can have different counts (a filament with only a standard
|
|
25
|
+
* value next to one with both), so the array isn't always a clean multiple
|
|
26
|
+
* of the slot count. Bambu Studio sources don't write these keys; they
|
|
27
|
+
* name their variants instead (detectVariantIndex.ts).
|
|
28
|
+
*/
|
|
29
|
+
export declare function filamentVariantLayout(source: JsonRecord, slotCount: number): FilamentVariantLayout | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Most variants Snapmaker Orca stores for one filament (standard and high flow today). */
|
|
2
|
+
const MAX_STEP = 4;
|
|
3
|
+
/**
|
|
4
|
+
* How a source saved by Snapmaker Orca (or another Orca-family slicer)
|
|
5
|
+
* lays out its per-variant filament settings, or null for any other
|
|
6
|
+
* source.
|
|
7
|
+
*
|
|
8
|
+
* Snapmaker Orca 2.4 stores each per-variant filament setting (see
|
|
9
|
+
* FILAMENT_FLOW_VARIANT_KEYS) as one flat array: each filament's values in
|
|
10
|
+
* turn, `filament_flow_step_size[i]` of them, tagged by the matching
|
|
11
|
+
* entries of `filament_flow_support` ("standard", "high_flow"). Filaments
|
|
12
|
+
* in one file can have different counts (a filament with only a standard
|
|
13
|
+
* value next to one with both), so the array isn't always a clean multiple
|
|
14
|
+
* of the slot count. Bambu Studio sources don't write these keys; they
|
|
15
|
+
* name their variants instead (detectVariantIndex.ts).
|
|
16
|
+
*/
|
|
17
|
+
export function filamentVariantLayout(source, slotCount) {
|
|
18
|
+
const steps = source.filament_flow_step_size;
|
|
19
|
+
const support = source.filament_flow_support;
|
|
20
|
+
if (!Array.isArray(steps) || !Array.isArray(support) || slotCount < 1 || steps.length !== slotCount)
|
|
21
|
+
return null;
|
|
22
|
+
const counts = steps.map((s) => Number(s));
|
|
23
|
+
if (!counts.every((n) => Number.isInteger(n) && n >= 1 && n <= MAX_STEP))
|
|
24
|
+
return null;
|
|
25
|
+
const length = counts.reduce((a, b) => a + b, 0);
|
|
26
|
+
if (support.length !== length || !support.every((s) => typeof s === "string"))
|
|
27
|
+
return null;
|
|
28
|
+
const slots = [];
|
|
29
|
+
let offset = 0;
|
|
30
|
+
for (const count of counts) {
|
|
31
|
+
const tags = support.slice(offset, offset + count);
|
|
32
|
+
const standard = tags.indexOf("standard");
|
|
33
|
+
const highFlow = tags.indexOf("high_flow");
|
|
34
|
+
slots.push({ standard: offset + (standard >= 0 ? standard : 0), highFlow: highFlow >= 0 ? offset + highFlow : null });
|
|
35
|
+
offset += count;
|
|
36
|
+
}
|
|
37
|
+
return { length, slots };
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Gives every per-filament setting one value per filament slot.
|
|
4
|
+
*
|
|
5
|
+
* The creator's filament settings come from the source and already have
|
|
6
|
+
* one value per slot. Settings the source doesn't carry (Orca-only or
|
|
7
|
+
* Snapmaker-only ones such as ramming, cooling moves or stamping) keep the
|
|
8
|
+
* U1 profile's stock value, but the stock profile describes a single
|
|
9
|
+
* filament, sometimes with a standard and a high-flow value. Those are
|
|
10
|
+
* repeated so each slot gets the stock standard value, matching the one
|
|
11
|
+
* value per slot the rest of the filament settings use.
|
|
12
|
+
*
|
|
13
|
+
* @param filamentKeys the keys of a single filament's settings (the filament template's keys).
|
|
14
|
+
* @param fromSource keys whose values came from the source file, already one per slot.
|
|
15
|
+
*/
|
|
16
|
+
export declare function fillFilamentSlots(settings: JsonRecord, filamentKeys: ReadonlySet<string>, fromSource: ReadonlySet<string>, slotCount: number): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gives every per-filament setting one value per filament slot.
|
|
3
|
+
*
|
|
4
|
+
* The creator's filament settings come from the source and already have
|
|
5
|
+
* one value per slot. Settings the source doesn't carry (Orca-only or
|
|
6
|
+
* Snapmaker-only ones such as ramming, cooling moves or stamping) keep the
|
|
7
|
+
* U1 profile's stock value, but the stock profile describes a single
|
|
8
|
+
* filament, sometimes with a standard and a high-flow value. Those are
|
|
9
|
+
* repeated so each slot gets the stock standard value, matching the one
|
|
10
|
+
* value per slot the rest of the filament settings use.
|
|
11
|
+
*
|
|
12
|
+
* @param filamentKeys the keys of a single filament's settings (the filament template's keys).
|
|
13
|
+
* @param fromSource keys whose values came from the source file, already one per slot.
|
|
14
|
+
*/
|
|
15
|
+
export function fillFilamentSlots(settings, filamentKeys, fromSource, slotCount) {
|
|
16
|
+
if (slotCount < 1)
|
|
17
|
+
return;
|
|
18
|
+
for (const key of filamentKeys) {
|
|
19
|
+
if (fromSource.has(key))
|
|
20
|
+
continue;
|
|
21
|
+
const value = settings[key];
|
|
22
|
+
if (!Array.isArray(value) || value.length === 0 || value.length === slotCount)
|
|
23
|
+
continue;
|
|
24
|
+
settings[key] = Array.from({ length: slotCount }, () => value[0]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the tier name out of a `print_settings_id`/`name`-shaped
|
|
3
|
+
* string, e.g. `"0.08mm Extra Fine @BBL X1C"` -> "Extra Fine", or our own
|
|
4
|
+
* `"0.08 High Quality @Snapmaker U1 (0.4 nozzle)"` -> "High Quality". Both
|
|
5
|
+
* Bambu's and Snapmaker's naming follow the same
|
|
6
|
+
* `{layer height}[mm] {tier name} @{printer}` shape, so one parser covers
|
|
7
|
+
* both sides of the match.
|
|
8
|
+
*
|
|
9
|
+
* Returns `null` when the string doesn't fit that shape (missing "@", no
|
|
10
|
+
* text between the number and "@", etc.) -- callers should treat that as
|
|
11
|
+
* "no tier name signal available" rather than guess.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseTierName(text: string): string | null;
|
|
14
|
+
/** Case/whitespace-insensitive comparison key for two tier names. */
|
|
15
|
+
export declare function normalizeTierName(name: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the tier name out of a `print_settings_id`/`name`-shaped
|
|
4
|
+
* string, e.g. `"0.08mm Extra Fine @BBL X1C"` -> "Extra Fine", or our own
|
|
5
|
+
* `"0.08 High Quality @Snapmaker U1 (0.4 nozzle)"` -> "High Quality". Both
|
|
6
|
+
* Bambu's and Snapmaker's naming follow the same
|
|
7
|
+
* `{layer height}[mm] {tier name} @{printer}` shape, so one parser covers
|
|
8
|
+
* both sides of the match.
|
|
9
|
+
*
|
|
10
|
+
* Returns `null` when the string doesn't fit that shape (missing "@", no
|
|
11
|
+
* text between the number and "@", etc.) -- callers should treat that as
|
|
12
|
+
* "no tier name signal available" rather than guess.
|
|
13
|
+
*/
|
|
14
|
+
export function parseTierName(text) {
|
|
15
|
+
const match = /^[\d.]+(?:mm)?\s+(.+?)\s+@/.exec(text.trim());
|
|
16
|
+
return match ? match[1] : null;
|
|
17
|
+
}
|
|
18
|
+
/** Case/whitespace-insensitive comparison key for two tier names. */
|
|
19
|
+
export function normalizeTierName(name) {
|
|
20
|
+
return name.trim().toLowerCase().replace(/\s+/g, " ");
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** A candidate profile to fuzzy-match against, from the profile catalog's list. */
|
|
2
|
+
export interface ProfileCandidate {
|
|
3
|
+
id: string;
|
|
4
|
+
layerHeight: number;
|
|
5
|
+
}
|
|
6
|
+
export interface PickNearestProfileResult {
|
|
7
|
+
profileId: string;
|
|
8
|
+
/** True when a candidate's layerHeight matched the target exactly. */
|
|
9
|
+
exact: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Picks the candidate whose layerHeight is closest to the Bambu source's
|
|
13
|
+
* own detected layer height. Ties resolve to the first candidate at that
|
|
14
|
+
* distance (candidates should be pre-sorted by layerHeight ascending, so
|
|
15
|
+
* this favors the finer of two equidistant options).
|
|
16
|
+
*
|
|
17
|
+
* Returns `null` when there are no candidates, or when `targetLayerHeight`
|
|
18
|
+
* is null (unparseable/missing on the Bambu source) -- callers should fall
|
|
19
|
+
* back to a default profile in that case rather than guess.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pickNearestProfile(candidates: ProfileCandidate[], targetLayerHeight: number | null): PickNearestProfileResult | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks the candidate whose layerHeight is closest to the Bambu source's
|
|
3
|
+
* own detected layer height. Ties resolve to the first candidate at that
|
|
4
|
+
* distance (candidates should be pre-sorted by layerHeight ascending, so
|
|
5
|
+
* this favors the finer of two equidistant options).
|
|
6
|
+
*
|
|
7
|
+
* Returns `null` when there are no candidates, or when `targetLayerHeight`
|
|
8
|
+
* is null (unparseable/missing on the Bambu source) -- callers should fall
|
|
9
|
+
* back to a default profile in that case rather than guess.
|
|
10
|
+
*/
|
|
11
|
+
export function pickNearestProfile(candidates, targetLayerHeight) {
|
|
12
|
+
if (candidates.length === 0 || targetLayerHeight === null)
|
|
13
|
+
return null;
|
|
14
|
+
let best = candidates[0];
|
|
15
|
+
let bestDistance = Math.abs(candidates[0].layerHeight - targetLayerHeight);
|
|
16
|
+
for (const candidate of candidates.slice(1)) {
|
|
17
|
+
const distance = Math.abs(candidate.layerHeight - targetLayerHeight);
|
|
18
|
+
if (distance < bestDistance) {
|
|
19
|
+
best = candidate;
|
|
20
|
+
bestDistance = distance;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { profileId: best.id, exact: bestDistance < 1e-9 };
|
|
24
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ProfileCandidate } from "./pickNearestProfile.js";
|
|
2
|
+
/** A candidate profile for tier-aware selection -- a superset of ProfileCandidate. */
|
|
3
|
+
export interface TierAwareProfileCandidate extends ProfileCandidate {
|
|
4
|
+
tierName: string;
|
|
5
|
+
autoSelectable: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PickProfileResult {
|
|
8
|
+
profileId: string;
|
|
9
|
+
exact: boolean;
|
|
10
|
+
/** True when the Bambu source's own tier name (e.g. "Extra Fine") matched a candidate's tier name directly. */
|
|
11
|
+
matchedByTierName: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Picks a profile for a detected nozzle diameter, preferring the source's
|
|
15
|
+
* own tier name (parsed from its print_settings_id, e.g. "Extra Fine" out
|
|
16
|
+
* of `"0.08mm Extra Fine @BBL X1C"`) over pure nearest-layer-height
|
|
17
|
+
* matching. This is what disambiguates ties that layer height alone
|
|
18
|
+
* can't -- e.g. "0.08 Extra Fine" and "0.08 High Quality" @0.4mm sit at
|
|
19
|
+
* the identical layer height, but only one shares the source file's own
|
|
20
|
+
* tier name.
|
|
21
|
+
*
|
|
22
|
+
* Two stages:
|
|
23
|
+
* 1. If `targetTierName` is provided, filter candidates to ones whose
|
|
24
|
+
* `tierName` matches it (case/whitespace-insensitive), *ignoring*
|
|
25
|
+
* `autoSelectable` -- a direct name match is a stronger signal than
|
|
26
|
+
* the tie-break table `autoSelectable` encodes, so it's allowed to
|
|
27
|
+
* pick a normally-non-auto-selectable tier. Among matches, nearest by
|
|
28
|
+
* layer height. The result is only trusted if it's at least as good a
|
|
29
|
+
* layer-height fit as the best name-agnostic candidate (see
|
|
30
|
+
* `isTierNameMatchTrustworthy`) -- this is what catches a
|
|
31
|
+
* cross-vendor naming coincidence (confirmed on a real Creality Print
|
|
32
|
+
* export: its own "Standard" tier was 0.12mm, but Snapmaker's own
|
|
33
|
+
* "Standard" tier is 0.20mm -- the shared word doesn't mean the same
|
|
34
|
+
* layer height once the source isn't Bambu Studio). A genuine Bambu
|
|
35
|
+
* source's tier name always ties or wins this check by construction,
|
|
36
|
+
* so this doesn't change behavior for the case the check was
|
|
37
|
+
* originally built for.
|
|
38
|
+
* 2. Otherwise (no tier name, no candidate shares it, or the name match
|
|
39
|
+
* isn't trustworthy), fall back to `pickNearestProfile` restricted to
|
|
40
|
+
* `autoSelectable` candidates only -- unchanged from the original
|
|
41
|
+
* layer-height-only behavior.
|
|
42
|
+
*
|
|
43
|
+
* Returns `null` when there are no candidates at all, or `targetLayerHeight`
|
|
44
|
+
* is null with no tier-name match either.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pickProfile(candidates: TierAwareProfileCandidate[], target: {
|
|
47
|
+
layerHeight: number | null;
|
|
48
|
+
tierName: string | null;
|
|
49
|
+
}): PickProfileResult | null;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { normalizeTierName } from "./parseTierName.js";
|
|
3
|
+
import { pickNearestProfile } from "./pickNearestProfile.js";
|
|
4
|
+
/**
|
|
5
|
+
* Picks a profile for a detected nozzle diameter, preferring the source's
|
|
6
|
+
* own tier name (parsed from its print_settings_id, e.g. "Extra Fine" out
|
|
7
|
+
* of `"0.08mm Extra Fine @BBL X1C"`) over pure nearest-layer-height
|
|
8
|
+
* matching. This is what disambiguates ties that layer height alone
|
|
9
|
+
* can't -- e.g. "0.08 Extra Fine" and "0.08 High Quality" @0.4mm sit at
|
|
10
|
+
* the identical layer height, but only one shares the source file's own
|
|
11
|
+
* tier name.
|
|
12
|
+
*
|
|
13
|
+
* Two stages:
|
|
14
|
+
* 1. If `targetTierName` is provided, filter candidates to ones whose
|
|
15
|
+
* `tierName` matches it (case/whitespace-insensitive), *ignoring*
|
|
16
|
+
* `autoSelectable` -- a direct name match is a stronger signal than
|
|
17
|
+
* the tie-break table `autoSelectable` encodes, so it's allowed to
|
|
18
|
+
* pick a normally-non-auto-selectable tier. Among matches, nearest by
|
|
19
|
+
* layer height. The result is only trusted if it's at least as good a
|
|
20
|
+
* layer-height fit as the best name-agnostic candidate (see
|
|
21
|
+
* `isTierNameMatchTrustworthy`) -- this is what catches a
|
|
22
|
+
* cross-vendor naming coincidence (confirmed on a real Creality Print
|
|
23
|
+
* export: its own "Standard" tier was 0.12mm, but Snapmaker's own
|
|
24
|
+
* "Standard" tier is 0.20mm -- the shared word doesn't mean the same
|
|
25
|
+
* layer height once the source isn't Bambu Studio). A genuine Bambu
|
|
26
|
+
* source's tier name always ties or wins this check by construction,
|
|
27
|
+
* so this doesn't change behavior for the case the check was
|
|
28
|
+
* originally built for.
|
|
29
|
+
* 2. Otherwise (no tier name, no candidate shares it, or the name match
|
|
30
|
+
* isn't trustworthy), fall back to `pickNearestProfile` restricted to
|
|
31
|
+
* `autoSelectable` candidates only -- unchanged from the original
|
|
32
|
+
* layer-height-only behavior.
|
|
33
|
+
*
|
|
34
|
+
* Returns `null` when there are no candidates at all, or `targetLayerHeight`
|
|
35
|
+
* is null with no tier-name match either.
|
|
36
|
+
*/
|
|
37
|
+
export function pickProfile(candidates, target) {
|
|
38
|
+
const autoSelectableCandidates = candidates.filter((c) => c.autoSelectable);
|
|
39
|
+
const nearestByHeight = pickNearestProfile(autoSelectableCandidates, target.layerHeight);
|
|
40
|
+
if (target.tierName) {
|
|
41
|
+
const normalizedTarget = normalizeTierName(target.tierName);
|
|
42
|
+
const nameMatches = candidates.filter((c) => normalizeTierName(c.tierName) === normalizedTarget);
|
|
43
|
+
const pickedByName = pickNearestProfile(nameMatches, target.layerHeight ?? nameMatches[0]?.layerHeight ?? null);
|
|
44
|
+
if (pickedByName && isTierNameMatchTrustworthy(pickedByName, nearestByHeight, candidates, target.layerHeight)) {
|
|
45
|
+
return { ...pickedByName, matchedByTierName: true };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return nearestByHeight ? { ...nearestByHeight, matchedByTierName: false } : null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A tier-NAME match is only trustworthy when its own layer height is at
|
|
52
|
+
* least as close to the target as the best name-agnostic candidate's --
|
|
53
|
+
* i.e. the name match must not be a WORSE layer-height fit than simply
|
|
54
|
+
* ignoring the name entirely. When there's no target layer height (or no
|
|
55
|
+
* name-agnostic candidate) to compare against at all, the name match is
|
|
56
|
+
* trusted unconditionally, matching the original behavior for that edge
|
|
57
|
+
* case.
|
|
58
|
+
*/
|
|
59
|
+
function isTierNameMatchTrustworthy(pickedByName, nearestByHeight, candidates, targetLayerHeight) {
|
|
60
|
+
if (targetLayerHeight === null || !nearestByHeight)
|
|
61
|
+
return true;
|
|
62
|
+
const namedHeight = candidates.find((c) => c.id === pickedByName.profileId)?.layerHeight;
|
|
63
|
+
const nearestHeight = candidates.find((c) => c.id === nearestByHeight.profileId)?.layerHeight;
|
|
64
|
+
if (namedHeight === undefined || nearestHeight === undefined)
|
|
65
|
+
return true;
|
|
66
|
+
return Math.abs(namedHeight - targetLayerHeight) <= Math.abs(nearestHeight - targetLayerHeight) + 1e-9;
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion policy: which source settings are dropped, which are always
|
|
3
|
+
* kept, which are forced, and which filament keys never transfer. These are
|
|
4
|
+
* the project's own decisions, applied the same way to every profile, so they live in the
|
|
5
|
+
* core rather than in the profile data.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BLOCKLIST: readonly string[];
|
|
8
|
+
export declare const MIN_COMPARISON_KEYS: readonly string[];
|
|
9
|
+
export declare const ALWAYS_TRANSFER_KEYS: readonly string[];
|
|
10
|
+
export declare const U1_VALUE_KEYS: readonly string[];
|
|
11
|
+
export declare const MACHINE_SETTINGS_KEYS: readonly string[];
|
|
12
|
+
/** Start, end, layer-change, filament-change and other machine G-code. A filament's own `filament_*_gcode` stays with the filament. */
|
|
13
|
+
export declare function isMachineGcodeKey(key: string): boolean;
|
|
14
|
+
export declare const FILAMENT_KEY_BLOCKLIST: readonly string[];
|