diff --git a/backend/snapstudio_api/routes_calibration.py b/backend/snapstudio_api/routes_calibration.py index efc4967a..41958f35 100644 --- a/backend/snapstudio_api/routes_calibration.py +++ b/backend/snapstudio_api/routes_calibration.py @@ -60,9 +60,15 @@ def evaluate(data: dict) -> tuple[int, dict]: family = data.get("family") if family not in ("frontlit", "backlit"): raise rv.ValidationError("Invalid 'family'") + material = rv.require_bounded_str(data, "material", 32) if "material" in data else "PLA" + if not material.strip(): + raise rv.ValidationError("Material must not be empty") basis = service.basis_document(family, rv.require_positive_float(data, "layer_height_mm"), rv.optional_positive_float(data, "nozzle_mm", 0.4), - rv.optional_bounded_str(data, "material", 32) or "PLA") + material, + source=source, model=rv.optional_bounded_str(data, "model", 128), + first_layer_height_mm=rv.require_positive_float(data, "first_layer_height_mm") + if "first_layer_height_mm" in data else None) palette = decoded.value.to_dict() result = service.evaluate(palette, basis, _colors(data), _owned(data)) saved = service.save_run(basis, palette, result, data_dir=paths.data_dir()) diff --git a/backend/snapstudio_core/calibration/README.md b/backend/snapstudio_core/calibration/README.md new file mode 100644 index 00000000..4b3364d3 --- /dev/null +++ b/backend/snapstudio_core/calibration/README.md @@ -0,0 +1,44 @@ +# Palette calibration input and history + +DitherForge TXT accepts `#RRGGBB 1.9 Label`, a label without TD, and the +`td=1.9` form. Lines starting with `# `, `;` or `//` are comments. Missing TD +is explicitly nominal (1.0), never a measurement. Invalid or conflicting TD +is not replaced with a nominal value. The earlier Studio `td Label` syntax +remains readable for compatibility. + +Kromacut v2 `.kpal` files are JSON objects with `version: 2`, `colors`, +optional `colorNames` and optional `disabledColors` indices. Indices remain +in their original positions. Disabled colours are shown but receive no +physical reading or owned-filament suggestion. The earlier Studio `palette` +row representation remains readable; it is not the upstream export format. +Palette-library arrays and unsupported schema versions are not evaluated. + +The screen accepts TXT, JSON and KPAL. Physical observations and owned spool +colours start empty. Changing the palette or the calibration basis clears +observations and invalidates an in-flight result. File reads also have an +identity guard, so an older import cannot replace a later selection. + +The visible basis includes family, layer height, first-layer height, nozzle, +material, palette source and an optional user-entered model/revision label. +These fields participate in the basis hash. The label is not a verified model +file identity. Omitted first-layer/model/source data on older history remains +unknown. This changes no database schema: extended basis data stays in the +existing saved comparison payload. History is local, newest first, up to 50; +viewing it never reapplies old readings to current input. + +The results are advisory RGB comparisons. No printer, spectrometer or +physical calibration is performed. Tests use synthetic fixtures conforming +to pinned upstream contracts, rather than captured physical readings. + +Contract references: +- [DitherForge README](https://github.com/rtwfroody/ditherforge/blob/4d3552a434e8084d9b5fe573959a3493325be29f/README.md) +- [Kromacut palette manager](https://github.com/vycdev/Kromacut/blob/94874755426ee7f33b3684a5544e7fab0e2e73f7/src/lib/paletteManager.ts) + + +Review follow-up: every explicit TD token is checked, repeated td= assignments +are refused, and leading/fallback values must agree. A blank material is refused; +only an omitted material retains the legacy PLA default. Blank model labels become +unknown. The expanded basis/palette documents change their hashes: pre-change +identities are not reproduced, and old saved comparisons are left untouched. +A numeric leading label such as `#FF0000 2 Tone` is interpreted as TD 2 by the +documented upstream grammar, rather than a label beginning with the number 2. diff --git a/backend/snapstudio_core/calibration/palette.py b/backend/snapstudio_core/calibration/palette.py index 07f21afc..5fa733f7 100644 --- a/backend/snapstudio_core/calibration/palette.py +++ b/backend/snapstudio_core/calibration/palette.py @@ -17,10 +17,11 @@ class PaletteEntry: color: str td: float td_provenance: str + enabled: bool = True def to_dict(self) -> dict: return {"label": self.label, "color": self.color, "td": self.td, - "td_provenance": self.td_provenance} + "td_provenance": self.td_provenance, "enabled": self.enabled} @dataclass @@ -48,35 +49,35 @@ def parse_ditherforge(text: str) -> Decoded[Palette]: diagnostics: list[Diagnostic] = [] for number, line in enumerate(text.splitlines(), 1): stripped = line.strip() - if not stripped or stripped.startswith(";") or stripped.startswith("//"): + if not stripped or stripped.startswith(";") or stripped.startswith("//") or stripped.startswith("# "): continue - # `td=` is a fallback syntax and may appear after the optional label. match = _DITHER.match(stripped) if not match: diagnostics.append(diag("invalid_palette_line", f"line:{number}", ERROR)) continue color, remainder = match.groups() remainder = remainder or "" - # The documented `td label` shape carries a label with no measured TD. - # A numeric value can follow `td`, while `td=` is the fallback form. - fallback = re.search(r"\btd\s*=\s*([0-9.eE+-]+)", remainder, re.IGNORECASE) - td_text = fallback.group(1) if fallback else None - label = remainder - leading_td = re.match(r"^td(?:\s+([0-9.eE+-]+))?(?:\s+|$)(.*)$", remainder, re.IGNORECASE) + assignments = list(re.finditer(r"\btd\s*=\s*(\S*)", remainder, re.IGNORECASE)) + values = [item.group(1) for item in assignments] + label = re.sub(r"\btd\s*=\s*\S*", "", remainder, flags=re.IGNORECASE).strip() + leading_td = re.match(r"^td(?:\s+([0-9.eE+-]+))?(?:\s+|$)(.*)$", label, re.IGNORECASE) + numeric = re.match(r"^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)(?:\s+|$)(.*)$", label) if leading_td: if leading_td.group(1) is not None: - td_text = leading_td.group(1) + values.append(leading_td.group(1)) label = leading_td.group(2) - if fallback: - label = re.sub(r"\btd\s*=\s*[0-9.eE+-]+", "", label or "", flags=re.IGNORECASE).strip() + elif numeric: + values.append(numeric.group(1)) + label = numeric.group(2) try: - td = float(td_text) if td_text is not None else 1.0 + numbers = [float(value) for value in values] except ValueError: - diagnostics.append(diag("invalid_td", f"line:{number}", ERROR)) - continue - if not (td > 0 and td < float("inf")): - diagnostics.append(diag("invalid_td", f"line:{number}", ERROR)) + numbers = [float("nan")] + if len(assignments) > 1 or any(not (0 < value < float("inf")) for value in numbers) or len(set(numbers)) > 1: + diagnostics.append(diag("invalid_or_conflicting_td", f"line:{number}", ERROR)) continue + td = numbers[0] if numbers else 1.0 + td_text = values[0] if values else None entries.append(PaletteEntry((label or f"Color {len(entries) + 1}").strip(), f"#{color.upper()}", td, "provided" if td_text is not None else "derived")) @@ -88,6 +89,31 @@ def parse_ditherforge(text: str) -> Decoded[Palette]: def _build_kromacut(reader) -> Palette: + # Kromacut v2 exports parallel arrays in a .kpal JSON object. Keep every + # original index, including disabled colours, so readings cannot shift rows. + if "colors" in reader.raw: + colors = reader.raw["colors"] + names = reader.raw.get("colorNames", []) + disabled = reader.raw.get("disabledColors", []) + if not isinstance(colors, list) or not colors or len(colors) > 256: + reader.error("invalid_colors", "colors") + return Palette("kromacut_json_v2", []) + if not isinstance(names, list) or len(names) > len(colors) or any(not isinstance(n, str) or len(n) > 256 for n in names): + reader.error("invalid_color_names", "colorNames") + return Palette("kromacut_json_v2", []) + if not isinstance(disabled, list) or any(type(i) is not int or not 0 <= i < len(colors) for i in disabled): + reader.error("invalid_disabled_colors", "disabledColors") + return Palette("kromacut_json_v2", []) + entries = [] + for index, raw_color in enumerate(colors): + color = _color(raw_color) + if color is None: + reader.error("invalid_color", f"colors[{index}]") + continue + label = names[index].strip() if index < len(names) else "" + entries.append(PaletteEntry(label or f"Color {index + 1}", color, 1.0, "derived", index not in disabled)) + return Palette("kromacut_json_v2", entries) + # Retain the earlier Studio row representation for saved fixtures. rows = reader.items("palette", required=True) if not rows: reader.error("empty_palette", "palette") diff --git a/backend/snapstudio_core/calibration/service.py b/backend/snapstudio_core/calibration/service.py index 16192b38..0bfccacd 100644 --- a/backend/snapstudio_core/calibration/service.py +++ b/backend/snapstudio_core/calibration/service.py @@ -30,21 +30,32 @@ """ -def basis_document(family: str, layer_height_mm: float, nozzle_mm: float, material: str) -> dict: +def basis_document(family: str, layer_height_mm: float, nozzle_mm: float, material: str, + *, source: str | None = None, model: str | None = None, + first_layer_height_mm: float | None = None) -> dict: if family not in ("frontlit", "backlit"): raise ValueError("family must be frontlit or backlit") - values = (layer_height_mm, nozzle_mm) + values = (layer_height_mm, nozzle_mm) + (() if first_layer_height_mm is None else (first_layer_height_mm,)) + if not isinstance(material, str) or not material.strip() or len(material) > 32: + raise ValueError("material must be a non-empty name of at most 32 characters") + if source not in (None, "ditherforge_txt", "kromacut_json"): + raise ValueError("unknown palette source") + if model is not None and (not isinstance(model, str) or len(model) > 128): + raise ValueError("model must be at most 128 characters") if any(isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(v) or v <= 0 for v in values): raise ValueError("layer height and nozzle must be positive finite numbers") normalized = {"family": family, "layer_height_mm": round(float(layer_height_mm), 4), "nozzle_mm": round(float(nozzle_mm), 4), "material": material.strip().upper()} + normalized.update(source=source, model=(model.strip() or None) if model else None, + first_layer_height_mm=round(float(first_layer_height_mm), 4) if first_layer_height_mm is not None else None) return {**normalized, "calibration_basis_id": "calibration-basis:" + content_hash(normalized).split(":", 1)[1]} def evaluate(palette: dict, basis: dict, physical_colors: dict[str, str], owned_filaments: list[dict]) -> dict: entries = [] for index, item in enumerate(palette["entries"]): - physical = physical_colors.get(str(index)) + enabled = item.get("enabled", True) + physical = physical_colors.get(str(index)) if enabled else None alternatives = [] for spool in owned_filaments: color = spool.get("color") if isinstance(spool, dict) else None @@ -57,7 +68,7 @@ def evaluate(palette: dict, basis: dict, physical_colors: dict[str, str], owned_ entries.append({"label": item["label"], "simulated_color": item["color"], "physical_color": physical, "physical_distance": material_plan.colour_distance( item["color"], physical), "td": item["td"], - "td_provenance": item["td_provenance"], "alternatives": alternatives[:3]}) + "td_provenance": item["td_provenance"], "enabled": enabled, "alternatives": alternatives[:3] if enabled else []}) return {"calibration_basis": basis, "entries": entries, "advisory": "Palette colours are simulated targets; physical readings are separate observations. Owned-filament matches are advisory."} diff --git a/backend/tests/calibration/test_real_palette_formats.py b/backend/tests/calibration/test_real_palette_formats.py new file mode 100644 index 00000000..ca115192 --- /dev/null +++ b/backend/tests/calibration/test_real_palette_formats.py @@ -0,0 +1,73 @@ +import json +import pytest +from snapstudio_core.calibration import palette, service + +def test_upstream_ditherforge_numeric_td_and_comments(): + result = palette.parse_ditherforge("# Collection comment\n#FF0000 1.9 Red\n#00FF00 0.4 Green\n#0000FF Blue") + assert result.valid_for_evaluation + assert [(e.label,e.td,e.td_provenance) for e in result.value.entries] == [ + ("Red",1.9,"provided"),("Green",0.4,"provided"),("Blue",1.0,"derived")] + +@pytest.mark.parametrize("td", ["0", "-1", "1e999"]) +def test_numeric_td_must_be_positive_finite(td): + assert palette.parse_ditherforge(f"#FF0000 {td} Red").value is None + +def test_kromacut_exported_v2_colors_names_and_disabled_indices(): + raw = {"version":2,"name":"Synthetic palette","colors":["#FF0000","#00FF00"], + "colorNames":["Red","Green"],"disabledColors":[1],"createdAt":1,"updatedAt":1} + result=palette.parse_kromacut(json.dumps(raw)) + assert result.valid_for_evaluation + assert [e.color for e in result.value.entries] == ["#FF0000","#00FF00"] + assert [e.label for e in result.value.entries] == ["Red","Green"] + assert [e.enabled for e in result.value.entries] == [True,False] + assert all(e.td_provenance=="derived" for e in result.value.entries) + +@pytest.mark.parametrize("changes", [ + {"colors":["not-a-colour"]},{"disabledColors":[9]},{"disabledColors":[True]}, + {"colorNames":"not-an-array"}]) +def test_invalid_kpal_metadata_is_refused(changes): + raw={"version":2,"colors":["#FF0000"],"colorNames":["Red"],"disabledColors":[]} + assert palette.parse_kromacut({**raw,**changes}).value is None + +def test_basis_distinguishes_generator_model_and_first_layer(): + common=("frontlit",0.2,0.4,"PLA") + a=service.basis_document(*common,source="ditherforge_txt",model="swatch-A",first_layer_height_mm=0.2) + for changes in [dict(source="kromacut_json"),dict(model="swatch-B"),dict(first_layer_height_mm=0.3)]: + b=service.basis_document(*common,**{**dict(source="ditherforge_txt",model="swatch-A",first_layer_height_mm=0.2),**changes}) + assert a["calibration_basis_id"] != b["calibration_basis_id"] + +def test_disabled_color_keeps_its_index_without_claiming_a_physical_reading(): + from snapstudio_core.calibration.service import evaluate + parsed = palette.parse_kromacut({"version": 2, "colors": ["#112233", "#445566"], "disabledColors": [0]}).value.to_dict() + result = evaluate(parsed, service.basis_document("frontlit", .2, .4, "PLA"), {"0": "#aaaaaa", "1": "#bbbbbb"}, []) + assert result["entries"][0]["enabled"] is False + assert result["entries"][0]["physical_color"] is None + assert result["entries"][1]["physical_color"] == "#bbbbbb" + +def test_route_persists_basis_identity_and_real_kpal_rows(tmp_path, monkeypatch): + from snapstudio_api.routes_calibration import evaluate, get_history + import json + monkeypatch.setenv("SNAPSTUDIO_DATA_DIR", str(tmp_path)) + code, body = evaluate({"source": "kromacut_json", "content": json.dumps({"version": 2, "colors": ["#123456"]}), + "family": "backlit", "layer_height_mm": .16, "nozzle_mm": .6, "material": "PETG", "model": "synthetic-swatch-2", "first_layer_height_mm": .24}) + assert code == 200 and body["status"] == "evaluated" + basis = body["result"]["calibration_basis"] + assert basis["source"] == "kromacut_json" and basis["model"] == "synthetic-swatch-2" + assert basis["first_layer_height_mm"] == .24 and basis["nozzle_mm"] == .6 + assert get_history({})[1]["runs"][0]["calibration_basis"] == basis + +@pytest.mark.parametrize("row", ["#FF0000 td=oops Red", "#FF0000 td=1.2junk Red", "#FF0000 1.9 Red td=1..2", "#FF0000 1.9 Red td=2"]) +def test_invalid_or_conflicting_td_does_not_fall_back_to_nominal(row): + assert palette.parse_ditherforge(row).value is None + +@pytest.mark.parametrize("row", ["#FF0000 1.9 Red td=1.9 td=2", "#FF0000 td=1.9 Red td=oops", "#FF0000 td 1.9 Red td=2", "#FF0000 td=1.9 td=1.9"]) +def test_all_explicit_td_values_are_validated(row): + assert palette.parse_ditherforge(row).value is None + +@pytest.mark.parametrize("material", ["", " "]) +def test_empty_material_is_not_silently_replaced_with_pla(tmp_path, monkeypatch, material): + from snapstudio_api.routes_calibration import evaluate + from snapstudio_api.request_validation import ValidationError + monkeypatch.setenv("SNAPSTUDIO_DATA_DIR", str(tmp_path)) + with pytest.raises(ValidationError): + evaluate({"source":"ditherforge_txt", "content":"#FF0000 Red", "family":"frontlit", "layer_height_mm":.2, "material": material}) diff --git a/desktop/src/lib/calibration/CalibrationView.test.tsx b/desktop/src/lib/calibration/CalibrationView.test.tsx new file mode 100644 index 00000000..5123b3f9 --- /dev/null +++ b/desktop/src/lib/calibration/CalibrationView.test.tsx @@ -0,0 +1,63 @@ +// @vitest-environment jsdom +import React from "react"; +import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { afterEach, beforeEach, expect, it, vi } from "vitest"; +import CalibrationView from "./CalibrationView"; +import { calibrationHistory, evaluateCalibration } from "@/lib/calibrationApi"; +vi.mock("@/lib/calibrationApi", () => ({ evaluateCalibration: vi.fn(), calibrationHistory: vi.fn() })); +const unknown = { status: "unknown", decoded: { diagnostics: [{ code: "old-result" }] }, result: null }; +beforeEach(() => vi.clearAllMocks()); +afterEach(cleanup); + +it("starts without invented physical readings and sends the visible basis", async () => { + vi.mocked(evaluateCalibration).mockResolvedValue(unknown as never); + render(); + expect((screen.getByLabelText("Physical colors") as HTMLTextAreaElement).value).toBe(""); + expect((screen.getByLabelText("Owned filaments") as HTMLTextAreaElement).value).toBe(""); + fireEvent.change(screen.getByLabelText("Nozzle diameter"), { target: { value: "0.6" } }); + fireEvent.change(screen.getByLabelText("Material"), { target: { value: "PETG" } }); + fireEvent.change(screen.getByLabelText("Calibration model"), { target: { value: "swatch-B" } }); + fireEvent.change(screen.getByLabelText("First layer height"), { target: { value: "0.3" } }); + fireEvent.click(screen.getByText("Compare palette")); + await waitFor(() => expect(evaluateCalibration).toHaveBeenCalledWith(expect.objectContaining({ nozzle_mm: 0.6, material: "PETG", model: "swatch-B", first_layer_height_mm: 0.3, physical_colors: {} }))); +}); + +it("clears readings when palette content or format changes", () => { + render(); + const readings = screen.getByLabelText("Physical colors") as HTMLTextAreaElement; + fireEvent.change(readings, { target: { value: "#123456" } }); + fireEvent.change(screen.getByLabelText("Palette content"), { target: { value: "#abcdef 1.2 New" } }); + expect(readings.value).toBe(""); + fireEvent.change(readings, { target: { value: "#123456" } }); + fireEvent.change(screen.getByLabelText("Palette format"), { target: { value: "kromacut_json" } }); + expect(readings.value).toBe(""); +}); + +it("ignores an evaluation completed after inputs change", async () => { + let finish!: (r: never) => void; + vi.mocked(evaluateCalibration).mockReturnValue(new Promise(resolve => { finish = resolve; })); + render(); + fireEvent.click(screen.getByText("Compare palette")); + fireEvent.change(screen.getByLabelText("Layer height"), { target: { value: "0.3" } }); + await act(async () => finish(unknown as never)); + expect(screen.queryByText("Palette version not evaluated")).toBeNull(); +}); + +it("loads kpal with the correct format and clears old observations", async () => { + render(); + fireEvent.change(screen.getByLabelText("Physical colors"), { target: { value: "#123456" } }); + const text = JSON.stringify({ version: 2, colors: ["#aabbcc"] }); + const file = { name: "synthetic.kpal", size: text.length, text: () => Promise.resolve(text) }; + fireEvent.change(screen.getByLabelText("Load palette file"), { target: { files: [file] } }); + await waitFor(() => expect((screen.getByLabelText("Palette content") as HTMLTextAreaElement).value).toBe(text)); + expect((screen.getByLabelText("Palette format") as HTMLSelectElement).value).toBe("kromacut_json"); + expect((screen.getByLabelText("Physical colors") as HTMLTextAreaElement).value).toBe(""); +}); + +it("browses saved readings without applying them to current inputs", async () => { + vi.mocked(calibrationHistory).mockResolvedValue({ runs: [{ calibration_basis: { calibration_basis_id: "saved-basis", family: "backlit", material: "PLA", layer_height_mm: 0.2, nozzle_mm: 0.4 }, entries: [{ label: "Saved red", simulated_color: "#ff0000", physical_color: "#ee0000" }], inputs_revision: { revision: "saved-revision" } }] } as never); + render(); + fireEvent.click(screen.getByText("Load saved comparisons")); + await screen.findByText(/Saved red: target/); + expect((screen.getByLabelText("Physical colors") as HTMLTextAreaElement).value).toBe(""); +}); diff --git a/desktop/src/lib/calibration/CalibrationView.tsx b/desktop/src/lib/calibration/CalibrationView.tsx index 797a3212..e341c8ec 100644 --- a/desktop/src/lib/calibration/CalibrationView.tsx +++ b/desktop/src/lib/calibration/CalibrationView.tsx @@ -1,24 +1,53 @@ -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Palette } from "lucide-react"; import { Button } from "@/components/ui/button"; import { PageHeader } from "@/components/ui/layout"; -import { evaluateCalibration } from "@/lib/calibrationApi"; -import type { CalibrationResponse } from "@/lib/calibrationApi"; +import { calibrationHistory, evaluateCalibration } from "@/lib/calibrationApi"; +import type { CalibrationResponse, CalibrationRun } from "@/lib/calibrationApi"; const field = "rounded-md border border-border bg-card px-3 py-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-primary/50"; export default function CalibrationView() { + const generation = useRef(0); + const importGeneration = useRef(0); + useEffect(() => () => { generation.current += 1; importGeneration.current += 1; }, []); const [source, setSource] = useState<"ditherforge_txt" | "kromacut_json">("ditherforge_txt"); const [content, setContent] = useState("#E94B35 td=0.8 Vermilion\n#2878B8 td Blue\n#F2C14E td=1.1 Ochre"); const [family, setFamily] = useState<"frontlit" | "backlit">("frontlit"); const [layerHeight, setLayerHeight] = useState("0.20"); - const [measurementText, setMeasurementText] = useState("#DA4D3C\n\n#2D70A8"); - const [ownedText, setOwnedText] = useState("PLA Red #D94335\nPLA Blue #236FAE\nPLA Yellow #E8BB43"); + const [measurementText, setMeasurementText] = useState(""); + const [ownedText, setOwnedText] = useState(""); + const [nozzle, setNozzle] = useState("0.4"); + const [material, setMaterial] = useState("PLA"); + const [model, setModel] = useState(""); + const [firstLayer, setFirstLayer] = useState("0.20"); + const [history, setHistory] = useState([]); + const [historyError, setHistoryError] = useState(null); + const [historyBusy, setHistoryBusy] = useState(false); + const historyGeneration = useRef(0); + useEffect(() => () => { historyGeneration.current += 1; }, []); const [response, setResponse] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); + function invalidate(clearReadings = false) { + generation.current += 1; + importGeneration.current += 1; + setResponse(null); setError(null); setBusy(false); + if (clearReadings) setMeasurementText(""); + } + async function loadHistory() { + const request = ++historyGeneration.current; + setHistoryBusy(true); setHistoryError(null); + try { + const saved = await calibrationHistory(); + if (request === historyGeneration.current) setHistory(saved.runs); + } catch (cause) { + if (request === historyGeneration.current) setHistoryError(cause instanceof Error ? cause.message : "History could not be loaded."); + } finally { if (request === historyGeneration.current) setHistoryBusy(false); } + } const run = async () => { + const request = ++generation.current; setBusy(true); setError(null); setResponse(null); try { const physical_colors: Record = {}; @@ -28,12 +57,12 @@ export default function CalibrationView() { if (!match) throw new Error("Owned filaments use one per line: label #RRGGBB"); return { label: match[1], color: match[2] }; }); - const result = await evaluateCalibration({ source, content, family, layer_height_mm: Number(layerHeight), nozzle_mm: 0.4, - material: "PLA", physical_colors, owned_filaments }); - setResponse(result); + const result = await evaluateCalibration({ source, content, family, layer_height_mm: Number(layerHeight), nozzle_mm: Number(nozzle), + material, model, first_layer_height_mm: Number(firstLayer), physical_colors, owned_filaments }); + if (request === generation.current) setResponse(result); } catch (cause) { - setError(cause instanceof Error ? cause.message : "Calibration could not be evaluated."); - } finally { setBusy(false); } + if (request === generation.current) setError(cause instanceof Error ? cause.message : "Calibration could not be evaluated."); + } finally { if (request === generation.current) setBusy(false); } }; return
@@ -42,25 +71,41 @@ export default function CalibrationView() {

Palette input

- { invalidate(true); setSource(e.target.value as typeof source); }}> - { invalidate(true); setFamily(e.target.value as typeof family); }}> - + +
+