From 017963d5a5b8686434201df00a41d9d1c9c0f84c Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 10 Nov 2026 00:54:31 +0800 Subject: [PATCH] Correct CAD docs and comments that disagree with the code --- docs/CAD/design/SKETCHER_TOOL_ARCHITECTURE.md | 29 +++++++++++-------- docs/HLSD/design-tab.md | 9 +++--- docs/HLSD/mcp-server.md | 4 +-- scripts/CAD/README.md | 4 +-- src/slic3r/GUI/CAD/DesignPanel.cpp | 7 ++--- src/slic3r/GUI/CAD/DesignSketchTool.cpp | 5 ++-- src/slic3r/GUI/Mcp/McpToolsCad.cpp | 4 +-- tests/libslic3r/test_caddocument.cpp | 4 +-- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/docs/CAD/design/SKETCHER_TOOL_ARCHITECTURE.md b/docs/CAD/design/SKETCHER_TOOL_ARCHITECTURE.md index c326d62121..4f3f24d5ae 100644 --- a/docs/CAD/design/SKETCHER_TOOL_ARCHITECTURE.md +++ b/docs/CAD/design/SKETCHER_TOOL_ARCHITECTURE.md @@ -437,13 +437,17 @@ cleared anyway (`:10689-10699`); abort a value field and the placed dimension ** its measured value (`cancel_dimension_value`, `:2174` — deliberate, but it means a cancelled gesture has already added a constraint, and nothing says so). -**`apply_dimension` records a poison value.** Its per-case thresholds move nothing for -`v <= 0` (Length/Diameter/Radius, `:611-613`) or `v < 0` (Distance/DistanceToLine, `:622`, `:639`) — -and then `record_dimension_constraint(v)` runs **unconditionally** (`:659`). A negative, zero or NaN -value that moved nothing is still pushed to the solver as a constraint it must satisfy and cannot, -silently corrupting the sketch rather than failing. The `sketch_set_value` CAD tool -(`Mcp/McpToolsCad.cpp`) refuses such a value before it calls `apply_dimension`. So the agent surface -validates and the GUI does not — the GUI is the less safe caller of its own function. +**`apply_dimension` refuses an out-of-range value before it records anything.** Its per-case +thresholds move nothing for `v <= 0` (Length/Diameter/Radius, `:611-613`) or `v < 0` +(Distance/DistanceToLine, `:622`, `:639`), and `record_dimension_constraint(v)` after them runs +**unconditionally** (`:659`): a negative, zero or NaN value that moved nothing would be pushed to the +solver as a constraint it must satisfy and cannot, silently corrupting the sketch. So a guard at the +top of `apply_dimension` refuses a value that is not finite, not above zero for a length, radius or +diameter, or negative for a distance, and says why on the status line, before it moves or records +anything. The `sketch_set_value` CAD tool (`Mcp/McpToolsCad.cpp`) checks the same rule, and refuses a +selection with nothing to dimension, before it calls `apply_dimension`, so that its call fails with +the reason rather than reporting a value the sketch tool refused only on its status line. The GUI +and the agent surface are equally safe callers of the function. **`record_dimension_constraint` never dedupes at all.** It `push_back`s unconditionally (`:674`, `:684`, `:691`, `:700`), so applying the selection-path dimension twice leaves **two** @@ -522,11 +526,12 @@ Three rules the type enforces, each closing a defect above: contradiction you can see. `drive == Reference` renders `measured` only, and the palette is the one already in the tab (green quote = measured, driving colour = driven). 2. **`apply(value)` returns a `WriteOutcome`** (`Ok | ClampedTo | Refused`, the base-operator type - from §0.2) — the same type for the solver path, the geometric path and the MCP server. The guard - `sketch_set_value` runs in `Mcp/McpToolsCad.cpp` moves *into* `apply`, so the GUI cannot be the - unsafe caller of its own function any more. `Refused` keeps the field open with the typed text - and the reason, which is also what makes the `Coincident`-flip reversible: the dimension keeps - its `type` and only its value changes. + from §0.2) — the same type for the solver path, the geometric path and the MCP server. The + range guard `apply_dimension` runs becomes `apply`'s `Refused`, so every caller learns of a + refusal from the result rather than from the status line, and `sketch_set_value` in + `Mcp/McpToolsCad.cpp` keeps no copy of the check. `Refused` keeps the field open with the typed + text and the reason, which is also what makes the `Coincident`-flip reversible: the dimension + keeps its `type` and only its value changes. 3. **One dimension per (type, operand pair) lives in one `std::vector`**, and the constraint slot is a *projection* of it (`upsert` semantics from `:1074-1130`, kept). The click path and the selection path both become thin callers of one `Dimension` builder, so the operand diff --git a/docs/HLSD/design-tab.md b/docs/HLSD/design-tab.md index 88bb2a1cb4..cd9a5a8159 100644 --- a/docs/HLSD/design-tab.md +++ b/docs/HLSD/design-tab.md @@ -368,8 +368,9 @@ callers share, and the CAD tool calls that function with explicit arguments inst widgets. `call_cad_tool` needs the MCP server on (`--mcp`, or Preferences) and the CAD feature on -(Preferences > Features, read only at startup); with the feature off it is refused, and the two -inspect tools still answer, with a note on how a person turns it on. A call is refused (`-32002`) +(Preferences > Features; the Design page is built only at startup, so turning it on takes a +restart); with the feature off it is refused, and the two inspect tools still answer, with a note +on how a person turns it on. A call is refused (`-32002`) while the Design tab is busy: a `change` CAD tool does not run under an open feature card or sketch session, nor a `change` or `sketch` one during a body Move, nor any while a rebuild owns the document. Face and edge ids name faces and edges of the current model, and a rebuild renumbers @@ -474,8 +475,8 @@ live through a long rebuild, and a call whose job fails after its reply, and Three checks in `scripts/CAD/` drive a running app through its MCP server as an agent does and grade the sketch layer against arithmetic: `check-mcp-sketch.py`, `check-sketch-engine.py` and `check-sketch-engine-corpus.py`, which grades it against the vector geometry of real drawings. -They need the MCP server and the CAD feature on and run on every platform, but not in CI, which -runs no application. `scripts/CAD/README.md` says how to run each. +They need the MCP server and the CAD feature on and run on every platform; no CI job runs them. +`scripts/CAD/README.md` says how to run each. The offer table is checked in CI: the `check_cad_offer_table.yml` workflow fails when `DesignOffer.hpp` is not what `gen_offer_table.py` makes of `tool_atlas.json`. diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index ef0ab7d0cb..9e081caba1 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -1071,8 +1071,8 @@ UI does not answer, the reply goes out without the note, which is only advice. `run_cad_tool()` runs the CAD tool on the UI thread, inside `call_cad_tool`'s mutate guard, and refuses a call by its cause, in this order. The MCP server is up before the main window, so first come `ui_plater()`'s "shutting down" and "still starting" refusals, as for any tool. Then the G-code -viewer, which has no Design tab (`-32001`); the CAD feature off (Preferences > Features, which the -app reads only at startup, so turning it on takes a restart); and a Design panel that cannot be +viewer, which has no Design tab (`-32001`); the CAD feature off (Preferences > Features; the Design +page is built only at startup, so turning it on takes a restart); and a Design panel that cannot be built (`-32001`: no page was made at startup, the page is mid-build, or its build failed), whose message says to retry and then restart. The panel is otherwise built on the first call, since in a headless session nobody clicks the tab; `get_app_state.design_tab` says whether this session built diff --git a/scripts/CAD/README.md b/scripts/CAD/README.md index 5d7334b041..849f28392f 100644 --- a/scripts/CAD/README.md +++ b/scripts/CAD/README.md @@ -11,7 +11,7 @@ other suite. Three checks drive the Design tab through the app's MCP server, with the same CAD tools an agent calls, and compare what the app reports with arithmetic. Each needs a running OrcaSlicer with the MCP server on (`--mcp`, or "MCP server" under AI features in -Preferences) and the CAD feature on (Preferences > Features, read at startup). +Preferences) and the CAD feature on (Preferences > Features, which takes effect after a restart). `tools/mcp/orca_mcp.py launch --cad` starts one with both. A check finds the app through its data directory, where the server writes its port and token: the one passed to the check, else `$ORCA_DATADIR`, else the platform's own (`tools/mcp/README.md` describes attaching). @@ -21,7 +21,7 @@ They run on Windows, macOS and Linux, and exit 0 when every assertion held. |---|---|---| | `check-mcp-sketch.py` | The sketch layer, asserting what decides whether a profile is buildable: closed loops, offsets that survive, a circle read as a void rather than a second body. | `python3 scripts/CAD/check-mcp-sketch.py [datadir]` | | `check-sketch-engine.py` | A ladder of 2D sketches of increasing complexity, judged on vertices, lengths, radii, tangency, symmetry and closure rather than on area. | `python3 scripts/CAD/check-sketch-engine.py [datadir]` | -| `check-sketch-engine-corpus.py` | The same ladder graded against real drawings: a systematic sample of the StudyCadCam sheets, each judged against its own vector geometry. | `python3 scripts/CAD/check-sketch-engine-corpus.py --corpus DIR [--datadir DIR] [--step N] [--limit N] [--scale]` | +| `check-sketch-engine-corpus.py` | The same ladder graded against real drawings: a systematic sample of the StudyCadCam sheets, each judged against its own vector geometry. | `python3 scripts/CAD/check-sketch-engine-corpus.py --corpus DIR [--datadir DIR] [--step N] [--limit N] [--scale] [--budget S]` | For example: diff --git a/src/slic3r/GUI/CAD/DesignPanel.cpp b/src/slic3r/GUI/CAD/DesignPanel.cpp index ff5aa0982c..88175aa16b 100644 --- a/src/slic3r/GUI/CAD/DesignPanel.cpp +++ b/src/slic3r/GUI/CAD/DesignPanel.cpp @@ -7464,10 +7464,9 @@ void DesignPanel::load_recipe(const std::string& blob) if (!m_doc.deserialize_recipe(blob)) { // Carry the kernel's reason. deserialize_recipe distinguishes three cases that matter // very differently to the person reading this — saved by a NEWER build, saved by an - // OLDER one, or genuinely unreadable — and replacing all three with one sentence left - // the user unable to tell "update OrcaSlicer" from "your file is damaged". Same - // error-loss class as the 31 Mcp/McpToolsCad.cpp sites (1de72de9ed): the message - // exists, it was simply not passed on. + // OLDER one, or genuinely unreadable — and one sentence for all three would leave the + // user unable to tell "update OrcaSlicer" from "your file is damaged". The generic + // sentence is only for a failure that set no reason. set_status(StatusKind::Error, m_doc.error.empty() ? _L("Could not restore the CAD model from this project") : wxString::Format(_L("Could not restore the CAD model: %s"), wxString::FromUTF8(m_doc.error))); diff --git a/src/slic3r/GUI/CAD/DesignSketchTool.cpp b/src/slic3r/GUI/CAD/DesignSketchTool.cpp index 3a92b289cb..48bb56bb31 100644 --- a/src/slic3r/GUI/CAD/DesignSketchTool.cpp +++ b/src/slic3r/GUI/CAD/DesignSketchTool.cpp @@ -296,9 +296,8 @@ void DesignSketchTool::set_tool(Mode mode) // includes inline_busy(), so letters are swallowed while a field is open — the switch has to // come from the menu, the toolbar or the MCP server's call_cad_tool.) // - // reset_autoedit() is the existing helper for exactly this and its comment already says it - // "mirrors set_tool's resync" — the three lines that used to be here were that mirror drifting - // out of step, missing the two members that matter. The already-queued CallAfter then finds + // reset_autoedit() drains the queue: besides the flags and the seen baseline it clears + // m_autoedit_dims and sets m_autoedit_dim_idx to -1, so the already-queued CallAfter finds // m_autoedit_dim_idx == -1 and returns through the guard at the top of open_next_autoedit_dim. // // The current value is COMMITTED rather than cancelled, matching the ready-edit-op rule a few diff --git a/src/slic3r/GUI/Mcp/McpToolsCad.cpp b/src/slic3r/GUI/Mcp/McpToolsCad.cpp index e5f1afe8e8..6087947fd7 100644 --- a/src/slic3r/GUI/Mcp/McpToolsCad.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsCad.cpp @@ -157,7 +157,7 @@ const char* const kIdsNote = const char* const kFailureNote = "A rejected rebuild is reported in the reply: ok is false or error is not empty."; // cad_feature_note()'s text: run_cad_tool() refuses every CAD tool while the feature is off, and the -// app reads the preference only at startup. +// Design page is built only at startup, so turning the feature on takes a restart. const char* const kCadOffNote = "The CAD feature is off: call_cad_tool is refused until a person enables it in " "Preferences > Features and restarts OrcaSlicer."; @@ -6158,7 +6158,7 @@ void register_cad_tools(McpService& service) "A CAD tool that takes long (thread, sweep, loft) may reply with a running job. With face or edge ids, pass the " "generation they were read at (describe_scene, query_topology), so ids from before the model changed are refused. " "Needs the CAD feature, which a person enables in Preferences > Features; it takes effect after a restart.", - object_schema({{"tool", prop("string", "A CAD tool's name (list_cad_tools).")}, + object_schema({{"tool", prop("string", "A CAD tool's name (list_cad_tools); its arguments go in args.")}, {"args", {{"type", "object"}, {"description", "Its arguments (describe_cad_tool)."}}}}, {"tool"}), [](const json& args, ToolContext& ctx) { diff --git a/tests/libslic3r/test_caddocument.cpp b/tests/libslic3r/test_caddocument.cpp index 7baf337291..995226151e 100644 --- a/tests/libslic3r/test_caddocument.cpp +++ b/tests/libslic3r/test_caddocument.cpp @@ -5162,8 +5162,8 @@ TEST_CASE("unknown identifier fails recompute", "[CadDocument][variables]") // The checkpoint -> mutate -> recompute -> undo-on-failure pattern is what both the GUI and // Mcp/McpToolsCad.cpp use to keep a bad edit out of the document. It only works if the snapshot -// covers `variables` as well as `features`: undo() used to restore features alone, so a bad variable -// survived the rollback and every later recompute failed — the document was left unusable. +// covers `variables` as well as `features`: an undo() that restored features alone would let a bad +// variable survive the rollback, and every later recompute would fail — the document left unusable. TEST_CASE("undo rolls back a bad variable, not just features", "[CadDocument][variables]") { CadDocument doc;