any2orca 0.0.0-stage → 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 +99 -2
- 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 +85 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { VARIANT_PROCESS_KEYS } from "./applyHighFlowHotends.js";
|
|
3
|
+
const VARIANT_KEYS = new Set(VARIANT_PROCESS_KEYS);
|
|
4
|
+
/**
|
|
5
|
+
* Writes a preset's values over the merged settings, so the user's own
|
|
6
|
+
* values win over the creator's. The caller has already checked every key
|
|
7
|
+
* and value (resolvePreset); only keys the profile has are written, so each
|
|
8
|
+
* one is already flagged in different_settings_to_system.
|
|
9
|
+
*
|
|
10
|
+
* A setting stored per hotend type (`[standard, high_flow]`) gets the
|
|
11
|
+
* preset's value as its standard entry; the high-flow entry is left to the
|
|
12
|
+
* profile and the high-flow option, which run after this.
|
|
13
|
+
*/
|
|
14
|
+
export function applyPresetChanges(settings, changes, warnings) {
|
|
15
|
+
for (const key of Object.keys(changes).sort()) {
|
|
16
|
+
if (!Object.hasOwn(settings, key))
|
|
17
|
+
continue;
|
|
18
|
+
const value = changes[key];
|
|
19
|
+
const current = settings[key];
|
|
20
|
+
settings[key] = VARIANT_KEYS.has(key) && Array.isArray(current) && typeof value === "string" ? [value, ...current.slice(1)] : value;
|
|
21
|
+
warnings.push(` preset: ${key} set to ${Array.isArray(value) ? value.join(", ") : value}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface BedCorners {
|
|
2
|
+
minX: number;
|
|
3
|
+
maxX: number;
|
|
4
|
+
minY: number;
|
|
5
|
+
maxY: number;
|
|
6
|
+
centerX: number;
|
|
7
|
+
centerY: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parse a `printable_area` array of `"XxY"` bed-polygon corner strings
|
|
11
|
+
* into its bounds and centroid. The bed center, the plate pitch and the
|
|
12
|
+
* clearance-scaling pass all use this, since they parse the same
|
|
13
|
+
* `printable_area` array.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseBedCorners(printableArea: readonly string[]): BedCorners;
|
|
16
|
+
/**
|
|
17
|
+
* The centroid (avg X, avg Y) of a bed polygon's corners.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bedCenter(printableArea: readonly string[]): [number, number];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a `printable_area` array of `"XxY"` bed-polygon corner strings
|
|
3
|
+
* into its bounds and centroid. The bed center, the plate pitch and the
|
|
4
|
+
* clearance-scaling pass all use this, since they parse the same
|
|
5
|
+
* `printable_area` array.
|
|
6
|
+
*/
|
|
7
|
+
export function parseBedCorners(printableArea) {
|
|
8
|
+
const xs = [];
|
|
9
|
+
const ys = [];
|
|
10
|
+
for (const corner of printableArea) {
|
|
11
|
+
const [xStr, yStr] = corner.split("x");
|
|
12
|
+
xs.push(Number.parseFloat(xStr));
|
|
13
|
+
ys.push(Number.parseFloat(yStr));
|
|
14
|
+
}
|
|
15
|
+
const minX = Math.min(...xs);
|
|
16
|
+
const maxX = Math.max(...xs);
|
|
17
|
+
const minY = Math.min(...ys);
|
|
18
|
+
const maxY = Math.max(...ys);
|
|
19
|
+
return {
|
|
20
|
+
minX,
|
|
21
|
+
maxX,
|
|
22
|
+
minY,
|
|
23
|
+
maxY,
|
|
24
|
+
centerX: xs.reduce((a, b) => a + b, 0) / xs.length,
|
|
25
|
+
centerY: ys.reduce((a, b) => a + b, 0) / ys.length,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The centroid (avg X, avg Y) of a bed polygon's corners.
|
|
30
|
+
*/
|
|
31
|
+
export function bedCenter(printableArea) {
|
|
32
|
+
const { centerX, centerY } = parseBedCorners(printableArea);
|
|
33
|
+
return [centerX, centerY];
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FilamentSlot } from "./extractFilamentSlots.js";
|
|
2
|
+
import type { JsonRecord } from "./types.js";
|
|
3
|
+
export interface BuildFilamentConfigsResult {
|
|
4
|
+
/** arcname (e.g. "Metadata/filament_settings_1.config") -> parsed config JSON object. */
|
|
5
|
+
files: Record<string, JsonRecord>;
|
|
6
|
+
uniqueNames: unknown[] | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Given per-filament-slot dicts (from `extractFilamentSlots`) and the Orca
|
|
10
|
+
* filament shape template, produce deduplicated filament config objects
|
|
11
|
+
* (one per unique `filament_settings_id`) plus the list of unique names in
|
|
12
|
+
* slot order.
|
|
13
|
+
*
|
|
14
|
+
* Returns parsed JSON objects rather than encoded file bytes: the pipeline's response is JSON end-to-end (see
|
|
15
|
+
* `ConfigFilesSchema` in schema.ts), and `applyConvertResponse`
|
|
16
|
+
* (archive/zip.ts) serializes these into the final zip.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildFilamentConfigs(slots: FilamentSlot[], filamentShape: JsonRecord, filamentKeyBlocklist: ReadonlySet<string>): BuildFilamentConfigsResult;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given per-filament-slot dicts (from `extractFilamentSlots`) and the Orca
|
|
3
|
+
* filament shape template, produce deduplicated filament config objects
|
|
4
|
+
* (one per unique `filament_settings_id`) plus the list of unique names in
|
|
5
|
+
* slot order.
|
|
6
|
+
*
|
|
7
|
+
* Returns parsed JSON objects rather than encoded file bytes: the pipeline's response is JSON end-to-end (see
|
|
8
|
+
* `ConfigFilesSchema` in schema.ts), and `applyConvertResponse`
|
|
9
|
+
* (archive/zip.ts) serializes these into the final zip.
|
|
10
|
+
*/
|
|
11
|
+
export function buildFilamentConfigs(slots, filamentShape, filamentKeyBlocklist) {
|
|
12
|
+
if (slots.length === 0) {
|
|
13
|
+
return { files: {}, uniqueNames: null };
|
|
14
|
+
}
|
|
15
|
+
const uniqueNames = [];
|
|
16
|
+
for (const slot of slots) {
|
|
17
|
+
const name = slot.filament_settings_id ?? "Unnamed Filament";
|
|
18
|
+
if (!uniqueNames.some((n) => n === name)) {
|
|
19
|
+
uniqueNames.push(name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const files = {};
|
|
23
|
+
uniqueNames.forEach((name, i) => {
|
|
24
|
+
const idx = i + 1;
|
|
25
|
+
const rep = slots.find((s) => (s.filament_settings_id ?? "Unnamed Filament") === name);
|
|
26
|
+
const cfg = { ...filamentShape };
|
|
27
|
+
for (const [key, val] of Object.entries(rep)) {
|
|
28
|
+
if (filamentKeyBlocklist.has(key))
|
|
29
|
+
continue;
|
|
30
|
+
if (key === "filament_colour") {
|
|
31
|
+
cfg.default_filament_colour = [val];
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (!(key in filamentShape))
|
|
35
|
+
continue;
|
|
36
|
+
cfg[key] = [val];
|
|
37
|
+
}
|
|
38
|
+
// The template's id belongs to one of Snapmaker's own presets; an embedded preset carries its filament's id, or none.
|
|
39
|
+
const ownId = rep.filament_ids;
|
|
40
|
+
if (typeof ownId === "string" && ownId.length > 0)
|
|
41
|
+
cfg.filament_id = ownId;
|
|
42
|
+
else
|
|
43
|
+
delete cfg.filament_id;
|
|
44
|
+
cfg.name = name;
|
|
45
|
+
cfg.filament_settings_id = [name];
|
|
46
|
+
files[`Metadata/filament_settings_${idx}.config`] = cfg;
|
|
47
|
+
});
|
|
48
|
+
return { files, uniqueNames };
|
|
49
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
export type ChangedTriple = [key: string, oldValue: unknown, newValue: unknown];
|
|
3
|
+
export interface BuildProjectSettingsResult {
|
|
4
|
+
newSettings: JsonRecord;
|
|
5
|
+
changedKeys: ChangedTriple[];
|
|
6
|
+
filamentChanged: ChangedTriple[];
|
|
7
|
+
transferableCount: number;
|
|
8
|
+
/** Keys the creator changed whose values couldn't be fitted to the U1's layout, so the U1's stock value was kept (each with a warning). */
|
|
9
|
+
notCarried: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The core project_settings.config merge: transfer whatever's eligible
|
|
13
|
+
* from the Bambu source onto the Orca baseline template, overlay the
|
|
14
|
+
* per-project filament arrays, and rebuild `different_settings_to_system`
|
|
15
|
+
* so Orca doesn't silently fall back to the system preset for anything we
|
|
16
|
+
* changed. Settings that must keep the U1 profile's value are simply never
|
|
17
|
+
* transferred (they're in `blocklist`), so the baseline's stock value stays.
|
|
18
|
+
*
|
|
19
|
+
* @param filamentKeyArrays from `extractFilamentSlots`'s result (`null` when extraction failed -- treated as no overlay).
|
|
20
|
+
* @param blocklist keys that must never transfer from Bambu: physical-hardware/machine-identity keys (`BLOCKLIST`) and keys that keep the U1 profile's own value (`U1_VALUE_KEYS`).
|
|
21
|
+
* @param minComparisonKeys travel_speed/`*_acceleration`-style motion-safety keys: honored only when Bambu's value is LOWER than the U1 profile's own default, unconditionally (not gated on customization) -- see that constant's own doc comment.
|
|
22
|
+
* @param alwaysTransferKeys keys that always track Bambu's real value, unconditionally (not gated on customization, no min-comparison either) -- e.g. print_sequence (layout-coupled) and the infill-density family (Bambu's customization flag doesn't reliably cover them) -- see that constant's own doc comment.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildProjectSettings(baselineSettings: JsonRecord, bambuSettings: JsonRecord, filamentKeyArrays: Record<string, unknown[]> | null, blocklist: ReadonlySet<string>, minComparisonKeys: ReadonlySet<string>, alwaysTransferKeys: ReadonlySet<string>, warnings: string[]): BuildProjectSettingsResult;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
|
|
3
|
+
import { coerceValue } from "./coerceValue.js";
|
|
4
|
+
import { collapseNozzleVariants } from "./collapseNozzleVariants.js";
|
|
5
|
+
import { detectVariantIndex } from "./detectVariantIndex.js";
|
|
6
|
+
import { jsonEqual } from "./internal/jsonEqual.js";
|
|
7
|
+
import { resolveMinIfLower } from "./resolveMinIfLower.js";
|
|
8
|
+
import { stripBambuOnlyNozzleVariantKeys } from "./stripBambuOnlyNozzleVariantKeys.js";
|
|
9
|
+
/** Bambu/Orca both store this as an array whose first element is a `;`-joined key list (remaining elements are unused padding). */
|
|
10
|
+
function parseDifferentSettingsToSystem(value) {
|
|
11
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
12
|
+
return new Set();
|
|
13
|
+
return new Set(String(value[0])
|
|
14
|
+
.split(";")
|
|
15
|
+
.filter((k) => k.length > 0));
|
|
16
|
+
}
|
|
17
|
+
// Older option names Snapmaker Orca still reads and translates itself (Bambu Studio's infill and ironing "zig-zag").
|
|
18
|
+
const LEGACY_CHOICES = new Set(["zig-zag"]);
|
|
19
|
+
/** For a setting with a fixed set of choices, the first value that isn't one Snapmaker Orca offers, if any. */
|
|
20
|
+
function unknownChoice(key, value) {
|
|
21
|
+
const info = Object.hasOwn(SETTINGS_CATALOG, key) ? SETTINGS_CATALOG[key] : undefined;
|
|
22
|
+
if (!info || info.type !== "coEnum" || !info.choices)
|
|
23
|
+
return null;
|
|
24
|
+
for (const entry of Array.isArray(value) ? value : [value]) {
|
|
25
|
+
const text = String(entry);
|
|
26
|
+
if (!info.choices.includes(text) && !LEGACY_CHOICES.has(text))
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The core project_settings.config merge: transfer whatever's eligible
|
|
33
|
+
* from the Bambu source onto the Orca baseline template, overlay the
|
|
34
|
+
* per-project filament arrays, and rebuild `different_settings_to_system`
|
|
35
|
+
* so Orca doesn't silently fall back to the system preset for anything we
|
|
36
|
+
* changed. Settings that must keep the U1 profile's value are simply never
|
|
37
|
+
* transferred (they're in `blocklist`), so the baseline's stock value stays.
|
|
38
|
+
*
|
|
39
|
+
* @param filamentKeyArrays from `extractFilamentSlots`'s result (`null` when extraction failed -- treated as no overlay).
|
|
40
|
+
* @param blocklist keys that must never transfer from Bambu: physical-hardware/machine-identity keys (`BLOCKLIST`) and keys that keep the U1 profile's own value (`U1_VALUE_KEYS`).
|
|
41
|
+
* @param minComparisonKeys travel_speed/`*_acceleration`-style motion-safety keys: honored only when Bambu's value is LOWER than the U1 profile's own default, unconditionally (not gated on customization) -- see that constant's own doc comment.
|
|
42
|
+
* @param alwaysTransferKeys keys that always track Bambu's real value, unconditionally (not gated on customization, no min-comparison either) -- e.g. print_sequence (layout-coupled) and the infill-density family (Bambu's customization flag doesn't reliably cover them) -- see that constant's own doc comment.
|
|
43
|
+
*/
|
|
44
|
+
export function buildProjectSettings(baselineSettings, bambuSettings, filamentKeyArrays, blocklist, minComparisonKeys, alwaysTransferKeys, warnings) {
|
|
45
|
+
// Bambu's OWN customized-keys signal (from the source file, before any
|
|
46
|
+
// of our merging) -- the creator explicitly touched these in Bambu
|
|
47
|
+
// Studio, as opposed to Bambu's file just incidentally reporting its
|
|
48
|
+
// printer/preset's own unmodified default for a key.
|
|
49
|
+
const bambuCustomizedKeys = parseDifferentSettingsToSystem(bambuSettings.different_settings_to_system);
|
|
50
|
+
// A two-nozzle source's per-nozzle values, reduced to the one-value-per-variant layout every step below expects.
|
|
51
|
+
const { settings: source, conflicts, variantIndex: sharedNozzleVariant } = collapseNozzleVariants(bambuSettings);
|
|
52
|
+
const variantIndex = detectVariantIndex(bambuSettings) ?? sharedNozzleVariant;
|
|
53
|
+
const sharedKeys = Object.keys(bambuSettings).filter((k) => Object.hasOwn(baselineSettings, k));
|
|
54
|
+
// Ordinary transfer: only keys the creator explicitly customized in
|
|
55
|
+
// Bambu Studio. Everything else keeps the selected U1 tier's own tuned
|
|
56
|
+
// value (see the customization gate's comment in policy.ts).
|
|
57
|
+
const transferable = sharedKeys
|
|
58
|
+
.filter((k) => !blocklist.has(k) && !minComparisonKeys.has(k) && !alwaysTransferKeys.has(k))
|
|
59
|
+
// Filament arrays and flush volumes are overlaid as a whole below, sized to the project's filaments.
|
|
60
|
+
.filter((k) => !(filamentKeyArrays && Object.hasOwn(filamentKeyArrays, k)) && !k.startsWith("flush_volumes_"))
|
|
61
|
+
.filter((k) => bambuCustomizedKeys.has(k))
|
|
62
|
+
.sort();
|
|
63
|
+
const newSettings = { ...baselineSettings };
|
|
64
|
+
const changedKeys = [];
|
|
65
|
+
const notCarried = [];
|
|
66
|
+
for (const key of transferable) {
|
|
67
|
+
const [newVal, changed, didNotFit] = coerceValue(baselineSettings[key], source[key], key, warnings, variantIndex);
|
|
68
|
+
const unknown = didNotFit ? null : unknownChoice(key, newVal);
|
|
69
|
+
if (unknown !== null) {
|
|
70
|
+
notCarried.push(key);
|
|
71
|
+
warnings.push(` WARN: the creator's ${key} ("${unknown.slice(0, 40)}") isn't one of Snapmaker Orca's choices, so Snapmaker's stock value is used.`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (didNotFit) {
|
|
75
|
+
notCarried.push(key);
|
|
76
|
+
const shown = String(source[key]);
|
|
77
|
+
warnings.push(` WARN: the creator changed ${key}, but its values${shown ? ` (${shown})` : ""} don't fit the U1's layout, so Snapmaker's stock value is used.`);
|
|
78
|
+
}
|
|
79
|
+
if (changed) {
|
|
80
|
+
changedKeys.push([key, baselineSettings[key], newVal]);
|
|
81
|
+
newSettings[key] = newVal;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Motion-safety keys: unconditional (not gated on the customization
|
|
85
|
+
// flag above) -- Bambu's value is honored only when it's lower/more
|
|
86
|
+
// conservative than the U1 tier's own default. See minComparisonKeys.
|
|
87
|
+
const minCompareApplicable = sharedKeys.filter((k) => minComparisonKeys.has(k) && !blocklist.has(k)).sort();
|
|
88
|
+
for (const key of minCompareApplicable) {
|
|
89
|
+
const [newVal, changed] = resolveMinIfLower(baselineSettings[key], source[key], variantIndex);
|
|
90
|
+
if (changed) {
|
|
91
|
+
changedKeys.push([key, baselineSettings[key], newVal]);
|
|
92
|
+
newSettings[key] = newVal;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Layout-coupled keys: unconditional (not gated on the customization
|
|
96
|
+
// flag) -- always track Bambu's real value. See alwaysTransferKeys.
|
|
97
|
+
const alwaysTransferApplicable = sharedKeys.filter((k) => alwaysTransferKeys.has(k) && !blocklist.has(k)).sort();
|
|
98
|
+
for (const key of alwaysTransferApplicable) {
|
|
99
|
+
const [newVal, changed] = coerceValue(baselineSettings[key], source[key], key, warnings, variantIndex);
|
|
100
|
+
const unknown = unknownChoice(key, newVal);
|
|
101
|
+
if (unknown !== null) {
|
|
102
|
+
notCarried.push(key);
|
|
103
|
+
warnings.push(` WARN: the source file's ${key} ("${unknown.slice(0, 40)}") isn't one of Snapmaker Orca's choices, so Snapmaker's stock value is used.`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (changed) {
|
|
107
|
+
changedKeys.push([key, baselineSettings[key], newVal]);
|
|
108
|
+
newSettings[key] = newVal;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// No setting marked as changed, and nothing carried over anyway: an Anycubic Slicer Next export after a
|
|
112
|
+
// printer profile switch looks like this, because the switch resets every setting without marking it,
|
|
113
|
+
// so the creator's tuning is gone before the file is saved. Nothing can recover it; the note says so.
|
|
114
|
+
if (bambuCustomizedKeys.size === 0 && changedKeys.length === 0) {
|
|
115
|
+
warnings.push(" WARN: No changed print settings were marked in this file. If the printer profile was switched in the slicer without re-applying the settings afterward, they may not have carried over.");
|
|
116
|
+
}
|
|
117
|
+
// Only for keys that were actually carried over: a disagreement in a setting the U1 doesn't take from the source isn't news.
|
|
118
|
+
const carried = new Set([...transferable, ...minCompareApplicable, ...alwaysTransferApplicable]);
|
|
119
|
+
for (const [key, values] of conflicts) {
|
|
120
|
+
if (!carried.has(key) || notCarried.includes(key))
|
|
121
|
+
continue;
|
|
122
|
+
warnings.push(` WARN: ${key} differs between the source printer's two nozzles (${values.join(", ")}); the lower value is used for every toolhead.`);
|
|
123
|
+
}
|
|
124
|
+
// Overlay filament identity/color/property arrays (full replacement).
|
|
125
|
+
const filamentChanged = [];
|
|
126
|
+
for (const [key, arr] of Object.entries(filamentKeyArrays ?? {})) {
|
|
127
|
+
const old = newSettings[key];
|
|
128
|
+
if (!jsonEqual(old, arr)) {
|
|
129
|
+
filamentChanged.push([key, old, arr]);
|
|
130
|
+
}
|
|
131
|
+
newSettings[key] = arr;
|
|
132
|
+
}
|
|
133
|
+
// Unconditional safety net, not gated on anything above -- see this
|
|
134
|
+
// function's own doc comment for why a Bambu-only nozzle-variant field
|
|
135
|
+
// must never survive into U1 output regardless of how it got here.
|
|
136
|
+
stripBambuOnlyNozzleVariantKeys(newSettings, baselineSettings);
|
|
137
|
+
// Flag EVERY key we actually write in different_settings_to_system,
|
|
138
|
+
// unconditionally -- not just the ones that changed this merge. Orca
|
|
139
|
+
// doesn't just read project_settings.config at face value -- for any
|
|
140
|
+
// key not listed here, it falls back to whatever LOCAL system preset
|
|
141
|
+
// matches print_settings_id, silently ignoring the value we wrote even
|
|
142
|
+
// though it's correct on disk. Every key is listed: a value equal to the
|
|
143
|
+
// system preset's is harmless to list, while a differing one left
|
|
144
|
+
// unlisted would be silently reverted when the file is opened.
|
|
145
|
+
//
|
|
146
|
+
// A stock baseline has no list of its own (Snapmaker Orca writes none
|
|
147
|
+
// for an unmodified project), so one is created with Orca's layout: the
|
|
148
|
+
// print entry, one entry per filament, then the printer entry.
|
|
149
|
+
const allKeys = Object.keys(newSettings)
|
|
150
|
+
.filter((k) => k !== "different_settings_to_system")
|
|
151
|
+
.sort();
|
|
152
|
+
const diffs = newSettings.different_settings_to_system;
|
|
153
|
+
const filamentCount = Array.isArray(newSettings.filament_colour) ? newSettings.filament_colour.length : 1;
|
|
154
|
+
newSettings.different_settings_to_system = Array.isArray(diffs)
|
|
155
|
+
? [allKeys.join(";"), ...diffs.slice(1)]
|
|
156
|
+
: [allKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), ""];
|
|
157
|
+
return {
|
|
158
|
+
newSettings,
|
|
159
|
+
changedKeys,
|
|
160
|
+
filamentChanged,
|
|
161
|
+
transferableCount: transferable.length + minCompareApplicable.length + alwaysTransferApplicable.length,
|
|
162
|
+
notCarried,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the source file's own layer height on a tier that doesn't match it
|
|
4
|
+
* exactly. The U1 catalog follows Snapmaker's 18 tiers, which leave gaps (e.g. no 0.42mm tier for
|
|
5
|
+
* the 0.6 nozzle; the nearest is 0.30mm Standard). layer_height is normally
|
|
6
|
+
* tier-defining and not transferred, but printing a 0.42mm file at 0.30mm
|
|
7
|
+
* would quietly discard the creator's choice, so the caller turns this on
|
|
8
|
+
* only when it auto-matched a tier that isn't an exact layer-height match.
|
|
9
|
+
* An explicitly chosen tier is never overridden.
|
|
10
|
+
*
|
|
11
|
+
* Clamped to the printer's own min/max layer height. Mutates `settings` in
|
|
12
|
+
* place (a fresh object owned by the pipeline). No-op when the source has
|
|
13
|
+
* no usable layer height or it already equals the tier's.
|
|
14
|
+
*/
|
|
15
|
+
export declare function carrySourceLayerHeight(settings: JsonRecord, sourceSettings: JsonRecord, machineSettings: JsonRecord, warnings: string[]): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function toNumber(raw) {
|
|
2
|
+
const value = typeof raw === "string" ? Number.parseFloat(raw) : typeof raw === "number" ? raw : Number.NaN;
|
|
3
|
+
return Number.isFinite(value) ? value : null;
|
|
4
|
+
}
|
|
5
|
+
/** Tightest bound across every extruder entry (the U1 lists one per toolhead). */
|
|
6
|
+
function bound(raw, pick) {
|
|
7
|
+
const values = (Array.isArray(raw) ? raw : [raw]).map(toNumber).filter((v) => v !== null);
|
|
8
|
+
return values.length > 0 ? pick(values) : null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Keeps the source file's own layer height on a tier that doesn't match it
|
|
12
|
+
* exactly. The U1 catalog follows Snapmaker's 18 tiers, which leave gaps (e.g. no 0.42mm tier for
|
|
13
|
+
* the 0.6 nozzle; the nearest is 0.30mm Standard). layer_height is normally
|
|
14
|
+
* tier-defining and not transferred, but printing a 0.42mm file at 0.30mm
|
|
15
|
+
* would quietly discard the creator's choice, so the caller turns this on
|
|
16
|
+
* only when it auto-matched a tier that isn't an exact layer-height match.
|
|
17
|
+
* An explicitly chosen tier is never overridden.
|
|
18
|
+
*
|
|
19
|
+
* Clamped to the printer's own min/max layer height. Mutates `settings` in
|
|
20
|
+
* place (a fresh object owned by the pipeline). No-op when the source has
|
|
21
|
+
* no usable layer height or it already equals the tier's.
|
|
22
|
+
*/
|
|
23
|
+
export function carrySourceLayerHeight(settings, sourceSettings, machineSettings, warnings) {
|
|
24
|
+
const source = toNumber(sourceSettings.layer_height);
|
|
25
|
+
const tier = toNumber(settings.layer_height);
|
|
26
|
+
if (source === null || tier === null || source === tier)
|
|
27
|
+
return;
|
|
28
|
+
const min = bound(machineSettings.min_layer_height, (v) => Math.max(...v));
|
|
29
|
+
const max = bound(machineSettings.max_layer_height, (v) => Math.min(...v));
|
|
30
|
+
let kept = source;
|
|
31
|
+
if (min !== null && kept < min)
|
|
32
|
+
kept = min;
|
|
33
|
+
if (max !== null && kept > max)
|
|
34
|
+
kept = max;
|
|
35
|
+
if (kept === tier)
|
|
36
|
+
return;
|
|
37
|
+
settings.layer_height = String(kept);
|
|
38
|
+
warnings.push(kept === source
|
|
39
|
+
? ` WARN: the U1 has no ${source}mm profile for this nozzle size, so your file's ${source}mm layer height was kept, on the closest profile (${tier}mm).`
|
|
40
|
+
: ` WARN: your file's ${source}mm layer height is outside what the U1 supports for this nozzle size, so it was set to ${kept}mm, on the closest profile (${tier}mm).`);
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Snapmaker Orca 2.4.1 added `top_color_penetration_layers` and
|
|
4
|
+
* `bottom_color_penetration_layers` (how deep painted color reaches into
|
|
5
|
+
* the shell). When a value is larger than the shell has layers, Snapmaker Orca shows
|
|
6
|
+
* "The paint penetration layers (current: N) exceed the shell layers
|
|
7
|
+
* (current: M)... will be reset automatically" and resets it itself. A
|
|
8
|
+
* creator's own shell setting (say 3 top layers) can be lower than the
|
|
9
|
+
* tier's default penetration, so apply the same reset up front: no dialog,
|
|
10
|
+
* same result. Only a value larger than its shell layer count changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clampColorPenetration(settings: JsonRecord, notes: string[]): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapmaker Orca 2.4.1 added `top_color_penetration_layers` and
|
|
3
|
+
* `bottom_color_penetration_layers` (how deep painted color reaches into
|
|
4
|
+
* the shell). When a value is larger than the shell has layers, Snapmaker Orca shows
|
|
5
|
+
* "The paint penetration layers (current: N) exceed the shell layers
|
|
6
|
+
* (current: M)... will be reset automatically" and resets it itself. A
|
|
7
|
+
* creator's own shell setting (say 3 top layers) can be lower than the
|
|
8
|
+
* tier's default penetration, so apply the same reset up front: no dialog,
|
|
9
|
+
* same result. Only a value larger than its shell layer count changes.
|
|
10
|
+
*/
|
|
11
|
+
export function clampColorPenetration(settings, notes) {
|
|
12
|
+
for (const side of ["top", "bottom"]) {
|
|
13
|
+
const penetrationKey = `${side}_color_penetration_layers`;
|
|
14
|
+
const penetration = toWholeNumber(settings[penetrationKey]);
|
|
15
|
+
const shellLayers = toWholeNumber(settings[`${side}_shell_layers`]);
|
|
16
|
+
if (penetration === null || shellLayers === null || penetration <= shellLayers)
|
|
17
|
+
continue;
|
|
18
|
+
settings[penetrationKey] = String(shellLayers);
|
|
19
|
+
notes.push(` ${penetrationKey} lowered from ${penetration} to ${shellLayers} to fit the ${side} shell layers, as Snapmaker Orca does when opening it.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function toWholeNumber(value) {
|
|
23
|
+
const single = Array.isArray(value) ? value[0] : value;
|
|
24
|
+
if (typeof single !== "string" && typeof single !== "number")
|
|
25
|
+
return null;
|
|
26
|
+
const parsed = Number(single);
|
|
27
|
+
return Number.isInteger(parsed) && parsed >= 0 ? parsed : null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { JsonRecord } from "./types.js";
|
|
2
|
+
/** Print and travel speeds, mm/s. Limited by the machine's X/Y maximum speed. */
|
|
3
|
+
export declare const SPEED_KEYS: readonly ["outer_wall_speed", "inner_wall_speed", "sparse_infill_speed", "internal_solid_infill_speed", "top_surface_speed", "gap_infill_speed", "bridge_speed", "support_speed", "support_interface_speed", "ironing_speed", "initial_layer_speed", "initial_layer_infill_speed", "overhang_1_4_speed", "overhang_2_4_speed", "overhang_3_4_speed", "overhang_4_4_speed", "skirt_speed", "travel_speed"];
|
|
4
|
+
/** Accelerations while extruding, mm/s². Limited by the machine's maximum extruding acceleration. */
|
|
5
|
+
export declare const EXTRUDING_ACCELERATION_KEYS: readonly ["default_acceleration", "outer_wall_acceleration", "inner_wall_acceleration", "top_surface_acceleration", "initial_layer_acceleration", "bridge_acceleration", "sparse_infill_acceleration", "internal_solid_infill_acceleration"];
|
|
6
|
+
/**
|
|
7
|
+
* Caps speeds and accelerations that came from the source file at the U1's
|
|
8
|
+
* own machine limits from its profile (machine_max_speed_x/y,
|
|
9
|
+
* machine_max_acceleration_extruding/travel), never at any particular source
|
|
10
|
+
* printer's numbers. A source made for a faster printer can't ask the U1 for
|
|
11
|
+
* more than it allows.
|
|
12
|
+
*
|
|
13
|
+
* Snapmaker's stock values are never changed, even where Snapmaker's profile
|
|
14
|
+
* sets one above its own machine limit (the 0.20mm Standard high-flow speeds
|
|
15
|
+
* are 600 mm/s against a 500 mm/s limit); the printer applies the limit to
|
|
16
|
+
* those itself. So only entries that differ from the U1 profile's own value
|
|
17
|
+
* are capped. Percentages (relative to another setting) and "nil" entries
|
|
18
|
+
* are left alone, and so is any setting whose limit the machine profile
|
|
19
|
+
* doesn't give.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clampToMachineLimits(settings: JsonRecord, baseline: JsonRecord, machineSettings: JsonRecord, warnings: string[]): void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Print and travel speeds, mm/s. Limited by the machine's X/Y maximum speed. */
|
|
2
|
+
export const SPEED_KEYS = [
|
|
3
|
+
"outer_wall_speed",
|
|
4
|
+
"inner_wall_speed",
|
|
5
|
+
"sparse_infill_speed",
|
|
6
|
+
"internal_solid_infill_speed",
|
|
7
|
+
"top_surface_speed",
|
|
8
|
+
"gap_infill_speed",
|
|
9
|
+
"bridge_speed",
|
|
10
|
+
"support_speed",
|
|
11
|
+
"support_interface_speed",
|
|
12
|
+
"ironing_speed",
|
|
13
|
+
"initial_layer_speed",
|
|
14
|
+
"initial_layer_infill_speed",
|
|
15
|
+
"overhang_1_4_speed",
|
|
16
|
+
"overhang_2_4_speed",
|
|
17
|
+
"overhang_3_4_speed",
|
|
18
|
+
"overhang_4_4_speed",
|
|
19
|
+
"skirt_speed",
|
|
20
|
+
"travel_speed",
|
|
21
|
+
];
|
|
22
|
+
/** Accelerations while extruding, mm/s². Limited by the machine's maximum extruding acceleration. */
|
|
23
|
+
export const EXTRUDING_ACCELERATION_KEYS = [
|
|
24
|
+
"default_acceleration",
|
|
25
|
+
"outer_wall_acceleration",
|
|
26
|
+
"inner_wall_acceleration",
|
|
27
|
+
"top_surface_acceleration",
|
|
28
|
+
"initial_layer_acceleration",
|
|
29
|
+
"bridge_acceleration",
|
|
30
|
+
"sparse_infill_acceleration",
|
|
31
|
+
"internal_solid_infill_acceleration",
|
|
32
|
+
];
|
|
33
|
+
function firstNumber(value) {
|
|
34
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
35
|
+
const n = typeof raw === "string" || typeof raw === "number" ? Number(raw) : NaN;
|
|
36
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Caps speeds and accelerations that came from the source file at the U1's
|
|
40
|
+
* own machine limits from its profile (machine_max_speed_x/y,
|
|
41
|
+
* machine_max_acceleration_extruding/travel), never at any particular source
|
|
42
|
+
* printer's numbers. A source made for a faster printer can't ask the U1 for
|
|
43
|
+
* more than it allows.
|
|
44
|
+
*
|
|
45
|
+
* Snapmaker's stock values are never changed, even where Snapmaker's profile
|
|
46
|
+
* sets one above its own machine limit (the 0.20mm Standard high-flow speeds
|
|
47
|
+
* are 600 mm/s against a 500 mm/s limit); the printer applies the limit to
|
|
48
|
+
* those itself. So only entries that differ from the U1 profile's own value
|
|
49
|
+
* are capped. Percentages (relative to another setting) and "nil" entries
|
|
50
|
+
* are left alone, and so is any setting whose limit the machine profile
|
|
51
|
+
* doesn't give.
|
|
52
|
+
*/
|
|
53
|
+
export function clampToMachineLimits(settings, baseline, machineSettings, warnings) {
|
|
54
|
+
const maxSpeed = Math.min(firstNumber(machineSettings.machine_max_speed_x) ?? Infinity, firstNumber(machineSettings.machine_max_speed_y) ?? Infinity);
|
|
55
|
+
const maxExtruding = firstNumber(machineSettings.machine_max_acceleration_extruding) ?? Infinity;
|
|
56
|
+
const maxTravel = firstNumber(machineSettings.machine_max_acceleration_travel) ?? Infinity;
|
|
57
|
+
const limits = [
|
|
58
|
+
[SPEED_KEYS, maxSpeed, "mm/s"],
|
|
59
|
+
[EXTRUDING_ACCELERATION_KEYS, maxExtruding, "mm/s²"],
|
|
60
|
+
[["travel_acceleration"], maxTravel, "mm/s²"],
|
|
61
|
+
];
|
|
62
|
+
for (const [keys, limit, unit] of limits) {
|
|
63
|
+
if (!Number.isFinite(limit))
|
|
64
|
+
continue;
|
|
65
|
+
for (const key of keys) {
|
|
66
|
+
const value = settings[key];
|
|
67
|
+
if (value === undefined)
|
|
68
|
+
continue;
|
|
69
|
+
const stock = baseline[key];
|
|
70
|
+
const stockEntry = (i) => (Array.isArray(stock) ? (stock[i] ?? stock[0]) : stock);
|
|
71
|
+
const clamp = (entry, i) => {
|
|
72
|
+
if (typeof entry !== "string" || entry.endsWith("%") || entry === "nil" || entry === stockEntry(i))
|
|
73
|
+
return entry;
|
|
74
|
+
const n = Number(entry);
|
|
75
|
+
return Number.isFinite(n) && n > limit ? String(limit) : entry;
|
|
76
|
+
};
|
|
77
|
+
const clamped = Array.isArray(value) ? value.map(clamp) : clamp(value, 0);
|
|
78
|
+
if (JSON.stringify(clamped) !== JSON.stringify(value)) {
|
|
79
|
+
settings[key] = clamped;
|
|
80
|
+
warnings.push(` WARN: ${key} lowered to ${limit} ${unit}, the U1's machine limit.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconcile a single settings key's value between the Orca baseline
|
|
3
|
+
* template and the Bambu source when their types/lengths differ.
|
|
4
|
+
*
|
|
5
|
+
* @param variantIndex which column to prefer when `bambuVal` is a
|
|
6
|
+
* per-nozzle-variant array with genuinely differing values (see
|
|
7
|
+
* detectVariantIndex.ts) -- `null` means no signal was available, so
|
|
8
|
+
* the first value is used and flagged for manual review, same as
|
|
9
|
+
* before that mechanism existed.
|
|
10
|
+
* @returns `[newValue, changed]` — `changed` is true only when the
|
|
11
|
+
* resolved value actually differs from the baseline's — plus a third
|
|
12
|
+
* element, `true`, when Bambu's value couldn't be fitted at all and the
|
|
13
|
+
* baseline's was kept instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function coerceValue(baselineVal: unknown, bambuVal: unknown, key: string, warnings: string[], variantIndex?: number | null): [unknown, boolean, true?];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { jsonEqual } from "./internal/jsonEqual.js";
|
|
3
|
+
/** True if every element of a non-empty array is equal to the first. */
|
|
4
|
+
function allSame(arr) {
|
|
5
|
+
return arr.length > 0 && arr.every((v) => jsonEqual(v, arr[0]));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reconcile a single settings key's value between the Orca baseline
|
|
9
|
+
* template and the Bambu source when their types/lengths differ.
|
|
10
|
+
*
|
|
11
|
+
* @param variantIndex which column to prefer when `bambuVal` is a
|
|
12
|
+
* per-nozzle-variant array with genuinely differing values (see
|
|
13
|
+
* detectVariantIndex.ts) -- `null` means no signal was available, so
|
|
14
|
+
* the first value is used and flagged for manual review, same as
|
|
15
|
+
* before that mechanism existed.
|
|
16
|
+
* @returns `[newValue, changed]` — `changed` is true only when the
|
|
17
|
+
* resolved value actually differs from the baseline's — plus a third
|
|
18
|
+
* element, `true`, when Bambu's value couldn't be fitted at all and the
|
|
19
|
+
* baseline's was kept instead.
|
|
20
|
+
*/
|
|
21
|
+
export function coerceValue(baselineVal, bambuVal, key, warnings, variantIndex = null) {
|
|
22
|
+
const baselineIsList = Array.isArray(baselineVal);
|
|
23
|
+
const bambuIsList = Array.isArray(bambuVal);
|
|
24
|
+
if (baselineIsList && bambuIsList) {
|
|
25
|
+
if (baselineVal.length === bambuVal.length) {
|
|
26
|
+
return [bambuVal, !jsonEqual(bambuVal, baselineVal)];
|
|
27
|
+
}
|
|
28
|
+
if (allSame(bambuVal)) {
|
|
29
|
+
const broadcast = new Array(baselineVal.length).fill(bambuVal[0]);
|
|
30
|
+
return [broadcast, !jsonEqual(broadcast, baselineVal)];
|
|
31
|
+
}
|
|
32
|
+
warnings.push(` SKIP ${key}: list length mismatch (template=${baselineVal.length}, ` +
|
|
33
|
+
`source=${bambuVal.length}) and the source's values aren't uniform; left unchanged.`);
|
|
34
|
+
return [baselineVal, false, true];
|
|
35
|
+
}
|
|
36
|
+
if (baselineIsList && !bambuIsList) {
|
|
37
|
+
const broadcast = new Array(baselineVal.length).fill(bambuVal);
|
|
38
|
+
return [broadcast, !jsonEqual(broadcast, baselineVal)];
|
|
39
|
+
}
|
|
40
|
+
if (!baselineIsList && bambuIsList) {
|
|
41
|
+
if (allSame(bambuVal)) {
|
|
42
|
+
return [bambuVal[0], !jsonEqual(bambuVal[0], baselineVal)];
|
|
43
|
+
}
|
|
44
|
+
if (variantIndex !== null && variantIndex < bambuVal.length) {
|
|
45
|
+
const chosen = bambuVal[variantIndex];
|
|
46
|
+
warnings.push(` NOTE ${key}: the source file has one value per nozzle variant ${JSON.stringify(bambuVal)}; ` +
|
|
47
|
+
`using the one matching the installed nozzle variant (${JSON.stringify(chosen)}).`);
|
|
48
|
+
return [chosen, !jsonEqual(chosen, baselineVal)];
|
|
49
|
+
}
|
|
50
|
+
warnings.push(` WARN ${key}: the U1 takes one value but the source file has differing ` +
|
|
51
|
+
`per-extruder values ${JSON.stringify(bambuVal)}; using the first value ` +
|
|
52
|
+
`(${JSON.stringify(bambuVal[0])}). Review this one manually.`);
|
|
53
|
+
return [bambuVal[0], !jsonEqual(bambuVal[0], baselineVal)];
|
|
54
|
+
}
|
|
55
|
+
return [bambuVal, !jsonEqual(bambuVal, baselineVal)];
|
|
56
|
+
}
|