diff --git a/docs/HLSD/design-tab.md b/docs/HLSD/design-tab.md index e0bee6f579..3a50852329 100644 --- a/docs/HLSD/design-tab.md +++ b/docs/HLSD/design-tab.md @@ -364,36 +364,68 @@ emits `src/slic3r/GUI/CAD/DesignOffer.hpp` from it. The header is checked in and hand-edited; the `check_cad_offer_table.yml` workflow runs the generator with `--check` on every push and pull request that touches the atlas, the generator or the header, which is what makes "GENERATED — DO NOT EDIT" a fact rather than a request. The generator also refuses an atlas with a -duplicate verb id, since `mcp_run_verb` resolves a verb by id and would make the second one -unreachable. +duplicate verb id, since a verb is resolved by id (`mcp_run_verb`, a command's key) and the second +one would be unreachable, and a table in which an entry's name is not marked for translation in the +`Design` context (`L_CONTEXT`): every name is a command's title, which a person sees translated, and +the mark compiles to the bare string, so nothing at run time could tell it is missing. + +The same table is the Design tab's Speed Dial tiles and its automation commands, so the three cannot drift +apart. The header's `kDesignTools` holds 134 entries: the 93 verbs, each with its menu row, and 41 commands +with no row (`row` -1), such as `describe_scene`, `sketch_add` or `commit`. Every entry but `align`, which has +no GUI path, is a command of the catalog whose key is the entry's id and whose title is its name. An entry +with an `action` does what its menu row does when it is called with no arguments, and has a tile. An entry +with a `tool` block also runs silently, with arguments: the block is that form's access, params, examples and +whether it reports a rejected rebuild in its reply, which the header carries as JSON text (`doc`) beside the +entry's `access` and `ok_false`. `modal` marks the three entries whose action opens a dialog that waits for an +answer: a modal one for SVG (a file picker) and Color, which holds the call that opened it until it is answered, +and the Design tab's own modeless dialog for Text, which does not. +`kDesignSelectionIds` names the selection kinds in `OfferSel`'s order, the ids the verbs' `accepts` use. The atlas and its generator sit in `scripts/CAD/` rather than in `docs/`: they are build inputs for a checked-in header, not documentation. ## Automation surface -The document is automated through the app's MCP server, on every platform, with three tools: -`list_cad_tools` lists the Design tab's CAD tools, `describe_cad_tool` gives a CAD tool's arguments, -how its failure shows and runnable examples, and `call_cad_tool {tool, args}` runs one. The CAD -tools (`Mcp/McpToolsCad.*`) describe the scene, query topology, measure, and run the same verbs the -offer does — they re-implement nothing, so a scripted action and a clicked one cannot diverge. Where -a GUI action is bound to a selection, a card or a dialog, its work is split into a function both -callers share, and the CAD tool calls that function with explicit arguments instead of driving the -widgets. +The document is automated through the app's MCP server, on every platform, with the Design tab's +commands, one per entry of its table, in the command catalog's group `Design`: `search_tools {group: +"Design"}` lists them, `search_tools {tool}` gives one's arguments, how its failure shows and runnable +examples, and `call_tool {tool, args}` runs one. A person picks the same commands from the Speed Dial: +while the Design tab is shown with the CAD feature on, it has a tile for each entry with an action of the +mode the tab is in, the sketch's tools in a sketch and the model's outside one, titled as the right-click +menu names it and with its icon, and on any other tab, or once the feature is turned off, none; a pinned +Design tile stays pinned while it is not shown, and takes no place on the favourites bar meanwhile. A command +with no arguments does what the menu's row does, only in the mode the row belongs to, and replies +`{"result": {"interactive": true, ...}}` with what the tab shows then (its busy reason and status line); +with arguments, or `silent: true`, the commands (`Mcp/McpToolsCad.*`) describe the scene, query +topology, measure, and run the same verbs the offer does — they re-implement nothing, so a scripted +action and a clicked one cannot diverge. Where a GUI action is bound to a selection, a card or a dialog, +its work is split into a function both callers share, and the command calls that function with explicit +arguments instead of driving the widgets. + +An agent's call needs the MCP server on (`--mcp`, or Preferences), and every command, a person's tile +included, needs the CAD feature on (Preferences > Features). The catalog holds them only when the feature +is on at startup, as the main window makes the Design page only then, so turning it on takes a restart; +with it off they are unknown commands, and `get_app_state` says in `cad_note` how a person turns it on. +Turned off while OrcaSlicer runs, the tab stays until the restart, but the Speed Dial has no tile of it. A +call is refused (`-32002`) while the Design tab is busy: none runs while a rebuild owns the document, +`change` and `sketch` commands do not run under an open feature card, the Text dialog, Constrain mode or a +body Move, and a `change` one does not run under a sketch session, which `sketch` ones drive. `read` +commands are refused only during a rebuild, and so is the opening of a tool, which is also refused in the +mode its row does not belong to (a model tool in a sketch, a sketch tool outside one): the tab's right-click +menu offers a tool only in its mode and refuses it for nothing else, and each tool decides what an open card +means to it. For the menu, and so for the commands, a sketch in Constrain mode is open, while the tab's keys +there are the model's: there a command does what its menu row does, not what its key does. A tool whose +menu row only the right-click menu reaches (a `btn:` or `fly:` action) is +refused for a selection its row does not accept, saying so and naming the selections it takes. `undo` and +`redo` are the shared commands of the Speed Dial and act on the history of the tab shown, the Design tab's +while it is shown; `history: "design"` names the Design tab's from any tab. -`call_cad_tool` needs the MCP server on (`--mcp`, or Preferences) and the CAD feature on -(Preferences > Features; the main window creates the Design page 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: none -runs while a rebuild owns the document, `change` and `sketch` CAD tools do not run under an open -feature card, the Text dialog, Constrain mode or a body Move, and a `change` one does not run under -a sketch session, which `sketch` ones drive. `read` CAD tools are refused only during a rebuild. Face and edge ids name faces and edges of the current model, and a rebuild renumbers them while a stale id still names a real face or edge, so the replies carry the model's `generation`: a call that passes ids with the `generation` they were read at is refused (`-32010`) once the model has moved on, rather than acting on another face or edge. -The CAD tools add features through the kernel calls the cards use, named as the cards name them, +The commands add features through the kernel calls the cards use, named as the cards name them, one checkpoint per call. A rebuild that fails is taken back with `CadDocument::rollback()`, which leaves nothing to redo, and the status line says "Edit rejected" as it does for a refused GUI edit; the call reports the kernel's reason. Planes are named as in the cards: a @@ -428,7 +460,7 @@ a value field is pending. Topology reads come from the kernel: `GeometryEngine::surface_info()` gives a face's surface type, area and analytic numbers, `edge_faces()` the faces along each edge, `edge_convexity()` whether two faces meet in an outside or inside corner (OCCT's fillet classification), and -`min_distance()` the closest points of two shapes. The Plane card's Confirm and the `plane` CAD tool +`min_distance()` the closest points of two shapes. The Plane card's Confirm and the `plane` command share `CadDocument::datum_plane_refusal()`, which refuses a construction that is missing a reference, names a face or edge no longer on the model, or puts a tangent plane on a face that is not a cylinder, so neither reaches the kernel's silent fallback to an offset plane; a refused @@ -448,8 +480,8 @@ clicks and drags it at pixels, so a left click picks and a right click opens the `wxEVT_CHAR_HOOK` as a real key press does, travelling up from the focused widget, so Escape, Enter and the tool shortcuts behave as they do for a person. -`docs/HLSD/mcp-server.md` describes the CAD tool table, access rules, error convention and replay -tests. +`docs/HLSD/mcp-server.md` describes the Design commands, their table, access rules, error convention +and replay tests. ## Where the code lives @@ -464,10 +496,10 @@ tests. | `src/slic3r/GUI/CAD/DesignRowList.*` | the Feature tree and Bodies lists, with per-row actions | | `src/slic3r/GUI/CAD/DesignCanvas.*` | viewport integration | | `src/slic3r/GUI/CAD/DesignSketchTool.*` | in-canvas sketching | -| `src/slic3r/GUI/Mcp/McpToolsCad.*` | the automation surface: the CAD tool table behind the MCP server's `list_cad_tools`, `describe_cad_tool` and `call_cad_tool` | +| `src/slic3r/GUI/Mcp/McpToolsCad.*` | the automation surface: the Design commands made from the table, their silent forms (`kSilentForms`) and their gate | | `src/slic3r/GUI/CAD/DesignInteraction.hpp` | the Esc level contract | -| `src/slic3r/GUI/CAD/DesignOffer.hpp` | generated offer table | -| `scripts/CAD/tool_atlas.json` | source of truth for the offer | +| `src/slic3r/GUI/CAD/DesignOffer.hpp` | the generated table: the offer, the tiles and the commands | +| `scripts/CAD/tool_atlas.json` | source of truth for the table | ## Verification @@ -478,18 +510,19 @@ The kernel is covered by Catch2 suites in `tests/libslic3r/` (`test_caddocument` `libslic3r_tests "[CadDocument]"` runs the document's cases. The automation surface has its own checks. `slic3rutils_tests "[Mcp][CAD]"` -(`tests/slic3rutils/test_mcp_cad.cpp`) runs the CAD tools' argument checks and kernel calls on a -`CadDocument` or a bare `DesignSketchTool`, with no panel, and checks the table itself: a row per -dispatched CAD tool, the summaries, and examples that call only real CAD tools with the arguments -they declare. On a live application launched with `tools/mcp/orca_mcp.py launch --cad`, the replays -`tools/mcp/tests/cad_*.json` drive `call_cad_tool`, the live tests `tools/mcp/test_cad_replay.py`, +(`tests/slic3rutils/test_mcp_cad.cpp`) runs the commands' argument checks and kernel calls on a +`CadDocument` or a bare `DesignSketchTool`, with no panel, and checks the table and the commands the +catalog holds: one per entry but `align`, a silent form for every tool block and a block for every silent +form, their schemas and summaries, and examples that call only real commands with arguments their schemas +take. On a live application launched with `tools/mcp/orca_mcp.py launch --cad`, the replays +`tools/mcp/tests/cad_*.json` drive the commands through `call_tool`, the live tests `tools/mcp/test_cad_replay.py`, `test_cad_slow_build.py` and `test_cad_failed_job.py` cover journaling and replay, the app staying live through a long rebuild, and a call whose job fails after its reply, and -`tools/mcp/test_cad_examples.py` runs every CAD tool's examples, each on a fresh design. The GUI +`tools/mcp/test_cad_examples.py` runs every command's examples, each on a fresh design. The GUI tests `tools/mcp/test_cad_sketching.py`, `test_cad_context_menu.py` and `test_cad_click_edit.py` drive the tab as a person does, through the server's UI tools: they draw on the canvas with clicks and typed values, run the offer's verbs from a right click and type into the value fields with -no click into them, and grade what `call_cad_tool`'s read tools and `list_widgets` report back. They +no click into them, and grade what the reading commands and `list_widgets` report back. They need an English UI and no CI job runs them; `tools/mcp/README.md` says how to run them. Three checks in `scripts/CAD/` drive a running app through its MCP server as an agent does and diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index c723174e57..dc1ff19d4b 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -21,8 +21,9 @@ stdio client ──▶ orca-slicer --mcp-stdio ──┘ │ JobRegistry, Journal ``` -`McpService`, owned by `GUI_App`, owns all of it except the bridge, plus the `ToolRegistry` and -the `ModalTracker`. +`McpService`, owned by `GUI_App`, owns all of it except the bridge, plus the `ModalTracker`. The +commands it serves are the process's command catalog (`NativeCommands::instance()`, see Tool catalog), +which startup builds without a service. ## Transport @@ -78,7 +79,7 @@ as `value`, `action` as `id` or `button`, `object` as `objects`, `plate` as `pla `query`, `settings` as `values`, and `path` as `save_path` where the tool has no `path` of its own. A value in another JSON form is converted: a number, boolean, array or object written as a string, an index as a string where a name may also go -(`"0"` for a plate), a single item for an array. A +(`"0"` for a plate), a single item for an array, also where null may stand for the array. A value outside its argument's enum moves to the one other argument whose enum takes it, when the call leaves that out: `set_view`'s `canvas: "front"` is its `camera`. Each enum lists only its own values, since listing a camera direction under both had agents give it to the wrong one. Anything that still @@ -87,13 +88,16 @@ each was an agent's first guess, many times over, and each cost a failed call an The server `instructions` (under the 4096 characters clients keep) give the workflow: `get_app_state`, act, then check the result with the reading tools, keeping screenshots for what those do not report. +The rest is in three sections, by what the tools are for: running the session, acting on project data, +which an agent should prefer, and driving the GUI itself. They say to prefer typed tools over clicks and never retry a call that returned a job, point to `get_settings`' meta and search for what a setting does, say how a gizmo opens and is driven (and that `pick_gizmo_file` only stands in for a file picker inside one, since its name draws agents to it for any gizmo work), that the camera turns with `set_view` rather than a drag, and which indices are 0-based. They also point to `search_tools {query}` as the one search across every catalog an agent calls into: -the tools, the operations plugins offer (which `tools/list` never shows, so nothing else tells an agent -they exist), Speed Dial actions, settings, the Python API and the Design tab's CAD tools. An agent rarely +the commands, among them those `tools/list` never shows (the Speed Dial's commands, the Design tab's and +the operations plugins offer, so nothing else tells an agent they exist), the Speed Dial's other actions, +settings and the Python API. An agent rarely knows which catalog answers "how do I add a brim", and each catalog has its own search with its own arguments. Clients that defer tools load only their names and the instructions at first, so the instructions are how an agent without a skill learns which tool to @@ -185,8 +189,10 @@ are already open, such as Preferences when the server is turned on from there. ## Threading Tool handlers never run on the UI thread. Anything that touches wx goes through -`ToolContext::run_ui()`. It posts a closure through `UiInvoker` to a `UiDispatcher`, then waits. -The dispatcher is `wxApp::CallAfter` in the app and a queue the test drains in tests. A closure +`ToolContext::run_ui()`. A command a person picks is the one call that runs there: its context, a +`PersonContext`, runs the closure in place (see Speed Dial catalog). For every other call `run_ui()` +posts a closure through `UiInvoker` to a `UiDispatcher`, then waits. The dispatcher is +`wxApp::CallAfter` in the app and a queue the test drains in tests. A closure still queued after 10 s is abandoned without running, and the call fails saying it was not run and is safe to retry. Once a closure has started it may use the caller's stack (the handler's captures), so the caller waits for it to finish, through shutdown too; the closure ends when the UI thread @@ -224,12 +230,12 @@ topmost modal, they apply the mutate checks themselves (`UiInvoker::require_muta operation admission (`McpCore::admit()`). `cancel_job` is a recover call too, so neither a dialog the operation opened nor another call's nested loop keeps it out. -`ToolDef::inline_call` decides where a call runs. Pure observation tools run on the request +`NativeCommand::inline_call` decides where a call runs. Pure observation tools run on the request thread. Every tool that can activate UI runs as a job on its own thread, recover tools that click in dialogs included, since a click can open another modal (Preferences, Keyboard shortcuts, Edit). `JobRegistry` names jobs `j1`, `j2`, …, records each job's tool and parent, allows 64 running and keeps the last 64 results, plus finished jobs whose parent (a running replay) may still wait for -them, up to 1024 in all. The request thread waits up to `ToolDef::budget_ms` (45 s, under +them, up to 1024 in all. The request thread waits up to `NativeCommand::budget_ms` (45 s, under Codex's 60 s tool timeout); after that the reply is `{status: "running", job, tool, note}` and the job keeps going until `wait {for: "job"}` (at most 50 s per call) returns its result. The server never retries a mutating call, and every envelope tells the model not to either. @@ -371,7 +377,7 @@ plugin API (`orca.host`). What one of them does is often what another does too: command, a tool, and a command run through `run_action`. The checks, the refusal and its wording, the undo snapshot and the order of the owner calls of such a function are in one place, `src/slic3r/GUI/Operations/` (namespace `Slic3r::GUI::Ops`), and the three interfaces convert their -arguments and results around it. A command keeps its key and param, a tool its name, arguments and +arguments and results around it. A command keeps its key and arguments, a tool its name, arguments and reply, and a binding its signature; what they share is the rule. **What is an operation.** An effect, or a rule about one owner's state that its own widgets also @@ -400,7 +406,7 @@ error also carries the code (`code`) and puts the names under the key it has alw `presets`). `run_action` replies with the English text and the code too, where the command ran an operation, so a command's refusal reads the same through every route. A caller may add a hint after the text (the `export` tool's `wait {for:"idle"}`), never a second wording. A check of an argument's -form (a path that does not resolve, a param that does not parse, an extension the tool does not +form (a path that does not resolve, an argument its schema refuses, an extension the tool does not write) stays with the caller that owns the argument. **Undo.** An operation takes the undo snapshot its function takes, once, after its checks pass. A @@ -423,7 +429,7 @@ open a dialog of its own (a STEP file's mesh options, the modified-presets quest `Plater::load_project()`, the Transfer-or-discard prompt of `Tab::select_preset()` when no answer is given). A call that stops there behaves as any call behind a dialog: a tool replies `blocked_by_dialog`, and a plugin's call waits for the person. A path that asks a person keeps its -owner method: with no param, and for `load_project` and `new_project` with or without one, a +owner method: with no arguments, and for `load_project` and `new_project` with or without them, a command is the asking path and calls the owner. **The plugin API.** Where an operation exists for what a binding does, the binding calls it and @@ -436,7 +442,7 @@ makes the filament tab edit the preset, since its transaction edits that preset. **What the layer includes.** Owner headers, libslic3r and wx. Nothing from `GUI/Mcp`, `NativeCommands.hpp` or `plugin/`, and neither nlohmann/json nor pybind11. The three interfaces -include it, and GUI code may. The dispatch core (`McpCore`, `ToolRegistry`, `JobRegistry`) includes +include it, and GUI code may. The dispatch core (`McpCore`, `CommandCatalog`, `JobRegistry`) includes nothing from it, and `plugin/` includes nothing from `GUI/Mcp`. | File | Operations | Reached by | @@ -485,19 +491,20 @@ A check only one route makes stays with that route, as a step of its own before **Keeping it so.** Two checks, neither of which reads what a handler does: -- `ToolDef` and `NativeCommand` have a field naming the operations an entry reaches (`reaching()` - where a tool is registered, the `reaches` table of the commands). It is in no listing. A unit test - (`test_operations`) walks `McpService::offline_catalog()` and `NativeCommands::catalog()` and - requires every tool that is not read-only and every command with a param to name an operation or - to be on the test's exception list, with the reason: it runs what its arguments name, it drives the - GUI, it changes the session and not the project, its function has one entry point, or it is an - asking path. A new tool or param command has to say which it is. -- `scripts/check_operation_calls.py`, run by the `Check operation calls` workflow, bans in the - callers' files (`NativeCommands.cpp`, the `McpTools*.cpp` files but the CAD tools', - `plugin/host/*.cpp`) the owner methods the operations call, by name. A banned call that stays, - because another function uses the same owner method or the caller is an asking path, is listed in - `scripts/operation_calls_baseline.txt` by file and exact source line, under its reason. The check - fails on a banned call that is not listed and on a listed line the source no longer has. +- `NativeCommand` has a field naming the operations a command reaches (`reaching()` where a tool is + registered, the `reaches` table of the Speed Dial's commands). It is in no listing. A unit test + (`test_operations`) walks `NativeCommands::instance()` and requires every listed command that is not + read-only and every palette command that takes arguments (one with a tile that is not listed, whose + schema has an argument beside `silent`) to name an operation or to be on the test's exception list, + with the reason: it runs what its arguments name, it drives the GUI, it changes the session and not the + project, its function has one entry point, it is an asking path, or it calls the undo and redo of a + history (`undo`, `redo`). A new tool or command that takes arguments has to say which it is. +- `scripts/check_operation_calls.py`, run by the `Check operation calls` workflow, bans in the callers' files + (`NativeCommands.cpp`, the `McpTools*.cpp` files but the Design commands' `McpToolsCad.cpp`, + `plugin/host/*.cpp`) the owner methods the operations call, by name. A banned call that stays, because + another function uses the same owner method or the caller is an asking path, is listed in + `scripts/operation_calls_baseline.txt` by file and exact source line, under its reason. The check fails on a + banned call that is not listed and on a listed line the source no longer has. Neither catches a rule written again through calls that are not banned, such as a check made of getters. That is for review: a caller's handler converts, calls, and shapes the reply. @@ -511,67 +518,79 @@ a replay file. Where the GUI has no name for the thing, the name is a plain verb `answer_dialog`), and a word the GUI uses for something else is avoided: `run_script` would read as the Run Script panel, which runs Python. -| Group | Tool | Purpose | -|---|---|---| -| App | `get_app_state` | version, platform and display backend, ready, window, the displays' work areas, the MCP endpoint, whether Python runs and Python scripts are allowed, whether the Design tab is on, tab, mode, project, presets, plates, objects, the selection, slicing, the Preview's view type, time mode and layer range, the camera of the 3D view shown, print host uploads, the open gizmo, dialogs, menus closed unseen, auto-answer rules, notifications, jobs | -| | `wait` | `ready`, `idle`, `dialog`, `no_dialog` or a `job` (default the job given, else `idle`); `timeout_s` up to 50 | -| | `get_log` | end of the current log file, filtered by minimum level | -| Speed Dial | `search_actions` | search the action catalog by a query's words, best match first, or list it by group and title; paged | -| | `run_action` | run an action by id (or the name inside it), with its optional `param`; an error when the action did nothing; waits for a background job it starts (arrange, orient) | -| Project | `open_files` | load models, a project or G-code by absolute path, with no dialog | -| | `new_project` | start an empty project (`discard_changes` if it has unsaved changes); `preset_changes` keeps or discards modified presets | -| | `generate_calibration_test` | a Calibration menu test with typed parameters and no dialog: a new project with the test model and the preset changes the test needs, printed with filament slot 1; refused while presets are modified unless `preset_changes` keeps or discards them | -| | `save_project` | save the project as `.3mf` to a path (a `.gcode.3mf` path is refused: that is `export` `sliced_3mf`) | -| | `export` | `gcode`, `sliced_3mf`, `3mf` or `stl` to a path, by default the one its extension names; `gcode` is an export operation | -| Presets | `list_presets` | printer, process or filament presets with flags (system, user, inside the project, the preset inherited from), paged | -| | `select_preset` | select by name through the selector (filament per slot), showing a hidden preset first; `preset_changes` transfers or discards unsaved changes without the prompt | -| | `get_settings` | values and metadata (description, settings page and group, enum labels, per-variant entries) by key, by page or group, or found by words matched in keys, labels and descriptions, of the edited or any saved preset, of an object's or part's overrides with the values they print with, of the project's own settings (plate type, slot colours, flushing volumes, purge mode, prime tower positions, mixed slots), of a plate's (plate type, print sequence, spiral vase, filament orders, name, lock), or of named preferences (read only); `compare` lists only what differs from another preset, the saved one or the parent | -| | `set_settings` | set values the way the settings tab does, all or none; one entry of a per-variant value; object and part overrides and filaments; the project's and a plate's own settings through their controls' and dialogs' code; `null` takes a preset's key back to its saved or parent value, `reset_all` drops a preset's unsaved changes first; replies with every setting that `changed` | -| | `save_preset` | save the preset being edited under a name, as a user preset or inside the project | -| | `delete_preset` | delete a user or project preset, selected or not, as the tab's Delete does (destructive) | -| Objects | `list_objects` | each plate with the objects on it, then the objects on no plate: objects (filament, auto drop, overrides, brim ears, height range modifiers, variable layer height profile), their instances there (placement, mirrored, bounding box, canvas rectangle on request) and parts (type, filament, placement and bounding box on the bed, scaled and mesh volume, painted facets, text and SVG sources), paged | -| | `list_plates` | plates with the settings they print with and those they set themselves, how many objects are on each, name, lock, slice state, prime tower position and layer G-codes, paged | -| | `select_objects` | select objects, instances or parts (indices checked against what the object has), all, or none | -| | `transform` | translate, rotate, scale or size one instance, relative or absolute, move it to a `position` or to another plate; or the same for one part (`part`) | -| | `add_part` | add a part, negative part, modifier, support blocker or enforcer, or precise seam to an object: a shape at a size or a model file, optionally at a position | -| | `arrange` | arrange every unlocked plate or one plate, or fill an object's plate with instances or copies, with the Arrange options panel's settings; waits for the job | -| | `set_height_ranges` | replace an object's height range modifiers: Z ranges with their own layer height, filament and process settings | -| | `set_variable_layer_height` | the Variable layer height panel's Adaptive (with its quality), Smooth (radius, keep min) or Reset on an object | -| Slice | `slice` | current, one or all plates, then the Preview tab as after the Slice button; outcome for each plate, and for an `ok` one its time, filament totals with the flush, cost, layers, max Z, filament changes and grams per slot by use | -| | `cancel_job` | stop the running slice or G-code export, a pending automatic reslice, or a background job an MCP call started (optionally only a given job), or with `job` a running `encode_recording`; allowed during an operation | -| | `set_custom_gcode_at_layer` | add or remove a plate's pauses, custom G-code, custom templates and filament changes on its sliced layers, as the Preview layer slider's menu does | -| View | `set_view` | tab (Design included), 3D view (`canvas`: Prepare, preview, assemble), camera of the 3D view shown (a direction; the Design view's on the Design tab), the point it looks at (`look_at`) and its zoom, `orbit` around what it looks at by degrees on every 3D view, and a `camera_state` readback; preview layers (by number or height), color scheme as the legend's combo picks it, legend rows and time estimate | -| | `screenshot` | the main window, the 3D view shown (the Design view on the Design tab), topmost dialog or one widget: a downscaled image and a full-size PNG | -| | `get_slice_stats` | a sliced plate's summary, time and grams per feature type, per-layer Z, height, time and grams (paged), grams per object instance, and the Preview's legend state and colour ranges | -| Recording | `start_recording` | record the main window with its modal dialogs, or the 3D view shown, into an MJPEG `.mkv`, with the current tool call as a caption and the pointer highlighted when asked for, and with `encode` an MP4 of it once stopped | -| | `stop_recording` | capture the last state, end the recording and report its file once written: length, frames, drops, the mean UI time of a capture, size and why it ended; the job of the encode `start_recording` asked for | -| | `encode_recording` | encode a recording into an H.265 or H.264 MP4 with the system ffmpeg; cancellable | -| GUI | `list_windows` | the open windows, modal or not, with refs for `screenshot`, `list_widgets` and the input tools, their state and whether they resize, paged | -| | `set_window` | size, move, maximize, minimize or raise the main window, the topmost modal dialog or a window `list_windows` lists, and reply with what the window became once it holds still and the 3D view has drawn at its size | -| | `list_widgets` | widgets, rows of lists, trees and tables, popups, menus, GL toolbar items, gizmos, the Prepare view's plates and plate icons, and ImGui items, with refs | -| | `click` | activate a ref or locator, click a row's cell or a plate icon, or click a point of a 3D canvas or custom-drawn widget; list the menu it opens, or run one of its items | -| | `set_widget_value` | set a widget's text, value, selection or checked state, or a row's checkbox | -| | `press_keys` | send a key chord to a target or the focused window, whose panels' key hooks see it first; list or run the menu it opens | -| | `mouse_gesture` | canvas gestures: move, down, up, click, drag, wheel, at pixels or at points of the model (the Design view at pixels); list or run a right click's menu; reports when a gesture moved the camera | -| | `pick_gizmo_file` | what the open gizmo's file pickers do, with a path: SVG change file and save as, texture import | -| | `answer_dialog` | press a button of the topmost wx dialog or native message box, or of its page for a web dialog | -| | `auto_answer_dialogs` | answer matching modals as they open (native ones unseen, a file or folder picker with a path, web ones on their page), and one already open | -| | `run_javascript` | run JavaScript in a web view (the topmost dialog's while a modal is open), with a page element as `el`, and return the result | -| Replays and scripts | `run_replay` | run a replay file or inline replay, with results per step | -| | `export_replay` | write the session journal as a replay; calls whose job is still running are left out and listed | -| | `run_script` | run Python code against `orca.host`, calling tools through `orca.host.tools`; needs the Python setting (see Python scripts); cancellable | -| | `search_python_api` | search the `orca` package in the running build: names, signatures and documentation, paged | -| API | `search_tools` | look up any registered tool or plugin operation by name, list every name, or search every catalog by words | -| | `call_tool` | call a registered tool or plugin operation by name; runs and is journaled as that tool's own call | -| CAD | `list_cad_tools` | the Design tab's CAD tools, each with its access and one-line summary, narrowed by a query, paged (CAD builds; answers with the CAD feature off too) | -| | `describe_cad_tool` | one CAD tool or a list: summary, details, params with `required`, how a failure shows and examples (CAD builds; answers with the CAD feature off too) | -| | `call_cad_tool` | run a CAD tool of the Design tab: sketches, features, reads and measurements, feature and body edits, undo, commit to plate (CAD builds, Design tab enabled) | +What each tool does, the arguments it takes and what it replies are in its description, which `tools/list` +gives a client and the command reference `tests/data/command_catalog.json` holds for a reader (see Making a +feature reachable). By area, the tools are: -Each tool has a lane, the way it acts, set by `ToolRegistry::add()` from `tool_lane()`: core (the -session, recovery and Python), API (project data by index and name, JSON in and out) and UI (the GUI -itself). Every caller reaches every tool; the lane is a hint for the agent choosing one. It starts each -description (`[core]`, `[api]`, `[ui]`), orders `tools/list` (core, then API, then UI) and orders the -server instructions. +**App.** `get_app_state`, `wait` and `get_log`. + +**Speed Dial.** `search_actions` and `run_action`. + +**Project.** `open_files`, `new_project`, `generate_calibration_test`, `save_project` and `export`. + +**Presets.** `list_presets`, `select_preset`, `get_settings`, `set_settings`, `save_preset` and `delete_preset`. + +**Objects.** `list_objects`, `list_plates`, `select_objects`, `transform`, `add_part`, `arrange`, +`set_height_ranges` and `set_variable_layer_height`. + +**Slice.** `slice`, `cancel_job` and `set_custom_gcode_at_layer`. + +**View.** `set_view`, `screenshot` and `get_slice_stats`. + +**Recording.** `start_recording`, `stop_recording` and `encode_recording`. + +**GUI.** `list_windows`, `set_window`, `list_widgets`, `click`, `set_widget_value`, `press_keys`, +`mouse_gesture`, `pick_gizmo_file`, `answer_dialog`, `auto_answer_dialogs` and `run_javascript`. + +**Replays and scripts.** `run_replay`, `export_replay`, `run_script` and `search_python_api`. + +**API.** `search_tools` and `call_tool`. + +The tools are commands of the process's command catalog (`CommandCatalog`, `NativeCommands::instance()`; see +Speed Dial catalog), beside the Speed Dial's: a tool is a `NativeCommand` with `listed` set, which +`tools/list` shows in the order the tools were added. Startup builds the catalog, with no MCP service: +`register_all_commands()` adds the Speed Dial's commands, then each tool family in a fixed order of calls +(app, api, project, config, scene, layer, view, replay, python, record, action, ui), each through its +`register_*_tools(catalog)`, and between record and action the Design tab's commands, which no listing shows, +in a CAD build with the CAD feature on (`register_cad_commands()`; see Design tab), so `tools/list` starts +with the app's state, the search and the generic call, and ends with the tools that drive the GUI. A tool is +made with `inspect_tool()`, `mutate_tool()`, `record_tool()` or `recover_input_tool()`, which take its group +first and build it through `long_command()` with its function unchanged, so it runs where its call does. A +function reaches the service through its call's context, `ToolContext::service()`: the core gives the service +that owns it (`McpCore::set_service()`), a person's pick starts the runtime without its endpoint, and a core +built on its own, as in a unit test, refuses, which ends the call in an error. Every key is unique across the +catalog, tools and Speed Dial commands together. + +Every command is called by its key: `tools/call`, `call_tool`, a replay step and a script's call reach a +Speed Dial command (`obj_arrange`, `load_project`) as they reach a tool, run and journal it as its own +call, and the Action Replay window describes such a step as `run_action` of its tile +(`describe_step()`). `tools/list` and the editors' tool list (`editor_tool_catalog()`) read the listed +commands only, in the order they were added, so they show the typed tools. `search_tools` reads every +command, then the plugin operations of the catalog's source (`search_commands()`; see Plugins and the +tools), so its one inventory finds a Speed Dial command's key as it finds a tool's. + +Four commands are both a tool and a tile: `new_project`, `save_project`, `start_recording` and +`stop_recording`. Each is registered once, in its tool's family, through `with_person_form()`, which gives the +tool the tile's title, icon and group (`Commands`) and its schema `silent` (`Mcp::with_silent()`). Called with +no arguments, each does what a person's pick does: New Project asks about unsaved changes, Save Project +saves to the project's file or asks for one, Start Recording opens its dialog, and Stop Recording stops the +recording without waiting for its file and shows the person where it went; an agent's call of that form +replies `blocked_by_dialog` while a dialog asks. New Project's and Save Project's tools are mutate calls, +so their form is refused where any mutate call is. The recording tools run behind dialogs, but Start +Recording's form, which opens a dialog, is refused while a modal dialog is open or another call's nested +loop runs (`UiInvoker::require_mutate()`); Stop Recording's form, which opens nothing, runs where the tool +does. With arguments, or `silent: true`, it is the tool, which asks nothing, and the journal keeps +`silent`, so a replay of it asks nothing either. `save_project`'s path is required once any argument is +given, under `then`; `start_recording` given arguments records for up to an hour unless `max_seconds` +says otherwise, and its reply says the limit it runs under. + +Each tool has a group (`NativeCommand::group`), the way it acts: `core` (the session, recovery from +dialogs, replays and Python), `api` (project data by index and name, JSON in and out, and the operations +plugins offer) or `ui` (the GUI itself); the four tools that are also tiles are in their tile's group, +`Commands`. Every caller reaches every tool, and the group only filters: `search_tools {group}` keeps the +commands and operations of one group, the Speed Dial's sections (`Object`, `View` and the rest) among the +groups, compared in any case, and its matches and `{tool}` replies say each one's group. A group no command +has is refused as an unknown name is, "Unknown group: …", naming the groups there are (`groups`). Each tool also has an access label, which `tools/list` sends as MCP's annotations. Clients act on it differently: Codex asks a person before every call of a destructive tool (unless it is also read-only), @@ -602,9 +621,11 @@ entry of `objects`, `instances` and `parts`: the `ObjectID` values `list_objects too. `check_expected_ids()` refuses the call before anything changes when the index names another object or part now, so a replay or script addresses what it read. `list_objects`' description says what the ids are for and names the tools that take them, so each property only points back at it. Ids are allocated per -process, so the journal leaves them out of those tools' calls (`without_expected_ids()`), through -`call_tool` and inline `run_replay` steps too, and a replay addresses by index; a `run_script` step's code -and `args`, and a plugin operation's own arguments, are kept as written. +process, so a tool that takes them names them in its `id_args`, which `with_expected_ids()` reads from its +schema where the tool is registered, and the core gives the journal its calls without them +(`without_expected_ids()`, which looks the command up in the catalog), through `call_tool` and inline +`run_replay` steps too, and a replay addresses by index; a `run_script` step's code and `args`, and a plugin +operation's own arguments, are kept as written. Descriptions keep one order: what the tool does, the arguments that change it, `Reply:` with the fields it has, then edge cases; a long one puts each case on a line of its own (the scopes of @@ -628,25 +649,22 @@ any of them. Where a tool takes two unlike things of one word, each says whose it is: `discard_changes` drops the project's unsaved changes, `preset_changes` keeps, transfers or discards the presets'. -An agent calls into three catalogs by name: the tools (with the operations plugins offer), the Speed -Dial's actions and the Design tab's CAD tools. `search_tools {query}` finds a name in any of them, -but each runs through its own tool, so a name reaches the wrong one: `call_tool {tool: "extrude"}`, -`run_action {id: "slice"}`, `call_cad_tool {tool: "list_objects"}`. The refusal then says where the -name does run, in place of the closest names of the catalog asked, which would point the wrong way. -`other_catalog_hint()` (McpToolsActions.cpp) looks the name up in the other two: the registry, the -CAD tool table, and `NativeCommands::catalog()`, the built-in commands, by key or full id. All three -answer on any thread, which the registry's other actions (plates, recent projects, plugin scripts) -do not, and those are not names an agent takes for a tool's. `ToolRegistry::unknown_tool()` builds -the error for every lookup of a tool that misses, through `set_elsewhere()`, which keeps the -protocol layer free of the GUI: `tools/call`, `call_tool`, `search_tools {tool}`, a replay step and a -plugin's or script's call. `run_action`, `call_cad_tool` and `describe_cad_tool` ask it themselves. +An agent calls into two catalogs by name: the commands (the typed tools, the Speed Dial's commands, the +Design tab's and the operations plugins offer) and the Speed Dial's actions, which `run_action` runs. +`search_tools {query}` finds a name in either, and a command runs by its key through `tools/call` and +`call_tool`, with `search_tools` giving the schema of one `tools/list` does not show. A name that misses +is answered with the closest names of the catalog asked and nothing else. +`CommandCatalog::unknown_command()` builds the error for every lookup of a command that misses: +`tools/call`, `call_tool`, `search_tools {tool}`, a replay step and a plugin's or script's call. +`run_action` gives the closest action ids, and says that `search_actions` finds an action and +`search_tools` a command, since the name may be a command's that has no tile; a tile's key runs its +command. For a Design tile that is not shown it says when the tile is there instead, and that `call_tool` +runs its command from any tab. -Each tool family registers itself from its own `McpTools*.cpp` through `register_*_tools()`. -List tools take `limit` and `offset` and reply `{items, offset, total}` (`page()`; `list_objects`, a tree, -has `plates` and `outside` in place of `items`), with `next_offset` while -more remain: `search_actions` and `list_cad_tools` too, whose one page holds every CAD tool by default. The -server instructions give that shape once, rather -than every description, and each `limit` states its default. `McpPaths.hpp` requires +Each tool family lives in its own `McpTools*.cpp`. List tools take `limit` and `offset` and reply +`{items, offset, total}` (`page()`; `list_objects`, a tree, has `plates` and `outside` in place of +`items`), with `next_offset` while more remain: `search_actions` too. The server instructions give that +shape once, rather than every description, and each `limit` states its default. `McpPaths.hpp` requires absolute paths, since a relative one would resolve against `/log`, the GUI's working directory; an output's directory must exist, and an existing file is replaced only with `overwrite: true`. Paths arrive and leave as UTF-8 text, and so does Orca's `data_dir()`; @@ -1244,74 +1262,139 @@ it with `save_preset`; staying in the test project, `set_settings {"reset_all": the preset's scope drops the test's settings there and sets the value in one call. The Speed Dial's `calib_*` commands still open the dialogs, and their descriptions point at `generate_calibration_test`. -### Design tab: `list_cad_tools`, `describe_cad_tool` and `call_cad_tool` +### Design tab: the Design commands -`call_cad_tool {tool, args}` is the one way into the Design tab, under the mutate guard. Its CAD -tools (`Mcp/McpToolsCad.cpp`) sit behind one generic tool rather than a schema each, so agents that -never open the Design tab pay nothing for them. One table, `kCadTools`, declares every CAD tool's -name, access and handler; `run_cad_tool()`, the busy gate and `cad_tool_table()` all read it. -`cad_tool_table()` is the table of record, built once from `tool_rows()` and `kCadTools`: one row -per CAD tool with a summary of one sentence (at most 120 characters), details, typed params with -units, defaults and `required` (true for a param without a default), its access, `failure` -(`error`, or `reply` with a `failure_note` for a tool that reports a rejected rebuild in its reply) -and examples. +The Design tab's sketches, features, reads and measurements, feature and body edits and its commit to the +plate are commands of the catalog (`Mcp/McpToolsCad.cpp`) in the group `Design`, not listed, so agents that +never open the Design tab pay nothing for them in `tools/list`. Those that open a tool are in the palette, +whose tiles for them the Speed Dial has while the Design tab is shown (see Speed Dial catalog). +`register_all_commands()` adds them through `register_cad_commands()` only when the catalog is built with +the CAD feature on (`CatalogOptions::cad`, which startup takes from `enable_cad_feature` in the editor). With +it off the catalog holds none: `call_tool {tool: "hole"}` is an unknown command, and `get_app_state` carries +`cad_note`, how a person turns the feature on (`cad_note()`, in the editor while the catalog holds no Design +command or the preference is off). The catalog is sealed at startup and the main window makes the Design +page only then, so turning the feature on or off takes effect after a restart, but for the Speed Dial's +Design tiles, which go as soon as it is turned off (see Speed Dial catalog); a window rebuilt for a +language change in between makes the page by the new preference, while the catalog keeps the commands it +started with. -Two inspect tools read the table, which needs no Design panel and no UI thread. `list_cad_tools -{query?}` gives each CAD tool's name, access and summary in the table's order, which groups them by -what they do, as a page like every list's (`items`, `offset`, `total`; its default limit of 200 -holds them all), with `ids` (how face and edge ids expire) and `use`; `query` keeps the tools whose -name, summary or details hold it, in any case, and `total` counts the ones kept. -`describe_cad_tool {tool}` gives the whole row of a name, or of each name of a list, once and in -the order asked, and `id_lifetime` when one of them takes or gives face or edge ids; an unknown -name fails with the close ones, or, when it is a tool's or a Speed Dial action's, with where that -runs, as `call_cad_tool` answers one too, before any of the refusals below (see Tool catalog). Both -answer with the CAD feature off too, and then add a `note` on -how a person turns it on. That preference lives in `AppConfig`, which Preferences may write -meanwhile, so it is read on the UI thread (`observe_ui`, `cad_feature_note()`), which the call waits -for up to the usual queue timeout of 10 s; when the UI does not answer by then, or refuses, the reply -goes out without the note, which is only advice. +One table, the Design tab's, declares every command: `kDesignTools` in `CAD/DesignOffer.hpp`, generated from +`scripts/CAD/tool_atlas.json`, which is also the right-click menu (`docs/HLSD/design-tab.md`). Every entry but +`align`, which has no GUI path, is a command: its id is the key and its name the title, so the body's move is +`body_transform`, apart from Prepare's `transform`, and the surface tools are `surf_extrude` and the rest. An +entry with an action, its menu row's, has a person's form and a tile. An entry with a tool block has a silent +form, whose function `kSilentForms` binds by the entry's id; a unit test fails for a block with no function +and a function with no block. The block gives the silent form's access, a summary of one sentence (at most 120 +characters), details, typed params with units, defaults and limits, one to three examples, and whether it +reports a rejected rebuild in its reply (`ok_false`); the header carries it as JSON text (`doc`). +`register_cad_commands()` makes a command of each entry (`cad_command()`), in the table's order: the menu's +verbs, then the 41 entries with no menu row, 133 commands in all. It is `read_only` for a `read` block, and +has the entry's icon. Its description is the summary, the details and, with `ok_false`, how a rejected rebuild +shows; an entry with an action only has its hint and what its call does: what its menu row or key does, which +may open a tool, start a sketch tool or act at once, with the status line in the reply, and the mode it runs +in, "only in an open sketch" or "only outside a sketch" by its row. Its examples are the block's, each +`{title, calls: [{tool, args}], needs?}` ending with the command it documents, where an argument +`{"from_call": i, "key": k}` is the value under `k` in the result of call `i`, and a call of a command that +has both forms with no other argument is `{"silent": true}`. Its input schema (`cad_input_schema()`) is built +from the params: a type written `"a|b"` is the list of both, `min`, `exclusive_min` and `max` are `minimum`, +`exclusiveMinimum` and `maximum`, `enum` and `default` carry over, the unit joins the description, and a param +without a default is required. A param whose default is null is one its function reads as left out when it is +null (no limit, the open sketch), so its type also admits null, and its enum holds null: `extrude {"sketch": +null}` runs the silent form on its default rectangle, as `extrude {"silent": true}` does. A param marked +`"nullable": false` keeps its type, as its function reads a null as a value given: `thread`'s `plane`, which a +thread on a plane resolves as the plane named, and `sketch_transform`'s `angle`, `scale`, `count` and `pivot`, +which an op they do not apply to refuses whenever they are present. For an entry with both forms it goes through `with_silent()`: `silent` is a +property, and what the silent form requires is under `"if": {"minProperties": 1}, "then": {"required": +[...]}`, so the call with no arguments, the person's form, requires nothing (`fillet {}` opens the Fillet +tool, while `fillet {radius: 2}` needs `edge`). The description, the silent form's, says nothing of that call, +so `silent`'s says what it does and the mode it runs in (all 32 such entries are the model's, outside a +sketch). An entry with an action only takes no argument at all (`additionalProperties: false`), so `sk_rect +{silent: true}` is refused by its schema. A limit is the one the tool's function or the kernel applies to +every call that passes the param, so the schema refuses no call the function would run: a distance that may be +negative, or a depth a through hole ignores, has none. A command with a silent form also takes `generation`, +never required, whose description says how face and edge ids expire, and its schema does not refuse an +argument it does not name, since a tool may read more (a param in radians also in degrees under its name with +`_deg`); the normalizer reads `index` as `feature` and `params` or `values` as `fields` +(`normalize_arguments()`), the names `describe_feature`, `set_feature` and the tree edits also read. -`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; the main -window creates the Design page 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 it. Then come an unknown CAD tool (`-32601`, with the close names and a -pointer to `list_cad_tools`), a busy Design tab (`-32002`), and a `generation` that is not an -unsigned integer (`-32602`) or not the model's (`-32010`). Before the generation is read, the -project's recipe is loaded into an empty document (`DesignPanel::hydrate_from_model()`), as showing -the tab would. +A call with no arguments of an entry with an action, an agent's or a tile's, is the person's form +(`open_tool()`). It passes `cad_gate()` with `CadAccess::None`, whose only busy rule is the rebuild's, so the +recipe is loaded and the call refused while the model is being rebuilt, and runs the action in place +(`DesignPanel::mcp_run_verb()`), as the menu's row and the tab's keys do: an open card does not refuse it, +since each tool decides what that means to it. Before the action, `open_refusal()` refuses it in two cases +(`-32000`). An entry runs only in the mode its row belongs to, where the right-click menu offers it +(`offered_in_mode()`, by the menu's `sketch_map_applies()`, for which a sketch in Constrain mode is open too): a +model tool such as Shell in an open sketch is refused with "This tool works on the model: finish or cancel the +sketch first" (`mode: "model"`), a sketch tool outside a sketch with "This tool works in a sketch: open a +sketch first" (`mode: "sketch"`). No entry is offered in both modes, and the only keys read in both, the +Ctrl+Shift ones, are no entry's action. The tab's keys take the sketch's entries only in Sketch mode, so in +Constrain mode they reach the model's while the menu offers the sketch's: there a command does what its menu +row does, not what its key does. And an action that only the right-click menu reaches (`btn:`, `fly:`), +whose row the menu greys for a selection it does not accept, is refused for one with "This tool does not apply +to what is selected", its details naming the selection (`selection_kind`, `selection`) and the atlas ids of +those the row accepts (`accepts`). It never gives the row's refusal, which is about the document (no body yet) +and which the menu shows only for a row that takes the selection. A `key:` action runs whatever is selected, +as its key does. The reply is `{"result": {"interactive": true, "tool", "applies", "modal", "selection_kind", +"busy", "status"}}`: whether the row accepts the selection, whether a dialog the action opened held the call +until it was answered (the atlas's `modal` entries but Text, whose dialog is modeless: +`DesignPanel::mcp_text_dialog_open()` tells it), the selection's kind, `mcp_busy()`'s reason after the action +(a card, a dialog or a sketch now open) or null, and the text of the tab's status line (`DesignPanel::mcp_status()`). It claims nothing about +what the action did, which may be to open a card, arm a sketch tool, act at once, or say on the status line +why it cannot (Loft with fewer than two profile sketches). A modal dialog the action opens holds the call, +which the core reports as blocked by it, as for `new_project {}`; Text's dialog is modeless, so `sk_text {}` +replies at once with a `busy` that names it, and its own Cancel or Escape closes it. For a person's pick, a +refusal is shown in the UI's language where its text is a msgid, as these three refusals are. `describe_scene` +gives `selection`, `{kind, id}`, the selection the right-click menu would be built for, by its `OfferSel` and +its atlas id (`kDesignSelectionIds`). -Access decides what `DesignPanel::mcp_busy()` lets through. Nothing runs while a rebuild's worker -owns the document; otherwise `read` CAD tools always run. `change` and `sketch` CAD tools are -refused under an open feature card, the Text dialog, Constrain mode or an open body Move. A card -holds a candidate built from the document as it was when it opened, which a change underneath would -overwrite, or be overwritten by, on Confirm; the Move holds a body index that a change could point -at another body. A sketch session lets `sketch` CAD tools through, since driving it is their point, -and refuses `change` ones, as the GUI would not let the edit land there. +An agent finds them as it finds any command: `search_tools {group: "Design"}` lists their names, a query +finds them among the commands with their input schemas, and `search_tools {tool}` gives one's group, +`read_only`, description, input schema and examples. `call_tool {tool, args}` runs one, its arguments +validated against its schema, and replies `{"result": ...}`, the tool's own reply; a replay step calls one +by its name or through `call_tool`, and `orca_mcp.py`'s `call_command()` from Python. An unknown name is +answered as any unknown command is, with the closest key. -A CAD tool that fails is an error (an `isError` result with `code` `-32000`, `OCCT: …` for a kernel +A call runs its function on the UI thread: a person's pick in place, an automated call in one UI closure +under the mutate guard, then `settle()`. Before the silent form, `cad_gate()` 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); 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 has the page. Then come a busy Design tab (`-32002`), +and a `generation` that is not an unsigned integer (`-32602`) or not the model's (`-32010`). Before the +generation is read, the project's recipe is loaded into an empty document +(`DesignPanel::hydrate_from_model()`), as showing the tab would. + +A silent form's access (`CadAccess`, from its block) decides what `DesignPanel::mcp_busy()` lets through. +Nothing runs while a rebuild's worker owns the document; otherwise `read` commands always run, and so does the +opening of a tool. `change` and `sketch` commands are refused under an open feature card, the Text dialog, +Constrain mode or an open body Move; in Constrain mode `sketch_commit` and `sketch_cancel` are refused too, +and the tab's own Confirm or Cancel ends it. A card holds a candidate built from the document as it was when +it opened, which a change underneath would overwrite, or be overwritten by, on Confirm; the Move holds a body +index that a change could point at another body. A sketch session lets `sketch` commands through, since +driving it is their point, and refuses `change` ones, as the GUI would not let the edit land there. + +A Design command that fails is an error (an `isError` result with `code` `-32000`, `OCCT: …` for a kernel exception) and leaves the design as it was, so `export_replay` drops it and a replay never repeats a call that did nothing. That holds for argument errors and for a rebuild the kernel rejects alike. -The exceptions are the CAD tools whose `failure` is `reply` (`fillet`, `chamfer`, `boolean`, -`pattern`, `mirror`, `shell`, the surface tools, `import_step`, `set_variable` and others): they -report a rejected rebuild in their reply, `{ok: false, error}`, after the same rollback, so such a -call is journaled and replays the same rejection. `extrude`, `revolve`, the `hole` tools, `split` +The exceptions are the silent forms whose block has `ok_false`, whose descriptions say so (`fillet`, +`chamfer`, `boolean`, `pattern`, `mirror`, `shell`, the surface tools, `import_step`, `set_variable` +and others): they report a rejected rebuild in their reply, `{ok: false, error}`, after the same +rollback, so such a call is journaled and replays the same rejection. `extrude`, `revolve`, the `hole` tools, `split` and `sketch_add` fail as errors, so none of them fails two ways depending on its arguments. The feature tools that fail as errors add through `add_feature()`: one checkpoint, a rebuild, and on failure `CadDocument::rollback()`, which restores the checkpoint without leaving the refused recipe on the redo stack and with the redo branch the checkpoint cleared, then "Edit rejected" on the -status line as for a refused GUI edit. Features made through `call_cad_tool` are named as the cards +status line as for a refused GUI edit. Features made through a Design command are named as the cards name them ("Extrude 3"), from the panel's own counter. `generation` guards face and edge ids within a session, but its value depends on the session's -history, so the journal records `call_cad_tool` without `args.generation` and a replay rebuilds the -same ids. +history, so the journal records a Design command's call without `generation`, and with `silent`, which it +adds to a call of a command that has both forms when the call gave nothing else, so that the replay runs the +silent form rather than opening the tool; a replay rebuilds the same ids. -The plane-taking CAD tools (`sketch_begin`, `extrude`, `revolve`, the `hole` tools, `thread`, +The plane-taking commands (`sketch_begin`, `extrude`, `revolve`, the `hole` tools, `thread`, `split`, `pattern`, `mirror`, `helix`, `project`) share one resolver, `cad_resolve_plane()`: `"XY"`, `"XZ"` or `"YZ"` through `modeling_origin`, `{"datum": i}` for a Plane feature, or `{"body": b, "face": f}` for a planar face. A face plane for sketching is @@ -1328,7 +1411,7 @@ evaluate), the bodies with the feature that made them, whether their eye is on, canvas draws and whether the Move gizmo placed them, the undo and redo depth, mate conflicts and the document's `auto_close_loops`. `describe_feature {feature}` reads one feature as its card shows it, from one per-type table, `feature_card()`: `params`, the `editable` ones named as the -`CadFeature` members (the names `set_feature_expr` binds) with the `ranges` of the card's spin +`CadFeature` members (the names `edit_feature` binds) with the `ranges` of the card's spin controls, `expr`, the structure the card keeps in `refs` (feature and body indices, face and edge ids), a sketch's plane, entities and constraints (snake_case types, point references with a role, angles in degrees), `used_by` / `bodies_made`, and, for imported Text or SVG art, how many regions it @@ -1345,7 +1428,7 @@ its choices). A field an expression drives is refused, since the next rebuild wo and so is an end condition that needs a pick the feature does not hold. A rebuild the kernel refuses fails the call after `rollback()`. Numeric fields go through `CadDocument::set_numeric_field()`, the allow-list expressions use, so a literal edit and a binding -reach the same fields. An empty `expr` removes a binding (`set_feature_expr`) or a variable +reach the same fields. An empty `expr` removes a binding (`edit_feature`) or a variable (`set_variable`), as the Variables panel's Clear and Remove do; a binding on a field the evaluator does not know, or removing one that is not there, is refused. @@ -1396,7 +1479,7 @@ indices move down. `sketch_constraints` reads the open sketch's constraints, or by `sketch`. Live sketch edits are not on the Design undo stack until the commit, as in the GUI. `query_topology` reads a body from one enumeration (`faces_of()`, `edges_of()`, whose ordinals are -the ids every other CAD tool takes). A face's kind is its OCCT surface type, from +the ids every other Design command takes). A face's kind is its OCCT surface type, from `GeometryEngine::surface_info()`, with its area and the numbers that define it: a cylinder's radius and axis, a cone's apex, axis into its opening, half angle and the radii the face reaches, a sphere's centre and radius, a torus's centre, axis and radii; `internal` marks a bore or a @@ -1417,7 +1500,7 @@ OCCT's `BRepExtrema_DistShapeShape`), and `parallel_gap` across two parallel pla may name its own body, and `{"face": f, "axis": true}` stands for a cylinder's axis over the face's length, so a hole's height or spacing is one call. -The hole tools drill a face plane's own body, or the body `body` names, else the last body, and +The hole commands drill a face plane's own body, or the body `body` names, else the last body, and take `at` instead of `x`/`y`: a world point projected onto the plane along its normal (the reply's `off_plane` says how far), or a cylindrical face or circular edge whose axis the hole shares, which replays on any printer. `cad_hole_placement()` resolves all of it before the checkpoint. `extrude @@ -1452,16 +1535,36 @@ and inspection tools answer from inside that loop: `get_app_state`, `list_widget non-modal `wxProgressDialog` titled "Design") and `screenshot`, of the window or of the dialog's own ref. On Windows the dialog is the system's task dialog, run on a thread of its own, so it is no wx window and `list_widgets` does not list it; the other tools answer as elsewhere. Mutating calls, -another `call_cad_tool` among them, are refused by `UiInvoker` as running inside `call_cad_tool`, and -`mcp_busy()` refuses every CAD tool while a rebuild's worker owns the document, the GUI's own -rebuilds included. A call past the reply budget becomes a running job. +another Design command and `undo` among them, are refused by `UiInvoker` as running inside the +rebuilding call ("Busy: thread is still running"), and `mcp_busy()` refuses every Design command while +a rebuild's worker owns the document, the GUI's own rebuilds included. A call past the reply budget +becomes a running job. -`undo` and `redo` are Edit > Undo and Redo with the Design tab shown (`menu_undo_redo()`, behind -the same `menu_can_undo_redo()` gate): the Design history, or inside a sketch session the sketch's -own, which takes off or puts back the last drawn shape. `run_action undo` stays Prepare's history. -They have sketch access, so they run in a sketch session, and like every changing CAD tool they are -refused under an open card, Constrain mode or a pending body Move. The Design history is not saved -with a project. +`undo` and `redo` are the Speed Dial's commands (`NativeCommands.cpp`), shared by the Design tab and +the project, and act on the history of the tab shown, as Edit > Undo and Redo and the top bar's buttons +do: the Design tab's while `MainFrame::shown_design_panel()` is not null, else the project's. +`history`, `design` or `project`, names one for automation, which acts whatever tab is shown: a Design +command runs with Prepare in front, so a replay that drives the Design tab from there would otherwise +undo a project change. The Design history's is `cad_undo_redo()`: Edit > Undo and Redo with the +Design tab shown (`menu_undo_redo()`, behind the same `menu_can_undo_redo()` gate), the Design +history, or inside a sketch session the sketch's own, which takes off or puts back the last drawn +shape, past `cad_gate()` with sketch access, so it runs in a sketch session and is refused under an +open card, Constrain mode or a pending body Move, and during a rebuild. A refusal is the call's error +and never falls through to the other history. The project's is `Plater::undo()` and `redo()`, the Edit menu's, +which step past the snapshots that do not modify the project to the nearest one that does and load it, and leave +the active snapshot where it is when there is none, while a background job holds the model, or (undo) in the +assemble view for a record that is not a gizmo's. The call counts the active history's undo and redo items before +and after (`Plater::undo_redo_string_getter()`), which change only when the active snapshot moves, and is refused +with "Nothing was undone in the project's history" (or redone) when neither changed. Success means an entry of the +history was taken back or put back, as the Undo list shows it, not that the project differs afterwards: the plater +classes a snapshot by its type, and an action can leave one that changed nothing (renaming an object to the name it +has). That is an automated call's, `run_action` of the tile +included: a person's pick from the Speed Dial does what the Edit menu's item does, through +`menu_undo_redo()`, and where `menu_can_undo_redo()` greys that item it does nothing and shows +nothing. The reply is the tile's, with `history` and, for the +Design tab's, `result`, `cad_undo_redo()`'s reply; with the CAD feature off, or in a build without CAD, +`design` fails ("The CAD feature is off"). Their examples, which call Design commands, are only in a +catalog that holds them. The Design history is not saved with a project. The Feature tree's and Bodies list's edits are split from their handlers into index-taking `DesignPanel` cores that the handlers call after resolving the selected row, so `feature_delete`, @@ -1487,9 +1590,9 @@ List's delete path, under one outer snapshot so the commit and the deletions are step. It refuses before anything changes: an index out of range or repeated, an object that is part of a cut (deleting one asks the person first), an open gizmo, a design with no body, or every body hidden. The reply gives the new objects' `list_objects` indices after the deletions. -`commit` is the one CAD tool that changes Prepare's model. It needs no refusal of its own: -`call_cad_tool`'s mutate guard keeps every CAD tool out of a modal dialog and out of another call's -nested event loop. +`commit` is the one Design command that changes Prepare's model. It needs no refusal of its own: +the mutate guard a Design command's call runs under keeps it out of a modal dialog and out of another +call's nested event loop. `new_design {discard_changes}` is New Design without its confirmation: `clear_document()`, which also clears the Design undo history and leaves committed objects on the plate. A design with @@ -1514,14 +1617,16 @@ A change made only in the Design tab marks the project modified, as other projec Prepare's undo stack does: `sync_recipe_to_model()` sets the plater's dirty flag besides the backup's change mark. So `get_app_state.project.dirty`, the window title and `open_files` / `new_project {discard_changes}` agree with the unsaved-changes prompt that Open and New Project -show. A project holding only a design loads no objects, and `Plater::load_project()` still names -it after its file, since a loaded recipe counts as a loaded project. +show. A project holding only a design loads no objects, and `Plater::load_project()` names it after +its file all the same, since a loaded recipe counts as a loaded project. -`tests/slic3rutils/test_mcp_cad.cpp` (`[Mcp][CAD]`) checks the CAD tool table against `kCadTools` -and its readers (`cad_list_tools()`, `cad_describe_tool()`), the CAD-off note, the plane resolver, -the rollbacks, and the CAD tools through their public seams +`tests/slic3rutils/test_mcp_cad.cpp` (`[Mcp][CAD]`) checks the Design commands as the catalog holds +them (one per entry of the Design table but `align`, a silent form for every block and a block for every +silent form, which entries have a tile and an icon, their schemas, descriptions and access, and every +example's calls against their commands' schemas), that none is registered with the feature off, how a call is +journaled, the plane resolver, the rollbacks, and the tools through their public seams (`cad_sketch_extrude()`, `cad_sketch_call()`, `cad_query_topology()`, `cad_thread()` and the rest), -which take a `CadDocument` or a bare `DesignSketchTool` and need no Design panel. The replay +which take a `CadDocument` or a bare `DesignSketchTool` and need no Design panel. The replays run on an instance that `tools/mcp/orca_mcp.py launch --cad` starts: `tools/mcp/tests/cad_sketch_to_solid.json`, `cad_sketch_edit.json`, `cad_topology_targets.json`, `cad_features.json`, `cad_doc.json` and `cad_canvas.json` (the Design view as a canvas target, its @@ -1530,27 +1635,117 @@ failed calls and `generation`s, exports it and replays it to the same features a properties; `tools/mcp/test_cad_slow_build.py` checks the window during a guarded rebuild; `tools/mcp/test_cad_failed_job.py` exports a session whose call failed after its reply budget (a hole that misses a slow-to-rebuild coil), which leaves it out, and replays it. +`tools/mcp/test_cad_examples.py` runs every example, `undo`'s and `redo`'s too, each on a fresh design, +and fails an example when a call fails or its result has `ok` false, an error, or is the person's form. `tools/mcp/test_cad_sketching.py`, `test_cad_context_menu.py` and `test_cad_click_edit.py` drive the Design tab through the GUI tools as a person does (canvas gestures, typed values, the offer -menu, file pickers answered by path rules) and read the result back with `read` CAD tools. +menu, file pickers answered by path rules) and read the result back with `read` Design commands. ## Speed Dial catalog `search_actions` and `run_action` serve the Speed Dial's `ActionRegistry`: built-in commands, plates, recent projects, plugin scripts and pages, and, on request, settings. Built-in commands are -`NativeCommand`s in `NativeCommands.cpp`, with three fields for automation that the palette never -shows: `description` (English, for agents), `param` (a `CommandParam {type, help}`, typed `None`, -`Percent`, `Tab`, `Path`, `Index` or `Text`) and `completion` (`Export` when the effect finishes in -the background after `run()` returns). `describe_commands()` fills them from one table, with a -key-prefix rule for calibration dialogs (pointing at `generate_calibration_test`), camera views and primitives, and `CommandAction` copies -them into the `AppAction`. The palette keeps `input` for its picker and never passes a path. +`NativeCommand`s, added by `register_all_commands()` (`NativeCommands.cpp`). Beside what the palette +shows, each has what automation reads: `description` (English, for agents), `input_schema` (the JSON +Schema of its arguments) and `completion` (`Export` when the effect finishes in the background after the +command returns). `describe_commands()` fills the descriptions from one table, with a key-prefix rule for +calibration dialogs (pointing at `generate_calibration_test`), camera views and primitives; +`CommandAction` copies them, the schema and the command's key into the `AppAction`. + +The commands live in one `CommandCatalog` (`CommandCatalog.hpp`, which includes no wx), built once at startup +by `NativeCommands::build()` before the MCP service starts, and sealed: from then on it never changes and any +thread reads it (`NativeCommands::instance()`, `find()`). A process that never calls `build()`, +such as the unit tests and the stdio bridge, gets it built on first use; nothing in the GUI process reads it +before startup builds it, the MCP service included, which `GUI_App` starts after `build()`. +`register_all_commands()` adds the Speed Dial's commands, then the typed tools (see Tool catalog). Those with +`in_palette` have a tile, and `ActionRegistry` makes an action of each of them (`palette_commands()`) and of +nothing else in the catalog: no typed tool has one, but the four that are also a Speed Dial command. The +Design tab's are the exception: `palette_commands()` leaves group `Design` out, and +`ActionRegistry::materialize_design_actions()`, which `materialize_live()` runs beside the plate and +recent-project families for `snapshot()`, `describe()` and `find_live()`, holds a tile for each Design command +with `in_palette` whose entry is offered in the tab's mode (`Mcp::design_tiles()`, by `Mcp::offered_in_mode()`) +while `MainFrame::shown_design_panel()` is not null and the CAD feature is on, and none otherwise, so the Speed +Dial has the sketch's tiles in an open sketch, the model's outside one, and no Design tile on another tab, nor +once the feature is turned off: the tab stays until the restart, but `cad_gate()` would refuse every pick of +its tiles. A tile's title is `NativeCommands::tile_title()`: for a Design command, the entry's name translated +with the `Design` context (`title_context()`), as the right-click menu translates it, and its icon is the +entry's. Every place that shows a person a command's title translates it so: the Action Replay window's step +and its summary line, a person's job notices ("Started", "Finished"), the tool list of the replay and script +editors, and a recording's caption of a call (`CaptionBoard` keeps the context beside the title). Every +entry's name is marked for translation in that context (`gen_offer_table.py` writes it as `L_CONTEXT`), also +an entry's with no menu row, which has no tile but is shown in these places. A pin of a Design tile stays in +the stored favourites while its tile is not live, and only leaves the bar that is shown (`prune_favourites()`, +`is_design_tile_id()`, which goes by the Design table, so also when the CAD feature was off at startup). Every +other pin with no live action is dropped. A build without CAD has no Design tile, and drops such a pin as any +other. The bar's limit of ten is on what it shows: the first ten live pins in their stored order. A pin is +refused only while the bar shows ten (`add_favourite()`), so a hidden pin never fills it, and a live pin past +the tenth stays stored and comes onto the bar once a pin before it is unpinned. After each pin, unpin and reorder +the open Speed Dial's page is sent the bar as the registry then shows it (`SpeedDialWebDialog::send_favourites()`, +`ActionRegistry::favourites_bar()`), which replaces the page's own after the click's instant change, so the page +never shows fewer pins than the registry counts. Reordering the bar moves the +pins it shows among their own places, and every other pin keeps its place (`reordered_favourites()`). Ordinary +use stores at most thirty pins, ten for each of the three sets of live actions the bar is shown with (the +Design tab's model, a sketch, and every other tab); reading the stored list cuts it to +`ActionRegistry::kFavStoredLimit` (100), so a corrupt configuration cannot grow it. + +### One function, JSON arguments + +A command has one function, `run(args, context)`, which the palette, a menu and every automated caller +call. Its arguments are a JSON object that matches its `input_schema`, and every caller checks them first +with `Mcp::argument_error(command, args)`, which normalizes them as a tool's (`normalize_arguments()`) and +validates them. The context is a `Mcp::ToolContext`: the MCP core's for a call, or a `Mcp::PersonContext` +(`McpPersonContext.hpp`) for a person's pick, whose `person()` is true. A person's context runs UI +closures in place, has no job, no journal entry and no operation to hold, and reads as cancelled once +OrcaSlicer is closing; it needs no MCP service, so every tile runs with the server off. + +Two helpers wrap the function a command's author writes and place it on the thread it needs: + +- `ui_command(key, title, group, schema, fn, completion)`: `fn(args)` runs on the UI thread and returns an + `AppActionRunResult`, what a person's pick shows. Picked by a person, it runs in place, and the reply + carries that result as its `notice`. Called by automation, it runs in one `ctx.run_ui()` closure, then + `settle()`, and `from_run_result()` makes the reply: `{ran, level, message?}` with the fields of the + result's `reply`; an error for an Error or Busy level and for a command that did nothing, worded from an + operation's refusal in English with `{code, names?}` as details. With `CommandCompletion::Export` and + arguments, the closure first holds the project as an operation (`ctx.begin_operation()`), takes the + plater's export ticket around `fn`, and the call waits for the file (`await_gcode_export()`). +- `long_command(key, title, group, schema, fn, inline_call)`: `fn(args, ctx)` runs where its call does, + on the job's thread for an automated call. Picked by a person it is started as a job and returns at + once (`ctx.submit()`), since it must not hold the UI thread; a command with `inline_call` runs in place + instead. A person's context submits it with `McpCore::submit()` on the service's core, started without + its endpoint when the server is off: the job runs as a client's call does, under the same guards and + operation admission, is not journaled, and is marked as a person's run (`McpService::as_person()`), so a + script it runs runs as the person's. The pick replies at once with the notice "Started:" and the + command's title, or an Error when no job started (another operation holds the project, the app is + closing); the job's result shows as a notification when it ends. + +The palette and the menus call `NativeCommands::run(key, args)`: it checks the arguments, runs the command +with a person's context and returns the notice for `notify_result()`, or an Error holding the message when +the arguments are refused, the command throws or it fails without a notice. + +A command whose silent form needs a value has a person's form too, which asks for it: with no arguments +(`Mcp::person_form()`), a command opens its dialog as a person's pick does; with arguments that stand for +the dialog, it runs without asking. A path skips a file dialog, the Primitive size dialog's dimensions skip +that dialog, and so on (the tables below). Over automation this holds too: `export_gcode {}` opens its file +dialog and replies `blocked_by_dialog`. A command with one form, which needs its value, requires it in its +schema: Go to layer (`percent`) and Go to tab (`tab`), whose value the palette collects in its second phase +(`input`) and passes as `{"percent": 50}` or `{"tab": "preview"}`; called without it, they are refused. +A two-form command whose silent form also needs no argument takes `silent: true` (`Mcp::with_silent()`): +the schema gains `silent`, which only `true` fits, and moves the silent form's `required` list under +`"if": {"minProperties": 1}, "then": {"required": [...]}`, which the validator reads as "required once any +argument is given"; it reads no other use of `if`. `with_person_form()` makes such a command of a typed +tool and the tile's person's form, which runs as a `ui_command()` function does: `new_project`, +`save_project`, `start_recording` and `stop_recording` (see Tool catalog). Their silent form is the tool's +own function, which gets the arguments as given, `silent` included, so the journal records the call as +silent. + +### search_actions and run_action `ActionRegistry::describe(Query)` lists the actions, sorted by group and title, one page of them (`{items, offset, total}`). It can filter by group, lists settings only when asked, and keeps the actions whose id, title, group, source or description holds its `text`, including the English -aliases. Each entry has `id`, the English `title` and `group`, `kind`, `description`, -`param {type, help}`, and `completes: "export"` for exports. Built-in ids look like -`orca_command::orca`. +aliases. Each entry has `id`, the English `title` and `group`, `kind`, `description`, `command` (the +catalog key) for a command's tile, its `input_schema` when it takes arguments, and `completes: "export"` +for an export. Built-in ids look like `orca_command::orca`. `search_actions` gives `describe()` no text. An agent's query is a few words ("delete object"), which no action holds as one text, so `rank_actions()` (McpToolsActions.cpp) scores the listing with @@ -1562,80 +1757,95 @@ matching more of them in what they are called, then the shorter key, which is th `obj_delete` before `obj_delete_all`. The key is scored without the `orca_command:` and `:orca` around it, which would make "orca" and "command" match every built-in. `search_tools` ranks its `actions` with the same function, so the query that found an action there finds it, and -the rest, here. +the rest, here. Its `actions` are the actions that are no command (plates, recent projects, plugin +scripts and pages): a command's tile carries its key (`describe()`'s `command`), and the command is among +`search_tools`' commands already, so it appears there once. -`run_action` also takes the key alone (`plate_add`) when only one action -has it, as agents and the tools' own messages write it. `run_action` calls -`ActionRegistry::run(id, param, record_stats=false)`, so agent runs never reorder the palette. An -unknown id that is a tool's name or a CAD tool's is answered with where that runs (see Tool catalog); -any other returns up to three close ids, scored by edit distance against both the full id and its -key, a key that contains the request (`delete_all` in `obj_delete_all`) counting as closest. An action -with `completes_in_background` that gets a path runs as an export operation and completes when the -file is written. +`run_action {id, args}` also takes the key alone (`plate_add`) when only one action has it, as agents and +the tools' own messages write it. It resolves the id on the UI thread with `ActionRegistry::find_live()`, +which first re-materialises the families whose membership follows live state (plates, recent projects, the +Design tab's tiles; settings are not, being thousands), so the call after one that added a plate, opened a +sketch or switched the tab finds the tiles of the app as it is then, and no longer one that is gone. The +Speed Dial's own picks run from the snapshot it was opened with. An unknown id returns up to three +close ids, scored by edit distance against both the full id and its key, a key that contains the request +(`delete_all` in `obj_delete_all`) counting as closest, and says where to find an action or a command (see +Tool catalog); the id or key of a Design tile that is not live says instead that the tile is there only while +the Design tab is shown in its mode with the CAD feature on, and that `call_tool` runs its command from any +tab (`unknown_action()`). A command's tile runs the command's own function: +`args` are checked against its schema, and it runs through a `Mcp::TileContext`, which is `run_action`'s +own context except that a command rewriting its journal entry does so inside `run_action`'s, as +`{"id": ..., "args": ...}`, so a recorded session replays through `run_action`; the reply's `ran` is the +resolved id. Any other action (a plugin's script or page, a plate's, a setting's, a recent project's) takes +no arguments, so `args` other than `{}` are refused, saying so (`action_args_error()`); it runs through +`ActionRegistry::run(id, args, record_stats=false)`, so agent runs never reorder the palette, and replies as a +command does. -Given a path, a command with a `Path` param skips its file dialog and calls an entry point that has -none: an operation of `GUI/Operations` where a tool does the same thing (see The operations layer). -Without a param, it behaves as it does in the palette. The param is an absolute path, or, for -outputs, a JSON object string `{"path": "...", "overwrite": true}`. `path_param()` resolves it and -turns a bad path into an Error result. +### Commands that replace a dialog -| Command | Takes | Entry point | +Given its arguments, a command skips its dialog and calls an entry point that has none: an operation of +`GUI/Operations` where a tool does the same thing (see The operations layer). A path is absolute; an output +takes `overwrite: true` to replace a file that exists. `path_argument()` resolves `{"path", "overwrite"?}` and +turns a bad or missing path into an Error result. + +| Command | Arguments | Entry point | |---|---|---| -| `load_project` | `.3mf` | `Plater::load_project(path)`; still asks about unsaved changes | -| `import_file` | model file | `Ops::import_models()`: the file's geometry (a project file's settings are not loaded), as one undo step | -| `import_configs` | `.json`, `.zip`, `.orca_printer`, `.orca_filament`, `.orca_bundle`; `.gcode` | `Ops::import_presets()`; for G-code `MainFrame::load_config_file(path)` | -| `save_project_as` | output `.3mf` | `Ops::save_project_as()` | -| `export_gcode` | output `.gcode` | `Ops::start_gcode_export()`; completion `Export` | -| `export_sliced_file`, `export_all_sliced_file` | output `.gcode.3mf` | `Ops::export_sliced_3mf()` | -| `export_stl` | output `.stl` | `Ops::export_stl()` | -| `export_3mf` | output `.3mf` | `Ops::export_model_3mf()` | -| `export_stl_multi` | existing directory | `Plater::export_stl(..., multiple, dir)` | -| `add_primitive_svg` | `.svg` | `GLGizmoSVG::create_volume(path, type)`: a new object, or a part of the selected one; a job | -| `export_config` | existing directory | `ExportConfigsDialog(parent, dir)`: the dialog still opens, and its OK writes there | -| `install_local_plugin` | `.py`, `.whl` | `install_local_plugin_package(path, parent, message)`, the Plugins dialog's install: it still asks before replacing an installed plugin, in Orca's own "Overwrite Plugin" message dialog, which `answer_dialog` answers on every platform. Cancel makes the command an error saying that the plugin was not installed. A file that is not a `.py` or `.whl` is refused before that. A package that fails inspection or installation is an Error whose message is "Plugin installation failed:" and the reason, such as a `.py` without a name in its PEP 723 `[tool.orcaslicer.plugin]` table | +| `load_project` | `path`: `.3mf` | `Plater::load_project(path)`, which asks about unsaved changes as Open Project does | +| `import_file` | `path`: model file | `Ops::import_models()`: the file's geometry (a project file's settings are not loaded), as one undo step | +| `import_configs` | `path`: `.json`, `.zip`, `.orca_printer`, `.orca_filament`, `.orca_bundle`; `.gcode`; `on_conflict` | `Ops::import_presets()`; for G-code `MainFrame::load_config_file(path)` | +| `save_project_as` | `path`: output `.3mf`, `overwrite` | `Ops::save_project_as()` | +| `export_gcode` | `path`: output `.gcode`, `overwrite` | `Ops::start_gcode_export()`; completion `Export` | +| `export_sliced_file`, `export_all_sliced_file` | `path`: output `.gcode.3mf`, `overwrite` | `Ops::export_sliced_3mf()` | +| `export_stl` | `path`: output `.stl`, `overwrite` | `Ops::export_stl()` | +| `export_3mf` | `path`: output `.3mf`, `overwrite` | `Ops::export_model_3mf()` | +| `export_stl_multi` | `path`: existing directory | `Plater::export_stl(..., multiple, dir)` | +| `add_primitive_svg` | `path`: `.svg` | `GLGizmoSVG::create_volume(path, type)`: a new object, or a part of the selected one; a job | +| `export_config` | `path`: existing directory | `ExportConfigsDialog(parent, dir)`: the dialog opens, and its OK writes there | +| `install_local_plugin` | `path`: `.py`, `.whl` | `install_local_plugin_package(path, parent, message)`, the Plugins dialog's install: it asks before replacing an installed plugin, in Orca's own "Overwrite Plugin" message dialog, which `answer_dialog` answers on every platform. Cancel makes the command an error saying that the plugin was not installed. A file that is not a `.py` or `.whl` is refused before that. A package that fails inspection or installation is an Error whose message is "Plugin installation failed:" and the reason, such as a `.py` without a name in its PEP 723 `[tool.orcaslicer.plugin]` table | +| `open_preferences` | `tab`, `key` | `GUI_App::open_preferences(tab, key)`: the dialog opens on that tab, scrolled to the preference | +| `plate_goto` | `plate`: 0-based | `Ops::select_plate()` | The six shape commands (`add_primitive_cube`, `_cylinder`, `_sphere`, `_cone`, `_disc`, `_torus`) -take a `Text` param, the size the Primitive size dialog asks for (`"40 40 10"`, `"90 4"`), and then -call `ObjectList::load_generic_subobject(type, INVALID, true, size)`, which skips the dialog. A param -with the wrong count of positive numbers is an Error result. With an object selected they add +take `size`, the dimensions the Primitive size dialog asks for in its order (`[40, 40, 10]`, `[90, 4]`), +and then call `ObjectList::load_generic_subobject(type, INVALID, true, size)`, which skips the dialog. A +size with the wrong count of positive numbers is an Error result. With an object selected they add nothing (`ObjectList::can_add_shape_object()`), and say so as an Error, in the palette too. The object structure commands stand for the object list's context-menu items and the plate menu's Order By. Like those items, they act on the object list's selected rows, which `select_objects` sets: -| Command | Param | Entry point | Refused when | +| Command | Arguments | Entry point | Refused when | |---|---|---|---| | `obj_type_part`, `_negative`, `_modifier`, `_support_blocker`, `_support_enforcer`, `_precise_seam` | none | `ObjectList::set_volume_type(type, true, false)` | a selected row is not a part; the object's last solid part; a text or SVG part to a support or seam type | -| `obj_rename` | Text: the name | `ObjectList::rename_item(item, name)` | not one object or part row; characters a file name cannot hold | -| `obj_set_instances` | Index: 1-1000 | `Ops::set_instance_count()` | no object selected; 0 (use `obj_delete`); a cut object; an unprintable instance | +| `obj_rename` | `name` | `ObjectList::rename_item(item, name)` | not one object or part row; characters a file name cannot hold | +| `obj_set_instances` | `count`: 1-1000 | `Ops::set_instance_count()` | no object selected; a count below 1 (use `obj_delete`) or above 1000; a cut object; an unprintable instance | | `obj_assemble` | none | `ObjectList::merge(true)` | fewer than two object rows; a cut object | | `obj_instances_to_objects` | none | `ObjectList::split_instances()` | no object with more than one instance selected | -| `obj_order_by_name`, `_filament`, `_height`, `_size` | Text: `all` for every plate | `ObjectList::order_objects(order, all)` | no objects to order; a gizmo is open | +| `obj_order_by_name`, `_filament`, `_height`, `_size` | `all`: every plate | `ObjectList::order_objects(order, all)` | no objects to order; a gizmo is open | Change Type checks the rows itself: with no part row selected, `set_volume_type()` falls back to the 3D selection, which for a selected object holds every part, a change no menu offers. That function returns why it changed nothing and shows it only for the menu (`show_errors`), so the rule stays in one place. `rename_item(item, name)` and `set_number_of_copies(num)` are the work of the Rename and -Set number of instances items without their dialogs, which the items keep; without a param, the +Set number of instances items without their dialogs, which the items keep; with no arguments, the commands open those dialogs. Order By keeps the menu's toggle: choosing the order the objects already have reverses it. A command whose effect its message does not carry sets `AppActionRunResult::reply`, a JSON object -whose fields `run_action` adds to its reply and the palette never shows. `obj_order_by_*` reply with +whose fields an automated call's reply has and the palette never shows. `obj_order_by_*` reply with the sorted plates' objects in their new order (`order: [{object, name, plate}]`) and `descending`, `obj_assemble` with the new object's `object` and `name`, `obj_instances_to_objects` with the `objects` the instances are in, and `obj_set_instances` with `object` and `instances`. -Commands that still open a dialog, such as `export_config`, `plate_rename` or `send_gcode` (see -Print host uploads), return `blocked_by_dialog`, and the agent answers the dialog; the plate scope sets -a name without one. +Commands that open a dialog whatever their arguments, such as `export_config`, `plate_rename` or `send_gcode` +(see Print host uploads), return `blocked_by_dialog`, and the agent answers the dialog; the plate scope sets a +name without one. `filament_add` and `filament_delete` are the filament list's + and - buttons and a slot's Delete menu item (`Sidebar::add_filament()` and `Sidebar::delete_filament()`, then the slot counter). They run where the buttons show, for printers that take several filaments through one extruder, and not on a G-code file; elsewhere, and at the slot limit or with one slot left, they return Info. A new slot goes after the physical slots, so mixed filaments move up by one with the objects on them; the message names the new -slot. `filament_delete` takes a 1-based slot, the last physical one without it, and remaps the objects on +slot. `filament_delete` takes a 1-based `slot`, the last physical one without it, and remaps the objects on it as the GUI does. A mixed filament is refused (an Error): it is deleted from the mixed filament list. `import_configs` with a path imports presets as the Import Configs dialog does, through @@ -1644,14 +1854,14 @@ go to `PresetBundle::import_presets()`, and the presets are reloaded and the sid file (`.json`) is imported alone, a `.zip` or bundle (`.orca_printer`, `.orca_filament`, `.orca_bundle`) with every preset inside it. The dialog asks about each preset that exists already; the command answers that question itself, never with "to all", so it is asked about every such preset and the message can name -them all: the param `{"path": ..., "on_conflict": "overwrite"}` replaces them, and by default (`"skip"`) they -are kept. `overwrite`, which other path params use for an output file, is refused here rather than read -with that other meaning. The message lists the presets imported, replaced and kept, found by comparing the +them all: `on_conflict: "overwrite"` replaces them, and by default (`"skip"`) they are kept. The schema has +no `overwrite`, which the output commands take for a file, so it is refused here rather than read with +that other meaning. The message lists the presets imported, replaced and kept, found by comparing the preset names before and after; a call that changes nothing is an Error with the dialog's hint about adding -the printer first. A `.gcode` still loads the settings it was sliced with through +the printer first. A `.gcode` loads the settings it was sliced with through `MainFrame::load_config_file(path)`. -`export_config` with a directory still opens the Export Preset Bundle dialog, given that directory: its +`export_config` with a directory opens the Export Preset Bundle dialog, given that directory: its OK writes there instead of asking for a folder. The agent picks the kind by clicking its label (`click`), checks presets with `set_widget_value` on their checkboxes, which are named after the preset, printer or filament they stand for, presses OK with `answer_dialog`, and answers the result message. The command @@ -1659,8 +1869,8 @@ is an Error when the dialog is closed without exporting. Preset files are not ex dialog: its archive functions read its own checkboxes. A command that does nothing, such as an object command with nothing selected, returns its message -with `AppActionRunResult::done` false. The palette shows it at its level, Info for most, as it always -has; `run_action` replies `isError`. `obj_arrange` and `obj_orient` say why they did nothing (no +with `AppActionRunResult::done` false. The palette shows it at its level, Info for most; an automated +call replies `isError`. `obj_arrange` and `obj_orient` say why they did nothing (no objects, or another background job running) and reset the prepare state a plate's Arrange or Auto Rotate icon leaves behind, so they act on every plate as the toolbar does. Their job is the call's operation (see Worker jobs), so `run_action` returns once it is done. @@ -1669,20 +1879,22 @@ operation (see Worker jobs), so `run_action` returns once it is done. Most features need only a Speed Dial command: -1. Add it to `build_command_catalog()` with a key, title, group and runner. Give it a row in - `describe_commands()` with an English description of what it does and what it returns. -2. If it opens a file dialog, give it a `Path` param with help text. Given a param, the runner - resolves it with `path_param()` and calls an entry point that shows no dialog. It must not - prompt; it returns an Error result instead. -3. If the effect finishes in the background after `run()` returns, set - `CommandCompletion::Export` so that `run_action` waits for the file. +1. Add it in `register_all_commands()` with a key, title, group and function, through `add()` or + `add_with_icon()`, which build it with `ui_command()`. Give it a row in `describe_commands()` with an + English description of what it does and what it returns. +2. If it opens a dialog, give it the arguments that stand for the dialog: + `add(...).input_schema = Mcp::object_schema({...})`. With no arguments the function opens the dialog + (`Mcp::person_form(args)`); with them, it resolves them (`path_argument()` for a file) and calls an entry + point that shows no dialog. It must not prompt; it returns an Error result instead. +3. If the effect finishes in the background after the function returns, pass + `CommandCompletion::Export` to `ui_command()` so that a call given the file waits for it. The command then appears in the palette, in `search_actions` and `run_action`, and in replays. What the command does goes into an operation of `GUI/Operations` (see The operations layer): its -checks, its refusals and their wording, its undo snapshot. The runner resolves its param, calls the +checks, its refusals and their wording, its undo snapshot. The function reads its arguments, calls the operation and answers `refused()` with the refusal or a result, and names the operation in the -`reaches` table. A command with no param that asks the person calls the owner's method. +`reaches` table. With no arguments, a command that asks the person calls the owner's method. When an agent needs structured arguments or results, or has to wait for the effect, add a typed tool to the matching `McpTools*.cpp`. Use `inspect_tool()` for pure observation, which runs inline, @@ -1694,13 +1906,24 @@ runs, so `arg_string()` and its siblings can read the arguments. Do all wx work and get the plater with `ui_plater()`, which fails until the main window is up. A tool that changes something calls an operation of `GUI/Operations` for it, the one its command calls where there is one, throws `refused()` for the operation's refusal and is registered through `reaching()` with the -operations it calls. Throw `ToolFailure` -with a message the model can act on for what is the tool's own to check, such as the form of an argument. Call `settle()` after a change so queued events are handled +operations it calls. Throw `ToolFailure` with a message the model can act on for what is the tool's own +to check, such as the form of an argument. Call `settle()` after a change so queued events are handled before the reply, and page lists with `page()`. For work that finishes later, call `ctx.begin_operation()`, wait with `poll_ui()`, and give the work an identity, as slicing and export do. Work on the UI job worker needs none of that: the call that starts it holds it as its operation (see Worker jobs). Describe the tool in English, including what the reply holds and when it is a job. +A new or changed command changes the command reference, `tests/data/command_catalog.json`: the +`catalog_reference()` (`CommandCatalog.hpp`) of the catalog a run with the Design tab holds, every added +command in the order it was added with its key, English title, group, description, schema, examples, +whether it is listed and has a tile, its access labels, guard, completion and the operations it names. It +is where a reader outside the app sees every command, and the skill's list of the Speed Dial's commands is +written from it (`tools/mcp/gen_skill_reference.py`). The unit test "the checked-in command reference +matches the catalog" fails until it is regenerated: run `slic3rutils_tests "[Reference]"` with +`ORCA_UPDATE_COMMAND_REFERENCE=1` in the environment and check the file in. The test compares the file with +its line ends made LF, since a checkout may turn them into CRLF, and a build without CAD does not check it. +A plugin's operations are not in it: they are not the build's. + ## GUI automation `list_widgets` (`UiInspector`) returns a compact text tree of the shown top-level windows, each @@ -1797,7 +2020,7 @@ tools and screenshots reach: `list_widgets` lists its ImGui items, `click` and ` and `mouse_gesture` takes `canvas: "design"` (`"current"` is the view shown, `shown_canvas()`). A click there goes to the Design view's own handlers, so a left click picks a face, edge or body and a right click opens the offer menu, which is listed or run like any other. Points of the model name -Prepare's objects, so on the Design view `mouse_gesture` takes pixels only; `call_cad_tool query_topology` +Prepare's objects, so on the Design view `mouse_gesture` takes pixels only; the `query_topology` command gives its faces. ### Windows @@ -1954,7 +2177,7 @@ command that opens a dialog from the 3D view's queued right click leaves it open returns; the reply then lists it under `dialogs`. The call waits for that queued click by queuing a `CallAfter` on the canvas behind it (one handler's queue is first in, first out) before it settles and reads the capture. A later menu in the same call is closed unseen and counted (`menus_closed`); -a menu that opens in a window where nothing is armed (a `call_cad_tool run_verb` whose offer opens later) +a menu that opens in a window where nothing is armed (a call that queues a menu to open later) is closed unseen too. The last three such menus, with the tool whose window took them, are in `get_app_state.closed_menus`. @@ -2175,7 +2398,7 @@ plater's camera, and the Design tab swaps its own into that slot while it is sho (`DesignCanvas::enter_viewport()`), so `Plater::get_camera()` is always the shown view's and one code path serves all of them. `look_at` is the point the camera looks at, in mm in the view's world coordinates, as `list_objects` gives positions. On the Design tab these are the Design view's, the -frame the CAD tools' world points use, where `describe_scene`'s `modeling_origin` is the sketch +frame the Design commands' world points use, where `describe_scene`'s `modeling_origin` is the sketch planes' origin. `Camera::set_target()` moves the camera parallel, keeping its direction and distance. `zoom` is viewport pixels per mm at the target's depth, which are screenshot pixels: exact everywhere in an orthographic view, and only at the target's depth in a perspective one @@ -2770,7 +2993,7 @@ the UI thread, and a step after the replay sees a closed file. At exit `stop()` file, then drops what is still queued and leaves the sink to its threads, which own its state. A recording counts as active until its file is closed, for the one-at-a-time rule and for encodes. -**Encoding up front.** `start_recording` takes the Start Recording command's encoding keys (`encode`, +**Encoding up front.** `start_recording` takes the Start Recording dialog's encoding keys (`encode`, `encode_preset`, `codec`, `crf`, `speed`, `profile`), checked by `apply_recording_overrides()` with its defaults, the Balanced preset, and refuses `encode` without an ffmpeg before anything records. The recording keeps `encode_recording`'s arguments (`RecordingOptions::encode`), and the `stop_recording` @@ -2783,14 +3006,15 @@ the endpoint, is not encoded. An agent can still encode any recording later with **From the app.** The Speed Dial commands `take_screenshot`, `start_recording` and `stop_recording`, which the Help menu also has, give a person screenshots and recordings without an agent: a PNG of the main window, and a recording of it for up to an hour. Both go in the person's Downloads folder unless they chose another. +`start_recording` and `stop_recording` are the tools too, of which this is the form with no arguments +(`with_person_form()`, see Tool catalog); given arguments, or `silent: true`, they are the tools above, and +`start_recording` then also records for up to an hour unless `max_seconds` says otherwise. Start Recording opens `RecordingDialog`, which splits its settings by the file they make. Record holds the JPEG quality of the `.mkv` and a switch for each overlay, the pointer and the caption, both off unless the person turns them on. Encode to MP4 holds whether ffmpeg encodes it once it ends, with a built-in preset or codec, CRF, speed and profile; it is off and disabled when no ffmpeg is found, and says how to get one. A rail joins the two stages and shows whether the second runs. The dialog remembers what it starts with in -AppConfig's `recording` section (`RecordingSettings`). The command's parameter overrides those settings for -one recording, and with `silent` starts at once without the dialog and remembers nothing; a silent start -that would encode without an ffmpeg is refused rather than recording unencoded. The encode is +AppConfig's `recording` section (`RecordingSettings`). The encode is `encode_recording` itself, run by `McpService::encode_when_closed()` as an unjournaled job once the recording's file is closed (`McpRecorder::wait_closed()`), so it can be cancelled like any encode. No reply names the job, which only exists once the file is closed: an agent finds it in `get_app_state.jobs` and waits @@ -2861,7 +3085,7 @@ falls to almost nothing while the window is still and rises for the motion, wher spend it evenly; the video's length in the reply is the MP4's movie header's (`mp4_duration()`); an ffmpeg without the encoder is refused, naming what is needed. It runs without a console window, polled every 100 ms and terminated when the call is cancelled -(`ToolDef::cancellable`: `cancel_job {job}` stops it through `McpService::request_stop()`). On Windows it is +(`NativeCommand::cancellable`: `cancel_job {job}` stops it through `McpService::request_stop()`). On Windows it is ended with `TerminateProcess()` on its handle and waited for on that handle, since `TerminateProcess()` returns before the process is gone and boost's `terminate()` closes the handle right after it; a child not gone within 5 s keeps its files, which the error names, and its source and destination stay reserved for @@ -3031,8 +3255,9 @@ window is such a navigation, to that file (`WebViewHostDialog::dropped_file()`), nothing while a replay runs, as Open is unavailable then. The browser's own keys are off, so Ctrl+R and F5 don't reload the page back to its draft. The page's editor starts from a commented draft and suggests the replay's keys, tool names, a tool's arguments and their allowed values, and -`${…}` placeholders; the tool part comes from the registry, which the dialog sends once the service is -ready, so the suggestions match the build. Save writes the text back to the file it was opened from, or +`${…}` placeholders; the tool part comes from the command catalog's listed tools (`editor_tool_catalog()`), +which the dialog sends once the service is ready, so the suggestions match the build. Save writes the text +back to the file it was opened from, or asks where to put a new replay file and offers the replay's name as the file name. A replay saved somewhere new is that file's from then on: `${replay_dir}` and its output folder follow the file, as for an opened one. Closing the window, or opening another replay, with unsaved edits asks first. The page @@ -3105,7 +3330,9 @@ returned a job into a step with `"await": false` and `"save_as": "jobN"`, points the `wait {for: "job"}` that followed at `${jobs.jobN}` (dropping waits on jobs it never saw start) and rewrites screenshot paths to `${out_dir}/`. It moves a recording's path there too (`start_recording` records the one it used), and an encode's `save_path`, and -an encode's source when an earlier `start_recording` recorded it; another source stays where it is. +an encode's source when an earlier `start_recording` recorded it; another source stays where it is. A +`run_action` of a command's tile, named by its key or its full id, is rewritten as a call of that command, +inside the tile's `{id, args}`, so a recording started from the Start Recording tile moves the same way. A call that runs as a job is judged by its job's final result, not by its reply. `McpCore` tells the journal the job's id when it starts it (`Journal::job_started()`) and its result when the handler @@ -3267,7 +3494,8 @@ code. The install isn't covered by the watcher; uv's 120 s timeout bounds it. **Identity.** A person's script runs under the audit identity `script`, an agent's under `mcp` (`kScriptIdentityPerson`, `kScriptIdentityAgent`); `McpService::person_run()` tells them apart by the run's -lineage, since the panel's and `--mcp-run`'s jobs are marked as a person's (`as_person()`). The plugin audit +lineage, since the panel's, `--mcp-run`'s and a person's pick of a long command's jobs are marked as a person's +(`as_person()`). The plugin audit ([plugin-permissions.md](plugin-permissions.md)) judges a script under its identity as it judges a plugin, with one difference: a script has no install state to hold a grant, so it is never asked, and what the implicit rules don't allow is denied with a `PermissionError` that names the setting. The threads, pool tasks and window @@ -3302,6 +3530,11 @@ while it lasts, through the run's bridge: its calls are `ToolContext::call_child each has its tool's guards, admission and undo, and the GIL is released while it waits. At the end the bridge closes, and the run waits for calls already inside it before its `ToolContext` goes. An error result raises `orca.host.tools.ToolError` with its data as `details`. Code with no audit identity at all is refused. +`orca.host.tools.list()` and `describe(name)` only read the command catalog, so they need no run and work +on any thread, for any code: `list()` gives every command of `NativeCommands::instance()` and then the +operations its sources hold, each `{name, title, group, description, read_only, listed}`, and +`describe(name)` one command's entry of the command reference (`command_reference()`, see Making a feature +reachable), or raises `ToolError` with `did_you_mean` for a name the catalog does not resolve. **A script's UI.** What a script's run opens (windows, dock panels, progress dialogs, message boxes, notification links) is registered under a run-unique owner (`script/`; a plugin key never holds `/`), and closes with the @@ -3466,7 +3699,7 @@ worker, a Python thread one starts (the thread shim carries the mark) or MCP's o operation (`ScopedToolCallerThread`). A call from the UI thread, a slicing hook or another plugin callback is refused before anything waits. `install_plugin_tool_caller()` routes a plugin's calls. The UI thread, which owns the service and runs the plugin's unload, admits each one: the plugin must still be -loaded and its scope not ended, and the service is started in its catalog-only mode when MCP is off; the +loaded and its scope not ended, and the service is started without its endpoint when MCP is off; the call then holds a lease the service's drain waits for. A caller that stops waiting because the app closes marks its admission abandoned, so no lease is taken that nobody releases. The call runs as `McpCore::call_plugin()`: a top-level job owned by the plugin @@ -3496,7 +3729,9 @@ Its operations are staged and offered once the plugin's load has committed load that did not commit, an exception included, drops them, and they are withdrawn when the plugin unloads. An operation is reached as `plugin..` through `call_tool`, `orca.host.tools.call` and replay steps, and never -appears in `tools/list`: `ToolRegistry::set_dynamic()` resolves those names (`ToolRegistry::lookup()`). +appears in `tools/list`: they are a source of the command catalog (`CommandSource`, added by +`register_api_tools()`), whose `CommandCatalog::lookup()` resolves those names after the catalog's own +commands, and whose `source_commands()` `search_tools` lists. It runs as a job, under the mutate guard and journaled when it changes something, under the inspect guard otherwise; its handler runs under the plugin's identity and grants, and each call is logged with the plugin and the caller. A call is refused once the plugin has unloaded, by the plugin manager's state, and @@ -3504,24 +3739,30 @@ by `PluginOperations::invoke()` when the operation found is no longer the one of offered again by a new load). The call's job is the caller's, so an operation already running when its plugin unloads runs to its end; its own tool calls are refused from then on. -**`search_tools` and `call_tool`.** `search_tools` gives the schema of any registered tool or operation, -or lists every name; for `call_cad_tool` it points to `list_cad_tools` and `describe_cad_tool`, which list -and describe the Design tab's CAD tools. -Its search by words is the one search across catalogs: the best five tools and operations that match (more -with `limit`), a tool with the first sentence of its description, since `tools/list` has its schema, and an -operation with its schema, which nothing else lists; and beside them the best five of each other catalog with -its total and how to use it: Speed Dial -actions, the settings being edited (`search_settings()`, as `get_settings` searches without a scope), the -Python reference and the Design tab's CAD tools (scored on their details too, and noting when the Design -tab is off). Every catalog is ranked +**`search_tools` and `call_tool`.** `search_tools` reads one inventory (`search_commands()`): every +command of the catalog and the operations its source holds. `{tool}` gives any command's description, +schema, group, `read_only` and `listed`, and its examples when it has some (the Design commands, and `undo` +and `redo` with them), and a call with neither `tool` nor `query` lists every name. Its `group` narrows the names and +the command matches to one group (see Tool catalog); the other catalogs' matches beside them are not +narrowed. +Its search by words is the one search across catalogs: the best five commands that match (more with +`limit`), each `{name, group, summary, listed}`, the summary the first sentence of its description. A +listed command's schema is in `tools/list`; one that is not listed, a Speed Dial command, a Design command or a +plugin's operation, also carries its `input_schema`, and its description where that says more than the +summary, which nothing else shows (an operation's first +sentence only says a plugin offers it). A command is matched on its key, its title and its description, +and among equal matches a listed one comes first. The reply's `use` says that `call_tool {tool, args}` +runs a command that is not listed. Beside them come the best five of each other catalog with its total +and how to use it: the Speed Dial's actions that are no command, the settings being edited +(`search_settings()`, as `get_settings` searches without a scope) and the Python reference. Every catalog is ranked the same way (`query_words()`, `match_score()`): a query word matches where a word of the name or text starts with it, CamelCase parts included, and entries matching more words, then more of them in the name, -come first. Scores of different catalogs don't compare, so each keeps its own list. Actions, settings -and the Design tab's CAD tools are read on the UI thread: when it can't run the call (a native dialog holds -it, or it is busy) the search leaves those three out, and before the main window exists (the server starts -ahead of it) it leaves out the settings. The tools, operations and Python reference answer whatever the UI -thread is doing. `call_tool {tool, args}` is dispatched before it runs -(`resolve_api_call()`, in the protocol, in child calls and in the plugin caller): the target's arguments +come first. Scores of different catalogs don't compare, so each keeps its own list. Actions and settings +are read on the UI thread: when it can't run the call (a native dialog holds +it, or it is busy) the search leaves those two out, and before the main window exists (the server starts +ahead of it) it leaves out the settings. The commands, operations and Python reference answer whatever the +UI thread is doing. `call_tool {tool, args}` runs any command of the catalog, listed or not, and is dispatched +before it runs (`resolve_call()`, in the protocol, in child calls and in the plugin caller): the target's arguments are normalized and validated, and the call runs as the target's own, with its guard, mode, budget and journal flag, so the journal records the target. @@ -3536,14 +3777,15 @@ Replies go to stdout; a 202 writes nothing. The bridge starts OrcaSlicer only for a tool call, so an agent session that is registered user-wide but never calls a tool never opens the app. While nothing answers, every other message is answered -by an `McpProtocol` of the bridge's own over `McpService::offline_catalog()`, given the headers the +by an `McpProtocol` of the bridge's own over the process's command catalog (`NativeCommands::instance()`, +built there on first use, since the bridge never starts the GUI that builds it), given the headers the server would get: the handshake, `ping`, `tools/list`, `server/discover`, notifications and unknown methods get exactly the reply this build's server gives. That holds because these methods read -only the catalog and the server's details, and the server keeps no session. The catalog is held by -a service that is never started: registering a tool only describes it (a schema built from -constants and compile-time options), and its handler runs only when the tool is called, so -building it needs neither wx nor a window. A tool's registration must stay that way, never reading -app state; a unit test builds the catalog without the app. +only the catalog and the server's details, and the server keeps no session. The catalog needs no +service: registering a command only describes it (a schema built from constants and compile-time +options), and its function runs only when the command is called, reaching the service through its +call's context, so building it needs neither wx nor a window. A command's registration must stay that +way, never reading app state; a unit test builds the catalog without the app. A `tools/call` with nothing answering starts `orca-slicer --mcp` detached, with the bridge's `--datadir` and `--mcp-port`, and waits up to 60 s. If that process exits within seconds, a running @@ -3616,12 +3858,20 @@ that can't connect over HTTP; its setup names this executable, so it breaks when ## Testing Unit tests are Catch2 cases tagged `[Mcp]` in `tests/slic3rutils/test_mcp_*.cpp`, run with -`slic3rutils_tests "[Mcp]"`. `test_mcp_protocol` covers both eras, argument validation, the names -and values read in place of a tool's own, and the error for an unknown tool another catalog has; +`slic3rutils_tests "[Mcp]"`. `test_mcp_protocol` covers both eras, the order of `tools/list`, argument +validation, the names and values read in place of a tool's own, and the error for an unknown tool, which names +the closest; `test_mcp_http` the endpoint rules and a live server (deadlines, eviction, stop); `test_mcp_token` who owns the discovery file and when a port counts as held by another window; `test_mcp_core` `UiInvoker`, `McpCore` and `JobRegistry` on a hand-stepped dispatcher (guards, abandoned calls, -jobs, blocked_by_dialog, admission, slots, idle, journal); `test_operations` (tagged `[Operations]`) +jobs, blocked_by_dialog, admission, slots, idle, journal and the id arguments it leaves out, a context +with no service, a submitted call); +`test_command_catalog` (tagged `[CommandCatalog]`) the catalog itself: unique keys, the palette's +commands, which are listed, the merged commands' schemas and forms, a tool list built without a +service, a Speed Dial command found by the one lookup, each command's `id_args` against its schema, the +history `undo` and `redo` take, and the command reference (tagged `[Reference]`): the checked-in file against +the catalog, and that its entries hold what `tools/list` tells a client and both forms of a two-form command; +`test_operations` (tagged `[Operations]`) the slice and export outcomes, an operation's `Outcome` and `Refusal`, and the catalogs' operation names and exception lists; `test_mcp_replay` parsing, substitution, matchers and await; `test_mcp_ui` labels, snapshot text, ref liveness, synthetic key state, a key's way through the hooks of its target's @@ -3646,7 +3896,7 @@ dialog's description, a web dialog rule's wx buttons and web view handles; budget, non-blocking push, finish, abort and failed frames, the video transform, overlays and frame repeats, captions and what they hide, the ffmpeg command and listings, the files recordings and encodes reserve, and the journal's recording paths; `test_mcp_tools` setting serialization, how a query ranks -the Speed Dial's actions, and which catalog a name its own lacks is pointed to; `test_mcp_config` the object and part scopes' keys and +the Speed Dial's actions, each typed tool's group, `search_tools`' one inventory and its group filter, and which arguments the journal leaves out; `test_mcp_config` the object and part scopes' keys and effective values, the names and places `save_preset` accepts, enum labels and descriptions, the settings search, per-variant entries and their writes, preset comparison, `changed`, which unsaved changes a call discarded, which presets `delete_preset` refuses or deletes with a custom printer, the project scope's slot colours, @@ -3696,14 +3946,14 @@ answers 200 or 500, `tools/mcp/test_recovery_under_load.py` answering a dialog while stalled clients hold every connection. See `tools/mcp/README.md`. -`test_mcp_scene` covers the scene and layer tools without the app: `transform`'s `size`, the shape -commands' size param, notifications updated before the first ImGui frame, `arrange`'s option rules, +`test_mcp_scene` covers the scene and layer tools without the app: `transform`'s `size`, the arguments +of the commands that replace a dialog, notifications updated before the first ImGui frame, `arrange`'s option rules, worker-job admission on a stand-in worker (a job past the reply budget, a slow cancel and a timeout, three ways to start one, recover input and a person's job), `list_objects`' descriptions of a `Model` built in the test (its rows by plate, the plate filter and paging, placement and boxes on the bed, mirrors, filament fallback, precise seam subtypes, height ranges, the summary of a variable layer height profile), `add_part`'s type names and shape -sizes, the object structure commands' params, the height ranges `set_height_ranges` accepts (order, +sizes, the object structure commands' arguments, the height ranges `set_height_ranges` accepts (order, overlaps, bounds, keys), and `set_custom_gcode_at_layer`'s edits of a layer slider built in the test (by layer and height, in-place edits, refusals that leave the slider as it was, the type names). On the app, `tools/mcp/tests/scene.json` checks object structure and placement (transform on instances, plates and diff --git a/localization/i18n/OrcaSlicer.pot b/localization/i18n/OrcaSlicer.pot index e8ff50e250..951aa72f09 100644 --- a/localization/i18n/OrcaSlicer.pot +++ b/localization/i18n/OrcaSlicer.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-06 11:18-0600\n" +"POT-Creation-Date: 2026-11-13 19:50+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2474,12 +2474,6 @@ msgstr "" msgid "Unknown error" msgstr "" -msgid "Select plugin package" -msgstr "" - -msgid "Plugin files (*.py;*.whl)|*.py;*.whl" -msgstr "" - msgid "Plugin Terminal" msgstr "" @@ -2693,6 +2687,7 @@ msgid "" "No - Do not change these settings for me" msgstr "" +#. TRN Read by a screen reader for one entry of the code editor's list of suggestions. msgid "Suggestion" msgstr "" @@ -3323,6 +3318,9 @@ msgstr "" msgid "Choose part type" msgstr "" +msgid "A text or SVG part can only be a part, a negative part or a modifier." +msgstr "" + msgid "Instances to Separated Objects" msgstr "" @@ -4237,12 +4235,422 @@ msgstr "" msgid "Multi-device" msgstr "" -msgid "AMS Materials Setting" +msgid "Replay files" +msgstr "" + +msgid "All files" +msgstr "" + +msgid "Current plate" +msgstr "" + +msgid "All plates" +msgstr "" + +#. TRN %1% is a plate number, counted from 1. +#, possible-boost-format +msgid "Plate %1%" +msgstr "" + +#. TRN A step that runs another replay; %1% is how many steps that replay has. +#, possible-boost-format +msgid "A replay of %1% step" +msgid_plural "A replay of %1% steps" +msgstr[0] "" +msgstr[1] "" + +#, possible-boost-format +msgid "Checks that %1% is %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is not %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is more than %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is at least %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is less than %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is at most %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% contains %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% matches %2%." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is missing." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is there." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is not empty." +msgstr "" + +#, possible-boost-format +msgid "Checks that %1% is empty." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was missing." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was there, which the replay did not expect." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, which the replay did not expect." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not more than %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not at least %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not less than %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not at most %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, which does not contain %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, which does not match %3%." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was %2%, not empty." +msgstr "" + +#, possible-boost-format +msgid "The step finished, but %1% was empty." +msgstr "" + +msgid "Action Replay" +msgstr "" + +msgid "Open replay…" +msgstr "" + +msgid "Save" +msgstr "" + +#. TRN Saves a new replay file: the button opens a file dialog. +msgid "Save…" +msgstr "" + +msgid "Save as…" +msgstr "" + +#. TRN Shown for a moment after a replay file is saved. +msgid "Saved" +msgstr "" + +msgid "(edited)" +msgstr "" + +#. TRN The name a new replay starts with, in the editor of the Action Replay window. +msgid "Untitled replay" +msgstr "" + +msgid "Steps" +msgstr "" + +msgid "Steps appear here as you write them." +msgstr "" + +msgid "Replay file" +msgstr "" + +msgid "Write a replay here, or open one." +msgstr "" + +#. TRN The first comment line a new replay starts with. MCP is the protocol AI agents use to drive OrcaSlicer. +msgid "A replay file runs OrcaSlicer's tools in order, the way an AI agent does through MCP." +msgstr "" + +#. TRN A comment line a new replay starts with. "tool", "args" and "expect" are the file's keys and stay in English. +msgid "Each step names a \"tool\" and its \"args\"; \"expect\" checks the result before the next step." +msgstr "" + +#. TRN %s is the placeholder ${out_dir}, written as is in the replay file. +#, possible-c-format, possible-boost-format +msgid "%s is this run's output folder." +msgstr "" + +#. TRN The first %s is a key such as Ctrl+Space, the second one such as Ctrl+Enter. +#, possible-c-format, possible-boost-format +msgid "%s shows suggestions, %s replays the file." +msgstr "" + +msgid "Replay" +msgstr "" + +msgid "Replay again" +msgstr "" + +msgid "Stop" msgstr "" msgid "Close" msgstr "" +msgid "Open output folder" +msgstr "" + +msgid "Run this step" +msgstr "" + +msgid "Show raw result" +msgstr "" + +msgid "Hide raw result" +msgstr "" + +msgid "Show in folder" +msgstr "" + +msgid "Skipped" +msgstr "" + +msgid "Checks the result" +msgstr "" + +msgid "Writes a file" +msgstr "" + +msgid "Changes presets" +msgstr "" + +msgid "Replaces the project" +msgstr "" + +msgid "Sends to a printer" +msgstr "" + +#. TRN A duration; %s is a number of seconds such as 0.8. +#, possible-c-format, possible-boost-format +msgid "%s s" +msgstr "" + +#. TRN %s is the number of the step that is running. +#, possible-c-format, possible-boost-format +msgid "Running step %s" +msgstr "" + +#. TRN The first %s is the number of the step that is running, the second how many steps there are. +#, possible-c-format, possible-boost-format +msgid "Running step %s of %s" +msgstr "" + +msgid "Don't use OrcaSlicer until the replay finishes." +msgstr "" + +msgid "OrcaSlicer is still starting…" +msgstr "" + +msgid "Open a replay file" +msgstr "" + +#, possible-boost-format +msgid "Can't read %1%." +msgstr "" + +#. TRN %1% is a file name. +#, possible-boost-format +msgid "%1% is a Python script. Python scripts run in the Run Script panel." +msgstr "" + +msgid "Open in Run Script" +msgstr "" + +msgid "Save the replay file" +msgstr "" + +#, possible-c-format, possible-boost-format +msgid "" +"The file %s already exists.\n" +"Do you want to replace it?" +msgstr "" + +msgid "Confirm Save As" +msgstr "" + +#, possible-boost-format +msgid "Can't save %1%." +msgstr "" + +msgid "" +"Save this replay file?\n" +"If you don't, your changes are lost." +msgstr "" + +#. TRN %1% is a replay file's name. +#. TRN %1% is a script's file name. +#, possible-boost-format +msgid "" +"Save the changes to %1%?\n" +"If you don't, your changes are lost." +msgstr "" + +msgid "Don't save" +msgstr "" + +msgid "Replays can't run while OrcaSlicer is starting or closing." +msgstr "" + +#. TRN %1% is a step number, %2% the name of the tool the replay asks for. +#, possible-boost-format +msgid "Step %1% uses a tool this version of OrcaSlicer doesn't have: %2%" +msgstr "" + +#, possible-boost-format +msgid "%1% step" +msgid_plural "%1% steps" +msgstr[0] "" +msgstr[1] "" + +msgid "The replay could not run." +msgstr "" + +msgid "This replay replaces the current project, which has unsaved changes. Save them before replaying it?" +msgstr "" + +#. TRN %1% is the step the run stopped at, %2% how many steps the replay has. +msgid "Stopped." +msgstr "" + +#, possible-boost-format +msgid "The step didn't finish within %1% second." +msgid_plural "The step didn't finish within %1% seconds." +msgstr[0] "" +msgstr[1] "" + +msgid "The step's result was not what the replay expected." +msgstr "" + +msgid "The replay's check of this step's result isn't valid." +msgstr "" + +#. TRN %1% is a placeholder such as ${vars.model} that the replay uses. +#, possible-boost-format +msgid "The replay refers to %1%, which has no value." +msgstr "" + +#. TRN %1% is the number of the step that saves the job this step needs. +#, possible-boost-format +msgid "This step needs the job saved by step %1%. Run that step first." +msgstr "" + +msgid "This step needs a job that no step of this replay saves." +msgstr "" + +msgid "The script was stopped." +msgstr "" + +msgid "The script ran out of time." +msgstr "" + +msgid "The script raised an exception." +msgstr "" + +msgid "This step failed." +msgstr "" + +#. TRN %1% is how many more lines of a script's output there are. +#, possible-boost-format +msgid "(%1% more line)" +msgid_plural "(%1% more lines)" +msgstr[0] "" +msgstr[1] "" + +#. TRN %1% is the value a Python script returned, as JSON. +#, possible-boost-format +msgid "Result: %1%" +msgstr "" + +#, possible-boost-format +msgid "%1% object" +msgid_plural "%1% objects" +msgstr[0] "" +msgstr[1] "" + +#, possible-boost-format +msgid "%1% plate sliced" +msgid_plural "%1% plates sliced" +msgstr[0] "" +msgstr[1] "" + +#, possible-boost-format +msgid "%1% plate did not slice" +msgid_plural "%1% plates did not slice" +msgstr[0] "" +msgstr[1] "" + +#. TRN %1% is the number of the step of the nested replay that failed. +#, possible-boost-format +msgid "The nested replay failed at step %1%." +msgstr "" + +#, possible-boost-format +msgid "Stopped at step %1% of %2%" +msgstr "" + +#. TRN %1% is the step that failed, %2% how many steps the replay has. +msgid "The step failed." +msgstr "" + +#, possible-boost-format +msgid "Failed at step %1% of %2%" +msgstr "" + +msgid "Finished, but a nested replay failed." +msgstr "" + +msgid "The step passed." +msgstr "" + +#, possible-boost-format +msgid "Passed, %1% step in %2% s" +msgid_plural "Passed, %1% steps in %2% s" +msgstr[0] "" +msgstr[1] "" + +msgid "A replay is running. Stop it and close this window?" +msgstr "" + +msgid "AMS Materials Setting" +msgstr "" + msgid "" "Nozzle\n" "Temperature" @@ -4349,9 +4757,6 @@ msgstr "" msgid "Calibration completed. Please find the most uniform extrusion line on your hot bed like the picture below, and fill the value on its left side into the factor K input box." msgstr "" -msgid "Save" -msgstr "" - msgctxt "Navigation" msgid "Back" msgstr "" @@ -5776,6 +6181,9 @@ msgstr "" msgid "Invalid format. Expected vector format: \"%1%\"" msgstr "" +msgid "The excluded bed area is invalid. It must be a simple, non-self-intersecting polygon." +msgstr "" + msgid "System agents" msgstr "" @@ -6487,6 +6895,9 @@ msgstr "" msgid "Set viewing angle" msgstr "" +msgid "Follow camera" +msgstr "" + msgid "Paint Toolbar" msgstr "" @@ -6756,6 +7167,24 @@ msgstr "" msgid "Measure how fast the 3D scene renders in Prepare and Preview" msgstr "" +msgid "Take Screenshot" +msgstr "" + +msgid "Save a picture of the main window" +msgstr "" + +msgid "Start Recording" +msgstr "" + +msgid "Record a video of the main window" +msgstr "" + +msgid "Stop Recording" +msgstr "" + +msgid "Stop the recording and save it" +msgstr "" + msgid "Show Tip of the Day" msgstr "" @@ -6893,6 +7322,15 @@ msgstr "" msgid "Export" msgstr "" +msgid "Run Script" +msgstr "" + +msgid "Show or hide the Run Script panel" +msgstr "" + +msgid "Open a replay file and replay its steps" +msgstr "" + msgid "Quit" msgstr "" @@ -7195,6 +7633,646 @@ msgstr "" msgid "Synchronization" msgstr "" +#. TRN %1% is the title of a command a person started, which ran on in the background. +#, possible-boost-format +msgid "Finished: %1%" +msgstr "" + +#. TRN %1% is the title of a command a person started, which runs on in the background. +#, possible-boost-format +msgid "Started: %1%" +msgstr "" + +msgid "Search Speed Dial actions" +msgstr "" + +msgid "Run a Speed Dial action" +msgstr "" + +msgid "Find tools, actions, settings and APIs" +msgstr "" + +msgid "Call a tool or plugin operation" +msgstr "" + +msgid "Get app state" +msgstr "" + +msgid "Wait for a condition" +msgstr "" + +msgid "Read the log" +msgstr "" + +msgid "Rebuilding model…" +msgstr "" + +msgid "Mesh" +msgstr "" + +msgid "Fillet" +msgstr "" + +msgid "Chamfer" +msgstr "" + +msgctxt "Design" +msgid "Hole" +msgstr "" + +msgid "Boolean" +msgstr "" + +msgctxt "Design" +msgid "Pattern" +msgstr "" + +msgctxt "Design" +msgid "Shell" +msgstr "" + +msgctxt "Design" +msgid "Rib" +msgstr "" + +msgid "Surface Extrude" +msgstr "" + +msgid "Surface Revolve" +msgstr "" + +msgid "Thicken Surface" +msgstr "" + +msgid "Surface Offset" +msgstr "" + +msgid "Surface Loft" +msgstr "" + +msgid "Surface Fill" +msgstr "" + +msgid "Draft" +msgstr "" + +#, possible-c-format, possible-boost-format +msgid "Face %d" +msgstr "" + +msgctxt "Design" +msgid "Extrude" +msgstr "" + +msgid "Sketch" +msgstr "" + +msgid "Revolve" +msgstr "" + +msgctxt "Design" +msgid "Mirror" +msgstr "" + +msgid "Thicken" +msgstr "" + +msgctxt "Design" +msgid "Split" +msgstr "" + +msgctxt "Design" +msgid "Cut" +msgstr "" + +msgctxt "Design" +msgid "Project" +msgstr "" + +msgid "Delete Face" +msgstr "" + +msgid "Axis" +msgstr "" + +msgid "Coordinate system" +msgstr "" + +msgctxt "Design" +msgid "Plane" +msgstr "" + +msgid "Helix" +msgstr "" + +msgid "Thread" +msgstr "" + +msgid "Sweep" +msgstr "" + +msgid "Loft" +msgstr "" + +msgid "Mate" +msgstr "" + +#, possible-c-format, possible-boost-format +msgid "Variable '%s' could not be removed (likely still referenced by a feature expression): %s" +msgstr "" + +msgid "Commit to Plate" +msgstr "" + +#. TRN Refusal of a Design tab tool picked for a selection its right-click menu row is greyed for (Constrain +#. sketch with a face selected). +msgid "This tool does not apply to what is selected" +msgstr "" + +#. TRN Refusal of a Design tab tool picked outside a sketch, when it is a sketch tool (a line, a rectangle). +msgid "This tool works in a sketch: open a sketch first" +msgstr "" + +#. TRN Refusal of a Design tab tool picked while a sketch is open, when it works on the model (Extrude, Shell). +msgid "This tool works on the model: finish or cancel the sketch first" +msgstr "" + +msgid "List presets" +msgstr "" + +msgid "Select a preset" +msgstr "" + +msgid "Save a preset" +msgstr "" + +msgid "Delete a preset" +msgstr "" + +msgid "Read settings" +msgstr "" + +msgid "Change settings" +msgstr "" + +msgid "List plates" +msgstr "" + +msgid "Set height range modifiers" +msgstr "" + +msgid "Set a variable layer height profile" +msgstr "" + +msgid "Set custom G-code at a layer" +msgstr "" + +msgid "Open files" +msgstr "" + +msgid "Commands" +msgstr "" + +msgid "Generate a calibration test" +msgstr "" + +msgid "Run a Python script" +msgstr "" + +msgid "Search the Python API" +msgstr "" + +msgid "Encode a recording" +msgstr "" + +msgid "Run a replay" +msgstr "" + +msgid "Export this session as a replay" +msgstr "" + +msgid "List objects" +msgstr "" + +msgid "Select objects" +msgstr "" + +msgid "Move, rotate or scale an instance or a part" +msgstr "" + +msgid "Add a part or modifier to an object" +msgstr "" + +msgid "Arrange objects or fill the bed" +msgstr "" + +msgid "Cancel a job" +msgstr "" + +msgid "List the windows" +msgstr "" + +msgid "Size or move a window" +msgstr "" + +msgid "List the widgets" +msgstr "" + +msgid "Click an element" +msgstr "" + +msgid "Set a widget's value" +msgstr "" + +msgid "Press keys" +msgstr "" + +msgid "Mouse gesture on the 3D view" +msgstr "" + +msgid "Pick a file for the open gizmo" +msgstr "" + +msgid "Answer a dialog" +msgstr "" + +msgid "Answer dialogs automatically" +msgstr "" + +msgid "Run JavaScript in a web view" +msgstr "" + +msgid "Take a screenshot" +msgstr "" + +msgid "Get slice statistics" +msgstr "" + +msgid "Point the view" +msgstr "" + +msgid "Python scripts" +msgstr "" + +msgid "Python scripts are subject to the same permission checks as plugins: the scripts you run in the Run Script panel or with --mcp-run, and the ones AI agents send through the MCP server. When this option is on, they bypass the permission checks, which is useful for fully automated workflows." +msgstr "" + +msgid "Run Python scripts unrestricted" +msgstr "" + +msgid "Small file" +msgstr "" + +msgid "Balanced" +msgstr "" + +msgid "High quality" +msgstr "" + +msgid "Most compatible" +msgstr "" + +msgid "Record" +msgstr "" + +msgid "MJPEG in .mkv" +msgstr "" + +msgid "Each frame is kept as a JPEG while you work, so recording stays light on the app." +msgstr "" + +msgid "JPEG quality" +msgstr "" + +msgid "30 to 95. Higher is sharper and makes a larger file." +msgstr "" + +msgid "Highlight the pointer" +msgstr "" + +msgid "A ring follows the pointer, and its clicks ripple." +msgstr "" + +msgid "Caption each step" +msgstr "" + +msgid "Names each step an agent or script takes, at the bottom." +msgstr "" + +msgid "Encode to MP4" +msgstr "" + +msgid "When the recording ends, ffmpeg turns it into an MP4 that is easy to share. The .mkv is kept." +msgstr "" + +msgid "ffmpeg wasn't found, so recordings can't be encoded. Install ffmpeg with libx265 and libx264, or set ORCA_FFMPEG to one, then open this dialog again." +msgstr "" + +msgid "Preset" +msgstr "" + +msgid "Codec" +msgstr "" + +msgid "Profile" +msgstr "" + +msgid "Quality (CRF), lower is sharper" +msgstr "" + +msgid "Speed, slower is smaller" +msgstr "" + +#, possible-boost-format +msgid "Uses %1%" +msgstr "" + +msgid "Change..." +msgstr "" + +msgid "Use the default folder" +msgstr "" + +msgid "Recordings, their MP4s and screenshots are saved here." +msgstr "" + +msgid "Save in" +msgstr "" + +msgid "Start recording" +msgstr "" + +msgid "Choose where recordings and screenshots are saved" +msgstr "" + +#. TRN %1% is a codec's name, such as H.265. +#, possible-boost-format +msgid "%1% in .mp4" +msgstr "" + +#. TRN Short label of the indicator the main window shows while a recording runs, as on a camera. +msgid "REC" +msgstr "" + +msgid "Recording. Click to stop." +msgstr "" + +#. TRN The title of the one cell a new script starts with, which lists the objects of the project. +msgid "List the objects" +msgstr "" + +#. TRN A comment line of a new script in the Run Script panel. orca.host is the name of OrcaSlicer's Python API. +msgid "Run Script runs Python with OrcaSlicer's tools and the orca.host API." +msgstr "" + +#. TRN A comment line of a new script. %1% is the cell marker "# %%", written as is; %2% and %3% are keys, such as +#. Shift+Enter and Ctrl+Enter. +#, possible-boost-format +msgid "A line that starts with %1% starts a cell. %2% runs the cell at the cursor, %3% all of them." +msgstr "" + +#. TRN A button of the Run Script panel that starts a new script. +msgctxt "Script" +msgid "New" +msgstr "" + +msgid "Start a new script" +msgstr "" + +msgid "Open…" +msgstr "" + +msgid "Open a Python script" +msgstr "" + +msgid "Recent scripts" +msgstr "" + +msgid "No recent scripts" +msgstr "" + +msgid "Close script" +msgstr "" + +#. TRN %s is a key, such as Ctrl+S. +#, possible-c-format, possible-boost-format +msgid "Save the script (%s)" +msgstr "" + +msgid "Run all" +msgstr "" + +#. TRN %s is a key, such as Ctrl+Enter. +#, possible-c-format, possible-boost-format +msgid "Restart the session and run every cell (%s)" +msgstr "" + +msgid "Run cell" +msgstr "" + +#. TRN %s is a key, such as Shift+Enter. +#, possible-c-format, possible-boost-format +msgid "Run the cell at the cursor (%s)" +msgstr "" + +msgid "Interrupt the code that runs now and the threads the session started" +msgstr "" + +msgid "Restart session" +msgstr "" + +msgid "End the session: its variables, imports and threads go" +msgstr "" + +msgid "Untitled script" +msgstr "" + +#. TRN The first item of the Run Script panel's session line, before the number of cells run and of variables. +msgid "Session" +msgstr "" + +msgid "No session yet" +msgstr "" + +msgid "Running" +msgstr "" + +msgid "Threads are running" +msgstr "" + +msgid "Ending the session…" +msgstr "" + +#. TRN The first %s is the number of the cell that runs, the second how many cells the file has. +#, possible-c-format, possible-boost-format +msgid "Running cell %s of %s" +msgstr "" + +msgid "Running the file" +msgstr "" + +msgid "Don't use OrcaSlicer until the script finishes." +msgstr "" + +#. TRN The heading of the console's block for a cell; %s is its number. +#, possible-c-format, possible-boost-format +msgid "Cell %s" +msgstr "" + +msgid "(no output)" +msgstr "" + +#. TRN A link in the heading of Run all's block in the Run Script console: opens every cell's row to show its output. +msgid "Expand all" +msgstr "" + +#. TRN A link in the heading of Run all's block in the Run Script console: folds every cell's row to its heading. +msgid "Collapse all" +msgstr "" + +#. TRN The + below the last line of the Run Script editor, which adds a "# %%" cell at the end of the script. +msgid "Add a cell" +msgstr "" + +msgid "Add a cell at the end of the script" +msgstr "" + +msgid "Python, run in the session" +msgstr "" + +msgid "Clear" +msgstr "" + +msgid "Clear the console: the session and its variables stay" +msgstr "" + +#. TRN A menu of the Run Script panel: how the editor shows the script's cells, the parts that start with "# %%". +msgid "Cells" +msgstr "" + +msgid "How the editor shows the script's cells" +msgstr "" + +#. TRN The heading of the Run Script panel's Cells menu, above its styles: Margin bars only, Dividers, Header bands... +msgid "Show cells with" +msgstr "" + +#. TRN A style of the Run Script panel's Cells menu: only the coloured bar beside each cell's line numbers. +msgid "Margin bars only" +msgstr "" + +#. TRN A style of the Run Script panel's Cells menu: a line across the editor above each cell. +msgid "Dividers" +msgstr "" + +#. TRN A style of the Run Script panel's Cells menu: each cell's first line, "# %% title", drawn as a shaded band. +msgid "Header bands" +msgstr "" + +#. TRN A style of the Run Script panel's Cells menu: every other cell has a shaded background. +msgid "Shaded cells" +msgstr "" + +msgid "Highlight the cell at the cursor" +msgstr "" + +#. TRN For a screen reader: the divider between the Run Script panel's editor and its console, whose value is the +#. editor's share of the panel's width. +msgid "Width of the editor" +msgstr "" + +msgid "Drag to share the width between the editor and the console. Double-click to reset it." +msgstr "" + +#. TRN The arrows on the divider between the Run Script panel's editor and console, and the strip a hidden side leaves at +#. the panel's edge. +msgid "Hide the editor" +msgstr "" + +msgid "Hide the console" +msgstr "" + +msgid "Show the editor" +msgstr "" + +msgid "Show the console" +msgstr "" + +#. TRN The strip a hidden console leaves at the Run Script panel's edge, while a script runs or after one ran. +msgid "Show the console: a script is running" +msgstr "" + +msgid "Show the console: it has new output" +msgstr "" + +msgid "Show the console: the last run failed" +msgstr "" + +#. TRN The label of the strip a hidden console leaves at the Run Script panel's edge. +msgid "Console" +msgstr "" + +msgid "New script" +msgstr "" + +msgid "Open a script…" +msgstr "" + +msgid "Open a script, or start a new one." +msgstr "" + +msgid "Start a script" +msgstr "" + +#. TRN %s is the cell marker "# %%", written as is. orca.host is the name of OrcaSlicer's Python API. +#, possible-c-format, possible-boost-format +msgid "A Python script runs inside OrcaSlicer and can call every tool an AI agent can, plus the whole orca.host API. Split it into cells with %s and try one cell at a time." +msgstr "" + +#. TRN A line in the console of the Run Script panel, where Run all started a new session. +msgid "Session restarted for Run all" +msgstr "" + +#. TRN The session line of the Run Script panel: how many cells ran in the session. +#, possible-boost-format +msgid "%1% cell run" +msgid_plural "%1% cells run" +msgstr[0] "" +msgstr[1] "" + +#. TRN The session line of the Run Script panel: how many variables the session holds. +#, possible-boost-format +msgid "%1% variable" +msgid_plural "%1% variables" +msgstr[0] "" +msgstr[1] "" + +msgid "" +"Save this script?\n" +"If you don't, your changes are lost." +msgstr "" + +msgid "Save the script" +msgstr "" + +#. TRN %1% is a file name, %2% the text encoding it is in (such as cp1252), %3% why the text doesn't fit it. +#, possible-boost-format +msgid "Can't save %1% in its encoding, %2%: %3%" +msgstr "" + +#, possible-boost-format +msgid "%1% can't be read as Python source: %2%" +msgstr "" + +msgid "Scripts can't run while OrcaSlicer is starting or closing." +msgstr "" + +msgid "The script could not run." +msgstr "" + +msgid "Python is not available in this OrcaSlicer." +msgstr "" + msgid "The device cannot handle more conversations. Please retry later." msgstr "" @@ -7574,18 +8652,12 @@ msgstr "" msgid "Parts Skip" msgstr "" -msgid "Stop" -msgstr "" - msgid "Layer: N/A" msgstr "" msgid "Click to view thermal preconditioning explanation" msgstr "" -msgid "Clear" -msgstr "" - msgid "" "You have completed printing the mall model,\n" "but synchronizing rating information has failed." @@ -7948,19 +9020,82 @@ msgstr "" msgid "Select an object first." msgstr "" +msgid "Wait for the running background job to finish." +msgstr "" + +msgid "There are no objects to orient." +msgstr "" + +#. TRN %1% is why, in English. +#, possible-boost-format +msgid "The recording was saved, but could not be encoded: %1%" +msgstr "" + +msgid "Recording encoded" +msgstr "" + +msgid "A recording is already running." +msgstr "" + +msgid "Recording cancelled." +msgstr "" + +msgid "Recording saved. Encoding it to MP4..." +msgstr "" + +msgid "Recording saved" +msgstr "" + +#. TRN %1% is why, in English. +#, possible-boost-format +msgid "The recording could not start: %1%" +msgstr "" + +#. TRN "Stop Recording" is the command that ends the recording. +msgid "Recording started. Stop Recording saves it." +msgstr "" + +msgid "No recording is running." +msgstr "" + +#. TRN %1% is a comma-separated list of preset names. +#, possible-boost-format +msgid "Imported presets: %1%." +msgstr "" + +#. TRN %1% is a comma-separated list of preset names. +#, possible-boost-format +msgid "Replaced presets: %1%." +msgstr "" + +#. TRN %1% is a comma-separated list of preset names. +#, possible-boost-format +msgid "Kept the existing presets: %1%." +msgstr "" + msgid "Slice and Preview" msgstr "" msgid "Slice & Export" msgstr "" +msgid "Slice All Plates" +msgstr "" + msgid "Go to layer (percent)" msgstr "" -msgid "Commands" +msgid "Go to tab..." msgstr "" -msgid "Go to tab..." +#. TRN %1% is the tab id the command was given, such as "preview". +#, possible-boost-format +msgid "No tab has the id \"%1%\"." +msgstr "" + +#. TRN %1% is the id of the tab that could not be opened, such as "monitor". +#, possible-boost-format +msgid "The \"%1%\" tab could not be opened." msgstr "" msgid "Load Project" @@ -7969,6 +9104,17 @@ msgstr "" msgid "Save Project As" msgstr "" +#. TRN %1% is why, in English. +#, possible-boost-format +msgid "The screenshot could not be taken: %1%" +msgstr "" + +msgid "The screenshot could not be saved." +msgstr "" + +msgid "Screenshot saved" +msgstr "" + msgid "Mode: Simple" msgstr "" @@ -7999,6 +9145,9 @@ msgstr "" msgid "Export All Sliced Files" msgstr "" +msgid "Send G-code to printer host" +msgstr "" + msgid "Max Volumetric Speed Calibration" msgstr "" @@ -8056,6 +9205,9 @@ msgstr "" msgid "Delete All Objects" msgstr "" +msgid "Select All Objects" +msgstr "" + msgid "Mirror X" msgstr "" @@ -8092,6 +9244,66 @@ msgstr "" msgid "Auto-Orient" msgstr "" +msgid "Select a part first." +msgstr "" + +msgid "Change Type to Part" +msgstr "" + +msgid "Change Type to Negative Part" +msgstr "" + +msgid "Change Type to Modifier" +msgstr "" + +msgid "Change Type to Support Blocker" +msgstr "" + +msgid "Change Type to Support Enforcer" +msgstr "" + +msgid "Change Type to Precise Seam" +msgstr "" + +msgid "Select one object or part first." +msgstr "" + +msgid "Invalid name, the following characters are not allowed:" +msgstr "" + +msgid "Set Number of Instances" +msgstr "" + +msgid "Select two or more objects first." +msgstr "" + +msgid "Cut objects can't be assembled." +msgstr "" + +msgid "Select an object with more than one instance first." +msgstr "" + +msgid "There are no objects to order." +msgstr "" + +msgid "Order by Name" +msgstr "" + +msgid "Order by Filament" +msgstr "" + +msgid "Order by Height" +msgstr "" + +msgid "Order by Size" +msgstr "" + +msgid "Deselect all objects to add a primitive object. To add a shape to the selected object, use its Add Part menu." +msgstr "" + +msgid "The SVG file could not be added." +msgstr "" + msgid "Add Plate" msgstr "" @@ -8122,12 +9334,49 @@ msgstr "" msgid "Connect a printer to synchronize the AMS filament list." msgstr "" +msgid "Filament slots belong to a filament (FFF) project, not to a G-code file." +msgstr "" + +msgid "This printer has one filament per extruder; change the number of extruders in the printer settings." +msgstr "" + +msgid "Add Filament Slot" +msgstr "" + +msgid "No more filament slots can be added." +msgstr "" + +#, possible-boost-format +msgid "Added filament slot %1%." +msgstr "" + +msgid "Delete Filament Slot" +msgstr "" + +msgid "The only filament slot cannot be deleted." +msgstr "" + +#, possible-boost-format +msgid "Filament slot must be 1 to %1%." +msgstr "" + +#, possible-boost-format +msgid "Filament slot %1% is a mixed filament; delete it from the mixed filament list." +msgstr "" + +#, possible-boost-format +msgid "Deleted filament slot %1%." +msgstr "" + msgid "Open Preset Bundle" msgstr "" msgid "Sign in to sync presets." msgstr "" +msgid "The configuration was not loaded." +msgstr "" + msgid "Export All Objects as STLs" msgstr "" @@ -8140,6 +9389,9 @@ msgstr "" msgid "Export Toolpaths as OBJ" msgstr "" +msgid "Nothing was exported." +msgstr "" + msgid "About OrcaSlicer" msgstr "" @@ -8161,6 +9413,15 @@ msgstr "" msgid "Install Local Plugin" msgstr "" +msgid "Select plugin package" +msgstr "" + +msgid "Plugin files (*.py;*.whl)|*.py;*.whl" +msgstr "" + +msgid "The plugin was not installed." +msgstr "" + msgid "Unknown command." msgstr "" @@ -8333,6 +9594,153 @@ msgstr "" msgid "Error loading shaders" msgstr "" +#. TRN The OpenGL context could not be made current, so nothing can be drawn in the 3D view. +msgid "OpenGL could not be activated for the 3D view, so it cannot be shown." +msgstr "" + +#. TRN %1% is the name of a graphics card or display adapter as Windows reports it, such as "Microsoft Basic Display Adapter". +#, possible-boost-format +msgid "The window is on a display driven by \"%1%\"." +msgstr "" + +msgid "Make sure the display adapter driving this window's display is enabled and its driver is installed and up to date." +msgstr "" + +msgid "If the computer has more than one graphics card, connecting the monitor to another one may help." +msgstr "" + +msgid "If the problem remains, close any overlay or screen capture software and try again." +msgstr "" + +msgid "The file was not written." +msgstr "" + +msgid "The project has no objects." +msgstr "" + +msgid "Another export job is running." +msgstr "" + +msgid "Slicing is in progress. Wait for it to finish and export again." +msgstr "" + +msgid "The plate's slice ended with an error. Fix what it reports and slice again before exporting." +msgstr "" + +msgid "The plate is not sliced. Slice it first." +msgstr "" + +msgid "The export did not start." +msgstr "" + +msgid "The sliced file was not written. Slice first and check for slicing errors." +msgstr "" + +msgid "This printer prints with Print plate, not through a print host." +msgstr "" + +msgid "This printer has no print host. Set one in the printer's connection settings." +msgstr "" + +#, possible-boost-format +msgid "Plate %1% could not be selected." +msgstr "" + +msgid "The preview has no layers. Slice the plate first." +msgstr "" + +#. TRN %1% is the plate index asked for. +#, possible-boost-format +msgid "Plate %1% does not exist (the project has plate 0 only)" +msgstr "" + +#. TRN %1% is the plate index asked for, %2% the last plate's index. +#, possible-boost-format +msgid "Plate %1% does not exist (the project has plates 0..%2%)" +msgstr "" + +msgid "There are no objects to arrange." +msgstr "" + +#, possible-boost-format +msgid "\"%1%\" names several hidden presets. Use the preset's internal name." +msgstr "" + +#, possible-boost-format +msgid "\"%1%\" is not compatible with the selected printer." +msgstr "" + +#. TRN %1% is a preset name, %2% a filament slot number. +#, possible-boost-format +msgid "The selector of filament slot %2% does not offer \"%1%\"." +msgstr "" + +#, possible-boost-format +msgid "The preset selector does not offer \"%1%\"." +msgstr "" + +#, possible-boost-format +msgid "The name \"%1%\" is ambiguous in the selector of filament slot %2%. Use the preset's internal name." +msgstr "" + +#, possible-boost-format +msgid "The name \"%1%\" is ambiguous in the preset selector. Use the preset's internal name." +msgstr "" + +msgid "The settings tab is not available." +msgstr "" + +#. TRN %1% is the filament slot number asked for, %2% the last slot's number. +#, possible-boost-format +msgid "Filament slot %1% does not exist (the slots are 1..%2%)" +msgstr "" + +msgid "The unsaved changes cannot be transferred: a printer's changes stay with it." +msgstr "" + +#, possible-boost-format +msgid "The unsaved changes cannot be transferred: \"%1%\" is a filament of another type." +msgstr "" + +#, possible-boost-format +msgid "Filament slot %1% is a mixed-color virtual slot, which has no filament preset of its own." +msgstr "" + +#, possible-boost-format +msgid "Selecting \"%1%\" was cancelled." +msgstr "" + +#. TRN %1% is the preset asked for, %2% the one that is selected. +#, possible-boost-format +msgid "\"%2%\" was selected instead of \"%1%\"." +msgstr "" + +msgid "" +"No presets were imported.\n" +"Hint: Make sure you have added the corresponding printer before importing the configs." +msgstr "" + +msgid "The project has unsaved changes." +msgstr "" + +msgid "Nothing was imported." +msgstr "" + +msgid "A project is saved without G-code, so its file name cannot end in .gcode.3mf. Export the sliced file instead." +msgstr "" + +msgid "The project was not saved." +msgstr "" + +msgid "A cut object keeps its number of instances." +msgstr "" + +msgid "Make every instance of the object printable first." +msgstr "" + +msgid "The number of instances is a whole number from 1 to 1000." +msgstr "" + msgctxt "Layers" msgid "Top" msgstr "" @@ -8727,9 +10135,6 @@ msgstr "" msgid "Slicing plate %1%: %2%" msgstr "" -msgid "Invalid name, the following characters are not allowed:" -msgstr "" - msgid "Sliced Info" msgstr "" @@ -9058,6 +10463,9 @@ msgstr "" msgid "This project contains a model made in the Design tab and no other geometry. Enable \"CAD feature (experimental)\" in Preferences and restart to see and edit it; it is kept when the project is saved." msgstr "" +msgid "The invalid area has been removed, so please define it again using a valid polygon." +msgstr "" + msgid "Your object appears to be too large, do you want to scale it down to fit the print bed automatically?" msgstr "" @@ -9079,15 +10487,6 @@ msgstr "" msgid "Export OBJ file:" msgstr "" -#, possible-c-format, possible-boost-format -msgid "" -"The file %s already exists.\n" -"Do you want to replace it?" -msgstr "" - -msgid "Confirm Save As" -msgstr "" - msgid "Delete object which is a part of cut object" msgstr "" @@ -9118,9 +10517,6 @@ msgstr "" msgid "Cannot slice: the prime tower overlaps an area reserved for IDEX/IQEX parallel printing (a secondary zone, or a carriage clearance strip inside the primary zone)." msgstr "" -msgid "Another export job is running." -msgstr "" - msgid "Unable to replace with more than one volume" msgstr "" @@ -9737,6 +11133,51 @@ msgstr "" msgid "Choose Download Directory" msgstr "" +msgid "Another OrcaSlicer window is serving agents. This window takes over when it closes." +msgstr "" + +msgid "Not running" +msgstr "" + +msgid "The port must be between 1024 and 65535" +msgstr "" + +msgid "The agent connects to the open OrcaSlicer while the MCP server is on. The setup holds the access token, so don't share it." +msgstr "" + +msgid "The agent starts this copy of OrcaSlicer when it isn't open, so set the agent up again after OrcaSlicer moves." +msgstr "" + +msgid "Run the copied command in a terminal, then start a new Claude Code session." +msgstr "" + +msgid "Add the copied lines to config.toml in the .codex folder of your home folder, then start a new Codex session." +msgstr "" + +msgid "Add the copied setting to opencode.json in the .config/opencode folder of your home folder, then restart opencode." +msgstr "" + +msgid "Add the copied entry to cordis.patch.yml in the .dsh folder of your home folder, then restart DeepSeek Harness." +msgstr "" + +msgid "Other apps" +msgstr "" + +msgid "Add the copied settings to the app's MCP configuration file. For an app that can't connect over HTTP, choose stdio." +msgstr "" + +msgid "Copied" +msgstr "" + +msgid "Unrestricted" +msgstr "" + +msgid "Restricted" +msgstr "" + +msgid "Change" +msgstr "" + #, possible-c-format, possible-boost-format msgid "" "You've selected network plug-in version %s.\n" @@ -9854,6 +11295,45 @@ msgstr "" msgid "With this option enabled, the Design tab is shown, where models can be built and edited parametrically. This feature is experimental and still under development." msgstr "" +msgid "AI features" +msgstr "" + +msgid "Let AI agents such as Claude Code and Codex open and slice models, change settings and take screenshots while OrcaSlicer is open. Only programs on this computer can connect." +msgstr "" + +msgid "MCP server" +msgstr "" + +msgid "Run a local server that AI agents connect to through the Model Context Protocol (MCP)." +msgstr "" + +msgid "Server port" +msgstr "" + +msgid "Local port of the MCP server." +msgstr "" + +msgid "Server address" +msgstr "" + +msgid "The address agents connect to over HTTP, with the access token." +msgstr "" + +msgid "Connection type" +msgstr "" + +msgid "How the agent you set up below connects to OrcaSlicer." +msgstr "" + +msgid "Add to an agent" +msgstr "" + +msgid "Copy the setup that connects the chosen agent to OrcaSlicer." +msgstr "" + +msgid "Whether Python scripts are subject to the same permission checks as plugins, or bypass them." +msgstr "" + msgid "Pop up to select filament grouping mode" msgstr "" @@ -10098,6 +11578,23 @@ msgid "" "You can still switch the view type in the preview afterwards." msgstr "" +msgid "Simplify preview while dragging" +msgstr "" + +msgid "" +"What the sliced preview draws while you drag the camera or a preview slider, or zoom with the mouse wheel, so that large prints stay responsive. The full toolpaths are restored as soon as you let go.\n" +"Off: the full toolpaths.\n" +"Solid model: the sliced objects and the prime tower as solid shapes in the colors of the current view, cut to the visible layer range, with its bottom and top layers and the supports drawn as toolpaths. Negative volumes are not cut out. A print made object by object, or one on a belt printer, keeps its full toolpaths.\n" +"Shell only: every layer without its sparse infill, internal solid infill, internal bridges and gap fill, which lie under the walls and skins. Walls, top and bottom surfaces, bridges, supports and the prime tower are drawn whole, so the print looks the same from outside.\n" +"The bottom and top layers of the visible range are always drawn whole; a layer with no infill of its own, as with infill combination, takes the layers down to the nearest one with infill along." +msgstr "" + +msgid "Solid model" +msgstr "" + +msgid "Shell only" +msgstr "" + msgid "Dim lower layers" msgstr "" @@ -10112,9 +11609,6 @@ msgid "" "99% is barely darkened, 0% renders them black. Capped at 99% because 100% would be the same as disabling the option." msgstr "" -msgid "Preset" -msgstr "" - msgid "Remember printer configuration" msgstr "" @@ -10320,6 +11814,27 @@ msgid "" "Off, a translucent filament is matte and an opaque one keeps the highlight of the plain view." msgstr "" +msgid "Persistent" +msgstr "" + +msgid "When Outline is enabled in the 3D canvas menu, outlines visible objects even when they are not selected." +msgstr "" + +msgid "The configured outline color is invalid." +msgstr "" + +msgid "Persistent color" +msgstr "" + +msgid "Choose the color of the persistent outlines of unselected objects." +msgstr "" + +msgid "Selection color" +msgstr "" + +msgid "Choose the color of the outlines of selected objects." +msgstr "" + msgid "Anti-aliasing" msgstr "" @@ -12572,9 +14087,6 @@ msgstr "" msgid "Transfer" msgstr "" -msgid "Don't save" -msgstr "" - msgid "Discard" msgstr "" @@ -13333,9 +14845,6 @@ msgstr "" msgid "HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate." msgstr "" -msgid "This system uses HTTPS certificates from the system Certificate Store or Keychain. To use a custom CA file, import it there." -msgstr "" - msgid "Printer model" msgstr "" @@ -13354,6 +14863,9 @@ msgstr "" msgid "Manual Setup" msgstr "" +msgid "This system uses HTTPS certificates from the system Certificate Store or Keychain. To use a custom CA file, import it there." +msgstr "" + msgid "IP and Access Code Verified! You may close the window" msgstr "" @@ -13857,6 +15369,21 @@ msgstr "" msgid "If you still want to print, you can enable the option in Preferences / Control / Slicing / Remove mixed temperature restriction." msgstr "" +msgid "A prime tower requires that all objects have the same layer height." +msgstr "" + +msgid "A prime tower requires that all objects are printed over the same number of raft layers." +msgstr "" + +msgid "The prime tower is only supported for multiple objects if they are printed with the same support_top_z_distance." +msgstr "" + +msgid "A prime tower requires that all objects are sliced with the same layer height." +msgstr "" + +msgid "The prime tower is only supported if all objects have the same variable layer height." +msgstr "" + msgid "No extrusions under current settings." msgstr "" @@ -13982,21 +15509,6 @@ msgstr "" msgid "A prime tower requires any “support gap” to be a multiple of layer height." msgstr "" -msgid "A prime tower requires that all objects have the same layer height." -msgstr "" - -msgid "A prime tower requires that all objects are printed over the same number of raft layers." -msgstr "" - -msgid "The prime tower is only supported for multiple objects if they are printed with the same support_top_z_distance." -msgstr "" - -msgid "A prime tower requires that all objects are sliced with the same layer height." -msgstr "" - -msgid "The prime tower is only supported if all objects have the same variable layer height." -msgstr "" - msgid "One or more object were assigned an extruder that the printer does not have." msgstr "" @@ -19448,6 +20960,39 @@ msgstr "" msgid "Load and store settings at the given directory. This is useful for maintaining different profiles or including configurations from a network storage." msgstr "" +msgid "Start the MCP server for AI agents on 127.0.0.1 for this run, whatever the preference says." +msgstr "" + +msgid "MCP server port" +msgstr "" + +msgid "Port of the MCP server. Defaults to the preference, or 13619." +msgstr "" + +msgid "MCP server token" +msgstr "" + +msgid "Bearer token the MCP server requires for this run. The ORCA_MCP_TOKEN environment variable takes precedence and does not show up in the process list." +msgstr "" + +msgid "Run a replay or script" +msgstr "" + +msgid "Run a replay (.json) or a Python script (.py) once the GUI is ready, then exit: 0 when it passed or finished, 1 when a step failed or the script did not finish, 2 when the file is invalid or cannot be read." +msgstr "" + +msgid "Replay output directory" +msgstr "" + +msgid "Where --mcp-run writes a replay's result.json and screenshots. Defaults to .out next to the replay." +msgstr "" + +msgid "MCP stdio bridge" +msgstr "" + +msgid "Act as an MCP server on standard input and output for clients that cannot use HTTP, forwarding to the running OrcaSlicer (started with --mcp when none answers)." +msgstr "" + msgid "Output directory" msgstr "" @@ -21573,9 +23118,6 @@ msgstr "" msgid "Only materials of the same type can be selected." msgstr "" -msgid "Send G-code to printer host" -msgstr "" - msgid "Upload to Printer Host with the following filename:" msgstr "" @@ -23359,9 +24901,6 @@ msgstr "" msgid "Export Presets" msgstr "" -msgid "Show in folder" -msgstr "" - msgid "Delete bundle" msgstr "" @@ -23839,46 +25378,30 @@ msgstr "" msgid "Add material (extrude / revolve / sweep / loft / thicken / rib)" msgstr "" -msgctxt "Design" -msgid "Extrude" -msgstr "" - msgid "Extrude a sketch profile, or push/pull a picked face" msgstr "" msgid "Create a sketch, or pick a solid face, first" msgstr "" -msgid "Revolve" -msgstr "" - msgid "Revolve a profile about an axis" msgstr "" msgid "Create a sketch profile to revolve first" msgstr "" -msgid "Sweep" -msgstr "" - msgid "Sweep a profile along a path" msgstr "" msgid "Create a profile sketch to sweep first" msgstr "" -msgid "Loft" -msgstr "" - msgid "Loft (skin) between two or more profiles" msgstr "" msgid "Create at least two profile sketches to loft" msgstr "" -msgid "Thicken" -msgstr "" - msgid "Offset a solid face into a thin plate (new body)" msgstr "" @@ -23889,10 +25412,6 @@ msgstr "" msgid "Body %zu" msgstr "" -msgctxt "Design" -msgid "Rib" -msgstr "" - msgid "Grow a thin wall from an open sketch line, fused to a body" msgstr "" @@ -23902,10 +25421,6 @@ msgstr "" msgid "Create a sketch with an open line first" msgstr "" -msgctxt "Design" -msgid "Pattern" -msgstr "" - msgid "Create a solid body to pattern first" msgstr "" @@ -23915,48 +25430,30 @@ msgstr "" msgid "Surface (extrude / revolve / loft / fill / offset / thicken)" msgstr "" -msgid "Surface Extrude" -msgstr "" - msgid "Extrude a sketch into a sheet body (no end caps)" msgstr "" msgid "Create a sketch first" msgstr "" -msgid "Surface Revolve" -msgstr "" - msgid "Revolve a sketch profile into a sheet body" msgstr "" -msgid "Surface Loft" -msgstr "" - msgid "Loft (skin) between 2+ profiles, open (no end caps)" msgstr "" -msgid "Surface Fill" -msgstr "" - msgid "Fill a sketch boundary with a smooth face" msgstr "" msgid "Create a sketch profile to fill first" msgstr "" -msgid "Surface Offset" -msgstr "" - msgid "Offset a sheet body's shell by a signed distance" msgstr "" msgid "No sheet body to offset — create a surface feature first" msgstr "" -msgid "Thicken Surface" -msgstr "" - msgid "Thicken a sheet body into a solid" msgstr "" @@ -23966,45 +25463,24 @@ msgstr "" msgid "Datum / Curve (plane / axis / coord sys / helix / project)" msgstr "" -msgctxt "Design" -msgid "Plane" -msgstr "" - msgid "Reference plane (offset / tilt / midplane / tangent / two edges / coincident)" msgstr "" -msgid "Axis" -msgstr "" - msgid "Datum axis (two points, face normal, cylinder centerline, two planes, along edge)" msgstr "" -msgid "Coordinate system" -msgstr "" - msgid "Datum coordinate system (world point, or face + direction edge)" msgstr "" -msgid "Helix" -msgstr "" - msgid "Helical curve (spring path) — use as a sweep path for coils / springs / augers" msgstr "" -msgctxt "Design" -msgid "Project" -msgstr "" - msgid "Project body edges onto a plane as sketch entities" msgstr "" msgid "Project needs a body — add or import one first" msgstr "" -#, possible-c-format, possible-boost-format -msgid "Face %d" -msgstr "" - msgid "(all edges)" msgstr "" @@ -24017,19 +25493,12 @@ msgstr "" msgid "Transform needs a body — add or import one first" msgstr "" -msgctxt "Design" -msgid "Mirror" -msgstr "" - msgid "Reflect a body about a plane" msgstr "" msgid "Mirror needs a body — add or import one first" msgstr "" -msgid "Mate" -msgstr "" - msgid "Assembly: align two coordinate systems (fastened, planar, revolute, slider, cylindrical)" msgstr "" @@ -24069,16 +25538,9 @@ msgstr "" msgid "Tilt a picked face by a draft angle" msgstr "" -msgctxt "Design" -msgid "Shell" -msgstr "" - msgid "Hollow the body to a wall thickness, opening a picked face" msgstr "" -msgid "Delete Face" -msgstr "" - msgid "Remove faces from a body and heal the solid" msgstr "" @@ -24091,19 +25553,12 @@ msgstr "" msgid "Hole / thread" msgstr "" -msgctxt "Design" -msgid "Hole" -msgstr "" - msgid "Drill a hole, centered on a picked face or placed on a plane" msgstr "" msgid "Pick a face or a plane to drill into" msgstr "" -msgid "Thread" -msgstr "" - msgid "Thread a cylindrical surface (inner bore / outer) or a circular edge" msgstr "" @@ -24252,15 +25707,9 @@ msgstr "" msgid "Fillet / chamfer" msgstr "" -msgid "Fillet" -msgstr "" - msgid "Pick two lines, then drag the arrow or click the radius to set it" msgstr "" -msgid "Chamfer" -msgstr "" - msgid "Pick two lines, then drag the arrow or click the distance to set it" msgstr "" @@ -24455,9 +25904,6 @@ msgstr "" msgid "Choose how Commit to Plate sends the bodies" msgstr "" -msgid "Commit to Plate" -msgstr "" - msgid "All bodies become one object with a part per body, keeping their relative positions" msgstr "" @@ -24473,9 +25919,6 @@ msgstr "" msgid "Height / Y" msgstr "" -msgid "Sketch" -msgstr "" - msgid "Distance X" msgstr "" @@ -24638,9 +26081,6 @@ msgstr "" msgid "Total angle (°)" msgstr "" -msgid "Boolean" -msgstr "" - msgid "Subtract" msgstr "" @@ -24650,10 +26090,6 @@ msgstr "" msgid "Keep tool body" msgstr "" -msgctxt "Design" -msgid "Cut" -msgstr "" - msgid "Body" msgstr "" @@ -24747,9 +26183,6 @@ msgstr "" msgid "Face" msgstr "" -msgid "Draft" -msgstr "" - msgid "Pick a side face, then set the draft angle. The face pivots about the body base." msgstr "" @@ -24967,6 +26400,15 @@ msgstr "" msgid "Constraints" msgstr "" +msgid "No constraints yet" +msgstr "" + +msgid "Zoom to selection" +msgstr "" + +msgid "Delete constraint" +msgstr "" + msgid "Feature tree" msgstr "" @@ -24993,9 +26435,6 @@ msgstr "" msgid "Show / hide" msgstr "" -msgid "Zoom to selection" -msgstr "" - msgid "Check interference — find overlapping bodies" msgstr "" @@ -25137,6 +26576,11 @@ msgstr[1] "" msgid "Sketch %d" msgstr "" +#. TRN %1% is the name of the sketch being edited, as its Feature tree row shows it. +#, possible-boost-format +msgid "Editing: %1% · N = look normal to the plane · Confirm or Cancel in the toolbar" +msgstr "" + #, possible-c-format, possible-boost-format msgid "Editing: Sketch %d · N = look normal to the plane · Confirm or Cancel in the toolbar" msgstr "" @@ -25181,9 +26625,6 @@ msgstr "" msgid "STEP import failed: %s" msgstr "" -msgid "Rebuilding model…" -msgstr "" - #, possible-c-format, possible-boost-format msgid "Imported %d solid — pick a face or edge, then Fillet / Cut / Shell to modify" msgid_plural "Imported %d solids — pick a face or edge, then Fillet / Cut / Shell to modify" @@ -25231,9 +26672,6 @@ msgstr "" msgid "Mesh conversion produced no geometry" msgstr "" -msgid "Mesh" -msgstr "" - #, possible-c-format, possible-boost-format msgid "Mesh import failed: %s" msgstr "" @@ -25670,7 +27108,7 @@ msgstr "" msgid " · Esc goes back to Select" msgstr "" -msgid " · click a constraint badge to remove it" +msgid " · click a constraint badge to select it" msgstr "" #, possible-c-format, possible-boost-format @@ -25757,21 +27195,6 @@ msgstr "" msgid "Click a solid EDGE in the viewport" msgstr "" -msgid "An angled plane needs an edge to tilt about — pick Edge A" -msgstr "" - -msgid "A midplane needs two faces — pick Face A and Face B" -msgstr "" - -msgid "Face A and Face B are the same face — a midplane needs two different faces" -msgstr "" - -msgid "A tangent plane needs a cylindrical face — pick Face A" -msgstr "" - -msgid "This plane needs two edges — pick Edge A and Edge B" -msgstr "" - msgid "Plane added — pick it as a sketch plane" msgstr "" @@ -26029,10 +27452,9 @@ msgstr "" msgid "Constraints (%d)" msgstr "" -msgid "No constraints yet" -msgstr "" - -msgid "Delete constraint" +#. TRN Design tab status line. %1% names the selected sketch constraint, e.g. "Horizontal E0·P0 — E0·P1". +#, possible-boost-format +msgid "%1% selected — Delete removes it" msgstr "" msgid "Constraint deleted" @@ -26202,10 +27624,10 @@ msgstr "" msgid "All bodies hidden — show one before committing" msgstr "" -msgid "Design Assembly" +msgid "Design Body" msgstr "" -msgid "Design Body" +msgid "Design Assembly" msgstr "" #, possible-c-format @@ -26319,10 +27741,6 @@ msgstr "" msgid "Edit Variable" msgstr "" -#, possible-c-format, possible-boost-format -msgid "Variable '%s' could not be removed (likely still referenced by a feature expression): %s" -msgstr "" - #, possible-c-format, possible-boost-format msgid "\"%s\" is not a value an expression can drive" msgstr "" @@ -26546,10 +27964,6 @@ msgstr "" msgid "Trim the body with a plane — drag the offset arrow; keep one half or both" msgstr "" -msgctxt "Design" -msgid "Split" -msgstr "" - msgid "Split needs a solid body — add or import one first" msgstr "" @@ -26955,6 +28369,170 @@ msgstr "" msgid "Type the angle between two lines, or the distance between the two picks" msgstr "" +msgctxt "Design" +msgid "Describe scene" +msgstr "" + +msgctxt "Design" +msgid "Describe feature" +msgstr "" + +msgctxt "Design" +msgid "Query topology" +msgstr "" + +msgctxt "Design" +msgid "Slice body" +msgstr "" + +msgctxt "Design" +msgid "Validate against" +msgstr "" + +msgctxt "Design" +msgid "Sketch describe" +msgstr "" + +msgctxt "Design" +msgid "Sketch validate" +msgstr "" + +msgctxt "Design" +msgid "Sketch constraints" +msgstr "" + +msgctxt "Design" +msgid "Import step" +msgstr "" + +msgctxt "Design" +msgid "Import mesh" +msgstr "" + +msgctxt "Design" +msgid "Hole styled" +msgstr "" + +msgctxt "Design" +msgid "Hole standard" +msgstr "" + +msgctxt "Design" +msgid "Bridge" +msgstr "" + +msgctxt "Design" +msgid "Set variable" +msgstr "" + +msgctxt "Design" +msgid "Set feature" +msgstr "" + +msgctxt "Design" +msgid "Feature delete" +msgstr "" + +msgctxt "Design" +msgid "Feature move" +msgstr "" + +msgctxt "Design" +msgid "Feature set enabled" +msgstr "" + +msgctxt "Design" +msgid "Feature rename" +msgstr "" + +msgctxt "Design" +msgid "Body set" +msgstr "" + +msgctxt "Design" +msgid "Body delete" +msgstr "" + +msgctxt "Design" +msgid "Commit" +msgstr "" + +msgctxt "Design" +msgid "New design" +msgstr "" + +msgctxt "Design" +msgid "Export step" +msgstr "" + +msgctxt "Design" +msgid "Sketch begin" +msgstr "" + +msgctxt "Design" +msgid "Sketch commit" +msgstr "" + +msgctxt "Design" +msgid "Sketch cancel" +msgstr "" + +msgctxt "Design" +msgid "Sketch add" +msgstr "" + +msgctxt "Design" +msgid "Sketch select" +msgstr "" + +msgctxt "Design" +msgid "Sketch delete" +msgstr "" + +msgctxt "Design" +msgid "Sketch construction" +msgstr "" + +msgctxt "Design" +msgid "Sketch offset" +msgstr "" + +msgctxt "Design" +msgid "Sketch mirror" +msgstr "" + +msgctxt "Design" +msgid "Sketch heal" +msgstr "" + +msgctxt "Design" +msgid "Sketch set value" +msgstr "" + +msgctxt "Design" +msgid "Sketch fillet" +msgstr "" + +msgctxt "Design" +msgid "Sketch chamfer" +msgstr "" + +msgctxt "Design" +msgid "Sketch trim" +msgstr "" + +msgctxt "Design" +msgid "Sketch transform" +msgstr "" + +msgctxt "Design" +msgid "Sketch constrain" +msgstr "" + +msgctxt "Design" +msgid "Sketch unconstrain" +msgstr "" + msgid "Type the text to insert" msgstr "" @@ -27309,6 +28887,24 @@ msgstr "" msgid "needs a cylindrical face at both ends — connector %1% is on a curved face" msgstr "" +msgid "A picked face or edge is no longer on the model — pick it again" +msgstr "" + +msgid "An angled plane needs an edge to tilt about — pick Edge A" +msgstr "" + +msgid "A midplane needs two faces — pick Face A and Face B" +msgstr "" + +msgid "Face A and Face B are the same face — a midplane needs two different faces" +msgstr "" + +msgid "A tangent plane needs a cylindrical face — pick Face A" +msgstr "" + +msgid "This plane needs two edges — pick Edge A and Edge B" +msgstr "" + #. TRN Datum plane entry in the reference plane list. %1% is the plane name. #, possible-boost-format msgid "%1% (base plane missing)" @@ -30131,9 +31727,6 @@ msgid_plural "Preview: %1% triangles" msgstr[0] "" msgstr[1] "" -msgid "Steps" -msgstr "" - msgid "Splits every triangle of the model into four, this many times over. Each step quadruples the count - 3 turns 100 k triangles into 6.4 M - so prefer refining only the painted area unless you need the whole model finer." msgstr "" @@ -30360,9 +31953,6 @@ msgstr "" msgid "Accurate" msgstr "" -msgid "Balanced" -msgstr "" - msgid "Quick" msgstr "" @@ -30587,6 +32177,10 @@ msgstr "" msgid "Failed to install plugin package. See the log for details." msgstr "" +#, possible-boost-format +msgid "Plugin installation failed: %1%" +msgstr "" + #, possible-c-format, possible-boost-format msgid "" "Plugin \"%s\" is already installed.\n" @@ -30896,6 +32490,21 @@ msgstr "" msgid "Add value to %s" msgstr "" +#. TRN %s is the original permission value that was removed outside this dialog. +#, possible-c-format, possible-boost-format +msgid "The original value is no longer granted: %s. Add the edited value or discard it." +msgstr "" + +#. TRN %s is the original permission value before the user's unsaved edit. +#, possible-c-format, possible-boost-format +msgid "Unsaved edit of: %s" +msgstr "" + +#. TRN %s is the original permission value whose unsaved edit will be discarded. +#, possible-c-format, possible-boost-format +msgid "Discard edit of %s" +msgstr "" + msgctxt "Permission value" msgid "Remove" msgstr "" @@ -31577,9 +33186,6 @@ msgstr "" msgid "Edit Mode" msgstr "" -msgid "Run Script" -msgstr "" - msgid "Add user script" msgstr "" @@ -31853,10 +33459,6 @@ msgstr "" msgid "The configuration could not be written to disk. Nothing was changed." msgstr "" -#, possible-boost-format -msgid "Plugin installation failed: %1%" -msgstr "" - #. TRN %1% is the plugin's cloud ID. #, possible-boost-format msgid "%1%: installed plugin was not found in the catalog." @@ -32043,6 +33645,13 @@ msgstr "" msgid "Failed to create plugin directory %1%: %2%" msgstr "" +#. TRN %1% is the name of a TOML table, %2% an example of the comment block that holds it. +#, possible-boost-format +msgid "" +"The plugin has no name. Its PEP 723 block needs a %1% table with a name, as in:\n" +"%2%" +msgstr "" + #. TRN %1% is a folder path, %2% the system error message. #, possible-boost-format msgid "Failed to back up existing plugin %1%: %2%" @@ -32092,6 +33701,14 @@ msgstr "" msgid "Plugin manifest not found: %1%" msgstr "" +#. TRN %1% is a plugin's file name without extension, such as "script". +#, possible-boost-format +msgid "The plugin name %1% is reserved; rename the plugin file" +msgstr "" + +msgid "Plugin discovery is still running" +msgstr "" + msgid "Failed to fetch plugins from the cloud. See logs for details." msgstr "" @@ -32472,6 +34089,92 @@ msgstr "" msgid "Remaining time:" msgstr "" +msgid "Suggestions" +msgstr "" + +#. TRN Read by a screen reader for the line numbers beside the code editor. +msgid "Line numbers. Press Enter to use the fold buttons with the arrow keys, and Escape to leave them." +msgstr "" + +msgid "Line numbers" +msgstr "" + +#. TRN Read by a screen reader for the code editor's text. +msgid "Code. Press Enter to start editing, and Escape to leave the editor." +msgstr "" + +msgid "Code editor" +msgstr "" + +#. TRN Shown when a person types in the code editor while a script runs. +msgid "You can edit once the run ends." +msgstr "" + +#. TRN The two %s are line numbers. +#, possible-c-format, possible-boost-format +msgid "Unfold lines %s to %s" +msgstr "" + +#. TRN A button beside the code editor's line numbers that shows lines it hid. +msgctxt "Code editor" +msgid "Unfold" +msgstr "" + +#. TRN %s is a line number. +#, possible-c-format, possible-boost-format +msgid "Fold the lines from line %s" +msgstr "" + +#. TRN A button beside the code editor's line numbers that hides the lines of a block. +msgctxt "Code editor" +msgid "Fold" +msgstr "" + +#. TRN The two %s are line numbers. +#, possible-c-format, possible-boost-format +msgid "Fold or unfold lines %s to %s" +msgstr "" + +msgid "Find all" +msgstr "" + +msgid "Search for" +msgstr "" + +msgid "Replace all" +msgstr "" + +#. TRN A button of the code editor's search box that replaces the next match. +msgctxt "Code editor" +msgid "Replace" +msgstr "" + +msgid "Replace with" +msgstr "" + +#. TRN The code editor's search box: the first %s is the match the cursor is on, the second how many there are. +#, possible-c-format, possible-boost-format +msgid "%s of %s" +msgstr "" + +msgid "Search in the selection" +msgstr "" + +msgid "Use a regular expression" +msgstr "" + +#. TRN Shows or hides the replace field of the code editor's search box. +msgid "Show or hide Replace" +msgstr "" + +msgid "Match whole words" +msgstr "" + +#. TRN Read by a screen reader as the cursor moves in the code editor; %s is a line number. +#, possible-c-format, possible-boost-format +msgid "Cursor on line %s" +msgstr "" + #: resources/data/hints.ini: [hint:Precise wall] msgid "Precise wall\nDid you know that turning on precise wall can improve precision and layer consistency?" msgstr "" diff --git a/localization/i18n/list.txt b/localization/i18n/list.txt index 763f229d58..4d9a68991f 100644 --- a/localization/i18n/list.txt +++ b/localization/i18n/list.txt @@ -151,6 +151,7 @@ src/slic3r/GUI/CameraPopup.cpp src/slic3r/GUI/ConnectPrinter.cpp src/slic3r/GUI/HMSPanel.cpp src/slic3r/GUI/MainFrame.cpp +src/slic3r/GUI/Mcp/McpPersonContext.cpp src/slic3r/GUI/Mcp/McpToolsActions.cpp src/slic3r/GUI/Mcp/McpToolsApi.cpp src/slic3r/GUI/Mcp/McpToolsApp.cpp diff --git a/resources/web/dialog/ActionReplay/action_replay.js b/resources/web/dialog/ActionReplay/action_replay.js index e337c0ac4b..340958495a 100644 --- a/resources/web/dialog/ActionReplay/action_replay.js +++ b/resources/web/dialog/ActionReplay/action_replay.js @@ -243,7 +243,7 @@ function makeRow(step) { head.setAttribute("aria-expanded", "false"); head.appendChild(el("span", "step-title", step.title)); if (step.what_text) head.appendChild(el("span", "step-what", step.what_text)); - if (step.param_text) head.appendChild(el("span", "step-param", step.param_text)); + if (step.args_text) head.appendChild(el("span", "step-args", step.args_text)); const tags = el("span", "step-tags"); for (const id of step.flags || []) { const label = FLAG_LABELS[id]; diff --git a/resources/web/dialog/ActionReplay/style.css b/resources/web/dialog/ActionReplay/style.css index 582695470c..dec9f1d5cb 100644 --- a/resources/web/dialog/ActionReplay/style.css +++ b/resources/web/dialog/ActionReplay/style.css @@ -215,7 +215,7 @@ button:focus-visible, textarea:focus-visible { outline: 2px solid var(--sr-accen } .step-title { font-weight: 600; } .step.is-wait .step-title, .step.is-skip .step-title { font-weight: 400; color: var(--sr-muted); } -.step-what, .step-param { display: block; color: var(--sr-muted); font-size: 12px; overflow-wrap: anywhere; } +.step-what, .step-args { display: block; color: var(--sr-muted); font-size: 12px; overflow-wrap: anywhere; } .step-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; } .tag { font-size: 11px; diff --git a/resources/web/dialog/SpeedDial/speeddial.js b/resources/web/dialog/SpeedDial/speeddial.js index f699d6859a..e8b8668378 100644 --- a/resources/web/dialog/SpeedDial/speeddial.js +++ b/resources/web/dialog/SpeedDial/speeddial.js @@ -822,6 +822,11 @@ window.HandleStudio = function (payload) { if (fid && FAVS.indexOf(fid) !== -1) FAVS.splice(FAVS.indexOf(fid), 1); render({ resize: true, keepScroll: true }); flashHint(T("sd_favs_full", "Favorites are full (%s max)", (payload.limit || K_FAV_LIMIT))); + } else if (payload.command === "favourites") { + // The bar as C++ now shows it, sent after each pin, unpin and reorder: it settles the click's optimistic + // change, and an unpin can bring a pin past the tenth onto the bar, which the page alone cannot know. + FAVS = payload.favourites || []; + render({ resize: true, keepScroll: true }); } }; @@ -1471,10 +1476,11 @@ function toggleFav(id) { } // Fire a command/plugin action; C++ owns the run-confirm (native dialog) + suppression, then -// closes the popup + toasts. +// closes the popup + toasts. A plain pick passes no arguments: a command then does what a person's +// pick does, asking in its dialog where it has one. function run(a) { if (!a) return; - SendMessage({ command: "run_action", id: a.id, title: a.title, param: "" }); + SendMessage({ command: "run_action", id: a.id, title: a.title, args: {} }); } // Activate an entry in the main phase. Two-phase commands switch the palette to their input phase @@ -1507,13 +1513,13 @@ function runJumpToLayer(pct) { if (!isFinite(n) || n < 0 || n > 100) return; var a = findActionByInput("percent"); if (!a) return; - SendMessage({ command: "run_action", id: a.id, title: a.title, param: String(n) }); + SendMessage({ command: "run_action", id: a.id, title: a.title, args: { percent: n } }); } function jumpToTab(t) { var a = findActionByInput("tab"); if (!a || !t) return; - SendMessage({ command: "run_action", id: a.id, title: a.title, param: t.id }); + SendMessage({ command: "run_action", id: a.id, title: a.title, args: { tab: t.id } }); } // Clear the shared query/cursor state when entering or leaving a phase. Callers set the diff --git a/resources/web/dialog/SpeedDial/speeddial.test.js b/resources/web/dialog/SpeedDial/speeddial.test.js index 6350bf33d1..a4840094a8 100644 --- a/resources/web/dialog/SpeedDial/speeddial.test.js +++ b/resources/web/dialog/SpeedDial/speeddial.test.js @@ -495,6 +495,19 @@ assert.deepEqual(ctx.visibleFavourites(["b", "a", "b"], [{ id: "a" }, { id: "b" assert.deepEqual(ctx.visibleFavourites([], [{ id: "a" }]), [], "no pins renders an empty quick-bar"); assert.deepEqual(ctx.visibleFavourites(["a"], []), [], "a stale config with no actions renders nothing"); +// The bar C++ sends after a pin, an unpin or a reorder replaces the page's: an unpin can bring a pin past the +// tenth onto the bar. Rendering needs the DOM, which this test has not, so it is stubbed. +var renderBefore = ctx.render, favsBefore = ctx.FAVS; +ctx.render = function () {}; +ctx.FAVS = ["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9"]; +ctx.HandleStudio({ command: "favourites", favourites: ["p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11"] }); +assert.deepEqual(ctx.FAVS, ["p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11"], + "the bar C++ sends replaces the page's, a pin past the tenth promoted onto it"); +ctx.HandleStudio(JSON.stringify({ command: "favourites", favourites: [] })); +assert.deepEqual(ctx.FAVS, [], "an empty bar, sent as text, empties the page's"); +ctx.render = renderBefore; +ctx.FAVS = favsBefore; + // actionIcon: the SVG base name for a tile's pictogram, or "" when the action has none (blank tile). assert.equal(ctx.actionIcon({ id: "x", title: "Slice", icon: "media_play" }), "media_play", "an action's icon base name is returned verbatim"); @@ -604,6 +617,28 @@ assert.equal(ctx.stateFromPayload({ tooltip_expanded: true }).tooltipExpanded, t assert.equal(ctx.resultCountText(100, 3, "lay"), "Matching actions: 3", "a search reports the shown match count only"); assert.equal(ctx.resultCountText(100, 100, ""), "Actions: 100", "an empty query reports the total"); +// run_action: a pick sends the command's arguments as an object, none for a plain pick, and the value +// of the second phase for Go to layer and Go to tab. +var sent = []; +var actionsBefore = ctx.ACTIONS; +ctx.SendWXMessage = function (text) { sent.push(JSON.parse(text)); }; +ctx.ACTIONS = [{ id: "layer", title: "Go to layer", input: "percent" }, { id: "tab", title: "Go to tab...", input: "tab" }]; +function lastRun() { + var m = sent[sent.length - 1]; + return { command: m.command, id: m.id, title: m.title, args: m.args }; +} +ctx.run({ id: "undo", title: "Undo" }); +assert.deepStrictEqual(lastRun(), { command: "run_action", id: "undo", title: "Undo", args: {} }, "a plain pick sends no arguments"); +ctx.runJumpToLayer("50"); +assert.deepStrictEqual(lastRun(), { command: "run_action", id: "layer", title: "Go to layer", args: { percent: 50 } }, + "the percent phase sends the percent as a number"); +ctx.jumpToTab({ id: "preview", title: "Preview" }); +assert.deepStrictEqual(lastRun(), { command: "run_action", id: "tab", title: "Go to tab...", args: { tab: "preview" } }, + "the tab phase sends the tab's id"); +assert.equal(sent.length, 3, "each pick sends one message"); +delete ctx.SendWXMessage; +ctx.ACTIONS = actionsBefore; + // ---- hover preview commit timing --------------------------------------------------------- // The footer preview commits only after the pointer rests on a row, so a pointer crossing the rows // between a rested row and the footer must not preview them (style.css rows are 44px). The timing diff --git a/scripts/CAD/README.md b/scripts/CAD/README.md index dca226865d..44306d6519 100644 --- a/scripts/CAD/README.md +++ b/scripts/CAD/README.md @@ -8,7 +8,7 @@ other suite. ## Checks against a running app -Three checks drive the Design tab through the app's MCP server, with the same CAD tools an +Three checks drive the Design tab through the app's MCP server, with the same Design commands 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, which takes effect after a restart). @@ -46,9 +46,25 @@ compiled against it cannot drift apart: | Generator | Source | Output | |---|---|---| -| `gen_offer_table.py` | `tool_atlas.json` — every offer verb with its row, key, icon, accepted selections and refusal string | `src/slic3r/GUI/CAD/DesignOffer.hpp` | +| `gen_offer_table.py` | `tool_atlas.json` — the Design tab's table: every offer verb with its row, key, icon, accepted selections and refusal string, and every Design command's silent form (a `tool` block) | `src/slic3r/GUI/CAD/DesignOffer.hpp` | | `mate-glyph/emit_glyph_table.py` | `mate-glyph/bear_outline.json`, measured off `mate-glyph/bear.step` by `extract_outline.py` | the `kBear…` tables in `DesignSketchTool.cpp` | +The atlas's `verbs` are one table for three things: the right-click menu (a verb with a `slot` has a +row there), the Speed Dial's Design tiles and the Design commands. Every verb but `align` is a command +whose key is its `id`. A verb with an `action` does what its menu row does when called with no +arguments, in the mode the row belongs to, and has a tile; one with a `tool` block also runs silently +with arguments, and the block holds what that form takes and does: its `access` (`read`, `change` or +`sketch`, which decides what a busy Design tab lets through), `ok_false` (it reports a rejected rebuild +in its reply), a `summary` of one sentence, +`details`, its `params` (each with `name`, `type`, `unit`, `default`, limits `min`, `exclusive_min` and +`max`, `enum` and `description`; one with no default is required, and one whose default is null also takes +null, unless `nullable` is false, which marks a param whose function reads a null as given), one to three +`examples` and `ids` +(it takes or gives face and edge ids). Entries with no `slot` and no `action` are commands only, and +`modal` marks a verb whose action opens a dialog. `src/slic3r/GUI/Mcp/McpToolsCad.cpp` binds each block +to the function that runs it (`kSilentForms`), and a unit test fails when a block has no function or a +function no block. The generator refuses an entry with neither an action nor a block, but `align`. + `python3 scripts/CAD/gen_offer_table.py` rewrites the header and `--check` proves the checked-in one matches the atlas. The "Check CAD offer table" workflow (`.github/workflows/check_cad_offer_table.yml`) runs the check on every push and pull diff --git a/scripts/CAD/check-mcp-sketch.py b/scripts/CAD/check-mcp-sketch.py index 7b50c86d49..5ffbd2d5f3 100755 --- a/scripts/CAD/check-mcp-sketch.py +++ b/scripts/CAD/check-mcp-sketch.py @@ -4,7 +4,7 @@ assert the things that decide whether a profile is buildable. WHY THIS EXISTS. Every question about the 2D layer ("is this loop closed?", "did the offset survive?", "is the circle a void or a second body?"), asked by clicking, costs a GUI session and a -human. The CAD tools make each one a call, and this script is the loop: build a known profile, ask +human. The Design commands make each one a call, and this script is the loop: build a known profile, ask the app what it thinks it has, compare against arithmetic. RUN IT AGAINST A RUNNING APP started with --mcp and the CAD feature on, for example: @@ -29,7 +29,7 @@ APP = orca_mcp.OrcaMcp.from_datadir(DATADIR) def call(method, **params): - return APP.call_cad_tool(method, **params) + return APP.call_command(method, **params)["result"] def near(a, b, tol=1e-6): diff --git a/scripts/CAD/check-sketch-engine-corpus.py b/scripts/CAD/check-sketch-engine-corpus.py index 14a17780ec..a9f34cd5bb 100644 --- a/scripts/CAD/check-sketch-engine-corpus.py +++ b/scripts/CAD/check-sketch-engine-corpus.py @@ -60,7 +60,7 @@ def try_call(method, **params): def call(method, **params): - return APP.call_cad_tool(method, **params) + return APP.call_command(method, **params)["result"] # ── SVG → line segments ────────────────────────────────────────────────────── @@ -338,7 +338,7 @@ def grade(pdf, name, report): def grade_scale(pdf, name, report, budget): """Same exactness, on a profile of several hundred entities, and timed. - "Interactive" is measurable from here even though nothing is clicked: every CAD tool runs on + "Interactive" is measurable from here even though nothing is clicked: every Design command runs on the UI THREAD, so the window was not repainting for at most the time its reply takes. A round trip that stays inside the budget is a window that stayed responsive. """ diff --git a/scripts/CAD/check-sketch-engine.py b/scripts/CAD/check-sketch-engine.py index 97772633b3..31073e23ce 100755 --- a/scripts/CAD/check-sketch-engine.py +++ b/scripts/CAD/check-sketch-engine.py @@ -40,7 +40,7 @@ _fail = 0 def call(method, **params): - return APP.call_cad_tool(method, **params) + return APP.call_command(method, **params)["result"] def check(kind, cond, what): diff --git a/scripts/CAD/gen_offer_table.py b/scripts/CAD/gen_offer_table.py index 11d36469a8..3d8f0b664f 100644 --- a/scripts/CAD/gen_offer_table.py +++ b/scripts/CAD/gen_offer_table.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 -"""Emit the C++ offer table from scripts/CAD/tool_atlas.json. +"""Emit the Design tab's table from scripts/CAD/tool_atlas.json. python3 scripts/CAD/gen_offer_table.py # rewrite the header python3 scripts/CAD/gen_offer_table.py --check # verify the checked-in header -The map exists ONCE: the atlas is the only place a verb's row, key, icon and refusal -string are written down, so the menu the user sees cannot drift from the table the code -is compiled against. +The map exists ONCE: the atlas is the only place a verb's row, key, icon, refusal string and +Design command are written down, so the menu the user sees, the Speed Dial's Design tiles and the +commands automation calls cannot drift from the table the code is compiled against. Output: src/slic3r/GUI/CAD/DesignOffer.hpp, checked in and never hand-edited. """ @@ -30,6 +30,16 @@ ENUM = { "sk_line": "SkLine", "sk_arc": "SkArc", "sk_point": "SkPoint", "sk_2ent": "Sk2Ent", } +# a tool block's access -> CadAccess enumerator +ACCESS = {"read": "Read", "change": "Change", "sketch": "Sketch"} + +# The keys of a tool block that its command's description, schema and examples are made from. +DOC_KEYS = ("summary", "details", "params", "examples", "ids") + +# A doc is emitted as adjacent string literals of at most this many characters each, so every +# compiler takes it (MSVC refuses one literal over 16 KiB) and a change to it shows on its own line. +DOC_PIECE = 96 + def cstr(s): if s is None: @@ -48,25 +58,62 @@ def tstr_design(s): return "nullptr" if s is None else "L_CONTEXT(" + cstr(s) + ', "Design")' +def doc_text(block): + """A tool block's summary, details, params, examples and ids as compact JSON text.""" + return json.dumps({k: block[k] for k in DOC_KEYS}, ensure_ascii=False, separators=(",", ":")) + + +def doc_literal(block, indent): + if block is None: + return "nullptr" + text = doc_text(block) + pieces = [text[i:i + DOC_PIECE] for i in range(0, len(text), DOC_PIECE)] + return ("\n" + indent).join(cstr(p) for p in pieces) + + def validate(A): """Refuse an atlas the header cannot represent, naming every fault at once. An unknown slot or selection would surface as a bare ValueError from .index() below, and a - duplicate verb id would not surface at all: DesignPanel::mcp_run_verb looks a verb up by id - and takes the first match, so the second row would be unreachable from the offer. + duplicate verb id would not surface at all: a verb is looked up by id (DesignPanel::mcp_run_verb, + the catalog's command keys) and the first match taken, so the second row would be unreachable. + A row with neither an action nor a tool block would be a command that does nothing; only align, + which is in the menu greyed until it has a GUI path, is allowed to be one. """ slot_ids = {s["id"] for s in A["slots"]} sel_ids = {s["id"] for s in A["selections"]} errs, seen = [], set() for v in A["verbs"]: - if v["slot"] not in slot_ids: - errs.append(f'{v["id"]}: unknown slot {v["slot"]!r}') - for a in v["accepts"]: + vid = v["id"] + if v["slot"] is None: + # A command only: no menu row, so no action the menu could run either. + if v.get("action"): + errs.append(f"{vid}: an action needs a slot") + elif v["slot"] not in slot_ids: + errs.append(f'{vid}: unknown slot {v["slot"]!r}') + for a in v.get("accepts", []): if a not in sel_ids: - errs.append(f'{v["id"]}: accepts unknown selection {a!r}') - if v["id"] in seen: - errs.append(f'{v["id"]}: duplicate verb id') - seen.add(v["id"]) + errs.append(f"{vid}: accepts unknown selection {a!r}") + if vid in seen: + errs.append(f"{vid}: duplicate verb id") + seen.add(vid) + block = v.get("tool") + if not v.get("action") and block is None and vid != "align": + errs.append(f"{vid}: neither an action nor a tool block") + if v.get("modal") and not v.get("action"): + errs.append(f"{vid}: modal without an action") + if block is not None: + if block.get("access") not in ACCESS: + errs.append(f'{vid}: tool access {block.get("access")!r} is not one of {sorted(ACCESS)}') + missing = [k for k in DOC_KEYS + ("ok_false",) if k not in block] + if missing: + errs.append(f"{vid}: tool block lacks {missing}") + elif len(doc_text(block).encode("utf-8")) > 60000: + errs.append(f"{vid}: tool block over 60000 bytes") + # nullable false keeps a param's type from admitting null, which only a null default gives it. + for p in block.get("params", []): + if "nullable" in p and ("default" not in p or p["default"] is not None): + errs.append(f'{vid}: param {p.get("name")!r} has nullable but no null default') for s in sel_ids - set(ENUM): errs.append(f"selection {s!r} has no OfferSel enumerator") if errs: @@ -83,10 +130,13 @@ def main(): "// GENERATED FILE — DO NOT EDIT.", "// Source: scripts/CAD/tool_atlas.json Generator: scripts/CAD/gen_offer_table.py", "//", - "// The object-driven tool offer (charter 4.1): every verb has ONE row index, that index", - "// is the same in every selection it appears in, and verbs that do not apply are shown", - "// disabled in place with their reason rather than removed. Row order was ratified", - "// 2026-07-31; changing an index is a breaking change to every user's muscle memory.", + "// The Design tab's table. Its verbs are the object-driven tool offer (charter 4.1): every verb", + "// has ONE row index, that index is the same in every selection it appears in, and verbs that do", + "// not apply are shown disabled in place with their reason rather than removed. Row order was", + "// ratified 2026-07-31; changing an index is a breaking change to every user's muscle memory.", + "// Every entry but align is also a command of the catalog's group Design (Mcp::register_cad_commands()):", + "// called with no arguments, one with an action does what its menu row does; otherwise, and always for", + "// an entry with no action, it runs its tool block's silent form. An entry with no row is a command only.", "#ifndef slic3r_GUI_DesignOffer_hpp_", "#define slic3r_GUI_DesignOffer_hpp_", "", @@ -102,7 +152,7 @@ def main(): "namespace Slic3r { namespace GUI {", "", "// What the viewport has selected. Ordered as in tool_atlas.json; the bitmask in", - "// OfferVerb::accepts indexes these.", + "// DesignTool::accepts indexes these.", "enum class OfferSel : int {", ] for i, s in enumerate(sels): @@ -113,16 +163,33 @@ def main(): "", "inline uint32_t offer_bit(OfferSel s) { return 1u << int(s); }", "", - "// One row of the offer. `action` routes to the code that already implements the verb:", + "// The atlas's id of each selection, in OfferSel's order.", + "static const char* const kDesignSelectionIds[] = {", + ] + for s in sels: + lines.append(f" {cstr(s)},") + lines += [ + "};", + "", + "// What a Design command's silent form does to the document, which decides when the Design tab lets", + "// it run (DesignPanel::mcp_busy()). Read only looks, so it runs under anything but a rebuild. Sketch", + "// drives the live sketch session and Change edits the feature list or variables; both are refused under", + "// an open card, the Text dialog, Constrain mode or a body Move, and Change under a sketch session too,", + "// which is about to commit into the feature list. None: an entry with no silent form, and the opening", + "// of a tool, which only a rebuild refuses, as the Design tab's keys and menu do.", + "enum class CadAccess { None, Read, Change, Sketch };", + "", + "// One entry of the table. `action` routes to the code that already implements the verb:", '// "key:S+E" -> m_keys_feature[SHIFT(\'E\')]', '// "key:L" -> m_keys_sketch[\'L\']', '// "fly:material#4" -> row 4 of the "material" feature flyout', '// "btn:delete" -> a standalone toolbar button', - "// nullptr -> kernel support exists, no GUI path yet (row shows disabled)", - "struct OfferVerb {", - " const char* id;", + "// nullptr -> no GUI path (the row, if it has one, shows disabled)", + "struct DesignTool {", + " const char* id; // also the key of its Design command", " const char* name; // drawing-office word (L10); msgctxt \"Design\", translated at use", - " int row; // index into kOfferRowNames, the ratified address — NEVER reorder", + " int row; // index into kOfferRowNames, the ratified address — NEVER reorder;", + " // -1: no menu row, a command only", " const char* key; // shortcut shown in the row, or nullptr", " const char* action;", " const char* refusal; // why this row is greyed, in the product's own words", @@ -138,6 +205,13 @@ def main(): " const char* family;", " const char* icon; // resources/images name, or nullptr — the offer draws it beside the row", " const char* hint; // what the verb does / what to click; shown on hover", + " bool modal; // its action opens a dialog that waits for an answer: a modal one, which holds", + " // the call until it is answered, or Text's, which is modeless and does not", + " CadAccess access; // its silent form's, None without one", + " bool ok_false; // its silent form reports a rejected rebuild in its reply (ok false)", + " // Its silent form's summary, details, params, examples and ids as JSON text, the parameter", + " // schema of record; nullptr for an entry whose command only does what its row does.", + " const char* doc;", "};", "", "// Row labels, in ratified order.", @@ -158,7 +232,7 @@ def main(): lines += [ "};", "", - "static const OfferVerb kOfferVerbs[] = {", + "static const DesignTool kDesignTools[] = {", ] # A verb the user can PICK must say what it does. Fail loudly rather than ship a # bare name — the offer is now the only door to these tools. @@ -173,20 +247,33 @@ def main(): for ln in ([v["note"]] if isinstance(v.get("note"), str) else v.get("note") or []): lines.append(f" // {ln}") mask = 0 - for a in v["accepts"]: + for a in v.get("accepts", []): mask |= 1 << sels.index(a) n = v.get("needs") or {} + block = v.get("tool") + in_menu = v["slot"] is not None + # Every name is marked, an entry's with no row too: it is its command's title, which a person + # sees translated in the Design context in the Action Replay window and a recording's caption, + # and on the tile of an entry with a row. A table with an unmarked name is refused, written or + # checked, since nothing at run time can tell (L_CONTEXT compiles to the bare string). + name = tstr_design(v["name"]) + if not (name.startswith('L_CONTEXT("') and name.endswith('", "Design")')): + sys.exit(f'entry {v["id"]}: its name is not marked for translation in the Design context: {name}') lines.append( - " {%s, %s, %d, %s, %s, %s, 0x%08xu, %d, %d, %s, %s, %s, %s, %s}," % ( - cstr(v["id"]), tstr_design(v["name"]), slots.index(v["slot"]), + " {%s, %s, %d, %s, %s, %s, 0x%08xu, %d, %d, %s, %s, %s, %s, %s, %s, CadAccess::%s, %s,\n %s}," % ( + cstr(v["id"]), name, slots.index(v["slot"]) if in_menu else -1, cstr(v.get("key")), cstr(v.get("action")), tstr(v.get("refusal")), mask, n.get("bodies", 0), n.get("sketches", 0), "true" if n.get("sheet") else "false", "true" if v.get("mode") == "sketch" else "false", - tstr_design(v.get("family")), cstr(v.get("icon")), tstr(v.get("hint")))) + tstr_design(v.get("family")), cstr(v.get("icon")), tstr(v.get("hint")), + "true" if v.get("modal") else "false", + ACCESS[block["access"]] if block else "None", + "true" if block and block["ok_false"] else "false", + doc_literal(block, " "))) lines += [ "};", - f"static const int kOfferVerbCount = {len(A['verbs'])};", + f"static const int kDesignToolCount = {len(A['verbs'])};", "", "}} // namespace Slic3r::GUI", "", @@ -209,11 +296,13 @@ def main(): print(f"{os.path.relpath(OUT, REPO)} DIFFERS from tool_atlas.json:") print("\n".join(d[:60])) return 1 - with open(OUT, "w", encoding="utf-8") as f: + with open(OUT, "w", encoding="utf-8", newline="\n") as f: f.write(text) + in_menu = [v for v in A["verbs"] if v["slot"] is not None] wired = sum(1 for v in A["verbs"] if v.get("action")) - print(f"wrote {os.path.relpath(OUT, REPO)}: {len(A['verbs'])} verbs, " - f"{len(slots)} rows, {wired} wired to existing actions") + blocks = sum(1 for v in A["verbs"] if v.get("tool")) + print(f"wrote {os.path.relpath(OUT, REPO)}: {len(A['verbs'])} entries, {len(in_menu)} in " + f"{len(slots)} rows, {wired} wired to existing actions, {blocks} with a silent form") return 0 diff --git a/scripts/CAD/tool_atlas.json b/scripts/CAD/tool_atlas.json index a5acfbf497..f247a534a0 100644 --- a/scripts/CAD/tool_atlas.json +++ b/scripts/CAD/tool_atlas.json @@ -1,12 +1,14 @@ { "_comment": [ - "Source of truth for the object-driven tool offer (see docs/HLSD/design-tab.md).", + "Source of truth for the Design tab's table: the object-driven tool offer, its Speed Dial tiles and its", + "commands (see docs/HLSD/design-tab.md).", "Every verb, the selections it accepts, the document state it needs, and its fixed", "compass address. Extracted from the code, not from memory:", " verbs + shortcuts + refusal messages -> src/slic3r/GUI/CAD/DesignPanel.cpp (feat_dropdown", " call sites at 524/662/734/790/874/904, sk_key table at 369-400, m_keys_feature)", " kernel coverage -> src/libslic3r/CAD/CadDocument.hpp (enum CadFeatureType)", - " headless coverage -> src/slic3r/GUI/Mcp/McpToolsCad.cpp (the CAD tool table)", + " Design commands -> a verb's `tool` block, and the entries with no slot (commands only):", + " the silent form's access, params and examples; McpToolsCad.cpp binds each block to its function", " selection kinds -> src/slic3r/GUI/CAD/DesignCanvas.hpp (the on_*_selected callbacks)", "gen_offer_table.py emits src/slic3r/GUI/CAD/DesignOffer.hpp from this file, so the map", "exists once. Edit the atlas and regenerate; never hand-edit the header." @@ -222,7 +224,6 @@ "slot": "create", "key": "Shift+S", "feature": "Sketch", - "mcp": null, "accepts": [ "face_planar", "datum_plane", @@ -241,7 +242,6 @@ "slot": "add", "key": "Shift+E", "feature": "Extrude", - "mcp": "extrude", "accepts": [ "sk_loop", "face_planar" @@ -251,7 +251,57 @@ "gui": true, "action": "key:S+E", "icon": "design_extrude", - "hint": "Extrude a sketch profile, or push/pull a picked face" + "hint": "Extrude a sketch profile, or push/pull a picked face", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Extrude a committed sketch, one of its loops, a face or a drawn profile into a body.", + "details": "A committed sketch, or one loop of it, extrudes as the Extrude card does; push/pull grows a planar face of a body; a profile drawn here is an explicit closed `profile` (list of [x,y]) or a centred width x height rectangle on `plane`. End conditions match Onshape. Reply: extrude_index, the index of its sketch (-1 for a face), the boolean and body used, end, frame.", + "params": [ + {"name": "sketch", "type": "integer", "default": null, "description": "a committed Sketch feature to extrude (sketch_commit's sketch_index); profile, width, height and plane are then refused"}, + {"name": "loop", "type": "integer", "default": null, "description": "with sketch: one closed loop (closed_loops[].index of sketch_describe {sketch}) with the loops inside it as holes; a hole is a loop of its own, so its index extrudes the disc. Omit for the whole sketch"}, + {"name": "face", "type": "integer", "default": null, "description": "push/pull: a planar face (query_topology id) of `body` grown along its outward normal (flip for inward); boolean auto joins that body. sketch, loop, profile, width, height, plane and taper are then refused, and end is blind or symmetric"}, + {"name": "width", "type": "number", "unit": "mm", "default": 20}, + {"name": "height", "type": "number", "unit": "mm", "default": 20}, + {"name": "distance", "type": "number", "unit": "mm", "default": 10, "exclusive_min": 0}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."}, + {"name": "profile", "type": "array", "default": [], "description": "optional closed contour [[x,y],...] in plane mm; overrides width/height"}, + {"name": "boolean", "type": "string", "default": null, "enum": ["auto", "new", "union", "subtract", "intersect"], "description": "auto joins the body the profile touches, else makes a new body, as the card's default; default auto with sketch, new without"}, + {"name": "body", "type": "integer", "default": -1, "description": "the body to join, subtract from or intersect, or whose face is pushed; omit for the body a sketch touches, else the last body"}, + {"name": "end", "type": "string", "default": "blind", "enum": ["blind", "symmetric", "two_sided", "through_all", "up_to_face"]}, + {"name": "distance2", "type": "number", "unit": "mm", "default": 0, "description": "second-side depth when end=two_sided (else falls back to distance)"}, + {"name": "up_to_face", "type": "integer", "default": -1, "description": "face id (query_topology) of the body the extrude works on, when end=up_to_face"}, + {"name": "taper", "type": "number", "unit": "deg", "default": 0, "description": "draft/taper of the side wall"}, + {"name": "flip", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "A 20 x 20 x 5 mm plate on the XY plane", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}} + ] + }, + { + "title": "A committed sketch extruded 5 mm: a rectangle around a circle makes a plate with a bore", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "extrude", "args": {"distance": 5, "sketch": 0}} + ] + }, + { + "title": "A plate's top face pushed up 3 mm", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "extrude", "args": {"body": 0, "distance": 3, "face": 5, "generation": {"from_call": 1, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "revolve", @@ -259,7 +309,6 @@ "slot": "add", "key": "Shift+R", "feature": "Revolve", - "mcp": "revolve", "accepts": [ "sk_loop" ], @@ -268,7 +317,45 @@ "gui": true, "action": "key:S+R", "icon": "design_revolve", - "hint": "Revolve a profile about an axis" + "hint": "Revolve a profile about an axis", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Revolve a committed sketch as the Revolve card does, or a profile drawn here, about an axis.", + "details": "A sketch turns about a line of it or a plane axis; a profile drawn here is an explicit `profile` offset from the axis, or a width x height rectangle with one edge on the axis, centred along it, so a full turn is a cylinder width long of radius height. Reply: revolve_index, the index of its sketch, the boolean, body and axis used, frame.", + "params": [ + {"name": "sketch", "type": "integer", "default": null, "description": "a committed Sketch feature to revolve (sketch_commit's sketch_index); profile, width, height and plane are then refused"}, + {"name": "axis_entity", "type": "integer", "default": null, "description": "with sketch: a line of the sketch (entity index) as the axis, or -1 for the plane axis; omit for the sketch's only centerline (construction line) when it has one and axis is not given"}, + {"name": "width", "type": "number", "unit": "mm", "default": 20, "description": "without sketch or profile: the rectangle's length along the axis"}, + {"name": "height", "type": "number", "unit": "mm", "default": 10, "description": "without sketch or profile: how far the rectangle reaches out from the axis, the solid's radius"}, + {"name": "angle", "type": "number", "unit": "deg", "default": 360}, + {"name": "axis", "type": "integer", "default": 0, "enum": [0, 1], "description": "the plane's X (0) or Y (1) axis through its origin"}, + {"name": "flip", "type": "boolean", "default": false}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."}, + {"name": "profile", "type": "array", "default": [], "description": "optional closed contour [[x,y],...] in plane mm; overrides width/height"}, + {"name": "boolean", "type": "string", "default": "new", "enum": ["new", "union", "subtract", "intersect"]}, + {"name": "body", "type": "integer", "default": -1, "description": "the body to join, subtract from or intersect; omit for the last body"} + ], + "examples": [ + { + "title": "A ring: a profile 10 to 15 mm out from the XZ plane's vertical axis, turned a full circle", + "calls": [ + {"tool": "revolve", "args": {"axis": 1, "plane": "XZ", "profile": [[10, 0], [15, 0], [15, 10], [10, 10]]}} + ] + }, + { + "title": "A committed sketch turned about its centerline, a construction line", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "sketch_add", "args": {"rect": [10, 0, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"construction": true, "p0": [0, 0], "p1": [0, 10], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "revolve", "args": {"sketch": 0}} + ] + } + ], + "ids": true + } }, { "id": "sweep", @@ -276,7 +363,6 @@ "slot": "add", "key": "Shift+W", "feature": "Sweep", - "mcp": null, "accepts": [ "sk_loop" ], @@ -287,7 +373,44 @@ "gui": true, "action": "key:S+W", "icon": "design_sweep", - "hint": "Sweep a profile along a path" + "hint": "Sweep a profile along a path", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Sweep a committed sketch's closed profile along a path, a sketch or a helix, as the Sweep card does.", + "details": "Draw the profile across the path's start (a helix's start and tangent are in its reply); along a helix the profile keeps its angle to the helix axis. Long sweeps take seconds and the reply may be a job. Reply: sweep_index, bodies, boolean, body.", + "params": [ + {"name": "sketch", "type": "integer", "description": "the profile: a committed sketch's feature index"}, + {"name": "path", "type": "integer", "description": "feature index of a sketch or a helix, other than the profile"}, + {"name": "boolean", "type": "string", "default": "new", "enum": ["new", "union", "subtract", "intersect"]}, + {"name": "body", "type": "integer", "default": -1, "description": "the body a union, subtract or intersect works on; omit for the last body"} + ], + "examples": [ + { + "title": "A spring: a 2 mm circle across a helix's start, swept along it", + "calls": [ + {"tool": "helix", "args": {"height": 20, "pitch": 5, "radius": 10}}, + {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [10, 0], "radius": 1, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sweep", "args": {"path": 0, "sketch": 1}} + ] + }, + { + "title": "A 6 mm rod swept along a 40 mm line", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [0, 40], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 3, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sweep", "args": {"path": 0, "sketch": 1}} + ] + } + ], + "ids": false + } }, { "id": "loft", @@ -295,7 +418,6 @@ "slot": "add", "key": "Shift+L", "feature": "Loft", - "mcp": null, "accepts": [ "sk_loop" ], @@ -306,7 +428,35 @@ "gui": true, "action": "key:S+L", "icon": "design_loft", - "hint": "Loft (skin) between two or more profiles" + "hint": "Loft (skin) between two or more profiles", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Loft a solid through two or more committed sketches, in order, as the Loft card does.", + "details": "Each sketch is on its own plane (sketch on datum planes). Lofts take seconds and the reply may be a job. Reply: loft_index, bodies, boolean, body.", + "params": [ + {"name": "profiles", "type": "array", "description": "sketch feature indices, in loft order"}, + {"name": "ruled", "type": "boolean", "default": false, "description": "straight sections between the profiles instead of a smooth skin"}, + {"name": "boolean", "type": "string", "default": "new", "enum": ["new", "union", "subtract", "intersect"]}, + {"name": "body", "type": "integer", "default": -1, "description": "the body a union, subtract or intersect works on; omit for the last body"} + ], + "examples": [ + { + "title": "A square-to-round transition 20 mm tall, the circle sketched on a datum plane", + "calls": [ + {"tool": "plane", "args": {"base": "XY", "offset": 20, "type": "offset"}}, + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-10, -10, 10, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 6, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "loft", "args": {"profiles": [1, 2]}} + ] + } + ], + "ids": false + } }, { "id": "thicken", @@ -314,7 +464,6 @@ "slot": "add", "key": null, "feature": "Thicken", - "mcp": "thicken", "accepts": [ "face_planar", "face_other" @@ -326,7 +475,30 @@ "gui": true, "action": "fly:material#4", "icon": "design_thicken", - "hint": "Offset a solid face into a thin plate (new body)" + "hint": "Offset a solid face into a thin plate (new body)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Offset a face of a body by a wall thickness, producing a new thin solid body.", + "details": "", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"}, + {"name": "face", "type": "integer", "description": "face id to thicken (query_topology)"}, + {"name": "thickness", "type": "number", "unit": "mm", "default": 2}, + {"name": "flip", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "A 2 mm skin grown from a plate's top face as a new body", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "thicken", "args": {"body": 0, "face": 5, "generation": {"from_call": 1, "key": "generation"}, "thickness": 2}} + ] + } + ], + "ids": true + } }, { "id": "rib", @@ -334,7 +506,6 @@ "slot": "add", "key": "R", "feature": "Rib", - "mcp": "rib", "accepts": [ "sk_line" ], @@ -345,7 +516,34 @@ "gui": true, "action": "fly:material#5", "icon": "design_rib", - "hint": "Grow a thin wall from an open sketch line, fused to a body" + "hint": "Grow a thin wall from an open sketch line, fused to a body", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Grow a thin rib wall (stiffener) from an open Line sketch entity, fused to a body.", + "details": "The wall is centred on the line in the sketch plane, thickness wide, and grows depth along the sketch plane's normal.", + "params": [ + {"name": "sketch", "type": "integer", "description": "sketch feature index holding the open line"}, + {"name": "entity", "type": "integer", "description": "entity index of the open Line within the sketch"}, + {"name": "thickness", "type": "number", "unit": "mm", "default": 2}, + {"name": "depth", "type": "number", "unit": "mm", "default": 10, "description": "along the sketch plane's normal, or against it when negative"}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "A 2 mm rib 8 mm tall across a plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 3, "height": 20, "width": 40}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "sketch_begin", "args": {"generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [-15, 0], "p1": [15, 0], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "rib", "args": {"depth": 8, "entity": 0, "sketch": 2, "thickness": 2}} + ] + } + ], + "ids": false + } }, { "id": "boolean", @@ -353,7 +551,6 @@ "slot": "add", "key": "Shift+B", "feature": "Boolean", - "mcp": "boolean", "accepts": [ "bodies_2" ], @@ -364,7 +561,39 @@ "gui": true, "action": "btn:bool#0", "icon": "design_boolean", - "hint": "Fuse the tool body into the target — one solid, no seam" + "hint": "Fuse the tool body into the target — one solid, no seam", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Combine two bodies: union | subtract (tool from target) | intersect.", + "details": "", + "params": [ + {"name": "op", "type": "string", "default": "subtract", "enum": ["union", "subtract", "intersect"]}, + {"name": "target", "type": "integer", "default": 0}, + {"name": "tool", "type": "integer", "default": 1}, + {"name": "keep_tool", "type": "boolean", "default": false}, + {"name": "tolerance", "type": "number", "unit": "mm", "default": 0} + ], + "examples": [ + { + "title": "A post subtracted from a block", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 20, "height": 6, "width": 6}}, + {"tool": "boolean", "args": {"op": "subtract", "target": 0, "tool": 1}} + ] + }, + { + "title": "Two overlapping blocks joined into one body", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[5, -5], [20, -5], [20, 5], [5, 5]]}}, + {"tool": "boolean", "args": {"op": "union", "target": 0, "tool": 1}} + ] + } + ], + "ids": false + } }, { "id": "bool_subtract", @@ -372,7 +601,6 @@ "slot": "add", "key": null, "feature": "Boolean", - "mcp": null, "accepts": [ "bodies_2" ], @@ -392,7 +620,6 @@ "slot": "add", "key": null, "feature": "Boolean", - "mcp": null, "accepts": [ "bodies_2" ], @@ -412,7 +639,6 @@ "slot": "add", "key": "Shift+G", "feature": "SurfaceExtrude", - "mcp": "surface_extrude", "accepts": [ "sk_loop" ], @@ -421,7 +647,38 @@ "gui": true, "action": "key:S+G", "icon": "design_extrude", - "hint": "Extrude a sketch into a sheet body (no end caps)" + "hint": "Extrude a sketch into a sheet body (no end caps)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Extrude a sketch wire with no end caps -> an open sheet body.", + "details": "", + "params": [ + {"name": "sketch", "type": "integer", "description": "sketch feature index"}, + {"name": "distance", "type": "number", "unit": "mm", "default": 10, "description": "along the sketch plane's normal, or against it when negative"} + ], + "examples": [ + { + "title": "A 30 mm line extruded 10 mm into a flat sheet", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [-15, 0], "p1": [15, 0], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_extrude", "args": {"distance": 10, "sketch": 0}} + ] + }, + { + "title": "A circle extruded 20 mm into an open tube, with no end caps", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 10, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_extrude", "args": {"distance": 20, "sketch": 0}} + ] + } + ], + "ids": false + } }, { "id": "surf_revolve", @@ -429,7 +686,6 @@ "slot": "add", "key": null, "feature": "SurfaceRevolve", - "mcp": "surface_revolve", "accepts": [ "sk_loop" ], @@ -438,7 +694,39 @@ "gui": true, "action": "fly:surface#1", "icon": "design_revolve", - "hint": "Revolve a sketch profile into a sheet body" + "hint": "Revolve a sketch profile into a sheet body", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Revolve a sketch wire with no caps -> an open sheet body.", + "details": "", + "params": [ + {"name": "sketch", "type": "integer", "description": "sketch feature index"}, + {"name": "angle", "type": "number", "unit": "deg", "default": 360}, + {"name": "axis", "type": "integer", "default": 0, "enum": [0, 1], "description": "the sketch plane's X (0) or Y (1) axis through its origin"} + ], + "examples": [ + { + "title": "A cylinder's wall: a line 10 mm out from the XZ plane's vertical axis, turned a full circle", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [10, 0], "p1": [10, 20], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_revolve", "args": {"axis": 1, "sketch": 0}} + ] + }, + { + "title": "Half a truncated cone's wall: a sloping line turned 180 degrees about the XZ plane's vertical axis", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [5, 0], "p1": [15, 20], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_revolve", "args": {"angle": 180, "axis": 1, "sketch": 0}} + ] + } + ], + "ids": false + } }, { "id": "surf_loft", @@ -446,7 +734,6 @@ "slot": "add", "key": null, "feature": "SurfaceLoft", - "mcp": "surface_loft", "accepts": [ "sk_loop" ], @@ -457,7 +744,33 @@ "gui": true, "action": "fly:surface#2", "icon": "design_loft", - "hint": "Loft (skin) between 2+ profiles, open (no end caps)" + "hint": "Loft (skin) between 2+ profiles, open (no end caps)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Skin two or more profile sketches with no end caps -> an open sheet body.", + "details": "", + "params": [ + {"name": "profiles", "type": "array", "description": "sketch feature indices, in order"}, + {"name": "ruled", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "An open funnel skinned from a circle on XY to a wider one on a datum plane 20 mm up", + "calls": [ + {"tool": "plane", "args": {"base": "XY", "offset": 20, "type": "offset"}}, + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 5, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 15, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_loft", "args": {"profiles": [1, 2]}} + ] + } + ], + "ids": false + } }, { "id": "surf_fill", @@ -465,7 +778,6 @@ "slot": "add", "key": null, "feature": "SurfaceFill", - "mcp": "surface_fill", "accepts": [ "sk_loop" ], @@ -474,7 +786,37 @@ "gui": true, "action": "fly:surface#3", "icon": "design_surface", - "hint": "Fill a sketch boundary with a smooth face" + "hint": "Fill a sketch boundary with a smooth face", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Fill a sketch's closed boundary with one smooth face -> a sheet body.", + "details": "", + "params": [ + {"name": "sketch", "type": "integer", "description": "sketch feature index"} + ], + "examples": [ + { + "title": "A circle filled with a disc-shaped sheet", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 10, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_fill", "args": {"sketch": 0}} + ] + }, + { + "title": "A rectangle filled with a flat sheet", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_fill", "args": {"sketch": 0}} + ] + } + ], + "ids": false + } }, { "id": "thicken_surf", @@ -482,7 +824,6 @@ "slot": "add", "key": null, "feature": "ThickenSurface", - "mcp": "thicken_surface", "accepts": [ "body_sheet" ], @@ -493,7 +834,41 @@ "gui": true, "action": "fly:surface#5", "icon": "design_thicken", - "hint": "Thicken a sheet body into a solid" + "hint": "Thicken a sheet body into a solid", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Thicken a whole sheet body into a solid.", + "details": "A sheet of several faces whose free rims close into planar loops (the walls of a box with no lids) is capped at them and grows inward, into the closed shape that makes, whatever flip says; one whose rim can't be capped is refused. A single face or a closed shell is offset face by face along each face's normal, the one query_topology gives, or against it with flip; a closed shell can fail to thicken this way.", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "sheet body; omit for the last body"}, + {"name": "thickness", "type": "number", "unit": "mm", "default": 2}, + {"name": "flip", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "A 30 x 20 mm sheet thickened into a 2 mm plate, a new body", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_fill", "args": {"sketch": 0}}, + {"tool": "thicken_surf", "args": {"thickness": 2}} + ] + }, + { + "title": "An open tube thickened 1.5 mm outward into a pipe: flip, as its normal points inward", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 10, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_extrude", "args": {"distance": 20, "sketch": 0}}, + {"tool": "thicken_surf", "args": {"body": 0, "flip": true, "thickness": 1.5}} + ] + } + ], + "ids": false + } }, { "id": "hole", @@ -501,7 +876,6 @@ "slot": "remove", "key": "Shift+H", "feature": "Hole", - "mcp": "hole", "accepts": [ "face_planar", "datum_plane" @@ -513,7 +887,41 @@ "gui": true, "action": "key:S+H", "icon": "design_hole", - "hint": "Drill a hole, centered on a picked face or placed on a plane" + "hint": "Drill a hole, centered on a picked face or placed on a plane", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Drill a circular hole at (x,y) or `at` on a plane.", + "details": "Reply: hole_index, body, x and y in the frame, off_plane with at, frame.", + "params": [ + {"name": "diameter", "type": "number", "unit": "mm", "default": 5, "exclusive_min": 0}, + {"name": "depth", "type": "number", "unit": "mm", "default": 10}, + {"name": "through", "type": "boolean", "default": false}, + {"name": "x", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "y", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes."}, + {"name": "at", "type": "array|object", "default": null, "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}, + {"name": "body", "type": "integer", "default": -1, "description": "the body to drill; omit for a face plane's body, else the last body"} + ], + "examples": [ + { + "title": "A 5 mm hole through the middle of a plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}} + ] + }, + { + "title": "A 4 mm hole 3 mm deep into a plate's top face, 5 mm off centre", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "hole", "args": {"depth": 3, "diameter": 4, "generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}, "x": 5}} + ] + } + ], + "ids": true + } }, { "id": "thread", @@ -521,7 +929,6 @@ "slot": "remove", "key": "Shift+T", "feature": "Thread", - "mcp": null, "accepts": [ "face_cyl", "edge_circ" @@ -533,7 +940,57 @@ "gui": true, "action": "key:S+T", "icon": "design_thread", - "hint": "Thread a cylindrical surface (inner bore / outer) or a circular edge" + "hint": "Thread a cylindrical surface (inner bore / outer) or a circular edge", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Cut a thread as the Thread card does, along a cylindrical face or a circular edge, or on a plane.", + "details": "On a face a bore is tapped, a boss threaded; on a plane the thread goes at (x,y) or `at`. Without designation, a face or edge takes the nearest standard size, ISO metric and UTS alike. Long threads take seconds and the reply may be a job. Reply: thread_index, designation (null when custom), internal, diameter, pitch, depth, length, body, x, y, frame.", + "params": [ + {"name": "face", "type": "integer", "default": null, "description": "a cylindrical face id of `body` (query_topology); the thread runs its length from its lower end"}, + {"name": "edge", "type": "integer", "default": null, "description": "instead of face: a circular edge id of `body`, the thread rising along its normal; needs length"}, + {"name": "body", "type": "integer", "default": -1, "description": "the body of face or edge, or the body threaded on a plane; omit for the last body (on a plane, a face plane's body)"}, + {"name": "designation", "type": "string", "default": null, "description": "e.g. M5, M8x1, 1/4-20 UNC: sets diameter, pitch and depth"}, + {"name": "internal", "type": "boolean", "default": null, "description": "true taps a hole, false threads a rod; required on a plane, else from the face (a bore is internal), external for an edge"}, + {"name": "diameter", "type": "number", "unit": "mm", "default": null, "description": "nominal (major) diameter, replacing the standard's; with pitch, a custom thread"}, + {"name": "pitch", "type": "number", "unit": "mm", "default": null, "description": "replaces the standard's"}, + {"name": "depth", "type": "number", "unit": "mm", "default": null, "description": "radial depth; default the 60 degree V's for the pitch and role"}, + {"name": "length", "type": "number", "unit": "mm", "default": null, "description": "default the face's length; required for an edge or a plane"}, + {"name": "plane", "type": "string|object", "default": null, "nullable": false, "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes."}, + {"name": "x", "type": "number", "unit": "mm", "default": 0, "description": "on a plane: offset in the plane's frame from its origin, NOT world"}, + {"name": "y", "type": "number", "unit": "mm", "default": 0, "description": "on a plane: offset in the plane's frame from its origin, NOT world"}, + {"name": "at", "type": "array|object", "default": null, "description": "on a plane, instead of x and y: a world point [x, y, z], or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the thread shares, as hole takes it"} + ], + "examples": [ + { + "title": "An M8 thread tapped into a 6.8 mm hole through a block", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 6.8, "through": true}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, + {"tool": "thread", "args": {"body": 0, "designation": "M8", "face": 6, "generation": {"from_call": 2, "key": "generation"}}} + ] + }, + { + "title": "An M6 threaded rod 10 mm long, standing on the XY plane", + "calls": [ + {"tool": "thread", "args": {"designation": "M6", "internal": false, "length": 10, "plane": "XY"}} + ] + }, + { + "title": "A 10 mm boss threaded at the nearest standard size, which the reply's designation names", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 5, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "extrude", "args": {"distance": 12, "sketch": 0}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, + {"tool": "thread", "args": {"body": 0, "face": 0, "generation": {"from_call": 4, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "shell", @@ -541,7 +998,6 @@ "slot": "remove", "key": "Shift+K", "feature": "Shell", - "mcp": "shell", "accepts": [ "face_planar", "body_solid" @@ -553,7 +1009,36 @@ "gui": true, "action": "key:S+K", "icon": "design_shell", - "hint": "Hollow the body to a wall thickness, opening a picked face" + "hint": "Hollow the body to a wall thickness, opening a picked face", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Hollow a body to a wall thickness (inward); optionally leave one face open.", + "details": "", + "params": [ + {"name": "thickness", "type": "number", "unit": "mm", "default": 1, "exclusive_min": 0}, + {"name": "face", "type": "integer", "default": -1, "description": "face id to leave open (query_topology); omit for a closed hollow"}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "A 20 x 20 x 10 mm box hollowed to 1.5 mm walls, open at the top", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "shell", "args": {"body": 0, "face": 5, "generation": {"from_call": 1, "key": "generation"}, "thickness": 1.5}} + ] + }, + { + "title": "A block hollowed to closed 2 mm walls", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "shell", "args": {"thickness": 2}} + ] + } + ], + "ids": true + } }, { "id": "cut", @@ -561,7 +1046,6 @@ "slot": "remove", "key": "Shift+X", "feature": "Cut", - "mcp": null, "accepts": [ "body_solid", "datum_plane", @@ -587,7 +1071,6 @@ "slot": "remove", "key": null, "feature": "Cut", - "mcp": "split", "accepts": [ "body_solid", "face_planar", @@ -604,7 +1087,49 @@ "gui": false, "action": null, "icon": null, - "hint": "Split the body along a picked face into two solids" + "hint": "Split the body along a picked face into two solids", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Split a body with a plane, as the Cut card does, moved by offset and turned over by flip; or along the plane of a face.", + "details": "The upper piece is on the plane's normal side; keeping both makes two bodies, the lower one right after the upper. Reply: split_index, bodies, body, upper_body and lower_body (the pieces kept), frame (a plane's, after offset and flip).", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"}, + {"name": "plane", "type": "string|object", "default": null, "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."}, + {"name": "offset", "type": "number", "unit": "mm", "default": 0, "description": "with plane: along its normal"}, + {"name": "flip", "type": "boolean", "default": false, "description": "with plane: turn it over, swapping upper and lower"}, + {"name": "face", "type": "integer", "default": null, "description": "instead of plane: a face id (query_topology) to split along"}, + {"name": "face_body", "type": "integer", "default": -1, "description": "with face: the body that owns it; -1 = target"}, + {"name": "keep_upper", "type": "boolean", "default": true}, + {"name": "keep_lower", "type": "boolean", "default": true} + ], + "examples": [ + { + "title": "A block cut in two at half its height", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "split", "args": {"offset": 5, "plane": "XY"}} + ] + }, + { + "title": "A block cut at half its height, keeping only the lower half", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "split", "args": {"keep_upper": false, "offset": 5, "plane": "XY"}} + ] + }, + { + "title": "A block split along the top face of a wider plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 4, "height": 30, "width": 30}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 1}}, + {"tool": "split", "args": {"body": 0, "face": 5, "face_body": 1, "generation": {"from_call": 2, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "fillet", @@ -612,7 +1137,6 @@ "slot": "dressup", "key": "Shift+F", "feature": "Fillet", - "mcp": "fillet", "accepts": [ "edge_str", "edge_circ", @@ -626,7 +1150,37 @@ "gui": true, "action": "btn:dress#0", "icon": "design_filletedge", - "hint": "Pick an edge, then drag the radius arrow or type it" + "hint": "Pick an edge, then drag the radius arrow or type it", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Round measured edges of a body (edge ids from query_topology on that body).", + "details": "", + "params": [ + {"name": "edge", "type": "integer|array", "description": "one edge id, or an array of ids rounded together in one feature"}, + {"name": "radius", "type": "number", "unit": "mm", "default": 1, "exclusive_min": 0}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body. edge id is resolved against THIS body."} + ], + "examples": [ + { + "title": "A plate's four vertical corners rounded to 2 mm", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0, "convex": true, "direction": [0, 0, 1], "edge_kinds": ["line"]}}, + {"tool": "fillet", "args": {"body": 0, "edge": [0, 1, 4, 7], "generation": {"from_call": 1, "key": "generation"}, "radius": 2}} + ] + }, + { + "title": "One top edge of a plate rounded to 1 mm", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"adjacency": true, "at_extreme": "+z", "body": 0}}, + {"tool": "fillet", "args": {"body": 0, "edge": 3, "generation": {"from_call": 1, "key": "generation"}, "radius": 1}} + ] + } + ], + "ids": true + } }, { "id": "chamfer", @@ -634,7 +1188,6 @@ "slot": "dressup", "key": null, "feature": "Chamfer", - "mcp": "chamfer", "accepts": [ "edge_str", "edge_circ", @@ -648,7 +1201,29 @@ "gui": true, "action": "btn:dress#1", "icon": "design_chamfer", - "hint": "Pick an edge, then drag the distance arrow or type it" + "hint": "Pick an edge, then drag the distance arrow or type it", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Chamfer measured edges of a body (edge ids from query_topology on that body).", + "details": "", + "params": [ + {"name": "edge", "type": "integer|array", "description": "one edge id, or an array of ids chamfered together in one feature"}, + {"name": "distance", "type": "number", "unit": "mm", "default": 1, "exclusive_min": 0}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body. edge id is resolved against THIS body."} + ], + "examples": [ + { + "title": "A plate's top edges chamfered 1 mm", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"adjacency": true, "at_extreme": "+z", "body": 0}}, + {"tool": "chamfer", "args": {"body": 0, "distance": 1, "edge": [3, 6, 9, 11], "generation": {"from_call": 1, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "draft", @@ -656,7 +1231,6 @@ "slot": "dressup", "key": "Shift+D", "feature": "Draft", - "mcp": "draft", "accepts": [ "face_planar", "face_other" @@ -668,7 +1242,29 @@ "gui": true, "action": "key:S+D", "icon": "design_draft", - "hint": "Tilt a picked face by a draft angle" + "hint": "Tilt a picked face by a draft angle", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Taper a body face by an angle about its base (pull direction +Z).", + "details": "", + "params": [ + {"name": "face", "type": "integer", "description": "face id to draft (query_topology)"}, + {"name": "angle", "type": "number", "unit": "deg", "default": 5}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "A block's +X side tapered 5 degrees", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0, "direction": [1, 0, 0]}}, + {"tool": "draft", "args": {"angle": 5, "body": 0, "face": 1, "generation": {"from_call": 1, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "surf_offset", @@ -676,7 +1272,6 @@ "slot": "dressup", "key": null, "feature": "SurfaceOffset", - "mcp": "surface_offset", "accepts": [ "body_sheet" ], @@ -687,7 +1282,40 @@ "gui": true, "action": "fly:surface#4", "icon": "design_offset", - "hint": "Offset a sheet body's shell by a signed distance" + "hint": "Offset a sheet body's shell by a signed distance", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Offset a sheet body by a signed distance -> another sheet body.", + "details": "A positive offset moves each face along its normal, the one query_topology gives, and a negative one against it, so the side depends on how the sheet was made: an extruded circle's normal points inward.", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "sheet body; omit for the last body"}, + {"name": "offset", "type": "number", "unit": "mm", "default": 1} + ], + "examples": [ + { + "title": "A rectangular sheet copied 5 mm above itself", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_fill", "args": {"sketch": 0}}, + {"tool": "surf_offset", "args": {"offset": 5}} + ] + }, + { + "title": "An open tube of radius 10 mm offset -2 mm, against its inward normal, to one of radius 12 mm", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 10, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "surf_extrude", "args": {"distance": 20, "sketch": 0}}, + {"tool": "surf_offset", "args": {"body": 0, "offset": -2}} + ] + } + ], + "ids": false + } }, { "id": "pattern", @@ -695,7 +1323,6 @@ "slot": "repeat", "key": "Shift+N", "feature": "Pattern", - "mcp": "pattern", "accepts": [ "body_solid", "face_planar", @@ -709,7 +1336,39 @@ "gui": true, "action": "btn:pat#0", "icon": "design_array", - "hint": "Repeat the body along a direction — drag the spacing, set the count" + "hint": "Repeat the body along a direction — drag the spacing, set the count", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Replicate a body: linear (count along a plane axis at spacing) or circular (count over an angle about the plane normal).", + "details": "", + "params": [ + {"name": "circular", "type": "boolean", "default": false}, + {"name": "count", "type": "integer", "default": 3, "min": 1}, + {"name": "spacing", "type": "number", "unit": "mm", "default": 10, "description": "linear step"}, + {"name": "dir", "type": "integer", "default": 0, "enum": [0, 1], "description": "linear axis: 0=plane X, 1=plane Y"}, + {"name": "angle", "type": "number", "unit": "deg", "default": 360, "description": "circular total sweep"}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "Three plates 30 mm apart along X", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "pattern", "args": {"count": 3, "spacing": 30}} + ] + }, + { + "title": "Six blocks in a circle about the XY plane's normal", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "profile": [[20, -3], [30, -3], [30, 3], [20, 3]]}}, + {"tool": "pattern", "args": {"circular": true, "count": 6}} + ] + } + ], + "ids": true + } }, { "id": "pattern_circular", @@ -717,7 +1376,6 @@ "slot": "repeat", "key": null, "feature": "Pattern", - "mcp": null, "accepts": [ "body_solid", "face_planar", @@ -740,7 +1398,6 @@ "slot": "repeat", "key": "Shift+Z", "feature": "Mirror", - "mcp": "mirror", "accepts": [ "body_solid", "datum_plane", @@ -758,7 +1415,36 @@ "gui": true, "action": "key:S+Z", "icon": "design_mirror", - "hint": "Reflect a body about a plane" + "hint": "Reflect a body about a plane", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Mirror a body about a base plane.", + "details": "mode=new creates a mirrored copy; mode=add fuses the mirror back into the source.", + "params": [ + {"name": "plane", "type": "string|object", "default": "XZ", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."}, + {"name": "mode", "type": "string", "default": "new", "enum": ["new", "add"]}, + {"name": "keep_original", "type": "boolean", "default": true, "description": "when mode=new, keep the source body"}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "A mirrored copy of a block across the XZ plane", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "profile": [[-5, 5], [5, 5], [5, 15], [-5, 15]]}}, + {"tool": "mirror", "args": {"plane": "XZ"}} + ] + }, + { + "title": "A block against the XZ plane and its mirror image fused into one body", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "profile": [[-5, 0], [5, 0], [5, 10], [-5, 10]]}}, + {"tool": "mirror", "args": {"mode": "add", "plane": "XZ"}} + ] + } + ], + "ids": true + } }, { "id": "pat_curve", @@ -766,7 +1452,6 @@ "slot": "repeat", "key": null, "feature": "Pattern", - "mcp": "pattern_on_curve", "accepts": [ "body_solid", "edge_str" @@ -778,15 +1463,39 @@ "gui": false, "action": null, "icon": null, - "hint": "Repeat the body along a picked curve" + "hint": "Repeat the body along a picked curve", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Replicate a body along a sketch curve.", + "details": "`count` copies are placed at equal-parameter points on the entity, each translated by (P_i - P_0).", + "params": [ + {"name": "count", "type": "integer", "default": 3, "min": 1}, + {"name": "sketch", "type": "integer", "description": "feature index of the sketch holding the guide curve"}, + {"name": "entity", "type": "integer", "description": "entity index of the guide curve within that sketch"}, + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"} + ], + "examples": [ + { + "title": "Four pegs spaced along a half circle", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "end_angle_deg": 180, "radius": 30, "start_angle_deg": 0, "type": "arc"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "extrude", "args": {"distance": 10, "profile": [[28, -2], [32, -2], [32, 2], [28, 2]]}}, + {"tool": "pat_curve", "args": {"count": 4, "entity": 0, "sketch": 0}} + ] + } + ], + "ids": false + } }, { - "id": "transform", + "id": "body_transform", "name": "Move", "slot": "transform", "key": "Shift+Y", "feature": "Transform", - "mcp": "transform", "accepts": [ "body_solid", "body_sheet", @@ -805,7 +1514,44 @@ "gui": true, "action": "key:S+Y", "icon": "design_move", - "hint": "Move and/or rotate an existing body" + "hint": "Move and/or rotate an existing body", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Move and/or rotate a body (B-rep transform).", + "details": "copy=true keeps the source and appends the transformed copy as a new body.", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"}, + {"name": "dx", "type": "number", "unit": "mm", "default": 0}, + {"name": "dy", "type": "number", "unit": "mm", "default": 0}, + {"name": "dz", "type": "number", "unit": "mm", "default": 0}, + {"name": "axis_x", "type": "number", "default": 0}, + {"name": "axis_y", "type": "number", "default": 0}, + {"name": "axis_z", "type": "number", "default": 1}, + {"name": "pivot_x", "type": "number", "unit": "mm", "default": 0}, + {"name": "pivot_y", "type": "number", "unit": "mm", "default": 0}, + {"name": "pivot_z", "type": "number", "unit": "mm", "default": 0}, + {"name": "angle", "type": "number", "unit": "deg", "default": 0}, + {"name": "copy", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "A plate moved 30 mm along X", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "body_transform", "args": {"dx": 30}} + ] + }, + { + "title": "A copy of a plate 10 mm above it", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "body_transform", "args": {"copy": true, "dz": 10}} + ] + } + ], + "ids": false + } }, { "id": "mate", @@ -813,7 +1559,6 @@ "slot": "transform", "key": null, "feature": "Mate", - "mcp": "mate", "accepts": [ "coordsys", "bodies_2", @@ -826,7 +1571,36 @@ "gui": true, "action": "fly:placement#2", "icon": "design_c_coincident", - "hint": "Assembly: align two coordinate systems (fastened, planar, revolute, slider, cylindrical)" + "hint": "Assembly: align two coordinate systems (fastened, planar, revolute, slider, cylindrical)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Mate two bodies: transform the moving body (cs_b) so its connector lands on the fixed one (cs_a).", + "details": "kind: 0=Fastened, 1=Planar, 2=Revolute, 3=Slider, 4=Cylindrical.", + "params": [ + {"name": "kind", "type": "integer", "default": 0, "description": "0=Fastened (rigid), 1=Planar (normal only), 2=Revolute (free rotation about axis), 3=Slider (free translation along axis), 4=Cylindrical (free rotation+translation)"}, + {"name": "cs_a", "type": "integer", "description": "feature index of the fixed CoordSys (mate connector A)"}, + {"name": "cs_b", "type": "integer", "description": "feature index of the CoordSys on the body that moves"}, + {"name": "offset", "type": "number", "unit": "mm", "default": 0}, + {"name": "angle", "type": "number", "unit": "deg", "default": 0}, + {"name": "flip", "type": "boolean", "default": false} + ], + "examples": [ + { + "title": "A block stood on a plate: its bottom-face connector fastened, turned over, to the plate's top-face one", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[30, -5], [40, -5], [40, 5], [30, 5]]}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "coordsys_v", "args": {"body": 0, "face": 5, "generation": {"from_call": 2, "key": "generation"}, "type": "face_and_direction"}}, + {"tool": "query_topology", "args": {"at_extreme": "-z", "body": 1}}, + {"tool": "coordsys_v", "args": {"body": 1, "face": 4, "generation": {"from_call": 4, "key": "generation"}, "type": "face_and_direction"}}, + {"tool": "mate", "args": {"cs_a": 4, "cs_b": 5, "flip": true, "kind": 0}} + ] + } + ], + "ids": false + } }, { "id": "align", @@ -834,7 +1608,6 @@ "slot": "transform", "key": null, "feature": "Transform", - "mcp": "transform", "accepts": [ "face_planar" ], @@ -853,7 +1626,6 @@ "slot": "reference", "key": "Shift+P", "feature": "Plane", - "mcp": null, "accepts": [ "none", "face_planar", @@ -866,7 +1638,50 @@ "gui": true, "action": "key:S+P", "icon": "design_plane", - "hint": "Reference plane (offset / tilt / midplane / tangent / two edges / coincident)" + "hint": "Reference plane (offset / tilt / midplane / tangent / two edges / coincident)", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Add a datum plane as the Plane card does, to sketch or build on as {\"datum\": plane_index}.", + "details": "Offset from a base plane or a face, at an angle about an edge, midway between two faces, tangent to a cylindrical face, through two edges, or coincident with a base plane or a face. Not the `plane` param of other Design commands. Reply: plane_index, name, frame.", + "params": [ + {"name": "type", "type": "string", "default": "offset", "enum": ["offset", "angle", "midplane", "tangent", "two_edges", "coincident"]}, + {"name": "base", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin, or {\"datum\": i}: what offset, coincident and angle build on without face_a"}, + {"name": "offset", "type": "number", "unit": "mm", "default": 20, "description": "offset: distance along the normal of base or face_a"}, + {"name": "angle", "type": "number", "unit": "deg", "default": 0, "description": "offset without face_a: tilt about the base axis `axis`; angle: turn about edge_a from the reference plane; tangent: position around the cylinder"}, + {"name": "axis", "type": "integer", "default": 0, "enum": [0, 1], "description": "offset without face_a: tilt about the base plane's X (0) or Y (1) axis"}, + {"name": "face_a", "type": "object", "default": null, "description": "Face A, {\"body\": b, \"face\": f}: offset or coincident on a face; angle's reference plane; midplane's first face; tangent's cylindrical face"}, + {"name": "face_b", "type": "object", "default": null, "description": "Face B, {\"body\": b, \"face\": f}: midplane's second face"}, + {"name": "edge_a", "type": "object", "default": null, "description": "Edge A, {\"body\": b, \"edge\": e}: angle's hinge; two_edges' first edge"}, + {"name": "edge_b", "type": "object", "default": null, "description": "Edge B, {\"body\": b, \"edge\": e}: two_edges' second edge"}, + {"name": "size", "type": "array", "unit": "mm", "default": [60, 60], "description": "[u, v]: the size the plane is drawn at"} + ], + "examples": [ + { + "title": "A datum plane 20 mm above XY", + "calls": [ + {"tool": "plane", "args": {"base": "XY", "offset": 20, "type": "offset"}} + ] + }, + { + "title": "A datum plane midway between a block's top and bottom faces", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["planar"]}}, + {"tool": "plane", "args": {"face_a": {"body": 0, "face": 4}, "face_b": {"body": 0, "face": 5}, "generation": {"from_call": 1, "key": "generation"}, "type": "midplane"}} + ] + }, + { + "title": "A datum plane turned 30 degrees from a plate's top face about its front edge", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"adjacency": true, "at_extreme": "+z", "body": 0}}, + {"tool": "plane", "args": {"angle": 30, "edge_a": {"body": 0, "edge": 3}, "face_a": {"body": 0, "face": 5}, "generation": {"from_call": 1, "key": "generation"}, "type": "angle"}} + ] + } + ], + "ids": true + } }, { "id": "axis", @@ -874,7 +1689,6 @@ "slot": "reference", "key": "Shift+A", "feature": "Axis", - "mcp": "axis", "accepts": [ "none", "face_planar", @@ -887,7 +1701,51 @@ "gui": true, "action": "key:S+A", "icon": "design_line", - "hint": "Datum axis (two points, face normal, cylinder centerline, two planes, along edge)" + "hint": "Datum axis (two points, face normal, cylinder centerline, two planes, along edge)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Create a datum axis (reference line): two points, face normal, cylinder centreline, plane intersection, or along edge.", + "details": "", + "params": [ + {"name": "type", "type": "string", "default": "two_points", "enum": ["two_points", "face_normal", "cylinder", "plane_intersection", "along_edge"]}, + {"name": "p1", "type": "array", "default": [0, 0, 0], "description": "first point [x,y,z] for two_points"}, + {"name": "p2", "type": "array", "default": [0, 0, 10], "description": "second point [x,y,z] for two_points"}, + {"name": "body", "type": "integer", "default": -1, "description": "body for face/edge refs"}, + {"name": "face", "type": "integer", "default": -1, "description": "face id (query_topology) for face_normal/cylinder"}, + {"name": "edge", "type": "integer", "default": -1, "description": "edge id (query_topology) for along_edge"}, + {"name": "plane_a", "type": "integer", "default": -1, "description": "first datum plane feature index for plane_intersection"}, + {"name": "plane_b", "type": "integer", "default": -1, "description": "second datum plane feature index for plane_intersection"} + ], + "examples": [ + { + "title": "The axis of a hole through a plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, + {"tool": "axis", "args": {"body": 0, "face": 6, "generation": {"from_call": 2, "key": "generation"}, "type": "cylinder"}} + ] + }, + { + "title": "The normal through the centre of a plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "axis", "args": {"body": 0, "face": 5, "generation": {"from_call": 1, "key": "generation"}, "type": "face_normal"}} + ] + }, + { + "title": "The vertical line where two datum planes meet", + "calls": [ + {"tool": "plane", "args": {"base": "XZ", "offset": 10, "type": "offset"}}, + {"tool": "plane", "args": {"base": "YZ", "offset": 10, "type": "offset"}}, + {"tool": "axis", "args": {"plane_a": 0, "plane_b": 1, "type": "plane_intersection"}} + ] + } + ], + "ids": true + } }, { "id": "coordsys_v", @@ -895,7 +1753,6 @@ "slot": "reference", "key": "Shift+C", "feature": "CoordSys", - "mcp": "coordsys", "accepts": [ "none", "face_planar", @@ -906,7 +1763,32 @@ "gui": true, "action": "key:S+C", "icon": "design_point", - "hint": "Datum coordinate system (world point, or face + direction edge)" + "hint": "Datum coordinate system (world point, or face + direction edge)", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Create a datum coordinate system (origin + orthonormal axes).", + "details": "PointWorld aligns to world; FaceAndDirection uses a face for Z and an edge/hint for X.", + "params": [ + {"name": "type", "type": "string", "default": "point_world", "enum": ["point_world", "face_and_direction"]}, + {"name": "point", "type": "array", "default": [0, 0, 0], "description": "origin [x,y,z] for point_world"}, + {"name": "body", "type": "integer", "default": -1, "description": "body for face/edge refs"}, + {"name": "face", "type": "integer", "default": -1, "description": "face id (query_topology) for Z axis"}, + {"name": "edge", "type": "integer", "default": -1, "description": "edge id (query_topology) for X axis hint"}, + {"name": "x_hint", "type": "array", "default": [1, 0, 0], "description": "fallback X direction hint if no edge given"} + ], + "examples": [ + { + "title": "A connector on a plate's top face, its x axis along the front edge", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"adjacency": true, "at_extreme": "+z", "body": 0}}, + {"tool": "coordsys_v", "args": {"body": 0, "edge": 3, "face": 5, "generation": {"from_call": 1, "key": "generation"}, "type": "face_and_direction"}} + ] + } + ], + "ids": true + } }, { "id": "helix", @@ -914,7 +1796,6 @@ "slot": "reference", "key": null, "feature": "Helix", - "mcp": "helix", "accepts": [ "none", "datum_plane", @@ -925,7 +1806,36 @@ "gui": true, "action": "fly:plane#3", "icon": "design_thread", - "hint": "Helical curve (spring path) — use as a sweep path for coils / springs / augers" + "hint": "Helical curve (spring path) — use as a sweep path for coils / springs / augers", + "tool": { + "access": "change", + "ok_false": false, + "summary": "Create a helical curve, a sweep path for springs, coils and augers.", + "details": "It starts on the plane's x axis at `radius` from its origin. pitch = axial rise per turn. left_handed flips the winding. taper_deg != 0 gives a conical helix. Reply: helix_index, frame, start and tangent (world), to draw a sweep's profile across the curve there.", + "params": [ + {"name": "radius", "type": "number", "unit": "mm", "default": 10, "exclusive_min": 0}, + {"name": "pitch", "type": "number", "unit": "mm", "default": 5, "exclusive_min": 0}, + {"name": "height", "type": "number", "unit": "mm", "default": 20, "exclusive_min": 0}, + {"name": "left_handed", "type": "boolean", "default": false}, + {"name": "taper_deg", "type": "number", "unit": "deg", "default": 0}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."} + ], + "examples": [ + { + "title": "A four-turn helix on XY: radius 10 mm, pitch 5 mm, 20 mm tall", + "calls": [ + {"tool": "helix", "args": {"height": 20, "pitch": 5, "radius": 10}} + ] + }, + { + "title": "A left-handed conical helix tapering 10 degrees", + "calls": [ + {"tool": "helix", "args": {"height": 20, "left_handed": true, "pitch": 4, "radius": 10, "taper_deg": 10}} + ] + } + ], + "ids": true + } }, { "id": "project", @@ -933,7 +1843,6 @@ "slot": "reference", "key": null, "feature": "Project", - "mcp": "project", "accepts": [ "body_solid", "face_planar", @@ -946,7 +1855,38 @@ "gui": true, "action": "fly:plane#4", "icon": "design_sketch", - "hint": "Project body edges onto a plane as sketch entities" + "hint": "Project body edges onto a plane as sketch entities", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Project edges of a solid onto a sketch plane, producing a new sketch feature.", + "details": "", + "params": [ + {"name": "source_body", "type": "integer", "default": -1, "description": "body owning the edges; -1 = last body"}, + {"name": "face", "type": "integer", "default": -1, "description": "global face id on the source body; when set, all its edges are projected"}, + {"name": "edges", "type": "array", "default": [], "description": "global edge ids to project; empty => project the face"}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."} + ], + "examples": [ + { + "title": "A plate's top-face outline projected onto the XY plane as a new sketch", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "project", "args": {"face": 5, "generation": {"from_call": 1, "key": "generation"}, "plane": "XY", "source_body": 0}} + ] + }, + { + "title": "Two top edges of a plate, meeting at a corner, projected onto the XY plane", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"adjacency": true, "at_extreme": "+z", "body": 0}}, + {"tool": "project", "args": {"edges": [3, 6], "generation": {"from_call": 1, "key": "generation"}, "plane": "XY", "source_body": 0}} + ] + } + ], + "ids": true + } }, { "id": "measure", @@ -954,7 +1894,6 @@ "slot": "reference", "key": null, "feature": null, - "mcp": "measure", "accepts": [ "face_planar", "face_cyl", @@ -974,7 +1913,39 @@ "gui": false, "action": null, "icon": null, - "hint": "Measure between the picked points, edges or faces" + "hint": "Measure between the picked points, edges or faces", + "tool": { + "access": "read", + "ok_false": false, + "summary": "Measure two refs, on one body or two: distance, closest points, angle and the gap between parallel faces.", + "details": "distance is between their representative points (a face's centroid, an edge's middle, an axis's middle); min_distance comes with closest_a and closest_b; angle_deg when both have a direction; parallel_gap across two parallel planar faces.", + "params": [ + {"name": "body", "type": "integer", "default": 0, "description": "the body of a ref that names none"}, + {"name": "a", "type": "object", "description": "{\"face\": f}, {\"edge\": e} or {\"point\": [x, y, z]}, with an optional \"body\"; {\"face\": f, \"axis\": true} is a cylindrical face's axis over its length"}, + {"name": "b", "type": "object", "description": "as a"} + ], + "examples": [ + { + "title": "A plate's thickness, between its top and bottom faces", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["planar"]}}, + {"tool": "measure", "args": {"a": {"face": 5}, "b": {"face": 4}, "body": 0, "generation": {"from_call": 1, "key": "generation"}}} + ] + }, + { + "title": "The 10 mm gap between two blocks' facing sides", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[20, -5], [30, -5], [30, 5], [20, 5]]}}, + {"tool": "query_topology", "args": {"body": 0, "direction": [1, 0, 0]}}, + {"tool": "query_topology", "args": {"body": 1, "direction": [-1, 0, 0]}}, + {"tool": "measure", "args": {"a": {"body": 0, "face": 1}, "b": {"body": 1, "face": 3}, "generation": {"from_call": 3, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "mass_props", @@ -982,7 +1953,6 @@ "slot": "reference", "key": null, "feature": null, - "mcp": "mass_properties", "accepts": [ "body_solid", "face_planar", @@ -999,7 +1969,26 @@ "gui": true, "action": "btn:mass", "icon": "info", - "hint": "Report the volume and surface area of the selected body" + "hint": "Report the volume and surface area of the selected body", + "tool": { + "access": "read", + "ok_false": false, + "summary": "Volume / surface area / centre of mass / inertia tensor of a body.", + "details": "", + "params": [ + {"name": "body", "type": "integer", "default": 0} + ], + "examples": [ + { + "title": "The volume and centre of mass of a 20 x 20 x 5 mm plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "mass_props", "args": {"body": 0}} + ] + } + ], + "ids": false + } }, { "id": "interference", @@ -1007,7 +1996,6 @@ "slot": "reference", "key": null, "feature": null, - "mcp": "check_interference", "accepts": [ "body_solid", "bodies_2" @@ -1018,8 +2006,28 @@ "refusal": "Interference needs at least two bodies", "gui": true, "action": "btn:interference", - "icon": null, - "hint": "Check whether two bodies overlap — reports, changes nothing" + "icon": "design_boolean", + "hint": "Check whether two bodies overlap — reports, changes nothing", + "tool": { + "access": "read", + "ok_false": false, + "summary": "Solid bodies that overlap, as {body_a, body_b, volume}.", + "details": "Read-only; bodies that merely touch enclose no volume and are not reported.", + "params": [ + {"name": "min_volume", "type": "number", "unit": "mm^3", "default": 1e-06, "description": "overlap volume above which a pair counts as interfering"} + ], + "examples": [ + { + "title": "A post standing in a block: the two overlap", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 20, "height": 10, "width": 10}}, + {"tool": "interference", "args": {"silent": true}} + ] + } + ], + "ids": false + } }, { "id": "edit_feature", @@ -1027,7 +2035,6 @@ "slot": "modify", "key": null, "feature": null, - "mcp": "set_feature_expr", "accepts": [ "body_solid", "face_planar", @@ -1045,7 +2052,38 @@ "gui": true, "action": "btn:edit", "icon": "design_edit", - "hint": "Reopen the selected feature to change what it was made from" + "hint": "Reopen the selected feature to change what it was made from", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Bind a feature's numeric field to an expression over the design variables, or unbind it with an empty expr.", + "details": "Unbound, the field keeps its value.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"}, + {"name": "field", "type": "string", "description": "a numeric field of describe_feature's params, e.g. width, distance, hole_diameter, thread_diameter"}, + {"name": "expr", "type": "string", "description": "\"\" removes the binding"} + ], + "examples": [ + { + "title": "A plate's thickness bound to the variable t", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "set_variable", "args": {"expr": "8", "name": "t"}}, + {"tool": "edit_feature", "args": {"expr": "t", "feature": 1, "field": "distance"}} + ] + }, + { + "title": "A plate's thickness unbound, keeping the 8 mm the binding gave it", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "set_variable", "args": {"expr": "8", "name": "t"}}, + {"tool": "edit_feature", "args": {"expr": "t", "feature": 1, "field": "distance"}}, + {"tool": "edit_feature", "args": {"expr": "", "feature": 1, "field": "distance"}} + ] + } + ], + "ids": false + } }, { "id": "rename", @@ -1053,7 +2091,6 @@ "slot": "top", "key": "F2", "feature": "Tree", - "mcp": null, "mode": "model", "accepts": [ "sk_loop", @@ -1063,7 +2100,7 @@ "refusal": "Select a feature, or a body, to rename it", "gui": true, "action": "btn:rename", - "icon": null, + "icon": "rename_edit", "hint": "Give this feature a name you will recognise in the tree (a body takes its name from the feature that makes it)" }, { @@ -1072,7 +2109,6 @@ "slot": "modify", "key": null, "feature": "DeleteFace", - "mcp": "delete_face", "accepts": [ "face_planar", "face_cyl", @@ -1085,7 +2121,29 @@ "gui": true, "action": "fly:dressup#3", "icon": "design_delete", - "hint": "Remove faces from a body and heal the solid" + "hint": "Remove faces from a body and heal the solid", + "tool": { + "access": "change", + "ok_false": true, + "summary": "Remove faces from a solid, healing the gap via OCCT defeaturing.", + "details": "", + "params": [ + {"name": "body", "type": "integer", "default": -1, "description": "target body; omit for the last body"}, + {"name": "faces", "type": "array", "description": "global face ids to delete"} + ], + "examples": [ + { + "title": "A plate's bore filled in by deleting its cylindrical face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, + {"tool": "delete_face", "args": {"body": 0, "faces": [6], "generation": {"from_call": 2, "key": "generation"}}} + ] + } + ], + "ids": true + } }, { "id": "colour", @@ -1093,7 +2151,6 @@ "slot": "top", "key": null, "feature": null, - "mcp": null, "accepts": [ "body_solid", "body_sheet", @@ -1111,7 +2168,8 @@ "gui": true, "action": "btn:colour", "icon": "color_palette", - "hint": "Set the selected body's display color" + "hint": "Set the selected body's display color", + "modal": true }, { "id": "zoom_to", @@ -1119,7 +2177,6 @@ "slot": "top", "key": null, "feature": null, - "mcp": null, "mode": "model", "accepts": [ "body_solid", @@ -1145,7 +2202,6 @@ "slot": "modify", "key": "Del", "feature": null, - "mcp": null, "accepts": [ "sk_loop", "art", @@ -1195,7 +2251,6 @@ "slot": "create", "key": "L", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1218,7 +2273,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1241,7 +2295,6 @@ "slot": "create", "key": "R", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1264,7 +2317,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1287,7 +2339,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1310,7 +2361,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1333,7 +2383,6 @@ "slot": "create", "key": "C", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1356,7 +2405,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1379,7 +2427,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1402,7 +2449,6 @@ "slot": "create", "key": "A", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1425,7 +2471,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1448,7 +2493,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1471,7 +2515,6 @@ "slot": "create", "key": "S", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1494,7 +2537,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1517,7 +2559,6 @@ "slot": "create", "key": "E", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1540,7 +2581,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1563,7 +2603,6 @@ "slot": "create", "key": "B", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1585,7 +2624,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1608,7 +2646,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1631,7 +2668,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1654,7 +2690,6 @@ "slot": "create", "key": "G", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1677,7 +2712,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1700,7 +2734,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1723,7 +2756,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1746,7 +2778,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1769,7 +2800,6 @@ "slot": "create", "key": "P", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -1791,7 +2821,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1805,7 +2834,8 @@ "action": "btn:text", "mode": "sketch", "icon": "design_text", - "hint": "Type text; it becomes a Text feature on this sketch's plane, editable later" + "hint": "Type text; it becomes a Text feature on this sketch's plane, editable later", + "modal": true }, { "id": "sk_svg", @@ -1813,7 +2843,6 @@ "slot": "create", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_none", "sk_point", @@ -1827,7 +2856,8 @@ "action": "btn:svg", "mode": "sketch", "icon": "design_svg", - "hint": "Import an SVG outline into this sketch as editable lines" + "hint": "Import an SVG outline into this sketch as editable lines", + "modal": true }, { "id": "sk_offset", @@ -1835,7 +2865,6 @@ "slot": "add", "key": "O", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1855,7 +2884,6 @@ "slot": "remove", "key": "T", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1875,7 +2903,6 @@ "slot": "dressup", "key": "F", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1894,7 +2921,6 @@ "slot": "dressup", "key": "H", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1913,7 +2939,6 @@ "slot": "repeat", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_line", "sk_arc", @@ -1934,7 +2959,6 @@ "slot": "repeat", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_line", "sk_arc", @@ -1955,7 +2979,6 @@ "slot": "repeat", "key": "M", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1975,7 +2998,6 @@ "slot": "transform", "key": null, "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -1997,7 +3019,6 @@ "slot": "transform", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_line", "sk_arc", @@ -2019,7 +3040,6 @@ "slot": "transform", "key": null, "feature": "Sketch", - "mcp": null, "accepts": [ "sk_line", "sk_arc", @@ -2041,7 +3061,6 @@ "slot": "reference", "key": "D", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -2063,7 +3082,6 @@ "slot": "reference", "key": "K", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -2084,7 +3102,6 @@ "slot": "reference", "key": null, "feature": "Sketch", - "mcp": null, "mode": "model", "accepts": [ "sk_loop" @@ -2110,7 +3127,6 @@ "slot": "reference", "key": "Q", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_none", @@ -2122,7 +3138,7 @@ "refusal": null, "gui": true, "action": "key:Q", - "icon": null, + "icon": "design_construction", "hint": "Toggle construction: geometry that guides but is never built" }, { @@ -2131,7 +3147,6 @@ "slot": "modify", "key": "X", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -2151,7 +3166,6 @@ "slot": "modify", "key": "Del", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line", @@ -2172,7 +3186,6 @@ "slot": "modify", "key": "V", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_line" @@ -2197,7 +3210,6 @@ "slot": "modify", "key": "V", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_arc" @@ -2215,7 +3227,6 @@ "slot": "modify", "key": "V", "feature": "Sketch", - "mcp": null, "mode": "sketch", "accepts": [ "sk_2ent" @@ -2226,6 +3237,1417 @@ "action": "key:V", "icon": "design_dimension", "hint": "Type the angle between two lines, or the distance between the two picks" + }, + { + "id": "describe_scene", + "name": "Describe scene", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "The Design document: features, variables with their values, bodies, undo_depth / redo_depth and generation.", + "details": "A feature's bound lists the fields an expression drives; a body gives bbox, source_feature, visible, color and moved (by the Move gizmo). selection is what the right-click menu would be built for: its kind, the selection_kind a tool's opening reply gives, and its id (none, face_planar, body_solid, sk_line and the like).", + "params": [], + "examples": [ + { + "title": "An empty design", + "calls": [ + {"tool": "describe_scene", "args": {}} + ] + }, + { + "title": "A plate's two features and its body", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "describe_scene", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "describe_feature", + "name": "Describe feature", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "One feature as its card shows it: params, the editable ones with their ranges, expr, refs, used_by and bodies_made.", + "details": "expr holds its bindings, and refs the feature and body indices and face and edge ids it uses; a sketch adds its plane, entities and constraints (angles in degrees). Imported Text or SVG art shows its regions (a count), region_loops (how many closed loops each region has, its outer loop plus its holes; counts, not the loops' geometry) and region_areas (each region's filled area in mm² as placed, its outer loop less its holes).", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"} + ], + "examples": [ + { + "title": "A plate's extrude, with the fields its card edits", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "describe_feature", "args": {"feature": 1}} + ] + }, + { + "title": "A committed sketch's plane, entities and constraints", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "describe_feature", "args": {"feature": 0}} + ] + } + ], + "ids": true + } + }, + { + "id": "query_topology", + "name": "Query topology", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "A body's faces and edges, with their kinds and geometry, narrowed by face and edge filters.", + "details": "Faces give kind, area, centroid, normal, and a cylinder's, cone's, sphere's or torus's numbers; edges give kind, length, ends, a circle's centre and radius. Face filters (kinds, direction, at_extreme) and edge filters (edge_kinds, direction, convex) narrow their own list; when filters are given, a list none of its filters names is empty, or with adjacency holds the neighbours of the other list. Reply: face_count and edge_count of the body, faces_total and edges_total after filtering, next_offset while a page has more, generation.", + "params": [ + {"name": "body", "type": "integer", "default": 0}, + {"name": "kinds", "type": "array", "default": null, "description": "face kinds to list: planar, cylindrical, conical, spherical, toroidal, bezier, bspline, revolution, extrusion, offset, other"}, + {"name": "edge_kinds", "type": "array", "default": null, "description": "edge kinds to list: line, circle, ellipse, bspline, bezier, other"}, + {"name": "direction", "type": "array", "default": null, "description": "[x, y, z]: planar faces whose outward normal points this way, and line edges along it either way, within 1 degree"}, + {"name": "at_extreme", "type": "string", "default": null, "enum": ["+x", "-x", "+y", "-y", "+z", "-z"], "description": "faces whose centroid lies on that side of the body's bounding box, e.g. +z for the top face"}, + {"name": "convex", "type": "boolean", "default": null, "description": "edges where two faces meet in an outside (true) or inside (false) corner; implies adjacency"}, + {"name": "adjacency", "type": "boolean", "default": false, "description": "faces list their edges; edges list their faces (one for a seam) and say convex true or false, or tangent where the faces meet smoothly"}, + {"name": "limit", "type": "integer", "default": null, "min": 1, "description": "page size of both lists; omit for all"}, + {"name": "offset", "type": "integer", "default": 0} + ], + "examples": [ + { + "title": "Every face and edge of a 20 x 20 x 5 mm plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0}} + ] + }, + { + "title": "A plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}} + ] + }, + { + "title": "A plate's vertical outside corners, the edges a fillet rounds", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"body": 0, "convex": true, "direction": [0, 0, 1], "edge_kinds": ["line"]}} + ] + } + ], + "ids": true + } + }, + { + "id": "slice_body", + "name": "Slice body", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "Cross-section of a body by a base plane at an offset (sections-as-evidence).", + "details": "Returns ordered world contours, each flagged closed/open.", + "params": [ + {"name": "body", "type": "integer", "default": 0}, + {"name": "plane", "type": "string", "default": "XY", "enum": ["XY", "XZ", "YZ"]}, + {"name": "offset", "type": "number", "unit": "mm", "default": 0} + ], + "examples": [ + { + "title": "A plate's cross-section halfway up", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "slice_body", "args": {"body": 0, "offset": 2.5, "plane": "XY"}} + ] + }, + { + "title": "The two contours through a plate with a bore", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "extrude", "args": {"distance": 5, "sketch": 0}}, + {"tool": "slice_body", "args": {"body": 0, "offset": 2.5, "plane": "XY"}} + ] + } + ], + "ids": true + } + }, + { + "id": "validate_against", + "name": "Validate against", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "Compare a body with a reference: volume, bbox, centroid and surface deviation (the RE acceptance metric).", + "details": "The reference is {step:path|body:id}; the surface deviation is max/mean/rms in mm.", + "params": [ + {"name": "body", "type": "integer", "default": 0}, + {"name": "reference", "type": "object"} + ], + "examples": [ + { + "title": "A 5 mm plate against a 6 mm one", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 6, "height": 20, "width": 20}}, + {"tool": "validate_against", "args": {"body": 0, "reference": {"body": 1}}} + ] + }, + { + "title": "A plate against a reference part's STEP file", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "validate_against", "args": {"body": 0, "reference": {"step": "/path/to/reference.step"}}} + ], + "needs": "a STEP file of the reference part" + } + ], + "ids": false + } + }, + { + "id": "sketch_describe", + "name": "Sketch describe", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "The open sketch, or a committed one: entities, constraint count and its loops.", + "details": "The loops are closed_loops {index, entities, holes, area}, open_ends, defects, buildable. The open sketch adds dof, the armed tool, the selection (entity indices) and selected_constraint, the index of the constraint picked by its badge or the Constraints list, null for none; a committed one adds its name and plane.", + "params": [ + {"name": "sketch", "type": "integer", "default": null, "description": "a committed Sketch feature's index; omit for the open sketch"} + ], + "examples": [ + { + "title": "The open sketch: a rectangle with a circle inside it as a hole", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}]}}, + {"tool": "sketch_describe", "args": {}} + ] + }, + { + "title": "A committed sketch's plane, entities and loop", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sketch_describe", "args": {"sketch": 0}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_validate", + "name": "Sketch validate", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "The open sketch's loops (closed_loops, open_ends, defects, buildable) and dof.", + "details": "", + "params": [ + {"name": "tolerance", "type": "number", "unit": "mm", "default": 0.001, "description": "reported back"} + ], + "examples": [ + { + "title": "A triangle with a 0.05 mm gap: two open ends, not buildable", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [20, 0], "type": "line"}, {"p0": [20, 0.05], "p1": [20, 10], "type": "line"}, {"p0": [20, 10], "p1": [0, 0], "type": "line"}]}}, + {"tool": "sketch_validate", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_constraints", + "name": "Sketch constraints", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "read", + "ok_false": false, + "summary": "The constraints of the open sketch, or of a committed one: index, type, refs and value.", + "details": "A ref is {entity, role} for a point and {entity} for a whole entity; value is mm, or degrees for an angle. Reply: scope (live or committed), items, and dof and solve_ok for the open sketch.", + "params": [ + {"name": "sketch", "type": "integer", "default": null, "description": "a committed Sketch feature's index; omit for the open sketch"} + ], + "examples": [ + { + "title": "The coincident, horizontal and vertical constraints a drawn rectangle gets", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_constraints", "args": {}} + ] + }, + { + "title": "A committed sketch's constraints", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "sketch_constraints", "args": {"sketch": 0}} + ] + } + ], + "ids": false + } + }, + { + "id": "import_step", + "name": "Import step", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": true, + "summary": "Import a STEP file as native B-rep bodies (the reference part to measure).", + "details": "", + "params": [ + {"name": "path", "type": "string", "description": "absolute path"} + ], + "examples": [ + { + "title": "A part read from a STEP file as a body", + "calls": [ + {"tool": "import_step", "args": {"path": "/path/to/part.step"}} + ], + "needs": "a STEP file of the part" + } + ], + "ids": false + } + }, + { + "id": "import_mesh", + "name": "Import mesh", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": true, + "summary": "Convert a triangle mesh (STL/OBJ) into an editable B-rep body.", + "details": "Reports whether the result is a real solid or an open shell, and why.", + "params": [ + {"name": "path", "type": "string", "description": "absolute path"}, + {"name": "tolerance", "type": "number", "default": 0.01}, + {"name": "merge_angle_deg", "type": "number", "default": 5.0} + ], + "examples": [ + { + "title": "An STL mesh turned into an editable body", + "calls": [ + {"tool": "import_mesh", "args": {"path": "/path/to/part.stl"}} + ], + "needs": "an STL or OBJ mesh file" + } + ], + "ids": false + } + }, + { + "id": "hole_styled", + "name": "Hole styled", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Drill a hole with optional counterbore (style=1) or countersink (style=2) at (x,y) or `at` on a plane.", + "details": "Reply as hole.", + "params": [ + {"name": "diameter", "type": "number", "unit": "mm", "default": 5, "exclusive_min": 0}, + {"name": "depth", "type": "number", "unit": "mm", "default": 10}, + {"name": "through", "type": "boolean", "default": true}, + {"name": "x", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "y", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes."}, + {"name": "at", "type": "array|object", "default": null, "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}, + {"name": "body", "type": "integer", "default": -1, "description": "the body to drill; omit for a face plane's body, else the last body"}, + {"name": "style", "type": "integer", "default": 0, "description": "0=simple, 1=counterbore, 2=countersink"}, + {"name": "cbore_diameter", "type": "number", "unit": "mm", "default": 0}, + {"name": "cbore_depth", "type": "number", "unit": "mm", "default": 0}, + {"name": "csink_diameter", "type": "number", "unit": "mm", "default": 0}, + {"name": "csink_angle", "type": "number", "unit": "deg", "default": 90}, + {"name": "standard", "type": "string", "default": "", "description": "provenance designation, e.g. M6"} + ], + "examples": [ + { + "title": "A counterbored hole for an M6 cap screw through a 10 mm block's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 30, "width": 30}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "hole_styled", "args": {"cbore_depth": 6, "cbore_diameter": 11, "diameter": 6.6, "generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}, "style": 1}} + ] + }, + { + "title": "A countersunk hole through a plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "hole_styled", "args": {"csink_angle": 90, "csink_diameter": 9, "diameter": 4.5, "generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}, "style": 2}} + ] + } + ], + "ids": true + } + }, + { + "id": "hole_standard", + "name": "Hole standard", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Drill a standard clearance hole (ISO 273 / ANSI) at (x,y) or `at` on a plane.", + "details": "style: 0=simple, 1=counterbore, 2=countersink. Reply as hole.", + "params": [ + {"name": "designation", "type": "string", "description": "e.g. M6, 1/4-20"}, + {"name": "style", "type": "integer", "default": 0}, + {"name": "through", "type": "boolean", "default": true}, + {"name": "depth", "type": "number", "unit": "mm", "default": 10}, + {"name": "x", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "y", "type": "number", "unit": "mm", "default": 0, "description": "offset in the plane's frame from its origin, NOT world"}, + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes."}, + {"name": "at", "type": "array|object", "default": null, "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}, + {"name": "body", "type": "integer", "default": -1, "description": "the body to drill; omit for a face plane's body, else the last body"} + ], + "examples": [ + { + "title": "An M5 clearance hole through a plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "hole_standard", "args": {"designation": "M5", "generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}}} + ] + }, + { + "title": "An M6 counterbored clearance hole through a 10 mm block's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 10, "height": 30, "width": 30}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "hole_standard", "args": {"designation": "M6", "generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}, "style": 1}} + ] + } + ], + "ids": true + } + }, + { + "id": "bridge", + "name": "Bridge", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": true, + "summary": "Build a cubic-Bezier G1 bridge (BSpline) between two sketch-entity endpoints within a sketch feature.", + "details": "", + "params": [ + {"name": "sketch", "type": "integer", "description": "sketch feature index"}, + {"name": "ent_a", "type": "integer", "description": "first entity index within the sketch"}, + {"name": "end_a", "type": "integer", "default": 1, "enum": [0, 1], "description": "0 = start/p0 side, 1 = end/p1 side"}, + {"name": "ent_b", "type": "integer", "description": "second entity index within the sketch"}, + {"name": "end_b", "type": "integer", "default": 0, "enum": [0, 1], "description": "0 = start/p0 side, 1 = end/p1 side"} + ], + "examples": [ + { + "title": "A smooth curve joining the facing ends of two lines in a committed sketch", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [-20, 0], "p1": [-5, 0], "type": "line"}, {"p0": [5, 10], "p1": [20, 10], "type": "line"}]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "bridge", "args": {"end_a": 1, "end_b": 0, "ent_a": 0, "ent_b": 1, "sketch": 0}} + ] + } + ], + "ids": false + } + }, + { + "id": "set_variable", + "name": "Set variable", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": true, + "summary": "Set a design variable to an expression, or remove it with an empty expr.", + "details": "Feature fields bound with edit_feature follow it.", + "params": [ + {"name": "name", "type": "string"}, + {"name": "expr", "type": "string", "description": "e.g. \"20\" or \"width / 2 + 3\"; \"\" removes the variable"} + ], + "examples": [ + { + "title": "A variable w of 20", + "calls": [ + {"tool": "set_variable", "args": {"expr": "20", "name": "w"}} + ] + }, + { + "title": "A variable worked out from another: h = w / 2 + 3, which is 13", + "calls": [ + {"tool": "set_variable", "args": {"expr": "20", "name": "w"}}, + {"tool": "set_variable", "args": {"expr": "w / 2 + 3", "name": "h"}} + ] + }, + { + "title": "A variable removed with an empty expression", + "calls": [ + {"tool": "set_variable", "args": {"expr": "20", "name": "w"}}, + {"tool": "set_variable", "args": {"expr": "", "name": "w"}} + ] + } + ], + "ids": false + } + }, + { + "id": "set_feature", + "name": "Set feature", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Change a feature's editable fields as its card's Confirm does when editing: one undo step and a rebuild.", + "details": "A field an expression drives is refused. Reply: changed {field: [old, new]}.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"}, + {"name": "fields", "type": "object", "description": "{field: value} from describe_feature's editable, e.g. {\"distance\": 15}: numbers within its ranges; mode new|union|subtract|intersect; extrude_end blind|symmetric|two_sided|through_all; shape rectangle|circle; xf_* vectors [x, y, z]"} + ], + "examples": [ + { + "title": "A plate made 15 mm thick", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}} + ] + }, + { + "title": "A plate's hole widened from 5 to 8 mm", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "set_feature", "args": {"feature": 2, "fields": {"hole_diameter": 8}}} + ] + } + ], + "ids": false + } + }, + { + "id": "feature_delete", + "name": "Feature delete", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Delete a feature as its tree row's Delete does; deleting a sketch also deletes the features built on it.", + "details": "One undo step. Later indices shift. Reply: removed (how many features went), features, bodies.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"} + ], + "examples": [ + { + "title": "A plate's hole deleted", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "feature_delete", "args": {"feature": 2}} + ] + }, + { + "title": "A committed sketch deleted, and the extrude built on it with it", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_commit", "args": {}}, + {"tool": "extrude", "args": {"distance": 5, "sketch": 0}}, + {"tool": "feature_delete", "args": {"feature": 0}} + ] + } + ], + "ids": false + } + }, + { + "id": "feature_move", + "name": "Feature move", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Move a feature one place up or down the history, as Move up / Move down do.", + "details": "A feature cannot come before one it uses. One undo step. Reply: feature (its new index), from.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"}, + {"name": "delta", "type": "integer", "enum": [-1, 1], "description": "-1 up, 1 down"} + ], + "examples": [ + { + "title": "A datum plane moved up the history, above the extrude before it", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "plane", "args": {"base": "XY", "offset": 20, "type": "offset"}}, + {"tool": "feature_move", "args": {"delta": -1, "feature": 2}} + ] + } + ], + "ids": false + } + }, + { + "id": "feature_set_enabled", + "name": "Feature set enabled", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Show or hide (suppress) a feature as its row's eye does.", + "details": "A hidden feature is left out of the rebuild and bodies may renumber. One undo step, none when it already was. Reply: enabled, changed, bodies.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"}, + {"name": "enabled", "type": "boolean"} + ], + "examples": [ + { + "title": "A plate's hole hidden: the plate rebuilds without it", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "feature_set_enabled", "args": {"enabled": false, "feature": 2}} + ] + }, + { + "title": "A hidden hole shown again", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "hole", "args": {"diameter": 5, "through": true}}, + {"tool": "feature_set_enabled", "args": {"enabled": false, "feature": 2}}, + {"tool": "feature_set_enabled", "args": {"enabled": true, "feature": 2}} + ] + } + ], + "ids": false + } + }, + { + "id": "feature_rename", + "name": "Feature rename", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Rename a feature as F2 on its row does.", + "details": "Its own undo step. Reply: name, changed.", + "params": [ + {"name": "feature", "type": "integer", "description": "feature index (describe_scene)"}, + {"name": "name", "type": "string", "description": "trimmed; not empty"} + ], + "examples": [ + { + "title": "A plate's extrude renamed Base plate", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "feature_rename", "args": {"feature": 1, "name": "Base plate"}} + ] + } + ], + "ids": false + } + }, + { + "id": "body_set", + "name": "Body set", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Rename, colour or show/hide a body, as its Bodies row and the Color button do; give one or more.", + "details": "Not in the undo history. The name and colour are saved with the project and the name names its committed object; visibility is view state, and commit leaves hidden bodies out. Reply: name, color, visible.", + "params": [ + {"name": "body", "type": "integer", "description": "body index (describe_scene)"}, + {"name": "name", "type": "string", "default": null, "description": "trimmed; not empty"}, + {"name": "color", "type": "string", "default": null, "description": "\"#RRGGBB\""}, + {"name": "visible", "type": "boolean", "default": null} + ], + "examples": [ + { + "title": "A plate's body named Base and coloured blue", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "body_set", "args": {"body": 0, "color": "#3366CC", "name": "Base"}} + ] + }, + { + "title": "The second of two bodies hidden", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[20, -5], [30, -5], [30, 5], [20, 5]]}}, + {"tool": "body_set", "args": {"body": 1, "visible": false}} + ] + } + ], + "ids": false + } + }, + { + "id": "body_delete", + "name": "Body delete", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Delete a body as its row's Delete does: the feature that made it goes, which can take other features and bodies with it.", + "details": "One undo step. Reply: deleted_feature {index, type, name}, removed, features, bodies.", + "params": [ + {"name": "body", "type": "integer", "description": "body index (describe_scene)"} + ], + "examples": [ + { + "title": "The second of two bodies deleted, with the extrude that made it", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[20, -5], [30, -5], [30, 5], [20, 5]]}}, + {"tool": "body_delete", "args": {"body": 1}} + ] + } + ], + "ids": false + } + }, + { + "id": "commit", + "name": "Commit", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Commit to Plate: send the visible bodies to Prepare at their Move-gizmo positions and show Prepare.", + "details": "It is one Prepare undo step. A lone body is sent even when hidden. A body named in the Bodies list or with body_set names its object or part. Reply: objects (list_objects index after replace, name, parts: how many), bodies_sent, bodies_hidden, replaced.", + "params": [ + {"name": "mode", "type": "string", "default": "", "enum": ["assembly", "bodies"], "description": "assembly: one object with a part per body; bodies: an object per body. Default: the Commit button's mode, which this leaves as it is."}, + {"name": "replace", "type": "array", "default": [], "description": "list_objects indices to delete in the same undo step, such as an earlier commit. Their settings, modifiers and paint go with them."} + ], + "examples": [ + { + "title": "A plate sent to Prepare as one object", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "commit", "args": {}} + ] + }, + { + "title": "Two bodies sent to Prepare as an object each", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "extrude", "args": {"boolean": "new", "distance": 10, "profile": [[20, -5], [30, -5], [30, 5], [20, 5]]}}, + {"tool": "commit", "args": {"mode": "bodies"}} + ] + } + ], + "ids": false + } + }, + { + "id": "new_design", + "name": "New design", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "New Design: erase every feature, body and variable and the Design undo history.", + "details": "Committed objects stay on the plate. Reply: cleared {features, bodies, variables}.", + "params": [ + {"name": "discard_changes", "type": "boolean", "default": false, "description": "needed when the design is not empty"} + ], + "examples": [ + { + "title": "A plate's design erased", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "new_design", "args": {"discard_changes": true}} + ] + }, + { + "title": "An empty design started over, which needs no discard_changes", + "calls": [ + {"tool": "new_design", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "export_step", + "name": "Export step", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "change", + "ok_false": false, + "summary": "Export STEP: write every body to a file as native B-rep, at its Move-gizmo position.", + "details": "Reply: path, bytes, bodies, moved_bodies.", + "params": [ + {"name": "path", "type": "string", "description": "absolute path; its directory must exist"}, + {"name": "overwrite", "type": "boolean", "default": false, "description": "replace an existing file"} + ], + "examples": [ + { + "title": "A plate written to a STEP file", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "export_step", "args": {"path": "/path/to/part.step"}} + ], + "needs": "a folder to write the STEP file in" + } + ], + "ids": false + } + }, + { + "id": "sketch_begin", + "name": "Sketch begin", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Open a sketch session on a plane, as picking a plane or face for Sketch does.", + "details": "Sketch points are [x, y] in that plane's frame (mm), from its origin: modeling_origin for a base plane. Reply: frame.", + "params": [ + {"name": "plane", "type": "string|object", "default": "XY", "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes."} + ], + "examples": [ + { + "title": "A sketch on the XY plane", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}} + ] + }, + { + "title": "A sketch on a plate's top face", + "calls": [ + {"tool": "extrude", "args": {"distance": 5, "height": 20, "width": 20}}, + {"tool": "query_topology", "args": {"at_extreme": "+z", "body": 0}}, + {"tool": "sketch_begin", "args": {"generation": {"from_call": 1, "key": "generation"}, "plane": {"body": 0, "face": 5}}} + ] + }, + { + "title": "A sketch on a datum plane 20 mm above XY", + "calls": [ + {"tool": "plane", "args": {"base": "XY", "offset": 20, "type": "offset"}}, + {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}} + ] + } + ], + "ids": true + } + }, + { + "id": "sketch_commit", + "name": "Sketch commit", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Commit the open sketch as a Sketch feature, as the sketch's Confirm does, and leave sketch mode.", + "details": "An empty sketch is refused and stays open. Reply: sketch_index, name, features (the new count) and its loops (closed_loops with the index extrude's loop takes, open_ends, defects, buildable).", + "params": [], + "examples": [ + { + "title": "A rectangle around a circle, committed as a sketch of two loops", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}]}}, + {"tool": "sketch_commit", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_cancel", + "name": "Sketch cancel", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Discard the open sketch and leave sketch mode.", + "details": "", + "params": [], + "examples": [ + { + "title": "Discard a sketch with a rectangle drawn", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_cancel", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_add", + "name": "Sketch add", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Add entities or shapes to the open sketch: `entities` (a list), or one item's fields beside `type`, or `rect`.", + "details": "Entities: line {p0, p1}, circle {center, radius}, arc {center, radius, start_angle, end_angle}, point {p}. Shapes, built as their drawing tools build them: polygon {center, sides, radius (to a vertex) or across_flats, angle (of that vertex, or of the first edge's midpoint)}, slot {c0, c1, width}, ellipse {center, radius (semi-major), rminor, rotation}, ellipse_arc {the ellipse's fields, start_angle, end_angle: parametric, counter-clockwise}, spline {ctrl: 2 or more poles}. Each item of entities may carry its own construction: true; the top-level construction applies only to rect and to the single-type form. Points are [x, y] in the sketch plane (mm); angles are radians, or degrees as start_angle_deg and the like. A polygon is lines; its side count is not kept once committed. Reply: first_index, added, shapes [{first, count}] per item, entities, dof.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "entity or shape objects, each with a type"}, + {"name": "type", "type": "string", "default": "", "enum": ["line", "arc", "circle", "point", "polygon", "slot", "ellipse", "ellipse_arc", "spline"], "description": "one item, its fields beside it"}, + {"name": "rect", "type": "array", "default": [], "description": "[x0, y0, x1, y1]: a closed rectangle of four lines"}, + {"name": "start_angle", "type": "number", "unit": "rad", "default": 0, "description": "arc start, counter-clockwise from the plane's x axis"}, + {"name": "end_angle", "type": "number", "unit": "rad", "default": 0}, + {"name": "construction", "type": "boolean", "default": false, "description": "for rect and the single-type form; an item of entities carries its own"} + ], + "examples": [ + { + "title": "A 30 x 20 mm rectangle", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}} + ] + }, + { + "title": "A hexagon 10 mm across flats inside a circle", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 12, "type": "circle"}, {"across_flats": 10, "center": [0, 0], "sides": 6, "type": "polygon"}]}} + ] + }, + { + "title": "A quarter arc given in degrees, and a slot", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "end_angle_deg": 90, "radius": 20, "start_angle_deg": 0, "type": "arc"}, {"c0": [-10, -20], "c1": [10, -20], "type": "slot", "width": 6}]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_select", + "name": "Sketch select", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Select sketch entities by index; an empty list clears the selection.", + "details": "Reply: selected.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "entity indices"} + ], + "examples": [ + { + "title": "Select a rectangle's two long sides", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_select", "args": {"entities": [0, 2]}} + ] + }, + { + "title": "Clear the selection", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_select", "args": {"entities": [0]}}, + {"tool": "sketch_select", "args": {"entities": []}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_delete", + "name": "Sketch delete", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Delete sketch entities.", + "details": "Reply: removed, entities.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "entity indices; omit for the selection"} + ], + "examples": [ + { + "title": "Delete a rectangle's top side", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_delete", "args": {"entities": [2]}} + ] + }, + { + "title": "Delete the selected sides", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_select", "args": {"entities": [1, 3]}}, + {"tool": "sketch_delete", "args": {}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_construction", + "name": "Sketch construction", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": true, + "summary": "Toggle construction on sketch entities.", + "details": "Reply: changed.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "entity indices; omit for the selection"} + ], + "examples": [ + { + "title": "A centre line across a rectangle, made construction so it splits no loop", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, -10], "p1": [0, 10], "type": "line"}]}}, + {"tool": "sketch_construction", "args": {"entities": [4]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_offset", + "name": "Sketch offset", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Add an offset copy of sketch lines, arcs and circles.", + "details": "Reply: first_index, added, dof.", + "params": [ + {"name": "distance", "type": "number", "unit": "mm", "description": "signed offset"}, + {"name": "entities", "type": "array", "default": [], "description": "entity indices; omit for the selection, else every entity"} + ], + "examples": [ + { + "title": "A rectangle's 2 mm inner wall", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_offset", "args": {"distance": 2}} + ] + }, + { + "title": "A circle grown 2 mm by a negative offset", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 5, "type": "circle"}]}}, + {"tool": "sketch_offset", "args": {"distance": -2, "entities": [0]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_mirror", + "name": "Sketch mirror", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Add a mirrored copy of sketch entities about the line through axis_a and axis_b.", + "details": "Reply: first_index, added, dof.", + "params": [ + {"name": "axis_a", "type": "array", "default": [0, 0], "description": "[x, y] in the sketch plane, mm"}, + {"name": "axis_b", "type": "array", "default": [0, 1], "description": "[x, y] in the sketch plane, mm"}, + {"name": "entities", "type": "array", "default": [], "description": "entity indices; omit for the selection, else every entity"} + ], + "examples": [ + { + "title": "A circle mirrored across the sketch's y axis", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [10, 0], "radius": 3, "type": "circle"}]}}, + {"tool": "sketch_mirror", "args": {"axis_a": [0, 0], "axis_b": [0, 1]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_heal", + "name": "Sketch heal", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Weld sketch endpoints that nearly meet and constrain them coincident, so loops are closed by construction.", + "details": "Reply: welded and the loops.", + "params": [ + {"name": "tolerance", "type": "number", "unit": "mm", "default": 0.001}, + {"name": "ignore_construction", "type": "boolean", "default": true} + ], + "examples": [ + { + "title": "Close a triangle's 0.05 mm gap", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [20, 0], "type": "line"}, {"p0": [20, 0.05], "p1": [20, 10], "type": "line"}, {"p0": [20, 10], "p1": [0, 0], "type": "line"}]}}, + {"tool": "sketch_heal", "args": {"tolerance": 0.1}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_set_value", + "name": "Sketch set value", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Set the dimension of the selected sketch entities, as the value field does.", + "details": "A line's length, a circle's diameter, an arc's radius, or the angle or distance between two. Select them with sketch_select first. Reply: kind, before, value, dof and the loops.", + "params": [ + {"name": "value", "type": "number", "description": "mm, or degrees for an angle"} + ], + "examples": [ + { + "title": "A rectangle's bottom side made 40 mm long", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_select", "args": {"entities": [0]}}, + {"tool": "sketch_set_value", "args": {"value": 40}} + ] + }, + { + "title": "A circle's diameter set to 12 mm", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}]}}, + {"tool": "sketch_select", "args": {"entities": [0]}}, + {"tool": "sketch_set_value", "args": {"value": 12}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_fillet", + "name": "Sketch fillet", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Round the corner of two lines of the open sketch, as the Fillet tool does.", + "details": "Both lines are cut back and joined by an arc of `radius`, bound coincident and tangent to them; constraints the sharp corner held are released. Reply: entity (the arc), lines, released_constraints, entities, constraints, dof, solve_ok.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "the two line indices; omit for the selection"}, + {"name": "radius", "type": "number", "unit": "mm"} + ], + "examples": [ + { + "title": "A rectangle's corner rounded to 3 mm", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_fillet", "args": {"entities": [0, 1], "radius": 3}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_chamfer", + "name": "Sketch chamfer", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Bevel the corner of two lines of the open sketch, as the Chamfer tool does.", + "details": "Both lines are cut back by `distance` from the corner and joined by a line bound coincident to them. Reply: entity (the new line), lines, released_constraints, entities, constraints, dof, solve_ok.", + "params": [ + {"name": "entities", "type": "array", "default": [], "description": "the two line indices; omit for the selection"}, + {"name": "distance", "type": "number", "unit": "mm", "description": "setback along each line"} + ], + "examples": [ + { + "title": "A rectangle's corner bevelled 2 mm back", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_chamfer", "args": {"distance": 2, "entities": [1, 2]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_trim", + "name": "Sketch trim", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Trim or extend the open sketch's entity nearest `at`, as a Trim or Extend click there does.", + "details": "Trim: a line or an arc is cut back from its end nearer `at` to the first crossing with another entity beyond `at`; a circle loses the part between the crossings either side of `at` and becomes an arc. With extend, as an Extend click: the line's or arc's end nearer `at` runs out to the next entity. The entity's constraints are released. Reply: entity, geometry (its new fields), released_constraints, entities, dof.", + "params": [ + {"name": "at", "type": "array", "description": "[x, y] in the sketch plane, mm: a point on the part to cut, or near the end to extend"}, + {"name": "extend", "type": "boolean", "default": false}, + {"name": "tolerance", "type": "number", "unit": "mm", "default": 0.05, "description": "how far from `at` the entity may be"} + ], + "examples": [ + { + "title": "A line cut back to the line crossing it", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [-10, 0], "p1": [10, 0], "type": "line"}, {"p0": [0, -5], "p1": [0, 5], "type": "line"}]}}, + {"tool": "sketch_trim", "args": {"at": [5, 0]}} + ] + }, + { + "title": "A line extended down to the line below it", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [-10, 0], "p1": [10, 0], "type": "line"}, {"p0": [0, 3], "p1": [0, 8], "type": "line"}]}}, + {"tool": "sketch_trim", "args": {"at": [0, 3], "extend": true}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_transform", + "name": "Sketch transform", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Move, rotate, scale or array entities of the open sketch, as the transform tools' Confirm does.", + "details": "move {dx, dy}, rotate {angle, pivot} and scale {scale, pivot} change the entities and release the constraints that no longer hold. array {dx, dy, count} adds copies stepped by dx, dy; polar_array {pivot, angle, count} adds copies every angle/count about pivot (angle is the whole sweep, default 360 degrees). count includes the original, and each copy is bound to its source (equal length and parallel, or its radius). pivot defaults to the entities' centroid. Angles are radians, or degrees as angle_deg. Reply: moved and released_constraints, or first_index, added and bound; pivot; entities, dof.", + "params": [ + {"name": "op", "type": "string", "enum": ["move", "rotate", "scale", "array", "polar_array"]}, + {"name": "entities", "type": "array", "default": [], "description": "entity indices; omit for the selection"}, + {"name": "dx", "type": "number", "unit": "mm", "default": 0}, + {"name": "dy", "type": "number", "unit": "mm", "default": 0}, + {"name": "angle", "type": "number", "unit": "rad", "default": null, "nullable": false, "description": "or angle_deg"}, + {"name": "scale", "type": "number", "default": null, "nullable": false}, + {"name": "count", "type": "integer", "default": null, "nullable": false, "min": 2, "max": 1000}, + {"name": "pivot", "type": "array", "default": null, "nullable": false, "description": "[x, y] in the sketch plane, mm"} + ], + "examples": [ + { + "title": "A circle moved 10 mm along x", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 3, "type": "circle"}]}}, + {"tool": "sketch_transform", "args": {"dx": 10, "entities": [0], "op": "move"}} + ] + }, + { + "title": "Six holes on a 40 mm bolt circle", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [20, 0], "radius": 3, "type": "circle"}]}}, + {"tool": "sketch_transform", "args": {"angle_deg": 360, "count": 6, "entities": [0], "op": "polar_array", "pivot": [0, 0]}} + ] + }, + { + "title": "A line turned 30 degrees about its start", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [20, 0], "type": "line"}]}}, + {"tool": "sketch_transform", "args": {"angle_deg": 30, "entities": [0], "op": "rotate", "pivot": [0, 0]}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_constrain", + "name": "Sketch constrain", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Add a constraint to the open sketch, as a CONSTRAIN bar button does (sketch_set_value is the value field, V).", + "details": "With `entities`, else the selection, the button's own rules choose the points, and a value it would ask for is `value` or the current one. With `refs` the references are taken as written, in sketch_constraints' form: {entity, role} for a point (role p0, p1 or center; entity also \"origin\") and {entity} for a whole entity (also \"x_axis\", \"y_axis\"). distance, lock_x, lock_y, point_on_line and point_on_object have no button and take refs. A constraint the sketch cannot solve with is rolled back and the call fails. Reply: added (indices), items, constraints, dof, solve_ok.", + "params": [ + {"name": "type", "type": "string", "enum": ["fix", "coincident", "horizontal", "vertical", "distance", "lock_x", "lock_y", "equal_length", "parallel", "perpendicular", "concentric", "tangent", "midpoint", "symmetric", "angle", "radius", "diameter", "point_on_line", "point_on_object", "equal_radius", "collinear", "distance_x", "distance_y", "symmetric_about_y", "symmetric_about_x", "equal"], "description": "\"equal\" is the Equal button: equal length, or equal radius for two curves"}, + {"name": "entities", "type": "array", "default": [], "description": "1 to 3 entity indices; omit for the selection"}, + {"name": "refs", "type": "array", "default": [], "description": "[{entity, role?}], instead of entities"}, + {"name": "value", "type": "number", "default": null, "description": "mm, or degrees for an angle"} + ], + "examples": [ + { + "title": "A sloping line made horizontal", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [10, 2], "type": "line"}]}}, + {"tool": "sketch_constrain", "args": {"entities": [0], "type": "horizontal"}} + ] + }, + { + "title": "Two circles given equal radii", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"center": [0, 0], "radius": 4, "type": "circle"}, {"center": [15, 0], "radius": 6, "type": "circle"}]}}, + {"tool": "sketch_constrain", "args": {"entities": [0, 1], "type": "equal"}} + ] + }, + { + "title": "A line's ends held 25 mm apart, named by refs", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"entities": [{"p0": [0, 0], "p1": [10, 2], "type": "line"}]}}, + {"tool": "sketch_constrain", "args": {"refs": [{"entity": 0, "role": "p0"}, {"entity": 0, "role": "p1"}], "type": "distance", "value": 25}} + ] + } + ], + "ids": false + } + }, + { + "id": "sketch_unconstrain", + "name": "Sketch unconstrain", + "slot": null, + "action": null, + "gui": false, + "tool": { + "access": "sketch", + "ok_false": false, + "summary": "Delete a constraint of the open sketch, as its row's delete button does; the constraints after it move down one index.", + "details": "Reply: removed, constraints, dof, solve_ok.", + "params": [ + {"name": "index", "type": "integer", "description": "sketch_constraints' items[].index"} + ], + "examples": [ + { + "title": "A rectangle's bottom side freed from horizontal", + "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_constraints", "args": {}}, + {"tool": "sketch_unconstrain", "args": {"index": 4}} + ] + } + ], + "ids": false + } } ], "chrome_only": { diff --git a/scripts/check_operation_calls.py b/scripts/check_operation_calls.py index 18efc44ba7..10abc81aab 100644 --- a/scripts/check_operation_calls.py +++ b/scripts/check_operation_calls.py @@ -27,8 +27,8 @@ import sys REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASELINE = "scripts/operation_calls_baseline.txt" -# The callers: the command runners, the tools (the CAD tools are one entry point of their own behind -# call_cad_tool) and the plugin API. +# The callers: the command runners, the tools (the Design commands, whose functions are the Design tab's own +# entry points, are not among them) and the plugin API. CALLERS = ["src/slic3r/GUI/NativeCommands.cpp", "src/slic3r/GUI/Mcp/McpTools*.cpp", "src/slic3r/plugin/host/*.cpp"] NOT_CALLERS = {"src/slic3r/GUI/Mcp/McpToolsCad.cpp"} diff --git a/scripts/operation_calls_baseline.txt b/scripts/operation_calls_baseline.txt index 100f4e5d86..553ff4e057 100644 --- a/scripts/operation_calls_baseline.txt +++ b/scripts/operation_calls_baseline.txt @@ -10,9 +10,7 @@ # calls the owner's method, which asks the person what an operation would be told. plater->load_project(); plater->load_project(from_path(*path)); -plater->save_project(false); plater->save_project(true); -plater->new_project(); plater->export_stl(); plater->export_core_3mf(); plater->export_gcode_3mf(all); @@ -43,6 +41,12 @@ tab->select_preset(selected); # The undo step of a tool whose function has one automation entry point (set_height_ranges). plater.take_snapshot("Edit height ranges"); +[src/slic3r/GUI/Mcp/McpToolsProject.cpp] +# The asking path of a command, its person's form: new_project and save_project called with no arguments +# call the owner's method, which asks the person what an operation would be told. +plater->new_project(); +plater->save_project(false); + [src/slic3r/GUI/Mcp/McpToolsScene.cpp] # The undo step of a tool whose function has one automation entry point (transform). plater.take_snapshot("Transform object"); diff --git a/src/libslic3r/CAD/CadDocument.cpp b/src/libslic3r/CAD/CadDocument.cpp index 24b2113201..dfb9bd8c7d 100644 --- a/src/libslic3r/CAD/CadDocument.cpp +++ b/src/libslic3r/CAD/CadDocument.cpp @@ -4176,11 +4176,11 @@ bool CadDocument::recompute() } if (built.empty() && any_solid_feature) { error = _u8L("no solid-producing features"); return false; } - // A feature that leaves a body with a null shape must fail loudly. Until this existed, - // recompute() returned true and the document kept advertising the body: describe_scene - // counted it, error was empty, and only mass_properties on that specific body revealed - // anything was wrong. Returning false hands the caller its normal rollback path, so the - // operation that destroyed the body is undone rather than committed. + // A feature that leaves a body with a null shape fails the rebuild loudly. Were recompute() to + // return true, the document would go on listing the body: describe_scene would count it, error + // would be empty, and only mass_props on that body would show anything was wrong. Returning + // false hands the caller its normal rollback path, so the operation that destroyed the body is + // undone rather than committed. for (size_t i = 0; i < built.size(); ++i) { if (!built[i].shape.IsNull()) continue; const int src = built[i].source_feature; diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index e11dd6078c..01907a58ee 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -145,6 +145,8 @@ set(SLIC3R_GUI_SOURCES GUI/ActionRegistry.hpp GUI/ActionReplayDialog.cpp GUI/ActionReplayDialog.hpp + GUI/CommandCatalog.cpp + GUI/CommandCatalog.hpp GUI/NativeCommands.cpp GUI/NativeCommands.hpp GUI/Operations/ExportOps.cpp @@ -165,12 +167,15 @@ set(SLIC3R_GUI_SOURCES GUI/Mcp/CanvasTarget.hpp GUI/Mcp/JobRegistry.cpp GUI/Mcp/JobRegistry.hpp + GUI/Mcp/McpArguments.cpp GUI/Mcp/McpCore.cpp GUI/Mcp/McpCore.hpp GUI/Mcp/McpHttpServer.cpp GUI/Mcp/McpHttpServer.hpp GUI/Mcp/McpJournal.cpp GUI/Mcp/McpJournal.hpp + GUI/Mcp/McpPersonContext.cpp + GUI/Mcp/McpPersonContext.hpp GUI/Mcp/McpPersonRun.cpp GUI/Mcp/McpPersonRun.hpp GUI/Mcp/McpProtocol.cpp @@ -966,7 +971,7 @@ set(SLIC3R_GUI_SOURCES Utils/wxInspectorPlugins/Registration.hpp ) -# Design/CAD tab: parametric sketch UI, its gizmos, and the MCP server's CAD tools. +# Design/CAD tab: parametric sketch UI, its gizmos, and the MCP server's Design commands. # All of it sits behind SLIC3R_CAD and links the CAD kernel in libslic3r. if (SLIC3R_CAD) list(APPEND SLIC3R_GUI_SOURCES diff --git a/src/slic3r/GUI/ActionRegistry.cpp b/src/slic3r/GUI/ActionRegistry.cpp index fdaac5db5d..5b7aa57ecd 100644 --- a/src/slic3r/GUI/ActionRegistry.cpp +++ b/src/slic3r/GUI/ActionRegistry.cpp @@ -1,5 +1,6 @@ #include "ActionRegistry.hpp" +#include "CommandCatalog.hpp" #include "GUI.hpp" #include "GUI_App.hpp" #include "I18N.hpp" @@ -14,6 +15,11 @@ #include "SettingsIndex.hpp" #include "Tab.hpp" #include "slic3r/plugin/PluginManager.hpp" +#ifdef SLIC3R_CAD +#include "CAD/DesignOffer.hpp" +#include "CAD/DesignPanel.hpp" +#include "Mcp/McpToolsCad.hpp" +#endif #include #include @@ -36,8 +42,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -59,6 +67,61 @@ std::vector cap_favourites(const std::vector& ids, siz return out; } +bool is_design_tile_id([[maybe_unused]] const std::string& id) +{ +#ifdef SLIC3R_CAD + for (const DesignTool& t : kDesignTools) + if (t.action != nullptr && AppAction::compose_id(kCommandPrefix, t.id, kOrcaSourceKey) == id) + return true; +#endif + return false; +} + +void prune_favourites(const std::vector& favs, const std::function& live, + std::vector& stored, std::vector& shown) +{ + stored.clear(); + shown.clear(); + for (const std::string& id : favs) { + if (live(id)) { + stored.push_back(id); + if (shown.size() < ActionRegistry::kFavLimit) + shown.push_back(id); + } else if (is_design_tile_id(id)) { + stored.push_back(id); + } + } +} + +bool add_favourite(std::vector& favs, const std::string& id, const std::function& live) +{ + std::vector stored, shown; + prune_favourites(favs, live, stored, shown); + if (std::find(shown.begin(), shown.end(), id) != shown.end()) + return true; + // A full bar refuses a live pin past the tenth as it refuses a new one: the page shows neither as pinned. + if (shown.size() >= ActionRegistry::kFavLimit || favs.size() >= ActionRegistry::kFavStoredLimit) + return false; + if (std::find(favs.begin(), favs.end(), id) == favs.end()) + favs.push_back(id); + return true; +} + +std::vector reordered_favourites(std::vector stored, const std::vector& ids) +{ + std::vector moved; // the stored pins `ids` names, in its order + for (const std::string& id : ids) + if (std::find(stored.begin(), stored.end(), id) != stored.end() && std::find(moved.begin(), moved.end(), id) == moved.end()) + moved.push_back(id); + std::vector places; // where they are stored, in the stored order + for (std::size_t i = 0; i < stored.size(); ++i) + if (std::find(moved.begin(), moved.end(), stored[i]) != moved.end()) + places.push_back(i); + for (std::size_t k = 0; k < places.size(); ++k) + stored[places[k]] = moved[k]; + return stored; +} + namespace { constexpr const char* kConfigSection = "speed_dial"; @@ -169,7 +232,7 @@ struct PluginScriptAction : AppAction "). Its result arrives as a notification."; } - AppActionRunResult run(const std::string& /*param*/) const override + AppActionRunResult run(const nlohmann::json& /*args*/) const override { struct Outcome { @@ -246,7 +309,7 @@ struct PluginPageAction : AppAction // plugin filesystem icon path would not resolve to. } - AppActionRunResult run(const std::string& /*param*/) const override + AppActionRunResult run(const nlohmann::json& /*args*/) const override { MainFrame* mf = wxGetApp().mainframe; if (mf) @@ -364,7 +427,7 @@ struct SettingAction : AppAction this->required_mode = mode_in; } - AppActionRunResult run(const std::string& /*param*/) const override + AppActionRunResult run(const nlohmann::json& /*args*/) const override { wxGetApp().sidebar().jump_to_option(opt_key, type, category); return {AppActionRunResult::Level::Success}; @@ -413,8 +476,8 @@ struct PlateAction : AppAction this->automation_description = "Make plate " + std::to_string(index + 1) + " (index " + std::to_string(index) + ") the current plate."; } - AppActionRunResult run(const std::string& /*param*/) const override - { return NativeCommands::run("plate_goto", std::to_string(plate_index)); } + AppActionRunResult run(const nlohmann::json& /*args*/) const override + { return NativeCommands::run("plate_goto", {{"plate", plate_index}}); } }; // A dynamic "Open recent project " action, one per recent project file, rebuilt on every @@ -438,7 +501,7 @@ struct RecentProjectAction : AppAction this->automation_description = "Open the recent project " + file_path + "."; } - AppActionRunResult run(const std::string& /*param*/) const override + AppActionRunResult run(const nlohmann::json& /*args*/) const override { if (MainFrame* mf = wxGetApp().mainframe; mf) mf->open_recent_project(size_t(-1), wxString::FromUTF8(file_path)); @@ -544,12 +607,12 @@ void ActionRegistry::init() upsert(std::move(action)); } - // Built-in palette commands (Save/Load, Preferences, Mode switch, Slice/Preview, Go to layer). - // Register after plugins so the plugin ids win on any (unlikely) id collision - ids are distinct - // by prefix, so this is order-independent. The catalog (and its thin AppAction adapter) lives in - // NativeCommands; the registry only stores and dispatches the result. - for (const NativeCommand& c : NativeCommands::catalog()) - upsert(NativeCommands::make_action(c)); + // Built-in palette commands (Save/Load, Preferences, Mode switch, Slice/Preview, Go to layer): the + // catalog's commands with a tile, and no others. Register after plugins so the plugin ids win on any + // (unlikely) id collision - ids are distinct by prefix, so this is order-independent. The catalog (and + // its thin AppAction adapter) lives in NativeCommands; the registry only stores and dispatches the result. + for (const NativeCommand* c : NativeCommands::palette_commands(NativeCommands::instance())) + upsert(NativeCommands::make_action(*c)); } void ActionRegistry::relocalize_builtins() @@ -569,8 +632,8 @@ void ActionRegistry::relocalize_builtins() for (const std::string& id : stale) remove(id); - for (const NativeCommand& c : NativeCommands::catalog()) - upsert(NativeCommands::make_action(c)); + for (const NativeCommand* c : NativeCommands::palette_commands(NativeCommands::instance())) + upsert(NativeCommands::make_action(*c)); } void ActionRegistry::refresh_source(const std::string& plugin_key, ActionChange change) @@ -661,7 +724,7 @@ void ActionRegistry::remove(const std::string& id) void ActionRegistry::seed_state(AppAction& a) const { // Favourites carry the quick-launch order, so the persisted list is the source of truth - // (not re-derived from the frecency sort). Cap it so stale configs can't exceed kFavLimit. + // (not re-derived from the frecency sort). favourite_ids() caps it at kFavStoredLimit. auto favs = favourite_ids(); a.favourite = std::find(favs.begin(), favs.end(), a.id()) != favs.end(); @@ -695,9 +758,16 @@ const AppAction* ActionRegistry::by_id(const std::string& id) const AppAction* ActionRegistry::find(const std::string& id) { return const_cast(by_id(id)); } +const AppAction* ActionRegistry::find_live(const std::string& id) +{ + assert(wxThread::IsMain()); + materialize_live(); + return by_id(id); +} + // ---- dispatch + write-through ---------------------------------------------- -AppActionRunResult ActionRegistry::run(const std::string& id, const std::string& param, bool record_stats) +AppActionRunResult ActionRegistry::run(const std::string& id, const nlohmann::json& args, bool record_stats) { assert(wxThread::IsMain()); auto it = m_actions.find(id); @@ -707,7 +777,7 @@ AppActionRunResult ActionRegistry::run(const std::string& id, const std::string& // nested event loop; a queued source refresh can erase the entry while the // keep-alive preserves the action until run returns. std::shared_ptr keep = it->second; - AppActionRunResult o = keep->run(param); + AppActionRunResult o = keep->run(args); if (o.level == AppActionRunResult::Level::Busy || !record_stats) return o; @@ -733,14 +803,13 @@ bool ActionRegistry::set_favourite(const std::string& id, bool on) assert(wxThread::IsMain()); // Start from the capped, deduped list so a persisted config can never be written back larger. auto favs = favourite_ids(); - auto it = std::find(favs.begin(), favs.end(), id); - if (on && it == favs.end()) { - if (favs.size() >= kFavLimit) + if (on) { + // The live actions are the ones the open Speed Dial shows, as snapshot() materialised them. + if (!add_favourite(favs, id, [this](const std::string& pin) { return m_actions.count(pin) != 0; })) return false; // bar is full - the caller surfaces a hint - favs.push_back(id); - } - if (!on && it != favs.end()) + } else if (auto it = std::find(favs.begin(), favs.end(), id); it != favs.end()) { favs.erase(it); + } write_section("favourite_actions", nlohmann::json(favs)); if (AppAction* live = find(id)) live->favourite = on; @@ -750,26 +819,25 @@ bool ActionRegistry::set_favourite(const std::string& id, bool on) std::vector ActionRegistry::favourite_ids() const { assert(wxThread::IsMain()); - // Enforce the cap + dedupe on read so the persisted order can never grow past kFavLimit, even from an older config. - return cap_favourites(read_string_array("favourite_actions"), kFavLimit); + // Enforce the cap + dedupe on read so the persisted order can never grow past kFavStoredLimit, even from a + // corrupt config. + return cap_favourites(read_string_array("favourite_actions"), kFavStoredLimit); +} + +std::vector ActionRegistry::favourites_bar() const +{ + assert(wxThread::IsMain()); + std::vector stored, shown; + prune_favourites(favourite_ids(), [this](const std::string& id) { return m_actions.count(id) != 0; }, stored, shown); + return shown; } void ActionRegistry::reorder_favourites(const std::vector& ids) { assert(wxThread::IsMain()); - auto cur = read_string_array("favourite_actions"); - std::vector next; - // keep the requested order, but only ids that are actually favourites (guard a bad payload) - for (const auto& id : ids) - if (std::find(cur.begin(), cur.end(), id) != cur.end() && std::find(next.begin(), next.end(), id) == next.end()) - next.push_back(id); - // why: don't drop favourites the page omitted (e.g. pins with no live action hidden from the bar) - for (const auto& id : cur) - if (std::find(next.begin(), next.end(), id) == next.end()) - next.push_back(id); - // never write the bar back larger than the quick-launch slots - next = cap_favourites(next, kFavLimit); - write_section("favourite_actions", nlohmann::json(next)); + // Only ids that are favourites move (guard a bad payload), and the pins the page omitted, which its bar + // does not show, keep their places. + write_section("favourite_actions", nlohmann::json(reordered_favourites(favourite_ids(), ids))); } void ActionRegistry::materialize_setting_actions() @@ -941,6 +1009,49 @@ void ActionRegistry::materialize_recent_project_actions() drop_stale(m_actions, kRecentProjectPrefix, seen); } +void ActionRegistry::materialize_design_actions() +{ + assert(wxThread::IsMain()); +#ifdef SLIC3R_CAD + // The tiles act on the Design tab a person is looking at, so they are there only while it is shown, and + // only those of the mode it is in, the tools its right-click menu offers there; none while the CAD feature + // is off, though the tab stays until a restart (Mcp::design_tiles()). The catalog holds the Design commands + // only when the CAD feature was on at startup. + const MainFrame* frame = wxTheApp ? wxGetApp().mainframe : nullptr; + const DesignPanel* panel = frame != nullptr ? frame->shown_design_panel() : nullptr; + std::unordered_set seen; + if (panel != nullptr) { + nlohmann::json stats; + std::vector favs; + load_persisted(stats, favs); + for (const NativeCommand* command : + Mcp::design_tiles(NativeCommands::instance(), panel->mcp_sketch_map_applies(), wxGetApp().is_enable_cad_feature())) { + std::unique_ptr action = NativeCommands::make_action(*command); + const std::string id = action->id(); + seed_from(stats, favs, id, *action); + seen.insert(id); + m_actions.insert_or_assign(id, std::shared_ptr(std::move(action))); + } + } + // Drop the tiles of a tab no longer shown, of the other mode, or of a CAD feature turned off. Their ids are + // command ids like any other tile's, so they are told apart by their group. + for (auto it = m_actions.begin(); it != m_actions.end();) { + const AppAction& a = *it->second; + if (a.kind == AppActionKind::Command && a.group_en == kDesignGroup && seen.count(it->first) == 0) + it = m_actions.erase(it); + else + ++it; + } +#endif +} + +void ActionRegistry::materialize_live() +{ + materialize_plate_actions(); + materialize_recent_project_actions(); + materialize_design_actions(); +} + bool ActionRegistry::should_ask(const std::string& id) const { assert(wxThread::IsMain()); @@ -979,8 +1090,7 @@ nlohmann::json ActionRegistry::snapshot() // live plate list are materialised before we serialise the pool (tabs_list is built by the time // the palette opens). materialize_setting_actions(); - materialize_plate_actions(); - materialize_recent_project_actions(); + materialize_live(); std::vector sorted; sorted.reserve(m_actions.size()); @@ -1007,16 +1117,15 @@ nlohmann::json ActionRegistry::snapshot() // why: favourites is the ORDERED pin list - it must come from favourite_actions // as stored, not be re-derived from the frecency-sorted actions (that would // reorder the favourites bar). Drop pins with no live action (an option hidden by the - // current mode, an unloaded plugin, a gone plate/project) and persist the pruned list, so - // invisible pins can't silently fill the quick-launch cap. Order is preserved. - std::vector favs = favourite_ids(); - std::vector live_favs; - live_favs.reserve(favs.size()); - for (const auto& id : favs) - if (m_actions.count(id)) - live_favs.push_back(id); - if (live_favs.size() != favs.size()) - write_section("favourite_actions", nlohmann::json(live_favs)); + // current mode, an unloaded plugin, a gone plate/project) and persist the pruned list. Order is + // preserved. A Design tile's pin is kept but not shown while its tile is not live (another tab, + // the other mode): the person pinned it to use in the Design tab. The bar is the first + // kFavLimit live pins, so a pin it does not show never fills it. + const std::vector favs = favourite_ids(); + std::vector stored_favs, live_favs; + prune_favourites(favs, [this](const std::string& id) { return m_actions.count(id) != 0; }, stored_favs, live_favs); + if (stored_favs.size() != favs.size()) + write_section("favourite_actions", nlohmann::json(stored_favs)); nlohmann::json favourites(live_favs); // Recent = the last-N launched actions by recency (only actions with a run history). N is a @@ -1049,8 +1158,7 @@ nlohmann::json ActionRegistry::snapshot() nlohmann::json ActionRegistry::describe(const Query& query) { assert(wxThread::IsMain()); - materialize_plate_actions(); - materialize_recent_project_actions(); + materialize_live(); if (query.include_settings) materialize_setting_actions(); @@ -1103,8 +1211,10 @@ nlohmann::json ActionRegistry::describe(const Query& query) description = a.tooltip.substr(0, 300); if (!description.empty()) j["description"] = description; - if (a.param_type != "none") - j["param"] = {{"type", a.param_type}, {"help", a.param_help}}; + if (a.input_schema.is_object() && !a.input_schema.value("properties", nlohmann::json::object()).empty()) + j["input_schema"] = a.input_schema; + if (!a.command.empty()) + j["command"] = a.command; if (a.completes_in_background) j["completes"] = "export"; items.push_back(std::move(j)); diff --git a/src/slic3r/GUI/ActionRegistry.hpp b/src/slic3r/GUI/ActionRegistry.hpp index f870b4fef4..f7a2eee3d4 100644 --- a/src/slic3r/GUI/ActionRegistry.hpp +++ b/src/slic3r/GUI/ActionRegistry.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -40,8 +41,8 @@ struct AppActionRunResult // at its level all the same, and automation reports the run as failed. bool done = true; // For automation only: a JSON object saying what the command did that its message does not - // (the new object order, the object an Assemble made). run_action adds its fields to the reply; - // the palette never shows it. + // (the new object order, the object an Assemble made). An automated call's reply has its fields + // (NativeCommands::from_run_result()); the palette never shows it. std::string reply; // The operation's refusal that `message` words in the UI's language, when the command ran an // operation that refused: automation replies with its English text and its code. @@ -112,18 +113,20 @@ struct AppAction std::string full_label_en; // Full wiki URL, when the action has one (SettingActions whose row declared a label_path). std::string help_url; - // For automation (MCP, scripts): what the action does in English, what `param` means - // ("none", "percent", "tab", "path", "index", "text") and whether its effect finishes after - // run() returns (an export that runs in the background). Not shown in the palette. - std::string automation_description; - std::string param_type = "none"; - std::string param_help; - bool completes_in_background = false; + // For automation (MCP, scripts): what the action does in English, the arguments it takes (a JSON + // Schema; none for most actions) and whether its effect finishes after run() returns (an export that + // runs in the background). Not shown in the palette. + std::string automation_description; + nlohmann::json input_schema; + bool completes_in_background = false; + // The catalog key of a command's tile (NativeCommands), whose own function run_action runs; empty for + // every other action. + std::string command; virtual ~AppAction() = default; - // Re-resolves + runs (UI thread). `param` carries an optional per-run argument for - // commands (e.g. a layer percentage); plugins ignore it. - virtual AppActionRunResult run(const std::string& param = {}) const = 0; + // Re-resolves + runs (UI thread). `args` are a command's arguments (the layer percentage of Go to + // layer); the other actions take none. + virtual AppActionRunResult run(const nlohmann::json& args = nlohmann::json::object()) const = 0; protected: // The definition is constructor-set and immutable. Refreshes replace an action @@ -155,6 +158,8 @@ private: // action re-keys together. inline constexpr const char* kOrcaSourceKey = "orca"; inline constexpr const char* kOrcaSourceName = "OrcaSlicer"; +// The prefix of a catalog command's tile id, "orca_command::orca" (NativeCommands::make_action()). +inline constexpr const char* kCommandPrefix = "orca_command"; // True when a setting at `setting_mode` cannot be edited in `current_mode` and the UI must switch // first. Developer settings are handled as a separate prompt by the Speed Dial. @@ -164,9 +169,33 @@ inline bool requires_mode_switch(ConfigOptionMode setting_mode, ConfigOptionMode } // Cap + dedupe a persisted favourite-id list, preserving first-occurrence order. A stale or -// hand-edited config must never grow the quick-launch bar past `limit`, and a duplicated id must collapse to its first pin. +// hand-edited config must never grow the stored list past `limit`, and a duplicated id must collapse to its first pin. std::vector cap_favourites(const std::vector& ids, size_t limit); +// Whether `id` is the id of a Design tab tile, the tile of a Design command whose entry has an action. Such a +// tile is live only while that tab is shown, in its entry's mode. The Design table tells it apart, so it does +// even when the catalog holds no Design command (the CAD feature off at startup). A build without CAD has no +// table, and there it is never one. +bool is_design_tile_id(const std::string& id); + +// The pins snapshot() keeps, in their order: `stored` gets those with a live action (`live`) and the Design +// tab's whose tile is not live now (is_design_tile_id()), which the person pinned in that tab and keeps when +// the Speed Dial opens elsewhere; `shown`, the bar, gets the first ActionRegistry::kFavLimit live ones. A live +// pin past them stays stored and comes onto the bar once a pin before it is unpinned. Any other pin with no live +// action is dropped. +void prune_favourites(const std::vector& favs, const std::function& live, + std::vector& stored, std::vector& shown); + +// Pins `id` at the end of `favs`, the stored pins, unless the bar is full: it shows kFavLimit pins, counted as +// prune_favourites() shows them, so a pin that is not live takes no place on it. False, leaving `favs` as it is, +// when it is full or `favs` holds ActionRegistry::kFavStoredLimit pins; a pin already on the bar stays where it is. +bool add_favourite(std::vector& favs, const std::string& id, const std::function& live); + +// `stored` in the order the Speed Dial page asks for, which sends the pins its bar shows: the places those pins +// hold in `stored` take them in the order of `ids`, and every other pin (one the bar does not show) keeps its +// place. An id that is not stored is ignored, and one given twice counts once. `stored` holds no id twice. +std::vector reordered_favourites(std::vector stored, const std::vector& ids); + // One action as the Speed Dial page receives it. Each English alias (title_en, group_en, source_en, // full_label_en) is sent only when it is non-empty and differs from its localized counterpart, so an // English UI receives none and searches exactly the displayed text. @@ -180,9 +209,11 @@ nlohmann::json action_json(const AppAction& a); // 2. Loader load/unload callbacks route through refresh_source()/refresh_capability(), // which upsert()/remove() actions. The registry keeps the only action list and // restores persisted user state as actions arrive. -// 3. Dynamic built-in families (settings, plates, recent projects) are re-materialised at the top of -// snapshot(), because their membership follows live state (the current configs, plate list, recents). -// 4. Consumers use by_id(), snapshot(), and run() without knowing the source. +// 3. Dynamic built-in families (settings, plates, recent projects, the Design tab's tiles) are +// re-materialised at the top of snapshot(), because their membership follows live state (the current +// configs, plate list, recents, the tab shown and its mode); all but settings also at the top of +// describe() and of find_live(), an automated lookup by id. +// 4. Consumers use by_id(), find_live(), snapshot(), and run() without knowing the source. // // note: the static catalog lives in NativeCommands; the registry owns the pool, persistence and // dispatch, and materialises the dynamic families inline rather than behind a source interface. @@ -211,13 +242,24 @@ public: // Always-clean read surface. UI thread only. const AppAction* by_id(const std::string& id) const; + // The action `id` as the app is now: by_id() after the families whose membership follows live state + // (plates, recent projects, the Design tab's tiles) are re-materialised, for a caller that may have + // changed that state since the last snapshot() or describe(), such as an automated run_action after a + // sketch was opened or the tab switched. Settings are not, being thousands: snapshot() and describe() + // with include_settings materialise them. UI thread only. + const AppAction* find_live(const std::string& id); // Hard cap on the favourites bar: the numbered quick-launch slots (Alt/Option+1..9, 0). static constexpr size_t kFavLimit = 10; + // The stored pins at most. A pin is added only while the bar shows fewer than kFavLimit, so ordinary use + // stores at most kFavLimit for each set of live actions the bar is shown with (the Design tab's model, a + // sketch, and every other tab), thirty; reading the stored list cuts it to this, so a corrupt or + // hand-edited configuration cannot grow it. + static constexpr size_t kFavStoredLimit = 100; // Dispatch + write-through (registry is the only thing that touches AppConfig). Automation passes // record_stats = false so agent runs don't reorder the user's palette. - AppActionRunResult run(const std::string& id, const std::string& param = {}, bool record_stats = true); + AppActionRunResult run(const std::string& id, const nlohmann::json& args = nlohmann::json::object(), bool record_stats = true); // The catalog for agents: actions whose id, title, group, source or description contains `text` // (case-insensitive, English aliases included), sorted by group then title, one page of them as @@ -232,14 +274,17 @@ public: std::size_t limit = 50; }; nlohmann::json describe(const Query& query); - // Pin/unpin. Returns false when `on` would exceed kFavLimit (the bar is full) so the + // Pin/unpin. Returns false when `on` finds the bar full (add_favourite()) so the // caller can surface a "favourites are full" hint instead of silently dropping the pin. bool set_favourite(const std::string& id, bool on); - void reorder_favourites(const std::vector& ids); // persist a new bar order + void reorder_favourites(const std::vector& ids); // persist a new bar order (reordered_favourites()) - // Ordered pinned list (the source of truth), capped at kFavLimit and deduped, matching the - // visible bar the palette renders. + // Ordered pinned list (the source of truth), capped at kFavStoredLimit and deduped: the bar's pins and + // those it does not show (prune_favourites()). std::vector favourite_ids() const; + // The bar as it is now: the first kFavLimit live pins in stored order (prune_favourites()), the live actions + // being the ones the open Speed Dial shows, as snapshot() materialised them. UI thread. + std::vector favourites_bar() const; // Run-confirm gate, keyed by action id (per-action "don't ask again"). bool should_ask(const std::string& id) const; @@ -271,19 +316,30 @@ private: // (Re)materialise the current visible config settings as SettingActions from the live // searcher (respecting printer-tech + user-mode + visibility filtering), removing stale ones. - // Called at the top of snapshot() so the palette always reflects the current configs. + // Called at the top of snapshot(), so the palette always reflects the current configs, and by + // describe() when it is asked for settings. void materialize_setting_actions(); // (Re)materialise one "Go to Plate N" action per live plate, so the palette lists every plate // directly on each spawn (no second-phase picker). FFF-editor only; SLA/gcode modes have no - // plate UI, so nothing is materialised and stale ids are dropped. Called at the top of snapshot(). + // plate UI, so nothing is materialised and stale ids are dropped. Run by materialize_live(). void materialize_plate_actions(); // (Re)materialise one "Open recent project " action per recent project file, so the // palette lists every recent project and can load it by clicking. Keyed by file path (stable); - // files that no longer exist are skipped and their stale ids dropped. Called at the top of snapshot(). + // files that no longer exist are skipped and their stale ids dropped. Run by materialize_live(). void materialize_recent_project_actions(); + // (Re)materialise the Design tab's tiles: while the tab is shown with the CAD feature on, one per catalog + // command of group kDesignGroup with in_palette whose entry is offered in the tab's mode + // (Mcp::design_tiles()), titled as the right-click menu names its entry (the "Design" context) with the + // entry's icon; otherwise none. A build without CAD has none. + void materialize_design_actions(); + + // The three families above whose membership follows live state and is cheap to rebuild: plates, recent + // projects and the Design tab's tiles. snapshot(), describe() and find_live() run it first. + void materialize_live(); + // Loader callbacks (marshalled to the UI thread) land here. refresh_source rebuilds // one plugin's whole action set; refresh_capability touches a single capability. void refresh_source(const std::string& plugin_key, ActionChange change); diff --git a/src/slic3r/GUI/ActionReplayDialog.cpp b/src/slic3r/GUI/ActionReplayDialog.cpp index 7b8efaca17..5b907d470c 100644 --- a/src/slic3r/GUI/ActionReplayDialog.cpp +++ b/src/slic3r/GUI/ActionReplayDialog.cpp @@ -1,5 +1,6 @@ #include "ActionReplayDialog.hpp" +#include "CommandCatalog.hpp" #include "GLCanvas3D.hpp" #include "GUI.hpp" #include "GUI_App.hpp" @@ -116,7 +117,7 @@ std::string join(const json& items) return out; } -// The step's main line and, for a command with a param, the second line, from describe_step()'s `what`. +// The step's main line and, for a command given arguments, the second line, from describe_step()'s `what`. std::pair what_text(const json& what) { if (!what.is_object()) @@ -129,7 +130,9 @@ std::pair what_text(const json& what) if (kind == "command") { const std::string key = what.value("key", ""); const auto* command = NativeCommands::find(key); - return {command != nullptr ? _u8L(command->title.c_str()) : key, what.contains("param") ? value_text(what["param"]) : std::string()}; + // Titled as its tile is, so a Design command's step reads as the Design tab names its tool. + return {command != nullptr ? into_u8(NativeCommands::tile_title(*command)) : key, + what.contains("args") ? join(what["args"]) : std::string()}; } if (kind == "recent_project" || kind == "preset") return {what.value("name", ""), {}}; @@ -426,7 +429,7 @@ void ActionReplayDialog::send_service_state() m_ready_timer.Start(500); json msg{{"command", "service"}, {"ready", ready}}; if (ready) - msg["tools"] = Mcp::editor_tool_catalog(s->registry()); + msg["tools"] = Mcp::editor_tool_catalog(s->catalog()); call_web_handler(msg); } @@ -617,24 +620,24 @@ json ActionReplayDialog::describe(const Mcp::Replay& replay) const for (std::size_t i = 0; i < replay.steps.size(); ++i) { const Mcp::ReplayStep& step = replay.steps[i]; const Mcp::StepDescription d = Mcp::describe_step(step, replay, ctx); - const Mcp::ToolDef* def = s != nullptr ? s->registry().find(step.tool) : nullptr; + const NativeCommand* def = s != nullptr ? s->catalog().find(step.tool) : nullptr; json flags = json::array(); for (Mcp::StepFlag f : d.flags) flags.push_back(Mcp::flag_id(f)); json view{{"index", i + 1}, {"tool", step.tool}, - {"title", def != nullptr ? _u8L(def->title.c_str()) : step.tool}, + {"title", def != nullptr ? into_u8(NativeCommands::tile_title(*def)) : step.tool}, {"flags", std::move(flags)}, {"checks_result", d.checks_result}, {"optional", step.optional}, {"args", Mcp::substitute_lenient(step.args, replay, ctx)}, {"expect", step.expect}, {"checks", checks_view(step.expect)}}; - const auto [what, param] = what_text(d.what); + const auto [what, detail] = what_text(d.what); if (!what.empty()) view["what_text"] = what; - if (!param.empty()) - view["param_text"] = param; + if (!detail.empty()) + view["args_text"] = detail; steps.push_back(std::move(view)); } return steps; @@ -653,7 +656,7 @@ void ActionReplayDialog::parse(const nlohmann::json& payload) reply["error"] = err; else { for (std::size_t i = 0; i < replay->steps.size() && !reply.contains("error"); ++i) - if (s->registry().lookup(replay->steps[i].tool) == nullptr) + if (s->catalog().lookup(replay->steps[i].tool) == nullptr) // TRN %1% is a step number, %2% the name of the tool the replay asks for. reply["error"] = format(_u8L("Step %1% uses a tool this version of OrcaSlicer doesn't have: %2%"), i + 1, replay->steps[i].tool); diff --git a/src/slic3r/GUI/CAD/DesignCanvas.hpp b/src/slic3r/GUI/CAD/DesignCanvas.hpp index 822279a535..fd1dde8147 100644 --- a/src/slic3r/GUI/CAD/DesignCanvas.hpp +++ b/src/slic3r/GUI/CAD/DesignCanvas.hpp @@ -382,7 +382,7 @@ public: // Public: DesignPanel calls it after a tree edit to force a frame on software GL. // Scripted (MCP) access to the live sketch. One accessor rather than a passthrough per // verb: the MCP layer drives the SAME tool the mouse drives, which is the whole point of - // having it — a CAD tool that talked to a private copy would prove nothing about the app. + // having it — a Design command that talked to a private copy would prove nothing about the app. DesignSketchTool& mcp_sketch_tool() { return m_sketch_tool; } const DesignSketchTool& mcp_sketch_tool() const { return m_sketch_tool; } // The view's GL canvas, which MCP captures and sends input to as it does Prepare's. diff --git a/src/slic3r/GUI/CAD/DesignOffer.hpp b/src/slic3r/GUI/CAD/DesignOffer.hpp index 64c102bc91..dc8ac4da15 100644 --- a/src/slic3r/GUI/CAD/DesignOffer.hpp +++ b/src/slic3r/GUI/CAD/DesignOffer.hpp @@ -1,10 +1,13 @@ // GENERATED FILE — DO NOT EDIT. // Source: scripts/CAD/tool_atlas.json Generator: scripts/CAD/gen_offer_table.py // -// The object-driven tool offer (charter 4.1): every verb has ONE row index, that index -// is the same in every selection it appears in, and verbs that do not apply are shown -// disabled in place with their reason rather than removed. Row order was ratified -// 2026-07-31; changing an index is a breaking change to every user's muscle memory. +// The Design tab's table. Its verbs are the object-driven tool offer (charter 4.1): every verb +// has ONE row index, that index is the same in every selection it appears in, and verbs that do +// not apply are shown disabled in place with their reason rather than removed. Row order was +// ratified 2026-07-31; changing an index is a breaking change to every user's muscle memory. +// Every entry but align is also a command of the catalog's group Design (Mcp::register_cad_commands()): +// called with no arguments, one with an action does what its menu row does; otherwise, and always for +// an entry with no action, it runs its tool block's silent form. An entry with no row is a command only. #ifndef slic3r_GUI_DesignOffer_hpp_ #define slic3r_GUI_DesignOffer_hpp_ @@ -20,7 +23,7 @@ namespace Slic3r { namespace GUI { // What the viewport has selected. Ordered as in tool_atlas.json; the bitmask in -// OfferVerb::accepts indexes these. +// DesignTool::accepts indexes these. enum class OfferSel : int { None = 0, FacePlanar = 1, @@ -47,16 +50,49 @@ enum class OfferSel : int { inline uint32_t offer_bit(OfferSel s) { return 1u << int(s); } -// One row of the offer. `action` routes to the code that already implements the verb: +// The atlas's id of each selection, in OfferSel's order. +static const char* const kDesignSelectionIds[] = { + "none", + "face_planar", + "face_cyl", + "face_other", + "edge_str", + "edge_circ", + "vertex", + "body_solid", + "body_sheet", + "bodies_2", + "datum_plane", + "datum_axis", + "coordsys", + "art", + "sk_loop", + "sk_none", + "sk_line", + "sk_arc", + "sk_point", + "sk_2ent", +}; + +// What a Design command's silent form does to the document, which decides when the Design tab lets +// it run (DesignPanel::mcp_busy()). Read only looks, so it runs under anything but a rebuild. Sketch +// drives the live sketch session and Change edits the feature list or variables; both are refused under +// an open card, the Text dialog, Constrain mode or a body Move, and Change under a sketch session too, +// which is about to commit into the feature list. None: an entry with no silent form, and the opening +// of a tool, which only a rebuild refuses, as the Design tab's keys and menu do. +enum class CadAccess { None, Read, Change, Sketch }; + +// One entry of the table. `action` routes to the code that already implements the verb: // "key:S+E" -> m_keys_feature[SHIFT('E')] // "key:L" -> m_keys_sketch['L'] // "fly:material#4" -> row 4 of the "material" feature flyout // "btn:delete" -> a standalone toolbar button -// nullptr -> kernel support exists, no GUI path yet (row shows disabled) -struct OfferVerb { - const char* id; +// nullptr -> no GUI path (the row, if it has one, shows disabled) +struct DesignTool { + const char* id; // also the key of its Design command const char* name; // drawing-office word (L10); msgctxt "Design", translated at use - int row; // index into kOfferRowNames, the ratified address — NEVER reorder + int row; // index into kOfferRowNames, the ratified address — NEVER reorder; + // -1: no menu row, a command only const char* key; // shortcut shown in the row, or nullptr const char* action; const char* refusal; // why this row is greyed, in the product's own words @@ -72,6 +108,13 @@ struct OfferVerb { const char* family; const char* icon; // resources/images name, or nullptr — the offer draws it beside the row const char* hint; // what the verb does / what to click; shown on hover + bool modal; // its action opens a dialog that waits for an answer: a modal one, which holds + // the call until it is answered, or Text's, which is modeless and does not + CadAccess access; // its silent form's, None without one + bool ok_false; // its silent form reports a rejected rebuild in its reply (ok false) + // Its silent form's summary, details, params, examples and ids as JSON text, the parameter + // schema of record; nullptr for an entry whose command only does what its row does. + const char* doc; }; // Row labels, in ratified order. @@ -101,111 +144,1200 @@ static const bool kOfferRowFlat[] = { true, }; -static const OfferVerb kOfferVerbs[] = { - {"sketch", L_CONTEXT("Sketch", "Design"), 0, "Shift+S", "key:S+S", L("Select a flat face or a reference plane to sketch on"), 0x00000403u, 0, 0, false, false, nullptr, "design_sketch", L("Sketch on the selected flat face or plane, or click one next")}, - {"extrude", L_CONTEXT("Extrude", "Design"), 1, "Shift+E", "key:S+E", L("Create a sketch, or pick a solid face, first"), 0x00004002u, 0, 0, false, false, nullptr, "design_extrude", L("Extrude a sketch profile, or push/pull a picked face")}, - {"revolve", L_CONTEXT("Revolve", "Design"), 1, "Shift+R", "key:S+R", L("Create a sketch profile to revolve first"), 0x00004000u, 0, 0, false, false, nullptr, "design_revolve", L("Revolve a profile about an axis")}, - {"sweep", L_CONTEXT("Sweep", "Design"), 1, "Shift+W", "key:S+W", L("Create a profile sketch to sweep first"), 0x00004000u, 0, 2, false, false, nullptr, "design_sweep", L("Sweep a profile along a path")}, - {"loft", L_CONTEXT("Loft", "Design"), 1, "Shift+L", "key:S+L", L("Create at least two profile sketches to loft"), 0x00004000u, 0, 2, false, false, nullptr, "design_loft", L("Loft (skin) between two or more profiles")}, - {"thicken", L_CONTEXT("Thicken", "Design"), 1, nullptr, "fly:material#4", L("Thicken needs a solid body — add or import one first"), 0x0000000au, 1, 0, false, false, nullptr, "design_thicken", L("Offset a solid face into a thin plate (new body)")}, - {"rib", L_CONTEXT("Rib", "Design"), 1, "R", "fly:material#5", L("Rib needs a solid body — add or import one first"), 0x00010000u, 1, 0, false, false, nullptr, "design_rib", L("Grow a thin wall from an open sketch line, fused to a body")}, - {"boolean", L_CONTEXT("Join", "Design"), 1, "Shift+B", "btn:bool#0", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Fuse the tool body into the target — one solid, no seam")}, - {"bool_subtract", L_CONTEXT("Subtract", "Design"), 1, nullptr, "btn:bool#1", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Cut the tool body out of the target")}, - {"bool_intersect", L_CONTEXT("Intersect", "Design"), 1, nullptr, "btn:bool#2", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Keep only where the two bodies overlap")}, - {"surf_extrude", L_CONTEXT("Surface Extrude", "Design"), 1, "Shift+G", "key:S+G", L("Create a sketch first"), 0x00004000u, 0, 0, false, false, nullptr, "design_extrude", L("Extrude a sketch into a sheet body (no end caps)")}, - {"surf_revolve", L_CONTEXT("Surface Revolve", "Design"), 1, nullptr, "fly:surface#1", L("Create a sketch profile to revolve first"), 0x00004000u, 0, 0, false, false, nullptr, "design_revolve", L("Revolve a sketch profile into a sheet body")}, - {"surf_loft", L_CONTEXT("Surface Loft", "Design"), 1, nullptr, "fly:surface#2", L("Create at least two profile sketches to loft"), 0x00004000u, 0, 2, false, false, nullptr, "design_loft", L("Loft (skin) between 2+ profiles, open (no end caps)")}, - {"surf_fill", L_CONTEXT("Surface Fill", "Design"), 1, nullptr, "fly:surface#3", L("Create a closed sketch first"), 0x00004000u, 0, 0, false, false, nullptr, "design_surface", L("Fill a sketch boundary with a smooth face")}, - {"thicken_surf", L_CONTEXT("Thicken Surface", "Design"), 1, nullptr, "fly:surface#5", L("Thicken Surface needs a surface body — make one with a Surface tool first"), 0x00000100u, 0, 0, true, false, nullptr, "design_thicken", L("Thicken a sheet body into a solid")}, - {"hole", L_CONTEXT("Hole", "Design"), 2, "Shift+H", "key:S+H", L("Pick a face or a plane to drill into"), 0x00000402u, 1, 0, false, false, nullptr, "design_hole", L("Drill a hole, centered on a picked face or placed on a plane")}, - {"thread", L_CONTEXT("Thread", "Design"), 2, "Shift+T", "key:S+T", L("Pick a cylindrical surface (bore / outer) or a circular edge for a thread"), 0x00000024u, 1, 0, false, false, nullptr, "design_thread", L("Thread a cylindrical surface (inner bore / outer) or a circular edge")}, - {"shell", L_CONTEXT("Shell", "Design"), 2, "Shift+K", "key:S+K", L("Shell needs a solid body — add or import one first"), 0x00000082u, 1, 0, false, false, nullptr, "design_shell", L("Hollow the body to a wall thickness, opening a picked face")}, - {"cut", L_CONTEXT("Cut", "Design"), 2, "Shift+X", "key:S+X", L("Cut needs a solid body — add or import one first"), 0x000004feu, 1, 0, false, false, nullptr, "design_cut", L("Trim the body with a plane — drag the offset arrow; keep one half or both")}, - {"split", L_CONTEXT("Split", "Design"), 2, nullptr, nullptr, L("Split needs a solid body — add or import one first"), 0x000000feu, 1, 0, false, false, nullptr, nullptr, L("Split the body along a picked face into two solids")}, - {"fillet", L_CONTEXT("Fillet", "Design"), 3, "Shift+F", "btn:dress#0", L("Pick an edge to round"), 0x000000b2u, 1, 0, false, false, nullptr, "design_filletedge", L("Pick an edge, then drag the radius arrow or type it")}, - {"chamfer", L_CONTEXT("Chamfer", "Design"), 3, nullptr, "btn:dress#1", L("Pick an edge to bevel"), 0x000000b2u, 1, 0, false, false, nullptr, "design_chamfer", L("Pick an edge, then drag the distance arrow or type it")}, - {"draft", L_CONTEXT("Draft", "Design"), 3, "Shift+D", "key:S+D", L("Pick a face to taper"), 0x0000000au, 1, 0, false, false, nullptr, "design_draft", L("Tilt a picked face by a draft angle")}, - {"surf_offset", L_CONTEXT("Surface Offset", "Design"), 3, nullptr, "fly:surface#4", L("Surface Offset needs a surface body — make one with a Surface tool first"), 0x00000100u, 0, 0, true, false, nullptr, "design_offset", L("Offset a sheet body's shell by a signed distance")}, - {"pattern", L_CONTEXT("Linear pattern", "Design"), 4, "Shift+N", "btn:pat#0", L("Pattern needs a solid body — add or import one first"), 0x00006082u, 1, 0, false, false, nullptr, "design_array", L("Repeat the body along a direction — drag the spacing, set the count")}, - {"pattern_circular", L_CONTEXT("Circular pattern", "Design"), 4, nullptr, "btn:pat#1", L("Pattern needs a solid body — add or import one first"), 0x00006082u, 1, 0, false, false, nullptr, "design_polararray", L("Repeat the body around an axis — set the count and sweep")}, - {"mirror", L_CONTEXT("Mirror", "Design"), 4, "Shift+Z", "key:S+Z", L("Mirror needs a body — add or import one first"), 0x000004feu, 1, 0, false, false, nullptr, "design_mirror", L("Reflect a body about a plane")}, - {"pat_curve", L_CONTEXT("Pattern on Curve", "Design"), 4, nullptr, nullptr, L("Pattern on Curve needs a body and a curve"), 0x00000090u, 1, 0, false, false, nullptr, nullptr, L("Repeat the body along a picked curve")}, - {"transform", L_CONTEXT("Move", "Design"), 5, "Shift+Y", "key:S+Y", L("Transform needs a body — add or import one first"), 0x000021feu, 1, 0, false, false, nullptr, "design_move", L("Move and/or rotate an existing body")}, - {"mate", L_CONTEXT("Mate", "Design"), 5, nullptr, "fly:placement#2", L("Mate needs two coordinate systems — create them first"), 0x00001202u, 2, 0, false, false, nullptr, "design_c_coincident", L("Assembly: align two coordinate systems (fastened, planar, revolute, slider, cylindrical)")}, - {"align", L_CONTEXT("Align to", "Design"), 5, nullptr, nullptr, L("Align needs a body — add or import one first"), 0x00000002u, 1, 0, false, false, nullptr, nullptr, L("Align the body to a picked face or plane")}, - {"plane", L_CONTEXT("Plane", "Design"), 6, "Shift+P", "key:S+P", nullptr, 0x00000453u, 0, 0, false, false, nullptr, "design_plane", L("Reference plane (offset / tilt / midplane / tangent / two edges / coincident)")}, - {"axis", L_CONTEXT("Axis", "Design"), 6, "Shift+A", "key:S+A", nullptr, 0x00000057u, 0, 0, false, false, nullptr, "design_line", L("Datum axis (two points, face normal, cylinder centerline, two planes, along edge)")}, - {"coordsys_v", L_CONTEXT("Coordinate system", "Design"), 6, "Shift+C", "key:S+C", nullptr, 0x00000043u, 0, 0, false, false, nullptr, "design_point", L("Datum coordinate system (world point, or face + direction edge)")}, - {"helix", L_CONTEXT("Helix", "Design"), 6, nullptr, "fly:plane#3", nullptr, 0x00000405u, 0, 0, false, false, nullptr, "design_thread", L("Helical curve (spring path) — use as a sweep path for coils / springs / augers")}, - {"project", L_CONTEXT("Project", "Design"), 6, nullptr, "fly:plane#4", L("Project needs a body — add or import one first"), 0x00000482u, 1, 0, false, false, nullptr, "design_sketch", L("Project body edges onto a plane as sketch entities")}, - {"measure", L_CONTEXT("Measure", "Design"), 6, nullptr, nullptr, nullptr, 0x000b03feu, 0, 0, false, false, nullptr, nullptr, L("Measure between the picked points, edges or faces")}, - {"mass_props", L_CONTEXT("Volume and area", "Design"), 6, nullptr, "btn:mass", nullptr, 0x000000feu, 1, 0, false, false, nullptr, "info", L("Report the volume and surface area of the selected body")}, - {"interference", L_CONTEXT("Interference", "Design"), 6, nullptr, "btn:interference", L("Interference needs at least two bodies"), 0x00000280u, 2, 0, false, false, nullptr, nullptr, L("Check whether two bodies overlap — reports, changes nothing")}, - {"edit_feature", L_CONTEXT("Edit", "Design"), 7, nullptr, "btn:edit", nullptr, 0x00007d8eu, 0, 0, false, false, nullptr, "design_edit", L("Reopen the selected feature to change what it was made from")}, - {"rename", L_CONTEXT("Rename…", "Design"), 8, "F2", "btn:rename", L("Select a feature, or a body, to rename it"), 0x00004080u, 0, 0, false, false, nullptr, nullptr, L("Give this feature a name you will recognise in the tree (a body takes its name from the feature that makes it)")}, - {"delete_face", L_CONTEXT("Delete Face", "Design"), 7, nullptr, "fly:dressup#3", L("Delete Face needs a body — add or import one first"), 0x0000000eu, 1, 0, false, false, nullptr, "design_delete", L("Remove faces from a body and heal the solid")}, - {"colour", L_CONTEXT("Color", "Design"), 8, nullptr, "btn:colour", nullptr, 0x000001feu, 1, 0, false, false, nullptr, "color_palette", L("Set the selected body's display color")}, - {"zoom_to", L_CONTEXT("Zoom to selection", "Design"), 8, nullptr, "btn:zoom_to", nullptr, 0x000041feu, 0, 0, false, false, nullptr, "design_zoom", L("Frame the selection in the view, keeping the view direction")}, - {"delete", L_CONTEXT("Delete", "Design"), 7, "Del", "btn:delete", nullptr, 0x000f7c00u, 0, 0, false, false, nullptr, "design_delete", L("Delete what is selected")}, - {"delete_body", L_CONTEXT("Delete Body", "Design"), 7, nullptr, "btn:delete_body", nullptr, 0x000001feu, 1, 0, false, false, nullptr, "design_delete", L("Delete this whole body — removes the feature it was made from")}, - {"sk_line_t", L_CONTEXT("Line", "Design"), 0, "L", "key:L", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Line", "Design"), "design_line", L("Line — click start, then end")}, - {"sk_polyline", L_CONTEXT("Polyline", "Design"), 0, nullptr, "fly:design_line#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Line", "Design"), "design_polyline", L("Click points; click the first point to close the loop, right-click to end it open")}, - {"sk_rect", L_CONTEXT("Corner rectangle", "Design"), 0, "R", "key:R", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect", L("Rectangle — click two opposite corners")}, - {"sk_rect_center", L_CONTEXT("Center rectangle", "Design"), 0, nullptr, "fly:design_rect#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_crect", L("Click center, then a corner")}, - {"sk_rect_oblique", L_CONTEXT("Oblique rectangle", "Design"), 0, nullptr, "fly:design_rect#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect_oblique", L("Click two corners of one edge, then a point for the width")}, - {"sk_rect_rounded", L_CONTEXT("Rounded rectangle", "Design"), 0, nullptr, "fly:design_rect#3", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect_rounded", L("Click two opposite corners, then a point for the corner radius")}, - {"sk_circle", L_CONTEXT("Center circle", "Design"), 0, "C", "key:C", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle", L("Circle — click center, then radius")}, - {"sk_circle_2pt", L_CONTEXT("2-point circle", "Design"), 0, nullptr, "fly:design_circle#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle2pt", L("Click two ends of the diameter")}, - {"sk_circle_3pt", L_CONTEXT("3-point circle", "Design"), 0, nullptr, "fly:design_circle#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle3pt", L("Click three points on the circle")}, - {"sk_arc_t", L_CONTEXT("3-point arc", "Design"), 0, "A", "key:A", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_arc3pt", L("Arc — click start, end, then a point")}, - {"sk_arc_tangent", L_CONTEXT("Tangent arc", "Design"), 0, nullptr, "fly:design_arc3pt#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_tangentarc", L("Click start (on the last entity) then end")}, - {"sk_arc_center", L_CONTEXT("Center-point arc", "Design"), 0, nullptr, "fly:design_arc3pt#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_arc_center", L("Click center, then start, then a point for the end angle")}, - {"sk_slot", L_CONTEXT("Slot", "Design"), 0, "S", "key:S", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Slot", "Design"), "design_slot", L("Slot — two centerline ends, then the width")}, - {"sk_slot_arc", L_CONTEXT("Arc slot", "Design"), 0, nullptr, "fly:design_slot#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Slot", "Design"), "design_slot_arc", L("Click center, start, end, then a point for the width")}, - {"sk_ellipse", L_CONTEXT("Ellipse", "Design"), 0, "E", "key:E", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Ellipse", "Design"), "design_ellipse", L("Ellipse — center, major end, minor point")}, - {"sk_ellipse_arc", L_CONTEXT("Elliptical arc", "Design"), 0, nullptr, "fly:design_ellipse#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Ellipse", "Design"), "design_ellipse_arc", L("Click center, major-axis end, minor point, then arc start and end")}, - {"sk_spline", L_CONTEXT("Spline", "Design"), 0, "B", "key:B", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_bspline", L("Spline — click control points")}, - {"sk_poly_3", L_CONTEXT("Triangle", "Design"), 0, nullptr, "btn:poly#3", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Triangle — click center, then a vertex")}, - {"sk_poly_4", L_CONTEXT("Square", "Design"), 0, nullptr, "btn:poly#4", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Square — click center, then a vertex")}, - {"sk_poly_5", L_CONTEXT("Pentagon", "Design"), 0, nullptr, "btn:poly#5", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Pentagon — click center, then a vertex")}, - {"sk_polygon", L_CONTEXT("Hexagon", "Design"), 0, "G", "btn:poly#6", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Hexagon — click center, then a vertex")}, - {"sk_poly_8", L_CONTEXT("Octagon", "Design"), 0, nullptr, "btn:poly#8", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Octagon — click center, then a vertex")}, - {"sk_poly_12", L_CONTEXT("Dodecagon", "Design"), 0, nullptr, "btn:poly#12", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Dodecagon — click center, then a vertex")}, - {"sk_poly_inscribed", L_CONTEXT("Inscribed", "Design"), 0, nullptr, "btn:polyfit#0", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Measure the polygon to its corners (inscribed)")}, - {"sk_poly_circumscribed", L_CONTEXT("Circumscribed", "Design"), 0, nullptr, "btn:polyfit#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Measure the polygon to its flats (circumscribed)")}, - {"sk_point_t", L_CONTEXT("Point", "Design"), 0, "P", "key:P", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_point", L("Point — click to place")}, - {"sk_text", L_CONTEXT("Text", "Design"), 0, nullptr, "btn:text", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_text", L("Type text; it becomes a Text feature on this sketch's plane, editable later")}, - {"sk_svg", L_CONTEXT("SVG", "Design"), 0, nullptr, "btn:svg", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_svg", L("Import an SVG outline into this sketch as editable lines")}, - {"sk_offset", L_CONTEXT("Offset", "Design"), 1, "O", "key:O", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_offset", L("Offset — pick an entity, drag the distance")}, - {"sk_trim", L_CONTEXT("Trim", "Design"), 2, "T", "key:T", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_trim", L("Trim — click a segment to trim it")}, - {"sk_fillet", L_CONTEXT("Fillet", "Design"), 3, "F", "key:F", nullptr, 0x00090000u, 0, 0, false, true, nullptr, "design_filletedge", L("Fillet — pick two lines, set the radius")}, - {"sk_chamfer", L_CONTEXT("Chamfer", "Design"), 3, "H", "key:H", nullptr, 0x00090000u, 0, 0, false, true, nullptr, "design_chamfer", L("Chamfer — pick two lines, set the distance")}, - {"sk_array", L_CONTEXT("Linear array", "Design"), 4, nullptr, "fly:design_array#0", nullptr, 0x000b0000u, 0, 0, false, true, L_CONTEXT("Array", "Design"), "design_array", L("Pick entities, drag the spacing handle, click the count; click empty to apply")}, - {"sk_array_polar", L_CONTEXT("Polar array", "Design"), 4, nullptr, "fly:design_array#1", nullptr, 0x000b0000u, 0, 0, false, true, L_CONTEXT("Array", "Design"), "design_polararray", L("Pick entities, drag the sweep handle, click the count; click empty to apply")}, - {"sk_mirror", L_CONTEXT("Mirror", "Design"), 4, "M", "key:M", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_mirror", L("Mirror — pick axis, then entities")}, - {"sk_move", L_CONTEXT("Move", "Design"), 5, nullptr, "fly:design_move#0", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_move", L("Pick entities, then drag the handle or click the distance; click empty to apply")}, - {"sk_rotate", L_CONTEXT("Rotate", "Design"), 5, nullptr, "fly:design_move#1", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_rotate", L("Pick entities, then drag around the pivot or click the angle; click empty to apply")}, - {"sk_scale", L_CONTEXT("Scale", "Design"), 5, nullptr, "fly:design_move#2", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_scale", L("Pick entities, then drag the handle or click the factor; click empty to apply")}, - {"sk_dimension", L_CONTEXT("Dimension", "Design"), 6, "D", "key:D", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_dimension", L("Dimension — click 2 points or an entity")}, - {"sk_constrain", L_CONTEXT("Constrain", "Design"), 6, "K", "key:K", nullptr, 0x000f0000u, 0, 0, false, true, nullptr, "design_constrain", L("Constrain the selected sketch entities to each other")}, +static const DesignTool kDesignTools[] = { + {"sketch", L_CONTEXT("Sketch", "Design"), 0, "Shift+S", "key:S+S", L("Select a flat face or a reference plane to sketch on"), 0x00000403u, 0, 0, false, false, nullptr, "design_sketch", L("Sketch on the selected flat face or plane, or click one next"), false, CadAccess::None, false, + nullptr}, + {"extrude", L_CONTEXT("Extrude", "Design"), 1, "Shift+E", "key:S+E", L("Create a sketch, or pick a solid face, first"), 0x00004002u, 0, 0, false, false, nullptr, "design_extrude", L("Extrude a sketch profile, or push/pull a picked face"), false, CadAccess::Change, false, + "{\"summary\":\"Extrude a committed sketch, one of its loops, a face or a drawn profile into a body." + "\",\"details\":\"A committed sketch, or one loop of it, extrudes as the Extrude card does; push/pull" + " grows a planar face of a body; a profile drawn here is an explicit closed `profile` (list of [x" + ",y]) or a centred width x height rectangle on `plane`. End conditions match Onshape. Reply: extr" + "ude_index, the index of its sketch (-1 for a face), the boolean and body used, end, frame.\",\"par" + "ams\":[{\"name\":\"sketch\",\"type\":\"integer\",\"default\":null,\"description\":\"a committed Sketch feature" + " to extrude (sketch_commit's sketch_index); profile, width, height and plane are then refused\"}," + "{\"name\":\"loop\",\"type\":\"integer\",\"default\":null,\"description\":\"with sketch: one closed loop (clos" + "ed_loops[].index of sketch_describe {sketch}) with the loops inside it as holes; a hole is a loo" + "p of its own, so its index extrudes the disc. Omit for the whole sketch\"},{\"name\":\"face\",\"type\":" + "\"integer\",\"default\":null,\"description\":\"push/pull: a planar face (query_topology id) of `body` g" + "rown along its outward normal (flip for inward); boolean auto joins that body. sketch, loop, pro" + "file, width, height, plane and taper are then refused, and end is blind or symmetric\"},{\"name\":\"" + "width\",\"type\":\"number\",\"unit\":\"mm\",\"default\":20},{\"name\":\"height\",\"type\":\"number\",\"unit\":\"mm\",\"d" + "efault\":20},{\"name\":\"distance\",\"type\":\"number\",\"unit\":\"mm\",\"default\":10,\"exclusive_min\":0},{\"nam" + "e\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through" + " modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, a planar face " + "(origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives" + " the axes.\"},{\"name\":\"profile\",\"type\":\"array\",\"default\":[],\"description\":\"optional closed contou" + "r [[x,y],...] in plane mm; overrides width/height\"},{\"name\":\"boolean\",\"type\":\"string\",\"default\":" + "null,\"enum\":[\"auto\",\"new\",\"union\",\"subtract\",\"intersect\"],\"description\":\"auto joins the body the" + " profile touches, else makes a new body, as the card's default; default auto with sketch, new wi" + "thout\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"the body to join, subtract f" + "rom or intersect, or whose face is pushed; omit for the body a sketch touches, else the last bod" + "y\"},{\"name\":\"end\",\"type\":\"string\",\"default\":\"blind\",\"enum\":[\"blind\",\"symmetric\",\"two_sided\",\"thr" + "ough_all\",\"up_to_face\"]},{\"name\":\"distance2\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0,\"descriptio" + "n\":\"second-side depth when end=two_sided (else falls back to distance)\"},{\"name\":\"up_to_face\",\"t" + "ype\":\"integer\",\"default\":-1,\"description\":\"face id (query_topology) of the body the extrude work" + "s on, when end=up_to_face\"},{\"name\":\"taper\",\"type\":\"number\",\"unit\":\"deg\",\"default\":0,\"descriptio" + "n\":\"draft/taper of the side wall\"},{\"name\":\"flip\",\"type\":\"boolean\",\"default\":false}],\"examples\":" + "[{\"title\":\"A 20 x 20 x 5 mm plate on the XY plane\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\"" + ":5,\"height\":20,\"width\":20}}]},{\"title\":\"A committed sketch extruded 5 mm: a rectangle around a c" + "ircle makes a plate with a bore\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":" + "\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\"" + ":[0,0],\"radius\":4,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"extrude\",\"args" + "\":{\"distance\":5,\"sketch\":0}}]},{\"title\":\"A plate's top face pushed up 3 mm\",\"calls\":[{\"tool\":\"ex" + "trude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"at_extrem" + "e\":\"+z\",\"body\":0}},{\"tool\":\"extrude\",\"args\":{\"body\":0,\"distance\":3,\"face\":5,\"generation\":{\"from_" + "call\":1,\"key\":\"generation\"}}}]}],\"ids\":true}"}, + {"revolve", L_CONTEXT("Revolve", "Design"), 1, "Shift+R", "key:S+R", L("Create a sketch profile to revolve first"), 0x00004000u, 0, 0, false, false, nullptr, "design_revolve", L("Revolve a profile about an axis"), false, CadAccess::Change, false, + "{\"summary\":\"Revolve a committed sketch as the Revolve card does, or a profile drawn here, about " + "an axis.\",\"details\":\"A sketch turns about a line of it or a plane axis; a profile drawn here is " + "an explicit `profile` offset from the axis, or a width x height rectangle with one edge on the a" + "xis, centred along it, so a full turn is a cylinder width long of radius height. Reply: revolve_" + "index, the index of its sketch, the boolean, body and axis used, frame.\",\"params\":[{\"name\":\"sket" + "ch\",\"type\":\"integer\",\"default\":null,\"description\":\"a committed Sketch feature to revolve (sketch" + "_commit's sketch_index); profile, width, height and plane are then refused\"},{\"name\":\"axis_entit" + "y\",\"type\":\"integer\",\"default\":null,\"description\":\"with sketch: a line of the sketch (entity inde" + "x) as the axis, or -1 for the plane axis; omit for the sketch's only centerline (construction li" + "ne) when it has one and axis is not given\"},{\"name\":\"width\",\"type\":\"number\",\"unit\":\"mm\",\"default" + "\":20,\"description\":\"without sketch or profile: the rectangle's length along the axis\"},{\"name\":\"" + "height\",\"type\":\"number\",\"unit\":\"mm\",\"default\":10,\"description\":\"without sketch or profile: how f" + "ar the rectangle reaches out from the axis, the solid's radius\"},{\"name\":\"angle\",\"type\":\"number\"" + ",\"unit\":\"deg\",\"default\":360},{\"name\":\"axis\",\"type\":\"integer\",\"default\":0,\"enum\":[0,1],\"descripti" + "on\":\"the plane's X (0) or Y (1) axis through its origin\"},{\"name\":\"flip\",\"type\":\"boolean\",\"defau" + "lt\":false},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" o" + "r \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}" + ", a planar face (origin at its centroid, normal out of the body, x from the world axes). The rep" + "ly's frame gives the axes.\"},{\"name\":\"profile\",\"type\":\"array\",\"default\":[],\"description\":\"option" + "al closed contour [[x,y],...] in plane mm; overrides width/height\"},{\"name\":\"boolean\",\"type\":\"st" + "ring\",\"default\":\"new\",\"enum\":[\"new\",\"union\",\"subtract\",\"intersect\"]},{\"name\":\"body\",\"type\":\"inte" + "ger\",\"default\":-1,\"description\":\"the body to join, subtract from or intersect; omit for the last" + " body\"}],\"examples\":[{\"title\":\"A ring: a profile 10 to 15 mm out from the XZ plane's vertical ax" + "is, turned a full circle\",\"calls\":[{\"tool\":\"revolve\",\"args\":{\"axis\":1,\"plane\":\"XZ\",\"profile\":[[1" + "0,0],[15,0],[15,10],[10,10]]}}]},{\"title\":\"A committed sketch turned about its centerline, a con" + "struction line\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XZ\"}},{\"tool\":\"sketch_add\",\"arg" + "s\":{\"rect\":[10,0,15,10]}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"construction\":true,\"p0\":[0," + "0],\"p1\":[0,10],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"revolve\",\"args\":{\"s" + "ketch\":0}}]}],\"ids\":true}"}, + {"sweep", L_CONTEXT("Sweep", "Design"), 1, "Shift+W", "key:S+W", L("Create a profile sketch to sweep first"), 0x00004000u, 0, 2, false, false, nullptr, "design_sweep", L("Sweep a profile along a path"), false, CadAccess::Change, false, + "{\"summary\":\"Sweep a committed sketch's closed profile along a path, a sketch or a helix, as the " + "Sweep card does.\",\"details\":\"Draw the profile across the path's start (a helix's start and tange" + "nt are in its reply); along a helix the profile keeps its angle to the helix axis. Long sweeps t" + "ake seconds and the reply may be a job. Reply: sweep_index, bodies, boolean, body.\",\"params\":[{\"" + "name\":\"sketch\",\"type\":\"integer\",\"description\":\"the profile: a committed sketch's feature index\"}" + ",{\"name\":\"path\",\"type\":\"integer\",\"description\":\"feature index of a sketch or a helix, other than" + " the profile\"},{\"name\":\"boolean\",\"type\":\"string\",\"default\":\"new\",\"enum\":[\"new\",\"union\",\"subtract" + "\",\"intersect\"]},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"the body a union, su" + "btract or intersect works on; omit for the last body\"}],\"examples\":[{\"title\":\"A spring: a 2 mm c" + "ircle across a helix's start, swept along it\",\"calls\":[{\"tool\":\"helix\",\"args\":{\"height\":20,\"pitc" + "h\":5,\"radius\":10}},{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XZ\"}},{\"tool\":\"sketch_add\",\"args\":{\"e" + "ntities\":[{\"center\":[10,0],\"radius\":1,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"t" + "ool\":\"sweep\",\"args\":{\"path\":0,\"sketch\":1}}]},{\"title\":\"A 6 mm rod swept along a 40 mm line\",\"cal" + "ls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0" + "\":[0,0],\"p1\":[0,40],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"sketch_begin\"," + "\"args\":{\"plane\":\"XZ\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":3,\"type" + "\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"sweep\",\"args\":{\"path\":0,\"sketch\":1}}]" + "}],\"ids\":false}"}, + {"loft", L_CONTEXT("Loft", "Design"), 1, "Shift+L", "key:S+L", L("Create at least two profile sketches to loft"), 0x00004000u, 0, 2, false, false, nullptr, "design_loft", L("Loft (skin) between two or more profiles"), false, CadAccess::Change, false, + "{\"summary\":\"Loft a solid through two or more committed sketches, in order, as the Loft card does" + ".\",\"details\":\"Each sketch is on its own plane (sketch on datum planes). Lofts take seconds and t" + "he reply may be a job. Reply: loft_index, bodies, boolean, body.\",\"params\":[{\"name\":\"profiles\",\"" + "type\":\"array\",\"description\":\"sketch feature indices, in loft order\"},{\"name\":\"ruled\",\"type\":\"boo" + "lean\",\"default\":false,\"description\":\"straight sections between the profiles instead of a smooth " + "skin\"},{\"name\":\"boolean\",\"type\":\"string\",\"default\":\"new\",\"enum\":[\"new\",\"union\",\"subtract\",\"inter" + "sect\"]},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"the body a union, subtract o" + "r intersect works on; omit for the last body\"}],\"examples\":[{\"title\":\"A square-to-round transiti" + "on 20 mm tall, the circle sketched on a datum plane\",\"calls\":[{\"tool\":\"plane\",\"args\":{\"base\":\"XY" + "\",\"offset\":20,\"type\":\"offset\"}},{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_ad" + "d\",\"args\":{\"rect\":[-10,-10,10,10]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"sketch_begin\",\"a" + "rgs\":{\"plane\":{\"datum\":0}}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":6," + "\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"loft\",\"args\":{\"profiles\":[1,2]}}" + "]}],\"ids\":false}"}, + {"thicken", L_CONTEXT("Thicken", "Design"), 1, nullptr, "fly:material#4", L("Thicken needs a solid body — add or import one first"), 0x0000000au, 1, 0, false, false, nullptr, "design_thicken", L("Offset a solid face into a thin plate (new body)"), false, CadAccess::Change, true, + "{\"summary\":\"Offset a face of a body by a wall thickness, producing a new thin solid body.\",\"deta" + "ils\":\"\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body; omit " + "for the last body\"},{\"name\":\"face\",\"type\":\"integer\",\"description\":\"face id to thicken (query_top" + "ology)\"},{\"name\":\"thickness\",\"type\":\"number\",\"unit\":\"mm\",\"default\":2},{\"name\":\"flip\",\"type\":\"boo" + "lean\",\"default\":false}],\"examples\":[{\"title\":\"A 2 mm skin grown from a plate's top face as a new" + " body\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_t" + "opology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"thicken\",\"args\":{\"body\":0,\"face\":5,\"gener" + "ation\":{\"from_call\":1,\"key\":\"generation\"},\"thickness\":2}}]}],\"ids\":true}"}, + {"rib", L_CONTEXT("Rib", "Design"), 1, "R", "fly:material#5", L("Rib needs a solid body — add or import one first"), 0x00010000u, 1, 0, false, false, nullptr, "design_rib", L("Grow a thin wall from an open sketch line, fused to a body"), false, CadAccess::Change, true, + "{\"summary\":\"Grow a thin rib wall (stiffener) from an open Line sketch entity, fused to a body.\"," + "\"details\":\"The wall is centred on the line in the sketch plane, thickness wide, and grows depth " + "along the sketch plane's normal.\",\"params\":[{\"name\":\"sketch\",\"type\":\"integer\",\"description\":\"ske" + "tch feature index holding the open line\"},{\"name\":\"entity\",\"type\":\"integer\",\"description\":\"entit" + "y index of the open Line within the sketch\"},{\"name\":\"thickness\",\"type\":\"number\",\"unit\":\"mm\",\"de" + "fault\":2},{\"name\":\"depth\",\"type\":\"number\",\"unit\":\"mm\",\"default\":10,\"description\":\"along the sket" + "ch plane's normal, or against it when negative\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"d" + "escription\":\"target body; omit for the last body\"}],\"examples\":[{\"title\":\"A 2 mm rib 8 mm tall a" + "cross a plate's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":3,\"height\":20,\"width\":40" + "}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"sketch_begin\",\"args\":{" + "\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"plane\":{\"body\":0,\"face\":5}}},{\"tool\":\"sketch_ad" + "d\",\"args\":{\"entities\":[{\"p0\":[-15,0],\"p1\":[15,0],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args" + "\":{}},{\"tool\":\"rib\",\"args\":{\"depth\":8,\"entity\":0,\"sketch\":2,\"thickness\":2}}]}],\"ids\":false}"}, + {"boolean", L_CONTEXT("Join", "Design"), 1, "Shift+B", "btn:bool#0", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Fuse the tool body into the target — one solid, no seam"), false, CadAccess::Change, true, + "{\"summary\":\"Combine two bodies: union | subtract (tool from target) | intersect.\",\"details\":\"\",\"" + "params\":[{\"name\":\"op\",\"type\":\"string\",\"default\":\"subtract\",\"enum\":[\"union\",\"subtract\",\"intersect" + "\"]},{\"name\":\"target\",\"type\":\"integer\",\"default\":0},{\"name\":\"tool\",\"type\":\"integer\",\"default\":1}," + "{\"name\":\"keep_tool\",\"type\":\"boolean\",\"default\":false},{\"name\":\"tolerance\",\"type\":\"number\",\"unit\"" + ":\"mm\",\"default\":0}],\"examples\":[{\"title\":\"A post subtracted from a block\",\"calls\":[{\"tool\":\"extr" + "ude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"d" + "istance\":20,\"height\":6,\"width\":6}},{\"tool\":\"boolean\",\"args\":{\"op\":\"subtract\",\"target\":0,\"tool\":1" + "}}]},{\"title\":\"Two overlapping blocks joined into one body\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"" + "distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"distance\":10,\"p" + "rofile\":[[5,-5],[20,-5],[20,5],[5,5]]}},{\"tool\":\"boolean\",\"args\":{\"op\":\"union\",\"target\":0,\"tool\"" + ":1}}]}],\"ids\":false}"}, + {"bool_subtract", L_CONTEXT("Subtract", "Design"), 1, nullptr, "btn:bool#1", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Cut the tool body out of the target"), false, CadAccess::None, false, + nullptr}, + {"bool_intersect", L_CONTEXT("Intersect", "Design"), 1, nullptr, "btn:bool#2", L("Boolean needs two bodies — add or import a second one"), 0x00000200u, 2, 0, false, false, nullptr, "design_boolean", L("Keep only where the two bodies overlap"), false, CadAccess::None, false, + nullptr}, + {"surf_extrude", L_CONTEXT("Surface Extrude", "Design"), 1, "Shift+G", "key:S+G", L("Create a sketch first"), 0x00004000u, 0, 0, false, false, nullptr, "design_extrude", L("Extrude a sketch into a sheet body (no end caps)"), false, CadAccess::Change, true, + "{\"summary\":\"Extrude a sketch wire with no end caps -> an open sheet body.\",\"details\":\"\",\"params\"" + ":[{\"name\":\"sketch\",\"type\":\"integer\",\"description\":\"sketch feature index\"},{\"name\":\"distance\",\"ty" + "pe\":\"number\",\"unit\":\"mm\",\"default\":10,\"description\":\"along the sketch plane's normal, or against" + " it when negative\"}],\"examples\":[{\"title\":\"A 30 mm line extruded 10 mm into a flat sheet\",\"calls" + "\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":" + "[-15,0],\"p1\":[15,0],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_extrude\"," + "\"args\":{\"distance\":10,\"sketch\":0}}]},{\"title\":\"A circle extruded 20 mm into an open tube, with n" + "o end caps\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{" + "\"entities\":[{\"center\":[0,0],\"radius\":10,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{" + "\"tool\":\"surf_extrude\",\"args\":{\"distance\":20,\"sketch\":0}}]}],\"ids\":false}"}, + {"surf_revolve", L_CONTEXT("Surface Revolve", "Design"), 1, nullptr, "fly:surface#1", L("Create a sketch profile to revolve first"), 0x00004000u, 0, 0, false, false, nullptr, "design_revolve", L("Revolve a sketch profile into a sheet body"), false, CadAccess::Change, true, + "{\"summary\":\"Revolve a sketch wire with no caps -> an open sheet body.\",\"details\":\"\",\"params\":[{\"" + "name\":\"sketch\",\"type\":\"integer\",\"description\":\"sketch feature index\"},{\"name\":\"angle\",\"type\":\"nu" + "mber\",\"unit\":\"deg\",\"default\":360},{\"name\":\"axis\",\"type\":\"integer\",\"default\":0,\"enum\":[0,1],\"desc" + "ription\":\"the sketch plane's X (0) or Y (1) axis through its origin\"}],\"examples\":[{\"title\":\"A c" + "ylinder's wall: a line 10 mm out from the XZ plane's vertical axis, turned a full circle\",\"calls" + "\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XZ\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":" + "[10,0],\"p1\":[10,20],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_revolve\"," + "\"args\":{\"axis\":1,\"sketch\":0}}]},{\"title\":\"Half a truncated cone's wall: a sloping line turned 18" + "0 degrees about the XZ plane's vertical axis\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"X" + "Z\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":[5,0],\"p1\":[15,20],\"type\":\"line\"}]}},{\"tool\"" + ":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_revolve\",\"args\":{\"angle\":180,\"axis\":1,\"sketch\":0}}]}]," + "\"ids\":false}"}, + {"surf_loft", L_CONTEXT("Surface Loft", "Design"), 1, nullptr, "fly:surface#2", L("Create at least two profile sketches to loft"), 0x00004000u, 0, 2, false, false, nullptr, "design_loft", L("Loft (skin) between 2+ profiles, open (no end caps)"), false, CadAccess::Change, true, + "{\"summary\":\"Skin two or more profile sketches with no end caps -> an open sheet body.\",\"details\"" + ":\"\",\"params\":[{\"name\":\"profiles\",\"type\":\"array\",\"description\":\"sketch feature indices, in order\"" + "},{\"name\":\"ruled\",\"type\":\"boolean\",\"default\":false}],\"examples\":[{\"title\":\"An open funnel skinne" + "d from a circle on XY to a wider one on a datum plane 20 mm up\",\"calls\":[{\"tool\":\"plane\",\"args\":" + "{\"base\":\"XY\",\"offset\":20,\"type\":\"offset\"}},{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\"" + ":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":5,\"type\":\"circle\"}]}},{\"tool\":\"sketch" + "_commit\",\"args\":{}},{\"tool\":\"sketch_begin\",\"args\":{\"plane\":{\"datum\":0}}},{\"tool\":\"sketch_add\",\"a" + "rgs\":{\"entities\":[{\"center\":[0,0],\"radius\":15,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\"" + ":{}},{\"tool\":\"surf_loft\",\"args\":{\"profiles\":[1,2]}}]}],\"ids\":false}"}, + {"surf_fill", L_CONTEXT("Surface Fill", "Design"), 1, nullptr, "fly:surface#3", L("Create a closed sketch first"), 0x00004000u, 0, 0, false, false, nullptr, "design_surface", L("Fill a sketch boundary with a smooth face"), false, CadAccess::Change, true, + "{\"summary\":\"Fill a sketch's closed boundary with one smooth face -> a sheet body.\",\"details\":\"\"," + "\"params\":[{\"name\":\"sketch\",\"type\":\"integer\",\"description\":\"sketch feature index\"}],\"examples\":[{" + "\"title\":\"A circle filled with a disc-shaped sheet\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plan" + "e\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":10,\"type\":\"circle\"}]" + "}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_fill\",\"args\":{\"sketch\":0}}]},{\"title\":\"A rec" + "tangle filled with a flat sheet\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":" + "\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_f" + "ill\",\"args\":{\"sketch\":0}}]}],\"ids\":false}"}, + {"thicken_surf", L_CONTEXT("Thicken Surface", "Design"), 1, nullptr, "fly:surface#5", L("Thicken Surface needs a surface body — make one with a Surface tool first"), 0x00000100u, 0, 0, true, false, nullptr, "design_thicken", L("Thicken a sheet body into a solid"), false, CadAccess::Change, true, + "{\"summary\":\"Thicken a whole sheet body into a solid.\",\"details\":\"A sheet of several faces whose " + "free rims close into planar loops (the walls of a box with no lids) is capped at them and grows " + "inward, into the closed shape that makes, whatever flip says; one whose rim can't be capped is r" + "efused. A single face or a closed shell is offset face by face along each face's normal, the one" + " query_topology gives, or against it with flip; a closed shell can fail to thicken this way.\",\"p" + "arams\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"sheet body; omit for the las" + "t body\"},{\"name\":\"thickness\",\"type\":\"number\",\"unit\":\"mm\",\"default\":2},{\"name\":\"flip\",\"type\":\"boo" + "lean\",\"default\":false}],\"examples\":[{\"title\":\"A 30 x 20 mm sheet thickened into a 2 mm plate, a " + "new body\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"r" + "ect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_fill\",\"args\":{\"sketch\":0" + "}},{\"tool\":\"thicken_surf\",\"args\":{\"thickness\":2}}]},{\"title\":\"An open tube thickened 1.5 mm outw" + "ard into a pipe: flip, as its normal points inward\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"pla" + "ne\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":10,\"type\":\"circle\"}" + "]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_extrude\",\"args\":{\"distance\":20,\"sketch\":0}}" + ",{\"tool\":\"thicken_surf\",\"args\":{\"body\":0,\"flip\":true,\"thickness\":1.5}}]}],\"ids\":false}"}, + {"hole", L_CONTEXT("Hole", "Design"), 2, "Shift+H", "key:S+H", L("Pick a face or a plane to drill into"), 0x00000402u, 1, 0, false, false, nullptr, "design_hole", L("Drill a hole, centered on a picked face or placed on a plane"), false, CadAccess::Change, false, + "{\"summary\":\"Drill a circular hole at (x,y) or `at` on a plane.\",\"details\":\"Reply: hole_index, bo" + "dy, x and y in the frame, off_plane with at, frame.\",\"params\":[{\"name\":\"diameter\",\"type\":\"number" + "\",\"unit\":\"mm\",\"default\":5,\"exclusive_min\":0},{\"name\":\"depth\",\"type\":\"number\",\"unit\":\"mm\",\"defaul" + "t\":10},{\"name\":\"through\",\"type\":\"boolean\",\"default\":false},{\"name\":\"x\",\"type\":\"number\",\"unit\":\"m" + "m\",\"default\":0,\"description\":\"offset in the plane's frame from its origin, NOT world\"},{\"name\":\"" + "y\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0,\"description\":\"offset in the plane's frame from its o" + "rigin, NOT world\"},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", " + "\\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"fa" + "ce\\\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x" + " along its longest edge). The reply's frame gives the axes.\"},{\"name\":\"at\",\"type\":\"array|object\"" + ",\"default\":null,\"description\":\"instead of x and y: a world point [x, y, z], projected onto the p" + "lane along its normal (off_plane says how far), or {\\\"body\\\": b, \\\"face\\\": f} a cylindrical face" + " or {\\\"body\\\": b, \\\"edge\\\": e} a circular edge whose axis the hole shares. A world point moves w" + "ith modeling_origin; x and y replay on any printer\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-" + "1,\"description\":\"the body to drill; omit for a face plane's body, else the last body\"}],\"example" + "s\":[{\"title\":\"A 5 mm hole through the middle of a plate\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"through\":true}}]},{\"title" + "\":\"A 4 mm hole 3 mm deep into a plate's top face, 5 mm off centre\",\"calls\":[{\"tool\":\"extrude\",\"a" + "rgs\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"" + "body\":0}},{\"tool\":\"hole\",\"args\":{\"depth\":3,\"diameter\":4,\"generation\":{\"from_call\":1,\"key\":\"gener" + "ation\"},\"plane\":{\"body\":0,\"face\":5},\"x\":5}}]}],\"ids\":true}"}, + {"thread", L_CONTEXT("Thread", "Design"), 2, "Shift+T", "key:S+T", L("Pick a cylindrical surface (bore / outer) or a circular edge for a thread"), 0x00000024u, 1, 0, false, false, nullptr, "design_thread", L("Thread a cylindrical surface (inner bore / outer) or a circular edge"), false, CadAccess::Change, false, + "{\"summary\":\"Cut a thread as the Thread card does, along a cylindrical face or a circular edge, o" + "r on a plane.\",\"details\":\"On a face a bore is tapped, a boss threaded; on a plane the thread goe" + "s at (x,y) or `at`. Without designation, a face or edge takes the nearest standard size, ISO met" + "ric and UTS alike. Long threads take seconds and the reply may be a job. Reply: thread_index, de" + "signation (null when custom), internal, diameter, pitch, depth, length, body, x, y, frame.\",\"par" + "ams\":[{\"name\":\"face\",\"type\":\"integer\",\"default\":null,\"description\":\"a cylindrical face id of `bo" + "dy` (query_topology); the thread runs its length from its lower end\"},{\"name\":\"edge\",\"type\":\"int" + "eger\",\"default\":null,\"description\":\"instead of face: a circular edge id of `body`, the thread ri" + "sing along its normal; needs length\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\"" + ":\"the body of face or edge, or the body threaded on a plane; omit for the last body (on a plane," + " a face plane's body)\"},{\"name\":\"designation\",\"type\":\"string\",\"default\":null,\"description\":\"e.g." + " M5, M8x1, 1/4-20 UNC: sets diameter, pitch and depth\"},{\"name\":\"internal\",\"type\":\"boolean\",\"def" + "ault\":null,\"description\":\"true taps a hole, false threads a rod; required on a plane, else from " + "the face (a bore is internal), external for an edge\"},{\"name\":\"diameter\",\"type\":\"number\",\"unit\":" + "\"mm\",\"default\":null,\"description\":\"nominal (major) diameter, replacing the standard's; with pitc" + "h, a custom thread\"},{\"name\":\"pitch\",\"type\":\"number\",\"unit\":\"mm\",\"default\":null,\"description\":\"r" + "eplaces the standard's\"},{\"name\":\"depth\",\"type\":\"number\",\"unit\":\"mm\",\"default\":null,\"description" + "\":\"radial depth; default the 60 degree V's for the pitch and role\"},{\"name\":\"length\",\"type\":\"num" + "ber\",\"unit\":\"mm\",\"default\":null,\"description\":\"default the face's length; required for an edge o" + "r a plane\"},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":null,\"nullable\":false,\"description\"" + ":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\" + "\": b, \\\"face\\\": f}, a planar face to drill into that body (origin at its centroid, normal into t" + "he body, x along its longest edge). The reply's frame gives the axes.\"},{\"name\":\"x\",\"type\":\"numb" + "er\",\"unit\":\"mm\",\"default\":0,\"description\":\"on a plane: offset in the plane's frame from its orig" + "in, NOT world\"},{\"name\":\"y\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0,\"description\":\"on a plane: o" + "ffset in the plane's frame from its origin, NOT world\"},{\"name\":\"at\",\"type\":\"array|object\",\"defa" + "ult\":null,\"description\":\"on a plane, instead of x and y: a world point [x, y, z], or {\\\"body\\\": " + "b, \\\"face\\\": f} a cylindrical face or {\\\"body\\\": b, \\\"edge\\\": e} a circular edge whose axis the " + "thread shares, as hole takes it\"}],\"examples\":[{\"title\":\"An M8 thread tapped into a 6.8 mm hole " + "through a block\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"too" + "l\":\"hole\",\"args\":{\"diameter\":6.8,\"through\":true}},{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"kin" + "ds\":[\"cylindrical\"]}},{\"tool\":\"thread\",\"args\":{\"body\":0,\"designation\":\"M8\",\"face\":6,\"generation\"" + ":{\"from_call\":2,\"key\":\"generation\"}}}]},{\"title\":\"An M6 threaded rod 10 mm long, standing on the" + " XY plane\",\"calls\":[{\"tool\":\"thread\",\"args\":{\"designation\":\"M6\",\"internal\":false,\"length\":10,\"pl" + "ane\":\"XY\"}}]},{\"title\":\"A 10 mm boss threaded at the nearest standard size, which the reply's de" + "signation names\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"ar" + "gs\":{\"entities\":[{\"center\":[0,0],\"radius\":5,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{" + "}},{\"tool\":\"extrude\",\"args\":{\"distance\":12,\"sketch\":0}},{\"tool\":\"query_topology\",\"args\":{\"body\":" + "0,\"kinds\":[\"cylindrical\"]}},{\"tool\":\"thread\",\"args\":{\"body\":0,\"face\":0,\"generation\":{\"from_call\"" + ":4,\"key\":\"generation\"}}}]}],\"ids\":true}"}, + {"shell", L_CONTEXT("Shell", "Design"), 2, "Shift+K", "key:S+K", L("Shell needs a solid body — add or import one first"), 0x00000082u, 1, 0, false, false, nullptr, "design_shell", L("Hollow the body to a wall thickness, opening a picked face"), false, CadAccess::Change, true, + "{\"summary\":\"Hollow a body to a wall thickness (inward); optionally leave one face open.\",\"detail" + "s\":\"\",\"params\":[{\"name\":\"thickness\",\"type\":\"number\",\"unit\":\"mm\",\"default\":1,\"exclusive_min\":0},{" + "\"name\":\"face\",\"type\":\"integer\",\"default\":-1,\"description\":\"face id to leave open (query_topology" + "); omit for a closed hollow\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target" + " body; omit for the last body\"}],\"examples\":[{\"title\":\"A 20 x 20 x 10 mm box hollowed to 1.5 mm " + "walls, open at the top\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}" + "},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"shell\",\"args\":{\"body\":0" + ",\"face\":5,\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"thickness\":1.5}}]},{\"title\":\"A block " + "hollowed to closed 2 mm walls\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"wid" + "th\":20}},{\"tool\":\"shell\",\"args\":{\"thickness\":2}}]}],\"ids\":true}"}, + {"cut", L_CONTEXT("Cut", "Design"), 2, "Shift+X", "key:S+X", L("Cut needs a solid body — add or import one first"), 0x000004feu, 1, 0, false, false, nullptr, "design_cut", L("Trim the body with a plane — drag the offset arrow; keep one half or both"), false, CadAccess::None, false, + nullptr}, + {"split", L_CONTEXT("Split", "Design"), 2, nullptr, nullptr, L("Split needs a solid body — add or import one first"), 0x000000feu, 1, 0, false, false, nullptr, nullptr, L("Split the body along a picked face into two solids"), false, CadAccess::Change, false, + "{\"summary\":\"Split a body with a plane, as the Cut card does, moved by offset and turned over by " + "flip; or along the plane of a face.\",\"details\":\"The upper piece is on the plane's normal side; k" + "eeping both makes two bodies, the lower one right after the upper. Reply: split_index, bodies, b" + "ody, upper_body and lower_body (the pieces kept), frame (a plane's, after offset and flip).\",\"pa" + "rams\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body; omit for the las" + "t body\"},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":null,\"description\":\"\\\"XY\\\", \\\"XZ\\\" or " + "\\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, " + "a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply" + "'s frame gives the axes.\"},{\"name\":\"offset\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0,\"description" + "\":\"with plane: along its normal\"},{\"name\":\"flip\",\"type\":\"boolean\",\"default\":false,\"description\":" + "\"with plane: turn it over, swapping upper and lower\"},{\"name\":\"face\",\"type\":\"integer\",\"default\":" + "null,\"description\":\"instead of plane: a face id (query_topology) to split along\"},{\"name\":\"face_" + "body\",\"type\":\"integer\",\"default\":-1,\"description\":\"with face: the body that owns it; -1 = target" + "\"},{\"name\":\"keep_upper\",\"type\":\"boolean\",\"default\":true},{\"name\":\"keep_lower\",\"type\":\"boolean\",\"" + "default\":true}],\"examples\":[{\"title\":\"A block cut in two at half its height\",\"calls\":[{\"tool\":\"e" + "xtrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"split\",\"args\":{\"offset\":5,\"plane" + "\":\"XY\"}}]},{\"title\":\"A block cut at half its height, keeping only the lower half\",\"calls\":[{\"too" + "l\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"split\",\"args\":{\"keep_upper\"" + ":false,\"offset\":5,\"plane\":\"XY\"}}]},{\"title\":\"A block split along the top face of a wider plate\"," + "\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"arg" + "s\":{\"boolean\":\"new\",\"distance\":4,\"height\":30,\"width\":30}},{\"tool\":\"query_topology\",\"args\":{\"at_e" + "xtreme\":\"+z\",\"body\":1}},{\"tool\":\"split\",\"args\":{\"body\":0,\"face\":5,\"face_body\":1,\"generation\":{\"f" + "rom_call\":2,\"key\":\"generation\"}}}]}],\"ids\":true}"}, + {"fillet", L_CONTEXT("Fillet", "Design"), 3, "Shift+F", "btn:dress#0", L("Pick an edge to round"), 0x000000b2u, 1, 0, false, false, nullptr, "design_filletedge", L("Pick an edge, then drag the radius arrow or type it"), false, CadAccess::Change, true, + "{\"summary\":\"Round measured edges of a body (edge ids from query_topology on that body).\",\"detail" + "s\":\"\",\"params\":[{\"name\":\"edge\",\"type\":\"integer|array\",\"description\":\"one edge id, or an array of" + " ids rounded together in one feature\"},{\"name\":\"radius\",\"type\":\"number\",\"unit\":\"mm\",\"default\":1," + "\"exclusive_min\":0},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body; omit" + " for the last body. edge id is resolved against THIS body.\"}],\"examples\":[{\"title\":\"A plate's fo" + "ur vertical corners rounded to 2 mm\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20" + ",\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"convex\":true,\"direction\":[0,0,1],\"edge_" + "kinds\":[\"line\"]}},{\"tool\":\"fillet\",\"args\":{\"body\":0,\"edge\":[0,1,4,7],\"generation\":{\"from_call\":1" + ",\"key\":\"generation\"},\"radius\":2}}]},{\"title\":\"One top edge of a plate rounded to 1 mm\",\"calls\":[" + "{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":" + "{\"adjacency\":true,\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"fillet\",\"args\":{\"body\":0,\"edge\":3,\"gener" + "ation\":{\"from_call\":1,\"key\":\"generation\"},\"radius\":1}}]}],\"ids\":true}"}, + {"chamfer", L_CONTEXT("Chamfer", "Design"), 3, nullptr, "btn:dress#1", L("Pick an edge to bevel"), 0x000000b2u, 1, 0, false, false, nullptr, "design_chamfer", L("Pick an edge, then drag the distance arrow or type it"), false, CadAccess::Change, true, + "{\"summary\":\"Chamfer measured edges of a body (edge ids from query_topology on that body).\",\"deta" + "ils\":\"\",\"params\":[{\"name\":\"edge\",\"type\":\"integer|array\",\"description\":\"one edge id, or an array " + "of ids chamfered together in one feature\"},{\"name\":\"distance\",\"type\":\"number\",\"unit\":\"mm\",\"defau" + "lt\":1,\"exclusive_min\":0},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body" + "; omit for the last body. edge id is resolved against THIS body.\"}],\"examples\":[{\"title\":\"A plat" + "e's top edges chamfered 1 mm\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width" + "\":20}},{\"tool\":\"query_topology\",\"args\":{\"adjacency\":true,\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"c" + "hamfer\",\"args\":{\"body\":0,\"distance\":1,\"edge\":[3,6,9,11],\"generation\":{\"from_call\":1,\"key\":\"gener" + "ation\"}}}]}],\"ids\":true}"}, + {"draft", L_CONTEXT("Draft", "Design"), 3, "Shift+D", "key:S+D", L("Pick a face to taper"), 0x0000000au, 1, 0, false, false, nullptr, "design_draft", L("Tilt a picked face by a draft angle"), false, CadAccess::Change, true, + "{\"summary\":\"Taper a body face by an angle about its base (pull direction +Z).\",\"details\":\"\",\"par" + "ams\":[{\"name\":\"face\",\"type\":\"integer\",\"description\":\"face id to draft (query_topology)\"},{\"name\"" + ":\"angle\",\"type\":\"number\",\"unit\":\"deg\",\"default\":5},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1," + "\"description\":\"target body; omit for the last body\"}],\"examples\":[{\"title\":\"A block's +X side ta" + "pered 5 degrees\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"too" + "l\":\"query_topology\",\"args\":{\"body\":0,\"direction\":[1,0,0]}},{\"tool\":\"draft\",\"args\":{\"angle\":5,\"bo" + "dy\":0,\"face\":1,\"generation\":{\"from_call\":1,\"key\":\"generation\"}}}]}],\"ids\":true}"}, + {"surf_offset", L_CONTEXT("Surface Offset", "Design"), 3, nullptr, "fly:surface#4", L("Surface Offset needs a surface body — make one with a Surface tool first"), 0x00000100u, 0, 0, true, false, nullptr, "design_offset", L("Offset a sheet body's shell by a signed distance"), false, CadAccess::Change, true, + "{\"summary\":\"Offset a sheet body by a signed distance -> another sheet body.\",\"details\":\"A positi" + "ve offset moves each face along its normal, the one query_topology gives, and a negative one aga" + "inst it, so the side depends on how the sheet was made: an extruded circle's normal points inwar" + "d.\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"sheet body; omit for t" + "he last body\"},{\"name\":\"offset\",\"type\":\"number\",\"unit\":\"mm\",\"default\":1}],\"examples\":[{\"title\":\"" + "A rectangular sheet copied 5 mm above itself\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"X" + "Y\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"" + "tool\":\"surf_fill\",\"args\":{\"sketch\":0}},{\"tool\":\"surf_offset\",\"args\":{\"offset\":5}}]},{\"title\":\"An" + " open tube of radius 10 mm offset -2 mm, against its inward normal, to one of radius 12 mm\",\"cal" + "ls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"ce" + "nter\":[0,0],\"radius\":10,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"surf_ext" + "rude\",\"args\":{\"distance\":20,\"sketch\":0}},{\"tool\":\"surf_offset\",\"args\":{\"body\":0,\"offset\":-2}}]}]" + ",\"ids\":false}"}, + {"pattern", L_CONTEXT("Linear pattern", "Design"), 4, "Shift+N", "btn:pat#0", L("Pattern needs a solid body — add or import one first"), 0x00006082u, 1, 0, false, false, nullptr, "design_array", L("Repeat the body along a direction — drag the spacing, set the count"), false, CadAccess::Change, true, + "{\"summary\":\"Replicate a body: linear (count along a plane axis at spacing) or circular (count ov" + "er an angle about the plane normal).\",\"details\":\"\",\"params\":[{\"name\":\"circular\",\"type\":\"boolean\"" + ",\"default\":false},{\"name\":\"count\",\"type\":\"integer\",\"default\":3,\"min\":1},{\"name\":\"spacing\",\"type\"" + ":\"number\",\"unit\":\"mm\",\"default\":10,\"description\":\"linear step\"},{\"name\":\"dir\",\"type\":\"integer\",\"" + "default\":0,\"enum\":[0,1],\"description\":\"linear axis: 0=plane X, 1=plane Y\"},{\"name\":\"angle\",\"type" + "\":\"number\",\"unit\":\"deg\",\"default\":360,\"description\":\"circular total sweep\"},{\"name\":\"plane\",\"typ" + "e\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origi" + "n; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, a planar face (origin at its " + "centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.\"},{\"" + "name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body; omit for the last body\"}]" + ",\"examples\":[{\"title\":\"Three plates 30 mm apart along X\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"height\":20,\"width\":20}},{\"tool\":\"pattern\",\"args\":{\"count\":3,\"spacing\":30}}]},{\"title\":" + "\"Six blocks in a circle about the XY plane's normal\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distanc" + "e\":5,\"profile\":[[20,-3],[30,-3],[30,3],[20,3]]}},{\"tool\":\"pattern\",\"args\":{\"circular\":true,\"coun" + "t\":6}}]}],\"ids\":true}"}, + {"pattern_circular", L_CONTEXT("Circular pattern", "Design"), 4, nullptr, "btn:pat#1", L("Pattern needs a solid body — add or import one first"), 0x00006082u, 1, 0, false, false, nullptr, "design_polararray", L("Repeat the body around an axis — set the count and sweep"), false, CadAccess::None, false, + nullptr}, + {"mirror", L_CONTEXT("Mirror", "Design"), 4, "Shift+Z", "key:S+Z", L("Mirror needs a body — add or import one first"), 0x000004feu, 1, 0, false, false, nullptr, "design_mirror", L("Reflect a body about a plane"), false, CadAccess::Change, true, + "{\"summary\":\"Mirror a body about a base plane.\",\"details\":\"mode=new creates a mirrored copy; mode" + "=add fuses the mirror back into the source.\",\"params\":[{\"name\":\"plane\",\"type\":\"string|object\",\"d" + "efault\":\"XZ\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a " + "Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, a planar face (origin at its centroid, normal out " + "of the body, x from the world axes). The reply's frame gives the axes.\"},{\"name\":\"mode\",\"type\":\"" + "string\",\"default\":\"new\",\"enum\":[\"new\",\"add\"]},{\"name\":\"keep_original\",\"type\":\"boolean\",\"default\"" + ":true,\"description\":\"when mode=new, keep the source body\"},{\"name\":\"body\",\"type\":\"integer\",\"defa" + "ult\":-1,\"description\":\"target body; omit for the last body\"}],\"examples\":[{\"title\":\"A mirrored c" + "opy of a block across the XZ plane\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"profile\":[[" + "-5,5],[5,5],[5,15],[-5,15]]}},{\"tool\":\"mirror\",\"args\":{\"plane\":\"XZ\"}}]},{\"title\":\"A block agains" + "t the XZ plane and its mirror image fused into one body\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"profile\":[[-5,0],[5,0],[5,10],[-5,10]]}},{\"tool\":\"mirror\",\"args\":{\"mode\":\"add\",\"plane\"" + ":\"XZ\"}}]}],\"ids\":true}"}, + {"pat_curve", L_CONTEXT("Pattern on Curve", "Design"), 4, nullptr, nullptr, L("Pattern on Curve needs a body and a curve"), 0x00000090u, 1, 0, false, false, nullptr, nullptr, L("Repeat the body along a picked curve"), false, CadAccess::Change, true, + "{\"summary\":\"Replicate a body along a sketch curve.\",\"details\":\"`count` copies are placed at equa" + "l-parameter points on the entity, each translated by (P_i - P_0).\",\"params\":[{\"name\":\"count\",\"ty" + "pe\":\"integer\",\"default\":3,\"min\":1},{\"name\":\"sketch\",\"type\":\"integer\",\"description\":\"feature inde" + "x of the sketch holding the guide curve\"},{\"name\":\"entity\",\"type\":\"integer\",\"description\":\"entit" + "y index of the guide curve within that sketch\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"de" + "scription\":\"target body; omit for the last body\"}],\"examples\":[{\"title\":\"Four pegs spaced along " + "a half circle\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args" + "\":{\"entities\":[{\"center\":[0,0],\"end_angle_deg\":180,\"radius\":30,\"start_angle_deg\":0,\"type\":\"arc\"}" + "]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"profile\":[[28,-2" + "],[32,-2],[32,2],[28,2]]}},{\"tool\":\"pat_curve\",\"args\":{\"count\":4,\"entity\":0,\"sketch\":0}}]}],\"ids" + "\":false}"}, + {"body_transform", L_CONTEXT("Move", "Design"), 5, "Shift+Y", "key:S+Y", L("Transform needs a body — add or import one first"), 0x000021feu, 1, 0, false, false, nullptr, "design_move", L("Move and/or rotate an existing body"), false, CadAccess::Change, true, + "{\"summary\":\"Move and/or rotate a body (B-rep transform).\",\"details\":\"copy=true keeps the source " + "and appends the transformed copy as a new body.\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"defa" + "ult\":-1,\"description\":\"target body; omit for the last body\"},{\"name\":\"dx\",\"type\":\"number\",\"unit\"" + ":\"mm\",\"default\":0},{\"name\":\"dy\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":\"dz\",\"type\":\"nu" + "mber\",\"unit\":\"mm\",\"default\":0},{\"name\":\"axis_x\",\"type\":\"number\",\"default\":0},{\"name\":\"axis_y\",\"t" + "ype\":\"number\",\"default\":0},{\"name\":\"axis_z\",\"type\":\"number\",\"default\":1},{\"name\":\"pivot_x\",\"type" + "\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":\"pivot_y\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{" + "\"name\":\"pivot_z\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":\"angle\",\"type\":\"number\",\"unit\"" + ":\"deg\",\"default\":0},{\"name\":\"copy\",\"type\":\"boolean\",\"default\":false}],\"examples\":[{\"title\":\"A pl" + "ate moved 30 mm along X\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}" + "},{\"tool\":\"body_transform\",\"args\":{\"dx\":30}}]},{\"title\":\"A copy of a plate 10 mm above it\",\"call" + "s\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"body_transform\",\"ar" + "gs\":{\"copy\":true,\"dz\":10}}]}],\"ids\":false}"}, + {"mate", L_CONTEXT("Mate", "Design"), 5, nullptr, "fly:placement#2", L("Mate needs two coordinate systems — create them first"), 0x00001202u, 2, 0, false, false, nullptr, "design_c_coincident", L("Assembly: align two coordinate systems (fastened, planar, revolute, slider, cylindrical)"), false, CadAccess::Change, true, + "{\"summary\":\"Mate two bodies: transform the moving body (cs_b) so its connector lands on the fixe" + "d one (cs_a).\",\"details\":\"kind: 0=Fastened, 1=Planar, 2=Revolute, 3=Slider, 4=Cylindrical.\",\"par" + "ams\":[{\"name\":\"kind\",\"type\":\"integer\",\"default\":0,\"description\":\"0=Fastened (rigid), 1=Planar (n" + "ormal only), 2=Revolute (free rotation about axis), 3=Slider (free translation along axis), 4=Cy" + "lindrical (free rotation+translation)\"},{\"name\":\"cs_a\",\"type\":\"integer\",\"description\":\"feature i" + "ndex of the fixed CoordSys (mate connector A)\"},{\"name\":\"cs_b\",\"type\":\"integer\",\"description\":\"f" + "eature index of the CoordSys on the body that moves\"},{\"name\":\"offset\",\"type\":\"number\",\"unit\":\"m" + "m\",\"default\":0},{\"name\":\"angle\",\"type\":\"number\",\"unit\":\"deg\",\"default\":0},{\"name\":\"flip\",\"type\":" + "\"boolean\",\"default\":false}],\"examples\":[{\"title\":\"A block stood on a plate: its bottom-face conn" + "ector fastened, turned over, to the plate's top-face one\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"di" + "stance\":5,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"distance\":10,\"prof" + "ile\":[[30,-5],[40,-5],[40,5],[30,5]]}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\"" + ":0}},{\"tool\":\"coordsys_v\",\"args\":{\"body\":0,\"face\":5,\"generation\":{\"from_call\":2,\"key\":\"generatio" + "n\"},\"type\":\"face_and_direction\"}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"-z\",\"body\":1}}," + "{\"tool\":\"coordsys_v\",\"args\":{\"body\":1,\"face\":4,\"generation\":{\"from_call\":4,\"key\":\"generation\"},\"" + "type\":\"face_and_direction\"}},{\"tool\":\"mate\",\"args\":{\"cs_a\":4,\"cs_b\":5,\"flip\":true,\"kind\":0}}]}]," + "\"ids\":false}"}, + {"align", L_CONTEXT("Align to", "Design"), 5, nullptr, nullptr, L("Align needs a body — add or import one first"), 0x00000002u, 1, 0, false, false, nullptr, nullptr, L("Align the body to a picked face or plane"), false, CadAccess::None, false, + nullptr}, + {"plane", L_CONTEXT("Plane", "Design"), 6, "Shift+P", "key:S+P", nullptr, 0x00000453u, 0, 0, false, false, nullptr, "design_plane", L("Reference plane (offset / tilt / midplane / tangent / two edges / coincident)"), false, CadAccess::Change, false, + "{\"summary\":\"Add a datum plane as the Plane card does, to sketch or build on as {\\\"datum\\\": plane" + "_index}.\",\"details\":\"Offset from a base plane or a face, at an angle about an edge, midway betwe" + "en two faces, tangent to a cylindrical face, through two edges, or coincident with a base plane " + "or a face. Not the `plane` param of other Design commands. Reply: plane_index, name, frame.\",\"pa" + "rams\":[{\"name\":\"type\",\"type\":\"string\",\"default\":\"offset\",\"enum\":[\"offset\",\"angle\",\"midplane\",\"ta" + "ngent\",\"two_edges\",\"coincident\"]},{\"name\":\"base\",\"type\":\"string|object\",\"default\":\"XY\",\"descript" + "ion\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin, or {\\\"datum\\\": i}: what offset, coincide" + "nt and angle build on without face_a\"},{\"name\":\"offset\",\"type\":\"number\",\"unit\":\"mm\",\"default\":20" + ",\"description\":\"offset: distance along the normal of base or face_a\"},{\"name\":\"angle\",\"type\":\"nu" + "mber\",\"unit\":\"deg\",\"default\":0,\"description\":\"offset without face_a: tilt about the base axis `a" + "xis`; angle: turn about edge_a from the reference plane; tangent: position around the cylinder\"}" + ",{\"name\":\"axis\",\"type\":\"integer\",\"default\":0,\"enum\":[0,1],\"description\":\"offset without face_a: " + "tilt about the base plane's X (0) or Y (1) axis\"},{\"name\":\"face_a\",\"type\":\"object\",\"default\":nul" + "l,\"description\":\"Face A, {\\\"body\\\": b, \\\"face\\\": f}: offset or coincident on a face; angle's ref" + "erence plane; midplane's first face; tangent's cylindrical face\"},{\"name\":\"face_b\",\"type\":\"objec" + "t\",\"default\":null,\"description\":\"Face B, {\\\"body\\\": b, \\\"face\\\": f}: midplane's second face\"},{\"" + "name\":\"edge_a\",\"type\":\"object\",\"default\":null,\"description\":\"Edge A, {\\\"body\\\": b, \\\"edge\\\": e}:" + " angle's hinge; two_edges' first edge\"},{\"name\":\"edge_b\",\"type\":\"object\",\"default\":null,\"descrip" + "tion\":\"Edge B, {\\\"body\\\": b, \\\"edge\\\": e}: two_edges' second edge\"},{\"name\":\"size\",\"type\":\"array" + "\",\"unit\":\"mm\",\"default\":[60,60],\"description\":\"[u, v]: the size the plane is drawn at\"}],\"exampl" + "es\":[{\"title\":\"A datum plane 20 mm above XY\",\"calls\":[{\"tool\":\"plane\",\"args\":{\"base\":\"XY\",\"offse" + "t\":20,\"type\":\"offset\"}}]},{\"title\":\"A datum plane midway between a block's top and bottom faces\"" + ",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"query_topolo" + "gy\",\"args\":{\"body\":0,\"kinds\":[\"planar\"]}},{\"tool\":\"plane\",\"args\":{\"face_a\":{\"body\":0,\"face\":4},\"" + "face_b\":{\"body\":0,\"face\":5},\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"type\":\"midplane\"}}]" + "},{\"title\":\"A datum plane turned 30 degrees from a plate's top face about its front edge\",\"calls" + "\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"arg" + "s\":{\"adjacency\":true,\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"plane\",\"args\":{\"angle\":30,\"edge_a\":{\"" + "body\":0,\"edge\":3},\"face_a\":{\"body\":0,\"face\":5},\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"" + "type\":\"angle\"}}]}],\"ids\":true}"}, + {"axis", L_CONTEXT("Axis", "Design"), 6, "Shift+A", "key:S+A", nullptr, 0x00000057u, 0, 0, false, false, nullptr, "design_line", L("Datum axis (two points, face normal, cylinder centerline, two planes, along edge)"), false, CadAccess::Change, true, + "{\"summary\":\"Create a datum axis (reference line): two points, face normal, cylinder centreline, " + "plane intersection, or along edge.\",\"details\":\"\",\"params\":[{\"name\":\"type\",\"type\":\"string\",\"defau" + "lt\":\"two_points\",\"enum\":[\"two_points\",\"face_normal\",\"cylinder\",\"plane_intersection\",\"along_edge\"" + "]},{\"name\":\"p1\",\"type\":\"array\",\"default\":[0,0,0],\"description\":\"first point [x,y,z] for two_poin" + "ts\"},{\"name\":\"p2\",\"type\":\"array\",\"default\":[0,0,10],\"description\":\"second point [x,y,z] for two_" + "points\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"body for face/edge refs\"},{" + "\"name\":\"face\",\"type\":\"integer\",\"default\":-1,\"description\":\"face id (query_topology) for face_nor" + "mal/cylinder\"},{\"name\":\"edge\",\"type\":\"integer\",\"default\":-1,\"description\":\"edge id (query_topolo" + "gy) for along_edge\"},{\"name\":\"plane_a\",\"type\":\"integer\",\"default\":-1,\"description\":\"first datum " + "plane feature index for plane_intersection\"},{\"name\":\"plane_b\",\"type\":\"integer\",\"default\":-1,\"de" + "scription\":\"second datum plane feature index for plane_intersection\"}],\"examples\":[{\"title\":\"The" + " axis of a hole through a plate\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"wi" + "dth\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"through\":true}},{\"tool\":\"query_topology\",\"args\":{" + "\"body\":0,\"kinds\":[\"cylindrical\"]}},{\"tool\":\"axis\",\"args\":{\"body\":0,\"face\":6,\"generation\":{\"from_" + "call\":2,\"key\":\"generation\"},\"type\":\"cylinder\"}}]},{\"title\":\"The normal through the centre of a p" + "late's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool" + "\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"axis\",\"args\":{\"body\":0,\"face\":5" + ",\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"type\":\"face_normal\"}}]},{\"title\":\"The vertical" + " line where two datum planes meet\",\"calls\":[{\"tool\":\"plane\",\"args\":{\"base\":\"XZ\",\"offset\":10,\"typ" + "e\":\"offset\"}},{\"tool\":\"plane\",\"args\":{\"base\":\"YZ\",\"offset\":10,\"type\":\"offset\"}},{\"tool\":\"axis\",\"" + "args\":{\"plane_a\":0,\"plane_b\":1,\"type\":\"plane_intersection\"}}]}],\"ids\":true}"}, + {"coordsys_v", L_CONTEXT("Coordinate system", "Design"), 6, "Shift+C", "key:S+C", nullptr, 0x00000043u, 0, 0, false, false, nullptr, "design_point", L("Datum coordinate system (world point, or face + direction edge)"), false, CadAccess::Change, true, + "{\"summary\":\"Create a datum coordinate system (origin + orthonormal axes).\",\"details\":\"PointWorld" + " aligns to world; FaceAndDirection uses a face for Z and an edge/hint for X.\",\"params\":[{\"name\":" + "\"type\",\"type\":\"string\",\"default\":\"point_world\",\"enum\":[\"point_world\",\"face_and_direction\"]},{\"na" + "me\":\"point\",\"type\":\"array\",\"default\":[0,0,0],\"description\":\"origin [x,y,z] for point_world\"},{\"n" + "ame\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"body for face/edge refs\"},{\"name\":\"face" + "\",\"type\":\"integer\",\"default\":-1,\"description\":\"face id (query_topology) for Z axis\"},{\"name\":\"ed" + "ge\",\"type\":\"integer\",\"default\":-1,\"description\":\"edge id (query_topology) for X axis hint\"},{\"na" + "me\":\"x_hint\",\"type\":\"array\",\"default\":[1,0,0],\"description\":\"fallback X direction hint if no edg" + "e given\"}],\"examples\":[{\"title\":\"A connector on a plate's top face, its x axis along the front e" + "dge\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_top" + "ology\",\"args\":{\"adjacency\":true,\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"coordsys_v\",\"args\":{\"body\"" + ":0,\"edge\":3,\"face\":5,\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"type\":\"face_and_direction\"" + "}}]}],\"ids\":true}"}, + {"helix", L_CONTEXT("Helix", "Design"), 6, nullptr, "fly:plane#3", nullptr, 0x00000405u, 0, 0, false, false, nullptr, "design_thread", L("Helical curve (spring path) — use as a sweep path for coils / springs / augers"), false, CadAccess::Change, false, + "{\"summary\":\"Create a helical curve, a sweep path for springs, coils and augers.\",\"details\":\"It s" + "tarts on the plane's x axis at `radius` from its origin. pitch = axial rise per turn. left_hande" + "d flips the winding. taper_deg != 0 gives a conical helix. Reply: helix_index, frame, start and " + "tangent (world), to draw a sweep's profile across the curve there.\",\"params\":[{\"name\":\"radius\",\"" + "type\":\"number\",\"unit\":\"mm\",\"default\":10,\"exclusive_min\":0},{\"name\":\"pitch\",\"type\":\"number\",\"unit" + "\":\"mm\",\"default\":5,\"exclusive_min\":0},{\"name\":\"height\",\"type\":\"number\",\"unit\":\"mm\",\"default\":20," + "\"exclusive_min\":0},{\"name\":\"left_handed\",\"type\":\"boolean\",\"default\":false},{\"name\":\"taper_deg\",\"" + "type\":\"number\",\"unit\":\"deg\",\"default\":0},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"" + "description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature;" + " or {\\\"body\\\": b, \\\"face\\\": f}, a planar face (origin at its centroid, normal out of the body, x" + " from the world axes). The reply's frame gives the axes.\"}],\"examples\":[{\"title\":\"A four-turn he" + "lix on XY: radius 10 mm, pitch 5 mm, 20 mm tall\",\"calls\":[{\"tool\":\"helix\",\"args\":{\"height\":20,\"p" + "itch\":5,\"radius\":10}}]},{\"title\":\"A left-handed conical helix tapering 10 degrees\",\"calls\":[{\"to" + "ol\":\"helix\",\"args\":{\"height\":20,\"left_handed\":true,\"pitch\":4,\"radius\":10,\"taper_deg\":10}}]}],\"id" + "s\":true}"}, + {"project", L_CONTEXT("Project", "Design"), 6, nullptr, "fly:plane#4", L("Project needs a body — add or import one first"), 0x00000482u, 1, 0, false, false, nullptr, "design_sketch", L("Project body edges onto a plane as sketch entities"), false, CadAccess::Change, true, + "{\"summary\":\"Project edges of a solid onto a sketch plane, producing a new sketch feature.\",\"deta" + "ils\":\"\",\"params\":[{\"name\":\"source_body\",\"type\":\"integer\",\"default\":-1,\"description\":\"body owning" + " the edges; -1 = last body\"},{\"name\":\"face\",\"type\":\"integer\",\"default\":-1,\"description\":\"global " + "face id on the source body; when set, all its edges are projected\"},{\"name\":\"edges\",\"type\":\"arra" + "y\",\"default\":[],\"description\":\"global edge ids to project; empty => project the face\"},{\"name\":\"" + "plane\",\"type\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through mod" + "eling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, a planar face (ori" + "gin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the" + " axes.\"}],\"examples\":[{\"title\":\"A plate's top-face outline projected onto the XY plane as a new " + "sketch\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_" + "topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"project\",\"args\":{\"face\":5,\"generation\":{" + "\"from_call\":1,\"key\":\"generation\"},\"plane\":\"XY\",\"source_body\":0}}]},{\"title\":\"Two top edges of a " + "plate, meeting at a corner, projected onto the XY plane\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"adjacency\":true,\"at_extreme\"" + ":\"+z\",\"body\":0}},{\"tool\":\"project\",\"args\":{\"edges\":[3,6],\"generation\":{\"from_call\":1,\"key\":\"gene" + "ration\"},\"plane\":\"XY\",\"source_body\":0}}]}],\"ids\":true}"}, + {"measure", L_CONTEXT("Measure", "Design"), 6, nullptr, nullptr, nullptr, 0x000b03feu, 0, 0, false, false, nullptr, nullptr, L("Measure between the picked points, edges or faces"), false, CadAccess::Read, false, + "{\"summary\":\"Measure two refs, on one body or two: distance, closest points, angle and the gap be" + "tween parallel faces.\",\"details\":\"distance is between their representative points (a face's cent" + "roid, an edge's middle, an axis's middle); min_distance comes with closest_a and closest_b; angl" + "e_deg when both have a direction; parallel_gap across two parallel planar faces.\",\"params\":[{\"na" + "me\":\"body\",\"type\":\"integer\",\"default\":0,\"description\":\"the body of a ref that names none\"},{\"nam" + "e\":\"a\",\"type\":\"object\",\"description\":\"{\\\"face\\\": f}, {\\\"edge\\\": e} or {\\\"point\\\": [x, y, z]}, wi" + "th an optional \\\"body\\\"; {\\\"face\\\": f, \\\"axis\\\": true} is a cylindrical face's axis over its len" + "gth\"},{\"name\":\"b\",\"type\":\"object\",\"description\":\"as a\"}],\"examples\":[{\"title\":\"A plate's thickne" + "ss, between its top and bottom faces\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":2" + "0,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"kinds\":[\"planar\"]}},{\"tool\":\"measure\"," + "\"args\":{\"a\":{\"face\":5},\"b\":{\"face\":4},\"body\":0,\"generation\":{\"from_call\":1,\"key\":\"generation\"}}}" + "]},{\"title\":\"The 10 mm gap between two blocks' facing sides\",\"calls\":[{\"tool\":\"extrude\",\"args\":{" + "\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"distance\":10,\"" + "profile\":[[20,-5],[30,-5],[30,5],[20,5]]}},{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"direction\"" + ":[1,0,0]}},{\"tool\":\"query_topology\",\"args\":{\"body\":1,\"direction\":[-1,0,0]}},{\"tool\":\"measure\",\"a" + "rgs\":{\"a\":{\"body\":0,\"face\":1},\"b\":{\"body\":1,\"face\":3},\"generation\":{\"from_call\":3,\"key\":\"generat" + "ion\"}}}]}],\"ids\":true}"}, + {"mass_props", L_CONTEXT("Volume and area", "Design"), 6, nullptr, "btn:mass", nullptr, 0x000000feu, 1, 0, false, false, nullptr, "info", L("Report the volume and surface area of the selected body"), false, CadAccess::Read, false, + "{\"summary\":\"Volume / surface area / centre of mass / inertia tensor of a body.\",\"details\":\"\",\"pa" + "rams\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":0}],\"examples\":[{\"title\":\"The volume and centre" + " of mass of a 20 x 20 x 5 mm plate\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20," + "\"width\":20}},{\"tool\":\"mass_props\",\"args\":{\"body\":0}}]}],\"ids\":false}"}, + {"interference", L_CONTEXT("Interference", "Design"), 6, nullptr, "btn:interference", L("Interference needs at least two bodies"), 0x00000280u, 2, 0, false, false, nullptr, "design_boolean", L("Check whether two bodies overlap — reports, changes nothing"), false, CadAccess::Read, false, + "{\"summary\":\"Solid bodies that overlap, as {body_a, body_b, volume}.\",\"details\":\"Read-only; bodie" + "s that merely touch enclose no volume and are not reported.\",\"params\":[{\"name\":\"min_volume\",\"typ" + "e\":\"number\",\"unit\":\"mm^3\",\"default\":1e-06,\"description\":\"overlap volume above which a pair count" + "s as interfering\"}],\"examples\":[{\"title\":\"A post standing in a block: the two overlap\",\"calls\":[" + "{\"tool\":\"extrude\",\"args\":{\"distance\":10,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"bool" + "ean\":\"new\",\"distance\":20,\"height\":10,\"width\":10}},{\"tool\":\"interference\",\"args\":{\"silent\":true}}" + "]}],\"ids\":false}"}, + {"edit_feature", L_CONTEXT("Edit", "Design"), 7, nullptr, "btn:edit", nullptr, 0x00007d8eu, 0, 0, false, false, nullptr, "design_edit", L("Reopen the selected feature to change what it was made from"), false, CadAccess::Change, true, + "{\"summary\":\"Bind a feature's numeric field to an expression over the design variables, or unbind" + " it with an empty expr.\",\"details\":\"Unbound, the field keeps its value.\",\"params\":[{\"name\":\"feat" + "ure\",\"type\":\"integer\",\"description\":\"feature index (describe_scene)\"},{\"name\":\"field\",\"type\":\"st" + "ring\",\"description\":\"a numeric field of describe_feature's params, e.g. width, distance, hole_di" + "ameter, thread_diameter\"},{\"name\":\"expr\",\"type\":\"string\",\"description\":\"\\\"\\\" removes the binding" + "\"}],\"examples\":[{\"title\":\"A plate's thickness bound to the variable t\",\"calls\":[{\"tool\":\"extrude" + "\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"set_variable\",\"args\":{\"expr\":\"8\",\"name\"" + ":\"t\"}},{\"tool\":\"edit_feature\",\"args\":{\"expr\":\"t\",\"feature\":1,\"field\":\"distance\"}}]},{\"title\":\"A " + "plate's thickness unbound, keeping the 8 mm the binding gave it\",\"calls\":[{\"tool\":\"extrude\",\"arg" + "s\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"set_variable\",\"args\":{\"expr\":\"8\",\"name\":\"t\"}}" + ",{\"tool\":\"edit_feature\",\"args\":{\"expr\":\"t\",\"feature\":1,\"field\":\"distance\"}},{\"tool\":\"edit_featur" + "e\",\"args\":{\"expr\":\"\",\"feature\":1,\"field\":\"distance\"}}]}],\"ids\":false}"}, + {"rename", L_CONTEXT("Rename…", "Design"), 8, "F2", "btn:rename", L("Select a feature, or a body, to rename it"), 0x00004080u, 0, 0, false, false, nullptr, "rename_edit", L("Give this feature a name you will recognise in the tree (a body takes its name from the feature that makes it)"), false, CadAccess::None, false, + nullptr}, + {"delete_face", L_CONTEXT("Delete Face", "Design"), 7, nullptr, "fly:dressup#3", L("Delete Face needs a body — add or import one first"), 0x0000000eu, 1, 0, false, false, nullptr, "design_delete", L("Remove faces from a body and heal the solid"), false, CadAccess::Change, true, + "{\"summary\":\"Remove faces from a solid, healing the gap via OCCT defeaturing.\",\"details\":\"\",\"para" + "ms\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"target body; omit for the last " + "body\"},{\"name\":\"faces\",\"type\":\"array\",\"description\":\"global face ids to delete\"}],\"examples\":[{\"" + "title\":\"A plate's bore filled in by deleting its cylindrical face\",\"calls\":[{\"tool\":\"extrude\",\"a" + "rgs\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"through\":true}}" + ",{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"kinds\":[\"cylindrical\"]}},{\"tool\":\"delete_face\",\"args" + "\":{\"body\":0,\"faces\":[6],\"generation\":{\"from_call\":2,\"key\":\"generation\"}}}]}],\"ids\":true}"}, + {"colour", L_CONTEXT("Color", "Design"), 8, nullptr, "btn:colour", nullptr, 0x000001feu, 1, 0, false, false, nullptr, "color_palette", L("Set the selected body's display color"), true, CadAccess::None, false, + nullptr}, + {"zoom_to", L_CONTEXT("Zoom to selection", "Design"), 8, nullptr, "btn:zoom_to", nullptr, 0x000041feu, 0, 0, false, false, nullptr, "design_zoom", L("Frame the selection in the view, keeping the view direction"), false, CadAccess::None, false, + nullptr}, + {"delete", L_CONTEXT("Delete", "Design"), 7, "Del", "btn:delete", nullptr, 0x000f7c00u, 0, 0, false, false, nullptr, "design_delete", L("Delete what is selected"), false, CadAccess::None, false, + nullptr}, + {"delete_body", L_CONTEXT("Delete Body", "Design"), 7, nullptr, "btn:delete_body", nullptr, 0x000001feu, 1, 0, false, false, nullptr, "design_delete", L("Delete this whole body — removes the feature it was made from"), false, CadAccess::None, false, + nullptr}, + {"sk_line_t", L_CONTEXT("Line", "Design"), 0, "L", "key:L", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Line", "Design"), "design_line", L("Line — click start, then end"), false, CadAccess::None, false, + nullptr}, + {"sk_polyline", L_CONTEXT("Polyline", "Design"), 0, nullptr, "fly:design_line#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Line", "Design"), "design_polyline", L("Click points; click the first point to close the loop, right-click to end it open"), false, CadAccess::None, false, + nullptr}, + {"sk_rect", L_CONTEXT("Corner rectangle", "Design"), 0, "R", "key:R", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect", L("Rectangle — click two opposite corners"), false, CadAccess::None, false, + nullptr}, + {"sk_rect_center", L_CONTEXT("Center rectangle", "Design"), 0, nullptr, "fly:design_rect#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_crect", L("Click center, then a corner"), false, CadAccess::None, false, + nullptr}, + {"sk_rect_oblique", L_CONTEXT("Oblique rectangle", "Design"), 0, nullptr, "fly:design_rect#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect_oblique", L("Click two corners of one edge, then a point for the width"), false, CadAccess::None, false, + nullptr}, + {"sk_rect_rounded", L_CONTEXT("Rounded rectangle", "Design"), 0, nullptr, "fly:design_rect#3", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Rectangle", "Design"), "design_rect_rounded", L("Click two opposite corners, then a point for the corner radius"), false, CadAccess::None, false, + nullptr}, + {"sk_circle", L_CONTEXT("Center circle", "Design"), 0, "C", "key:C", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle", L("Circle — click center, then radius"), false, CadAccess::None, false, + nullptr}, + {"sk_circle_2pt", L_CONTEXT("2-point circle", "Design"), 0, nullptr, "fly:design_circle#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle2pt", L("Click two ends of the diameter"), false, CadAccess::None, false, + nullptr}, + {"sk_circle_3pt", L_CONTEXT("3-point circle", "Design"), 0, nullptr, "fly:design_circle#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Circle", "Design"), "design_circle3pt", L("Click three points on the circle"), false, CadAccess::None, false, + nullptr}, + {"sk_arc_t", L_CONTEXT("3-point arc", "Design"), 0, "A", "key:A", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_arc3pt", L("Arc — click start, end, then a point"), false, CadAccess::None, false, + nullptr}, + {"sk_arc_tangent", L_CONTEXT("Tangent arc", "Design"), 0, nullptr, "fly:design_arc3pt#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_tangentarc", L("Click start (on the last entity) then end"), false, CadAccess::None, false, + nullptr}, + {"sk_arc_center", L_CONTEXT("Center-point arc", "Design"), 0, nullptr, "fly:design_arc3pt#2", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Arc", "Design"), "design_arc_center", L("Click center, then start, then a point for the end angle"), false, CadAccess::None, false, + nullptr}, + {"sk_slot", L_CONTEXT("Slot", "Design"), 0, "S", "key:S", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Slot", "Design"), "design_slot", L("Slot — two centerline ends, then the width"), false, CadAccess::None, false, + nullptr}, + {"sk_slot_arc", L_CONTEXT("Arc slot", "Design"), 0, nullptr, "fly:design_slot#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Slot", "Design"), "design_slot_arc", L("Click center, start, end, then a point for the width"), false, CadAccess::None, false, + nullptr}, + {"sk_ellipse", L_CONTEXT("Ellipse", "Design"), 0, "E", "key:E", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Ellipse", "Design"), "design_ellipse", L("Ellipse — center, major end, minor point"), false, CadAccess::None, false, + nullptr}, + {"sk_ellipse_arc", L_CONTEXT("Elliptical arc", "Design"), 0, nullptr, "fly:design_ellipse#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Ellipse", "Design"), "design_ellipse_arc", L("Click center, major-axis end, minor point, then arc start and end"), false, CadAccess::None, false, + nullptr}, + {"sk_spline", L_CONTEXT("Spline", "Design"), 0, "B", "key:B", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_bspline", L("Spline — click control points"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_3", L_CONTEXT("Triangle", "Design"), 0, nullptr, "btn:poly#3", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Triangle — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_4", L_CONTEXT("Square", "Design"), 0, nullptr, "btn:poly#4", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Square — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_5", L_CONTEXT("Pentagon", "Design"), 0, nullptr, "btn:poly#5", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Pentagon — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_polygon", L_CONTEXT("Hexagon", "Design"), 0, "G", "btn:poly#6", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Hexagon — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_8", L_CONTEXT("Octagon", "Design"), 0, nullptr, "btn:poly#8", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Octagon — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_12", L_CONTEXT("Dodecagon", "Design"), 0, nullptr, "btn:poly#12", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Dodecagon — click center, then a vertex"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_inscribed", L_CONTEXT("Inscribed", "Design"), 0, nullptr, "btn:polyfit#0", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Measure the polygon to its corners (inscribed)"), false, CadAccess::None, false, + nullptr}, + {"sk_poly_circumscribed", L_CONTEXT("Circumscribed", "Design"), 0, nullptr, "btn:polyfit#1", nullptr, 0x000f8000u, 0, 0, false, true, L_CONTEXT("Polygon", "Design"), "design_polygon", L("Measure the polygon to its flats (circumscribed)"), false, CadAccess::None, false, + nullptr}, + {"sk_point_t", L_CONTEXT("Point", "Design"), 0, "P", "key:P", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_point", L("Point — click to place"), false, CadAccess::None, false, + nullptr}, + {"sk_text", L_CONTEXT("Text", "Design"), 0, nullptr, "btn:text", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_text", L("Type text; it becomes a Text feature on this sketch's plane, editable later"), true, CadAccess::None, false, + nullptr}, + {"sk_svg", L_CONTEXT("SVG", "Design"), 0, nullptr, "btn:svg", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_svg", L("Import an SVG outline into this sketch as editable lines"), true, CadAccess::None, false, + nullptr}, + {"sk_offset", L_CONTEXT("Offset", "Design"), 1, "O", "key:O", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_offset", L("Offset — pick an entity, drag the distance"), false, CadAccess::None, false, + nullptr}, + {"sk_trim", L_CONTEXT("Trim", "Design"), 2, "T", "key:T", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_trim", L("Trim — click a segment to trim it"), false, CadAccess::None, false, + nullptr}, + {"sk_fillet", L_CONTEXT("Fillet", "Design"), 3, "F", "key:F", nullptr, 0x00090000u, 0, 0, false, true, nullptr, "design_filletedge", L("Fillet — pick two lines, set the radius"), false, CadAccess::None, false, + nullptr}, + {"sk_chamfer", L_CONTEXT("Chamfer", "Design"), 3, "H", "key:H", nullptr, 0x00090000u, 0, 0, false, true, nullptr, "design_chamfer", L("Chamfer — pick two lines, set the distance"), false, CadAccess::None, false, + nullptr}, + {"sk_array", L_CONTEXT("Linear array", "Design"), 4, nullptr, "fly:design_array#0", nullptr, 0x000b0000u, 0, 0, false, true, L_CONTEXT("Array", "Design"), "design_array", L("Pick entities, drag the spacing handle, click the count; click empty to apply"), false, CadAccess::None, false, + nullptr}, + {"sk_array_polar", L_CONTEXT("Polar array", "Design"), 4, nullptr, "fly:design_array#1", nullptr, 0x000b0000u, 0, 0, false, true, L_CONTEXT("Array", "Design"), "design_polararray", L("Pick entities, drag the sweep handle, click the count; click empty to apply"), false, CadAccess::None, false, + nullptr}, + {"sk_mirror", L_CONTEXT("Mirror", "Design"), 4, "M", "key:M", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_mirror", L("Mirror — pick axis, then entities"), false, CadAccess::None, false, + nullptr}, + {"sk_move", L_CONTEXT("Move", "Design"), 5, nullptr, "fly:design_move#0", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_move", L("Pick entities, then drag the handle or click the distance; click empty to apply"), false, CadAccess::None, false, + nullptr}, + {"sk_rotate", L_CONTEXT("Rotate", "Design"), 5, nullptr, "fly:design_move#1", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_rotate", L("Pick entities, then drag around the pivot or click the angle; click empty to apply"), false, CadAccess::None, false, + nullptr}, + {"sk_scale", L_CONTEXT("Scale", "Design"), 5, nullptr, "fly:design_move#2", nullptr, 0x000f0000u, 0, 0, false, true, L_CONTEXT("Move", "Design"), "design_scale", L("Pick entities, then drag the handle or click the factor; click empty to apply"), false, CadAccess::None, false, + nullptr}, + {"sk_dimension", L_CONTEXT("Dimension", "Design"), 6, "D", "key:D", nullptr, 0x000f8000u, 0, 0, false, true, nullptr, "design_dimension", L("Dimension — click 2 points or an entity"), false, CadAccess::None, false, + nullptr}, + {"sk_constrain", L_CONTEXT("Constrain", "Design"), 6, "K", "key:K", nullptr, 0x000f0000u, 0, 0, false, true, nullptr, "design_constrain", L("Constrain the selected sketch entities to each other"), false, CadAccess::None, false, + nullptr}, // Same verb, model-mode vocabulary: offered when a SKETCH is selected (bit 14, SkLoop), the // state a user is in right after finishing one. Without this row the only way in was the // toolbar icon, and constraints read as absent — see the Onshape-comparison report. // It sits in the Reference row, the address the sketch-mode Constrain has: one verb, one row. - {"constrain", L_CONTEXT("Constrain sketch", "Design"), 6, nullptr, "btn:constrain", L("Select a sketch to constrain it"), 0x00004000u, 0, 1, false, false, nullptr, "design_constrain", L("Add dimensions and relations (coincident, tangent, parallel...) to the selected sketch")}, - {"sk_construct", L_CONTEXT("Construction", "Design"), 6, "Q", "key:Q", nullptr, 0x000b8000u, 0, 0, false, true, nullptr, nullptr, L("Toggle construction: geometry that guides but is never built")}, - {"sk_extend", L_CONTEXT("Extend", "Design"), 7, "X", "key:X", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_extend", L("Extend — click a line/arc to extend it")}, - {"sk_delete", L_CONTEXT("Delete", "Design"), 7, "Del", "btn:sk_delete", nullptr, 0x000f0000u, 0, 0, false, true, nullptr, "design_delete", L("Delete the selected sketch entities")}, + {"constrain", L_CONTEXT("Constrain sketch", "Design"), 6, nullptr, "btn:constrain", L("Select a sketch to constrain it"), 0x00004000u, 0, 1, false, false, nullptr, "design_constrain", L("Add dimensions and relations (coincident, tangent, parallel...) to the selected sketch"), false, CadAccess::None, false, + nullptr}, + {"sk_construct", L_CONTEXT("Construction", "Design"), 6, "Q", "key:Q", nullptr, 0x000b8000u, 0, 0, false, true, nullptr, "design_construction", L("Toggle construction: geometry that guides but is never built"), false, CadAccess::None, false, + nullptr}, + {"sk_extend", L_CONTEXT("Extend", "Design"), 7, "X", "key:X", nullptr, 0x000b0000u, 0, 0, false, true, nullptr, "design_extend", L("Extend — click a line/arc to extend it"), false, CadAccess::None, false, + nullptr}, + {"sk_delete", L_CONTEXT("Delete", "Design"), 7, "Del", "btn:sk_delete", nullptr, 0x000f0000u, 0, 0, false, true, nullptr, "design_delete", L("Delete the selected sketch entities"), false, CadAccess::None, false, + nullptr}, // Typing the defining number of the element you pointed at. Three rows rather than one so // each names the quantity in the drawing-office word for THAT element; all three land on // the same handler, because dimension_kind() already resolves the quantity from the // selection. Without these, an element's own numbers were reachable only by arming the // Dimension tool and re-picking geometry that was already selected. - {"sk_length", L_CONTEXT("Length…", "Design"), 7, "V", "key:V", nullptr, 0x00010000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the length of this line")}, - {"sk_radius", L_CONTEXT("Radius / diameter…", "Design"), 7, "V", "key:V", nullptr, 0x00020000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the radius of this arc, or the diameter of this circle")}, - {"sk_angdist", L_CONTEXT("Angle / distance…", "Design"), 7, "V", "key:V", nullptr, 0x00080000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the angle between two lines, or the distance between the two picks")}, + {"sk_length", L_CONTEXT("Length…", "Design"), 7, "V", "key:V", nullptr, 0x00010000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the length of this line"), false, CadAccess::None, false, + nullptr}, + {"sk_radius", L_CONTEXT("Radius / diameter…", "Design"), 7, "V", "key:V", nullptr, 0x00020000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the radius of this arc, or the diameter of this circle"), false, CadAccess::None, false, + nullptr}, + {"sk_angdist", L_CONTEXT("Angle / distance…", "Design"), 7, "V", "key:V", nullptr, 0x00080000u, 0, 0, false, true, nullptr, "design_dimension", L("Type the angle between two lines, or the distance between the two picks"), false, CadAccess::None, false, + nullptr}, + {"describe_scene", L_CONTEXT("Describe scene", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"The Design document: features, variables with their values, bodies, undo_depth / red" + "o_depth and generation.\",\"details\":\"A feature's bound lists the fields an expression drives; a b" + "ody gives bbox, source_feature, visible, color and moved (by the Move gizmo). selection is what " + "the right-click menu would be built for: its kind, the selection_kind a tool's opening reply giv" + "es, and its id (none, face_planar, body_solid, sk_line and the like).\",\"params\":[],\"examples\":[{" + "\"title\":\"An empty design\",\"calls\":[{\"tool\":\"describe_scene\",\"args\":{}}]},{\"title\":\"A plate's two" + " features and its body\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}}" + ",{\"tool\":\"describe_scene\",\"args\":{}}]}],\"ids\":false}"}, + {"describe_feature", L_CONTEXT("Describe feature", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"One feature as its card shows it: params, the editable ones with their ranges, expr," + " refs, used_by and bodies_made.\",\"details\":\"expr holds its bindings, and refs the feature and bo" + "dy indices and face and edge ids it uses; a sketch adds its plane, entities and constraints (ang" + "les in degrees). Imported Text or SVG art shows its regions (a count), region_loops (how many cl" + "osed loops each region has, its outer loop plus its holes; counts, not the loops' geometry) and " + "region_areas (each region's filled area in mm² as placed, its outer loop less its holes).\",\"para" + "ms\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"feature index (describe_scene)\"}],\"exampl" + "es\":[{\"title\":\"A plate's extrude, with the fields its card edits\",\"calls\":[{\"tool\":\"extrude\",\"ar" + "gs\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"describe_feature\",\"args\":{\"feature\":1}}]},{\"" + "title\":\"A committed sketch's plane, entities and constraints\",\"calls\":[{\"tool\":\"sketch_begin\",\"a" + "rgs\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commi" + "t\",\"args\":{}},{\"tool\":\"describe_feature\",\"args\":{\"feature\":0}}]}],\"ids\":true}"}, + {"query_topology", L_CONTEXT("Query topology", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"A body's faces and edges, with their kinds and geometry, narrowed by face and edge f" + "ilters.\",\"details\":\"Faces give kind, area, centroid, normal, and a cylinder's, cone's, sphere's " + "or torus's numbers; edges give kind, length, ends, a circle's centre and radius. Face filters (k" + "inds, direction, at_extreme) and edge filters (edge_kinds, direction, convex) narrow their own l" + "ist; when filters are given, a list none of its filters names is empty, or with adjacency holds " + "the neighbours of the other list. Reply: face_count and edge_count of the body, faces_total and " + "edges_total after filtering, next_offset while a page has more, generation.\",\"params\":[{\"name\":\"" + "body\",\"type\":\"integer\",\"default\":0},{\"name\":\"kinds\",\"type\":\"array\",\"default\":null,\"description\":" + "\"face kinds to list: planar, cylindrical, conical, spherical, toroidal, bezier, bspline, revolut" + "ion, extrusion, offset, other\"},{\"name\":\"edge_kinds\",\"type\":\"array\",\"default\":null,\"description\"" + ":\"edge kinds to list: line, circle, ellipse, bspline, bezier, other\"},{\"name\":\"direction\",\"type\"" + ":\"array\",\"default\":null,\"description\":\"[x, y, z]: planar faces whose outward normal points this " + "way, and line edges along it either way, within 1 degree\"},{\"name\":\"at_extreme\",\"type\":\"string\"," + "\"default\":null,\"enum\":[\"+x\",\"-x\",\"+y\",\"-y\",\"+z\",\"-z\"],\"description\":\"faces whose centroid lies o" + "n that side of the body's bounding box, e.g. +z for the top face\"},{\"name\":\"convex\",\"type\":\"bool" + "ean\",\"default\":null,\"description\":\"edges where two faces meet in an outside (true) or inside (fa" + "lse) corner; implies adjacency\"},{\"name\":\"adjacency\",\"type\":\"boolean\",\"default\":false,\"descripti" + "on\":\"faces list their edges; edges list their faces (one for a seam) and say convex true or fals" + "e, or tangent where the faces meet smoothly\"},{\"name\":\"limit\",\"type\":\"integer\",\"default\":null,\"m" + "in\":1,\"description\":\"page size of both lists; omit for all\"},{\"name\":\"offset\",\"type\":\"integer\",\"" + "default\":0}],\"examples\":[{\"title\":\"Every face and edge of a 20 x 20 x 5 mm plate\",\"calls\":[{\"too" + "l\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"bod" + "y\":0}}]},{\"title\":\"A plate's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":" + "20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}}]},{\"title\":\"A plat" + "e's vertical outside corners, the edges a fillet rounds\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"height\":20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"body\":0,\"convex\":true,\"direc" + "tion\":[0,0,1],\"edge_kinds\":[\"line\"]}}]}],\"ids\":true}"}, + {"slice_body", L_CONTEXT("Slice body", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"Cross-section of a body by a base plane at an offset (sections-as-evidence).\",\"detai" + "ls\":\"Returns ordered world contours, each flagged closed/open.\",\"params\":[{\"name\":\"body\",\"type\":" + "\"integer\",\"default\":0},{\"name\":\"plane\",\"type\":\"string\",\"default\":\"XY\",\"enum\":[\"XY\",\"XZ\",\"YZ\"]},{" + "\"name\":\"offset\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0}],\"examples\":[{\"title\":\"A plate's cross-" + "section halfway up\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"t" + "ool\":\"slice_body\",\"args\":{\"body\":0,\"offset\":2.5,\"plane\":\"XY\"}}]},{\"title\":\"The two contours thro" + "ugh a plate with a bore\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_" + "add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"" + "radius\":4,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"extrude\",\"args\":{\"dist" + "ance\":5,\"sketch\":0}},{\"tool\":\"slice_body\",\"args\":{\"body\":0,\"offset\":2.5,\"plane\":\"XY\"}}]}],\"ids\":" + "true}"}, + {"validate_against", L_CONTEXT("Validate against", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"Compare a body with a reference: volume, bbox, centroid and surface deviation (the R" + "E acceptance metric).\",\"details\":\"The reference is {step:path|body:id}; the surface deviation is" + " max/mean/rms in mm.\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"default\":0},{\"name\":\"reference\"" + ",\"type\":\"object\"}],\"examples\":[{\"title\":\"A 5 mm plate against a 6 mm one\",\"calls\":[{\"tool\":\"extr" + "ude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"di" + "stance\":6,\"height\":20,\"width\":20}},{\"tool\":\"validate_against\",\"args\":{\"body\":0,\"reference\":{\"bod" + "y\":1}}}]},{\"title\":\"A plate against a reference part's STEP file\",\"calls\":[{\"tool\":\"extrude\",\"ar" + "gs\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"validate_against\",\"args\":{\"body\":0,\"referenc" + "e\":{\"step\":\"/path/to/reference.step\"}}}],\"needs\":\"a STEP file of the reference part\"}],\"ids\":fal" + "se}"}, + {"sketch_describe", L_CONTEXT("Sketch describe", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"The open sketch, or a committed one: entities, constraint count and its loops.\",\"det" + "ails\":\"The loops are closed_loops {index, entities, holes, area}, open_ends, defects, buildable." + " The open sketch adds dof, the armed tool, the selection (entity indices) and selected_constrain" + "t, the index of the constraint picked by its badge or the Constraints list, null for none; a com" + "mitted one adds its name and plane.\",\"params\":[{\"name\":\"sketch\",\"type\":\"integer\",\"default\":null," + "\"description\":\"a committed Sketch feature's index; omit for the open sketch\"}],\"examples\":[{\"tit" + "le\":\"The open sketch: a rectangle with a circle inside it as a hole\",\"calls\":[{\"tool\":\"sketch_be" + "gin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketc" + "h_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":4,\"type\":\"circle\"}]}},{\"tool\":\"sketch_descri" + "be\",\"args\":{}}]},{\"title\":\"A committed sketch's plane, entities and loop\",\"calls\":[{\"tool\":\"sket" + "ch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"" + "sketch_commit\",\"args\":{}},{\"tool\":\"sketch_describe\",\"args\":{\"sketch\":0}}]}],\"ids\":false}"}, + {"sketch_validate", L_CONTEXT("Sketch validate", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"The open sketch's loops (closed_loops, open_ends, defects, buildable) and dof.\",\"det" + "ails\":\"\",\"params\":[{\"name\":\"tolerance\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0.001,\"description\"" + ":\"reported back\"}],\"examples\":[{\"title\":\"A triangle with a 0.05 mm gap: two open ends, not build" + "able\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entit" + "ies\":[{\"p0\":[0,0],\"p1\":[20,0],\"type\":\"line\"},{\"p0\":[20,0.05],\"p1\":[20,10],\"type\":\"line\"},{\"p0\":[" + "20,10],\"p1\":[0,0],\"type\":\"line\"}]}},{\"tool\":\"sketch_validate\",\"args\":{}}]}],\"ids\":false}"}, + {"sketch_constraints", L_CONTEXT("Sketch constraints", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Read, false, + "{\"summary\":\"The constraints of the open sketch, or of a committed one: index, type, refs and val" + "ue.\",\"details\":\"A ref is {entity, role} for a point and {entity} for a whole entity; value is mm" + ", or degrees for an angle. Reply: scope (live or committed), items, and dof and solve_ok for the" + " open sketch.\",\"params\":[{\"name\":\"sketch\",\"type\":\"integer\",\"default\":null,\"description\":\"a commi" + "tted Sketch feature's index; omit for the open sketch\"}],\"examples\":[{\"title\":\"The coincident, h" + "orizontal and vertical constraints a drawn rectangle gets\",\"calls\":[{\"tool\":\"sketch_begin\",\"args" + "\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_constrai" + "nts\",\"args\":{}}]},{\"title\":\"A committed sketch's constraints\",\"calls\":[{\"tool\":\"sketch_begin\",\"a" + "rgs\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commi" + "t\",\"args\":{}},{\"tool\":\"sketch_constraints\",\"args\":{\"sketch\":0}}]}],\"ids\":false}"}, + {"import_step", L_CONTEXT("Import step", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, true, + "{\"summary\":\"Import a STEP file as native B-rep bodies (the reference part to measure).\",\"details" + "\":\"\",\"params\":[{\"name\":\"path\",\"type\":\"string\",\"description\":\"absolute path\"}],\"examples\":[{\"titl" + "e\":\"A part read from a STEP file as a body\",\"calls\":[{\"tool\":\"import_step\",\"args\":{\"path\":\"/path" + "/to/part.step\"}}],\"needs\":\"a STEP file of the part\"}],\"ids\":false}"}, + {"import_mesh", L_CONTEXT("Import mesh", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, true, + "{\"summary\":\"Convert a triangle mesh (STL/OBJ) into an editable B-rep body.\",\"details\":\"Reports w" + "hether the result is a real solid or an open shell, and why.\",\"params\":[{\"name\":\"path\",\"type\":\"s" + "tring\",\"description\":\"absolute path\"},{\"name\":\"tolerance\",\"type\":\"number\",\"default\":0.01},{\"name" + "\":\"merge_angle_deg\",\"type\":\"number\",\"default\":5.0}],\"examples\":[{\"title\":\"An STL mesh turned int" + "o an editable body\",\"calls\":[{\"tool\":\"import_mesh\",\"args\":{\"path\":\"/path/to/part.stl\"}}],\"needs\"" + ":\"an STL or OBJ mesh file\"}],\"ids\":false}"}, + {"hole_styled", L_CONTEXT("Hole styled", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Drill a hole with optional counterbore (style=1) or countersink (style=2) at (x,y) o" + "r `at` on a plane.\",\"details\":\"Reply as hole.\",\"params\":[{\"name\":\"diameter\",\"type\":\"number\",\"uni" + "t\":\"mm\",\"default\":5,\"exclusive_min\":0},{\"name\":\"depth\",\"type\":\"number\",\"unit\":\"mm\",\"default\":10}" + ",{\"name\":\"through\",\"type\":\"boolean\",\"default\":true},{\"name\":\"x\",\"type\":\"number\",\"unit\":\"mm\",\"def" + "ault\":0,\"description\":\"offset in the plane's frame from its origin, NOT world\"},{\"name\":\"y\",\"typ" + "e\":\"number\",\"unit\":\"mm\",\"default\":0,\"description\":\"offset in the plane's frame from its origin, " + "NOT world\"},{\"name\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" " + "or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f" + "}, a planar face to drill into that body (origin at its centroid, normal into the body, x along " + "its longest edge). The reply's frame gives the axes.\"},{\"name\":\"at\",\"type\":\"array|object\",\"defau" + "lt\":null,\"description\":\"instead of x and y: a world point [x, y, z], projected onto the plane al" + "ong its normal (off_plane says how far), or {\\\"body\\\": b, \\\"face\\\": f} a cylindrical face or {\\\"" + "body\\\": b, \\\"edge\\\": e} a circular edge whose axis the hole shares. A world point moves with mod" + "eling_origin; x and y replay on any printer\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"desc" + "ription\":\"the body to drill; omit for a face plane's body, else the last body\"},{\"name\":\"style\"," + "\"type\":\"integer\",\"default\":0,\"description\":\"0=simple, 1=counterbore, 2=countersink\"},{\"name\":\"cb" + "ore_diameter\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":\"cbore_depth\",\"type\":\"number\",\"un" + "it\":\"mm\",\"default\":0},{\"name\":\"csink_diameter\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":" + "\"csink_angle\",\"type\":\"number\",\"unit\":\"deg\",\"default\":90},{\"name\":\"standard\",\"type\":\"string\",\"def" + "ault\":\"\",\"description\":\"provenance designation, e.g. M6\"}],\"examples\":[{\"title\":\"A counterbored " + "hole for an M6 cap screw through a 10 mm block's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"d" + "istance\":10,\"height\":30,\"width\":30}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0" + "}},{\"tool\":\"hole_styled\",\"args\":{\"cbore_depth\":6,\"cbore_diameter\":11,\"diameter\":6.6,\"generation\"" + ":{\"from_call\":1,\"key\":\"generation\"},\"plane\":{\"body\":0,\"face\":5},\"style\":1}}]},{\"title\":\"A counte" + "rsunk hole through a plate's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":" + "20,\"width\":20}},{\"tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"hole_styl" + "ed\",\"args\":{\"csink_angle\":90,\"csink_diameter\":9,\"diameter\":4.5,\"generation\":{\"from_call\":1,\"key\"" + ":\"generation\"},\"plane\":{\"body\":0,\"face\":5},\"style\":2}}]}],\"ids\":true}"}, + {"hole_standard", L_CONTEXT("Hole standard", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Drill a standard clearance hole (ISO 273 / ANSI) at (x,y) or `at` on a plane.\",\"deta" + "ils\":\"style: 0=simple, 1=counterbore, 2=countersink. Reply as hole.\",\"params\":[{\"name\":\"designat" + "ion\",\"type\":\"string\",\"description\":\"e.g. M6, 1/4-20\"},{\"name\":\"style\",\"type\":\"integer\",\"default\"" + ":0},{\"name\":\"through\",\"type\":\"boolean\",\"default\":true},{\"name\":\"depth\",\"type\":\"number\",\"unit\":\"m" + "m\",\"default\":10},{\"name\":\"x\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0,\"description\":\"offset in th" + "e plane's frame from its origin, NOT world\"},{\"name\":\"y\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0" + ",\"description\":\"offset in the plane's frame from its origin, NOT world\"},{\"name\":\"plane\",\"type\":" + "\"string|object\",\"default\":\"XY\",\"description\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; " + "{\\\"datum\\\": i}, a Plane feature; or {\\\"body\\\": b, \\\"face\\\": f}, a planar face to drill into that" + " body (origin at its centroid, normal into the body, x along its longest edge). The reply's fram" + "e gives the axes.\"},{\"name\":\"at\",\"type\":\"array|object\",\"default\":null,\"description\":\"instead of " + "x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how " + "far), or {\\\"body\\\": b, \\\"face\\\": f} a cylindrical face or {\\\"body\\\": b, \\\"edge\\\": e} a circular " + "edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any" + " printer\"},{\"name\":\"body\",\"type\":\"integer\",\"default\":-1,\"description\":\"the body to drill; omit f" + "or a face plane's body, else the last body\"}],\"examples\":[{\"title\":\"An M5 clearance hole through" + " a plate's top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"" + "tool\":\"query_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"hole_standard\",\"args\":{\"des" + "ignation\":\"M5\",\"generation\":{\"from_call\":1,\"key\":\"generation\"},\"plane\":{\"body\":0,\"face\":5}}}]},{" + "\"title\":\"An M6 counterbored clearance hole through a 10 mm block's top face\",\"calls\":[{\"tool\":\"e" + "xtrude\",\"args\":{\"distance\":10,\"height\":30,\"width\":30}},{\"tool\":\"query_topology\",\"args\":{\"at_extr" + "eme\":\"+z\",\"body\":0}},{\"tool\":\"hole_standard\",\"args\":{\"designation\":\"M6\",\"generation\":{\"from_call" + "\":1,\"key\":\"generation\"},\"plane\":{\"body\":0,\"face\":5},\"style\":1}}]}],\"ids\":true}"}, + {"bridge", L_CONTEXT("Bridge", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, true, + "{\"summary\":\"Build a cubic-Bezier G1 bridge (BSpline) between two sketch-entity endpoints within " + "a sketch feature.\",\"details\":\"\",\"params\":[{\"name\":\"sketch\",\"type\":\"integer\",\"description\":\"sketc" + "h feature index\"},{\"name\":\"ent_a\",\"type\":\"integer\",\"description\":\"first entity index within the " + "sketch\"},{\"name\":\"end_a\",\"type\":\"integer\",\"default\":1,\"enum\":[0,1],\"description\":\"0 = start/p0 s" + "ide, 1 = end/p1 side\"},{\"name\":\"ent_b\",\"type\":\"integer\",\"description\":\"second entity index withi" + "n the sketch\"},{\"name\":\"end_b\",\"type\":\"integer\",\"default\":0,\"enum\":[0,1],\"description\":\"0 = star" + "t/p0 side, 1 = end/p1 side\"}],\"examples\":[{\"title\":\"A smooth curve joining the facing ends of tw" + "o lines in a committed sketch\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"s" + "ketch_add\",\"args\":{\"entities\":[{\"p0\":[-20,0],\"p1\":[-5,0],\"type\":\"line\"},{\"p0\":[5,10],\"p1\":[20,10" + "],\"type\":\"line\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"bridge\",\"args\":{\"end_a\":1,\"end_b" + "\":0,\"ent_a\":0,\"ent_b\":1,\"sketch\":0}}]}],\"ids\":false}"}, + {"set_variable", L_CONTEXT("Set variable", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, true, + "{\"summary\":\"Set a design variable to an expression, or remove it with an empty expr.\",\"details\":" + "\"Feature fields bound with edit_feature follow it.\",\"params\":[{\"name\":\"name\",\"type\":\"string\"},{\"" + "name\":\"expr\",\"type\":\"string\",\"description\":\"e.g. \\\"20\\\" or \\\"width / 2 + 3\\\"; \\\"\\\" removes the v" + "ariable\"}],\"examples\":[{\"title\":\"A variable w of 20\",\"calls\":[{\"tool\":\"set_variable\",\"args\":{\"ex" + "pr\":\"20\",\"name\":\"w\"}}]},{\"title\":\"A variable worked out from another: h = w / 2 + 3, which is 13" + "\",\"calls\":[{\"tool\":\"set_variable\",\"args\":{\"expr\":\"20\",\"name\":\"w\"}},{\"tool\":\"set_variable\",\"args\"" + ":{\"expr\":\"w / 2 + 3\",\"name\":\"h\"}}]},{\"title\":\"A variable removed with an empty expression\",\"call" + "s\":[{\"tool\":\"set_variable\",\"args\":{\"expr\":\"20\",\"name\":\"w\"}},{\"tool\":\"set_variable\",\"args\":{\"expr" + "\":\"\",\"name\":\"w\"}}]}],\"ids\":false}"}, + {"set_feature", L_CONTEXT("Set feature", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Change a feature's editable fields as its card's Confirm does when editing: one undo" + " step and a rebuild.\",\"details\":\"A field an expression drives is refused. Reply: changed {field:" + " [old, new]}.\",\"params\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"feature index (descri" + "be_scene)\"},{\"name\":\"fields\",\"type\":\"object\",\"description\":\"{field: value} from describe_feature" + "'s editable, e.g. {\\\"distance\\\": 15}: numbers within its ranges; mode new|union|subtract|interse" + "ct; extrude_end blind|symmetric|two_sided|through_all; shape rectangle|circle; xf_* vectors [x, " + "y, z]\"}],\"examples\":[{\"title\":\"A plate made 15 mm thick\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"dis" + "tance\":5,\"height\":20,\"width\":20}},{\"tool\":\"set_feature\",\"args\":{\"feature\":1,\"fields\":{\"distance\"" + ":15}}}]},{\"title\":\"A plate's hole widened from 5 to 8 mm\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"di" + "stance\":5,\"height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"through\":true}},{\"tool\":" + "\"set_feature\",\"args\":{\"feature\":2,\"fields\":{\"hole_diameter\":8}}}]}],\"ids\":false}"}, + {"feature_delete", L_CONTEXT("Feature delete", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Delete a feature as its tree row's Delete does; deleting a sketch also deletes the f" + "eatures built on it.\",\"details\":\"One undo step. Later indices shift. Reply: removed (how many fe" + "atures went), features, bodies.\",\"params\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"fea" + "ture index (describe_scene)\"}],\"examples\":[{\"title\":\"A plate's hole deleted\",\"calls\":[{\"tool\":\"e" + "xtrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"throu" + "gh\":true}},{\"tool\":\"feature_delete\",\"args\":{\"feature\":2}}]},{\"title\":\"A committed sketch deleted" + ", and the extrude built on it with it\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"" + "tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_commit\",\"args\":{}},{\"tool\":\"" + "extrude\",\"args\":{\"distance\":5,\"sketch\":0}},{\"tool\":\"feature_delete\",\"args\":{\"feature\":0}}]}],\"id" + "s\":false}"}, + {"feature_move", L_CONTEXT("Feature move", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Move a feature one place up or down the history, as Move up / Move down do.\",\"detail" + "s\":\"A feature cannot come before one it uses. One undo step. Reply: feature (its new index), fro" + "m.\",\"params\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"feature index (describe_scene)\"}" + ",{\"name\":\"delta\",\"type\":\"integer\",\"enum\":[-1,1],\"description\":\"-1 up, 1 down\"}],\"examples\":[{\"ti" + "tle\":\"A datum plane moved up the history, above the extrude before it\",\"calls\":[{\"tool\":\"extrude" + "\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"plane\",\"args\":{\"base\":\"XY\",\"offset\":20," + "\"type\":\"offset\"}},{\"tool\":\"feature_move\",\"args\":{\"delta\":-1,\"feature\":2}}]}],\"ids\":false}"}, + {"feature_set_enabled", L_CONTEXT("Feature set enabled", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Show or hide (suppress) a feature as its row's eye does.\",\"details\":\"A hidden featur" + "e is left out of the rebuild and bodies may renumber. One undo step, none when it already was. R" + "eply: enabled, changed, bodies.\",\"params\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"fea" + "ture index (describe_scene)\"},{\"name\":\"enabled\",\"type\":\"boolean\"}],\"examples\":[{\"title\":\"A plate" + "'s hole hidden: the plate rebuilds without it\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"" + "height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diameter\":5,\"through\":true}},{\"tool\":\"feature_se" + "t_enabled\",\"args\":{\"enabled\":false,\"feature\":2}}]},{\"title\":\"A hidden hole shown again\",\"calls\":" + "[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"hole\",\"args\":{\"diamete" + "r\":5,\"through\":true}},{\"tool\":\"feature_set_enabled\",\"args\":{\"enabled\":false,\"feature\":2}},{\"tool" + "\":\"feature_set_enabled\",\"args\":{\"enabled\":true,\"feature\":2}}]}],\"ids\":false}"}, + {"feature_rename", L_CONTEXT("Feature rename", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Rename a feature as F2 on its row does.\",\"details\":\"Its own undo step. Reply: name, " + "changed.\",\"params\":[{\"name\":\"feature\",\"type\":\"integer\",\"description\":\"feature index (describe_sc" + "ene)\"},{\"name\":\"name\",\"type\":\"string\",\"description\":\"trimmed; not empty\"}],\"examples\":[{\"title\":" + "\"A plate's extrude renamed Base plate\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":" + "20,\"width\":20}},{\"tool\":\"feature_rename\",\"args\":{\"feature\":1,\"name\":\"Base plate\"}}]}],\"ids\":fals" + "e}"}, + {"body_set", L_CONTEXT("Body set", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Rename, colour or show/hide a body, as its Bodies row and the Color button do; give " + "one or more.\",\"details\":\"Not in the undo history. The name and colour are saved with the project" + " and the name names its committed object; visibility is view state, and commit leaves hidden bod" + "ies out. Reply: name, color, visible.\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"description\":\"" + "body index (describe_scene)\"},{\"name\":\"name\",\"type\":\"string\",\"default\":null,\"description\":\"trimm" + "ed; not empty\"},{\"name\":\"color\",\"type\":\"string\",\"default\":null,\"description\":\"\\\"#RRGGBB\\\"\"},{\"na" + "me\":\"visible\",\"type\":\"boolean\",\"default\":null}],\"examples\":[{\"title\":\"A plate's body named Base " + "and coloured blue\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"to" + "ol\":\"body_set\",\"args\":{\"body\":0,\"color\":\"#3366CC\",\"name\":\"Base\"}}]},{\"title\":\"The second of two " + "bodies hidden\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":" + "\"extrude\",\"args\":{\"boolean\":\"new\",\"distance\":10,\"profile\":[[20,-5],[30,-5],[30,5],[20,5]]}},{\"to" + "ol\":\"body_set\",\"args\":{\"body\":1,\"visible\":false}}]}],\"ids\":false}"}, + {"body_delete", L_CONTEXT("Body delete", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Delete a body as its row's Delete does: the feature that made it goes, which can tak" + "e other features and bodies with it.\",\"details\":\"One undo step. Reply: deleted_feature {index, t" + "ype, name}, removed, features, bodies.\",\"params\":[{\"name\":\"body\",\"type\":\"integer\",\"description\":" + "\"body index (describe_scene)\"}],\"examples\":[{\"title\":\"The second of two bodies deleted, with the" + " extrude that made it\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}}," + "{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"distance\":10,\"profile\":[[20,-5],[30,-5],[30,5],[20,5]" + "]}},{\"tool\":\"body_delete\",\"args\":{\"body\":1}}]}],\"ids\":false}"}, + {"commit", L_CONTEXT("Commit", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Commit to Plate: send the visible bodies to Prepare at their Move-gizmo positions an" + "d show Prepare.\",\"details\":\"It is one Prepare undo step. A lone body is sent even when hidden. A" + " body named in the Bodies list or with body_set names its object or part. Reply: objects (list_o" + "bjects index after replace, name, parts: how many), bodies_sent, bodies_hidden, replaced.\",\"para" + "ms\":[{\"name\":\"mode\",\"type\":\"string\",\"default\":\"\",\"enum\":[\"assembly\",\"bodies\"],\"description\":\"ass" + "embly: one object with a part per body; bodies: an object per body. Default: the Commit button's" + " mode, which this leaves as it is.\"},{\"name\":\"replace\",\"type\":\"array\",\"default\":[],\"description\"" + ":\"list_objects indices to delete in the same undo step, such as an earlier commit. Their setting" + "s, modifiers and paint go with them.\"}],\"examples\":[{\"title\":\"A plate sent to Prepare as one obj" + "ect\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"commit\",\"" + "args\":{}}]},{\"title\":\"Two bodies sent to Prepare as an object each\",\"calls\":[{\"tool\":\"extrude\",\"" + "args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"extrude\",\"args\":{\"boolean\":\"new\",\"distance" + "\":10,\"profile\":[[20,-5],[30,-5],[30,5],[20,5]]}},{\"tool\":\"commit\",\"args\":{\"mode\":\"bodies\"}}]}],\"" + "ids\":false}"}, + {"new_design", L_CONTEXT("New design", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"New Design: erase every feature, body and variable and the Design undo history.\",\"de" + "tails\":\"Committed objects stay on the plate. Reply: cleared {features, bodies, variables}.\",\"par" + "ams\":[{\"name\":\"discard_changes\",\"type\":\"boolean\",\"default\":false,\"description\":\"needed when the " + "design is not empty\"}],\"examples\":[{\"title\":\"A plate's design erased\",\"calls\":[{\"tool\":\"extrude\"" + ",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"new_design\",\"args\":{\"discard_changes\":tr" + "ue}}]},{\"title\":\"An empty design started over, which needs no discard_changes\",\"calls\":[{\"tool\":" + "\"new_design\",\"args\":{}}]}],\"ids\":false}"}, + {"export_step", L_CONTEXT("Export step", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Change, false, + "{\"summary\":\"Export STEP: write every body to a file as native B-rep, at its Move-gizmo position." + "\",\"details\":\"Reply: path, bytes, bodies, moved_bodies.\",\"params\":[{\"name\":\"path\",\"type\":\"string\"" + ",\"description\":\"absolute path; its directory must exist\"},{\"name\":\"overwrite\",\"type\":\"boolean\",\"" + "default\":false,\"description\":\"replace an existing file\"}],\"examples\":[{\"title\":\"A plate written " + "to a STEP file\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\"" + ":\"export_step\",\"args\":{\"path\":\"/path/to/part.step\"}}],\"needs\":\"a folder to write the STEP file i" + "n\"}],\"ids\":false}"}, + {"sketch_begin", L_CONTEXT("Sketch begin", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Open a sketch session on a plane, as picking a plane or face for Sketch does.\",\"deta" + "ils\":\"Sketch points are [x, y] in that plane's frame (mm), from its origin: modeling_origin for " + "a base plane. Reply: frame.\",\"params\":[{\"name\":\"plane\",\"type\":\"string|object\",\"default\":\"XY\",\"de" + "scription\":\"\\\"XY\\\", \\\"XZ\\\" or \\\"YZ\\\" through modeling_origin; {\\\"datum\\\": i}, a Plane feature; o" + "r {\\\"body\\\": b, \\\"face\\\": f}, a planar face (origin at its centroid, normal out of the body, x f" + "rom the world axes). The reply's frame gives the axes.\"}],\"examples\":[{\"title\":\"A sketch on the " + "XY plane\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}}]},{\"title\":\"A sketch on a plate" + "'s top face\",\"calls\":[{\"tool\":\"extrude\",\"args\":{\"distance\":5,\"height\":20,\"width\":20}},{\"tool\":\"q" + "uery_topology\",\"args\":{\"at_extreme\":\"+z\",\"body\":0}},{\"tool\":\"sketch_begin\",\"args\":{\"generation\":" + "{\"from_call\":1,\"key\":\"generation\"},\"plane\":{\"body\":0,\"face\":5}}}]},{\"title\":\"A sketch on a datum" + " plane 20 mm above XY\",\"calls\":[{\"tool\":\"plane\",\"args\":{\"base\":\"XY\",\"offset\":20,\"type\":\"offset\"}" + "},{\"tool\":\"sketch_begin\",\"args\":{\"plane\":{\"datum\":0}}}]}],\"ids\":true}"}, + {"sketch_commit", L_CONTEXT("Sketch commit", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Commit the open sketch as a Sketch feature, as the sketch's Confirm does, and leave " + "sketch mode.\",\"details\":\"An empty sketch is refused and stays open. Reply: sketch_index, name, f" + "eatures (the new count) and its loops (closed_loops with the index extrude's loop takes, open_en" + "ds, defects, buildable).\",\"params\":[],\"examples\":[{\"title\":\"A rectangle around a circle, committ" + "ed as a sketch of two loops\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"ske" + "tch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0," + "0],\"radius\":4,\"type\":\"circle\"}]}},{\"tool\":\"sketch_commit\",\"args\":{}}]}],\"ids\":false}"}, + {"sketch_cancel", L_CONTEXT("Sketch cancel", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Discard the open sketch and leave sketch mode.\",\"details\":\"\",\"params\":[],\"examples\":" + "[{\"title\":\"Discard a sketch with a rectangle drawn\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"pla" + "ne\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_cancel\",\"args\":" + "{}}]}],\"ids\":false}"}, + {"sketch_add", L_CONTEXT("Sketch add", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Add entities or shapes to the open sketch: `entities` (a list), or one item's fields" + " beside `type`, or `rect`.\",\"details\":\"Entities: line {p0, p1}, circle {center, radius}, arc {ce" + "nter, radius, start_angle, end_angle}, point {p}. Shapes, built as their drawing tools build the" + "m: polygon {center, sides, radius (to a vertex) or across_flats, angle (of that vertex, or of th" + "e first edge's midpoint)}, slot {c0, c1, width}, ellipse {center, radius (semi-major), rminor, r" + "otation}, ellipse_arc {the ellipse's fields, start_angle, end_angle: parametric, counter-clockwi" + "se}, spline {ctrl: 2 or more poles}. Each item of entities may carry its own construction: true;" + " the top-level construction applies only to rect and to the single-type form. Points are [x, y] " + "in the sketch plane (mm); angles are radians, or degrees as start_angle_deg and the like. A poly" + "gon is lines; its side count is not kept once committed. Reply: first_index, added, shapes [{fir" + "st, count}] per item, entities, dof.\",\"params\":[{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"" + "description\":\"entity or shape objects, each with a type\"},{\"name\":\"type\",\"type\":\"string\",\"defaul" + "t\":\"\",\"enum\":[\"line\",\"arc\",\"circle\",\"point\",\"polygon\",\"slot\",\"ellipse\",\"ellipse_arc\",\"spline\"],\"" + "description\":\"one item, its fields beside it\"},{\"name\":\"rect\",\"type\":\"array\",\"default\":[],\"descr" + "iption\":\"[x0, y0, x1, y1]: a closed rectangle of four lines\"},{\"name\":\"start_angle\",\"type\":\"numb" + "er\",\"unit\":\"rad\",\"default\":0,\"description\":\"arc start, counter-clockwise from the plane's x axis" + "\"},{\"name\":\"end_angle\",\"type\":\"number\",\"unit\":\"rad\",\"default\":0},{\"name\":\"construction\",\"type\":\"" + "boolean\",\"default\":false,\"description\":\"for rect and the single-type form; an item of entities c" + "arries its own\"}],\"examples\":[{\"title\":\"A 30 x 20 mm rectangle\",\"calls\":[{\"tool\":\"sketch_begin\"," + "\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}}]},{\"title\":\"A hexag" + "on 10 mm across flats inside a circle\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"" + "tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":12,\"type\":\"circle\"},{\"across_fla" + "ts\":10,\"center\":[0,0],\"sides\":6,\"type\":\"polygon\"}]}}]},{\"title\":\"A quarter arc given in degrees," + " and a slot\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":" + "{\"entities\":[{\"center\":[0,0],\"end_angle_deg\":90,\"radius\":20,\"start_angle_deg\":0,\"type\":\"arc\"},{\"" + "c0\":[-10,-20],\"c1\":[10,-20],\"type\":\"slot\",\"width\":6}]}}]}],\"ids\":false}"}, + {"sketch_select", L_CONTEXT("Sketch select", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Select sketch entities by index; an empty list clears the selection.\",\"details\":\"Rep" + "ly: selected.\",\"params\":[{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"description\":\"entity in" + "dices\"}],\"examples\":[{\"title\":\"Select a rectangle's two long sides\",\"calls\":[{\"tool\":\"sketch_beg" + "in\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch" + "_select\",\"args\":{\"entities\":[0,2]}}]},{\"title\":\"Clear the selection\",\"calls\":[{\"tool\":\"sketch_be" + "gin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketc" + "h_select\",\"args\":{\"entities\":[0]}},{\"tool\":\"sketch_select\",\"args\":{\"entities\":[]}}]}],\"ids\":fals" + "e}"}, + {"sketch_delete", L_CONTEXT("Sketch delete", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Delete sketch entities.\",\"details\":\"Reply: removed, entities.\",\"params\":[{\"name\":\"en" + "tities\",\"type\":\"array\",\"default\":[],\"description\":\"entity indices; omit for the selection\"}],\"ex" + "amples\":[{\"title\":\"Delete a rectangle's top side\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane" + "\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_delete\",\"args\":{\"" + "entities\":[2]}}]},{\"title\":\"Delete the selected sides\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"" + "plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_select\",\"arg" + "s\":{\"entities\":[1,3]}},{\"tool\":\"sketch_delete\",\"args\":{}}]}],\"ids\":false}"}, + {"sketch_construction", L_CONTEXT("Sketch construction", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, true, + "{\"summary\":\"Toggle construction on sketch entities.\",\"details\":\"Reply: changed.\",\"params\":[{\"nam" + "e\":\"entities\",\"type\":\"array\",\"default\":[],\"description\":\"entity indices; omit for the selection\"" + "}],\"examples\":[{\"title\":\"A centre line across a rectangle, made construction so it splits no loo" + "p\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-" + "15,-10,15,10]}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":[0,-10],\"p1\":[0,10],\"type\":\"line\"" + "}]}},{\"tool\":\"sketch_construction\",\"args\":{\"entities\":[4]}}]}],\"ids\":false}"}, + {"sketch_offset", L_CONTEXT("Sketch offset", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Add an offset copy of sketch lines, arcs and circles.\",\"details\":\"Reply: first_index" + ", added, dof.\",\"params\":[{\"name\":\"distance\",\"type\":\"number\",\"unit\":\"mm\",\"description\":\"signed of" + "fset\"},{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"description\":\"entity indices; omit for th" + "e selection, else every entity\"}],\"examples\":[{\"title\":\"A rectangle's 2 mm inner wall\",\"calls\":[" + "{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10" + "]}},{\"tool\":\"sketch_offset\",\"args\":{\"distance\":2}}]},{\"title\":\"A circle grown 2 mm by a negative" + " offset\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"en" + "tities\":[{\"center\":[0,0],\"radius\":5,\"type\":\"circle\"}]}},{\"tool\":\"sketch_offset\",\"args\":{\"distanc" + "e\":-2,\"entities\":[0]}}]}],\"ids\":false}"}, + {"sketch_mirror", L_CONTEXT("Sketch mirror", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Add a mirrored copy of sketch entities about the line through axis_a and axis_b.\",\"d" + "etails\":\"Reply: first_index, added, dof.\",\"params\":[{\"name\":\"axis_a\",\"type\":\"array\",\"default\":[0" + ",0],\"description\":\"[x, y] in the sketch plane, mm\"},{\"name\":\"axis_b\",\"type\":\"array\",\"default\":[0" + ",1],\"description\":\"[x, y] in the sketch plane, mm\"},{\"name\":\"entities\",\"type\":\"array\",\"default\":" + "[],\"description\":\"entity indices; omit for the selection, else every entity\"}],\"examples\":[{\"tit" + "le\":\"A circle mirrored across the sketch's y axis\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plan" + "e\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[10,0],\"radius\":3,\"type\":\"circle\"}]" + "}},{\"tool\":\"sketch_mirror\",\"args\":{\"axis_a\":[0,0],\"axis_b\":[0,1]}}]}],\"ids\":false}"}, + {"sketch_heal", L_CONTEXT("Sketch heal", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Weld sketch endpoints that nearly meet and constrain them coincident, so loops are c" + "losed by construction.\",\"details\":\"Reply: welded and the loops.\",\"params\":[{\"name\":\"tolerance\",\"" + "type\":\"number\",\"unit\":\"mm\",\"default\":0.001},{\"name\":\"ignore_construction\",\"type\":\"boolean\",\"defa" + "ult\":true}],\"examples\":[{\"title\":\"Close a triangle's 0.05 mm gap\",\"calls\":[{\"tool\":\"sketch_begin" + "\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":[0,0],\"p1\":[20,0],\"type\"" + ":\"line\"},{\"p0\":[20,0.05],\"p1\":[20,10],\"type\":\"line\"},{\"p0\":[20,10],\"p1\":[0,0],\"type\":\"line\"}]}}," + "{\"tool\":\"sketch_heal\",\"args\":{\"tolerance\":0.1}}]}],\"ids\":false}"}, + {"sketch_set_value", L_CONTEXT("Sketch set value", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Set the dimension of the selected sketch entities, as the value field does.\",\"detail" + "s\":\"A line's length, a circle's diameter, an arc's radius, or the angle or distance between two." + " Select them with sketch_select first. Reply: kind, before, value, dof and the loops.\",\"params\":" + "[{\"name\":\"value\",\"type\":\"number\",\"description\":\"mm, or degrees for an angle\"}],\"examples\":[{\"tit" + "le\":\"A rectangle's bottom side made 40 mm long\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":" + "\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_select\",\"args\":{\"en" + "tities\":[0]}},{\"tool\":\"sketch_set_value\",\"args\":{\"value\":40}}]},{\"title\":\"A circle's diameter se" + "t to 12 mm\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{" + "\"entities\":[{\"center\":[0,0],\"radius\":4,\"type\":\"circle\"}]}},{\"tool\":\"sketch_select\",\"args\":{\"enti" + "ties\":[0]}},{\"tool\":\"sketch_set_value\",\"args\":{\"value\":12}}]}],\"ids\":false}"}, + {"sketch_fillet", L_CONTEXT("Sketch fillet", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Round the corner of two lines of the open sketch, as the Fillet tool does.\",\"details" + "\":\"Both lines are cut back and joined by an arc of `radius`, bound coincident and tangent to the" + "m; constraints the sharp corner held are released. Reply: entity (the arc), lines, released_cons" + "traints, entities, constraints, dof, solve_ok.\",\"params\":[{\"name\":\"entities\",\"type\":\"array\",\"def" + "ault\":[],\"description\":\"the two line indices; omit for the selection\"},{\"name\":\"radius\",\"type\":\"" + "number\",\"unit\":\"mm\"}],\"examples\":[{\"title\":\"A rectangle's corner rounded to 3 mm\",\"calls\":[{\"too" + "l\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{" + "\"tool\":\"sketch_fillet\",\"args\":{\"entities\":[0,1],\"radius\":3}}]}],\"ids\":false}"}, + {"sketch_chamfer", L_CONTEXT("Sketch chamfer", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Bevel the corner of two lines of the open sketch, as the Chamfer tool does.\",\"detail" + "s\":\"Both lines are cut back by `distance` from the corner and joined by a line bound coincident " + "to them. Reply: entity (the new line), lines, released_constraints, entities, constraints, dof, " + "solve_ok.\",\"params\":[{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"description\":\"the two line " + "indices; omit for the selection\"},{\"name\":\"distance\",\"type\":\"number\",\"unit\":\"mm\",\"description\":\"" + "setback along each line\"}],\"examples\":[{\"title\":\"A rectangle's corner bevelled 2 mm back\",\"calls" + "\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15" + ",10]}},{\"tool\":\"sketch_chamfer\",\"args\":{\"distance\":2,\"entities\":[1,2]}}]}],\"ids\":false}"}, + {"sketch_trim", L_CONTEXT("Sketch trim", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Trim or extend the open sketch's entity nearest `at`, as a Trim or Extend click ther" + "e does.\",\"details\":\"Trim: a line or an arc is cut back from its end nearer `at` to the first cro" + "ssing with another entity beyond `at`; a circle loses the part between the crossings either side" + " of `at` and becomes an arc. With extend, as an Extend click: the line's or arc's end nearer `at" + "` runs out to the next entity. The entity's constraints are released. Reply: entity, geometry (i" + "ts new fields), released_constraints, entities, dof.\",\"params\":[{\"name\":\"at\",\"type\":\"array\",\"des" + "cription\":\"[x, y] in the sketch plane, mm: a point on the part to cut, or near the end to extend" + "\"},{\"name\":\"extend\",\"type\":\"boolean\",\"default\":false},{\"name\":\"tolerance\",\"type\":\"number\",\"unit\"" + ":\"mm\",\"default\":0.05,\"description\":\"how far from `at` the entity may be\"}],\"examples\":[{\"title\":" + "\"A line cut back to the line crossing it\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}}" + ",{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\":[-10,0],\"p1\":[10,0],\"type\":\"line\"},{\"p0\":[0,-5]," + "\"p1\":[0,5],\"type\":\"line\"}]}},{\"tool\":\"sketch_trim\",\"args\":{\"at\":[5,0]}}]},{\"title\":\"A line exten" + "ded down to the line below it\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"s" + "ketch_add\",\"args\":{\"entities\":[{\"p0\":[-10,0],\"p1\":[10,0],\"type\":\"line\"},{\"p0\":[0,3],\"p1\":[0,8],\"" + "type\":\"line\"}]}},{\"tool\":\"sketch_trim\",\"args\":{\"at\":[0,3],\"extend\":true}}]}],\"ids\":false}"}, + {"sketch_transform", L_CONTEXT("Sketch transform", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Move, rotate, scale or array entities of the open sketch, as the transform tools' Co" + "nfirm does.\",\"details\":\"move {dx, dy}, rotate {angle, pivot} and scale {scale, pivot} change the" + " entities and release the constraints that no longer hold. array {dx, dy, count} adds copies ste" + "pped by dx, dy; polar_array {pivot, angle, count} adds copies every angle/count about pivot (ang" + "le is the whole sweep, default 360 degrees). count includes the original, and each copy is bound" + " to its source (equal length and parallel, or its radius). pivot defaults to the entities' centr" + "oid. Angles are radians, or degrees as angle_deg. Reply: moved and released_constraints, or firs" + "t_index, added and bound; pivot; entities, dof.\",\"params\":[{\"name\":\"op\",\"type\":\"string\",\"enum\":[" + "\"move\",\"rotate\",\"scale\",\"array\",\"polar_array\"]},{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"" + "description\":\"entity indices; omit for the selection\"},{\"name\":\"dx\",\"type\":\"number\",\"unit\":\"mm\"," + "\"default\":0},{\"name\":\"dy\",\"type\":\"number\",\"unit\":\"mm\",\"default\":0},{\"name\":\"angle\",\"type\":\"numbe" + "r\",\"unit\":\"rad\",\"default\":null,\"nullable\":false,\"description\":\"or angle_deg\"},{\"name\":\"scale\",\"t" + "ype\":\"number\",\"default\":null,\"nullable\":false},{\"name\":\"count\",\"type\":\"integer\",\"default\":null,\"" + "nullable\":false,\"min\":2,\"max\":1000},{\"name\":\"pivot\",\"type\":\"array\",\"default\":null,\"nullable\":fal" + "se,\"description\":\"[x, y] in the sketch plane, mm\"}],\"examples\":[{\"title\":\"A circle moved 10 mm a" + "long x\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"ent" + "ities\":[{\"center\":[0,0],\"radius\":3,\"type\":\"circle\"}]}},{\"tool\":\"sketch_transform\",\"args\":{\"dx\":1" + "0,\"entities\":[0],\"op\":\"move\"}}]},{\"title\":\"Six holes on a 40 mm bolt circle\",\"calls\":[{\"tool\":\"s" + "ketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[20,0],\"r" + "adius\":3,\"type\":\"circle\"}]}},{\"tool\":\"sketch_transform\",\"args\":{\"angle_deg\":360,\"count\":6,\"entit" + "ies\":[0],\"op\":\"polar_array\",\"pivot\":[0,0]}}]},{\"title\":\"A line turned 30 degrees about its start" + "\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\"" + ":[{\"p0\":[0,0],\"p1\":[20,0],\"type\":\"line\"}]}},{\"tool\":\"sketch_transform\",\"args\":{\"angle_deg\":30,\"e" + "ntities\":[0],\"op\":\"rotate\",\"pivot\":[0,0]}}]}],\"ids\":false}"}, + {"sketch_constrain", L_CONTEXT("Sketch constrain", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Add a constraint to the open sketch, as a CONSTRAIN bar button does (sketch_set_valu" + "e is the value field, V).\",\"details\":\"With `entities`, else the selection, the button's own rule" + "s choose the points, and a value it would ask for is `value` or the current one. With `refs` the" + " references are taken as written, in sketch_constraints' form: {entity, role} for a point (role " + "p0, p1 or center; entity also \\\"origin\\\") and {entity} for a whole entity (also \\\"x_axis\\\", \\\"y_" + "axis\\\"). distance, lock_x, lock_y, point_on_line and point_on_object have no button and take ref" + "s. A constraint the sketch cannot solve with is rolled back and the call fails. Reply: added (in" + "dices), items, constraints, dof, solve_ok.\",\"params\":[{\"name\":\"type\",\"type\":\"string\",\"enum\":[\"fi" + "x\",\"coincident\",\"horizontal\",\"vertical\",\"distance\",\"lock_x\",\"lock_y\",\"equal_length\",\"parallel\",\"" + "perpendicular\",\"concentric\",\"tangent\",\"midpoint\",\"symmetric\",\"angle\",\"radius\",\"diameter\",\"point_" + "on_line\",\"point_on_object\",\"equal_radius\",\"collinear\",\"distance_x\",\"distance_y\",\"symmetric_about" + "_y\",\"symmetric_about_x\",\"equal\"],\"description\":\"\\\"equal\\\" is the Equal button: equal length, or " + "equal radius for two curves\"},{\"name\":\"entities\",\"type\":\"array\",\"default\":[],\"description\":\"1 to" + " 3 entity indices; omit for the selection\"},{\"name\":\"refs\",\"type\":\"array\",\"default\":[],\"descript" + "ion\":\"[{entity, role?}], instead of entities\"},{\"name\":\"value\",\"type\":\"number\",\"default\":null,\"d" + "escription\":\"mm, or degrees for an angle\"}],\"examples\":[{\"title\":\"A sloping line made horizontal" + "\",\"calls\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\"" + ":[{\"p0\":[0,0],\"p1\":[10,2],\"type\":\"line\"}]}},{\"tool\":\"sketch_constrain\",\"args\":{\"entities\":[0],\"t" + "ype\":\"horizontal\"}}]},{\"title\":\"Two circles given equal radii\",\"calls\":[{\"tool\":\"sketch_begin\",\"" + "args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"center\":[0,0],\"radius\":4,\"type\"" + ":\"circle\"},{\"center\":[15,0],\"radius\":6,\"type\":\"circle\"}]}},{\"tool\":\"sketch_constrain\",\"args\":{\"e" + "ntities\":[0,1],\"type\":\"equal\"}}]},{\"title\":\"A line's ends held 25 mm apart, named by refs\",\"call" + "s\":[{\"tool\":\"sketch_begin\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"entities\":[{\"p0\"" + ":[0,0],\"p1\":[10,2],\"type\":\"line\"}]}},{\"tool\":\"sketch_constrain\",\"args\":{\"refs\":[{\"entity\":0,\"rol" + "e\":\"p0\"},{\"entity\":0,\"role\":\"p1\"}],\"type\":\"distance\",\"value\":25}}]}],\"ids\":false}"}, + {"sketch_unconstrain", L_CONTEXT("Sketch unconstrain", "Design"), -1, nullptr, nullptr, nullptr, 0x00000000u, 0, 0, false, false, nullptr, nullptr, nullptr, false, CadAccess::Sketch, false, + "{\"summary\":\"Delete a constraint of the open sketch, as its row's delete button does; the constra" + "ints after it move down one index.\",\"details\":\"Reply: removed, constraints, dof, solve_ok.\",\"par" + "ams\":[{\"name\":\"index\",\"type\":\"integer\",\"description\":\"sketch_constraints' items[].index\"}],\"exam" + "ples\":[{\"title\":\"A rectangle's bottom side freed from horizontal\",\"calls\":[{\"tool\":\"sketch_begin" + "\",\"args\":{\"plane\":\"XY\"}},{\"tool\":\"sketch_add\",\"args\":{\"rect\":[-15,-10,15,10]}},{\"tool\":\"sketch_c" + "onstraints\",\"args\":{}},{\"tool\":\"sketch_unconstrain\",\"args\":{\"index\":4}}]}],\"ids\":false}"}, }; -static const int kOfferVerbCount = 93; +static const int kDesignToolCount = 134; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/CAD/DesignPanel.cpp b/src/slic3r/GUI/CAD/DesignPanel.cpp index 079ad90be9..f5ac124857 100644 --- a/src/slic3r/GUI/CAD/DesignPanel.cpp +++ b/src/slic3r/GUI/CAD/DesignPanel.cpp @@ -4390,11 +4390,11 @@ DesignPanel::DesignPanel(wxWindow* parent) // nothing when picked. That defect has shipped three times (edit_feature and sk_move carrying // action:null, then a whole flyout family the moment its widget stopped being built), and it // cannot be seen by reading either side alone. Verify the join once, here, where every - // registration is complete. Cheap: 86 map lookups, once per panel. + // registration is complete. Cheap: 89 map lookups, once per panel. { std::vector dead; - for (int i = 0; i < kOfferVerbCount; ++i) { - const OfferVerb& v = kOfferVerbs[i]; + for (int i = 0; i < kDesignToolCount; ++i) { + const DesignTool& v = kDesignTools[i]; if (v.action == nullptr || *v.action == '\0') continue; // kernel support, no GUI path — the row shows disabled const std::string a(v.action); @@ -4835,7 +4835,7 @@ void DesignPanel::on_import_svg() // touched while the worker owns it. Exceptions must not escape the worker: `work` is expected // to swallow them. // True while a worker owns the document. wxYield below runs pending events — and a queued MCP -// call is one — so the MCP server's call_cad_tool must check this and refuse rather than read or +// call is one — so the MCP server's Design commands must check this and refuse rather than read or // change the document under the worker (DesignPanel::mcp_busy). static std::atomic s_doc_worker_busy{0}; @@ -4881,7 +4881,7 @@ bool DesignPanel::mcp_busy(bool read_only, bool sketch_method, std::string& why) // The Move holds a body index that any change to the document, an undo included, could point // at another body; the tree edits and Undo refuse under it too. if (body_move_pending()) { why = "a body Move is open in the Design tab"; return true; } - // Sketch CAD tools drive the live sketch session, which is the point of them; everything else + // The sketch commands drive the live sketch session, which is the point of them; everything else // changes the feature list, which a live sketch session is about to commit into. if (!sketch_method && m_ui_mode == UiMode::Sketch) { why = "a sketch is open in the Design tab"; return true; } return false; @@ -5948,7 +5948,7 @@ void DesignPanel::on_check_interference() void DesignPanel::on_mass_properties() { // This bounds check is not defensive padding — it is what makes the verb safe to fire from - // call_cad_tool's run_verb, which has no offer menu to grey the row out. + // its Design command or Speed Dial tile, which have no offer menu to grey the row out. if (m_sel_solid_body < 0 || m_sel_solid_body >= int(m_doc.bodies.size())) { set_status(StatusKind::Info, _L("Select a body to measure it")); return; @@ -6311,14 +6311,14 @@ void DesignPanel::run_offer_action(const char* action) it->second(); } -// Look a verb up by its offer id and dispatch it — the "run_verb" half of the MCP offer surface. -// Unknown ids and rows whose action string is null (kernel support, no GUI route yet) return -// false without touching anything, so the caller can tell "no such verb" from "not wired yet". +// Look a verb up by its id and dispatch it, as a Design command with no arguments does (a Speed +// Dial tile, or an agent's call). Unknown ids and entries whose action string is null (no GUI +// route) return false without touching anything. bool DesignPanel::mcp_run_verb(const char* verb_id) { if (!verb_id) return false; - for (int i = 0; i < kOfferVerbCount; ++i) { - const OfferVerb& v = kOfferVerbs[i]; + for (int i = 0; i < kDesignToolCount; ++i) { + const DesignTool& v = kDesignTools[i]; if (std::string(v.id) == verb_id) { if (v.action == nullptr) return false; run_offer_action(v.action); @@ -6380,6 +6380,8 @@ wxString DesignPanel::kernel_error_text(const std::string& err) return wxString::FromUTF8(err); } +wxString DesignPanel::mcp_status() const { return m_status != nullptr ? m_status->GetLabel() : wxString(); } + void DesignPanel::set_status(StatusKind kind, const wxString& body) { if (m_status == nullptr) return; @@ -6397,7 +6399,7 @@ void DesignPanel::set_status(StatusKind kind, const wxString& body) if (glyph != nullptr && !text.IsEmpty() && !text.StartsWith(L"\u2713") && !text.StartsWith(L"\u2717") && !text.StartsWith(L"\u26A0")) text = wxString(glyph) + text; - m_status->SetLabel(text); // the ONE place that may call SetLabel directly + m_status->SetLabel(text); // the ONE place that may call SetLabel directly, so mcp_status() reads it // m_status is HIDDEN and kept only as the owner of the text and its colour — every caller // sets the colour on it just before calling here, so this stays the one place that knows // both. What the user reads is drawn along the BASE OF THE VIEWPORT: in the panel the line @@ -6599,7 +6601,7 @@ void DesignPanel::on_sketch_step(int mode, int step, int picks) } wxMenuItem* DesignPanel::append_offer_item(wxMenu* menu, int id, const wxString& text, - const OfferVerb& v) + const DesignTool& v) { auto* item = new wxMenuItem(menu, id, text); if (v.icon != nullptr && *v.icon != '\0') { @@ -6687,7 +6689,7 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) for (const auto& b : m_doc.bodies) if (CadDocument::is_sheet_shape(b.shape)) { sheet = true; break; } - auto applies = [&](const OfferVerb& v) { + auto applies = [&](const DesignTool& v) { return (v.accepts & bit) && v.need_bodies <= bodies && v.need_sketches <= sketches && (!v.need_sheet || sheet); }; @@ -6708,14 +6710,14 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) auto tr_design = [](const char* s) { return wxGetTranslation(wxString::FromUTF8(s), SLIC3R_APP_KEY, "Design"); }; - auto label = [&](const OfferVerb& v) { + auto label = [&](const DesignTool& v) { wxString s = I18N::translate(v.name, "Design"); if (v.key && *v.key) s += "\t" + wxString::FromUTF8(v.key); return s; }; wxMenu menu; - std::vector bound; // menu id offset -> verb + std::vector bound; // menu id offset -> verb const int base = wxID_HIGHEST + 4200; // Header: WHAT the rows below act on, named the way the tree and the cards name it. The rows @@ -6738,9 +6740,9 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) bool flat_items = false; for (const int row : rows) { - std::vector live, family; - for (int i = 0; i < kOfferVerbCount; ++i) { - const OfferVerb& v = kOfferVerbs[i]; + std::vector live, family; + for (int i = 0; i < kDesignToolCount; ++i) { + const DesignTool& v = kDesignTools[i]; if (v.row != row || v.sketch_mode != sketching) continue; family.push_back(&v); if (applies(v)) live.push_back(&v); @@ -6751,7 +6753,7 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) if (kOfferRowFlat[row]) { // Only the verbs about this selection; one blocked by the document stays, greyed, // with its reason, as it would inside a family. - for (const OfferVerb* v : family) { + for (const DesignTool* v : family) { if (!(v->accepts & bit)) continue; const int id = base + int(bound.size()); if (applies(*v)) { @@ -6790,7 +6792,7 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) // the family accepts this selection at all, the honest thing is to say so, or say // nothing. const char* why = nullptr; - for (const OfferVerb* v : family) + for (const DesignTool* v : family) if ((v->accepts & bit) && v->refusal) { why = v->refusal; break; } wxString s = fam; if (why) @@ -6801,7 +6803,7 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) why ? why : "no verb accepts this selection"); menu.Append(base + int(bound.size()), s)->Enable(false); bound.push_back(nullptr); - } else if (live.size() == 1 && std::none_of(family.begin(), family.end(), [&](const OfferVerb* v) { + } else if (live.size() == 1 && std::none_of(family.begin(), family.end(), [&](const DesignTool* v) { return (v->accepts & bit) && !applies(*v); })) { offer_trace("row=%d %s -> %s%s", row, kOfferRowNames[row], live[0]->id, live[0]->action ? "" : " (no GUI route)"); @@ -6819,7 +6821,7 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) // about it and stay out. auto* sub = new wxMenu(); std::vector> groups; // insertion-ordered - for (const OfferVerb* v : family) { + for (const DesignTool* v : family) { const bool ok = applies(*v); if (!ok && !(v->accepts & bit)) continue; wxMenu* target = sub; @@ -6881,9 +6883,9 @@ void DesignPanel::show_offer_menu(const wxPoint& screen_pos) } if (cs_a < 0 || cs_b < 0) { cs_a = cs_features[0]; cs_b = cs_features[1]; } - // The generated verb rows own [base, base + bound.size()); kOfferVerbCount is 87, so a - // gap of 500 keeps this section's ids clear of that range and lets its own handler index - // by a distinct offset. + // The generated verb rows own [base, base + bound.size()); the table has 93 entries with a + // row (kDesignToolCount, 134, counts the commands with none too), so a gap of 500 keeps this + // section's ids clear of that range and lets its own handler index by a distinct offset. const int mate_base = base + 500; menu.AppendSeparator(); @@ -7144,7 +7146,7 @@ bool DesignPanel::on_add_plane() // Tangent and confirming with nothing selected would produce an offset plane reported as // a success — the user asks for one construction and silently receives another. The kernel // keeps its fallback (it must return SOMETHING), but no user gesture should reach it. The - // rules are the kernel's, shared with call_cad_tool's `plane`. + // rules are the kernel's, shared with the plane command. CadFeature candidate; apply_plane_refs(candidate); if (const std::string why = m_doc.datum_plane_refusal(candidate); !why.empty()) { @@ -7383,7 +7385,7 @@ void DesignPanel::on_sys_color_changed() // Rehydrate the parametric model from a freshly loaded project (the 3MF carried the recipe in // Metadata/orca_cad.bin). Only into an EMPTY document, so an active design is never clobbered // when the user toggles back to the tab. Called on tab show and by the MCP server's -// call_cad_tool before every CAD tool, which would otherwise work on an empty document and then +// Design commands before each runs, which would otherwise work on an empty document and then // overwrite the project's recipe with just its own features. void DesignPanel::hydrate_from_model() { @@ -7397,7 +7399,7 @@ void DesignPanel::hydrate_from_model() // datum planes off the geometry. A loaded project brings its own (load_recipe). // The centre of the Design bed, not the plater's: the plater moves its bed onto the current // plate, so on plate 2+ the origin would land one plate stride away from the bed drawn here. - // Re-synced first because call_cad_tool calls this without on_tab_shown(). + // Re-synced first because the Design commands call this without on_tab_shown(). if (!m_doc.origin_from_recipe) { m_viewport->refresh_bed(); const Vec2d bc = m_viewport->bed_center(); @@ -8129,7 +8131,7 @@ bool DesignPanel::begin_renumber() void DesignPanel::after_tree_edit(bool ok) { - // Any edit of the history (undo, delete, show/hide, a CAD tool call...) writes the status line + // Any edit of the history (undo, delete, show/hide, a Design command's call...) writes the status line // over the plane prompt, so it ends the choice rather than leave it waiting unannounced. end_sketch_plane_choice(); update_undo_redo_buttons(); diff --git a/src/slic3r/GUI/CAD/DesignPanel.hpp b/src/slic3r/GUI/CAD/DesignPanel.hpp index 5c693221f7..680ed9e147 100644 --- a/src/slic3r/GUI/CAD/DesignPanel.hpp +++ b/src/slic3r/GUI/CAD/DesignPanel.hpp @@ -116,7 +116,7 @@ public: void set_body_color(int b, const ColorRGBA& color); void show_body(int b, bool shown); - // MCP hooks: let the MCP server's call_cad_tool (Mcp/McpToolsCad.cpp) drive and + // MCP hooks: let the MCP server's Design commands (Mcp/McpToolsCad.cpp) drive and // perceive the SAME kernel the GUI uses. Called only on the wx main thread. CadDocument& mcp_doc() { return m_doc; } // live document (read + mutate) // Refresh tree + viewport + status after a change; `ok` false says "Edit rejected: ". @@ -148,23 +148,28 @@ public: // The axis a fresh Revolve card offers for a sketch's entities: its only centerline (construction // line), which is what a profile is drawn around, or -1 for the plane axis. static int default_revolve_axis_entity(const std::vector& ents); - // The offer-table vocabulary without a right-click: the external controller asks which verbs - // exist (and which apply to the current selection) and fires one by id, so a deck key names a - // verb instead of spending a letter and every verb is reachable — including the rows with no - // keyboard shortcut, which are otherwise invisible to anything that parses key tables. + // The offer table's verbs without a right-click: a Design command with no arguments, a Speed Dial + // tile or an agent's call, fires one by id, so every verb is reachable — including the rows with + // no keyboard shortcut, which are otherwise invisible to anything that parses key tables. int mcp_offer_selection_kind() const { return offer_selection_kind(); } // OfferSel as int + // Whether the right-click menu offers the sketch's verbs now, not the model's (sketch_map_applies()). + bool mcp_sketch_map_applies() const { return sketch_map_applies(); } void mcp_run_action(const char* action) { run_offer_action(action); } // dispatch an action string - // Defined out of line in DesignPanel.cpp: it needs kOfferVerbs, which this header deliberately + // Defined out of line in DesignPanel.cpp: it needs kDesignTools, which this header deliberately // does not include (the table is generated and belongs to the offer-menu code). bool mcp_run_verb(const char* verb_id); - // Would a call from the MCP server's call_cad_tool collide with what the GUI is doing — a + // The text the status line shows, as the person reads it, in the UI's language. + wxString mcp_status() const; + // Whether the Text dialog is open: the tab's one modeless dialog, which leaves a call that opened it free. + bool mcp_text_dialog_open() const { return m_text_dlg != nullptr; } + // Would a call of the MCP server's Design commands collide with what the GUI is doing — a // rebuild in progress, an open feature card, a sketch session? A rebuild refuses every call, // since its worker owns the document; the rest refuse only one that changes something // (`read_only` false). `sketch_method` = it drives the live sketch rather than the feature // list. Fills `why` when it would. bool mcp_busy(bool read_only, bool sketch_method, std::string& why) const; // Load the project's recipe into an empty document, as showing the tab does. The MCP server's - // call_cad_tool may be the first thing to touch the Design tab after a project was opened. + // Design commands may be the first thing to touch the Design tab after a project was opened. void hydrate_from_model(); private: @@ -890,7 +895,7 @@ private: const std::string* mate_conflict_reason(int feature) const; wxMenuItem* append_offer_item(wxMenu* menu, int id, const wxString& text, - const struct OfferVerb& v); + const struct DesignTool& v); void show_offer_menu(const wxPoint& screen_pos); // Where the offer opens when no mouse press anchors it: the keyboard route, and the automatic // open on entering Sketch. The pointer if it is over the viewport, else the viewport's centre. diff --git a/src/slic3r/GUI/CAD/DesignSketchTool.cpp b/src/slic3r/GUI/CAD/DesignSketchTool.cpp index 81053d6af9..e4b691d74f 100644 --- a/src/slic3r/GUI/CAD/DesignSketchTool.cpp +++ b/src/slic3r/GUI/CAD/DesignSketchTool.cpp @@ -298,7 +298,7 @@ void DesignSketchTool::set_tool(Mode mode) // the offer; Width commits, the status line reads "Line — click start, then end", and the // rectangle's Height field is sitting over it. (The keyboard cannot reproduce it: in_text // 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.) + // come from the menu, the toolbar or the MCP server's Design commands.) // // 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 diff --git a/src/slic3r/GUI/CAD/DesignSketchTool.hpp b/src/slic3r/GUI/CAD/DesignSketchTool.hpp index 84489047e3..4981c91daa 100644 --- a/src/slic3r/GUI/CAD/DesignSketchTool.hpp +++ b/src/slic3r/GUI/CAD/DesignSketchTool.hpp @@ -433,7 +433,7 @@ public: } // Mate connectors. Without a glyph a connector is visible only to a program — - // resolve_datum_coordsys's one other consumer is the MCP server's call_cad_tool — so the frame + // resolve_datum_coordsys's one other consumer is the MCP server's Design commands — so the frame // a mate is built on could not be seen at all. The glyph has to answer two questions on sight // (wgsc): which way does Z point (the VERSE), and which of the pair is anchored versus driven // (the POLARITY). Nothing in any surveyed CAD system encodes the second one. diff --git a/src/slic3r/GUI/CommandCatalog.cpp b/src/slic3r/GUI/CommandCatalog.cpp new file mode 100644 index 0000000000..cf6d34f90d --- /dev/null +++ b/src/slic3r/GUI/CommandCatalog.cpp @@ -0,0 +1,139 @@ +#include "CommandCatalog.hpp" + +#include "Mcp/McpTypes.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Slic3r { namespace GUI { + +void CommandCatalog::add(NativeCommand command) +{ + if (m_sealed) + throw std::logic_error("The command catalog is sealed; " + command.key + " comes too late"); + if (m_index.count(command.key) != 0) + throw std::logic_error("The command " + command.key + " is in the catalog already"); + m_index.emplace(command.key, m_commands.size()); + m_commands.push_back(std::move(command)); +} + +void CommandCatalog::add_source(std::unique_ptr source) +{ + if (m_sealed) + throw std::logic_error("The command catalog is sealed; a source comes too late"); + m_sources.push_back(std::move(source)); +} + +void CommandCatalog::seal() { m_sealed = true; } + +const NativeCommand* CommandCatalog::find(const std::string& key) const +{ + const auto it = m_index.find(key); + return it == m_index.end() ? nullptr : &m_commands[it->second]; +} + +std::shared_ptr CommandCatalog::lookup(const std::string& key) const +{ + // The catalog owns its added commands, so the pointer shares no ownership. + if (const NativeCommand* command = find(key)) + return std::shared_ptr(std::shared_ptr(), command); + for (const std::unique_ptr& source : m_sources) + if (std::shared_ptr command = source->find(key)) + return command; + return nullptr; +} + +std::vector> CommandCatalog::source_commands() const +{ + std::vector> out; + for (const std::unique_ptr& source : m_sources) { + std::vector> held = source->all(); + out.insert(out.end(), std::make_move_iterator(held.begin()), std::make_move_iterator(held.end())); + } + return out; +} + +std::vector CommandCatalog::similar(const std::string& key, std::size_t limit) const +{ + std::vector> scored; + for (const NativeCommand& c : m_commands) + scored.emplace_back(c.key.find(key) != std::string::npos ? 0 : Mcp::edit_distance(key, c.key), c.key); + std::sort(scored.begin(), scored.end()); + std::vector out; + for (const auto& [score, name] : scored) + if (out.size() < limit && score <= std::max(3, key.size() / 2)) + out.push_back(name); + return out; +} + +std::string CommandCatalog::unknown_command(const std::string& key, bool suggest) const +{ + std::string message = "Unknown tool: " + key; + if (suggest) + if (const std::vector close = similar(key); !close.empty()) + message += " (did you mean " + close.front() + "?)"; + return message; +} + +namespace { + +const char* guard_name(Mcp::GuardClass guard) +{ + switch (guard) { + case Mcp::GuardClass::Inspect: return "inspect"; + case Mcp::GuardClass::Recover: return "recover"; + case Mcp::GuardClass::Mutate: return "mutate"; + } + return "mutate"; +} + +const char* completion_name(CommandCompletion completion) +{ + switch (completion) { + case CommandCompletion::None: return "none"; + case CommandCompletion::Export: return "export"; + } + return "none"; +} + +} // namespace + +nlohmann::json command_reference(const NativeCommand& command) +{ + nlohmann::json entry{{"key", command.key}, + {"title", command.title}, + {"group", command.group}, + {"description", command.description}, + {"input_schema", command.input_schema}, + {"listed", command.listed}, + {"in_palette", command.in_palette}, + {"read_only", command.read_only}, + {"destructive", command.destructive}, + {"idempotent", command.idempotent}, + {"open_world", command.open_world}, + {"guard", guard_name(command.guard)}, + {"completion", completion_name(command.completion)}, + {"operations", command.operations}}; + if (!command.examples.is_null()) + entry["examples"] = command.examples; + return entry; +} + +nlohmann::json catalog_reference(const CommandCatalog& catalog) +{ + nlohmann::json commands = nlohmann::json::array(); + for (const NativeCommand& command : catalog.commands()) + commands.push_back(command_reference(command)); + return {{"commands", std::move(commands)}}; +} + +}} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/CommandCatalog.hpp b/src/slic3r/GUI/CommandCatalog.hpp new file mode 100644 index 0000000000..a3201c6ee9 --- /dev/null +++ b/src/slic3r/GUI/CommandCatalog.hpp @@ -0,0 +1,154 @@ +#pragma once + +#include "Mcp/McpTypes.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +// The command type and the catalog that holds every command. No wx here, so that the wx-free units of +// the MCP server can include it. +namespace Slic3r { namespace GUI { + +// The group of the Design tab's commands (Mcp::register_cad_commands()), an untranslated msgid as every +// group is. Their tiles are the Speed Dial's only while the Design tab is shown. +inline constexpr const char* kDesignGroup = "Design"; + +// Commands whose effect finishes after they return. Export: the G-code export runs in the background +// process, so a call that gives the file waits for it. +enum class CommandCompletion { None, Export }; + +// A command's function: the arguments match `input_schema`; the context is the call's, a person's pick +// (ToolContext::person()) or an automated call. +using CommandFn = std::function; + +// One command of the app: identity, what a person sees of it, what an agent reads about it and how to +// run it. NativeCommands::make_action() wraps one as a thin AppAction for the Speed Dial, so the catalog +// is the single source of truth for the behaviour (`run`, which the Speed Dial, a menu and every automated +// caller call), the presentation (title/group/input/icon) and what automation needs to call it. +struct NativeCommand +{ + std::string key; + std::string title; // untranslated English msgid; make_action() translates it for display + // A tile's section, an untranslated msgid as the title is. A typed tool without a tile is in the group of the way it + // acts, which search_tools filters by: core runs the session, recovers from dialogs and runs Python, api acts on + // project data by index and name with JSON in and out, and ui drives the GUI itself. + std::string group; + // "percent"/"tab": the palette's second phase, which collects the value the command needs before it + // runs; "" to run at once. + std::string input; + std::string icon; // tile pictogram: an SVG base name under resources/images, or "" for a blank tile + std::string description; // English, for agents; not shown in the palette + CommandCompletion completion = CommandCompletion::None; + // The command's function. With no arguments it does what a person's pick does; with arguments that a + // dialog would otherwise ask for, it runs without asking. + CommandFn run; + nlohmann::json input_schema = {{"type", "object"}, {"properties", nlohmann::json::object()}}; + // Calls that document the command: [{title, calls: [{tool, args}], needs?}], or null. + nlohmann::json examples; + bool listed = false; // shown in tools/list: a typed tool + bool in_palette = false; // a person can pick it: it has a tile + // The access labels sent as MCP's annotations. Clients act on them: Codex asks a person before every call + // of a destructive command, and Claude Code runs read-only calls in parallel and retries idempotent ones. + // read_only: it changes nothing in the app or the project; screenshot is, since its PNG replaces no file + // without overwrite, and export_replay, which can clear the journal, is not. destructive: every call deletes + // what a person made, with no undo: delete_preset. A command that can lose work only when an argument asks + // for it is not: new_project, generate_calibration_test and open_files drop unsaved changes only with + // discard_changes, an output replaces a file only with overwrite, and encode_recording deletes its source + // only with delete_source. Nor is a command that runs what its arguments name (click and the other input + // tools, run_action, call_tool, run_replay, run_script), though what it runs may be. The client sees both in + // the arguments, and the label would ask on every call. open_world: it can reach outside OrcaSlicer (a + // printer, the cloud account, the network, or anything the computer allows), including through what it runs. + bool read_only = false, destructive = false, idempotent = false, open_world = false; + Mcp::GuardClass guard = Mcp::GuardClass::Mutate; + // inline_call: pure observation, which runs on the request thread and is never a job; everything that can + // activate UI runs as a job instead, because activating UI can open a modal that blocks the call. journal: + // recorded by the session journal for export_replay; observation commands turn it off, except wait and + // screenshot, which a replay needs. + bool inline_call = false, journal = true; + // allowed_during_operation: may run while an MCP slice/export operation holds the project (cancel_job). + // cancellable: `cancel_job {job}` stops a running call that is not an operation (encode_recording); the + // function sees ToolContext::cancelled() and ends. + bool allowed_during_operation = false, cancellable = false; + // How long a call may run before the reply returns a job envelope and the call continues. + int budget_ms = 45000; + // The arguments that carry an expected object or part id, which the session journal leaves out. + std::vector id_args; + // The operations (GUI/Operations) the command reaches when it is given arguments, by function name. A + // palette command that takes arguments names them or is on the exception list of the catalog test. + std::vector operations; +}; + +// The context a command's title is translated in, or nullptr for none: "Design" for a Design command, whose +// title is its entry's name, which the Design table marks in that context for every entry (DesignOffer.hpp), with +// a menu row or without, the context the Design tab's right-click menu translates a row's name in. Every place +// that shows a command's title translates it with this (NativeCommands::tile_title(), a recording's caption). +inline const char* title_context(const NativeCommand& command) +{ + return command.group == kDesignGroup ? "Design" : nullptr; +} + +// What the reference says of a command: key, title, group, description, input_schema, examples when it has +// some, listed, in_palette, the four access labels, guard ("inspect", "recover", "mutate"), completion +// ("none", "export") and operations. All of it is the command's English text and constants, never translated. +nlohmann::json command_reference(const NativeCommand& command); + +// Commands that come and go while the app runs (plugin operations). Any thread. +class CommandSource +{ +public: + virtual ~CommandSource() = default; + virtual std::shared_ptr find(const std::string& key) const = 0; + virtual std::vector> all() const = 0; +}; + +// Every command of the process: those added once while it is built, then sealed, and those its sources +// hold. Built on one thread; once sealed it never changes and is read on any thread. +class CommandCatalog +{ +public: + // Before seal(). A key added twice, or an addition after seal(), throws std::logic_error. + void add(NativeCommand command); + // Before seal(); after it, throws std::logic_error. A source's commands are not checked against the + // added ones: lookup() finds an added command first. + void add_source(std::unique_ptr source); + void seal(); + bool sealed() const { return m_sealed; } + + // A command added with add(), or nullptr. The pointer stays valid while the catalog lives once it is + // sealed. + const NativeCommand* find(const std::string& key) const; + // That, as a pointer that does not own it, else the first source's that holds `key`, which keeps it + // alive through a call; nullptr when neither has it. + std::shared_ptr lookup(const std::string& key) const; + // The commands added with add(), in the order they were added. + const std::vector& commands() const { return m_commands; } + // What the sources hold now, source by source. + std::vector> source_commands() const; + // Up to `limit` keys of added commands closest to `key`, for "did you mean" errors: a key that + // contains `key` first, then by edit distance, none further than max(3, half the length of `key`). + std::vector similar(const std::string& key, std::size_t limit = 3) const; + + // The error for a key lookup() does not resolve: "Unknown tool: ", with `suggest` followed by the + // closest key. + std::string unknown_command(const std::string& key, bool suggest = false) const; + +private: + std::vector m_commands; + std::unordered_map m_index; // key -> position in m_commands + std::vector> m_sources; + bool m_sealed = false; +}; + +// The reference of `catalog`: {"commands": [command_reference(), ...]} of the commands added with add(), in +// the order they were added. Its sources' commands are left out: they are a plugin's, not the build's. +// tests/data/command_catalog.json is this reference of the catalog a run with the Design tab holds, and the +// skill's list of the Speed Dial's commands is generated from that file (tools/mcp/gen_skill_reference.py). +nlohmann::json catalog_reference(const CommandCatalog& catalog); + +}} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index cae413e274..9d09490647 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -258,6 +258,7 @@ #include "slic3r/GUI/Mcp/McpOptions.hpp" #include "slic3r/GUI/Mcp/PythonScriptsDialog.hpp" #include "slic3r/GUI/Mcp/McpService.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/plugin/PluginOperations.hpp" #include "slic3r/GUI/ImGuiWrapper.hpp" #include "slic3r/GUI/ParamsDialog.hpp" @@ -3365,6 +3366,11 @@ bool GUI_App::on_init_inner() // wxSystemOptions::SetOption("msw.notebook.themed-background", 0); // Slic3r::debugf "wxWidgets version %s, Wx version %s\n", wxVERSION_STRING, wxVERSION; + // The command catalog, before anything that runs or lists a command: the MCP service below and the + // Speed Dial's action registry. The preference is read from the config, since is_enable_cad_feature() is in + // a CAD build only. + NativeCommands::build({is_editor() && app_config->get_bool("enable_cad_feature")}); + // The MCP server starts before the first startup dialog (the TLS prompt below, the setup wizard) // so an agent can see and answer it; tools that need the main window report not-ready until // post_init() has run. diff --git a/src/slic3r/GUI/Mcp/McpArguments.cpp b/src/slic3r/GUI/Mcp/McpArguments.cpp new file mode 100644 index 0000000000..d68b097c39 --- /dev/null +++ b/src/slic3r/GUI/Mcp/McpArguments.cpp @@ -0,0 +1,361 @@ +// Argument checking and name matching for the command catalog: the schema validator, the normalizer that +// reads what agents send in place of a schema's form, what tells a command's person's form from its silent +// one, the words and scores of the searches, and the edit distance every "did you mean" ranks with. It +// includes no wx header, so the wx-free units, such as the protocol layer, and their tests can use it. + +#include "McpTypes.hpp" + +#include "slic3r/GUI/CommandCatalog.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Slic3r { namespace GUI { namespace Mcp { + +using nlohmann::json; + +namespace { + +std::string json_type_name(const json& v) +{ + if (v.is_boolean()) return "boolean"; + if (v.is_number_integer() || v.is_number_unsigned()) return "integer"; + if (v.is_number()) return "number"; + if (v.is_string()) return "string"; + if (v.is_array()) return "array"; + if (v.is_object()) return "object"; + return "null"; +} + +bool type_matches(const json& value, const json& type) +{ + if (type.is_array()) + return std::any_of(type.begin(), type.end(), [&](const json& t) { return type_matches(value, t); }); + if (!type.is_string()) + return true; + const std::string t = type.get(); + if (t == "number") + return value.is_number(); + if (t == "integer") + return value.is_number_integer() || value.is_number_unsigned() || + (value.is_number_float() && value.get() == double(int64_t(value.get()))); + return json_type_name(value) == t; +} + +std::string validate_value(const json& schema, const json& value, const std::string& path) +{ + if (!schema.is_object()) + return {}; + if (auto it = schema.find("type"); it != schema.end() && !type_matches(value, *it)) + return path + " must be of type " + (it->is_string() ? it->get() : it->dump()) + ", got " + json_type_name(value); + if (auto it = schema.find("enum"); it != schema.end() && it->is_array() && + std::find(it->begin(), it->end(), value) == it->end()) + return path + " must be one of " + it->dump(); + // A bound is read only when it is a number: a plugin operation's schema may be draft-04, whose + // exclusiveMinimum is a boolean that qualifies minimum. + if (value.is_number()) { + if (auto it = schema.find("minimum"); it != schema.end() && it->is_number() && value.get() < it->get()) + return path + " must be >= " + it->dump(); + if (auto it = schema.find("exclusiveMinimum"); it != schema.end() && it->is_number() && value.get() <= it->get()) + return path + " must be > " + it->dump(); + if (auto it = schema.find("maximum"); it != schema.end() && it->is_number() && value.get() > it->get()) + return path + " must be <= " + it->dump(); + } + if (value.is_array()) { + if (auto it = schema.find("items"); it != schema.end()) + for (std::size_t i = 0; i < value.size(); ++i) + if (std::string err = validate_value(*it, value[i], path + "[" + std::to_string(i) + "]"); !err.empty()) + return err; + } + if (value.is_object() && schema.contains("properties")) { + const json& props = schema["properties"]; + const auto missing = [&](const json& required) -> std::string { + if (required.is_array()) + for (const json& key : required) + if (key.is_string() && !value.contains(key.get())) + return (path.empty() ? std::string() : path + ".") + key.get() + " is required"; + return {}; + }; + if (auto it = schema.find("required"); it != schema.end()) + if (std::string err = missing(*it); !err.empty()) + return err; + const bool closed = schema.value("additionalProperties", true) == false; + for (auto it = value.begin(); it != value.end(); ++it) { + const std::string child = path.empty() ? it.key() : path + "." + it.key(); + if (auto p = props.find(it.key()); p != props.end()) { + if (std::string err = validate_value(*p, it.value(), child); !err.empty()) + return err; + } else if (closed) { + std::vector names; + for (auto k = props.begin(); k != props.end(); ++k) + names.push_back(k.key()); + return "unknown argument " + child + " (accepted: " + json(names).dump() + ")"; + } + } + // with_silent()'s shape, and no other use of if: what the silent form requires, once the call gives any + // argument. After the properties, so that a wrong value is named before what is missing. + const auto cond = schema.find("if"), then = schema.find("then"); + if (cond != schema.end() && then != schema.end() && *cond == json{{"minProperties", 1}} && then->is_object() && !value.empty()) + if (auto it = then->find("required"); it != then->end()) + if (std::string err = missing(*it); !err.empty()) + return err; + } + return {}; +} + +// Argument names agents reach for in place of the ones the tools take, each with the names it may +// stand for, tried in order. +const std::vector>>& argument_aliases() +{ + static const std::vector>> aliases{ + {"ref", {"target"}}, {"key", {"keys"}}, {"text", {"value"}}, {"action", {"id", "button"}}, + {"object", {"objects"}}, {"plate", {"plates"}}, {"filter", {"query"}}, {"settings", {"values"}}, + // A capture's output file, where the tool has no path of its own. + {"path", {"save_path"}}, + // The Design commands' feature index and a feature's card fields, which their functions also read + // under these names. + {"index", {"feature"}}, {"params", {"fields"}}, {"values", {"fields"}}, + }; + return aliases; +} + +bool type_includes(const json& type, const char* name) +{ + return type.is_array() ? std::find(type.begin(), type.end(), name) != type.end() : type == name; +} + +// A value in another JSON form than its schema's: a number, boolean, array or object written as a +// string ("2", "true", "[1, 2]"), a plate index as a string where a name may also go ("0" for +// "current" | index), or a single item where an array is wanted. +void coerce_value(const json& schema, json& value) +{ + if (!schema.is_object() || !schema.contains("type")) + return; + const json& type = schema["type"]; + if (value.is_string()) { + json parsed = json::parse(value.get(), nullptr, /*allow_exceptions=*/false); + if (!parsed.is_discarded() && ((!type_matches(value, type) && type_matches(parsed, type)) || + (type_includes(type, "integer") && parsed.is_number_integer()))) { + value = std::move(parsed); + return; + } + } + // Also where null may stand for the array, and is left as it is there (a CAD param whose default is null). + const bool or_null = type == json::array({"array", "null"}); + if ((type == "array" || or_null) && !value.is_array() && !(or_null && value.is_null())) { + json item = value; + if (schema.contains("items")) + coerce_value(schema["items"], item); + json wrapped = json::array({std::move(item)}); + if (validate_value(schema, wrapped, "").empty()) + value = std::move(wrapped); + } +} + +// The words of `text` in lower case, split at anything but a letter or a digit. With `camel`, a word +// with a capital after a lower-case letter also counts as its parts: TriangleMesh as triangle and mesh. +std::vector text_words(const std::string& text, bool camel) +{ + std::vector words; + std::string word; + std::vector parts; // where each CamelCase part after the first starts in `word` + const auto flush = [&] { + if (word.empty()) + return; + std::size_t from = 0; + for (const std::size_t at : parts) { + words.push_back(word.substr(from, at - from)); + from = at; + } + if (!parts.empty()) + words.push_back(word.substr(from)); + words.push_back(std::exchange(word, {})); + parts.clear(); + }; + unsigned char previous = 0; + for (const char c : text) { + const auto u = static_cast(c); + if (!std::isalnum(u)) { + flush(); + previous = 0; + continue; + } + if (camel && std::isupper(u) && std::islower(previous)) + parts.push_back(word.size()); + word += char(std::tolower(u)); + previous = u; + } + flush(); + return words; +} + +// Whether a word of `words` starts with `w`. +bool has_word(const std::vector& words, const std::string& w) +{ + return std::any_of(words.begin(), words.end(), [&w](const std::string& word) { return word.compare(0, w.size(), w) == 0; }); +} + +} // namespace + +std::size_t edit_distance(const std::string& a, const std::string& b) +{ + std::vector row(b.size() + 1); + for (std::size_t j = 0; j <= b.size(); ++j) + row[j] = j; + for (std::size_t i = 1; i <= a.size(); ++i) { + std::size_t diag = row[0]; + row[0] = i; + for (std::size_t j = 1; j <= b.size(); ++j) { + const std::size_t up = row[j]; + row[j] = std::min({row[j] + 1, row[j - 1] + 1, diag + (a[i - 1] == b[j - 1] ? 0 : 1)}); + diag = up; + } + } + return row[b.size()]; +} + +void normalize_arguments(const json& schema, json& args) +{ + if (!args.is_object() || !schema.is_object() || !schema.contains("properties")) + return; + const json& props = schema["properties"]; + // x and y, and width and height, as list_windows reports them, read as the position and size arrays + // of a tool that takes those as window geometry, arrays of integers, and neither part by its own + // name. The mm arrays of the 3D tools (transform, add_part) hold numbers and never take a pair. Only + // both parts of a pair fold, and never over an array the call gives. + struct Pair + { + const char* name; + const char* first; + const char* second; + }; + const auto integer_array = [](const json& prop) { + return prop.is_object() && prop.value("type", json()) == "array" && prop.contains("items") && prop["items"].is_object() && + prop["items"].value("type", json()) == "integer"; + }; + for (const Pair& pair : {Pair{"position", "x", "y"}, Pair{"size", "width", "height"}}) { + if (!props.contains(pair.name) || !integer_array(props[pair.name]) || props.contains(pair.first) || props.contains(pair.second) || + args.contains(pair.name) || !args.contains(pair.first) || !args.contains(pair.second)) + continue; + args[pair.name] = json::array({args[pair.first], args[pair.second]}); + args.erase(pair.first); + args.erase(pair.second); + } + for (const auto& [alias, names] : argument_aliases()) { + if (!args.contains(alias) || props.contains(alias)) + continue; + // Only where the value fits: the click tool's action "click" is no button, and its error should name action. + for (const std::string& name : names) { + if (!props.contains(name) || args.contains(name)) + continue; + json value = args[alias]; + coerce_value(props[name], value); + if (validate_value(props[name], value, name).empty()) { + args[name] = std::move(value); + args.erase(alias); + break; + } + } + } + for (auto it = args.begin(); it != args.end(); ++it) + if (auto p = props.find(it.key()); p != props.end()) + coerce_value(*p, it.value()); + // A value outside its own enum that the enum of one other argument, which the call leaves out, + // takes: set_view's canvas "front" is its camera. The schema keeps each enum to its own values, + // as listing them under both names would have agents give a value to the wrong one. + std::vector> moves; + for (const auto& [key, value] : args.items()) { + const auto own = props.find(key); + if (own == props.end() || !own->contains("enum") || validate_value(*own, value, key).empty()) + continue; + std::vector fits; + for (const auto& [name, prop] : props.items()) + if (!args.contains(name) && prop.contains("enum") && validate_value(prop, value, name).empty()) + fits.push_back(name); + if (fits.size() == 1) + moves.emplace_back(key, fits.front()); + } + for (const auto& [from, to] : moves) + if (!args.contains(to)) { + args[to] = std::move(args[from]); + args.erase(from); + } +} + +std::string validate_arguments(const json& schema, const json& args) { return validate_value(schema, args, ""); } + +bool person_form(const json& args) { return args.is_null() || (args.is_object() && args.empty()); } + +json silent_args(json args) +{ + if (args.is_object()) + args.erase("silent"); + return args; +} + +json with_silent(json schema) +{ + schema["properties"]["silent"] = {{"type", "boolean"}, + {"enum", {true}}, + {"description", "true runs the command without asking, with the defaults of what the call " + "leaves out. A call with no arguments does what a person's pick does."}}; + if (auto it = schema.find("required"); it != schema.end()) { + json required = std::move(*it); + schema.erase(it); + if (!required.empty()) { + schema["if"] = {{"minProperties", 1}}; + schema["then"] = {{"required", std::move(required)}}; + } + } + return schema; +} + +std::string argument_error(const NativeCommand& command, json& args) +{ + normalize_arguments(command.input_schema, args); + return validate_arguments(command.input_schema, args); +} + +std::vector query_words(const std::string& query) +{ + std::vector words = text_words(query, false); + std::vector longer; + std::copy_if(words.begin(), words.end(), std::back_inserter(longer), [](const std::string& w) { return w.size() >= 3; }); + return longer.empty() ? words : longer; +} + +std::pair match_score(const std::vector& words, const std::string& name, const std::string& text) +{ + const std::vector in_name = text_words(name, true); + const std::vector in_text = text_words(text, true); + std::pair score; + for (const std::string& w : words) + if (has_word(in_name, w)) { + ++score.first; + ++score.second; + } else if (has_word(in_text, w)) + ++score.first; + return score; +} + +std::string first_sentence(const std::string& text) +{ + std::string line = text; + std::replace(line.begin(), line.end(), '\n', ' '); + for (std::size_t dot = line.find('.'); dot != std::string::npos; dot = line.find('.', dot + 1)) { + const bool abbreviation = dot >= 3 && (line.compare(dot - 3, 3, "e.g") == 0 || line.compare(dot - 3, 3, "i.e") == 0); + if (!abbreviation && (dot + 1 == line.size() || line[dot + 1] == ' ')) + return line.substr(0, dot + 1); + } + return line; +} + +}}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpCore.cpp b/src/slic3r/GUI/Mcp/McpCore.cpp index 3ae7ad3336..657a6534af 100644 --- a/src/slic3r/GUI/Mcp/McpCore.cpp +++ b/src/slic3r/GUI/Mcp/McpCore.cpp @@ -3,9 +3,12 @@ #include "JobRegistry.hpp" #include "McpJournal.hpp" #include "McpProtocol.hpp" +#include "McpService.hpp" #include "McpTypes.hpp" #include "UiInvoker.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include #include #include @@ -36,6 +39,18 @@ template void notify(CallObserver* observer, Fn&& fn) } } +// Gives a submitted call's result to the caller's `done`; what it throws stays here, out of the job's thread. +void deliver(const std::function& done, const ToolResult& result) +{ + if (!done) + return; + try { + done(result); + } catch (...) { + // The caller's own failure: the job ends all the same. + } +} + // What a mutating call is told while another job's operation holds the project. std::string busy_message(const std::string& op) { @@ -46,7 +61,7 @@ std::string busy_message(const std::string& op) class CallContext final : public ToolContext { public: - CallContext(McpCore& core, const ToolDef& def, std::string job, std::string parent, std::string plugin, Journal* journal, + CallContext(McpCore& core, const NativeCommand& def, std::string job, std::string parent, std::string plugin, Journal* journal, uint64_t journal_seq, CallObserver* observer, uint64_t call) : m_core(core) , m_def(def) @@ -62,9 +77,9 @@ public: nlohmann::json run_ui(const std::function& fn) override { if (m_def.guard == GuardClass::Inspect) - return m_core.ui().run(m_def.guard, m_def.name, fn); + return m_core.ui().run(m_def.guard, m_def.key, fn); const bool admit = m_def.guard == GuardClass::Mutate && !m_def.allowed_during_operation; - return m_core.ui().run(m_def.guard, m_def.name, [&]() -> nlohmann::json { + return m_core.ui().run(m_def.guard, m_def.key, [&]() -> nlohmann::json { // Admission again on the UI thread, where operations and worker jobs start: a call admitted // before one began must not change the project under it. if (admit) @@ -86,13 +101,20 @@ public: { // A job the call's change queued for later (a toolbar event, a render) starts between its // closures; the next one the call makes claims it. - return m_core.ui().run(GuardClass::Inspect, m_def.name, [&]() -> nlohmann::json { + return m_core.ui().run(GuardClass::Inspect, m_def.key, [&]() -> nlohmann::json { nlohmann::json out = fn(); claim_worker(); return out; }); } const std::string& job_id() const override { return m_job; } + // The service that owns the core; a core built on its own has none, and the base refuses. + McpService& service() override + { + if (McpService* service = m_core.service()) + return *service; + return ToolContext::service(); + } // A plugin's call reads as cancelled the moment the plugin unloads, before the unload's stop request comes; // a handler that waits or polls then ends, one that does neither runs to its end. bool cancelled() const override @@ -118,7 +140,7 @@ public: { notify(m_observer, [&](CallObserver& o) { o.call_args(m_call, args); }); if (m_journal != nullptr && m_seq != 0) - m_journal->set_args(m_seq, std::move(args)); + m_journal->set_args(m_seq, without_expected_ids(m_core.catalog(), m_def.key, std::move(args))); } void begin_operation() override @@ -144,8 +166,8 @@ private: m_core.claim_worker(m_job); } - McpCore& m_core; - const ToolDef& m_def; + McpCore& m_core; + const NativeCommand& m_def; std::string m_job; std::string m_parent; std::string m_plugin; @@ -156,10 +178,10 @@ private: bool m_saw_idle = false; // UI thread }; -ToolResult invoke(const ToolDef& def, const nlohmann::json& args, ToolContext& ctx) +ToolResult invoke(const NativeCommand& def, const nlohmann::json& args, ToolContext& ctx) { try { - return def.handler(args, ctx); + return def.run(args, ctx); } catch (const ToolFailure& f) { return ToolResult::error(f.what(), f.details); } catch (const std::exception& e) { @@ -171,9 +193,9 @@ ToolResult invoke(const ToolDef& def, const nlohmann::json& args, ToolContext& c } // namespace -McpCore::McpCore(const ToolRegistry& registry, UiInvoker& ui, JobRegistry& jobs, Journal* journal, CoreTiming timing, WorkerHooks worker, +McpCore::McpCore(const CommandCatalog& catalog, UiInvoker& ui, JobRegistry& jobs, Journal* journal, CoreTiming timing, WorkerHooks worker, CallObserver* observer) - : m_registry(registry), m_ui(ui), m_jobs(jobs), m_journal(journal), m_timing(timing), m_worker(std::move(worker)), m_observer(observer) + : m_catalog(catalog), m_ui(ui), m_jobs(jobs), m_journal(journal), m_timing(timing), m_worker(std::move(worker)), m_observer(observer) {} McpCore::~McpCore() @@ -201,33 +223,119 @@ void McpCore::leave() m_threads_cv.notify_all(); } -ToolResult McpCore::call(const ToolDef& def, const nlohmann::json& args) { return run(def, args, {}, {}); } - -ToolResult McpCore::call_child(const ToolDef& def, const nlohmann::json& args, const std::string& parent_job, const std::string& plugin) +bool McpCore::shutting_down() { - return run(def, args, parent_job, plugin); + std::lock_guard lock(m_threads_mutex); + return m_stopping || m_ui.is_shutdown(); +} + +ToolResult McpCore::call(const NativeCommand& command, const nlohmann::json& args) { return run(command, args, {}, {}); } + +ToolResult McpCore::call_child(const NativeCommand& command, const nlohmann::json& args, const std::string& parent_job, + const std::string& plugin) +{ + return run(command, args, parent_job, plugin); } ToolResult McpCore::call_child_named(const std::string& tool, const nlohmann::json& raw_args, const std::string& parent_job, const std::string& plugin) { - std::shared_ptr def = m_registry.lookup(tool); + std::shared_ptr def = m_catalog.lookup(tool); if (def == nullptr) - return ToolResult::error(m_registry.unknown_tool(tool)); + return ToolResult::error(m_catalog.unknown_command(tool)); nlohmann::json args = raw_args; if (std::string err = argument_error(*def, args); !err.empty()) return ToolResult::error("Invalid arguments: " + err); - if (std::string err = resolve_api_call(m_registry, def, args); !err.empty()) + if (std::string err = resolve_call(m_catalog, def, args); !err.empty()) return ToolResult::error(err); return call_child(*def, args, parent_job, plugin); } -ToolResult McpCore::call_plugin(const ToolDef& def, const nlohmann::json& args, const std::string& plugin_key) +ToolResult McpCore::call_plugin(const NativeCommand& command, const nlohmann::json& args, const std::string& plugin_key) { - return run(def, args, {}, plugin_key); + return run(command, args, {}, plugin_key); } -ToolResult McpCore::run(const ToolDef& def, const nlohmann::json& args, const std::string& parent, const std::string& plugin) +std::string McpCore::submit(const NativeCommand& command, const nlohmann::json& args, std::function done) +{ + if (m_ui.is_shutdown() || !enter()) + return {}; + struct Leave { McpCore* core; ~Leave() { core->leave(); } } leave_on_return{this}; + ToolResult refused; + // A person's pick: its job, and a script it runs, are the person's, as a run the person starts is. + const std::string job = start_job(m_service != nullptr ? m_service->as_person(command) : command, args, {}, {}, 0, m_next_call++, + done, refused); + // A refusal at shutdown is no answer to give: the caller is told nothing, as a call it never made. + if (job.empty() && !shutting_down()) + deliver(done, refused); + return job; +} + +std::string McpCore::start_job(const NativeCommand& def, const nlohmann::json& args, const std::string& parent, const std::string& plugin, + uint64_t seq, uint64_t call, const std::function& done, ToolResult& refused) +{ + // Operation admission: an MCP operation holds the project until it finishes; only recovery + // input and the commands that may run during an operation (cancel_job) get through. + if (def.guard == GuardClass::Mutate && !def.allowed_during_operation) + if (const auto busy = m_jobs.running_operations(); !busy.empty()) { + refused = ToolResult::error(busy_message(busy.front()) + " before changing the project", {{"job", busy.front()}}); + return {}; + } + + std::string job; + try { + job = m_jobs.create(def.key, parent, plugin); + } catch (const ToolFailure& f) { + refused = ToolResult::error(f.what()); + return {}; + } + if (seq != 0) + m_journal->job_started(seq, job); + + // A job that never runs, refused here at shutdown or because its thread can't start, ends in the + // journal too: an entry still running would keep its place, and its arguments' bytes, until the + // journal is cleared. + if (!enter()) { + refused = ToolResult::error("OrcaSlicer is shutting down"); + if (seq != 0) + m_journal->job_ended(seq, refused); + m_jobs.finish(job, refused); + return {}; + } + // The job thread owns copies of what it needs; the core outlives it, as the owner destroys the + // core only once drain() has seen every job thread leave. + try { + std::thread([this, def, args, job, parent, plugin, seq, call, done]() { + CallContext ctx(*this, def, job, parent, plugin, m_journal, seq, m_observer, call); + ToolResult result; + // The plugin may have unloaded since the job was registered; its handler then never starts. + if (m_jobs.unloaded(job, {})) { + result = ToolResult::error(kPluginUnloaded); + } else { + notify(m_observer, [&](CallObserver& o) { o.call_started(call, def, args, parent); }); + result = await_worker(job, def.key, invoke(def, args, ctx)); + notify(m_observer, [&](CallObserver& o) { o.call_ended(call, result); }); + } + // Before finish(): an export_replay right after the wait that sees the result must know it. + if (seq != 0) + m_journal->job_ended(seq, result); + deliver(done, result); + m_jobs.finish(job, std::move(result)); + set_dialog_of(job, 0); + leave(); + }).detach(); + } catch (const std::system_error& e) { + refused = ToolResult::error(std::string("Cannot start the call: ") + e.what()); + if (seq != 0) + m_journal->job_ended(seq, refused); + m_jobs.finish(job, refused); + leave(); + return {}; + } + return job; +} + +ToolResult McpCore::run(const NativeCommand& def, const nlohmann::json& args, const std::string& parent, const std::string& plugin) { if (m_ui.is_shutdown() || !enter()) return ToolResult::error("OrcaSlicer is shutting down"); @@ -236,7 +344,9 @@ ToolResult McpCore::run(const ToolDef& def, const nlohmann::json& args, const st // Only client calls are journaled; a replay's own steps run again through the replay, and a plugin's calls // are not the agent's. const bool journal = m_journal != nullptr && parent.empty() && plugin.empty() && def.journal; - const uint64_t seq = journal ? m_journal->begin(def.name, args, def.guard == GuardClass::Recover && !m_ui.open_dialogs().empty()) : 0; + const uint64_t seq = journal ? m_journal->begin(def.key, without_expected_ids(m_catalog, def.key, args), + def.guard == GuardClass::Recover && !m_ui.open_dialogs().empty()) : + 0; auto finish = [&](ToolResult r) { if (journal) m_journal->end(seq, r); @@ -262,63 +372,13 @@ ToolResult McpCore::run(const ToolDef& def, const nlohmann::json& args, const st return finish(std::move(r)); } - // Operation admission: an MCP operation holds the project until it finishes; only recovery - // input and the tools that may run during an operation (cancel_job) get through. - if (def.guard == GuardClass::Mutate && !def.allowed_during_operation) - if (const auto busy = m_jobs.running_operations(); !busy.empty()) - return finish(ToolResult::error(busy_message(busy.front()) + " before changing the project", {{"job", busy.front()}})); - - std::string job; - try { - job = m_jobs.create(def.name, parent, plugin); - } catch (const ToolFailure& f) { - return finish(ToolResult::error(f.what())); - } - if (journal) - m_journal->job_started(seq, job); - - // A job that never runs, refused here at shutdown or because its thread can't start, ends in the - // journal too: an entry still running would keep its place, and its arguments' bytes, until the - // journal is cleared. - if (!enter()) { - const ToolResult refused = ToolResult::error("OrcaSlicer is shutting down"); - if (journal) - m_journal->job_ended(seq, refused); - m_jobs.finish(job, refused); - return finish(refused); - } - // The job thread owns copies of what it needs; the core outlives it, as the owner destroys the - // core only once drain() has seen every job thread leave. - try { - std::thread([this, def, args, job, parent, plugin, seq, call]() { - CallContext ctx(*this, def, job, parent, plugin, m_journal, seq, m_observer, call); - ToolResult result; - // The plugin may have unloaded since the job was registered; its handler then never starts. - if (m_jobs.unloaded(job, {})) { - result = ToolResult::error(kPluginUnloaded); - } else { - notify(m_observer, [&](CallObserver& o) { o.call_started(call, def, args, parent); }); - result = await_worker(job, def.name, invoke(def, args, ctx)); - notify(m_observer, [&](CallObserver& o) { o.call_ended(call, result); }); - } - // Before finish(): an export_replay right after the wait that sees the result must know it. - if (seq != 0) - m_journal->job_ended(seq, result); - m_jobs.finish(job, std::move(result)); - set_dialog_of(job, 0); - leave(); - }).detach(); - } catch (const std::system_error& e) { - const ToolResult failed = ToolResult::error(std::string("Cannot start the call: ") + e.what()); - if (journal) - m_journal->job_ended(seq, failed); - m_jobs.finish(job, failed); - leave(); - return finish(failed); - } + ToolResult refused; + const std::string job = start_job(def, args, parent, plugin, seq, call, {}, refused); + if (job.empty()) + return finish(std::move(refused)); auto envelope = [&](const char* status, nlohmann::json extra) { - nlohmann::json out{{"status", status}, {"job", job}, {"tool", def.name}}; + nlohmann::json out{{"status", status}, {"job", job}, {"tool", def.key}}; out.update(extra); return ToolResult::ok(std::move(out)); }; diff --git a/src/slic3r/GUI/Mcp/McpCore.hpp b/src/slic3r/GUI/Mcp/McpCore.hpp index 13802656d5..fb0bfbd0a3 100644 --- a/src/slic3r/GUI/Mcp/McpCore.hpp +++ b/src/slic3r/GUI/Mcp/McpCore.hpp @@ -4,6 +4,8 @@ #include "McpTypes.hpp" #include "UiInvoker.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include #include @@ -20,6 +22,7 @@ namespace Slic3r { namespace GUI { namespace Mcp { class Journal; +class McpService; struct CoreTiming { @@ -48,17 +51,17 @@ class CallObserver public: virtual ~CallObserver() = default; // Right before the handler runs: on the request thread for an inline call, the job's thread for a job. - virtual void call_started(uint64_t call, const ToolDef& def, const nlohmann::json& args, const std::string& parent) = 0; + virtual void call_started(uint64_t call, const NativeCommand& command, const nlohmann::json& args, const std::string& parent) = 0; // The handler replaced the arguments the journal records (refs became locators). virtual void call_args(uint64_t call, const nlohmann::json& args) = 0; // The call's final result: a job's once it finished, its UI job worker included. virtual void call_ended(uint64_t call, const ToolResult& result) = 0; }; -// Executes tool calls for the protocol layer, replays and scripts: observation tools inline on the -// calling thread, everything else as a job on a thread of its own, with the reply budget, the -// blocked-by-dialog probe, blocking slots, operation admission and the session journal. Independent -// of wx so the threading contract is unit-testable with a hand-driven UiDispatcher. +// Executes command calls for the protocol layer, replays, scripts and a person's picks of long commands: +// observation commands inline on the calling thread, everything else as a job on a thread of its own, with +// the reply budget, the blocked-by-dialog probe, blocking slots, operation admission and the session +// journal. Independent of wx so the threading contract is unit-testable with a hand-driven UiDispatcher. // // A call that finds the UI job worker idle and leaves it busy has started a worker job, whichever // tool or input did it, and that job is its operation: the call holds admission, and its job ends, @@ -68,26 +71,34 @@ class McpCore : public ToolCaller { public: // `observer`, when given, must outlive the core. - McpCore(const ToolRegistry& registry, UiInvoker& ui, JobRegistry& jobs, Journal* journal, CoreTiming timing = {}, + McpCore(const CommandCatalog& catalog, UiInvoker& ui, JobRegistry& jobs, Journal* journal, CoreTiming timing = {}, WorkerHooks worker = {}, CallObserver* observer = nullptr); // Refuses new calls and waits for every call and job thread to leave, however long that takes: // they use the core. The owner drains first, so this returns at once. ~McpCore() override; - // A call from a client. Mutate tools become top-level jobs. - ToolResult call(const ToolDef& def, const nlohmann::json& args) override; + // A call from a client. Mutate commands become top-level jobs. + ToolResult call(const NativeCommand& command, const nlohmann::json& args) override; // A call made by a running job (a replay step or a script's call). The new job's parent is `parent_job`, so a // `wait {for:"idle"}` from that job does not wait for it, and the journal leaves it out. - ToolResult call_child(const ToolDef& def, const nlohmann::json& args, const std::string& parent_job, + ToolResult call_child(const NativeCommand& command, const nlohmann::json& args, const std::string& parent_job, const std::string& plugin = {}); - // A child call by the tool's name, as ToolContext::call_child() makes one, under any parent: the tool is looked up - // and its arguments normalized, validated and resolved first. Any thread. + // A child call by the command's key, as ToolContext::call_child() makes one, under any parent: the command is + // looked up and its arguments normalized, validated and resolved first. Any thread. ToolResult call_child_named(const std::string& tool, const nlohmann::json& args, const std::string& parent_job, const std::string& plugin = {}); // A call a plugin's code makes through orca.host.tools: run as a client's call is, its job owned by // `plugin_key` (JobRegistry::owner, ToolContext::caller_plugin), and never journaled, since the journal // is the agent's session. - ToolResult call_plugin(const ToolDef& def, const nlohmann::json& args, const std::string& plugin_key); + ToolResult call_plugin(const NativeCommand& command, const nlohmann::json& args, const std::string& plugin_key); + // Starts `command` as a client's call starts a job, under the same guards and operation admission, whatever + // its inline_call, and returns the job's id without waiting; not journaled. It is a person's pick, so with a + // service set the job runs as a person's run (McpService::as_person()). `done` gets the job's result on + // the job's thread as it ends. A call refused before a job starts (another job's operation holds the + // project, too many jobs) returns an empty id and gets its refusal through `done` at once, on the calling + // thread. Once the core is shutting down it returns an empty id and never calls `done`. What `done` throws + // is dropped. Any thread. + std::string submit(const NativeCommand& command, const nlohmann::json& args, std::function done); // Refuses new calls. The owner wakes UiInvoker and JobRegistry, which makes running calls return. void shutdown(); @@ -95,9 +106,13 @@ public: // `timeout`. The owner may destroy the core, and what it uses, only after this returns true. bool drain(std::chrono::milliseconds timeout); - const ToolRegistry& registry() const { return m_registry; } - UiInvoker& ui() { return m_ui; } - JobRegistry& jobs() { return m_jobs; } + const CommandCatalog& catalog() const { return m_catalog; } + UiInvoker& ui() { return m_ui; } + JobRegistry& jobs() { return m_jobs; } + // The service that owns the core, which ToolContext::service() of its calls returns; nullptr for a core + // built on its own, as a unit test builds one. Set once, before any call. + void set_service(McpService* service) { m_service = service; } + McpService* service() const { return m_service; } // Operation admission for a change made by `job` ("" for a call that holds nothing), on the UI // thread: throws ToolFailure while another job's operation holds the project, or while the UI job @@ -117,19 +132,27 @@ public: private: std::uint64_t dialog_of(const std::string& job) const; - ToolResult run(const ToolDef& def, const nlohmann::json& args, const std::string& parent, const std::string& plugin); + ToolResult run(const NativeCommand& command, const nlohmann::json& args, const std::string& parent, const std::string& plugin); + // Starts `command` as a job on a thread of its own, under operation admission: returns the job's id, or "" + // with `refused` set when no job started. The job's journal entry is `seq` (0 for none); `done`, when + // given, gets the job's result on its thread as it ends, before a wait on the job sees it. + std::string start_job(const NativeCommand& command, const nlohmann::json& args, const std::string& parent, const std::string& plugin, + uint64_t seq, uint64_t call, const std::function& done, ToolResult& refused); + // Whether the core refuses new calls. + bool shutting_down(); // On `job`'s thread once its handler returned: when it holds the UI job worker, waits until the // worker is idle, cancelling the job after CoreTiming::worker_timeout, and then lets it go. The // result becomes a failure when the job was cancelled or timed out. ToolResult await_worker(const std::string& job, const std::string& tool, ToolResult result); - const ToolRegistry& m_registry; - UiInvoker& m_ui; - JobRegistry& m_jobs; - Journal* m_journal; - CoreTiming m_timing; - WorkerHooks m_worker; - CallObserver* m_observer; + const CommandCatalog& m_catalog; + UiInvoker& m_ui; + JobRegistry& m_jobs; + Journal* m_journal; + CoreTiming m_timing; + WorkerHooks m_worker; + CallObserver* m_observer; + McpService* m_service = nullptr; std::atomic m_next_call{1}; // The job whose call started the worker's current job, and whether a cancel was asked for it. diff --git a/src/slic3r/GUI/Mcp/McpJournal.cpp b/src/slic3r/GUI/Mcp/McpJournal.cpp index 388a321dbd..ca49b59b66 100644 --- a/src/slic3r/GUI/Mcp/McpJournal.cpp +++ b/src/slic3r/GUI/Mcp/McpJournal.cpp @@ -2,6 +2,9 @@ #include "McpPaths.hpp" #include "McpTypes.hpp" +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include #include @@ -9,8 +12,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -25,22 +28,35 @@ namespace { // counted as replacement characters rather than thrown on: the journal only needs the size. std::size_t serialized_size(const json& args) { return args.dump(-1, ' ', false, json::error_handler_t::replace).size(); } +// The command a journaled call of `tool` with `args` runs, and the arguments it runs it with: the call's own, or, +// for run_action of a command's tile, named by the command's key or by the tile's full id, that command and the +// arguments inside the tile's {id, args}. +std::pair called_command(const std::string& tool, json& args) +{ + if (tool != "run_action" || !args.is_object() || !args.value("id", json()).is_string() || !args.value("args", json()).is_object()) + return {tool, &args}; + const std::string id = args["id"]; + const std::string prefix = std::string(kCommandPrefix) + ':', suffix = std::string(":") + kOrcaSourceKey; + if (id.find(':') == std::string::npos) + return {id, &args["args"]}; + if (id.size() > prefix.size() + suffix.size() && id.compare(0, prefix.size(), prefix) == 0 && + id.compare(id.size() - suffix.size(), suffix.size(), suffix) == 0) + return {id.substr(prefix.size(), id.size() - prefix.size() - suffix.size()), &args["args"]}; + return {tool, &args}; +} + } // namespace -json without_expected_ids(const std::string& tool, json args) +json without_expected_ids(const CommandCatalog& catalog, const std::string& command, json args) { - // The tools that take expected ids; any other tool's arguments (a plugin operation's own fields among - // them) are recorded as given. - static const std::set takes_ids{"set_settings", "transform", "add_part", "set_height_ranges", - "set_variable_layer_height", "select_objects"}; if (!args.is_object()) return args; - if (tool == "call_tool") { + if (command == "call_tool") { if (args.contains("args") && args["args"].is_object()) - args["args"] = without_expected_ids(args.value("tool", std::string()), std::move(args["args"])); + args["args"] = without_expected_ids(catalog, args.value("tool", std::string()), std::move(args["args"])); return args; } - if (tool == "run_replay") { + if (command == "run_replay") { // An inline replay given as JSON text is recorded as the object it parses to, so its steps are // stripped too. Text that doesn't parse stays as given: the call fails, and no replay keeps it. if (args.contains("replay") && args["replay"].is_string()) { @@ -51,11 +67,11 @@ json without_expected_ids(const std::string& tool, json args) if (args.contains("replay") && args["replay"].is_object() && args["replay"].contains("steps") && args["replay"]["steps"].is_array()) for (json& step : args["replay"]["steps"]) if (step.is_object() && step.contains("args")) - step["args"] = without_expected_ids(step.value("tool", std::string()), std::move(step["args"])); + step["args"] = without_expected_ids(catalog, step.value("tool", std::string()), std::move(step["args"])); return args; } - if (takes_ids.count(tool) != 0) - for (const char* key : {"object_id", "part_id", "object_ids", "part_ids", "instance_object_ids"}) + if (const std::shared_ptr def = catalog.lookup(command)) + for (const std::string& key : def->id_args) args.erase(key); return args; } @@ -66,7 +82,7 @@ uint64_t Journal::begin(const std::string& tool, const nlohmann::json& args, boo // every other call's begin and end waits on the lock. Entry e; e.tool = tool; - e.args = without_expected_ids(tool, args); + e.args = args; e.bytes = serialized_size(e.args); e.answers_dialog = answers_dialog; @@ -85,25 +101,12 @@ uint64_t Journal::begin(const std::string& tool, const nlohmann::json& args, boo void Journal::set_args(uint64_t seq, nlohmann::json args) { - // As in begin(), the copy and its size are made outside the lock; only the call's tool, which - // decides what the copy leaves out, is read under it. - auto find = [this, seq] { - return std::find_if(m_entries.begin(), m_entries.end(), [seq](const Entry& e) { return e.seq == seq; }); - }; - std::string tool; - { - std::lock_guard lock(m_mutex); - if (const auto it = find(); it != m_entries.end()) - tool = it->tool; - else - return; - } - args = without_expected_ids(tool, std::move(args)); + // As in begin(), the size is measured outside the lock. const std::size_t bytes = serialized_size(args); std::lock_guard lock(m_mutex); // export_replay {clear:true} may have emptied the journal meanwhile. - const auto it = find(); + const auto it = std::find_if(m_entries.begin(), m_entries.end(), [seq](const Entry& e) { return e.seq == seq; }); if (it == m_entries.end()) return; m_bytes -= it->bytes; @@ -222,22 +225,27 @@ nlohmann::json Journal::to_replay(const std::string& name, nlohmann::json* left_ continue; // waits on a job the journal did not see start step["args"]["job"] = "${jobs." + it->second + "}"; } + // The command the step calls and its arguments: run_action of a command's tile calls the tile's command + // with the arguments inside the tile's {id, args}, which the step keeps. + const auto [tool, called_args] = called_command(e.tool, step["args"]); + nlohmann::json& args = *called_args; auto in_out_dir = [&](const char* key) { - const std::string file = path_to_utf8(path_from_utf8(e.args[key].get()).filename()); + const std::string file = path_to_utf8(path_from_utf8(args[key].get()).filename()); return "${out_dir}/" + file; }; - auto has_path = [&](const char* key) { return e.args.contains(key) && e.args[key].is_string(); }; - if ((e.tool == "screenshot" || e.tool == "encode_recording") && has_path("save_path")) - step["args"]["save_path"] = in_out_dir("save_path"); - if (e.tool == "start_recording" && has_path("save_path")) { - step["args"]["save_path"] = in_out_dir("save_path"); - recordings[path_compare_key(path_from_utf8(e.args["save_path"].get()))] = step["args"]["save_path"]; + auto has_path = [&](const char* key) { return args.contains(key) && args[key].is_string(); }; + if ((tool == "screenshot" || tool == "encode_recording") && has_path("save_path")) + args["save_path"] = in_out_dir("save_path"); + if (tool == "start_recording" && has_path("save_path")) { + const std::string key = path_compare_key(path_from_utf8(args["save_path"].get())); + args["save_path"] = in_out_dir("save_path"); + recordings[key] = args["save_path"]; } // An encode of a recording this replay makes reads it where the replay writes it; any other // source stays where it is. - if (e.tool == "encode_recording" && has_path("path")) - if (auto it = recordings.find(path_compare_key(path_from_utf8(e.args["path"].get()))); it != recordings.end()) - step["args"]["path"] = it->second; + if (tool == "encode_recording" && has_path("path")) + if (auto it = recordings.find(path_compare_key(path_from_utf8(args["path"].get()))); it != recordings.end()) + args["path"] = it->second; if (e.unawaited()) { const std::string job_name = "job" + std::to_string(job_names.size() + 1); job_names[e.job] = job_name; diff --git a/src/slic3r/GUI/Mcp/McpJournal.hpp b/src/slic3r/GUI/Mcp/McpJournal.hpp index 2fc449850c..f698eb2840 100644 --- a/src/slic3r/GUI/Mcp/McpJournal.hpp +++ b/src/slic3r/GUI/Mcp/McpJournal.hpp @@ -2,6 +2,8 @@ #include "McpTypes.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include #include @@ -12,6 +14,13 @@ namespace Slic3r { namespace GUI { namespace Mcp { +// `args` of a call of `command` as the journal records them: without the command's id_args (expected object +// and part ids), as ids are allocated per process and a replay addresses by index. So are a call_tool call's +// arguments for its target and a run_replay's inline steps. The arguments of any other command stay as +// written: a plugin operation's own fields, and a run_script call's code and args, since a script reads the +// ids it uses. +nlohmann::json without_expected_ids(const CommandCatalog& catalog, const std::string& command, nlohmann::json args); + // The session's client calls, in the order they were made, for export_replay. A call that returned // a job envelope is replayed with `await:false` and a name its later `wait` refers to, so a step // that opened a dialog can be followed by the steps that answered it. An input call that only listed @@ -25,12 +34,8 @@ namespace Slic3r { namespace GUI { namespace Mcp { // that was running while a later call answered a dialog: the dialog may be one the job opened, after // its reply or before it, and the answer depends on it. Such a job replays with `await:false`, and a // call that answered a dialog replays after a `wait {for:"dialog"}`, since the dialog may open later -// than the job's replayed reply. Thread-safe. -// `args` of a `tool` call as the journal records them: expected object_id and part_id are left out, -// as ids are allocated per process and a replay addresses by index. Inside a run_replay's inline steps -// too; a run_script call's code and args stay as written, since a script reads the ids it uses. -nlohmann::json without_expected_ids(const std::string& tool, nlohmann::json args); - +// than the job's replayed reply. Thread-safe. It records the arguments it is given, which McpCore gives it +// through without_expected_ids(). class Journal { public: diff --git a/src/slic3r/GUI/Mcp/McpPaths.cpp b/src/slic3r/GUI/Mcp/McpPaths.cpp index 73e80e7ea5..6212c833a7 100644 --- a/src/slic3r/GUI/Mcp/McpPaths.cpp +++ b/src/slic3r/GUI/Mcp/McpPaths.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -155,28 +154,6 @@ std::optional resolve_output_dir(const std::string& path, std::string& return p; } -std::optional parse_path_param(const std::string& param, std::string& err) -{ - PathParam out; - const auto first = param.find_first_not_of(" \t"); - if (first != std::string::npos && param[first] == '{') { - const nlohmann::json j = nlohmann::json::parse(param, nullptr, false); - if (j.is_discarded() || !j.is_object() || !j.contains("path") || !j["path"].is_string()) { - err = "the parameter must be a path or {\"path\": \"...\", \"overwrite\": true}"; - return std::nullopt; - } - out.path = j["path"].get(); - out.overwrite = j.value("overwrite", false); - } else { - out.path = param; - } - if (out.path.empty()) { - err = "path is empty"; - return std::nullopt; - } - return out; -} - fs::path output_dir() { const fs::path dir = mcp_dir(path_from_utf8(data_dir())) / "out"; diff --git a/src/slic3r/GUI/Mcp/McpPaths.hpp b/src/slic3r/GUI/Mcp/McpPaths.hpp index a7a3fcba8b..1d4396bac7 100644 --- a/src/slic3r/GUI/Mcp/McpPaths.hpp +++ b/src/slic3r/GUI/Mcp/McpPaths.hpp @@ -40,13 +40,4 @@ boost::filesystem::path output_dir(); boost::filesystem::path timestamped_path(const boost::filesystem::path& dir, const std::string& kind, const std::string& extension, const std::vector& companions = {}, std::time_t when = std::time(nullptr)); -// The parameter of a Speed Dial command that takes a path: a plain absolute path, or a JSON object -// string {"path": "...", "overwrite": true}. -struct PathParam -{ - std::string path; - bool overwrite = false; -}; -std::optional parse_path_param(const std::string& param, std::string& err); - }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpPersonContext.cpp b/src/slic3r/GUI/Mcp/McpPersonContext.cpp new file mode 100644 index 0000000000..3a273a9693 --- /dev/null +++ b/src/slic3r/GUI/Mcp/McpPersonContext.cpp @@ -0,0 +1,107 @@ +#include "McpPersonContext.hpp" + +#include "McpCore.hpp" +#include "McpService.hpp" +#include "McpTypes.hpp" +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/GUI.hpp" +#include "slic3r/GUI/GUI_App.hpp" +#include "slic3r/GUI/I18N.hpp" +#include "slic3r/GUI/NativeCommands.hpp" +#include "slic3r/GUI/format.hpp" + +#include + +#include +#include + +#include +#include +#include +#include + +namespace Slic3r { namespace GUI { namespace Mcp { + +namespace { + +// What a person is shown once a job they started ends: what the command says, its error, or that it finished. +// `title` is the command's, in the UI's language (NativeCommands::tile_title()). +AppActionRunResult ended_notice(const ToolResult& result, const std::string& title) +{ + if (result.notice) + return *result.notice; + if (result.is_error) + return {AppActionRunResult::Level::Error, from_u8(result.message), false}; + // TRN %1% is the title of a command a person started, which ran on in the background. + return {AppActionRunResult::Level::Success, format_wxstr(_L("Finished: %1%"), from_u8(title))}; +} + +} // namespace + +const std::string& PersonContext::job_id() const +{ + static const std::string none; + return none; +} + +bool PersonContext::cancelled() const +{ + // No GUI_App in a unit test, which runs commands with this context too. + const auto* app = dynamic_cast(wxTheApp); + return app != nullptr && app->is_closing(); +} + +ToolResult PersonContext::call_child(const std::string& tool, const nlohmann::json& /*args*/) +{ + throw ToolFailure("A person's pick does not call " + tool); +} + +McpService& PersonContext::service() +{ + auto* app = dynamic_cast(wxTheApp); + if (app == nullptr || app->is_closing()) + throw ToolFailure("OrcaSlicer is closing"); + if (McpService* s = app->mcp_service(); s == nullptr || !s->started()) + app->start_mcp_service(false); + McpService* s = app->mcp_service(); + if (s == nullptr || !s->started() || s->stopping()) + throw ToolFailure("The automation runtime could not start"); + return *s; +} + +ToolResult PersonContext::submit(const std::string& key, const nlohmann::json& args) +{ + const std::shared_ptr command = NativeCommands::instance().lookup(key); + if (command == nullptr) + throw ToolFailure("Unknown command " + key); + McpService* const owner = &service(); + const std::thread::id caller = std::this_thread::get_id(); + auto refusal = std::make_shared>(); + const std::string title = into_u8(NativeCommands::tile_title(*command)); + const std::string job = owner->core().submit(*command, args, [owner, caller, refusal, title](const ToolResult& r) { + // A refusal comes at once, on this thread: it is the reply. A job's result comes on the job's thread, + // while the service still runs it, and is shown on the UI thread. + if (std::this_thread::get_id() == caller) { + *refusal = r; + return; + } + owner->post_ui([r, title] { + if (wxTheApp != nullptr && !wxGetApp().is_closing()) + NativeCommands::notify_result(ended_notice(r, title)); + }); + }); + if (job.empty()) { + const std::string why = *refusal ? (*refusal)->message : std::string("OrcaSlicer is closing"); + ToolResult failed = ToolResult::error(why); + failed.notice = std::make_shared(AppActionRunResult{AppActionRunResult::Level::Error, from_u8(why), false}); + return failed; + } + ToolResult started = ToolResult::ok({{"status", "running"}, {"job", job}, {"tool", key}}); + // TRN %1% is the title of a command a person started, which runs on in the background. + const wxString shown = format_wxstr(_L("Started: %1%"), from_u8(title)); + started.notice = std::make_shared(AppActionRunResult{AppActionRunResult::Level::Info, shown}); + return started; +} + +}}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpPersonContext.hpp b/src/slic3r/GUI/Mcp/McpPersonContext.hpp new file mode 100644 index 0000000000..8b875bc481 --- /dev/null +++ b/src/slic3r/GUI/Mcp/McpPersonContext.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include "McpTypes.hpp" + +#include + +#include +#include +#include +#include +#include + +// The contexts a command runs with besides the MCP core's own: a person's pick, and a Speed Dial tile that +// run_action runs. No wx here, so that the core's tests can include it. +namespace Slic3r { namespace GUI { namespace Mcp { + +// A person's pick from the Speed Dial or a menu, on the UI thread, which no MCP service needs to run: UI +// closures run in place, and there is no job, no journal entry and no operation to hold. +class PersonContext final : public ToolContext +{ +public: + bool person() const override { return true; } + // The MCP service, started without its endpoint when the server is off, as the Run Script panel starts + // it. Throws ToolFailure when it cannot start: OrcaSlicer is closing, or no app runs (a unit test). + McpService& service() override; + // Starts command `key` as a job on the service's core (McpCore::submit()), under the admission a client's + // call has, and returns at once: an Info notice "Started: ", or an Error when no job started. The + // job's result is shown as a notification once it ends. + ToolResult submit(const std::string& key, const nlohmann::json& args) override; + nlohmann::json run_ui(const std::function<nlohmann::json()>& fn) override { return fn(); } + nlohmann::json observe_ui(const std::function<nlohmann::json()>& fn) override { return fn(); } + const std::string& job_id() const override; + // Whether OrcaSlicer is closing. + bool cancelled() const override; + // A person's pick makes no child calls: throws ToolFailure. + ToolResult call_child(const std::string& tool, const nlohmann::json& args) override; + std::set<std::string> lineage() const override { return {}; } + void set_journal_args(nlohmann::json /*args*/) override {} + void begin_operation() override {} +}; + +// What run_action runs a command's tile with: the context of run_action's own call, except that a command +// that rewrites its journal entry does so inside run_action's, as {"id": <the tile's action id>, "args": ...}, +// so that a replay runs the tile again through run_action. +class TileContext final : public ToolContext +{ +public: + TileContext(ToolContext& call, std::string action_id) : m_call(call), m_id(std::move(action_id)) {} + + bool person() const override { return m_call.person(); } + McpService& service() override { return m_call.service(); } + ToolResult submit(const std::string& key, const nlohmann::json& args) override { return m_call.submit(key, args); } + nlohmann::json run_ui(const std::function<nlohmann::json()>& fn) override { return m_call.run_ui(fn); } + nlohmann::json observe_ui(const std::function<nlohmann::json()>& fn) override { return m_call.observe_ui(fn); } + const std::string& job_id() const override { return m_call.job_id(); } + bool cancelled() const override { return m_call.cancelled(); } + ToolResult call_child(const std::string& tool, const nlohmann::json& args) override { return m_call.call_child(tool, args); } + std::set<std::string> lineage() const override { return m_call.lineage(); } + void set_journal_args(nlohmann::json args) override + { + m_call.set_journal_args({{"id", m_id}, {"args", std::move(args)}}); + } + void begin_operation() override { m_call.begin_operation(); } + void works_in_dialog(std::uint64_t dialog) override { m_call.works_in_dialog(dialog); } + const std::string& caller_plugin() const override { return m_call.caller_plugin(); } + +private: + ToolContext& m_call; + std::string m_id; +}; + +}}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpPluginCaller.cpp b/src/slic3r/GUI/Mcp/McpPluginCaller.cpp index fdecbeb7ba..81e9d86b28 100644 --- a/src/slic3r/GUI/Mcp/McpPluginCaller.cpp +++ b/src/slic3r/GUI/Mcp/McpPluginCaller.cpp @@ -4,6 +4,7 @@ #include "McpService.hpp" #include "McpTypes.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/plugin/PluginManager.hpp" #include "slic3r/plugin/host/PluginHostTools.hpp" @@ -37,8 +38,8 @@ struct Admission }; // Admits a plugin's call on the UI thread, which owns the service and runs the plugin's unload: the plugin -// must still be loaded and its scope not ended, and the service is started in its catalog-only mode (no -// endpoint) when MCP is off, as Action Replay starts it. Returns the service with a lease taken, +// must still be loaded and its scope not ended, and the service is started without its endpoint when MCP is +// off, as Action Replay starts it. Returns the service with a lease taken, // or throws. A caller that stops waiting because the app closes marks the admission abandoned, under the // lock the UI thread answers it under, so no lease is taken that nobody releases. McpService* admit_plugin_call(const std::string& plugin) @@ -113,13 +114,14 @@ void install_plugin_tool_caller() McpService* service; ~Lease() { service->release_lease(); } } lease{service}; - std::shared_ptr<const ToolDef> def = service->registry().lookup(tool); + const CommandCatalog& catalog = service->catalog(); + std::shared_ptr<const NativeCommand> def = catalog.lookup(tool); if (def == nullptr) - throw ToolCallError(service->registry().unknown_tool(tool), {{"did_you_mean", service->registry().similar(tool)}}); + throw ToolCallError(catalog.unknown_command(tool), {{"did_you_mean", catalog.similar(tool)}}); json arguments = args; if (std::string err = argument_error(*def, arguments); !err.empty()) throw ToolCallError("Invalid arguments: " + err, json()); - if (std::string err = resolve_api_call(service->registry(), def, arguments); !err.empty()) + if (std::string err = resolve_call(catalog, def, arguments); !err.empty()) throw ToolCallError(err, json()); const ToolResult r = service->core().call_plugin(*def, arguments, plugin); diff --git a/src/slic3r/GUI/Mcp/McpProtocol.cpp b/src/slic3r/GUI/Mcp/McpProtocol.cpp index 5205ef1955..c5f69fa45b 100644 --- a/src/slic3r/GUI/Mcp/McpProtocol.cpp +++ b/src/slic3r/GUI/Mcp/McpProtocol.cpp @@ -1,12 +1,13 @@ #include "McpProtocol.hpp" #include "McpTypes.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include <algorithm> #include <cstddef> #include <cstdint> #include <exception> #include <memory> -#include <set> #include <string> #include <utility> #include <vector> @@ -62,311 +63,28 @@ int base64_value(char c) return -1; } -// Levenshtein distance, for "did you mean" suggestions on short identifiers. -std::size_t edit_distance(const std::string& a, const std::string& b) -{ - std::vector<std::size_t> row(b.size() + 1); - for (std::size_t j = 0; j <= b.size(); ++j) - row[j] = j; - for (std::size_t i = 1; i <= a.size(); ++i) { - std::size_t diag = row[0]; - row[0] = i; - for (std::size_t j = 1; j <= b.size(); ++j) { - const std::size_t up = row[j]; - row[j] = std::min({row[j] + 1, row[j - 1] + 1, diag + (a[i - 1] == b[j - 1] ? 0 : 1)}); - diag = up; - } - } - return row[b.size()]; -} - -std::string json_type_name(const json& v) -{ - if (v.is_boolean()) return "boolean"; - if (v.is_number_integer() || v.is_number_unsigned()) return "integer"; - if (v.is_number()) return "number"; - if (v.is_string()) return "string"; - if (v.is_array()) return "array"; - if (v.is_object()) return "object"; - return "null"; -} - -bool type_matches(const json& value, const json& type) -{ - if (type.is_array()) - return std::any_of(type.begin(), type.end(), [&](const json& t) { return type_matches(value, t); }); - if (!type.is_string()) - return true; - const std::string t = type.get<std::string>(); - if (t == "number") - return value.is_number(); - if (t == "integer") - return value.is_number_integer() || value.is_number_unsigned() || - (value.is_number_float() && value.get<double>() == double(int64_t(value.get<double>()))); - return json_type_name(value) == t; -} - -std::string validate_value(const json& schema, const json& value, const std::string& path) -{ - if (!schema.is_object()) - return {}; - if (auto it = schema.find("type"); it != schema.end() && !type_matches(value, *it)) - return path + " must be of type " + (it->is_string() ? it->get<std::string>() : it->dump()) + ", got " + json_type_name(value); - if (auto it = schema.find("enum"); it != schema.end() && it->is_array() && - std::find(it->begin(), it->end(), value) == it->end()) - return path + " must be one of " + it->dump(); - // A bound is read only when it is a number: a plugin operation's schema may be draft-04, whose - // exclusiveMinimum is a boolean that qualifies minimum. - if (value.is_number()) { - if (auto it = schema.find("minimum"); it != schema.end() && it->is_number() && value.get<double>() < it->get<double>()) - return path + " must be >= " + it->dump(); - if (auto it = schema.find("exclusiveMinimum"); it != schema.end() && it->is_number() && value.get<double>() <= it->get<double>()) - return path + " must be > " + it->dump(); - if (auto it = schema.find("maximum"); it != schema.end() && it->is_number() && value.get<double>() > it->get<double>()) - return path + " must be <= " + it->dump(); - } - if (value.is_array()) { - if (auto it = schema.find("items"); it != schema.end()) - for (std::size_t i = 0; i < value.size(); ++i) - if (std::string err = validate_value(*it, value[i], path + "[" + std::to_string(i) + "]"); !err.empty()) - return err; - } - if (value.is_object() && schema.contains("properties")) { - const json& props = schema["properties"]; - if (auto it = schema.find("required"); it != schema.end() && it->is_array()) - for (const json& key : *it) - if (key.is_string() && !value.contains(key.get<std::string>())) - return (path.empty() ? std::string() : path + ".") + key.get<std::string>() + " is required"; - const bool closed = schema.value("additionalProperties", true) == false; - for (auto it = value.begin(); it != value.end(); ++it) { - const std::string child = path.empty() ? it.key() : path + "." + it.key(); - if (auto p = props.find(it.key()); p != props.end()) { - if (std::string err = validate_value(*p, it.value(), child); !err.empty()) - return err; - } else if (closed) { - std::vector<std::string> names; - for (auto k = props.begin(); k != props.end(); ++k) - names.push_back(k.key()); - return "unknown argument " + child + " (accepted: " + json(names).dump() + ")"; - } - } - } - return {}; -} - -// Argument names agents reach for in place of the ones the tools take, each with the names it may -// stand for, tried in order. -const std::vector<std::pair<std::string, std::vector<std::string>>>& argument_aliases() -{ - static const std::vector<std::pair<std::string, std::vector<std::string>>> aliases{ - {"ref", {"target"}}, {"key", {"keys"}}, {"text", {"value"}}, {"action", {"id", "button"}}, - {"object", {"objects"}}, {"plate", {"plates"}}, {"filter", {"query"}}, {"settings", {"values"}}, - // A capture's output file, where the tool has no path of its own. - {"path", {"save_path"}}, - }; - return aliases; -} - -bool type_includes(const json& type, const char* name) -{ - return type.is_array() ? std::find(type.begin(), type.end(), name) != type.end() : type == name; -} - -// A value in another JSON form than its schema's: a number, boolean, array or object written as a -// string ("2", "true", "[1, 2]"), a plate index as a string where a name may also go ("0" for -// "current" | index), or a single item where an array is wanted. -void coerce_value(const json& schema, json& value) -{ - if (!schema.is_object() || !schema.contains("type")) - return; - const json& type = schema["type"]; - if (value.is_string()) { - json parsed = json::parse(value.get<std::string>(), nullptr, /*allow_exceptions=*/false); - if (!parsed.is_discarded() && ((!type_matches(value, type) && type_matches(parsed, type)) || - (type_includes(type, "integer") && parsed.is_number_integer()))) { - value = std::move(parsed); - return; - } - } - if (type == "array" && !value.is_array()) { - json item = value; - if (schema.contains("items")) - coerce_value(schema["items"], item); - json wrapped = json::array({std::move(item)}); - if (validate_value(schema, wrapped, "").empty()) - value = std::move(wrapped); - } -} - } // namespace -void normalize_arguments(const json& schema, json& args) -{ - if (!args.is_object() || !schema.is_object() || !schema.contains("properties")) - return; - const json& props = schema["properties"]; - // x and y, and width and height, as list_windows reports them, read as the position and size arrays - // of a tool that takes those as window geometry, arrays of integers, and neither part by its own - // name. The mm arrays of the 3D tools (transform, add_part) hold numbers and never take a pair. Only - // both parts of a pair fold, and never over an array the call gives. - struct Pair - { - const char* name; - const char* first; - const char* second; - }; - const auto integer_array = [](const json& prop) { - return prop.is_object() && prop.value("type", json()) == "array" && prop.contains("items") && prop["items"].is_object() && - prop["items"].value("type", json()) == "integer"; - }; - for (const Pair& pair : {Pair{"position", "x", "y"}, Pair{"size", "width", "height"}}) { - if (!props.contains(pair.name) || !integer_array(props[pair.name]) || props.contains(pair.first) || props.contains(pair.second) || - args.contains(pair.name) || !args.contains(pair.first) || !args.contains(pair.second)) - continue; - args[pair.name] = json::array({args[pair.first], args[pair.second]}); - args.erase(pair.first); - args.erase(pair.second); - } - for (const auto& [alias, names] : argument_aliases()) { - if (!args.contains(alias) || props.contains(alias)) - continue; - // Only where the value fits: the click tool's action "click" is no button, and its error should name action. - for (const std::string& name : names) { - if (!props.contains(name) || args.contains(name)) - continue; - json value = args[alias]; - coerce_value(props[name], value); - if (validate_value(props[name], value, name).empty()) { - args[name] = std::move(value); - args.erase(alias); - break; - } - } - } - for (auto it = args.begin(); it != args.end(); ++it) - if (auto p = props.find(it.key()); p != props.end()) - coerce_value(*p, it.value()); - // A value outside its own enum that the enum of one other argument, which the call leaves out, - // takes: set_view's canvas "front" is its camera. The schema keeps each enum to its own values, - // as listing them under both names would have agents give a value to the wrong one. - std::vector<std::pair<std::string, std::string>> moves; - for (const auto& [key, value] : args.items()) { - const auto own = props.find(key); - if (own == props.end() || !own->contains("enum") || validate_value(*own, value, key).empty()) - continue; - std::vector<std::string> fits; - for (const auto& [name, prop] : props.items()) - if (!args.contains(name) && prop.contains("enum") && validate_value(prop, value, name).empty()) - fits.push_back(name); - if (fits.size() == 1) - moves.emplace_back(key, fits.front()); - } - for (const auto& [from, to] : moves) - if (!args.contains(to)) { - args[to] = std::move(args[from]); - args.erase(from); - } -} +// ---- call_tool ---------------------------------------------------------------- -// ---- ToolRegistry ------------------------------------------------------------ - -ToolLane tool_lane(const std::string& name) +std::string resolve_call(const CommandCatalog& catalog, std::shared_ptr<const NativeCommand>& command, json& args) { - static const std::set<std::string> core{"get_app_state", "wait", "cancel_job", "get_log", "run_replay", - "export_replay", "answer_dialog", "auto_answer_dialogs", "run_script", "search_python_api"}; - static const std::set<std::string> ui{"list_windows", "set_window", "list_widgets", "click", - "set_widget_value", "press_keys", "mouse_gesture", "pick_gizmo_file", - "run_javascript", "set_view", "screenshot", "start_recording", - "stop_recording", "encode_recording", "search_actions", "run_action", - "select_objects"}; - if (core.count(name) != 0) - return ToolLane::Core; - if (ui.count(name) != 0) - return ToolLane::Ui; - return ToolLane::Api; -} - -const char* lane_name(ToolLane lane) -{ - switch (lane) { - case ToolLane::Core: return "core"; - case ToolLane::Ui: return "ui"; - case ToolLane::Api: break; - } - return "api"; -} - -void ToolRegistry::add(ToolDef def) -{ - def.lane = tool_lane(def.name); - const std::string tag = std::string("[") + lane_name(def.lane) + "] "; - // A def copied from the registry and added again already has its tag. - if (def.description.compare(0, tag.size(), tag) != 0) - def.description.insert(0, tag); - auto it = std::find_if(m_tools.begin(), m_tools.end(), [&](const ToolDef& t) { return t.name == def.name; }); - if (it != m_tools.end()) - *it = std::move(def); - else - m_tools.push_back(std::move(def)); -} - -const ToolDef* ToolRegistry::find(const std::string& name) const -{ - auto it = std::find_if(m_tools.begin(), m_tools.end(), [&](const ToolDef& t) { return t.name == name; }); - return it == m_tools.end() ? nullptr : &*it; -} - -std::shared_ptr<const ToolDef> ToolRegistry::lookup(const std::string& name) const -{ - if (const ToolDef* def = find(name)) - return std::shared_ptr<const ToolDef>(std::shared_ptr<const ToolDef>(), def); - return m_dynamic ? m_dynamic(name) : nullptr; -} - -std::string resolve_api_call(const ToolRegistry& registry, std::shared_ptr<const ToolDef>& def, json& args) -{ - if (!def || def->name != "call_tool") + if (!command || command->key != "call_tool") return {}; - const std::string target = args.value("tool", std::string()); - std::shared_ptr<const ToolDef> inner = registry.lookup(target); + const std::string target = args.value("tool", std::string()); + std::shared_ptr<const NativeCommand> inner = catalog.lookup(target); if (!inner) - return registry.unknown_tool(target, /*suggest=*/true); - if (inner->name == "call_tool") + return catalog.unknown_command(target, /*suggest=*/true); + if (inner->key == "call_tool") return "call_tool calls another tool, not itself"; json inner_args = args.contains("args") && args["args"].is_object() ? args["args"] : json::object(); if (std::string err = argument_error(*inner, inner_args); !err.empty()) return "Invalid arguments for " + target + ": " + err; - def = std::move(inner); - args = std::move(inner_args); + command = std::move(inner); + args = std::move(inner_args); return {}; } -std::vector<std::string> ToolRegistry::similar(const std::string& name, std::size_t limit) const -{ - std::vector<std::pair<std::size_t, std::string>> scored; - for (const ToolDef& t : m_tools) - scored.emplace_back(t.name.find(name) != std::string::npos ? 0 : edit_distance(name, t.name), t.name); - std::sort(scored.begin(), scored.end()); - std::vector<std::string> out; - for (const auto& [score, n] : scored) - if (out.size() < limit && score <= std::max<std::size_t>(3, name.size() / 2)) - out.push_back(n); - return out; -} - -std::string ToolRegistry::unknown_tool(const std::string& name, bool suggest) const -{ - std::string message = "Unknown tool: " + name; - if (const std::string elsewhere = m_elsewhere ? m_elsewhere(name) : std::string(); !elsewhere.empty()) - return message + "; " + elsewhere; - if (suggest) - if (const auto close = similar(name); !close.empty()) - message += " (did you mean " + close.front() + "?)"; - return message; -} - -std::string validate_arguments(const json& schema, const json& args) { return validate_value(schema, args, ""); } - std::string decode_header_value(const std::string& value) { static const std::string prefix = "=?base64?", suffix = "?="; @@ -390,21 +108,15 @@ std::string decode_header_value(const std::string& value) return out; } -std::string argument_error(const ToolDef& def, json& args) -{ - normalize_arguments(def.input_schema, args); - return validate_arguments(def.input_schema, args); -} - // ---- McpProtocol -------------------------------------------------------------- -McpProtocol::McpProtocol(const ToolRegistry& registry, ToolCaller& caller, ServerInfo info) - : m_registry(registry), m_caller(caller), m_info(std::move(info)) +McpProtocol::McpProtocol(const CommandCatalog& catalog, ToolCaller& caller, ServerInfo info) + : m_catalog(catalog), m_caller(caller), m_info(std::move(info)) {} -json McpProtocol::tool_to_json(const ToolDef& def) +json McpProtocol::tool_to_json(const NativeCommand& def) { - json t{{"name", def.name}, {"description", def.description}, {"inputSchema", def.input_schema}}; + json t{{"name", def.key}, {"description", def.description}, {"inputSchema", def.input_schema}}; if (!def.title.empty()) t["title"] = def.title; t["annotations"] = {{"readOnlyHint", def.read_only}, @@ -437,20 +149,19 @@ json McpProtocol::result_to_json(const ToolResult& result) json McpProtocol::tools_list() const { - // Core first, then the API lane an agent should prefer, then the UI lane; registration order within each. + // The listed commands, in the order they were added. json tools = json::array(); - for (const ToolLane lane : {ToolLane::Core, ToolLane::Api, ToolLane::Ui}) - for (const ToolDef& def : m_registry.tools()) - if (def.lane == lane) - tools.push_back(tool_to_json(def)); + for (const NativeCommand& def : m_catalog.commands()) + if (def.listed) + tools.push_back(tool_to_json(def)); return tools; } json McpProtocol::call_tool(const json& params, bool& unknown_tool, std::string& unknown_name) { unknown_tool = false; - const std::string name = params.value("name", ""); - std::shared_ptr<const ToolDef> def = m_registry.lookup(name); + const std::string name = params.value("name", ""); + std::shared_ptr<const NativeCommand> def = m_catalog.lookup(name); if (def == nullptr) { unknown_tool = true; unknown_name = name; @@ -461,7 +172,7 @@ json McpProtocol::call_tool(const json& params, bool& unknown_tool, std::string& return result_to_json(ToolResult::error("arguments must be an object")); if (std::string err = argument_error(*def, args); !err.empty()) return result_to_json(ToolResult::error("Invalid arguments: " + err)); - if (std::string err = resolve_api_call(m_registry, def, args); !err.empty()) + if (std::string err = resolve_call(m_catalog, def, args); !err.empty()) return result_to_json(ToolResult::error(err)); try { return result_to_json(m_caller.call(*def, args)); @@ -537,9 +248,9 @@ PostReply McpProtocol::handle_legacy(const json& id, const std::string& method, json result = call_tool(params, unknown, name); if (unknown) { json data{{"name", name}}; - if (auto close = m_registry.similar(name); !close.empty()) + if (auto close = m_catalog.similar(name); !close.empty()) data["did_you_mean"] = close; - return reply(200, error_body(id, kInvalidParams, m_registry.unknown_tool(name), std::move(data))); + return reply(200, error_body(id, kInvalidParams, m_catalog.unknown_command(name), std::move(data))); } return result_reply(id, std::move(result)); } @@ -599,9 +310,9 @@ PostReply McpProtocol::handle_modern(const json& id, const std::string& method, json result = call_tool(params, unknown, name); if (unknown) { json data{{"name", name}}; - if (auto close = m_registry.similar(name); !close.empty()) + if (auto close = m_catalog.similar(name); !close.empty()) data["did_you_mean"] = close; - return reply(200, error_body(id, kInvalidParams, m_registry.unknown_tool(name), std::move(data))); + return reply(200, error_body(id, kInvalidParams, m_catalog.unknown_command(name), std::move(data))); } return result_reply(id, complete(std::move(result))); } diff --git a/src/slic3r/GUI/Mcp/McpProtocol.hpp b/src/slic3r/GUI/Mcp/McpProtocol.hpp index 04a46cc292..29d44baf27 100644 --- a/src/slic3r/GUI/Mcp/McpProtocol.hpp +++ b/src/slic3r/GUI/Mcp/McpProtocol.hpp @@ -2,6 +2,8 @@ #include "McpTypes.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include <nlohmann/json.hpp> #include <string> @@ -49,11 +51,12 @@ struct PostReply class McpProtocol { public: - McpProtocol(const ToolRegistry& registry, ToolCaller& caller, ServerInfo info); + // tools/list shows the commands of `catalog` that are listed; tools/call reaches every command it holds. + McpProtocol(const CommandCatalog& catalog, ToolCaller& caller, ServerInfo info); PostReply handle_post(const PostRequest& request); - static nlohmann::json tool_to_json(const ToolDef& def); + static nlohmann::json tool_to_json(const NativeCommand& command); static nlohmann::json result_to_json(const ToolResult& result); private: @@ -64,18 +67,13 @@ private: nlohmann::json call_tool(const nlohmann::json& params, bool& unknown_tool, std::string& unknown_name); nlohmann::json tools_list() const; - const ToolRegistry& m_registry; - ToolCaller& m_caller; - ServerInfo m_info; + const CommandCatalog& m_catalog; + ToolCaller& m_caller; + ServerInfo m_info; }; // Decodes the `=?base64?...?=` sentinel form of an Mcp-Name / Mcp-Param header value; plain values // pass through unchanged. std::string decode_header_value(const std::string& value); -// Readies a call's arguments for `def`, as every caller of a tool does: normalizes `args` in place -// (normalize_arguments()) and returns why validate_arguments() refuses them; empty when they are valid. -// Each caller adds its own prefix. -std::string argument_error(const ToolDef& def, nlohmann::json& args); - }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpRecorder.cpp b/src/slic3r/GUI/Mcp/McpRecorder.cpp index ec493108e0..90fff7914a 100644 --- a/src/slic3r/GUI/Mcp/McpRecorder.cpp +++ b/src/slic3r/GUI/Mcp/McpRecorder.cpp @@ -10,9 +10,11 @@ #include "UiInspector.hpp" #include "VideoEncode.hpp" #include "VideoOverlay.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" +#include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Widgets/Label.hpp" @@ -368,7 +370,9 @@ OverlayCaption McpRecorder::caption_overlay(Recording& rec, const CaptionBoard:: // At most a few hundred bytes of each, more than any caption shows, so a long value costs little to // measure; only what fits is drawn. - std::vector<std::pair<std::string, SpanRole>> parts{{shorten(into_u8(wxGetTranslation(from_u8(line.title))), 400), SpanRole::Title}}; + const wxString title = line.context.empty() ? wxGetTranslation(from_u8(line.title)) + : I18N::translate(line.title, line.context.c_str()); + std::vector<std::pair<std::string, SpanRole>> parts{{shorten(into_u8(title), 400), SpanRole::Title}}; if (!line.detail.empty()) parts.push_back({shorten(line.detail, 400), SpanRole::Detail}); if (!line.error.empty()) @@ -851,7 +855,7 @@ void McpRecorder::shutdown(std::chrono::milliseconds timeout) rec->sink->abort("app_closing"); } -void McpRecorder::call_started(uint64_t call, const ToolDef& def, const json& args, const std::string& /*parent*/) +void McpRecorder::call_started(uint64_t call, const NativeCommand& def, const json& args, const std::string& /*parent*/) { // Calls that act on the app; the inspect ones, recording tools included, only look. if (def.guard == GuardClass::Inspect) @@ -859,8 +863,10 @@ void McpRecorder::call_started(uint64_t call, const ToolDef& def, const json& ar std::lock_guard<std::mutex> lock(m_mutex); if (!m_rec || m_rec->ending || !m_rec->options.captions) return; - m_rec->board.call_started(call, def.title, safe_caption_detail(def.name, args), Clock::now()); - m_captioned[call] = {def.name, {args}}; + const char* context = title_context(def); + m_rec->board.call_started(call, def.title, safe_caption_detail(def.key, args), Clock::now(), + context != nullptr ? context : ""); + m_captioned[call] = {def.key, {args}}; } void McpRecorder::call_args(uint64_t call, const json& args) diff --git a/src/slic3r/GUI/Mcp/McpRecorder.hpp b/src/slic3r/GUI/Mcp/McpRecorder.hpp index a27c58a50a..4c609a2335 100644 --- a/src/slic3r/GUI/Mcp/McpRecorder.hpp +++ b/src/slic3r/GUI/Mcp/McpRecorder.hpp @@ -5,6 +5,8 @@ #include "VideoEncode.hpp" #include "VideoOverlay.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include <boost/filesystem/path.hpp> #include <nlohmann/json.hpp> @@ -121,7 +123,7 @@ public: // still queued and leaves the rest to the sink's threads. void shutdown(std::chrono::milliseconds timeout); - void call_started(uint64_t call, const ToolDef& def, const nlohmann::json& args, const std::string& parent) override; + void call_started(uint64_t call, const NativeCommand& command, const nlohmann::json& args, const std::string& parent) override; void call_args(uint64_t call, const nlohmann::json& args) override; void call_ended(uint64_t call, const ToolResult& result) override; diff --git a/src/slic3r/GUI/Mcp/McpReplaySummary.cpp b/src/slic3r/GUI/Mcp/McpReplaySummary.cpp index 925e5bcd5d..13404992b4 100644 --- a/src/slic3r/GUI/Mcp/McpReplaySummary.cpp +++ b/src/slic3r/GUI/Mcp/McpReplaySummary.cpp @@ -1,6 +1,11 @@ #include "McpReplaySummary.hpp" #include "McpPaths.hpp" #include "McpReplay.hpp" +#include "McpTypes.hpp" + +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem/path.hpp> @@ -8,7 +13,6 @@ #include <array> #include <cstddef> -#include <exception> #include <initializer_list> #include <ios> #include <optional> @@ -113,19 +117,6 @@ std::pair<std::string, std::string> split_action_id(const std::string& id) return {id.substr(0, first), id.substr(first + 1, last - first - 1)}; } -// A Speed Dial param that names a file, in either of the forms path params take. -std::optional<std::string> param_file(const std::string& param) -{ - std::string err; - try { - if (const auto p = parse_path_param(param, err); p && path_from_utf8(p->path).is_absolute()) - return p->path; - } catch (const std::exception&) { - // A malformed {"overwrite": ...}; the param is then not read as a file. - } - return std::nullopt; -} - bool starts_with(const std::string& s, const char* prefix) { return s.rfind(prefix, 0) == 0; } bool one_of(const std::string& s, std::initializer_list<const char*> names) @@ -136,12 +127,19 @@ bool one_of(const std::string& s, std::initializer_list<const char*> names) return false; } -void describe_command(Builder& b, const std::string& key, const std::string& param) +void describe_command(Builder& b, const std::string& key, const json& args) { - const std::optional<std::string> file = param.empty() ? std::nullopt : param_file(param); - json what{{"kind", "command"}, {"key", key}}; - if (!param.empty()) - what["param"] = file ? file_name(*file) : param; + json what{{"kind", "command"}, {"key", key}}; + // Each argument as "name: value", the file of a path by its name. + if (args.is_object() && !args.empty()) { + json texts = json::array(); + for (const auto& [name, value] : args.items()) { + const bool file = name == "path" && value.is_string(); + texts.push_back(name + ": " + + (file ? file_name(value.get<std::string>()) : value.is_string() ? value.get<std::string>() : value.dump())); + } + what["args"] = std::move(texts); + } b.d.what = std::move(what); if (starts_with(key, "calib_")) { @@ -163,11 +161,10 @@ void describe_command(Builder& b, const std::string& key, const std::string& par void describe_action(Builder& b, const json& args) { - const std::string id = args.contains("id") && args["id"].is_string() ? args["id"].get<std::string>() : std::string(); - const std::string param = args.contains("param") && args["param"].is_string() ? args["param"].get<std::string>() : std::string(); - const auto [prefix, middle] = split_action_id(id); - if (prefix == "orca_command") { - describe_command(b, middle, param); + const std::string id = args.contains("id") && args["id"].is_string() ? args["id"].get<std::string>() : std::string(); + const auto [prefix, middle] = split_action_id(id); + if (prefix == kCommandPrefix) { + describe_command(b, middle, args.contains("args") ? args["args"] : json()); } else if (prefix == "orca_recent_project") { b.d.what = {{"kind", "recent_project"}, {"name", file_name(middle)}}; b.flag(StepFlag::ReplacesProject); @@ -183,6 +180,14 @@ void describe_action(Builder& b, const json& args) } } +// A command that has a tile and no typed tool's place in the tool list (load_project, export_stl): called by +// its key, it does what run_action of its tile does. +bool tile_command(const std::string& tool) +{ + const NativeCommand* command = NativeCommands::find(tool); + return command != nullptr && command->in_palette && !command->listed; +} + std::optional<std::string> read_text(const fs::path& path) { boost::nowide::ifstream in(path_to_utf8(path).c_str(), std::ios::binary); @@ -289,6 +294,11 @@ json describe_call(const std::string& tool, const json& args) describe_action(b, args); return b.d.what; } + if (tile_command(tool)) { + Builder b; + describe_command(b, tool, args); + return b.d.what; + } if (tool == "run_replay") return args.contains("path") && args["path"].is_string() ? json{{"kind", "files"}, {"names", {file_name(args["path"].get<std::string>())}}} : json(); @@ -321,6 +331,10 @@ StepDescription describe_step(const ReplayStep& step, const Replay& replay, cons describe_nested(b, args, ctx, depth); return b.done(); } + if (tile_command(tool)) { + describe_command(b, tool, args); + return b.done(); + } b.d.what = describe_what(tool, args); // A file written into the run's own output folder is the run's output, not an effect to flag. @@ -353,7 +367,8 @@ StepDescription describe_step(const ReplayStep& step, const Replay& replay, cons b.flag(StepFlag::ChangesPresets); if (one_of(tool, {"new_project", "generate_calibration_test"})) { b.flag(StepFlag::ReplacesProject); - b.replace("checked"); + // new_project with no arguments is New Project's: the app asks about the unsaved changes. + b.replace(tool == "new_project" && person_form(args) ? "app_asked" : "checked"); } if (tool == "open_files" && args.contains("paths") && args["paths"].is_array() && args["paths"].size() == 1 && args["paths"][0].is_string()) { diff --git a/src/slic3r/GUI/Mcp/McpReplaySummary.hpp b/src/slic3r/GUI/Mcp/McpReplaySummary.hpp index d3b491da6c..9a67cebe02 100644 --- a/src/slic3r/GUI/Mcp/McpReplaySummary.hpp +++ b/src/slic3r/GUI/Mcp/McpReplaySummary.hpp @@ -24,7 +24,7 @@ struct StepDescription { std::vector<StepFlag> flags; // no duplicates, in enum order // What the step acts on: {"kind":"files","names":[...]} | {"kind":"settings","pairs":[...]} - // | {"kind":"command","key":k,"param"?:p} (a file param as its file name) | {"kind":"recent_project","name":n} + // | {"kind":"command","key":k,"args"?:["name: value", ...]} (a file by its name) | {"kind":"recent_project","name":n} // | {"kind":"preset","name":n} | {"kind":"plates","plates":"current"|"all"|index} // | {"kind":"replay","steps":n} | {"kind":"value","text":t} | null. nlohmann::json what; @@ -38,7 +38,9 @@ struct StepDescription }; // Describes `step` of `replay`, substituting its arguments leniently over `ctx`; a file counts as -// written inside the output folder when it is inside ctx.out_dir. A run_replay step is described by +// written inside the output folder when it is inside ctx.out_dir. A step that calls a Speed Dial command +// by its key (one with a tile and no place in the tool list) is described as run_action of its tile is. +// A run_replay step is described by // the steps of its inline replay, or of its file when `path` reads and parses, each in the nested // run's own context (its vars merged with the step's `vars`, its own replay and output folders); // past `depth` 4, or when the file doesn't read or parse, it gets every flag, "checked" and diff --git a/src/slic3r/GUI/Mcp/McpService.cpp b/src/slic3r/GUI/Mcp/McpService.cpp index 5139e927eb..ce11dd7487 100644 --- a/src/slic3r/GUI/Mcp/McpService.cpp +++ b/src/slic3r/GUI/Mcp/McpService.cpp @@ -22,7 +22,9 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/ImGuiWrapper.hpp" #include "slic3r/GUI/Jobs/Worker.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/MainFrame.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/plugin/PluginManager.hpp" #include "slic3r/plugin/PythonScriptRunner.hpp" @@ -145,19 +147,16 @@ WorkerHooks ui_job_worker_hooks() return hooks; } -// Server instructions shown to the model; clients truncate them at 4096 characters. // The scope key of a plugin's calls, which no job id ("j<n>") can equal. std::string plugin_scope_key(const std::string& plugin_key) { return "plugin:" + plugin_key; } +// Server instructions shown to the model; clients truncate them at 4096 characters. const char* kInstructions = "OrcaSlicer, a 3D-printing slicer, driven through its GUI.\n" - "Each tool's description starts with its lane: [core] runs the session and recovers from dialogs, [api] acts on " - "project data by index and name with JSON in and out, [ui] drives the GUI itself. Every tool is callable; prefer " - "[api] tools, and use [ui] tools for what no [api] tool reaches or to see what a person sees.\n" "Workflow: get_app_state (is it ready? which presets, plates, dialogs?) -> act -> check it with the reading " "tools (list_objects, list_plates, get_settings, slice's reply, get_slice_stats); screenshot only to see what they " "do not report.\n" - "Core:\n" + "Running the session, dialogs, replays and scripts:\n" "- A call that takes long or opens a dialog returns {status:\"running\"|\"blocked_by_dialog\", job}. It keeps " "running: never retry it. Answer dialogs with answer_dialog (see get_app_state.dialogs), then wait {for:\"job\"}. " "A native message box (native: true) is answered with answer_dialog by one of the buttons listed for it; a file or " @@ -169,10 +168,11 @@ const char* kInstructions = "- run_script runs Python against orca.host, the plugin API (search_python_api searches it), computing over meshes and " "settings and calling tools through orca.host.tools; its own file, program, thread and network use is restricted " "unless get_app_state.python.scripts_unrestricted.\n" - "- Not sure what does something? search_tools {query} searches every catalog at once: the tools, the operations " - "plugins offer (plugin.<plugin>.<name>, which the tool list does not show; call_tool runs them), Speed Dial actions, " - "settings, the Python API and the Design tab's CAD tools, each match with how to use it.\n" - "API lane:\n" + "- Not sure what does something? search_tools {query} searches every catalog at once: the commands, with those the " + "tool list does not show (Speed Dial commands, the Design tab's, and operations plugins offer as " + "plugin.<plugin>.<name>; call_tool runs them), the Speed Dial's other actions, settings and the Python API, each " + "match with how to use it.\n" + "Acting on project data by index and name, JSON in and out; prefer these:\n" "- Typed tools: open_files, select_preset, set_settings, slice, export and the rest.\n" "- What a setting does, or which one controls an effect: get_settings with keys, or query with a few words, and no " "scope, which looks through the process, filament and printer settings; each item names its scope, the one " @@ -183,7 +183,7 @@ const char* kInstructions = "- Lists come in pages: {items, offset, total}, with next_offset while more remain; call again with that offset to " "read on. list_objects has plates and outside in place of items.\n" "- Paths are absolute. Outputs never overwrite a file unless overwrite is true.\n" - "UI lane:\n" + "Driving the GUI itself, for what those do not reach or to see what a person sees:\n" "- run_action runs every Speed Dial command (search_actions finds them): prefer it to GUI clicks.\n" "- list_widgets lists widgets, menus, 3D toolbar items, gizmos, ImGui items and web page elements with refs; click " "/ set_widget_value / press_keys / mouse_gesture act on refs from the latest list_widgets call, or on locators, which " @@ -211,17 +211,7 @@ void McpServiceDeleter::operator()(McpService* service) const McpService::McpService() = default; -const ToolRegistry& McpService::offline_catalog() -{ - // Kept, never destroyed: the catalog's handlers refer to this service, and the bridge answers from - // the catalog until the process exits. - static McpService* const service = [] { - auto* s = new McpService(); - s->register_tools(); - return s; - }(); - return service->m_registry; -} +const CommandCatalog& McpService::catalog() const { return NativeCommands::instance(); } ServerInfo McpService::server_info() { @@ -271,11 +261,12 @@ bool McpService::start(const McpLaunchOptions& options, bool serve, std::string& [this](const std::string& tool, bool running) { m_inspector->ui_activity(tool, running); }); // A plugin's calls are refused from the moment it unloads, before end_plugin_scope() comes. m_jobs.set_owner_liveness([](const std::string& plugin) { return PluginManager::instance().is_plugin_loaded(plugin); }); - m_core = std::make_unique<McpCore>(m_registry, *m_invoker, m_jobs, &m_journal, CoreTiming{}, ui_job_worker_hooks(), + m_core = std::make_unique<McpCore>(catalog(), *m_invoker, m_jobs, &m_journal, CoreTiming{}, ui_job_worker_hooks(), m_recorder.get()); + // A command reaches the service through its call's context (ToolContext::service()). + m_core->set_service(this); m_web_presses = std::make_shared<WebPresses>(); m_modals->set_before_press([this] { release_web_presses(m_web_presses, nullptr); }); - register_tools(); track_window_states(); m_inspector->capture_menus(true); if (ImGuiWrapper* imgui = wxGetApp().imgui()) @@ -315,7 +306,7 @@ bool McpService::start(const McpLaunchOptions& options, bool serve, std::string& // Request threads of an endpoint closed earlier may still be using the protocol object. if (!m_protocol) { - m_protocol = std::make_unique<McpProtocol>(m_registry, *m_core, server_info()); + m_protocol = std::make_unique<McpProtocol>(catalog(), *m_core, server_info()); m_gate = std::make_shared<RequestGate>(); m_gate->protocol = m_protocol.get(); } @@ -716,29 +707,10 @@ json McpService::describe() const return out; } -void McpService::register_tools() +NativeCommand McpService::as_person(const NativeCommand& command) { - register_app_tools(*this); - register_action_tools(*this); - register_project_tools(*this); - register_config_tools(*this); - register_scene_tools(*this); - register_layer_tools(*this); - register_view_tools(*this); - register_ui_tools(*this); - register_replay_tools(*this); - register_record_tools(*this); -#ifdef SLIC3R_CAD - register_cad_tools(*this); -#endif - register_python_tools(*this); - register_api_tools(*this); -} - -ToolDef McpService::as_person(const ToolDef& def) -{ - ToolDef person = def; - person.handler = [this, handler = def.handler](const json& args, ToolContext& ctx) { + NativeCommand person = command; + person.run = [this, handler = command.run](const json& args, ToolContext& ctx) { const std::string job = ctx.job_id(); { std::lock_guard<std::mutex> lock(m_run_state_mutex); @@ -791,7 +763,7 @@ void McpService::run_launch_file() if (!m_options.run_out.empty()) args["out_dir"] = m_options.run_out; } - const ToolDef def = as_person(*m_registry.find(python ? "run_script" : "run_replay")); + const NativeCommand def = as_person(*catalog().find(python ? "run_script" : "run_replay")); ToolResult r = m_core->call(def, args); // A replay or script that opened a dialog and answers it itself replies blocked_by_dialog first. const std::string status = r.is_error ? std::string() : r.data.value("status", ""); @@ -834,7 +806,7 @@ void McpService::post_ui(std::function<void()> fn) void McpService::request_stop(const std::string& job) { m_jobs.request_stop(job); } -std::optional<ToolResult> McpService::call_to_end(const ToolDef& def, const json& args) +std::optional<ToolResult> McpService::call_to_end(const NativeCommand& def, const json& args) { ToolResult r = m_core->call(def, args); const std::string status = r.is_error ? std::string() : r.data.value("status", ""); @@ -854,11 +826,11 @@ std::optional<ToolResult> McpService::call_to_end(const ToolDef& def, const json bool McpService::encode_when_closed(json args, std::function<void(const ToolResult&)> done) { - const ToolDef* encode = started() ? m_registry.find("encode_recording") : nullptr; + const NativeCommand* encode = started() ? catalog().find("encode_recording") : nullptr; if (encode == nullptr || m_stopping) return false; // A person's encode, outside the session journal like Action Replay's runs. - ToolDef def = *encode; + NativeCommand def = *encode; def.journal = false; std::lock_guard<std::mutex> lock(m_runs_mutex); // Threads that have set their flag are done or about to be; joining them keeps the list short. @@ -895,10 +867,10 @@ bool McpService::encode_when_closed(json args, std::function<void(const ToolResu ToolResult McpService::start_encode(const json& args) { - const ToolDef* encode = started() ? m_registry.find("encode_recording") : nullptr; + const NativeCommand* encode = started() ? catalog().find("encode_recording") : nullptr; if (encode == nullptr || m_stopping) return ToolResult::error("OrcaSlicer is shutting down"); - ToolDef def = *encode; + NativeCommand def = *encode; def.journal = false; def.budget_ms = 0; // the envelope at once; the result comes from wait return m_core->call(def, args); @@ -929,7 +901,7 @@ void McpService::stop_person_runs() std::shared_ptr<PersonRun> McpService::start_replay_run(Replay replay, ReplayContext sctx, std::optional<std::size_t> only_step, bool discard_authorized, PersonRun::Events events) { - const ToolDef* run_replay_def = started() ? m_registry.find("run_replay") : nullptr; + const NativeCommand* run_replay_def = started() ? catalog().find("run_replay") : nullptr; if (run_replay_def == nullptr || m_stopping) return nullptr; { @@ -950,9 +922,9 @@ std::shared_ptr<PersonRun> McpService::start_replay_run(Replay replay, ReplayCon auto shared = std::make_shared<Replay>(std::move(replay)); auto ctx_held = std::make_shared<ReplayContext>(std::move(sctx)); // run_replay's properties, outside the session journal: a person's run is not an agent's call. - ToolDef def = *run_replay_def; - def.journal = false; - def.handler = [this, run, shared, ctx_held, only_step, discard_authorized](const json&, ToolContext& ctx) { + NativeCommand def = *run_replay_def; + def.journal = false; + def.run = [this, run, shared, ctx_held, only_step, discard_authorized](const json&, ToolContext& ctx) { const std::string job = ctx.job_id(); run->set_job(job); struct Authorization @@ -1000,7 +972,7 @@ std::shared_ptr<PersonRun> McpService::start_replay_run(Replay replay, ReplayCon std::shared_ptr<PersonRun> McpService::start_python_session(std::shared_ptr<PythonSession> session, const fs::path& file, PersonRun::Events events) { - const ToolDef* run_script = started() ? m_registry.find("run_script") : nullptr; + const NativeCommand* run_script = started() ? catalog().find("run_script") : nullptr; if (run_script == nullptr || m_stopping || !session) return nullptr; { @@ -1020,9 +992,9 @@ std::shared_ptr<PersonRun> McpService::start_python_session(std::shared_ptr<Pyth auto hosted = std::make_shared<std::atomic<bool>>(false); auto filename = file.empty() ? std::string("<run_script>") : path_to_utf8(file); // run_script's properties, outside the session journal, as a person's run. - ToolDef def = as_person(*run_script); - def.journal = false; - def.handler = [this, run, session, hosted, filename](const json&, ToolContext& ctx) { + NativeCommand def = as_person(*run_script); + def.journal = false; + def.run = [this, run, session, hosted, filename](const json&, ToolContext& ctx) { run->set_job(ctx.job_id()); hosted->store(true); // A handler that refuses never hosts the session: it ends here all the same. diff --git a/src/slic3r/GUI/Mcp/McpService.hpp b/src/slic3r/GUI/Mcp/McpService.hpp index 3c498ed451..6686e94ec3 100644 --- a/src/slic3r/GUI/Mcp/McpService.hpp +++ b/src/slic3r/GUI/Mcp/McpService.hpp @@ -11,6 +11,8 @@ #include "McpTypes.hpp" #include "UiInvoker.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" + #include <boost/filesystem/path.hpp> #include <nlohmann/json.hpp> @@ -55,9 +57,10 @@ struct AutoAnswerSet bool paused = false; }; -// The MCP server inside the running app: owns the tool catalog, the UI invoker, jobs, the session -// journal, the modal-dialog tracker and the HTTP endpoint, and runs a --mcp-run once the app is -// ready. Created by GUI_App; started, suspended and stopped on the UI thread. +// The MCP server inside the running app: owns the UI invoker, jobs, the session journal, the +// modal-dialog tracker and the HTTP endpoint, serves the process's command catalog +// (NativeCommands::instance()), and runs a --mcp-run once the app is ready. Created by GUI_App; started, +// suspended and stopped on the UI thread. // // Off unless the preference or --mcp/--mcp-run asks for it; when off, none of this exists. // Held in an McpServicePtr, whose deleter is the only way to destroy one. @@ -68,17 +71,12 @@ public: McpService(const McpService&) = delete; McpService& operator=(const McpService&) = delete; - // The tool catalog this build serves, held by a service that is never started. Building it needs - // neither wx nor a window: registering a tool only describes it, and its handler runs only when - // the tool is called. The stdio bridge lists the tools from it while no OrcaSlicer is running. - // Built on first use and kept until the process exits. - static const ToolRegistry& offline_catalog(); // What initialize and server/discover report: the server's name, version and instructions. static ServerInfo server_info(); - // Builds the catalog and, when `serve` is true, opens the HTTP endpoint. A replay or script from - // `options` runs after mark_ready(). Returns false with `err` set when the endpoint can't start; - // the catalog stays usable for it either way. + // Starts the automation runtime (jobs, the core, the UI invoker) and, when `serve` is true, opens the HTTP + // endpoint. A replay or script from `options` runs after mark_ready(). Returns false with `err` set when + // the endpoint can't start; the runtime stays usable either way. bool start(const McpLaunchOptions& options, bool serve, std::string& err); // Stops everything; idempotent, and final: start() refuses afterwards. Wakes every waiting call // and closes the endpoint, but frees nothing: a call may still be on the UI thread's stack inside @@ -115,7 +113,9 @@ public: // Monotonic counter bumped by suspend(); refs carry it to detect a rebuilt UI. uint64_t ui_generation() const { return m_generation; } - ToolRegistry& registry() { return m_registry; } + // The process's command catalog, which the service serves; the same for every service. Any thread, once + // startup has built it (NativeCommands::build()). + const CommandCatalog& catalog() const; JobRegistry& jobs() { return m_jobs; } Journal& journal() { return m_journal; } UiInvoker& ui() { return *m_invoker; } @@ -195,9 +195,11 @@ public: // refused job sets too. nullptr when the service is not started or is stopping. UI thread. std::shared_ptr<PersonRun> start_python_session(std::shared_ptr<PythonSession> session, const boost::filesystem::path& file, PersonRun::Events events); - // True when a run a person started (Action Replay, the Run Script panel, --mcp-run) is in `lineage`: a - // run_script there runs as the person's script, not an agent's. Any thread. + // True when a run a person started (Action Replay, the Run Script panel, --mcp-run, a long command a person + // picked) is in `lineage`: a run_script there runs as the person's script, not an agent's. Any thread. bool person_run(const std::set<std::string>& lineage) const; + // `command` with a function that marks its job as a person's run while it runs (person_run()). + NativeCommand as_person(const NativeCommand& command); // Stops `job` and what it runs: every call it and its descendants make sees itself cancelled // (JobRegistry::request_stop). Any thread. void request_stop(const std::string& job); @@ -223,12 +225,9 @@ private: friend struct McpServiceDeleter; ~McpService(); - void register_tools(); - // `def` with a handler that marks its job as a person's run while it runs (person_run()). - ToolDef as_person(const ToolDef& def); - // Calls `def` and follows the job it starts to its end; nullopt when the service stops first. A thread + // Calls `command` and follows the job it starts to its end; nullopt when the service stops first. A thread // the service owns calls it. - std::optional<ToolResult> call_to_end(const ToolDef& def, const nlohmann::json& args); + std::optional<ToolResult> call_to_end(const NativeCommand& command, const nlohmann::json& args); void set_ready(); void run_launch_file(); GuardState guards_on_ui() const; @@ -240,7 +239,6 @@ private: bool m_port_held_by_other = false; std::unique_ptr<UiDispatcher> m_dispatcher; - ToolRegistry m_registry; JobRegistry m_jobs; Journal m_journal; // Before the invoker, so it outlives the invoker's callbacks, which read it. @@ -293,7 +291,7 @@ private: }; // Lets plugins call the tools through orca.host.tools: a call from a plugin's Script worker runs as -// McpCore::call_plugin(), starting the service in its catalog-only mode when MCP is off, and is logged. +// McpCore::call_plugin(), starting the service without its endpoint when MCP is off, and is logged. // Called once by GUI_App as it sets up plugins. void install_plugin_tool_caller(); diff --git a/src/slic3r/GUI/Mcp/McpStdioBridge.cpp b/src/slic3r/GUI/Mcp/McpStdioBridge.cpp index 8f97aff1d0..1b93bf87a1 100644 --- a/src/slic3r/GUI/Mcp/McpStdioBridge.cpp +++ b/src/slic3r/GUI/Mcp/McpStdioBridge.cpp @@ -6,6 +6,8 @@ #include "McpService.hpp" #include "McpTypes.hpp" #include "libslic3r/Utils.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "libslic3r_version.h" #include <boost/asio/connect.hpp> @@ -307,10 +309,11 @@ PostReply answer_offline(const std::string& line, const std::map<std::string, st // A tool needs the app, so the bridge never brings a tools/call here. struct NoApp final : ToolCaller { - ToolResult call(const ToolDef&, const json&) override { return ToolResult::error("OrcaSlicer is not running."); } + ToolResult call(const NativeCommand&, const json&) override { return ToolResult::error("OrcaSlicer is not running."); } }; static NoApp caller; - static McpProtocol protocol(McpService::offline_catalog(), caller, McpService::server_info()); + // The process catalog, built here on first use: this process never starts the GUI that builds it. + static McpProtocol protocol(NativeCommands::instance(), caller, McpService::server_info()); auto header = [&headers](const char* name) { const auto it = headers.find(name); return it == headers.end() ? std::string() : it->second; diff --git a/src/slic3r/GUI/Mcp/McpStdioBridge.hpp b/src/slic3r/GUI/Mcp/McpStdioBridge.hpp index fc673d9ee4..466589863d 100644 --- a/src/slic3r/GUI/Mcp/McpStdioBridge.hpp +++ b/src/slic3r/GUI/Mcp/McpStdioBridge.hpp @@ -11,7 +11,7 @@ namespace Slic3r { namespace GUI { namespace Mcp { // clients that only speak stdio (Claude Desktop, for one). Each newline-delimited JSON-RPC message // is POSTed to the running OrcaSlicer's endpoint found through <datadir>/mcp/server.json. While none // answers, every request but tools/call gets the reply this build's server would give, from its own -// catalog (McpService::offline_catalog()), and a tools/call starts OrcaSlicer with --mcp, giving it +// catalog (NativeCommands::instance()), and a tools/call starts OrcaSlicer with --mcp, giving it // up to 60 s: an agent session that never calls a tool never opens the app. Runs before any GUI setup. int run_stdio_bridge(int argc, char** argv); diff --git a/src/slic3r/GUI/Mcp/McpTools.hpp b/src/slic3r/GUI/Mcp/McpTools.hpp index 983e7ee61c..5d208f5b56 100644 --- a/src/slic3r/GUI/Mcp/McpTools.hpp +++ b/src/slic3r/GUI/Mcp/McpTools.hpp @@ -3,6 +3,7 @@ #include "McpTypes.hpp" #include "libslic3r/CustomGCode.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "libslic3r/Point.hpp" #include "libslic3r/Slicing.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" @@ -15,6 +16,7 @@ #include <cstdint> #include <functional> #include <initializer_list> +#include <memory> #include <optional> #include <string> #include <utility> @@ -38,6 +40,7 @@ namespace CustomGCode { struct Info; } namespace GUI { +struct AppAction; class IMSlider; class PartPlateList; class Plater; @@ -50,23 +53,23 @@ struct Refusal; namespace Mcp { class McpService; -class ToolRegistry; struct Replay; struct ReplayContext; -// Each tool family registers itself with the service. -void register_app_tools(McpService& service); -void register_action_tools(McpService& service); -void register_project_tools(McpService& service); -void register_config_tools(McpService& service); -void register_scene_tools(McpService& service); -void register_view_tools(McpService& service); -void register_ui_tools(McpService& service); -void register_replay_tools(McpService& service); -void register_record_tools(McpService& service); -void register_cad_tools(McpService& service); -void register_python_tools(McpService& service); -void register_api_tools(McpService& service); +// Each tool family adds its commands to the catalog (NativeCommands::register_all_commands()), and so do the +// Design tab's (register_cad_commands(), McpToolsCad.hpp). A command's function reaches the MCP service through +// its call's context (ToolContext::service()), so the catalog is built without one. +void register_app_tools(CommandCatalog& catalog); +void register_action_tools(CommandCatalog& catalog); +void register_project_tools(CommandCatalog& catalog); +void register_config_tools(CommandCatalog& catalog); +void register_scene_tools(CommandCatalog& catalog); +void register_view_tools(CommandCatalog& catalog); +void register_ui_tools(CommandCatalog& catalog); +void register_replay_tools(CommandCatalog& catalog); +void register_record_tools(CommandCatalog& catalog); +void register_python_tools(CommandCatalog& catalog); +void register_api_tools(CommandCatalog& catalog); // How run_replay_job() runs a replay beyond what the replay says. struct ReplayRunOptions @@ -96,19 +99,26 @@ nlohmann::json prop(const char* type, const std::string& description); nlohmann::json enum_prop(std::vector<std::string> values, const std::string& description); nlohmann::json array_prop(nlohmann::json items, const std::string& description); +// The typed tools are listed commands (tools/list shows them) made with NativeCommands::long_command(), their +// function unchanged, each in its `group`: core, api or ui (NativeCommand::group). // Pure observation: inline, read-only, inspect guard, not journaled. -ToolDef inspect_tool(std::string name, std::string title, std::string description, nlohmann::json schema, ToolHandler handler); +NativeCommand inspect_tool(std::string group, std::string name, std::string title, std::string description, nlohmann::json schema, + CommandFn handler); +// `command`, naming the operations (GUI/Operations) its function reaches, by function name. +NativeCommand reaching(std::vector<std::string> operations, NativeCommand command); // Anything that changes the app: a job under the mutate guard, journaled. -// `def`, naming the operations (GUI/Operations) its handler reaches, by function name. -ToolDef reaching(std::vector<std::string> operations, ToolDef def); -ToolDef mutate_tool(std::string name, std::string title, std::string description, nlohmann::json schema, ToolHandler handler, - bool destructive = false); +NativeCommand mutate_tool(std::string group, std::string name, std::string title, std::string description, nlohmann::json schema, + CommandFn handler, bool destructive = false); // ---- expected object IDs --------------------------------------------------------------------- // The schema of an expected ID argument: the id list_objects reports for an object or part (`of`), which // orca.host shows too, so a script addresses what it read. nlohmann::json expected_id_prop(const char* of); +// `command` with its id_args: the expected-id arguments its schema has (object_id and part_id, as +// expected_id_prop() describes them, and select_objects' object_ids, part_ids and instance_object_ids). Ids are +// allocated per process, so the session journal leaves them out (without_expected_ids()). +NativeCommand with_expected_ids(NativeCommand command); // Refuses the call when `args` names an expected object_id, or part_id, that is not the id of `object`, // or `volume`, which its index names now: the model changed since the caller read the index. Call it // before the tool changes anything. @@ -139,18 +149,18 @@ int arg_int(const nlohmann::json& args, const char* key, int fallback); double arg_double(const nlohmann::json& args, const char* key, double fallback); bool arg_bool(const nlohmann::json& args, const char* key, bool fallback); -// ---- search (McpToolsCommon.cpp) ------------------------------------------------------------- +// ---- search ---------------------------------------------------------------------------------- -// The words of a search query: lower case, split at anything but a letter or a digit. "to" or "of" -// starts a word of most help texts, so words of fewer than three letters are left out when the query -// has longer ones. -std::vector<std::string> query_words(const std::string& query); - -// How well an entry matches the words of query_words(): {words found in `name` or `text`, of them those -// found in `name`}, {0, 0} when none is. A word is found where a word of the text starts with it, so -// "retract" finds "retraction"; the text's words are split at underscores, dots and the like and also -// at a capital in a CamelCase name, so "mesh" finds TriangleMesh. -std::pair<int, int> match_score(const std::vector<std::string>& words, const std::string& name, const std::string& text); +// search_tools' answer from `catalog`, every command it holds and those its sources hold now, for `args`: +// - tool: that command's group, read_only, description and input schema, and its examples when it has some; +// ToolFailure, naming the closest keys, for a key lookup() does not resolve. +// - query: {total, items, use}, the `limit` (default 5) best matches by match_score(), each {name, group, summary, +// listed}, and one that is not listed, which no listing shows, with its input_schema too, and its description +// where it says more than the summary. +// - neither: {total, names}, in the order the catalog adds its commands, then its sources'. +// `group` keeps the commands of one group, in any case; a group no command has is refused, naming those there are. +// Any thread. +nlohmann::json search_commands(const CommandCatalog& catalog, const nlohmann::json& args); // The Speed Dial actions of `listed` (ActionRegistry::describe()'s items: id, title, group, description) // that `words` (of query_words()) describe, best first: those matching more of the words, then those @@ -159,18 +169,15 @@ std::pair<int, int> match_score(const std::vector<std::string>& words, const std // and search_tools both rank with it, so one query finds the same actions through either. nlohmann::json rank_actions(const nlohmann::json& listed, const std::vector<std::string>& words); -// The catalogs a name an agent calls can belong to: the registered tools and plugin operations, the -// Speed Dial's built-in commands, and the Design tab's CAD tools. -enum class Catalog { Tools, Actions, Cad }; +// Why run_action refuses `args` for `action`, or empty when it does not: a command's tile takes its command's +// arguments, which the command checks, and every other action (a plugin's script or page, a plate's, a setting's +// or a recent project's) takes none. +std::string action_args_error(const AppAction& action, const nlohmann::json& args); -// For a name `missed` does not have: where it does belong and how to call it there, as a clause for -// the error ("it is a CAD tool: call_cad_tool {tool: \"extrude\", args} runs it"); empty when no other -// catalog has it. A command is known by its id or by the name inside it. Any thread. -std::string other_catalog_hint(const ToolRegistry& registry, const std::string& name, Catalog missed); - -// The first sentence of `text` on one line, for a listing: up to the first full stop followed by a space -// or the end, "e.g." and "i.e." aside; the whole text when it has none. -std::string first_sentence(const std::string& text); +// What run_action answers for `id`, an action id or the name inside one, that no action of the app's state has: +// for a Design tab tile's, when that tile is there and that call_tool runs its command from any tab; for any +// other, where an action or a command is found. +std::string unknown_action(const std::string& id); // A setting value from JSON in the serialized form set_deserialize accepts: "3", "0.2", "1"/"0" // for booleans, "a,b" for arrays. A list of strings (`key` names a coStrings option, such as @@ -205,9 +212,9 @@ bool python_has_numpy(); // next work replaces. Hosts `session` (host_python_session()) under `filename` until it ends; a job cancel ends it. ToolResult run_python_session_job(McpService& service, ToolContext& ctx, PythonSession& session, const std::string& filename); -// What an editor suggests for each tool: [{name, title (translated), args: {name: {type?, enum?}}}]. The argument -// descriptions are written for agents, in English, and stay out. -nlohmann::json editor_tool_catalog(const ToolRegistry& registry); +// What an editor suggests for each listed command: [{name, title (translated), args: {name: {type?, enum?}}}]. The +// argument descriptions are written for agents, in English, and stay out. +nlohmann::json editor_tool_catalog(const CommandCatalog& catalog); // ---- settings scopes (McpToolsConfig.cpp) ---------------------------------------------------- @@ -488,7 +495,7 @@ std::vector<double> part_shape_size(const std::string& shape, const nlohmann::js // ---- layers (McpToolsLayers.cpp) ------------------------------------------------------------- -void register_layer_tools(McpService& service); +void register_layer_tools(CommandCatalog& catalog); // The settings a height range modifier takes: layer_height, the per-region process settings the object // list offers a part or a range (with `filaments` filament slots), and extruder, the range's filament. diff --git a/src/slic3r/GUI/Mcp/McpToolsActions.cpp b/src/slic3r/GUI/Mcp/McpToolsActions.cpp index cfafae9918..e12b013691 100644 --- a/src/slic3r/GUI/Mcp/McpToolsActions.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsActions.cpp @@ -2,26 +2,19 @@ // plugin scripts and pages, and (on request) settings - is reachable through these two tools. #include "slic3r/GUI/I18N.hpp" -#include "McpService.hpp" +#include "McpPersonContext.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" #include "slic3r/GUI/ActionRegistry.hpp" -#include "slic3r/GUI/GUI.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/GUI_App.hpp" -#ifdef SLIC3R_CAD -#include "slic3r/GUI/Mcp/McpToolsCad.hpp" -#endif #include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Operations/ExportOps.hpp" -#include "slic3r/GUI/Operations/Outcome.hpp" #include "slic3r/GUI/Operations/RunStatus.hpp" -#include "slic3r/GUI/Plater.hpp" #include <algorithm> #include <chrono> #include <cstddef> -#include <cstdint> -#include <optional> #include <string> #include <utility> #include <vector> @@ -40,23 +33,6 @@ ActionRegistry& registry_or_fail() return *reg; } -std::size_t edit_distance(const std::string& a, const std::string& b) -{ - std::vector<std::size_t> row(b.size() + 1); - for (std::size_t j = 0; j <= b.size(); ++j) - row[j] = j; - for (std::size_t i = 1; i <= a.size(); ++i) { - std::size_t diag = row[0]; - row[0] = i; - for (std::size_t j = 1; j <= b.size(); ++j) { - const std::size_t up = row[j]; - row[j] = std::min({row[j] + 1, row[j - 1] + 1, diag + (a[i - 1] == b[j - 1] ? 0 : 1)}); - diag = up; - } - } - return row[b.size()]; -} - // The name inside a "<source>:<name>:<plugin>" id (view_front in orca_command:view_front:orca), which // is what agents and the tools' own messages call an action. std::string short_id(const std::string& id) @@ -65,12 +41,13 @@ std::string short_id(const std::string& id) return first == std::string::npos || first == last ? id : id.substr(first + 1, last - first - 1); } -// The action `id` names: its full id, or a name only one action has. Otherwise ToolFailure: for a name -// that is a tool of `tools` or a CAD tool, where it runs; else the ids closest to it, scored against -// both forms, a name containing it (delete_all in obj_delete_all) counting as closest. -const AppAction& find_action(ActionRegistry& actions, std::string& id, const ToolRegistry& tools) +// The action `id` names: its full id, or a name only one action has, among the actions of the app's state now +// (find_live(): the call before may have opened a sketch, added a plate or switched the tab). Otherwise +// ToolFailure with the ids closest to it, scored against both forms, a name containing it (delete_all in +// obj_delete_all) counting as closest. +const AppAction& find_action(ActionRegistry& actions, std::string& id) { - if (const AppAction* action = actions.by_id(id)) + if (const AppAction* action = actions.find_live(id)) return *action; ActionRegistry::Query q; q.limit = 100000; @@ -89,27 +66,34 @@ const AppAction& find_action(ActionRegistry& actions, std::string& id, const Too id = named.front(); return *actions.by_id(id); } - if (const std::string elsewhere = other_catalog_hint(tools, id, Catalog::Actions); !elsewhere.empty()) - throw ToolFailure("Unknown action id " + id + "; " + elsewhere); std::sort(scored.begin(), scored.end()); json similar = json::array(); for (std::size_t i = 0; i < scored.size() && similar.size() < 3 && scored[i].first <= id.size() / 3 + 2; ++i) similar.push_back(scored[i].second); - throw ToolFailure("Unknown action id " + id + "; find it with search_actions", {{"similar", similar}}); -} - -const char* level_name(AppActionRunResult::Level level) -{ - switch (level) { - case AppActionRunResult::Level::Success: return "success"; - case AppActionRunResult::Level::Error: return "error"; - case AppActionRunResult::Level::Busy: return "busy"; - default: return "info"; - } + throw ToolFailure(unknown_action(id), {{"similar", similar}}); } } // namespace +std::string action_args_error(const AppAction& action, const json& args) +{ + if (!action.command.empty() || person_form(args)) + return {}; + return "The action " + action.id() + " takes no arguments: run it without args"; +} + +std::string unknown_action(const std::string& id) +{ + // A Design tile is no action while it is not live (ActionRegistry::materialize_design_actions()), but its + // command is in the catalog. + const std::string tile = id.find(':') != std::string::npos ? id : AppAction::compose_id(kCommandPrefix, id, kOrcaSourceKey); + if (is_design_tile_id(tile)) + return id + " is a Design tab tile, there only while the Design tab is shown in its mode (a sketch's or the model's) " + "with the CAD feature on; call_tool {\"tool\": \"" + short_id(tile) + "\"} runs its command from any tab"; + // The name may be a command's that has no tile, which call_tool runs. + return "Unknown action id " + id + "; find an action with search_actions, or a command with search_tools"; +} + json rank_actions(const json& listed, const std::vector<std::string>& words) { struct Hit @@ -140,29 +124,6 @@ json rank_actions(const json& listed, const std::vector<std::string>& words) return ranked; } -std::string other_catalog_hint(const ToolRegistry& registry, const std::string& name, Catalog missed) -{ - if (name.empty()) - return {}; - if (missed != Catalog::Tools && registry.lookup(name) != nullptr) - return "it is a tool of its own: call " + name + " directly"; -#ifdef SLIC3R_CAD - if (missed != Catalog::Cad) { - const std::vector<std::string> cad = cad_tool_names(); - if (std::find(cad.begin(), cad.end(), name) != cad.end()) - return "it is a CAD tool: call_cad_tool {tool: \"" + name + "\", args} runs it, and describe_cad_tool {tool} gives its arguments"; - } -#endif - // The built-in commands only: the registry's other actions (plates, recent projects, plugin - // scripts) are read on the UI thread, and their ids are not names an agent mistakes for a tool's. - if (missed != Catalog::Actions) { - const std::string key = short_id(name); - if (NativeCommands::find(key) != nullptr && (name == key || name == "orca_command:" + key + ":orca")) - return "it is a Speed Dial action: run_action {id: \"" + name + "\"} runs it"; - } - return {}; -} - ToolResult await_gcode_export(ToolContext& ctx, const Ops::ExportTicket& ticket) { json done = poll_ui( @@ -189,15 +150,14 @@ ToolResult await_gcode_export(ToolContext& ctx, const Ops::ExportTicket& ticket) return ToolResult::error("The export ended " + status, done); } -void register_action_tools(McpService& service) +void register_action_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(inspect_tool( - "search_actions", L("Search Speed Dial actions"), + catalog.add(inspect_tool( + "ui", "search_actions", L("Search Speed Dial actions"), "Search everything the Speed Dial can run: built-in commands (slice, export, views, object operations, plates, " "calibration wizards, help), recent projects, plugin scripts and pages. Each entry has an id for run_action, a " - "description and, when it takes one, a param (type and help). A query ranks them, best match first, as " + "description, the command's key for a built-in command, and, when it takes arguments, their input_schema. A query " + "ranks them, best match first, as " "search_tools does; without one they are listed by group and title. include_settings also lists settings (each " "jumps to that setting in the sidebar; use get_settings / set_settings to read or change values).", object_schema({{"query", prop("string", "A few words, e.g. \"delete object\": each is matched at the start of the words of " @@ -222,88 +182,56 @@ void register_action_tools(McpService& service) return ToolResult::ok(page(rank_actions(listed["items"], query_words(query)), args, 50)); })); - ToolDef run = mutate_tool( - "run_action", L("Run a Speed Dial action"), + NativeCommand run = mutate_tool( + "ui", "run_action", L("Run a Speed Dial action"), "Run one action by the id search_actions returned (orca_command:view_front:orca, or the name inside it, view_front), " - "with its param when it takes one (a percent, tab id, plate index, " - "or an absolute path - commands with a path parameter skip their file dialog; outputs need {\"path\": ..., " - "\"overwrite\": true} to replace a file). Actions that open a dialog return blocked_by_dialog; answer it with " - "answer_dialog, or, for a native one it can't press (a file picker), register auto_answer_dialogs before the call. " - "An export_gcode with a path " - "completes when the file is written; an action that starts a background job (obj_arrange, obj_orient) when the " - "job ends. An action that does nothing (no object selected) is an error. Some commands add what they did to the " - "reply (the obj_order_by_* order, the object obj_assemble made).", + "with args, the command's arguments, when it takes some (its input_schema). A command that asks in a dialog asks " + "when it is given no args, as a person's pick does, and runs without asking when given them: an absolute path " + "skips a file dialog, and an output needs {\"path\": ..., \"overwrite\": true} to replace a file. Go to layer and " + "Go to tab need their value ({\"percent\": 50}, {\"tab\": \"preview\"}). Actions that open a dialog return " + "blocked_by_dialog; answer it with answer_dialog, or, for a native one it can't press (a file picker), register " + "auto_answer_dialogs before the call. An export_gcode with a path completes when the file is written; an action " + "that starts a background job (obj_arrange, obj_orient) when the job ends. An action that does nothing (no object " + "selected) is an error. Some commands add what they did to the reply (the obj_order_by_* order, the object " + "obj_assemble made).", object_schema({{"id", prop("string", "Action id from search_actions, or the name inside it.")}, - {"param", prop("string", "Parameter, when the action takes one.")}}, + {"args", {{"type", "object"}, {"description", "The command's arguments, as its input_schema gives them."}}}}, {"id"}), - [&service](const json& args, ToolContext& ctx) { - std::string id = arg_string(args, "id"); - const std::string param = arg_string(args, "param"); - Ops::ExportTicket ticket; // of an action that completes in the background - json started = ctx.run_ui([&]() -> json { + [](const json& args, ToolContext& ctx) { + std::string id = arg_string(args, "id"); + json command_args = args.contains("args") ? args["args"] : json::object(); + std::string key; // the command of a command's tile + AppActionRunResult result; // of any other action + ctx.run_ui([&]() -> json { ActionRegistry& actions = registry_or_fail(); - const AppAction& action = find_action(actions, id, service.registry()); - // Without a path the command would ask for one in a native file dialog, which MCP - // can't fill in, and export behind it untracked. - if (action.completes_in_background && param.empty()) - throw ToolFailure("This action needs a path param here: " + action.param_help + - " (or use the export tool)"); - const bool background = action.completes_in_background; - if (background) - ctx.begin_operation(); // held from before the export starts - Plater* plater = wxGetApp().plater(); - uint64_t before = 0, revision = 0; - if (background && plater != nullptr) { - before = plater->export_seq(); - revision = plater->project_revision(); - } - const AppActionRunResult r = actions.run(id, param, /*record_stats=*/false); - json out{{"level", level_name(r.level)}, {"message", into_u8(r.message)}, {"done", r.done}, {"background", background}}; - // An operation's refusal is worded once, in English here as in a tool's reply. - if (r.refusal) { - out["message"] = r.refusal->english(); - out["refusal"] = {{"code", r.refusal->code}}; - if (!r.refusal->names.empty()) - out["refusal"]["names"] = r.refusal->names; - } - if (!r.reply.empty()) - out["reply"] = json::parse(r.reply, nullptr, /*allow_exceptions=*/false); - if (background && plater != nullptr) { - ticket.seq_before = before; - ticket.seq_after = plater->export_seq(); - ticket.revision = revision; - if (const auto run = plater->export_run(ticket.seq_after)) - ticket.path = run->path; - } - return out; + const AppAction& action = find_action(actions, id); + if (const std::string err = action_args_error(action, command_args); !err.empty()) + throw ToolFailure(err); + key = action.command; + if (key.empty()) + result = actions.run(id, command_args, /*record_stats=*/false); + return json(); }); - // A command that did nothing (no selection, no objects) fails here, though the palette - // shows it as information. - const bool done = started["done"].get<bool>(); - const json details = started.value("refusal", json()); - if (started["background"].get<bool>()) { - if (started["level"] == "error" || !done) - return ToolResult::error(started["message"].get<std::string>(), details); - if (ticket.seq_after == ticket.seq_before) - return ToolResult::error(started["message"].get<std::string>().empty() ? "The export did not start." : - started["message"].get<std::string>()); - return await_gcode_export(ctx, ticket); + if (key.empty()) { + settle(ctx); + return NativeCommands::from_run_result(id, result); } - settle(ctx); - const std::string level = started["level"]; - if (level == "error" || level == "busy" || !done) - return ToolResult::error(started["message"].get<std::string>().empty() ? "The action failed" : started["message"].get<std::string>(), - details); - json out{{"ran", id}, {"level", level}}; - if (!started["message"].get<std::string>().empty()) - out["message"] = started["message"]; - if (started.contains("reply") && started["reply"].is_object()) - out.update(started["reply"]); - return ToolResult::ok(out); + // A command's tile runs the command's own function, as a call of the command does, inside run_action's + // journal entry. + const NativeCommand* command = NativeCommands::find(key); + if (command == nullptr) + throw ToolFailure("Unknown command " + key); + if (const std::string err = argument_error(*command, command_args); !err.empty()) + throw ToolFailure("Invalid arguments for " + key + ": " + err); + TileContext tile(ctx, id); + ToolResult reply = command->run(command_args, tile); + if (!reply.is_error && reply.data.is_object()) + reply.data["ran"] = id; + return reply; }); // Its commands upload G-code to a print host (send_gcode) and sync presets with the cloud account (sync_presets). run.open_world = true; - reg.add(run); + catalog.add(run); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsApi.cpp b/src/slic3r/GUI/Mcp/McpToolsApi.cpp index 8c1ca38645..bf4c7e9cdb 100644 --- a/src/slic3r/GUI/Mcp/McpToolsApi.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsApi.cpp @@ -1,21 +1,22 @@ -// search_tools and call_tool: a generic way to every registered tool and to the operations plugins offer -// (plugin.<key>.<name>), which tools/list never shows. search_tools's search also reaches the other -// catalogs an agent calls into: Speed Dial actions, settings, the Python API and the Design tab's CAD tools. +// search_tools and call_tool: a generic way to every command of the catalog, those tools/list never shows +// among them: the Speed Dial's commands, the Design tab's and the operations plugins offer (plugin.<key>.<name>). +// search_tools's search also reaches the other catalogs an agent calls into: the Speed Dial's other actions, +// settings and the Python API. -#include "McpService.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" #include "slic3r/GUI/ActionRegistry.hpp" -#ifdef SLIC3R_CAD -#include "slic3r/GUI/Mcp/McpToolsCad.hpp" -#endif +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/GUI_App.hpp" +#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/plugin/PluginManager.hpp" #include "slic3r/plugin/PluginOperations.hpp" #include "slic3r/plugin/PythonInterpreter.hpp" +#include <boost/algorithm/string/predicate.hpp> #include <boost/log/trivial.hpp> #include <algorithm> @@ -30,10 +31,12 @@ namespace Slic3r { namespace GUI { namespace Mcp { using nlohmann::json; -json editor_tool_catalog(const ToolRegistry& registry) +json editor_tool_catalog(const CommandCatalog& catalog) { json tools = json::array(); - for (const ToolDef& def : registry.tools()) { + for (const NativeCommand& def : catalog.commands()) { + if (!def.listed) + continue; json args = json::object(); const auto properties = def.input_schema.find("properties"); if (properties != def.input_schema.end()) @@ -44,17 +47,47 @@ json editor_tool_catalog(const ToolRegistry& registry) arg[key] = schema[key]; args[name] = std::move(arg); } - tools.push_back({{"name", def.name}, {"title", _u8L(def.title.c_str())}, {"args", std::move(args)}}); + tools.push_back( + {{"name", def.key}, {"title", into_u8(NativeCommands::tile_title(def))}, {"args", std::move(args)}}); } return tools; } namespace { -// How many of each other catalog's matches search_tools shows beside the tools; its own search lists -// the rest. +// How many of each other catalog's matches search_tools shows beside the commands, and of the commands +// without a limit; each catalog's own search lists the rest. constexpr std::size_t kCatalogHits = 5; +// What search_tools looks through: every command of `catalog`, in the order they were added, then what its +// sources hold now; with `group`, those of that group, compared in any case. A group none of them has is +// refused with the groups there are, in the order they first appear. +std::vector<std::shared_ptr<const NativeCommand>> search_inventory(const CommandCatalog& catalog, const std::string& group) +{ + std::vector<std::shared_ptr<const NativeCommand>> all; + for (const NativeCommand& def : catalog.commands()) + all.emplace_back(std::shared_ptr<const NativeCommand>(), &def); // the catalog owns it + for (std::shared_ptr<const NativeCommand>& def : catalog.source_commands()) + all.push_back(std::move(def)); + if (group.empty()) + return all; + std::vector<std::shared_ptr<const NativeCommand>> out; + std::vector<std::string> groups; + for (std::shared_ptr<const NativeCommand>& def : all) { + if (std::find(groups.begin(), groups.end(), def->group) == groups.end()) + groups.push_back(def->group); + if (boost::algorithm::iequals(def->group, group)) + out.push_back(std::move(def)); + } + if (out.empty()) { + std::string names; + for (const std::string& name : groups) + names += (names.empty() ? "" : ", ") + name; + throw ToolFailure("Unknown group: " + group + "; the groups are " + names, {{"groups", groups}}); + } + return out; +} + // A catalog's best matches for search_tools, from `ranked`, its matches best first: {total, items, use} // with the first few, or null when nothing matched. json catalog_hits(const json& ranked, const std::string& use) @@ -67,18 +100,22 @@ json catalog_hits(const json& ranked, const std::string& use) return {{"total", ranked.size()}, {"items", std::move(items)}, {"use", use}}; } -// The Speed Dial actions, settings and CAD tools matching `words` (of `query`), for search_tools. A -// catalog that can't be read yet (startup, before the main window) is left out. UI thread. +// The Speed Dial's actions that are no command (plates, recent projects, plugin scripts and pages) and settings +// matching `words` (of `query`), for search_tools. A command's tile is left out: the command is among the +// commands already. A catalog that can't be read yet (startup, before the main window) is left out. UI thread. json ui_catalog_hits(const std::vector<std::string>& words, const std::string& query) { json out = json::object(); if (ActionRegistry* actions = wxGetApp().m_action_registry.get()) { ActionRegistry::Query all; all.limit = 100000; - const json listed = actions->describe(all); + json listed = actions->describe(all); + json others = json::array(); + for (json& action : listed["items"]) + if (!action.contains("command")) + others.push_back(std::move(action)); // Ranked as search_actions ranks them, so the same query reads on there from these. - out["actions"] = catalog_hits(rank_actions(listed["items"], words), - "run_action {id, param}; search_actions {query} lists the rest"); + out["actions"] = catalog_hits(rank_actions(others, words), "run_action {id, args}; search_actions {query} lists the rest"); } try { json settings = search_settings(query, kCatalogHits); @@ -88,26 +125,6 @@ json ui_catalog_hits(const std::vector<std::string>& words, const std::string& q } } catch (const ToolFailure&) { } -#ifdef SLIC3R_CAD - // Scored on the details too, so a word that is not in the one-line summary still finds the tool. - std::vector<std::pair<std::pair<int, int>, const json*>> scored; - for (const json& row : cad_tool_table()) { - const std::pair<int, int> score = match_score(words, row.at("name").get<std::string>(), - row.at("summary").get<std::string>() + ' ' + - row.at("details").get<std::string>()); - if (score.first > 0) - scored.emplace_back(score, &row); - } - std::stable_sort(scored.begin(), scored.end(), [](const auto& a, const auto& b) { return a.first > b.first; }); - json cad = json::array(); - for (const auto& [score, row] : scored) - cad.push_back({{"name", row->at("name")}, {"summary", row->at("summary")}}); - out["cad"] = catalog_hits(cad, - wxGetApp().is_enable_cad_feature() ? - "describe_cad_tool {tool} gives its arguments and examples; call_cad_tool {tool, args} runs it" : - "describe_cad_tool {tool} gives its arguments; call_cad_tool {tool, args} runs it once a person enables " - "the CAD feature in Preferences and restarts OrcaSlicer"); -#endif return out; } @@ -137,33 +154,34 @@ json python_hits(const std::string& query) {"use", "run_script {code}; search_python_api {query} gives each entry's whole documentation"}}; } -json describe_tool(const ToolDef& def) +json describe_tool(const NativeCommand& def) { - json out{{"name", def.name}, - {"lane", lane_name(def.lane)}, + json out{{"name", def.key}, + {"group", def.group}, + {"listed", def.listed}, {"read_only", def.read_only}, {"description", def.description}, {"input_schema", def.input_schema}}; - // The Design tab's CAD tools live behind one tool, and two others describe them. - if (def.name == "call_cad_tool") - out["cad_tools"] = "list_cad_tools lists the CAD tools; describe_cad_tool {tool} gives one's arguments and examples"; + if (!def.examples.is_null()) + out["examples"] = def.examples; return out; } -// A plugin's operation as a tool: a job (plugin code may take long), under the mutate guard and journaled -// when it changes something, under the inspect guard and unjournaled when it only reads. -std::shared_ptr<const ToolDef> operation_tool(const PluginOperation& op) +// A plugin's operation as a command: a job (plugin code may take long), under the mutate guard and journaled +// when it changes something, under the inspect guard and unjournaled when it only reads. Not listed; in the api +// group, as it is called by name with JSON in and out. +std::shared_ptr<const NativeCommand> operation_command(const PluginOperation& op) { - auto def = std::make_shared<ToolDef>(); - def->name = op.full_name(); + auto def = std::make_shared<NativeCommand>(); + def->key = op.full_name(); def->title = op.name; - def->description = "[api] Offered by a plugin. " + op.description; + def->group = "api"; + def->description = "Offered by a plugin. " + op.description; def->input_schema = op.schema; - def->lane = ToolLane::Api; def->read_only = !op.changes; def->guard = op.changes ? GuardClass::Mutate : GuardClass::Inspect; def->journal = op.changes; - def->handler = [op](const json& args, ToolContext& ctx) { + def->run = [op](const json& args, ToolContext& ctx) { // The operation runs third-party code: the log names who asked and whose code ran. const std::string caller = ctx.caller_plugin().empty() ? "client, replay or script" : "plugin " + ctx.caller_plugin(); BOOST_LOG_TRIVIAL(info) << "[MCP operation] plugin=" << op.plugin_key << " operation=" << op.name << " caller=" << caller; @@ -179,101 +197,134 @@ std::shared_ptr<const ToolDef> operation_tool(const PluginOperation& op) return def; } +// The operations the loaded plugins offer (plugin.<key>.<name>), which come and go with their plugins: a +// call finds one by name, and search_tools lists them; tools/list does not. +class PluginOperationSource final : public CommandSource +{ +public: + std::shared_ptr<const NativeCommand> find(const std::string& key) const override + { + if (key.rfind("plugin.", 0) != 0) + return nullptr; + if (auto op = PluginOperations::instance().find(key)) + return operation_command(*op); + return nullptr; + } + std::vector<std::shared_ptr<const NativeCommand>> all() const override + { + std::vector<std::shared_ptr<const NativeCommand>> out; + for (const PluginOperation& op : PluginOperations::instance().all()) + out.push_back(operation_command(op)); + return out; + } +}; + } // namespace -void register_api_tools(McpService& service) +json search_commands(const CommandCatalog& catalog, const json& args) { - ToolRegistry& reg = service.registry(); - // Plugin operations resolve by name, beside the registered tools, without being listed. - reg.set_dynamic([](const std::string& name) -> std::shared_ptr<const ToolDef> { - if (name.rfind("plugin.", 0) != 0) - return nullptr; - if (auto op = PluginOperations::instance().find(name)) - return operation_tool(*op); - return nullptr; + if (args.contains("tool")) { + const std::string name = arg_string(args, "tool"); + if (const std::shared_ptr<const NativeCommand> def = catalog.lookup(name)) + return describe_tool(*def); + throw ToolFailure(catalog.unknown_command(name), {{"did_you_mean", catalog.similar(name)}}); + } + const std::vector<std::shared_ptr<const NativeCommand>> all = search_inventory(catalog, arg_string(args, "group")); + const std::string query = arg_string(args, "query"); + json items = json::array(); + if (query.empty()) { + for (const auto& def : all) + items.push_back(def->key); + return {{"total", items.size()}, {"names", std::move(items)}}; + } + // A command is called by its key; its title, a person's name for it, counts as its text. Among equal + // matches a listed command comes first: the typed tools are what an agent calls, and many tiles run one. + const std::vector<std::string> words = query_words(query); + std::vector<std::pair<std::pair<int, int>, const NativeCommand*>> scored; + for (const auto& def : all) { + const std::pair<int, int> score = match_score(words, def->key, def->title + ' ' + def->description); + if (score.first > 0) + scored.emplace_back(score, def.get()); + } + std::stable_sort(scored.begin(), scored.end(), [](const auto& a, const auto& b) { + return a.first != b.first ? a.first > b.first : a.second->listed && !b.second->listed; }); - // A CAD tool or a Speed Dial action called as a tool is told where it runs: search_tools finds - // all three by one query, so their names reach call_tool and the tool list's callers too. - reg.set_elsewhere([®](const std::string& name) { return other_catalog_hint(reg, name, Catalog::Tools); }); + const std::size_t limit = std::size_t(arg_int(args, "limit", int(kCatalogHits))); + for (std::size_t i = 0; i < scored.size() && i < limit; ++i) { + const NativeCommand& def = *scored[i].second; + const std::string summary = first_sentence(def.description); + json item{{"name", def.key}, {"group", def.group}, {"summary", summary}, {"listed", def.listed}}; + // A listed command's schema is in tools/list; nothing else shows the others' description and schema. + if (!def.listed) { + if (def.description != summary) + item["description"] = def.description; + item["input_schema"] = def.input_schema; + } + items.push_back(std::move(item)); + } + return {{"total", scored.size()}, + {"items", std::move(items)}, + {"use", "call a listed command by its name; call_tool {tool, args} runs one that is not listed"}}; +} - reg.add(inspect_tool( - "search_tools", L("Find tools, actions, settings and APIs"), - "Find what does something, in one search, or look up one tool. With query: the tools and the operations plugins " - "offer (plugin.<plugin>.<name>, not in the tool list) that match, best first, a tool with its first sentence (its " - "schema is in the tool list, or here with tool) and an operation with its schema; and beside " - "them the best few matches of each other catalog, with its total and how to use it: actions (Speed Dial commands " - "for run_action), settings (get_settings / set_settings), python (the orca API for run_script) and cad (CAD " - "tools for call_cad_tool). With tool: that tool's or operation's description and input schema. With neither: every " - "tool and operation name. Call tools and operations with call_tool.", - object_schema({{"tool", prop("string", "A tool or operation name: its schema.")}, +void register_api_tools(CommandCatalog& catalog) +{ + // Plugin operations resolve by name, beside the catalog's commands, without being listed. + catalog.add_source(std::make_unique<PluginOperationSource>()); + + catalog.add(inspect_tool( + "api", "search_tools", L("Find tools, actions, settings and APIs"), + "Find what does something, in one search, or look up one command. With query: the commands that match, best " + "first, each with its group, the first sentence of its description and listed, whether the tool list shows it; " + "one that is not listed (a Speed Dial command, a Design tab command, or an operation a plugin offers, " + "plugin.<plugin>.<name>) comes with its input schema, and its description when that says more, which nothing " + "else shows. Beside them, the best few matches of each other catalog, with its total and how to use it: actions " + "(the Speed Dial's plates, recent projects and plugin scripts and pages, for run_action), settings (get_settings " + "/ set_settings) and python (the orca API for run_script). With tool: that command's description and input schema, " + "and its examples when it has some (the Design commands do). With neither: every command's name. group keeps the " + "names and the command matches to one group; the other catalogs' matches stay as they are. call_tool runs any " + "command, listed or not.", + object_schema({{"tool", prop("string", "A command's name: its description and schema.")}, {"query", prop("string", "A few words saying what you want to do or find, e.g. \"brim\" or \"mesh normals\".")}, - {"limit", {{"type", "integer"}, {"minimum", 1}, {"maximum", 200}, {"description", "At most this many tools (default 5)."}}}}), - [&service](const json& args, ToolContext& ctx) { - std::vector<std::shared_ptr<const ToolDef>> all; - for (const ToolDef& def : service.registry().tools()) - all.emplace_back(std::shared_ptr<const ToolDef>(), &def); - for (const PluginOperation& op : PluginOperations::instance().all()) - all.push_back(operation_tool(op)); - - if (args.contains("tool")) { - const std::string name = arg_string(args, "tool"); - for (const auto& def : all) - if (def->name == name) - return ToolResult::ok(describe_tool(*def)); - throw ToolFailure(service.registry().unknown_tool(name), {{"did_you_mean", service.registry().similar(name)}}); - } - const std::size_t limit = std::size_t(arg_int(args, "limit", int(kCatalogHits))); + {"group", prop("string", "Only the commands of this group, in any case: core (the session, dialogs and " + "Python), api (project data by index and name; plugin operations too), ui (the " + "GUI itself), Design (the Design tab's, with the CAD feature on), or a Speed Dial " + "section such as Commands, Object or View. A group no command has is refused with " + "the groups there are.")}, + {"limit", {{"type", "integer"}, {"minimum", 1}, {"maximum", 200}, {"description", "At most this many commands (default 5)."}}}}), + [](const json& args, ToolContext& ctx) { + json out = search_commands(NativeCommands::instance(), args); + if (args.contains("tool") || arg_string(args, "query").empty()) + return ToolResult::ok(std::move(out)); const std::string query = arg_string(args, "query"); const std::vector<std::string> words = query_words(query); - json items = json::array(); - if (query.empty()) { - for (const auto& def : all) - items.push_back(def->name); - return ToolResult::ok({{"total", items.size()}, {"names", std::move(items)}}); - } - std::vector<std::pair<std::pair<int, int>, std::shared_ptr<const ToolDef>>> scored; - for (const auto& def : all) { - const std::pair<int, int> score = match_score(words, def->name, def->description); - if (score.first > 0) - scored.emplace_back(score, def); - } - std::stable_sort(scored.begin(), scored.end(), [](const auto& a, const auto& b) { return a.first > b.first; }); - // A registered tool's schema is in tools/list already, so a match names it with its first sentence; an - // operation's is nowhere else, so it comes with the match. - for (std::size_t i = 0; i < scored.size() && i < limit; ++i) { - const ToolDef& def = *scored[i].second; - if (def.name.rfind("plugin.", 0) == 0) - items.push_back(describe_tool(def)); - else - items.push_back({{"name", def.name}, {"lane", lane_name(def.lane)}, {"summary", first_sentence(def.description)}}); - } - json out{{"total", scored.size()}, {"items", std::move(items)}}; - // The tools and operations answer without the UI thread: one held by a dialog or still starting - // leaves its catalogs out rather than failing the search. + // The commands answer without the UI thread: one held by a dialog or still starting leaves its + // catalogs out rather than failing the search. try { out.update(ctx.run_ui([&] { return ui_catalog_hits(words, query); })); } catch (const ToolFailure&) { } out["python"] = python_hits(query); - for (const char* catalog : {"actions", "settings", "python", "cad"}) - if (out.contains(catalog) && out[catalog].is_null()) - out.erase(catalog); + for (const char* other : {"actions", "settings", "python"}) + if (out.contains(other) && out[other].is_null()) + out.erase(other); return ToolResult::ok(std::move(out)); })); - // Dispatched before it runs (resolve_api_call): the call runs as the target's own, with its guard, + // Dispatched before it runs (resolve_call): the call runs as the target's own, with its guard, // mode, budget and journal flag, and is journaled as the target's call. This handler is never reached. - ToolDef call = mutate_tool( - "call_tool", L("Call a tool or plugin operation"), - "Call any registered tool, or an operation a plugin offers (see search_tools), by name with its arguments. It " - "runs and is recorded as that tool's own call, with its guards and reply budget.", - object_schema({{"tool", prop("string", "The tool or operation to call.")}, + NativeCommand call = mutate_tool( + "api", "call_tool", L("Call a tool or plugin operation"), + "Call any command by name with its arguments: a tool, or one the tool list does not show, a Speed Dial command, a " + "Design tab command or an operation a plugin offers (see search_tools). It runs and is recorded as that command's " + "own call, with its guards and reply budget.", + object_schema({{"tool", prop("string", "The command to call.")}, {"args", {{"type", "object"}, {"description", "Its arguments."}}}}, {"tool"}), [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("call_tool is dispatched to its tool before it runs"); }); // It calls any tool, run_script included, and plugin code. call.open_world = true; - reg.add(call); + catalog.add(call); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsApp.cpp b/src/slic3r/GUI/Mcp/McpToolsApp.cpp index 6c5a931d12..eeca0366b5 100644 --- a/src/slic3r/GUI/Mcp/McpToolsApp.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsApp.cpp @@ -26,6 +26,9 @@ #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/PrintHostDialogs.hpp" #include "slic3r/plugin/PythonInterpreter.hpp" +#ifdef SLIC3R_CAD +#include "McpToolsCad.hpp" +#endif #if defined(__WXGTK__) #include "slic3r/GUI/LinuxDisplayBackend.hpp" #endif @@ -148,6 +151,8 @@ json app_state(McpService& service) // The page exists only when the CAD preference was on at startup. #ifdef SLIC3R_CAD state["design_tab"] = frame->m_design_page != nullptr; + if (json note = cad_note(service.catalog()); !note.is_null()) + state["cad_note"] = std::move(note); #else state["design_tab"] = false; #endif @@ -239,19 +244,18 @@ bool condition_holds(McpService& service, const std::string& condition, const st } // namespace -void register_app_tools(McpService& service) +void register_app_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(inspect_tool( - "get_app_state", L("Get app state"), + catalog.add(inspect_tool( + "core", "get_app_state", L("Get app state"), "Snapshot of OrcaSlicer. Call it first and whenever you are unsure what the app is doing. The app: version, platform " "and display backend, whether it is ready, the main window, the displays (each one's work area x, y, width and " "height, as set_window takes positions, its scale and whether it is primary), the MCP endpoint (mcp), python " "(available: Python runs " "in this build; scripts_unrestricted: a script's own file, network, process and thread access is not held to " - "OrcaSlicer's folders, which only a person turns on, in Preferences > AI features > Python scripts) and design_tab (the Design tab and call_cad_tool are on; a person turns the CAD feature on in " - "Preferences and restarts). The project: current tab and mode, printer technology, name, path and unsaved changes, " + "OrcaSlicer's folders, which only a person turns on, in Preferences > AI features > Python scripts), design_tab " + "(the Design tab is on, and call_tool runs its commands, search_tools' group Design) and, when they do not run, " + "cad_note, how a person turns the CAD feature on. The project: current tab and mode, printer technology, name, path and unsaved changes, " "selected printer/process/filament presets, plates (count, current), object count, the selection (objects, the " "instances [[object, instance]] they are selected in and, when parts rather than whole instances are selected, " "parts [[object, part]], in the indices select_objects takes; wipe_tower when a prime tower is selected; canvas is the 3D " @@ -265,10 +269,13 @@ void register_app_tools(McpService& service) "control; menus closed unseen (a menu a call opened that no reply listed), auto_answer_dialogs rules in force, " "notifications, print host uploads (state, progress, error), the open gizmo, running jobs and a running " "recording.", - object_schema({}), [&service](const json&, ToolContext& ctx) { return ToolResult::ok(ctx.run_ui([&service] { return app_state(service); })); })); + object_schema({}), [](const json&, ToolContext& ctx) { + McpService& service = ctx.service(); + return ToolResult::ok(ctx.run_ui([&service] { return app_state(service); })); + })); - ToolDef wait = inspect_tool( - "wait", L("Wait for a condition"), + NativeCommand wait = inspect_tool( + "core", "wait", L("Wait for a condition"), "Block until a condition holds or timeout_s passes (max 50). for: \"ready\" (startup finished), \"idle\" (no dialog, " "no running job, nothing slicing or arranging, no gizmo working in the background; a run_script run counts only " "through the calls it makes), \"dialog\" / \"no_dialog\", or \"job\" with a job id an earlier call returned, whose " @@ -277,7 +284,8 @@ void register_app_tools(McpService& service) "is given, else idle.")}, {"job", prop("string", "Job id, for \"job\".")}, {"timeout_s", {{"type", "number"}, {"minimum", 0}, {"maximum", 50}, {"description", "Default 30."}}}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const std::string what = arg_string(args, "for", args.contains("job") ? "job" : "idle"); const auto timeout = std::chrono::milliseconds(int(arg_double(args, "timeout_s", 30) * 1000)); const auto start = std::chrono::steady_clock::now(); @@ -302,10 +310,10 @@ void register_app_tools(McpService& service) } }); wait.journal = true; // a replay needs the same waits - reg.add(wait); + catalog.add(wait); - reg.add(inspect_tool( - "get_log", L("Read the log"), + catalog.add(inspect_tool( + "core", "get_log", L("Read the log"), "The last lines of OrcaSlicer's current log file, optionally only those at or above a level.", object_schema({{"lines", {{"type", "integer"}, {"minimum", 1}, {"maximum", 2000}, {"description", "Default 200."}}}, {"level", enum_prop({"trace", "debug", "info", "warning", "error", "fatal"}, "Minimum level.")}}), diff --git a/src/slic3r/GUI/Mcp/McpToolsCad.cpp b/src/slic3r/GUI/Mcp/McpToolsCad.cpp index 5d338038d9..d6eefee59a 100644 --- a/src/slic3r/GUI/Mcp/McpToolsCad.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsCad.cpp @@ -1,7 +1,9 @@ -// The CAD tools behind the MCP server's call_cad_tool, and the registration of call_cad_tool, -// list_cad_tools and describe_cad_tool. kCadTools declares every CAD tool's name, access and handler; -// run_cad_tool() runs one on the UI thread, through the GUI's own CadDocument and DesignPanel's mcp_* -// hooks, behind the Design tab's busy and stale-id checks. tool_rows() describes them. +// The Design tab's commands. The Design table (kDesignTools, generated from scripts/CAD/tool_atlas.json) +// declares every one, its menu row, action, access and tool block; kSilentForms binds a block to the function +// that runs it. register_cad_commands() makes a command of each entry: with no arguments one that has an +// action does what its menu row does (open_tool()), and otherwise run_cad_tool() runs its silent form on the +// UI thread, through the GUI's own CadDocument and DesignPanel's mcp_* hooks, behind the Design tab's busy and +// stale-id checks (cad_gate()). #include "McpToolsCad.hpp" #include "libslic3r/Point.hpp" @@ -28,8 +30,10 @@ #include <nlohmann/json.hpp> #include <wx/string.h> +#include <wx/translation.h> #include <Standard_Failure.hxx> // OCCT base error +#include "slic3r/GUI/GUI.hpp" // into_u8 #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/MainFrame.hpp" @@ -38,7 +42,7 @@ #include "slic3r/GUI/ObjectDataViewModel.hpp" // itObject #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/Gizmos/GLGizmosManager.hpp" -#include "McpService.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" #include "McpPaths.hpp" @@ -46,7 +50,7 @@ #include "slic3r/GUI/CAD/DesignPanel.hpp" #include "slic3r/GUI/CAD/DesignCanvas.hpp" #include "slic3r/GUI/CAD/DesignSketchTool.hpp" -#include "slic3r/GUI/CAD/DesignOffer.hpp" // offer table — served whole by list_verbs, fired by run_verb +#include "slic3r/GUI/CAD/DesignOffer.hpp" // the Design table: every command's row, action and tool block #include "libslic3r/CAD/CadDocument.hpp" #include "libslic3r/CAD/SketchEngine.hpp" @@ -58,6 +62,7 @@ #include "libslic3r/Color.hpp" #include "libslic3r/format.hpp" #include "libslic3r/Format/OBJ.hpp" +#include "libslic3r_version.h" #include <boost/algorithm/string/case_conv.hpp> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> @@ -137,1359 +142,45 @@ const char* feature_type_name(CadFeatureType t) return "Unknown"; } -// --- The CAD tool table: the parameter schema of record --------------------------- +// --- What the commands' descriptions and schemas add to the Design table --------------- -// Read this before using any face or edge id: describe_cad_tool adds it to a reply that describes -// a tool taking or giving them. -const char* const kIdLifetime = - "Global face and edge ids are indices into the CURRENT topology and expire the moment " - "a feature rebuilds the model. Reading the scene once and then issuing several " - "operations addresses the wrong edge on every call after the first, and does NOT " - "error, because a stale id still names a real edge. Either re-read query_topology " - "before each id-taking call, or pass the 'generation' you were given back with the " - "call and have it refused if the model has moved on."; +// The `generation` property of every Design command with a silent form: how face and edge ids expire, and +// how a call keeps from acting on a stale one. +const char* const kGenerationNote = + "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids " + "expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the " + "generation, a call whose ids were read before the model changed is refused."; -// list_cad_tools' short form of kIdLifetime. -const char* const kIdsNote = - "Face and edge ids expire when a feature rebuilds the model, and a stale id still names a real face " - "or edge. Pass the generation they were read at with the call, and stale ids are refused."; - -// How a CAD tool whose kCadTools entry has ok_false reports a rebuild the kernel rejects. +// How a silent form whose entry has ok_false reports a rebuild the kernel rejects. 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 -// main window creates the Design page only at startup (its panel is built on first use), 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."; +// The rest of the description of a command whose entry has an action and no silent form, after its hint and +// before mode_note(). +const char* const kOpensToolNote = + "It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a " + "tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then."; -// The `plane` param. A face resolves differently for drilling than for anything else (see -// cad_resolve_plane), so the row says which frame the tool gets. -json plane_param(const json& def, bool drill) +// The `silent` property of a command whose entry has both forms, before mode_note(). +const char* const kSilentNote = + "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design " + "tab's menu row does, as a person's pick does."; + +// The mode an entry with an action runs in, as the Design tab's right-click menu offers it (offered_in_mode()). +// A sketch being constrained counts as open, and refuses sketch_commit and sketch_cancel: the tab's own Confirm +// and Cancel buttons end it. +const char* mode_note(const DesignTool& t) { - return json{{"name", "plane"}, {"type", "string|object"}, {"default", def}, - {"description", drill - ? "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or " - "{\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its " - "centroid, normal into the body, x along its longest edge). The reply's frame gives the axes." - : "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or " - "{\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the " - "body, x from the world axes). The reply's frame gives the axes."}}; + return t.sketch_mode ? "It runs only in an open sketch (sketch_begin opens one)." + : "It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab " + "constrains a sketch, its Confirm or Cancel button ends that)."; } -// A row's examples, written as JSON text so that each reads as the calls an agent sends: -// [{title, calls: [{tool, args}], needs?}]. Each runs on a fresh, empty design and ends with the tool -// its row describes, so its indices and face and edge ids are the ones such a design gives. An -// argument {"from_call": i, "key": k} is the value under k in the reply of call i of the same -// example, which is how a generation is passed on. `needs` names a file from outside the app, at a -// placeholder path. tools/mcp/test_cad_examples.py runs them in the app. The text is kept as written -// here and parsed by tool_rows() once the rows are built, so an error reading it names its row. -json examples(const char* text) { return json(text); } - -// One row per dispatched CAD tool (kCadTools), grouped by what the tools do: its name, a summary of -// one sentence and at most 120 characters, the details (the rest, "" when the summary says it all), -// params, examples and, for a tool that takes face or edge ids or gives them, "ids": true. -// cad_tool_table() adds what kCadTools declares; a param without a default is one the tool requires. -json tool_rows() -{ - json rows = json::array({ - json{{"name", "describe_scene"}, {"summary", "The Design document: features, variables with their values, bodies, undo_depth / redo_depth and generation."}, - {"details", "A feature's bound lists the fields an expression drives; a body gives bbox, source_feature, visible, color and moved (by the Move gizmo)."}, - {"params", json::array()}, - {"examples", examples(R"json([ - {"title": "An empty design", "calls": [ - {"tool": "describe_scene", "args": {}}]}, - {"title": "A plate's two features and its body", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "describe_scene", "args": {}}]}])json")}}, - json{{"name", "describe_feature"}, {"ids", true}, {"summary", "One feature as its card shows it: params, the editable ones with their ranges, expr, refs, used_by and bodies_made."}, - {"details", "expr holds its bindings, and refs the feature and body indices and face and edge ids it uses; a sketch adds its plane, entities and constraints (angles in degrees). Imported Text or SVG art shows its regions (a count), region_loops (how many closed loops each region has, its outer loop plus its holes; counts, not the loops' geometry) and region_areas (each region's filled area in mm² as placed, its outer loop less its holes)."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's extrude, with the fields its card edits", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "describe_feature", "args": {"feature": 1}}]}, - {"title": "A committed sketch's plane, entities and constraints", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "describe_feature", "args": {"feature": 0}}]}])json")}}, - json{{"name", "set_feature"}, {"summary", "Change a feature's editable fields as its card's Confirm does when editing: one undo step and a rebuild."}, - {"details", "A field an expression drives is refused. Reply: changed {field: [old, new]}."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - json{{"name", "fields"}, {"type", "object"}, {"description", "{field: value} from describe_feature's editable, e.g. {\"distance\": 15}: numbers within its ranges; mode new|union|subtract|intersect; extrude_end blind|symmetric|two_sided|through_all; shape rectangle|circle; xf_* vectors [x, y, z]"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate made 15 mm thick", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}}]}, - {"title": "A plate's hole widened from 5 to 8 mm", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "set_feature", "args": {"feature": 2, "fields": {"hole_diameter": 8}}}]}])json")}}, - json{{"name", "extrude"}, {"ids", true}, {"summary", "Extrude a committed sketch, one of its loops, a face or a drawn profile into a body."}, - {"details", "A committed sketch, or one loop of it, extrudes as the Extrude card does; push/pull grows a planar face of a body; a profile drawn here is an explicit closed `profile` (list of [x,y]) or a centred width x height rectangle on `plane`. End conditions match Onshape. Reply: extrude_index, the index of its sketch (-1 for a face), the boolean and body used, end, frame."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"default", nullptr}, {"description", "a committed Sketch feature to extrude (sketch_commit's sketch_index); profile, width, height and plane are then refused"}}, - json{{"name", "loop"}, {"type", "integer"}, {"default", nullptr}, {"description", "with sketch: one closed loop (closed_loops[].index of sketch_describe {sketch}) with the loops inside it as holes; a hole is a loop of its own, so its index extrudes the disc. Omit for the whole sketch"}}, - json{{"name", "face"}, {"type", "integer"}, {"default", nullptr}, {"description", "push/pull: a planar face (query_topology id) of `body` grown along its outward normal (flip for inward); boolean auto joins that body. sketch, loop, profile, width, height, plane and taper are then refused, and end is blind or symmetric"}}, - json{{"name", "width"}, {"type", "number"}, {"unit", "mm"}, {"default", 20}, {"min", 0.01}}, - json{{"name", "height"}, {"type", "number"}, {"unit", "mm"}, {"default", 20}, {"min", 0.01}}, - json{{"name", "distance"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - plane_param("XY", false), - json{{"name", "profile"}, {"type", "array"}, {"default", json::array()}, {"description", "optional closed contour [[x,y],...] in plane mm; overrides width/height"}}, - json{{"name", "boolean"}, {"type", "string"}, {"enum", json::array({"auto", "new", "union", "subtract", "intersect"})}, {"default", nullptr}, {"description", "auto joins the body the profile touches, else makes a new body, as the card's default; default auto with sketch, new without"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body to join, subtract from or intersect, or whose face is pushed; omit for the body a sketch touches, else the last body"}}, - json{{"name", "end"}, {"type", "string"}, {"enum", json::array({"blind", "symmetric", "two_sided", "through_all", "up_to_face"})}, {"default", "blind"}}, - json{{"name", "distance2"},{"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "second-side depth when end=two_sided (else falls back to distance)"}}, - json{{"name", "up_to_face"},{"type", "integer"}, {"default", -1}, {"description", "face id (query_topology) of the body the extrude works on, when end=up_to_face"}}, - json{{"name", "taper"}, {"type", "number"}, {"unit", "deg"}, {"default", 0}, {"description", "draft/taper of the side wall"}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "A 20 x 20 x 5 mm plate on the XY plane", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}]}, - {"title": "A committed sketch extruded 5 mm: a rectangle around a circle makes a plate with a bore", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "extrude", "args": {"sketch": 0, "distance": 5}}]}, - {"title": "A plate's top face pushed up 3 mm", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "extrude", "args": {"body": 0, "face": 5, "distance": 3, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "revolve"}, {"ids", true}, {"summary", "Revolve a committed sketch as the Revolve card does, or a profile drawn here, about an axis."}, - {"details", "A sketch turns about a line of it or a plane axis; a profile drawn here is an explicit `profile` offset from the axis, or a width x height rectangle with one edge on the axis, centred along it, so a full turn is a cylinder width long of radius height. Reply: revolve_index, the index of its sketch, the boolean, body and axis used, frame."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"default", nullptr}, {"description", "a committed Sketch feature to revolve (sketch_commit's sketch_index); profile, width, height and plane are then refused"}}, - json{{"name", "axis_entity"}, {"type", "integer"}, {"default", nullptr}, {"description", "with sketch: a line of the sketch (entity index) as the axis, or -1 for the plane axis; omit for the sketch's only centerline (construction line) when it has one and axis is not given"}}, - json{{"name", "width"}, {"type", "number"}, {"unit", "mm"}, {"default", 20}, {"min", 0.01}, {"description", "without sketch or profile: the rectangle's length along the axis"}}, - json{{"name", "height"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}, {"description", "without sketch or profile: how far the rectangle reaches out from the axis, the solid's radius"}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 360}}, - json{{"name", "axis"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 0}, {"description", "the plane's X (0) or Y (1) axis through its origin"}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}}, - plane_param("XY", false), - json{{"name", "profile"}, {"type", "array"}, {"default", json::array()}, {"description", "optional closed contour [[x,y],...] in plane mm; overrides width/height"}}, - json{{"name", "boolean"}, {"type", "string"}, {"enum", json::array({"new", "union", "subtract", "intersect"})}, {"default", "new"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body to join, subtract from or intersect; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A ring: a profile 10 to 15 mm out from the XZ plane's vertical axis, turned a full circle", "calls": [ - {"tool": "revolve", "args": {"plane": "XZ", "profile": [[10, 0], [15, 0], [15, 10], [10, 10]], "axis": 1}}]}, - {"title": "A committed sketch turned about its centerline, a construction line", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XZ"}}, - {"tool": "sketch_add", "args": {"rect": [10, 0, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, 0], "p1": [0, 10], "construction": true}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "revolve", "args": {"sketch": 0}}]}])json")}}, - json{{"name", "fillet"}, {"ids", true}, {"summary", "Round measured edges of a body (edge ids from query_topology on that body)."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "edge"}, {"type", "integer|array"}, {"description", "one edge id, or an array of ids rounded together in one feature"}}, - json{{"name", "radius"}, {"type", "number"}, {"unit", "mm"}, {"default", 1}, {"min", 0.01}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body. edge id is resolved against THIS body."}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's four vertical corners rounded to 2 mm", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "edge_kinds": ["line"], "direction": [0, 0, 1], "convex": true}}, - {"tool": "fillet", "args": {"body": 0, "edge": [0, 1, 4, 7], "radius": 2, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "One top edge of a plate rounded to 1 mm", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z", "adjacency": true}}, - {"tool": "fillet", "args": {"body": 0, "edge": 3, "radius": 1, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "chamfer"}, {"ids", true}, {"summary", "Chamfer measured edges of a body (edge ids from query_topology on that body)."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "edge"}, {"type", "integer|array"}, {"description", "one edge id, or an array of ids chamfered together in one feature"}}, - json{{"name", "distance"}, {"type", "number"}, {"unit", "mm"}, {"default", 1}, {"min", 0.01}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body. edge id is resolved against THIS body."}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's top edges chamfered 1 mm", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z", "adjacency": true}}, - {"tool": "chamfer", "args": {"body": 0, "edge": [3, 6, 9, 11], "distance": 1, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "hole"}, {"ids", true}, {"summary", "Drill a circular hole at (x,y) or `at` on a plane."}, - {"details", "Reply: hole_index, body, x and y in the frame, off_plane with at, frame."}, - {"params", json::array({ - json{{"name", "diameter"}, {"type", "number"}, {"unit", "mm"}, {"default", 5}, {"min", 0.01}}, - json{{"name", "depth"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - json{{"name", "through"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "x"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - json{{"name", "y"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - plane_param("XY", true), - json{{"name", "at"}, {"type", "array|object"}, {"default", nullptr}, {"description", "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body to drill; omit for a face plane's body, else the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A 5 mm hole through the middle of a plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}]}, - {"title": "A 4 mm hole 3 mm deep into a plate's top face, 5 mm off centre", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "hole", "args": {"plane": {"body": 0, "face": 5}, "diameter": 4, "depth": 3, "x": 5, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "hole_styled"}, {"ids", true}, {"summary", "Drill a hole with optional counterbore (style=1) or countersink (style=2) at (x,y) or `at` on a plane."}, - {"details", "Reply as hole."}, - {"params", json::array({ - json{{"name", "diameter"}, {"type", "number"}, {"unit", "mm"}, {"default", 5}, {"min", 0.01}}, - json{{"name", "depth"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - json{{"name", "through"}, {"type", "boolean"}, {"default", true}}, - json{{"name", "x"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - json{{"name", "y"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - plane_param("XY", true), - json{{"name", "at"}, {"type", "array|object"}, {"default", nullptr}, {"description", "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body to drill; omit for a face plane's body, else the last body"}}, - json{{"name", "style"}, {"type", "integer"}, {"default", 0}, {"description", "0=simple, 1=counterbore, 2=countersink"}}, - json{{"name", "cbore_diameter"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "cbore_depth"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "csink_diameter"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "csink_angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 90}}, - json{{"name", "standard"}, {"type", "string"}, {"default", ""}, {"description", "provenance designation, e.g. M6"}}, - })}, - {"examples", examples(R"json([ - {"title": "A counterbored hole for an M6 cap screw through a 10 mm block's top face", "calls": [ - {"tool": "extrude", "args": {"width": 30, "height": 30, "distance": 10}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "hole_styled", "args": {"plane": {"body": 0, "face": 5}, "diameter": 6.6, "style": 1, "cbore_diameter": 11, "cbore_depth": 6, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "A countersunk hole through a plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "hole_styled", "args": {"plane": {"body": 0, "face": 5}, "diameter": 4.5, "style": 2, "csink_diameter": 9, "csink_angle": 90, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "hole_standard"}, {"ids", true}, {"summary", "Drill a standard clearance hole (ISO 273 / ANSI) at (x,y) or `at` on a plane."}, - {"details", "style: 0=simple, 1=counterbore, 2=countersink. Reply as hole."}, - {"params", json::array({ - json{{"name", "designation"}, {"type", "string"}, {"description", "e.g. M6, 1/4-20"}}, - json{{"name", "style"}, {"type", "integer"}, {"default", 0}}, - json{{"name", "through"}, {"type", "boolean"}, {"default", true}}, - json{{"name", "depth"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - json{{"name", "x"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - json{{"name", "y"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "offset in the plane's frame from its origin, NOT world"}}, - plane_param("XY", true), - json{{"name", "at"}, {"type", "array|object"}, {"default", nullptr}, {"description", "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body to drill; omit for a face plane's body, else the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "An M5 clearance hole through a plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "hole_standard", "args": {"plane": {"body": 0, "face": 5}, "designation": "M5", "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "An M6 counterbored clearance hole through a 10 mm block's top face", "calls": [ - {"tool": "extrude", "args": {"width": 30, "height": 30, "distance": 10}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "hole_standard", "args": {"plane": {"body": 0, "face": 5}, "designation": "M6", "style": 1, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "thread"}, {"ids", true}, {"summary", "Cut a thread as the Thread card does, along a cylindrical face or a circular edge, or on a plane."}, - {"details", "On a face a bore is tapped, a boss threaded; on a plane the thread goes at (x,y) or `at`. Without designation, a face or edge takes the nearest standard size, ISO metric and UTS alike. Long threads take seconds and the reply may be a job. Reply: thread_index, designation (null when custom), internal, diameter, pitch, depth, length, body, x, y, frame."}, - {"params", json::array({ - json{{"name", "face"}, {"type", "integer"}, {"default", nullptr}, {"description", "a cylindrical face id of `body` (query_topology); the thread runs its length from its lower end"}}, - json{{"name", "edge"}, {"type", "integer"}, {"default", nullptr}, {"description", "instead of face: a circular edge id of `body`, the thread rising along its normal; needs length"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body of face or edge, or the body threaded on a plane; omit for the last body (on a plane, a face plane's body)"}}, - json{{"name", "designation"}, {"type", "string"}, {"default", nullptr}, {"description", "e.g. M5, M8x1, 1/4-20 UNC: sets diameter, pitch and depth"}}, - json{{"name", "internal"}, {"type", "boolean"}, {"default", nullptr}, {"description", "true taps a hole, false threads a rod; required on a plane, else from the face (a bore is internal), external for an edge"}}, - json{{"name", "diameter"}, {"type", "number"}, {"unit", "mm"}, {"default", nullptr}, {"description", "nominal (major) diameter, replacing the standard's; with pitch, a custom thread"}}, - json{{"name", "pitch"}, {"type", "number"}, {"unit", "mm"}, {"default", nullptr}, {"description", "replaces the standard's"}}, - json{{"name", "depth"}, {"type", "number"}, {"unit", "mm"}, {"default", nullptr}, {"description", "radial depth; default the 60 degree V's for the pitch and role"}}, - json{{"name", "length"}, {"type", "number"}, {"unit", "mm"}, {"default", nullptr}, {"description", "default the face's length; required for an edge or a plane"}}, - plane_param(nullptr, true), - json{{"name", "x"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "on a plane: offset in the plane's frame from its origin, NOT world"}}, - json{{"name", "y"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "on a plane: offset in the plane's frame from its origin, NOT world"}}, - json{{"name", "at"}, {"type", "array|object"}, {"default", nullptr}, {"description", "on a plane, instead of x and y: a world point [x, y, z], or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the thread shares, as hole takes it"}}, - })}, - {"examples", examples(R"json([ - {"title": "An M8 thread tapped into a 6.8 mm hole through a block", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "hole", "args": {"diameter": 6.8, "through": true}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, - {"tool": "thread", "args": {"body": 0, "face": 6, "designation": "M8", "generation": {"from_call": 2, "key": "generation"}}}]}, - {"title": "An M6 threaded rod 10 mm long, standing on the XY plane", "calls": [ - {"tool": "thread", "args": {"plane": "XY", "internal": false, "designation": "M6", "length": 10}}]}, - {"title": "A 10 mm boss threaded at the nearest standard size, which the reply's designation names", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 5}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "extrude", "args": {"sketch": 0, "distance": 12}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, - {"tool": "thread", "args": {"body": 0, "face": 0, "generation": {"from_call": 4, "key": "generation"}}}]}])json")}}, - json{{"name", "boolean"}, {"summary", "Combine two bodies: union | subtract (tool from target) | intersect."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "op"}, {"type", "string"}, {"enum", json::array({"union", "subtract", "intersect"})}, {"default", "subtract"}}, - json{{"name", "target"}, {"type", "integer"}, {"default", 0}}, - json{{"name", "tool"}, {"type", "integer"}, {"default", 1}}, - json{{"name", "keep_tool"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "tolerance"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - })}, - {"examples", examples(R"json([ - {"title": "A post subtracted from a block", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "extrude", "args": {"width": 6, "height": 6, "distance": 20, "boolean": "new"}}, - {"tool": "boolean", "args": {"op": "subtract", "target": 0, "tool": 1}}]}, - {"title": "Two overlapping blocks joined into one body", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "extrude", "args": {"profile": [[5, -5], [20, -5], [20, 5], [5, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "boolean", "args": {"op": "union", "target": 0, "tool": 1}}]}])json")}}, - json{{"name", "pattern"}, {"ids", true}, {"summary", "Replicate a body: linear (count along a plane axis at spacing) or circular (count over an angle about the plane normal)."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "circular"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "count"}, {"type", "integer"}, {"default", 3}, {"min", 1}}, - json{{"name", "spacing"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"description", "linear step"}}, - json{{"name", "dir"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 0}, {"description", "linear axis: 0=plane X, 1=plane Y"}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 360}, {"description", "circular total sweep"}}, - plane_param("XY", false), - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "Three plates 30 mm apart along X", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "pattern", "args": {"count": 3, "spacing": 30}}]}, - {"title": "Six blocks in a circle about the XY plane's normal", "calls": [ - {"tool": "extrude", "args": {"profile": [[20, -3], [30, -3], [30, 3], [20, 3]], "distance": 5}}, - {"tool": "pattern", "args": {"circular": true, "count": 6}}]}])json")}}, - json{{"name", "pattern_on_curve"}, {"summary", "Replicate a body along a sketch curve."}, - {"details", "`count` copies are placed at equal-parameter points on the entity, each translated by (P_i - P_0)."}, - {"params", json::array({ - json{{"name", "count"}, {"type", "integer"}, {"default", 3}, {"min", 1}}, - json{{"name", "sketch"}, {"type", "integer"}, {"description", "feature index of the sketch holding the guide curve"}}, - json{{"name", "entity"}, {"type", "integer"}, {"description", "entity index of the guide curve within that sketch"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "Four pegs spaced along a half circle", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "arc", "center": [0, 0], "radius": 30, "start_angle_deg": 0, "end_angle_deg": 180}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "extrude", "args": {"profile": [[28, -2], [32, -2], [32, 2], [28, 2]], "distance": 10}}, - {"tool": "pattern_on_curve", "args": {"sketch": 0, "entity": 0, "count": 4}}]}])json")}}, - json{{"name", "shell"}, {"ids", true}, {"summary", "Hollow a body to a wall thickness (inward); optionally leave one face open."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "thickness"}, {"type", "number"}, {"unit", "mm"}, {"default", 1}, {"min", 0.01}}, - json{{"name", "face"}, {"type", "integer"}, {"default", -1}, {"description", "face id to leave open (query_topology); omit for a closed hollow"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A 20 x 20 x 10 mm box hollowed to 1.5 mm walls, open at the top", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "shell", "args": {"body": 0, "face": 5, "thickness": 1.5, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "A block hollowed to closed 2 mm walls", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "shell", "args": {"thickness": 2}}]}])json")}}, - json{{"name", "draft"}, {"ids", true}, {"summary", "Taper a body face by an angle about its base (pull direction +Z)."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "face"}, {"type", "integer"}, {"description", "face id to draft (query_topology)"}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 5}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A block's +X side tapered 5 degrees", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "query_topology", "args": {"body": 0, "direction": [1, 0, 0]}}, - {"tool": "draft", "args": {"body": 0, "face": 1, "angle": 5, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "mirror"}, {"ids", true}, {"summary", "Mirror a body about a base plane."}, - {"details", "mode=new creates a mirrored copy; mode=add fuses the mirror back into the source."}, - {"params", json::array({ - plane_param("XZ", false), - json{{"name", "mode"}, {"type", "string"}, {"enum", json::array({"new", "add"})}, {"default", "new"}}, - json{{"name", "keep_original"},{"type", "boolean"}, {"default", true}, {"description", "when mode=new, keep the source body"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A mirrored copy of a block across the XZ plane", "calls": [ - {"tool": "extrude", "args": {"profile": [[-5, 5], [5, 5], [5, 15], [-5, 15]], "distance": 5}}, - {"tool": "mirror", "args": {"plane": "XZ"}}]}, - {"title": "A block against the XZ plane and its mirror image fused into one body", "calls": [ - {"tool": "extrude", "args": {"profile": [[-5, 0], [5, 0], [5, 10], [-5, 10]], "distance": 5}}, - {"tool": "mirror", "args": {"plane": "XZ", "mode": "add"}}]}])json")}}, - json{{"name", "transform"}, {"summary", "Move and/or rotate a body (B-rep transform)."}, - {"details", "copy=true keeps the source and appends the transformed copy as a new body."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - json{{"name", "dx"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "dy"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "dz"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "axis_x"}, {"type", "number"}, {"default", 0}}, - json{{"name", "axis_y"}, {"type", "number"}, {"default", 0}}, - json{{"name", "axis_z"}, {"type", "number"}, {"default", 1}}, - json{{"name", "pivot_x"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "pivot_y"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "pivot_z"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 0}}, - json{{"name", "copy"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate moved 30 mm along X", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "transform", "args": {"dx": 30}}]}, - {"title": "A copy of a plate 10 mm above it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "transform", "args": {"dz": 10, "copy": true}}]}])json")}}, - json{{"name", "axis"}, {"ids", true}, {"summary", "Create a datum axis (reference line): two points, face normal, cylinder centreline, plane intersection, or along edge."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "type"}, {"type", "string"}, {"enum", json::array({"two_points", "face_normal", "cylinder", "plane_intersection", "along_edge"})}, {"default", "two_points"}}, - json{{"name", "p1"}, {"type", "array"}, {"default", json::array({0,0,0})}, {"description", "first point [x,y,z] for two_points"}}, - json{{"name", "p2"}, {"type", "array"}, {"default", json::array({0,0,10})}, {"description", "second point [x,y,z] for two_points"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "body for face/edge refs"}}, - json{{"name", "face"}, {"type", "integer"}, {"default", -1}, {"description", "face id (query_topology) for face_normal/cylinder"}}, - json{{"name", "edge"}, {"type", "integer"}, {"default", -1}, {"description", "edge id (query_topology) for along_edge"}}, - json{{"name", "plane_a"}, {"type", "integer"}, {"default", -1}, {"description", "first datum plane feature index for plane_intersection"}}, - json{{"name", "plane_b"}, {"type", "integer"}, {"default", -1}, {"description", "second datum plane feature index for plane_intersection"}}, - })}, - {"examples", examples(R"json([ - {"title": "The axis of a hole through a plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, - {"tool": "axis", "args": {"type": "cylinder", "body": 0, "face": 6, "generation": {"from_call": 2, "key": "generation"}}}]}, - {"title": "The normal through the centre of a plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "axis", "args": {"type": "face_normal", "body": 0, "face": 5, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "The vertical line where two datum planes meet", "calls": [ - {"tool": "plane", "args": {"type": "offset", "base": "XZ", "offset": 10}}, - {"tool": "plane", "args": {"type": "offset", "base": "YZ", "offset": 10}}, - {"tool": "axis", "args": {"type": "plane_intersection", "plane_a": 0, "plane_b": 1}}]}])json")}}, - json{{"name", "coordsys"}, {"ids", true}, {"summary", "Create a datum coordinate system (origin + orthonormal axes)."}, - {"details", "PointWorld aligns to world; FaceAndDirection uses a face for Z and an edge/hint for X."}, - {"params", json::array({ - json{{"name", "type"}, {"type", "string"}, {"enum", json::array({"point_world", "face_and_direction"})}, {"default", "point_world"}}, - json{{"name", "point"}, {"type", "array"}, {"default", json::array({0,0,0})}, {"description", "origin [x,y,z] for point_world"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "body for face/edge refs"}}, - json{{"name", "face"}, {"type", "integer"}, {"default", -1}, {"description", "face id (query_topology) for Z axis"}}, - json{{"name", "edge"}, {"type", "integer"}, {"default", -1}, {"description", "edge id (query_topology) for X axis hint"}}, - json{{"name", "x_hint"}, {"type", "array"}, {"default", json::array({1,0,0})}, {"description", "fallback X direction hint if no edge given"}}, - })}, - {"examples", examples(R"json([ - {"title": "A connector on a plate's top face, its x axis along the front edge", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z", "adjacency": true}}, - {"tool": "coordsys", "args": {"type": "face_and_direction", "body": 0, "face": 5, "edge": 3, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "plane"}, {"ids", true}, {"summary", "Add a datum plane as the Plane card does, to sketch or build on as {\"datum\": plane_index}."}, - {"details", "Offset from a base plane or a face, at an angle about an edge, midway between two faces, tangent to a cylindrical face, through two edges, or coincident with a base plane or a face. Not the `plane` param of other CAD tools. Reply: plane_index, name, frame."}, - {"params", json::array({ - json{{"name", "type"}, {"type", "string"}, {"enum", json::array({"offset", "angle", "midplane", "tangent", "two_edges", "coincident"})}, {"default", "offset"}}, - json{{"name", "base"}, {"type", "string|object"}, {"default", "XY"}, {"description", "\"XY\", \"XZ\" or \"YZ\" through modeling_origin, or {\"datum\": i}: what offset, coincident and angle build on without face_a"}}, - json{{"name", "offset"}, {"type", "number"}, {"unit", "mm"}, {"default", 20}, {"description", "offset: distance along the normal of base or face_a"}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 0}, {"description", "offset without face_a: tilt about the base axis `axis`; angle: turn about edge_a from the reference plane; tangent: position around the cylinder"}}, - json{{"name", "axis"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 0}, {"description", "offset without face_a: tilt about the base plane's X (0) or Y (1) axis"}}, - json{{"name", "face_a"}, {"type", "object"}, {"default", nullptr}, {"description", "Face A, {\"body\": b, \"face\": f}: offset or coincident on a face; angle's reference plane; midplane's first face; tangent's cylindrical face"}}, - json{{"name", "face_b"}, {"type", "object"}, {"default", nullptr}, {"description", "Face B, {\"body\": b, \"face\": f}: midplane's second face"}}, - json{{"name", "edge_a"}, {"type", "object"}, {"default", nullptr}, {"description", "Edge A, {\"body\": b, \"edge\": e}: angle's hinge; two_edges' first edge"}}, - json{{"name", "edge_b"}, {"type", "object"}, {"default", nullptr}, {"description", "Edge B, {\"body\": b, \"edge\": e}: two_edges' second edge"}}, - json{{"name", "size"}, {"type", "array"}, {"unit", "mm"}, {"default", json::array({60, 60})}, {"description", "[u, v]: the size the plane is drawn at"}}, - })}, - {"examples", examples(R"json([ - {"title": "A datum plane 20 mm above XY", "calls": [ - {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 20}}]}, - {"title": "A datum plane midway between a block's top and bottom faces", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["planar"]}}, - {"tool": "plane", "args": {"type": "midplane", "face_a": {"body": 0, "face": 4}, "face_b": {"body": 0, "face": 5}, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "A datum plane turned 30 degrees from a plate's top face about its front edge", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z", "adjacency": true}}, - {"tool": "plane", "args": {"type": "angle", "face_a": {"body": 0, "face": 5}, "edge_a": {"body": 0, "edge": 3}, "angle": 30, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "helix"}, {"ids", true}, {"summary", "Create a helical curve, a sweep path for springs, coils and augers."}, - {"details", "It starts on the plane's x axis at `radius` from its origin. pitch = axial rise per turn. left_handed flips the winding. taper_deg != 0 gives a conical helix. Reply: helix_index, frame, start and tangent (world), to draw a sweep's profile across the curve there."}, - {"params", json::array({ - json{{"name", "radius"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - json{{"name", "pitch"}, {"type", "number"}, {"unit", "mm"}, {"default", 5}, {"min", 0.01}}, - json{{"name", "height"}, {"type", "number"}, {"unit", "mm"}, {"default", 20}, {"min", 0.01}}, - json{{"name", "left_handed"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "taper_deg"}, {"type", "number"}, {"unit", "deg"}, {"default", 0}}, - plane_param("XY", false), - })}, - {"examples", examples(R"json([ - {"title": "A four-turn helix on XY: radius 10 mm, pitch 5 mm, 20 mm tall", "calls": [ - {"tool": "helix", "args": {"radius": 10, "pitch": 5, "height": 20}}]}, - {"title": "A left-handed conical helix tapering 10 degrees", "calls": [ - {"tool": "helix", "args": {"radius": 10, "pitch": 4, "height": 20, "left_handed": true, "taper_deg": 10}}]}])json")}}, - json{{"name", "sweep"}, {"summary", "Sweep a committed sketch's closed profile along a path, a sketch or a helix, as the Sweep card does."}, - {"details", "Draw the profile across the path's start (a helix's start and tangent are in its reply); along a helix the profile keeps its angle to the helix axis. Long sweeps take seconds and the reply may be a job. Reply: sweep_index, bodies, boolean, body."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "the profile: a committed sketch's feature index"}}, - json{{"name", "path"}, {"type", "integer"}, {"description", "feature index of a sketch or a helix, other than the profile"}}, - json{{"name", "boolean"}, {"type", "string"}, {"enum", json::array({"new", "union", "subtract", "intersect"})}, {"default", "new"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body a union, subtract or intersect works on; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A spring: a 2 mm circle across a helix's start, swept along it", "calls": [ - {"tool": "helix", "args": {"radius": 10, "pitch": 5, "height": 20}}, - {"tool": "sketch_begin", "args": {"plane": "XZ"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [10, 0], "radius": 1}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sweep", "args": {"sketch": 1, "path": 0}}]}, - {"title": "A 6 mm rod swept along a 40 mm line", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, 0], "p1": [0, 40]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sketch_begin", "args": {"plane": "XZ"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 3}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sweep", "args": {"sketch": 1, "path": 0}}]}])json")}}, - json{{"name", "loft"}, {"summary", "Loft a solid through two or more committed sketches, in order, as the Loft card does."}, - {"details", "Each sketch is on its own plane (sketch on datum planes). Lofts take seconds and the reply may be a job. Reply: loft_index, bodies, boolean, body."}, - {"params", json::array({ - json{{"name", "profiles"}, {"type", "array"}, {"description", "sketch feature indices, in loft order"}}, - json{{"name", "ruled"}, {"type", "boolean"}, {"default", false}, {"description", "straight sections between the profiles instead of a smooth skin"}}, - json{{"name", "boolean"}, {"type", "string"}, {"enum", json::array({"new", "union", "subtract", "intersect"})}, {"default", "new"}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "the body a union, subtract or intersect works on; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A square-to-round transition 20 mm tall, the circle sketched on a datum plane", "calls": [ - {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 20}}, - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-10, -10, 10, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 6}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "loft", "args": {"profiles": [1, 2]}}]}])json")}}, - json{{"name", "thicken"}, {"ids", true}, {"summary", "Offset a face of a body by a wall thickness, producing a new thin solid body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - json{{"name", "face"}, {"type", "integer"}, {"description", "face id to thicken (query_topology)"}}, - json{{"name", "thickness"}, {"type", "number"}, {"unit", "mm"}, {"default", 2}, {"min", 0.01}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "A 2 mm skin grown from a plate's top face as a new body", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "thicken", "args": {"body": 0, "face": 5, "thickness": 2, "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "split"}, {"ids", true}, {"summary", "Split a body with a plane, as the Cut card does, moved by offset and turned over by flip; or along the plane of a face."}, - {"details", "The upper piece is on the plane's normal side; keeping both makes two bodies, the lower one right after the upper. Reply: split_index, bodies, body, upper_body and lower_body (the pieces kept), frame (a plane's, after offset and flip)."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - plane_param(nullptr, false), - json{{"name", "offset"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}, {"description", "with plane: along its normal"}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}, {"description", "with plane: turn it over, swapping upper and lower"}}, - json{{"name", "face"}, {"type", "integer"}, {"default", nullptr}, {"description", "instead of plane: a face id (query_topology) to split along"}}, - json{{"name", "face_body"}, {"type", "integer"}, {"default", -1}, {"description", "with face: the body that owns it; -1 = target"}}, - json{{"name", "keep_upper"},{"type", "boolean"}, {"default", true}}, - json{{"name", "keep_lower"},{"type", "boolean"}, {"default", true}}, - })}, - {"examples", examples(R"json([ - {"title": "A block cut in two at half its height", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "split", "args": {"plane": "XY", "offset": 5}}]}, - {"title": "A block cut at half its height, keeping only the lower half", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "split", "args": {"plane": "XY", "offset": 5, "keep_upper": false}}]}, - {"title": "A block split along the top face of a wider plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "extrude", "args": {"width": 30, "height": 30, "distance": 4, "boolean": "new"}}, - {"tool": "query_topology", "args": {"body": 1, "at_extreme": "+z"}}, - {"tool": "split", "args": {"body": 0, "face": 5, "face_body": 1, "generation": {"from_call": 2, "key": "generation"}}}]}])json")}}, - json{{"name", "project"}, {"ids", true}, {"summary", "Project edges of a solid onto a sketch plane, producing a new sketch feature."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "source_body"}, {"type", "integer"}, {"default", -1}, {"description", "body owning the edges; -1 = last body"}}, - json{{"name", "face"}, {"type", "integer"}, {"default", -1}, {"description", "global face id on the source body; when set, all its edges are projected"}}, - json{{"name", "edges"}, {"type", "array"}, {"default", json::array()}, {"description", "global edge ids to project; empty => project the face"}}, - plane_param("XY", false), - })}, - {"examples", examples(R"json([ - {"title": "A plate's top-face outline projected onto the XY plane as a new sketch", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "project", "args": {"source_body": 0, "face": 5, "plane": "XY", "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "Two top edges of a plate, meeting at a corner, projected onto the XY plane", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z", "adjacency": true}}, - {"tool": "project", "args": {"source_body": 0, "edges": [3, 6], "plane": "XY", "generation": {"from_call": 1, "key": "generation"}}}]}])json")}}, - json{{"name", "delete_face"}, {"ids", true}, {"summary", "Remove faces from a solid, healing the gap via OCCT defeaturing."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - json{{"name", "faces"}, {"type", "array"}, {"description", "global face ids to delete"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's bore filled in by deleting its cylindrical face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["cylindrical"]}}, - {"tool": "delete_face", "args": {"body": 0, "faces": [6], "generation": {"from_call": 2, "key": "generation"}}}]}])json")}}, - json{{"name", "bridge"}, {"summary", "Build a cubic-Bezier G1 bridge (BSpline) between two sketch-entity endpoints within a sketch feature."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "sketch feature index"}}, - json{{"name", "ent_a"}, {"type", "integer"}, {"description", "first entity index within the sketch"}}, - json{{"name", "end_a"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 1}, {"description", "0 = start/p0 side, 1 = end/p1 side"}}, - json{{"name", "ent_b"}, {"type", "integer"}, {"description", "second entity index within the sketch"}}, - json{{"name", "end_b"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 0}, {"description", "0 = start/p0 side, 1 = end/p1 side"}}, - })}, - {"examples", examples(R"json([ - {"title": "A smooth curve joining the facing ends of two lines in a committed sketch", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [-20, 0], "p1": [-5, 0]}, {"type": "line", "p0": [5, 10], "p1": [20, 10]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "bridge", "args": {"sketch": 0, "ent_a": 0, "end_a": 1, "ent_b": 1, "end_b": 0}}]}])json")}}, - json{{"name", "rib"}, {"summary", "Grow a thin rib wall (stiffener) from an open Line sketch entity, fused to a body."}, - {"details", "The wall is centred on the line in the sketch plane, thickness wide, and grows depth along the sketch plane's normal."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "sketch feature index holding the open line"}}, - json{{"name", "entity"}, {"type", "integer"}, {"description", "entity index of the open Line within the sketch"}}, - json{{"name", "thickness"}, {"type", "number"}, {"unit", "mm"}, {"default", 2}, {"min", 0.01}}, - json{{"name", "depth"}, {"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "target body; omit for the last body"}}, - })}, - {"examples", examples(R"json([ - {"title": "A 2 mm rib 8 mm tall across a plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 40, "height": 20, "distance": 3}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "sketch_begin", "args": {"plane": {"body": 0, "face": 5}, "generation": {"from_call": 1, "key": "generation"}}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [-15, 0], "p1": [15, 0]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "rib", "args": {"sketch": 2, "entity": 0, "thickness": 2, "depth": 8}}]}])json")}}, - json{{"name", "surface_extrude"}, {"summary", "Extrude a sketch wire with no end caps -> an open sheet body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "sketch feature index"}}, - json{{"name", "distance"},{"type", "number"}, {"unit", "mm"}, {"default", 10}, {"min", 0.01}}, - })}, - {"examples", examples(R"json([ - {"title": "A 30 mm line extruded 10 mm into a flat sheet", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [-15, 0], "p1": [15, 0]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_extrude", "args": {"sketch": 0, "distance": 10}}]}, - {"title": "A circle extruded 20 mm into an open tube, with no end caps", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 10}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_extrude", "args": {"sketch": 0, "distance": 20}}]}])json")}}, - json{{"name", "surface_revolve"}, {"summary", "Revolve a sketch wire with no caps -> an open sheet body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "sketch feature index"}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 360}}, - json{{"name", "axis"}, {"type", "integer"}, {"enum", json::array({0, 1})}, {"default", 0}, {"description", "the sketch plane's X (0) or Y (1) axis through its origin"}}, - })}, - {"examples", examples(R"json([ - {"title": "A cylinder's wall: a line 10 mm out from the XZ plane's vertical axis, turned a full circle", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XZ"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [10, 0], "p1": [10, 20]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_revolve", "args": {"sketch": 0, "axis": 1}}]}, - {"title": "Half a truncated cone's wall: a sloping line turned 180 degrees about the XZ plane's vertical axis", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XZ"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [5, 0], "p1": [15, 20]}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_revolve", "args": {"sketch": 0, "axis": 1, "angle": 180}}]}])json")}}, - json{{"name", "mate"}, {"summary", "Mate two bodies: transform the moving body (cs_b) so its connector lands on the fixed one (cs_a)."}, - {"details", "kind: 0=Fastened, 1=Planar, 2=Revolute, 3=Slider, 4=Cylindrical."}, - {"params", json::array({ - json{{"name", "kind"}, {"type", "integer"}, {"default", 0}, {"description", "0=Fastened (rigid), 1=Planar (normal only), 2=Revolute (free rotation about axis), 3=Slider (free translation along axis), 4=Cylindrical (free rotation+translation)"}}, - json{{"name", "cs_a"}, {"type", "integer"}, {"description", "feature index of the fixed CoordSys (mate connector A)"}}, - json{{"name", "cs_b"}, {"type", "integer"}, {"description", "feature index of the CoordSys on the body that moves"}}, - json{{"name", "offset"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "deg"}, {"default", 0}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "A block stood on a plate: its bottom-face connector fastened, turned over, to the plate's top-face one", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "extrude", "args": {"profile": [[30, -5], [40, -5], [40, 5], [30, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "coordsys", "args": {"type": "face_and_direction", "body": 0, "face": 5, "generation": {"from_call": 2, "key": "generation"}}}, - {"tool": "query_topology", "args": {"body": 1, "at_extreme": "-z"}}, - {"tool": "coordsys", "args": {"type": "face_and_direction", "body": 1, "face": 4, "generation": {"from_call": 4, "key": "generation"}}}, - {"tool": "mate", "args": {"cs_a": 4, "cs_b": 5, "kind": 0, "flip": true}}]}])json")}}, - json{{"name", "check_interference"}, {"summary", "Solid bodies that overlap, as {body_a, body_b, volume}."}, - {"details", "Read-only; bodies that merely touch enclose no volume and are not reported."}, - {"params", json::array({ - json{{"name", "min_volume"}, {"type", "number"}, {"unit", "mm^3"}, {"default", 1e-6}, {"description", "overlap volume above which a pair counts as interfering"}}, - })}, - {"examples", examples(R"json([ - {"title": "A post standing in a block: the two overlap", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "extrude", "args": {"width": 10, "height": 10, "distance": 20, "boolean": "new"}}, - {"tool": "check_interference", "args": {}}]}])json")}}, - json{{"name", "query_topology"}, {"ids", true}, {"summary", "A body's faces and edges, with their kinds and geometry, narrowed by face and edge filters."}, - {"details", "Faces give kind, area, centroid, normal, and a cylinder's, cone's, sphere's or torus's numbers; edges give kind, length, ends, a circle's centre and radius. Face filters (kinds, direction, at_extreme) and edge filters (edge_kinds, direction, convex) narrow their own list; when filters are given, a list none of its filters names is empty, or with adjacency holds the neighbours of the other list. Reply: face_count and edge_count of the body, faces_total and edges_total after filtering, next_offset while a page has more, generation."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", 0}}, - json{{"name", "kinds"}, {"type", "array"}, {"default", nullptr}, {"description", "face kinds to list: planar, cylindrical, conical, spherical, toroidal, bezier, bspline, revolution, extrusion, offset, other"}}, - json{{"name", "edge_kinds"}, {"type", "array"}, {"default", nullptr}, {"description", "edge kinds to list: line, circle, ellipse, bspline, bezier, other"}}, - json{{"name", "direction"}, {"type", "array"}, {"default", nullptr}, {"description", "[x, y, z]: planar faces whose outward normal points this way, and line edges along it either way, within 1 degree"}}, - json{{"name", "at_extreme"}, {"type", "string"}, {"enum", json::array({"+x", "-x", "+y", "-y", "+z", "-z"})}, {"default", nullptr}, {"description", "faces whose centroid lies on that side of the body's bounding box, e.g. +z for the top face"}}, - json{{"name", "convex"}, {"type", "boolean"}, {"default", nullptr}, {"description", "edges where two faces meet in an outside (true) or inside (false) corner; implies adjacency"}}, - json{{"name", "adjacency"}, {"type", "boolean"}, {"default", false}, {"description", "faces list their edges; edges list their faces (one for a seam) and say convex true or false, or tangent where the faces meet smoothly"}}, - json{{"name", "limit"}, {"type", "integer"}, {"default", nullptr}, {"min", 1}, {"description", "page size of both lists; omit for all"}}, - json{{"name", "offset"}, {"type", "integer"}, {"default", 0}}, - })}, - {"examples", examples(R"json([ - {"title": "Every face and edge of a 20 x 20 x 5 mm plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0}}]}, - {"title": "A plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}]}, - {"title": "A plate's vertical outside corners, the edges a fillet rounds", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "edge_kinds": ["line"], "direction": [0, 0, 1], "convex": true}}]}])json")}}, - json{{"name", "measure"}, {"ids", true}, {"summary", "Measure two refs, on one body or two: distance, closest points, angle and the gap between parallel faces."}, - {"details", "distance is between their representative points (a face's centroid, an edge's middle, an axis's middle); min_distance comes with closest_a and closest_b; angle_deg when both have a direction; parallel_gap across two parallel planar faces."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", 0}, {"description", "the body of a ref that names none"}}, - json{{"name", "a"}, {"type", "object"}, {"description", "{\"face\": f}, {\"edge\": e} or {\"point\": [x, y, z]}, with an optional \"body\"; {\"face\": f, \"axis\": true} is a cylindrical face's axis over its length"}}, - json{{"name", "b"}, {"type", "object"}, {"description", "as a"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's thickness, between its top and bottom faces", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "kinds": ["planar"]}}, - {"tool": "measure", "args": {"body": 0, "a": {"face": 5}, "b": {"face": 4}, - "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "The 10 mm gap between two blocks' facing sides", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, - {"tool": "extrude", "args": {"profile": [[20, -5], [30, -5], [30, 5], [20, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "query_topology", "args": {"body": 0, "direction": [1, 0, 0]}}, - {"tool": "query_topology", "args": {"body": 1, "direction": [-1, 0, 0]}}, - {"tool": "measure", "args": {"a": {"body": 0, "face": 1}, "b": {"body": 1, "face": 3}, - "generation": {"from_call": 3, "key": "generation"}}}]}])json")}}, - json{{"name", "mass_properties"}, {"summary", "Volume / surface area / centre of mass / inertia tensor of a body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", 0}}, - })}, - {"examples", examples(R"json([ - {"title": "The volume and centre of mass of a 20 x 20 x 5 mm plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "mass_properties", "args": {"body": 0}}]}])json")}}, - json{{"name", "slice_body"}, {"ids", true}, {"summary", "Cross-section of a body by a base plane at an offset (sections-as-evidence)."}, - {"details", "Returns ordered world contours, each flagged closed/open."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", 0}}, - json{{"name", "plane"}, {"type", "string"}, {"enum", json::array({"XY", "XZ", "YZ"})}, {"default", "XY"}}, - json{{"name", "offset"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's cross-section halfway up", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "slice_body", "args": {"body": 0, "plane": "XY", "offset": 2.5}}]}, - {"title": "The two contours through a plate with a bore", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "extrude", "args": {"sketch": 0, "distance": 5}}, - {"tool": "slice_body", "args": {"body": 0, "plane": "XY", "offset": 2.5}}]}])json")}}, - json{{"name", "import_step"}, {"summary", "Import a STEP file as native B-rep bodies (the reference part to measure)."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "path"}, {"type", "string"}, {"description", "absolute path"}}, - })}, - {"examples", examples(R"json([ - {"title": "A part read from a STEP file as a body", "needs": "a STEP file of the part", "calls": [ - {"tool": "import_step", "args": {"path": "/path/to/part.step"}}]}])json")}}, - json{{"name", "import_mesh"}, {"summary", "Convert a triangle mesh (STL/OBJ) into an editable B-rep body."}, - {"details", "Reports whether the result is a real solid or an open shell, and why."}, - {"params", json::array({ - json{{"name", "path"}, {"type", "string"}, {"description", "absolute path"}}, - json{{"name", "tolerance"}, {"type", "number"}, {"default", 0.01}}, - json{{"name", "merge_angle_deg"}, {"type", "number"}, {"default", 5.0}}, - })}, - {"examples", examples(R"json([ - {"title": "An STL mesh turned into an editable body", "needs": "an STL or OBJ mesh file", "calls": [ - {"tool": "import_mesh", "args": {"path": "/path/to/part.stl"}}]}])json")}}, - json{{"name", "commit"}, {"summary", "Commit to Plate: send the visible bodies to Prepare at their Move-gizmo positions and show Prepare."}, - {"details", "It is one Prepare undo step. A lone body is sent even when hidden. A body named in the Bodies list or with body_set names its object or part. Reply: objects (list_objects index after replace, name, parts: how many), bodies_sent, bodies_hidden, replaced."}, - {"params", json::array({ - json{{"name", "mode"}, {"type", "string"}, {"enum", json::array({"assembly", "bodies"})}, {"default", ""}, {"description", "assembly: one object with a part per body; bodies: an object per body. Default: the Commit button's mode, which this leaves as it is."}}, - json{{"name", "replace"}, {"type", "array"}, {"default", json::array()}, {"description", "list_objects indices to delete in the same undo step, such as an earlier commit. Their settings, modifiers and paint go with them."}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate sent to Prepare as one object", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "commit", "args": {}}]}, - {"title": "Two bodies sent to Prepare as an object each", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "extrude", "args": {"profile": [[20, -5], [30, -5], [30, 5], [20, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "commit", "args": {"mode": "bodies"}}]}])json")}}, - json{{"name", "new_design"}, {"summary", "New Design: erase every feature, body and variable and the Design undo history."}, - {"details", "Committed objects stay on the plate. Reply: cleared {features, bodies, variables}."}, - {"params", json::array({ - json{{"name", "discard_changes"}, {"type", "boolean"}, {"default", false}, {"description", "needed when the design is not empty"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's design erased", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "new_design", "args": {"discard_changes": true}}]}, - {"title": "An empty design started over, which needs no discard_changes", "calls": [ - {"tool": "new_design", "args": {}}]}])json")}}, - json{{"name", "export_step"}, {"summary", "Export STEP: write every body to a file as native B-rep, at its Move-gizmo position."}, - {"details", "Reply: path, bytes, bodies, moved_bodies."}, - {"params", json::array({ - json{{"name", "path"}, {"type", "string"}, {"description", "absolute path; its directory must exist"}}, - json{{"name", "overwrite"}, {"type", "boolean"}, {"default", false}, {"description", "replace an existing file"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate written to a STEP file", "needs": "a folder to write the STEP file in", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "export_step", "args": {"path": "/path/to/part.step"}}]}])json")}}, - json{{"name", "undo"}, {"summary", "Edit > Undo in the Design tab: take back the last Design change, or in a sketch session the last drawn shape."}, - {"details", "A change to the Design history is a feature added, edited, deleted, moved, shown or hidden, or renamed, or a variable changed. run_action undo undoes Prepare's history instead. Reply: scope (design or sketch), undo_depth, redo_depth, features, bodies; entities in a sketch."}, - {"params", json::array()}, - {"examples", examples(R"json([ - {"title": "Take back an extrude, its sketch with it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "undo", "args": {}}]}, - {"title": "Take back the last shape drawn in a sketch", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "undo", "args": {}}]}])json")}}, - json{{"name", "redo"}, {"summary", "Edit > Redo in the Design tab: put back what undo took back, until the next change."}, - {"details", "Reply as undo's."}, - {"params", json::array()}, - {"examples", examples(R"json([ - {"title": "Put back an extrude undo took back", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "undo", "args": {}}, - {"tool": "redo", "args": {}}]}, - {"title": "Put back the shape undo took off a sketch", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "undo", "args": {}}, - {"tool": "redo", "args": {}}]}])json")}}, - json{{"name", "feature_delete"}, {"summary", "Delete a feature as its tree row's Delete does; deleting a sketch also deletes the features built on it."}, - {"details", "One undo step. Later indices shift. Reply: removed (how many features went), features, bodies."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's hole deleted", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "feature_delete", "args": {"feature": 2}}]}, - {"title": "A committed sketch deleted, and the extrude built on it with it", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "extrude", "args": {"sketch": 0, "distance": 5}}, - {"tool": "feature_delete", "args": {"feature": 0}}]}])json")}}, - json{{"name", "feature_move"}, {"summary", "Move a feature one place up or down the history, as Move up / Move down do."}, - {"details", "A feature cannot come before one it uses. One undo step. Reply: feature (its new index), from."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - json{{"name", "delta"}, {"type", "integer"}, {"enum", json::array({-1, 1})}, {"description", "-1 up, 1 down"}}, - })}, - {"examples", examples(R"json([ - {"title": "A datum plane moved up the history, above the extrude before it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 20}}, - {"tool": "feature_move", "args": {"feature": 2, "delta": -1}}]}])json")}}, - json{{"name", "feature_set_enabled"}, {"summary", "Show or hide (suppress) a feature as its row's eye does."}, - {"details", "A hidden feature is left out of the rebuild and bodies may renumber. One undo step, none when it already was. Reply: enabled, changed, bodies."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - json{{"name", "enabled"}, {"type", "boolean"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's hole hidden: the plate rebuilds without it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "feature_set_enabled", "args": {"feature": 2, "enabled": false}}]}, - {"title": "A hidden hole shown again", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "hole", "args": {"diameter": 5, "through": true}}, - {"tool": "feature_set_enabled", "args": {"feature": 2, "enabled": false}}, - {"tool": "feature_set_enabled", "args": {"feature": 2, "enabled": true}}]}])json")}}, - json{{"name", "feature_rename"}, {"summary", "Rename a feature as F2 on its row does."}, - {"details", "Its own undo step. Reply: name, changed."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - json{{"name", "name"}, {"type", "string"}, {"description", "trimmed; not empty"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's extrude renamed Base plate", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "feature_rename", "args": {"feature": 1, "name": "Base plate"}}]}])json")}}, - json{{"name", "body_set"}, {"summary", "Rename, colour or show/hide a body, as its Bodies row and the Color button do; give one or more."}, - {"details", "Not in the undo history. The name and colour are saved with the project and the name names its committed object; visibility is view state, and commit leaves hidden bodies out. Reply: name, color, visible."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"description", "body index (describe_scene)"}}, - json{{"name", "name"}, {"type", "string"}, {"default", nullptr}, {"description", "trimmed; not empty"}}, - json{{"name", "color"}, {"type", "string"}, {"default", nullptr}, {"description", "\"#RRGGBB\""}}, - json{{"name", "visible"}, {"type", "boolean"}, {"default", nullptr}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's body named Base and coloured blue", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "body_set", "args": {"body": 0, "name": "Base", "color": "#3366CC"}}]}, - {"title": "The second of two bodies hidden", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "extrude", "args": {"profile": [[20, -5], [30, -5], [30, 5], [20, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "body_set", "args": {"body": 1, "visible": false}}]}])json")}}, - json{{"name", "body_delete"}, {"summary", "Delete a body as its row's Delete does: the feature that made it goes, which can take other features and bodies with it."}, - {"details", "One undo step. Reply: deleted_feature {index, type, name}, removed, features, bodies."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"description", "body index (describe_scene)"}}, - })}, - {"examples", examples(R"json([ - {"title": "The second of two bodies deleted, with the extrude that made it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "extrude", "args": {"profile": [[20, -5], [30, -5], [30, 5], [20, 5]], "distance": 10, "boolean": "new"}}, - {"tool": "body_delete", "args": {"body": 1}}]}])json")}}, - json{{"name", "validate_against"}, {"summary", "Compare a body with a reference: volume, bbox, centroid and surface deviation (the RE acceptance metric)."}, - {"details", "The reference is {step:path|body:id}; the surface deviation is max/mean/rms in mm."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", 0}}, - json{{"name", "reference"}, {"type", "object"}}, - })}, - {"examples", examples(R"json([ - {"title": "A 5 mm plate against a 6 mm one", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 6, "boolean": "new"}}, - {"tool": "validate_against", "args": {"body": 0, "reference": {"body": 1}}}]}, - {"title": "A plate against a reference part's STEP file", "needs": "a STEP file of the reference part", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "validate_against", "args": {"body": 0, "reference": {"step": "/path/to/reference.step"}}}]}])json")}}, - json{{"name", "sketch_begin"}, {"ids", true}, {"summary", "Open a sketch session on a plane, as picking a plane or face for Sketch does."}, - {"details", "Sketch points are [x, y] in that plane's frame (mm), from its origin: modeling_origin for a base plane. Reply: frame."}, - {"params", json::array({ - plane_param("XY", false), - })}, - {"examples", examples(R"json([ - {"title": "A sketch on the XY plane", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}]}, - {"title": "A sketch on a plate's top face", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "query_topology", "args": {"body": 0, "at_extreme": "+z"}}, - {"tool": "sketch_begin", "args": {"plane": {"body": 0, "face": 5}, "generation": {"from_call": 1, "key": "generation"}}}]}, - {"title": "A sketch on a datum plane 20 mm above XY", "calls": [ - {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 20}}, - {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}]}])json")}}, - json{{"name", "sketch_commit"}, {"summary", "Commit the open sketch as a Sketch feature, as the sketch's Confirm does, and leave sketch mode."}, - {"details", "An empty sketch is refused and stays open. Reply: sketch_index, name, features (the new count) and its loops (closed_loops with the index extrude's loop takes, open_ends, defects, buildable)."}, - {"params", json::array()}, - {"examples", examples(R"json([ - {"title": "A rectangle around a circle, committed as a sketch of two loops", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "sketch_commit", "args": {}}]}])json")}}, - json{{"name", "sketch_cancel"}, {"summary", "Discard the open sketch and leave sketch mode."}, - {"details", ""}, - {"params", json::array()}, - {"examples", examples(R"json([ - {"title": "Discard a sketch with a rectangle drawn", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_cancel", "args": {}}]}])json")}}, - json{{"name", "sketch_add"}, {"summary", "Add entities or shapes to the open sketch: `entities` (a list), or one item's fields beside `type`, or `rect`."}, - {"details", "Entities: line {p0, p1}, circle {center, radius}, arc {center, radius, start_angle, end_angle}, point {p}. Shapes, built as their drawing tools build them: polygon {center, sides, radius (to a vertex) or across_flats, angle (of that vertex, or of the first edge's midpoint)}, slot {c0, c1, width}, ellipse {center, radius (semi-major), rminor, rotation}, ellipse_arc {the ellipse's fields, start_angle, end_angle: parametric, counter-clockwise}, spline {ctrl: 2 or more poles}. Each item of entities may carry its own construction: true; the top-level construction applies only to rect and to the single-type form. Points are [x, y] in the sketch plane (mm); angles are radians, or degrees as start_angle_deg and the like. A polygon is lines; its side count is not kept once committed. Reply: first_index, added, shapes [{first, count}] per item, entities, dof."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity or shape objects, each with a type"}}, - json{{"name", "type"}, {"type", "string"}, {"enum", json::array({"line", "arc", "circle", "point", "polygon", "slot", "ellipse", "ellipse_arc", "spline"})}, {"default", ""}, {"description", "one item, its fields beside it"}}, - json{{"name", "rect"}, {"type", "array"}, {"default", json::array()}, {"description", "[x0, y0, x1, y1]: a closed rectangle of four lines"}}, - json{{"name", "start_angle"}, {"type", "number"}, {"unit", "rad"}, {"default", 0}, {"description", "arc start, counter-clockwise from the plane's x axis"}}, - json{{"name", "end_angle"}, {"type", "number"}, {"unit", "rad"}, {"default", 0}}, - json{{"name", "construction"}, {"type", "boolean"}, {"default", false}, {"description", "for rect and the single-type form; an item of entities carries its own"}}, - })}, - {"examples", examples(R"json([ - {"title": "A 30 x 20 mm rectangle", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}]}, - {"title": "A hexagon 10 mm across flats inside a circle", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "circle", "center": [0, 0], "radius": 12}, - {"type": "polygon", "center": [0, 0], "sides": 6, "across_flats": 10}]}}]}, - {"title": "A quarter arc given in degrees, and a slot", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "arc", "center": [0, 0], "radius": 20, "start_angle_deg": 0, "end_angle_deg": 90}, - {"type": "slot", "c0": [-10, -20], "c1": [10, -20], "width": 6}]}}]}])json")}}, - json{{"name", "sketch_select"}, {"summary", "Select sketch entities by index; an empty list clears the selection."}, - {"details", "Reply: selected."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices"}}, - })}, - {"examples", examples(R"json([ - {"title": "Select a rectangle's two long sides", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_select", "args": {"entities": [0, 2]}}]}, - {"title": "Clear the selection", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_select", "args": {"entities": [0]}}, - {"tool": "sketch_select", "args": {"entities": []}}]}])json")}}, - json{{"name", "sketch_delete"}, {"summary", "Delete sketch entities."}, - {"details", "Reply: removed, entities."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices; omit for the selection"}}, - })}, - {"examples", examples(R"json([ - {"title": "Delete a rectangle's top side", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_delete", "args": {"entities": [2]}}]}, - {"title": "Delete the selected sides", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_select", "args": {"entities": [1, 3]}}, - {"tool": "sketch_delete", "args": {}}]}])json")}}, - json{{"name", "sketch_construction"}, {"summary", "Toggle construction on sketch entities."}, - {"details", "Reply: changed."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices; omit for the selection"}}, - })}, - {"examples", examples(R"json([ - {"title": "A centre line across a rectangle, made construction so it splits no loop", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, -10], "p1": [0, 10]}]}}, - {"tool": "sketch_construction", "args": {"entities": [4]}}]}])json")}}, - json{{"name", "sketch_offset"}, {"summary", "Add an offset copy of sketch lines, arcs and circles."}, - {"details", "Reply: first_index, added, dof."}, - {"params", json::array({ - json{{"name", "distance"}, {"type", "number"}, {"unit", "mm"}, {"description", "signed offset"}}, - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices; omit for the selection, else every entity"}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangle's 2 mm inner wall", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_offset", "args": {"distance": 2}}]}, - {"title": "A circle grown 2 mm by a negative offset", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 5}]}}, - {"tool": "sketch_offset", "args": {"distance": -2, "entities": [0]}}]}])json")}}, - json{{"name", "sketch_mirror"}, {"summary", "Add a mirrored copy of sketch entities about the line through axis_a and axis_b."}, - {"details", "Reply: first_index, added, dof."}, - {"params", json::array({ - json{{"name", "axis_a"}, {"type", "array"}, {"default", json::array({0, 0})}, {"description", "[x, y] in the sketch plane, mm"}}, - json{{"name", "axis_b"}, {"type", "array"}, {"default", json::array({0, 1})}, {"description", "[x, y] in the sketch plane, mm"}}, - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices; omit for the selection, else every entity"}}, - })}, - {"examples", examples(R"json([ - {"title": "A circle mirrored across the sketch's y axis", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [10, 0], "radius": 3}]}}, - {"tool": "sketch_mirror", "args": {"axis_a": [0, 0], "axis_b": [0, 1]}}]}])json")}}, - json{{"name", "sketch_describe"}, {"summary", "The open sketch, or a committed one: entities, constraint count and its loops."}, - {"details", "The loops are closed_loops {index, entities, holes, area}, open_ends, defects, buildable. The open sketch adds dof, the armed tool, the selection (entity indices) and selected_constraint, the index of the constraint picked by its badge or the Constraints list, null for none; a committed one adds its name and plane."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"default", nullptr}, {"description", "a committed Sketch feature's index; omit for the open sketch"}}, - })}, - {"examples", examples(R"json([ - {"title": "The open sketch: a rectangle with a circle inside it as a hole", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "sketch_describe", "args": {}}]}, - {"title": "A committed sketch's plane, entities and loop", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sketch_describe", "args": {"sketch": 0}}]}])json")}}, - json{{"name", "sketch_validate"}, {"summary", "The open sketch's loops (closed_loops, open_ends, defects, buildable) and dof."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "tolerance"}, {"type", "number"}, {"unit", "mm"}, {"default", 0.001}, {"description", "reported back"}}, - })}, - {"examples", examples(R"json([ - {"title": "A triangle with a 0.05 mm gap: two open ends, not buildable", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "line", "p0": [0, 0], "p1": [20, 0]}, - {"type": "line", "p0": [20, 0.05], "p1": [20, 10]}, - {"type": "line", "p0": [20, 10], "p1": [0, 0]}]}}, - {"tool": "sketch_validate", "args": {}}]}])json")}}, - json{{"name", "sketch_heal"}, {"summary", "Weld sketch endpoints that nearly meet and constrain them coincident, so loops are closed by construction."}, - {"details", "Reply: welded and the loops."}, - {"params", json::array({ - json{{"name", "tolerance"}, {"type", "number"}, {"unit", "mm"}, {"default", 0.001}}, - json{{"name", "ignore_construction"}, {"type", "boolean"}, {"default", true}}, - })}, - {"examples", examples(R"json([ - {"title": "Close a triangle's 0.05 mm gap", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "line", "p0": [0, 0], "p1": [20, 0]}, - {"type": "line", "p0": [20, 0.05], "p1": [20, 10]}, - {"type": "line", "p0": [20, 10], "p1": [0, 0]}]}}, - {"tool": "sketch_heal", "args": {"tolerance": 0.1}}]}])json")}}, - json{{"name", "sketch_set_value"}, {"summary", "Set the dimension of the selected sketch entities, as the value field does."}, - {"details", "A line's length, a circle's diameter, an arc's radius, or the angle or distance between two. Select them with sketch_select first. Reply: kind, before, value, dof and the loops."}, - {"params", json::array({ - json{{"name", "value"}, {"type", "number"}, {"description", "mm, or degrees for an angle"}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangle's bottom side made 40 mm long", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_select", "args": {"entities": [0]}}, - {"tool": "sketch_set_value", "args": {"value": 40}}]}, - {"title": "A circle's diameter set to 12 mm", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, - {"tool": "sketch_select", "args": {"entities": [0]}}, - {"tool": "sketch_set_value", "args": {"value": 12}}]}])json")}}, - json{{"name", "sketch_fillet"}, {"summary", "Round the corner of two lines of the open sketch, as the Fillet tool does."}, - {"details", "Both lines are cut back and joined by an arc of `radius`, bound coincident and tangent to them; constraints the sharp corner held are released. Reply: entity (the arc), lines, released_constraints, entities, constraints, dof, solve_ok."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "the two line indices; omit for the selection"}}, - json{{"name", "radius"}, {"type", "number"}, {"unit", "mm"}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangle's corner rounded to 3 mm", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_fillet", "args": {"entities": [0, 1], "radius": 3}}]}])json")}}, - json{{"name", "sketch_chamfer"}, {"summary", "Bevel the corner of two lines of the open sketch, as the Chamfer tool does."}, - {"details", "Both lines are cut back by `distance` from the corner and joined by a line bound coincident to them. Reply: entity (the new line), lines, released_constraints, entities, constraints, dof, solve_ok."}, - {"params", json::array({ - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "the two line indices; omit for the selection"}}, - json{{"name", "distance"}, {"type", "number"}, {"unit", "mm"}, {"description", "setback along each line"}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangle's corner bevelled 2 mm back", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_chamfer", "args": {"entities": [1, 2], "distance": 2}}]}])json")}}, - json{{"name", "sketch_trim"}, {"summary", "Trim or extend the open sketch's entity nearest `at`, as a Trim or Extend click there does."}, - {"details", "Trim: a line or an arc is cut back from its end nearer `at` to the first crossing with another entity beyond `at`; a circle loses the part between the crossings either side of `at` and becomes an arc. With extend, as an Extend click: the line's or arc's end nearer `at` runs out to the next entity. The entity's constraints are released. Reply: entity, geometry (its new fields), released_constraints, entities, dof."}, - {"params", json::array({ - json{{"name", "at"}, {"type", "array"}, {"description", "[x, y] in the sketch plane, mm: a point on the part to cut, or near the end to extend"}}, - json{{"name", "extend"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "tolerance"}, {"type", "number"}, {"unit", "mm"}, {"default", 0.05}, {"description", "how far from `at` the entity may be"}}, - })}, - {"examples", examples(R"json([ - {"title": "A line cut back to the line crossing it", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "line", "p0": [-10, 0], "p1": [10, 0]}, - {"type": "line", "p0": [0, -5], "p1": [0, 5]}]}}, - {"tool": "sketch_trim", "args": {"at": [5, 0]}}]}, - {"title": "A line extended down to the line below it", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "line", "p0": [-10, 0], "p1": [10, 0]}, - {"type": "line", "p0": [0, 3], "p1": [0, 8]}]}}, - {"tool": "sketch_trim", "args": {"at": [0, 3], "extend": true}}]}])json")}}, - json{{"name", "sketch_transform"}, {"summary", "Move, rotate, scale or array entities of the open sketch, as the transform tools' Confirm does."}, - {"details", "move {dx, dy}, rotate {angle, pivot} and scale {scale, pivot} change the entities and release the constraints that no longer hold. array {dx, dy, count} adds copies stepped by dx, dy; polar_array {pivot, angle, count} adds copies every angle/count about pivot (angle is the whole sweep, default 360 degrees). count includes the original, and each copy is bound to its source (equal length and parallel, or its radius). pivot defaults to the entities' centroid. Angles are radians, or degrees as angle_deg. Reply: moved and released_constraints, or first_index, added and bound; pivot; entities, dof."}, - {"params", json::array({ - json{{"name", "op"}, {"type", "string"}, {"enum", json::array({"move", "rotate", "scale", "array", "polar_array"})}}, - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "entity indices; omit for the selection"}}, - json{{"name", "dx"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "dy"}, {"type", "number"}, {"unit", "mm"}, {"default", 0}}, - json{{"name", "angle"}, {"type", "number"}, {"unit", "rad"}, {"default", nullptr}, {"description", "or angle_deg"}}, - json{{"name", "scale"}, {"type", "number"}, {"default", nullptr}}, - json{{"name", "count"}, {"type", "integer"}, {"default", nullptr}, {"min", 2}, {"max", 1000}}, - json{{"name", "pivot"}, {"type", "array"}, {"default", nullptr}, {"description", "[x, y] in the sketch plane, mm"}}, - })}, - {"examples", examples(R"json([ - {"title": "A circle moved 10 mm along x", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 3}]}}, - {"tool": "sketch_transform", "args": {"op": "move", "entities": [0], "dx": 10}}]}, - {"title": "Six holes on a 40 mm bolt circle", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [20, 0], "radius": 3}]}}, - {"tool": "sketch_transform", "args": {"op": "polar_array", "entities": [0], "pivot": [0, 0], "count": 6, "angle_deg": 360}}]}, - {"title": "A line turned 30 degrees about its start", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, 0], "p1": [20, 0]}]}}, - {"tool": "sketch_transform", "args": {"op": "rotate", "entities": [0], "angle_deg": 30, "pivot": [0, 0]}}]}])json")}}, - json{{"name", "sketch_constrain"}, {"summary", "Add a constraint to the open sketch, as a CONSTRAIN bar button does (sketch_set_value is the value field, V)."}, - {"details", "With `entities`, else the selection, the button's own rules choose the points, and a value it would ask for is `value` or the current one. With `refs` the references are taken as written, in sketch_constraints' form: {entity, role} for a point (role p0, p1 or center; entity also \"origin\") and {entity} for a whole entity (also \"x_axis\", \"y_axis\"). distance, lock_x, lock_y, point_on_line and point_on_object have no button and take refs. A constraint the sketch cannot solve with is rolled back and the call fails. Reply: added (indices), items, constraints, dof, solve_ok."}, - {"params", json::array({ - json{{"name", "type"}, {"type", "string"}, {"enum", json::array({"fix", "coincident", "horizontal", "vertical", "distance", "lock_x", "lock_y", "equal_length", "parallel", "perpendicular", "concentric", "tangent", "midpoint", "symmetric", "angle", "radius", "diameter", "point_on_line", "point_on_object", "equal_radius", "collinear", "distance_x", "distance_y", "symmetric_about_y", "symmetric_about_x", "equal"})}, {"description", "\"equal\" is the Equal button: equal length, or equal radius for two curves"}}, - json{{"name", "entities"}, {"type", "array"}, {"default", json::array()}, {"description", "1 to 3 entity indices; omit for the selection"}}, - json{{"name", "refs"}, {"type", "array"}, {"default", json::array()}, {"description", "[{entity, role?}], instead of entities"}}, - json{{"name", "value"}, {"type", "number"}, {"default", nullptr}, {"description", "mm, or degrees for an angle"}}, - })}, - {"examples", examples(R"json([ - {"title": "A sloping line made horizontal", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, 0], "p1": [10, 2]}]}}, - {"tool": "sketch_constrain", "args": {"type": "horizontal", "entities": [0]}}]}, - {"title": "Two circles given equal radii", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [ - {"type": "circle", "center": [0, 0], "radius": 4}, - {"type": "circle", "center": [15, 0], "radius": 6}]}}, - {"tool": "sketch_constrain", "args": {"type": "equal", "entities": [0, 1]}}]}, - {"title": "A line's ends held 25 mm apart, named by refs", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "line", "p0": [0, 0], "p1": [10, 2]}]}}, - {"tool": "sketch_constrain", "args": {"type": "distance", "value": 25, - "refs": [{"entity": 0, "role": "p0"}, {"entity": 0, "role": "p1"}]}}]}])json")}}, - json{{"name", "sketch_constraints"}, {"summary", "The constraints of the open sketch, or of a committed one: index, type, refs and value."}, - {"details", "A ref is {entity, role} for a point and {entity} for a whole entity; value is mm, or degrees for an angle. Reply: scope (live or committed), items, and dof and solve_ok for the open sketch."}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"default", nullptr}, {"description", "a committed Sketch feature's index; omit for the open sketch"}}, - })}, - {"examples", examples(R"json([ - {"title": "The coincident, horizontal and vertical constraints a drawn rectangle gets", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_constraints", "args": {}}]}, - {"title": "A committed sketch's constraints", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sketch_constraints", "args": {"sketch": 0}}]}])json")}}, - json{{"name", "sketch_unconstrain"}, {"summary", "Delete a constraint of the open sketch, as its row's delete button does; the constraints after it move down one index."}, - {"details", "Reply: removed, constraints, dof, solve_ok."}, - {"params", json::array({ - json{{"name", "index"}, {"type", "integer"}, {"description", "sketch_constraints' items[].index"}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangle's bottom side freed from horizontal", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_constraints", "args": {}}, - {"tool": "sketch_unconstrain", "args": {"index": 4}}]}])json")}}, - json{{"name", "list_verbs"}, {"summary", "The Design tab's right-click verbs, with id, name, key and whether each applies to the current selection."}, - {"details", "Each also says where the right-click menu lists it (row_name, then family, the submenu within the row, or null) and whether it opens a dialog. A row offering exactly one applicable verb lists it alone at the menu's top level."}, - {"params", json::array({ - json{{"name", "applicable_only"}, {"type", "boolean"}, {"default", false}}, - json{{"name", "sketch_mode"}, {"type", "boolean"}, {"default", nullptr}, {"description", "when given, only sketch-mode (true) or feature-mode (false) verbs"}}, - })}, - {"examples", examples(R"json([ - {"title": "The verbs that apply with nothing selected", "calls": [ - {"tool": "list_verbs", "args": {"applicable_only": true}}]}, - {"title": "The verbs an open sketch offers", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "list_verbs", "args": {"sketch_mode": true, "applicable_only": true}}]}])json")}}, - json{{"name", "run_verb"}, {"summary", "Fire a verb from list_verbs as its menu row or key does."}, - {"details", "It runs on the next event-loop turn, so the reply says only that it was dispatched; a verb that opens a card or dialog leaves it open."}, - {"params", json::array({ - json{{"name", "verb"}, {"type", "string"}, {"description", "verb id"}}, - })}, - {"examples", examples(R"json([ - {"title": "Sketch, as Shift+S fires it: with nothing picked, the Design tab offers the planes to sketch on", "calls": [ - {"tool": "run_verb", "args": {"verb": "sketch"}}]}])json")}}, - json{{"name", "set_variable"}, {"summary", "Set a design variable to an expression, or remove it with an empty expr."}, - {"details", "Feature fields bound with set_feature_expr follow it."}, - {"params", json::array({ - json{{"name", "name"}, {"type", "string"}}, - json{{"name", "expr"}, {"type", "string"}, {"description", "e.g. \"20\" or \"width / 2 + 3\"; \"\" removes the variable"}}, - })}, - {"examples", examples(R"json([ - {"title": "A variable w of 20", "calls": [ - {"tool": "set_variable", "args": {"name": "w", "expr": "20"}}]}, - {"title": "A variable worked out from another: h = w / 2 + 3, which is 13", "calls": [ - {"tool": "set_variable", "args": {"name": "w", "expr": "20"}}, - {"tool": "set_variable", "args": {"name": "h", "expr": "w / 2 + 3"}}]}, - {"title": "A variable removed with an empty expression", "calls": [ - {"tool": "set_variable", "args": {"name": "w", "expr": "20"}}, - {"tool": "set_variable", "args": {"name": "w", "expr": ""}}]}])json")}}, - json{{"name", "set_feature_expr"}, {"summary", "Bind a feature's numeric field to an expression over the design variables, or unbind it with an empty expr."}, - {"details", "Unbound, the field keeps its value."}, - {"params", json::array({ - json{{"name", "feature"}, {"type", "integer"}, {"description", "feature index (describe_scene)"}}, - json{{"name", "field"}, {"type", "string"}, {"description", "a numeric field of describe_feature's params, e.g. width, distance, hole_diameter, thread_diameter"}}, - json{{"name", "expr"}, {"type", "string"}, {"description", "\"\" removes the binding"}}, - })}, - {"examples", examples(R"json([ - {"title": "A plate's thickness bound to the variable t", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "set_variable", "args": {"name": "t", "expr": "8"}}, - {"tool": "set_feature_expr", "args": {"feature": 1, "field": "distance", "expr": "t"}}]}, - {"title": "A plate's thickness unbound, keeping the 8 mm the binding gave it", "calls": [ - {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, - {"tool": "set_variable", "args": {"name": "t", "expr": "8"}}, - {"tool": "set_feature_expr", "args": {"feature": 1, "field": "distance", "expr": "t"}}, - {"tool": "set_feature_expr", "args": {"feature": 1, "field": "distance", "expr": ""}}]}])json")}}, - json{{"name", "surface_loft"}, {"summary", "Skin two or more profile sketches with no end caps -> an open sheet body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "profiles"}, {"type", "array"}, {"description", "sketch feature indices, in order"}}, - json{{"name", "ruled"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "An open funnel skinned from a circle on XY to a wider one on a datum plane 20 mm up", "calls": [ - {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 20}}, - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 5}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 15}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_loft", "args": {"profiles": [1, 2]}}]}])json")}}, - json{{"name", "surface_fill"}, {"summary", "Fill a sketch's closed boundary with one smooth face -> a sheet body."}, - {"details", ""}, - {"params", json::array({ - json{{"name", "sketch"}, {"type", "integer"}, {"description", "sketch feature index"}}, - })}, - {"examples", examples(R"json([ - {"title": "A circle filled with a disc-shaped sheet", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 10}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_fill", "args": {"sketch": 0}}]}, - {"title": "A rectangle filled with a flat sheet", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_fill", "args": {"sketch": 0}}]}])json")}}, - json{{"name", "surface_offset"}, {"summary", "Offset a sheet body by a signed distance -> another sheet body."}, - {"details", "A positive offset moves each face along its normal, the one query_topology gives, and a negative one against it, so the side depends on how the sheet was made: an extruded circle's normal points inward."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "sheet body; omit for the last body"}}, - json{{"name", "offset"}, {"type", "number"}, {"unit", "mm"}, {"default", 1}}, - })}, - {"examples", examples(R"json([ - {"title": "A rectangular sheet copied 5 mm above itself", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_fill", "args": {"sketch": 0}}, - {"tool": "surface_offset", "args": {"offset": 5}}]}, - {"title": "An open tube of radius 10 mm offset -2 mm, against its inward normal, to one of radius 12 mm", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 10}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_extrude", "args": {"sketch": 0, "distance": 20}}, - {"tool": "surface_offset", "args": {"body": 0, "offset": -2}}]}])json")}}, - json{{"name", "thicken_surface"}, {"summary", "Thicken a whole sheet body into a solid."}, - {"details", "A sheet of several faces whose free rims close into planar loops (the walls of a box with no lids) is capped at them and grows inward, into the closed shape that makes, whatever flip says; one whose rim can't be capped is refused. A single face or a closed shell is offset face by face along each face's normal, the one query_topology gives, or against it with flip; a closed shell can fail to thicken this way."}, - {"params", json::array({ - json{{"name", "body"}, {"type", "integer"}, {"default", -1}, {"description", "sheet body; omit for the last body"}}, - json{{"name", "thickness"}, {"type", "number"}, {"unit", "mm"}, {"default", 2}, {"min", 0.01}}, - json{{"name", "flip"}, {"type", "boolean"}, {"default", false}}, - })}, - {"examples", examples(R"json([ - {"title": "A 30 x 20 mm sheet thickened into a 2 mm plate, a new body", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_fill", "args": {"sketch": 0}}, - {"tool": "thicken_surface", "args": {"thickness": 2}}]}, - {"title": "An open tube thickened 1.5 mm outward into a pipe: flip, as its normal points inward", "calls": [ - {"tool": "sketch_begin", "args": {"plane": "XY"}}, - {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 10}]}}, - {"tool": "sketch_commit", "args": {}}, - {"tool": "surface_extrude", "args": {"sketch": 0, "distance": 20}}, - {"tool": "thicken_surface", "args": {"body": 0, "thickness": 1.5, "flip": true}}]}])json")}}, - }); - for (json& row : rows) { - try { - row["examples"] = json::parse(row.at("examples").get<std::string>()); - } catch (const json::exception& e) { - throw std::runtime_error("the examples of the CAD tool " + row.value("name", std::string()) + " cannot be read: " + e.what()); - } - } - return rows; -} +// cad_note()'s text, given while the preference is off and while it is on but was off at startup. The +// catalog holds the Design commands only when the feature was on at startup, and the main window creates +// the Design page only then too (its panel is built on first use), so turning the feature on takes a restart. +const char* const kCadOffNote = "call_tool runs no Design command now: they need the CAD feature on in Preferences > " + "Features, and on when OrcaSlicer started. A person turns it on there if it is off, and " + "restarts OrcaSlicer."; json describe_scene(DesignPanel* panel) { @@ -1550,7 +241,7 @@ json describe_scene(DesignPanel* panel) {"bodies", std::move(bodies)}, {"error", doc.error}, // Pass this back as "generation" on any call that takes a face or edge id and the call - // is refused if the topology has moved on. See the stale-id guard in run_cad_tool(). + // is refused if the topology has moved on. See the stale-id guard in cad_gate(). {"generation", doc.topo_generation}, {"undo_depth", doc.undo_depth()}, {"redo_depth", doc.redo_depth()}, @@ -1558,6 +249,10 @@ json describe_scene(DesignPanel* panel) // the loops sketch_add's entities make. {"auto_close_loops", doc.auto_close_loops}, }; + // What the right-click menu would be built for: the selection's kind (an OfferSel) and its id in the + // atlas, which the entries' accepts name. + const int kind = panel->mcp_offer_selection_kind(); + out["selection"] = {{"kind", kind}, {"id", kDesignSelectionIds[kind]}}; if (!var_error.empty()) out["variables_error"] = var_error; if (!doc.mate_conflicts.empty()) { json conflicts = json::array(); @@ -1995,7 +690,7 @@ json action_chamfer(DesignPanel* panel, const json& params) {"bodies", int(doc.bodies.size())}, {"error", doc.error}}; } -// A hole CAD tool's reply: the feature, where it went (cad_hole_placement) and the frame of its plane. +// A hole command's reply: the feature, where it went (cad_hole_placement) and the frame of its plane. json hole_reply(json r, const json& placement, const SketchPlane& pl) { r.update(placement); @@ -2116,8 +811,8 @@ json action_pattern_on_curve(DesignPanel* panel, const json& params) { const int count = params.value("count", 3); if (count < 1) throw std::runtime_error("count must be >= 1"); - if (!params.contains("sketch")) throw std::runtime_error("pattern_on_curve needs 'sketch' (feature index)"); - if (!params.contains("entity")) throw std::runtime_error("pattern_on_curve needs 'entity' (entity index)"); + if (!params.contains("sketch")) throw std::runtime_error("pat_curve needs 'sketch' (feature index)"); + if (!params.contains("entity")) throw std::runtime_error("pat_curve needs 'entity' (entity index)"); const int sketch = params["sketch"].get<int>(); const int entity = params["entity"].get<int>(); CadDocument& doc = panel->mcp_doc(); @@ -2168,7 +863,7 @@ json action_rib(DesignPanel* panel, const json& params) json action_surface_extrude(DesignPanel* panel, const json& params) { - if (!params.contains("sketch")) throw std::runtime_error("surface_extrude needs 'sketch' (feature index)"); + if (!params.contains("sketch")) throw std::runtime_error("surf_extrude needs 'sketch' (feature index)"); CadDocument& doc = panel->mcp_doc(); int sketch = params["sketch"].get<int>(); double distance = params.value("distance", 10.0); @@ -2182,7 +877,7 @@ json action_surface_extrude(DesignPanel* panel, const json& params) json action_surface_revolve(DesignPanel* panel, const json& params) { - if (!params.contains("sketch")) throw std::runtime_error("surface_revolve needs 'sketch' (feature index)"); + if (!params.contains("sketch")) throw std::runtime_error("surf_revolve needs 'sketch' (feature index)"); CadDocument& doc = panel->mcp_doc(); int sketch = params["sketch"].get<int>(); double angle = params.value("angle", 360.0); @@ -2227,7 +922,7 @@ json action_surface_offset(DesignPanel* panel, const json& params) json action_surface_loft(DesignPanel* panel, const json& params) { if (!params.contains("profiles") || !params["profiles"].is_array()) - throw std::runtime_error("surface_loft needs 'profiles' (array of int feature indices)"); + throw std::runtime_error("surf_loft needs 'profiles' (array of int feature indices)"); CadDocument& doc = panel->mcp_doc(); std::vector<int> profiles; for (const json& j : params["profiles"]) profiles.push_back(j.get<int>()); @@ -2242,7 +937,7 @@ json action_surface_loft(DesignPanel* panel, const json& params) json action_surface_fill(DesignPanel* panel, const json& params) { - if (!params.contains("sketch")) throw std::runtime_error("surface_fill needs 'sketch' (feature index)"); + if (!params.contains("sketch")) throw std::runtime_error("surf_fill needs 'sketch' (feature index)"); CadDocument& doc = panel->mcp_doc(); int sketch = params["sketch"].get<int>(); doc.checkpoint(); @@ -2446,7 +1141,7 @@ json sketch_entity_to(const SketchEntity& e, int index) // --- A feature as its card shows it: describe_feature and set_feature ------------------------ -// Names in the call_cad_tool vocabulary, in enum order. +// Names in the Design commands' vocabulary, in enum order. const char* const kModes[] = {"new", "union", "subtract", "intersect"}; // BooleanMode const char* const kShapes[] = {"rectangle", "circle"}; // SketchShape const char* const kExtrudeEnds[] = {"blind", "symmetric", "two_sided", "through_all", "up_to_face", "up_to_vertex"}; @@ -2479,7 +1174,7 @@ template<size_t N> int enum_index(const std::string& key, const json& v, const c throw std::runtime_error(key + " must be one of " + list); } -// A constraint's value as call_cad_tool states it: an angle in degrees (the recipe holds radians), a +// A constraint's value as the Design commands state it: an angle in degrees (the recipe holds radians), a // length in mm. Null for the types that carry none. json constraint_value(SketchConstraintType t, double v) { @@ -2543,7 +1238,7 @@ json profile_constraint_json(const SketchConstraintDef& c, int index) } // A feature's card as data. `params` is what the card shows; `editable` the fields its Confirm -// writes, named as the CadFeature members (the names set_feature_expr binds); `ranges` the limits +// writes, named as the CadFeature members (the names edit_feature binds); `ranges` the limits // its spin controls set on the numeric ones; `refs` the structure the card keeps as it is (feature // and body indices, face and edge ids, which expire with every rebuild); `expr` the bindings. // describe_feature shows it and set_feature checks against it, so the two cannot disagree. @@ -3131,7 +1826,7 @@ json action_sketch_mirror(DesignPanel* panel, const json& params) return json{{"ok", true}, {"first_index", base}, {"added", int(out.size())}, {"dof", sketch_dof(t)}}; } -// The `sketch` a CAD tool reads or builds from: a Sketch feature, or a Project feature, whose +// The `sketch` a Design command reads or builds from: a Sketch feature, or a Project feature, whose // entities the kernel builds as a sketch's. int sketch_arg(const json& v, const CadDocument& doc) { @@ -3504,84 +2199,6 @@ json action_revolve(DesignPanel* panel, const json& params) return r; } -// Verbs whose handler opens a MODAL dialog. This matters more than it looks: a verb run inline -// would hold the call inside ShowModal() until a human dismisses the dialog, and every later call -// would wait behind it. Which is exactly the trap for a deck user: one button press and the app -// is modal, waiting for a mouse they may not be reaching for. -// -// So run_verb NEVER dispatches inline. The list here is only so list_verbs can label the keys -// that will want a mouse; re-derive it with -// grep -n ShowModal src/slic3r/GUI/CAD/DesignPanel.cpp -// and map each handler back to its action string in DesignOffer.hpp. -bool verb_is_modal(const char* id) -{ - static const char* kModal[] = { "sk_text", "sk_svg", "colour" }; - for (const char* m : kModal) - if (std::strcmp(m, id) == 0) return true; - return false; -} - -json action_list_verbs(DesignPanel* panel, const json& params) -{ - return cad_list_verbs(panel->mcp_offer_selection_kind(), params); -} - -json action_run_verb(DesignPanel* panel, const json& params) -{ - if (!params.contains("verb")) throw std::runtime_error("run_verb needs 'verb' (an offer verb id)"); - const std::string verb = params["verb"].get<std::string>(); - - // Scan the offer table BEFORE dispatching so the failure message can tell an unknown id from - // one that exists in the vocabulary but has no GUI path (action == nullptr). - bool known = false; - bool has_action = false; - const char* action = nullptr; - for (int i = 0; i < kOfferVerbCount; ++i) { - if (std::strcmp(kOfferVerbs[i].id, verb.c_str()) == 0) { - known = true; - has_action = (kOfferVerbs[i].action != nullptr); - action = kOfferVerbs[i].action; - break; - } - } - - if (!known) throw std::runtime_error("run_verb: unknown verb '" + verb + "'"); - if (!has_action) throw std::runtime_error("run_verb: '" + verb + "' has no GUI path yet"); - - // Whether the verb would be OFFERED for the current selection. Not a refusal: the GUI lets - // you press a tool's shortcut whatever is selected, and refusing here would make run_verb - // stricter than the keyboard for no reason. Reported so a caller can tell "did nothing - // because it did not apply" from "did nothing because it is broken". - const int kind = panel->mcp_offer_selection_kind(); - const uint32_t bit = offer_bit(OfferSel(kind)); - bool applies = false; - for (int i = 0; i < kOfferVerbCount; ++i) - if (std::strcmp(kOfferVerbs[i].id, verb.c_str()) == 0) { applies = (kOfferVerbs[i].accepts & bit) != 0; break; } - - // The rule is not "validate more", it is "run_verb should offer exactly what the GUI - // offers, no more and no less". A "btn:"/"fly:" verb is reachable in the GUI ONLY through - // the offer menu, which GREYS its row when it does not apply to the current selection — so - // a caller must not be able to fire it either. But a "key:" verb is reachable from the - // KEYBOARD whatever is selected, and the app permits that, so refusing it would make - // run_verb stricter than the keyboard for no reason. Refuse only the menu-only verbs. - if (!applies && action && - (std::strncmp(action, "btn:", 4) == 0 || std::strncmp(action, "fly:", 4) == 0)) { - throw std::runtime_error("run_verb: '" + verb + - "' does not apply to the current selection (selection_kind " + - std::to_string(kind) + ")"); - } - - // Dispatch on the NEXT turn of the event loop, never inline. See verb_is_modal above: a verb - // that opens a modal would otherwise hold this call inside ShowModal(). Deferring costs the - // ability to report the verb's outcome — which run_offer_action does not return anyway — and - // buys a call that no verb in the table can wedge. - wxGetApp().CallAfter([panel, verb]() { panel->mcp_run_verb(verb.c_str()); }); - - return json{{"ok", true}, {"verb", verb}, {"dispatched", true}, - {"applies", applies}, {"modal", verb_is_modal(verb.c_str())}, - {"selection_kind", kind}}; -} - json action_mirror(DesignPanel* panel, const json& params) { std::string m_str = params.value("mode", std::string("new")); @@ -3902,8 +2519,8 @@ json action_set_feature_expr(DesignPanel* panel, const json& params) { CadDocument& doc = panel->mcp_doc(); const int fi = feature_arg(params, doc); - if (!params.contains("field")) throw std::runtime_error("set_feature_expr needs 'field' name"); - if (!params.contains("expr")) throw std::runtime_error("set_feature_expr needs 'expr' string"); + if (!params.contains("field")) throw std::runtime_error("edit_feature needs 'field' name"); + if (!params.contains("expr")) throw std::runtime_error("edit_feature needs 'expr' string"); const std::string field = params["field"].get<std::string>(); const std::string expr = params["expr"].get<std::string>(); // A name the evaluator does not know would fail every later rebuild; the binding row refuses it too. @@ -3930,16 +2547,16 @@ json action_set_feature_expr(DesignPanel* panel, const json& params) // --- The Design history, the Feature tree and the Bodies list ---------------------------- // Edit > Undo / Redo with the Design tab shown: the Design history, or inside a sketch session the -// sketch's own, which takes off or puts back the last drawn shape. Prepare's history is -// run_action undo's. +// sketch's own, which takes off or puts back the last drawn shape. The project's history is undo's +// with history "project". json undo_redo(DesignPanel* panel, bool redo) { DesignCanvas* vp = panel->mcp_viewport(); const bool sketch = vp != nullptr && vp->is_sketching(); if (!panel->menu_can_undo_redo(redo)) { if (sketch) throw std::runtime_error(redo ? "Nothing to redo in the open sketch" : "Nothing to undo in the open sketch"); - throw std::runtime_error(redo ? "Nothing to redo in the Design history" - : "Nothing to undo in the Design history (run_action undo undoes Prepare's)"); + throw std::runtime_error(redo ? "Nothing to redo in the Design history (history \"project\" redoes the project's)" + : "Nothing to undo in the Design history (history \"project\" undoes the project's)"); } panel->menu_undo_redo(redo); if (sketch) return json{{"ok", true}, {"scope", "sketch"}, {"entities", vp->mcp_sketch_tool().entities().size()}}; @@ -4199,9 +2816,6 @@ json action_export_step(DesignPanel* panel, const json& params) // Each runs the sketch tool's own step for its button or gesture (DesignSketchTool's *_scripted // entry points), checks every argument first and throws, leaving the sketch as it was. -size_t edit_distance(const std::string& a, const std::string& b); // with the CAD tool lookup below -std::string lower(std::string s); - // SketchEntity::Type's names, as sketch_describe writes them. const char* const kEntityTypes[] = {"line", "arc", "circle", "point", "ellipse", "ellipse_arc", "spline"}; static_assert(std::size(kEntityTypes) == size_t(SketchEntity::Type::BSpline) + 1, "every entity type needs a name"); @@ -4525,16 +3139,18 @@ json sketch_transform(DesignSketchTool& t, const json& params) // CONSTRAIN bar's Equal (equal length, or equal radius for two curves). SketchConstraintType constraint_type_arg(const json& v) { - if (!v.is_string()) throw std::runtime_error("type must be a constraint type, such as \"parallel\" (describe_cad_tool sketch_constrain lists them)"); + if (!v.is_string()) + throw std::runtime_error("type must be a constraint type, such as \"parallel\" (search_tools {tool: \"sketch_constrain\"} lists them)"); const std::string s = v.get<std::string>(); if (s == "equal") return SketchConstraintType::EqualLength; for (size_t i = 0; i < std::size(kConstraintTypes); ++i) if (s == kConstraintTypes[i]) return SketchConstraintType(i); std::string close; for (const char* n : kConstraintTypes) - if (edit_distance(lower(s), n) <= 2 + s.size() / 4) close += std::string(close.empty() ? "" : ", ") + "\"" + n + "\""; + if (edit_distance(boost::algorithm::to_lower_copy(s), n) <= 2 + s.size() / 4) + close += std::string(close.empty() ? "" : ", ") + "\"" + n + "\""; throw std::runtime_error("unknown constraint type \"" + s + "\"" + (close.empty() ? "" : "; did you mean " + close) + - " (describe_cad_tool sketch_constrain lists them)"); + " (search_tools {tool: \"sketch_constrain\"} lists them)"); } // Why the CONSTRAIN bar refuses a pick, in ConstraintReject order: a code an agent can test and the @@ -4729,7 +3345,7 @@ json sketch_unconstrain(DesignSketchTool& t, const json& params) return r; } -// A CAD tool on the open sketch alone, then a repaint. +// A Design command on the open sketch alone, then a repaint. json on_open_sketch(DesignPanel* panel, const char* name, const json& params) { json r = cad_sketch_call(mcp_sketch(panel), name, params); @@ -4753,156 +3369,241 @@ json action_sketch_constraints(DesignPanel* panel, const json& params) // --- dispatcher --------------------------------------------------------------------- -// What mcp_busy() lets through. Read only looks, so it runs under anything but a rebuild. Sketch -// drives the live sketch session and Change edits the feature list or variables; both are refused -// under an open card, the Text dialog, Constrain mode or a body Move, and Change under a sketch -// session too, which is about to commit into the feature list. -enum class CadAccess { Read, Change, Sketch }; +} // namespace -struct CadTool -{ - const char* name; - CadAccess access; - bool ok_false; // the tool reports a rejected rebuild in its reply (ok false) instead of failing - json (*run)(DesignPanel* panel, const json& params); +// Every silent form, by the id of the Design table's entry whose tool block describes it: run_cad_tool() and +// register_cad_commands() read this, and the block gives its access. +const std::pair<const char*, CadRun> kSilentForms[] = { + {"describe_scene", [](DesignPanel* panel, const json&) { return describe_scene(panel); }}, + {"describe_feature", action_describe_feature}, + {"query_topology", query_topology}, + {"measure", measure}, + {"mass_props", mass_properties}, + {"slice_body", slice_body}, + {"validate_against", validate_against}, + {"interference", action_check_interference}, + {"sketch_describe", action_sketch_describe}, + {"sketch_validate", action_sketch_validate}, + {"sketch_constraints", action_sketch_constraints}, + {"import_step", import_step}, + {"import_mesh", import_mesh}, + {"extrude", action_extrude}, + {"revolve", action_revolve}, + {"fillet", action_fillet}, + {"chamfer", action_chamfer}, + {"hole", action_hole}, + {"hole_styled", action_hole_styled}, + {"hole_standard", action_hole_standard}, + {"boolean", action_boolean}, + {"pattern", action_pattern}, + {"pat_curve", action_pattern_on_curve}, + {"shell", action_shell}, + {"rib", action_rib}, + {"draft", action_draft}, + {"mirror", action_mirror}, + {"body_transform", action_transform}, + {"thicken", action_thicken}, + {"split", action_split}, + {"thread", action_thread}, + {"sweep", action_sweep}, + {"loft", action_loft}, + {"project", action_project}, + {"delete_face", action_delete_face}, + {"bridge", action_bridge}, + {"axis", action_axis}, + {"coordsys_v", action_coordsys}, + {"plane", action_plane}, + {"helix", action_helix}, + {"mate", action_mate}, + {"set_variable", action_set_variable}, + {"edit_feature", action_set_feature_expr}, + {"set_feature", action_set_feature}, + {"feature_delete", action_feature_delete}, + {"feature_move", action_feature_move}, + {"feature_set_enabled", action_feature_set_enabled}, + {"feature_rename", action_feature_rename}, + {"body_set", action_body_set}, + {"body_delete", action_body_delete}, + {"commit", action_commit}, + {"new_design", action_new_design}, + {"export_step", action_export_step}, + {"surf_extrude", action_surface_extrude}, + {"surf_revolve", action_surface_revolve}, + {"surf_loft", action_surface_loft}, + {"surf_fill", action_surface_fill}, + {"surf_offset", action_surface_offset}, + {"thicken_surf", action_thicken_surface}, + {"sketch_begin", action_sketch_begin}, + {"sketch_commit", action_sketch_commit}, + {"sketch_cancel", action_sketch_cancel}, + {"sketch_add", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_add", a); }}, + {"sketch_select", action_sketch_select}, + {"sketch_delete", action_sketch_delete}, + {"sketch_construction", action_sketch_construction}, + {"sketch_offset", action_sketch_offset}, + {"sketch_mirror", action_sketch_mirror}, + {"sketch_heal", action_sketch_heal}, + {"sketch_set_value", action_sketch_set_value}, + {"sketch_fillet", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_fillet", a); }}, + {"sketch_chamfer", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_chamfer", a); }}, + {"sketch_trim", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_trim", a); }}, + {"sketch_transform", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_transform", a); }}, + {"sketch_constrain", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_constrain", a); }}, + {"sketch_unconstrain", [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_unconstrain", a); }}, }; +const std::size_t kSilentFormCount = std::size(kSilentForms); -// Every CAD tool, declared once: run_cad_tool(), the busy gate and cad_tool_table() read this. -const CadTool kCadTools[] = { - {"describe_scene", CadAccess::Read, false, [](DesignPanel* panel, const json&) { return describe_scene(panel); }}, - {"describe_feature", CadAccess::Read, false, action_describe_feature}, - {"query_topology", CadAccess::Read, false, query_topology}, - {"measure", CadAccess::Read, false, measure}, - {"mass_properties", CadAccess::Read, false, mass_properties}, - {"slice_body", CadAccess::Read, false, slice_body}, - {"validate_against", CadAccess::Read, false, validate_against}, - {"check_interference", CadAccess::Read, false, action_check_interference}, - {"list_verbs", CadAccess::Read, false, action_list_verbs}, - {"sketch_describe", CadAccess::Read, false, action_sketch_describe}, - {"sketch_validate", CadAccess::Read, false, action_sketch_validate}, - {"sketch_constraints", CadAccess::Read, false, action_sketch_constraints}, - {"import_step", CadAccess::Change, true, import_step}, - {"import_mesh", CadAccess::Change, true, import_mesh}, - {"extrude", CadAccess::Change, false, action_extrude}, - {"revolve", CadAccess::Change, false, action_revolve}, - {"fillet", CadAccess::Change, true, action_fillet}, - {"chamfer", CadAccess::Change, true, action_chamfer}, - {"hole", CadAccess::Change, false, action_hole}, - {"hole_styled", CadAccess::Change, false, action_hole_styled}, - {"hole_standard", CadAccess::Change, false, action_hole_standard}, - {"boolean", CadAccess::Change, true, action_boolean}, - {"pattern", CadAccess::Change, true, action_pattern}, - {"pattern_on_curve", CadAccess::Change, true, action_pattern_on_curve}, - {"shell", CadAccess::Change, true, action_shell}, - {"rib", CadAccess::Change, true, action_rib}, - {"draft", CadAccess::Change, true, action_draft}, - {"mirror", CadAccess::Change, true, action_mirror}, - {"transform", CadAccess::Change, true, action_transform}, - {"thicken", CadAccess::Change, true, action_thicken}, - {"split", CadAccess::Change, false, action_split}, - {"thread", CadAccess::Change, false, action_thread}, - {"sweep", CadAccess::Change, false, action_sweep}, - {"loft", CadAccess::Change, false, action_loft}, - {"project", CadAccess::Change, true, action_project}, - {"delete_face", CadAccess::Change, true, action_delete_face}, - {"bridge", CadAccess::Change, true, action_bridge}, - {"axis", CadAccess::Change, true, action_axis}, - {"coordsys", CadAccess::Change, true, action_coordsys}, - {"plane", CadAccess::Change, false, action_plane}, - {"helix", CadAccess::Change, false, action_helix}, - {"mate", CadAccess::Change, true, action_mate}, - {"set_variable", CadAccess::Change, true, action_set_variable}, - {"set_feature_expr", CadAccess::Change, true, action_set_feature_expr}, - {"set_feature", CadAccess::Change, false, action_set_feature}, - {"feature_delete", CadAccess::Change, false, action_feature_delete}, - {"feature_move", CadAccess::Change, false, action_feature_move}, - {"feature_set_enabled", CadAccess::Change, false, action_feature_set_enabled}, - {"feature_rename", CadAccess::Change, false, action_feature_rename}, - {"body_set", CadAccess::Change, false, action_body_set}, - {"body_delete", CadAccess::Change, false, action_body_delete}, - {"commit", CadAccess::Change, false, action_commit}, - {"new_design", CadAccess::Change, false, action_new_design}, - {"export_step", CadAccess::Change, false, action_export_step}, - {"surface_extrude", CadAccess::Change, true, action_surface_extrude}, - {"surface_revolve", CadAccess::Change, true, action_surface_revolve}, - {"surface_loft", CadAccess::Change, true, action_surface_loft}, - {"surface_fill", CadAccess::Change, true, action_surface_fill}, - {"surface_offset", CadAccess::Change, true, action_surface_offset}, - {"thicken_surface", CadAccess::Change, true, action_thicken_surface}, - {"run_verb", CadAccess::Change, false, action_run_verb}, - // In a sketch session these take back or put back the last drawn shape, as Ctrl+Z does there. - {"undo", CadAccess::Sketch, false, [](DesignPanel* panel, const json&) { return undo_redo(panel, false); }}, - {"redo", CadAccess::Sketch, false, [](DesignPanel* panel, const json&) { return undo_redo(panel, true); }}, - {"sketch_begin", CadAccess::Sketch, false, action_sketch_begin}, - {"sketch_commit", CadAccess::Sketch, false, action_sketch_commit}, - {"sketch_cancel", CadAccess::Sketch, false, action_sketch_cancel}, - {"sketch_add", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_add", a); }}, - {"sketch_select", CadAccess::Sketch, false, action_sketch_select}, - {"sketch_delete", CadAccess::Sketch, false, action_sketch_delete}, - {"sketch_construction", CadAccess::Sketch, true, action_sketch_construction}, - {"sketch_offset", CadAccess::Sketch, false, action_sketch_offset}, - {"sketch_mirror", CadAccess::Sketch, false, action_sketch_mirror}, - {"sketch_heal", CadAccess::Sketch, false, action_sketch_heal}, - {"sketch_set_value", CadAccess::Sketch, false, action_sketch_set_value}, - {"sketch_fillet", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_fillet", a); }}, - {"sketch_chamfer", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_chamfer", a); }}, - {"sketch_trim", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_trim", a); }}, - {"sketch_transform", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_transform", a); }}, - {"sketch_constrain", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_constrain", a); }}, - {"sketch_unconstrain", CadAccess::Sketch, false, [](DesignPanel* p, const json& a) { return on_open_sketch(p, "sketch_unconstrain", a); }}, -}; +namespace { -const CadTool* find_cad_tool(const std::string& name) +// The silent form of entry `id`, or nullptr. +CadRun find_silent_form(const std::string& id) { - for (const CadTool& t : kCadTools) - if (name == t.name) return &t; + for (const auto& [key, run] : kSilentForms) + if (id == key) return run; return nullptr; } -size_t edit_distance(const std::string& a, const std::string& b) +// Runs `run`, a tool's handler, with its failure as the call's error: the handler's own refusal with its code, +// a kernel exception as "OCCT: ...", and any other as -32000. +json run_guarded(const std::function<json()>& run) { - std::vector<size_t> row(b.size() + 1); - for (size_t j = 0; j <= b.size(); ++j) row[j] = j; - for (size_t i = 1; i <= a.size(); ++i) { - size_t diag = row[0]; - row[0] = i; - for (size_t j = 1; j <= b.size(); ++j) { - const size_t up = row[j]; - row[j] = std::min({row[j] + 1, row[j - 1] + 1, diag + (a[i - 1] == b[j - 1] ? 0 : 1)}); - diag = up; - } + try { + return run(); + } catch (const ToolFailure&) { + throw; // a handler's own refusal, code included + } catch (const Standard_Failure& ex) { // derives from std::exception, so it comes first + throw ToolFailure(std::string("OCCT: ") + (*ex.what() ? ex.what() : "failure"), {{"code", -32000}}); + } catch (const std::exception& ex) { + throw ToolFailure(ex.what(), {{"code", -32000}}); } - return row[b.size()]; } -std::string lower(std::string s) +// Why a menu-only entry (a btn: or fly: action) is refused for a selection it does not accept. +// TRN Refusal of a Design tab tool picked for a selection its right-click menu row is greyed for (Constrain +// sketch with a face selected). +const char* const kDoesNotApply = L("This tool does not apply to what is selected"); +// Why an entry of the sketch's vocabulary is refused outside a sketch, and one of the model's inside one. +// TRN Refusal of a Design tab tool picked outside a sketch, when it is a sketch tool (a line, a rectangle). +const char* const kSketchTool = L("This tool works in a sketch: open a sketch first"); +// TRN Refusal of a Design tab tool picked while a sketch is open, when it works on the model (Extrude, Shell). +const char* const kModelTool = L("This tool works on the model: finish or cancel the sketch first"); + +// Entry `t`'s action, as a person's pick of its menu row or tile runs it: past cad_gate() with no access of its +// own, so that only a rebuild refuses it, as the Design tab's keys and menu are refused by nothing; each tool +// decides for itself what an open card means to it. The action runs in place, so a modal dialog it opens holds +// the call, which the core reports as blocked by that dialog. It is refused, as open_refusal() says, in the mode +// its row does not belong to, where the right-click menu does not offer it, and for a btn: or fly: action a +// selection the menu greys its row for. The reply claims nothing about what the action did, which may be to open +// a card, start a sketch tool, act at once or tell the person why it cannot: it says what the tab shows after it, +// its busy reason (a card, a dialog or a sketch now open) and its status line. +json open_tool(const DesignTool& t, const json& args) { - std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return char(std::tolower(c)); }); - return s; + DesignPanel* panel = cad_gate(CadAccess::None, args); + const int kind = panel->mcp_offer_selection_kind(); + const bool applies = (t.accepts & offer_bit(OfferSel(kind))) != 0; + if (std::optional<ToolFailure> refused = open_refusal(t, panel->mcp_sketch_map_applies(), kind)) + throw *refused; + const bool text_was_open = panel->mcp_text_dialog_open(); + panel->mcp_run_verb(t.id); + // A dialog the action opened held the call until it was answered, unless the action opened the Text dialog, + // which is modeless: the call returns with it open. A Text dialog open before the action is not its dialog. + const bool modal = t.modal && !(panel->mcp_text_dialog_open() && !text_was_open); + std::string why; + const bool busy = panel->mcp_busy(false, false, why); + return json{{"interactive", true}, + {"tool", t.id}, + {"applies", applies}, + {"modal", modal}, + {"selection_kind", kind}, + {"busy", busy ? json(why) : json()}, + {"status", into_u8(panel->mcp_status())}}; } -// "; did you mean a, b?" for a mistyped CAD tool name, or nothing when no name is close. -std::string close_cad_tools(const std::string& name) +// The command of the Design table's entry `t`, which has an action, a tool block or both. +NativeCommand design_command(const DesignTool& t) { - const std::string want = lower(name); - std::string close; - for (const CadTool& t : kCadTools) { - const std::string n = t.name; - if ((!want.empty() && (n.find(want) != std::string::npos || want.find(n) != std::string::npos)) - || edit_distance(n, want) <= 2 + want.size() / 4) - close += (close.empty() ? "" : ", ") + n; + const json doc = t.doc != nullptr ? json::parse(t.doc) : json(); + json schema; + if (doc.is_null()) + schema = {{"type", "object"}, {"properties", json::object()}, {"additionalProperties", false}}; + else + schema = cad_input_schema(doc); + // The person's form is the call with no arguments, which requires nothing (with_silent()), and runs in the + // entry's mode only. + if (t.action != nullptr && !doc.is_null()) { + schema = with_silent(std::move(schema)); + schema["properties"]["silent"]["description"] = std::string(kSilentNote) + " " + mode_note(t); } - return close.empty() ? std::string() : "; did you mean " + close + "?"; -} -const char* access_name(CadAccess access) -{ - return access == CadAccess::Read ? "read" : access == CadAccess::Sketch ? "sketch" : "change"; + const DesignTool* entry = &t; + NativeCommand c = cad_command(t.id, t.name, std::move(schema), [entry](const json& args) { + if (entry->action != nullptr && (entry->doc == nullptr || person_form(args))) + return open_tool(*entry, args); + return run_cad_tool(entry->id, silent_args(args)); + }); + c.in_palette = t.action != nullptr; + c.icon = t.icon != nullptr ? t.icon : ""; + if (doc.is_null()) { + c.description = std::string(t.hint) + ". " + kOpensToolNote + " " + mode_note(t); + return c; + } + if (find_silent_form(t.id) == nullptr) + throw std::logic_error(std::string("The Design table's entry ") + t.id + " has a tool block but no silent form"); + std::string description = doc.at("summary").get<std::string>(); + if (const std::string details = doc.at("details").get<std::string>(); !details.empty()) + description += ' ' + details; + if (t.ok_false) description += std::string(" ") + kFailureNote; + c.read_only = t.access == CadAccess::Read; + c.description = std::move(description); + c.examples = doc.at("examples"); + return c; } } // namespace -json run_cad_tool(const std::string& tool, const json& args) +const DesignTool* find_design_tool(const std::string& id) +{ + for (const DesignTool& t : kDesignTools) + if (id == t.id) return &t; + return nullptr; +} + +bool offered_in_mode(const DesignTool& t, bool sketching) { return t.sketch_mode == sketching; } + +std::vector<const NativeCommand*> design_tiles(const CommandCatalog& catalog, bool sketching, bool cad_on) +{ + std::vector<const NativeCommand*> tiles; + if (!cad_on) return tiles; + for (const NativeCommand& command : catalog.commands()) { + if (command.group != kDesignGroup || !command.in_palette) continue; + const DesignTool* entry = find_design_tool(command.key); + if (entry != nullptr && offered_in_mode(*entry, sketching)) tiles.push_back(&command); + } + return tiles; +} + +std::optional<ToolFailure> open_refusal(const DesignTool& t, bool sketching, int kind) +{ + if (!offered_in_mode(t, sketching)) + return ToolFailure(t.sketch_mode ? kSketchTool : kModelTool, + {{"code", -32000}, {"mode", t.sketch_mode ? "sketch" : "model"}}); + const std::string action(t.action); + const bool applies = (t.accepts & offer_bit(OfferSel(kind))) != 0; + if (applies || (action.rfind("btn:", 0) != 0 && action.rfind("fly:", 0) != 0)) + return std::nullopt; + // The row's own refusal is about the document (no body, no second sketch), which the menu shows only for + // a row that takes the selection; here the selection is the obstacle, so the reply names what to pick. + json accepts = json::array(); + for (int sel = 0; sel < int(OfferSel::Count); ++sel) + if ((t.accepts & offer_bit(OfferSel(sel))) != 0) + accepts.push_back(kDesignSelectionIds[sel]); + return ToolFailure(kDoesNotApply, {{"code", -32000}, + {"selection_kind", kind}, + {"selection", kDesignSelectionIds[kind]}, + {"accepts", std::move(accepts)}}); +} + +DesignPanel* cad_gate(CadAccess access, const json& args) { // The MCP server answers before the main window exists and while the app closes. ui_plater(); @@ -4919,18 +3620,11 @@ json run_cad_tool(const std::string& tool, const json& args) "OrcaSlicer (turning the CAD feature on takes effect after a restart)", {{"code", -32001}}); - const CadTool* t = find_cad_tool(tool); - if (t == nullptr) { - const std::string close = close_cad_tools(tool); - throw ToolFailure("Unknown CAD tool: " + tool + (close.empty() ? "." : close) + " list_cad_tools lists them.", - {{"code", -32601}}); - } - - // Only Read tools may run under a GUI editor or a sketch session they do not own. No tool may - // run during a rebuild, not even these: the rebuild's busy loop runs this call while the GUI's - // worker thread holds the document. Checked before hydrating, which writes it. + // Only Read commands, and the opening of a tool, may run under a GUI editor or a sketch session they do + // not own. None may run during a rebuild, not even these: the rebuild's busy loop runs this call while + // the GUI's worker thread holds the document. Checked before hydrating, which writes it. std::string why; - if (panel->mcp_busy(t->access == CadAccess::Read, t->access == CadAccess::Sketch, why)) + if (panel->mcp_busy(access == CadAccess::Read || access == CadAccess::None, access == CadAccess::Sketch, why)) throw ToolFailure("Design tab busy: " + why, {{"code", -32002}}); // A project opened without ever showing the Design tab has its recipe only in the Model; @@ -4950,10 +3644,11 @@ json run_cad_tool(const std::string& tool, const json& args) // So a caller may pass back the "generation" it got from describe_scene or query_topology, // and a mismatch is refused instead of silently obeyed. Optional by design: a call without it // is not checked, and supplying it is what buys the guarantee. One check here rather than one - // per handler, so a CAD tool added later cannot forget it. + // per handler, so a command added later cannot forget it. // - // The type is checked first because this runs outside the try below: a bare get<uint64_t>() - // on `"generation": "x"` would surface as an internal error instead of a parameter error. + // The type is checked first, as a caller that skips the schema (run_cad_tool() called directly) may + // pass any: a bare get<uint64_t>() on `"generation": "x"` would surface as an internal error instead + // of a parameter error. if (args.is_object() && args.contains("generation")) { if (!args["generation"].is_number_unsigned()) throw ToolFailure("generation must be an unsigned integer", {{"code", -32602}}); @@ -4966,143 +3661,113 @@ json run_cad_tool(const std::string& tool, const json& args) "edges, just not the ones you measured.", {{"code", -32010}}); } + return panel; +} - try { - return t->run(panel, args); - } catch (const ToolFailure&) { - throw; // a handler's own refusal, code included - } catch (const Standard_Failure& ex) { // derives from std::exception, so it comes first - throw ToolFailure(std::string("OCCT: ") + (*ex.what() ? ex.what() : "failure"), {{"code", -32000}}); - } catch (const std::exception& ex) { - throw ToolFailure(ex.what(), {{"code", -32000}}); +json run_cad_tool(const std::string& id, const json& args) +{ + const DesignTool* entry = find_design_tool(id); + const CadRun run = find_silent_form(id); + if (entry == nullptr || run == nullptr) + throw ToolFailure("No Design command runs silently as " + id, {{"code", -32601}}); + DesignPanel* panel = cad_gate(entry->access, args); + return run_guarded([&] { return run(panel, args); }); +} + +json cad_undo_redo(bool redo) +{ + DesignPanel* panel = cad_gate(CadAccess::Sketch, json::object()); + return run_guarded([&] { return undo_redo(panel, redo); }); +} + +json cad_input_schema(const json& block) +{ + json properties = json::object(); + json required = json::array(); + for (const json& param : block.at("params")) { + const std::string name = param.at("name").get<std::string>(); + const std::string type = param.at("type").get<std::string>(); + json property; + if (const std::size_t bar = type.find('|'); bar != std::string::npos) + property["type"] = json::array({type.substr(0, bar), type.substr(bar + 1)}); + else + property["type"] = type; + if (param.contains("min")) property["minimum"] = param["min"]; + if (param.contains("exclusive_min")) property["exclusiveMinimum"] = param["exclusive_min"]; + if (param.contains("max")) property["maximum"] = param["max"]; + if (param.contains("enum")) property["enum"] = param["enum"]; + if (param.contains("default")) property["default"] = param["default"]; + else required.push_back(name); + // A param whose default is null is one its function reads as left out when it is null (no limit, the open + // sketch), so a call may give null. One marked "nullable": false, whose function reads a null as given, + // keeps its type. + if (param.contains("default") && param["default"].is_null() && param.value("nullable", true)) { + if (!property["type"].is_array()) property["type"] = json::array({property["type"]}); + property["type"].push_back("null"); + if (property.contains("enum")) property["enum"].push_back(nullptr); + } + std::string description = param.value("description", std::string()); + if (const std::string unit = param.value("unit", std::string()); !unit.empty()) + description = description.empty() ? "In " + unit + "." : description + " (" + unit + ")"; + if (!description.empty()) property["description"] = std::move(description); + properties[name] = std::move(property); } + properties["generation"] = {{"type", "integer"}, {"minimum", 0}, {"description", kGenerationNote}}; + json schema{{"type", "object"}, {"properties", std::move(properties)}}; + if (!required.empty()) schema["required"] = std::move(required); + return schema; } -std::vector<std::string> cad_tool_names() +NativeCommand cad_command(std::string key, std::string title, json schema, std::function<json(const json& args)> fn) { - std::vector<std::string> out; - for (const CadTool& t : kCadTools) out.emplace_back(t.name); - return out; -} - -const json& cad_tool_table() -{ - // Built once: search_tools reads it on every search. A row whose tool kCadTools does not - // declare gets no access or failure; the unit tests compare the two tables. - static const json table = [] { - json rows = tool_rows(); - for (json& row : rows) { - if (const CadTool* t = find_cad_tool(row.at("name").get<std::string>())) { - row["access"] = access_name(t->access); - row["failure"] = t->ok_false ? "reply" : "error"; - if (t->ok_false) row["failure_note"] = kFailureNote; + NativeCommand c; + c.key = std::move(key); + c.title = std::move(title); + c.group = kDesignGroup; + c.input_schema = std::move(schema); + // A call with arguments that leaves only its generation out of the journal would replay with none, which + // for a command that also has a person's form opens the tool instead of running the silent form. + const bool takes_silent = c.input_schema.contains("properties") && c.input_schema["properties"].contains("silent"); + c.run = [fn = std::move(fn), takes_silent](const json& args, ToolContext& ctx) { + if (ctx.person()) { + try { + return ToolResult::ok({{"result", fn(args)}}); + } catch (const ToolFailure& refused) { + // What the person reads, in the UI's language where the text is a msgid (an entry's refusal). Looked + // up in the application's catalogue only, as the right-click menu's rows are (show_offer_menu()), so + // that a wxWidgets entry cannot answer for it. + throw ToolFailure(into_u8(wxGetTranslation(wxString::FromUTF8(refused.what()), SLIC3R_APP_KEY)), refused.details); } - for (json& p : row.at("params")) p["required"] = !p.contains("default"); } - return rows; - }(); - return table; -} - -json cad_list_tools(const std::string& query, const json& paging) -{ - const std::string q = lower(query); - auto has = [&q](const json& row, const char* key) { - return lower(row.at(key).get<std::string>()).find(q) != std::string::npos; + // `generation` guards ids within this session only: a replay rebuilds the same ids by replaying + // the history, but reaches another generation number, so a recorded one would refuse the replay. + // Journal the call without it. + json recorded = args; + if (recorded.is_object()) recorded.erase("generation"); + if (takes_silent && recorded.is_object() && recorded.empty() && !person_form(args)) + recorded["silent"] = true; + ctx.set_journal_args(std::move(recorded)); + json result = ctx.run_ui([&] { return fn(args); }); + settle(ctx); + return ToolResult::ok({{"result", std::move(result)}}); }; - json tools = json::array(); - for (const json& row : cad_tool_table()) - if (q.empty() || has(row, "name") || has(row, "summary") || has(row, "details")) - tools.push_back({{"name", row.at("name")}, {"access", row.value("access", json())}, {"summary", row.at("summary")}}); - // One page holds every CAD tool unless the call asks for less. - json reply = page(tools, paging, 200); - reply["ids"] = kIdsNote; - reply["use"] = "describe_cad_tool {tool} gives a tool's arguments and examples; call_cad_tool {tool, args} runs it"; - return reply; + return c; } -json cad_describe_tool(const json& tool) +void register_cad_commands(CommandCatalog& catalog) { - const char* const form = "tool takes a name or a list of names"; - std::vector<std::string> names; - if (tool.is_string()) { - names.push_back(tool.get<std::string>()); - } else if (tool.is_array() && !tool.empty()) { - for (const json& n : tool) { - if (!n.is_string()) throw std::runtime_error(form); - names.push_back(n.get<std::string>()); - } - } else { - throw std::runtime_error(form); - } - - const json& table = cad_tool_table(); - json rows = json::array(); - std::vector<std::string> described; - bool ids = false; - for (const std::string& name : names) { - if (name.empty()) throw std::runtime_error(form); - if (std::find(described.begin(), described.end(), name) != described.end()) continue; - const auto row = std::find_if(table.begin(), table.end(), [&name](const json& r) { return r.at("name") == name; }); - if (row == table.end()) throw std::runtime_error("Unknown CAD tool: " + name + close_cad_tools(name)); - described.push_back(name); - json out = *row; - ids = ids || out.value("ids", false); - out.erase("ids"); - rows.push_back(std::move(out)); - } - json reply{{"tools", std::move(rows)}}; - if (ids) reply["id_lifetime"] = kIdLifetime; - return reply; + for (const DesignTool& t : kDesignTools) + if (t.action != nullptr || t.doc != nullptr) + catalog.add(design_command(t)); } -json cad_feature_note(ToolContext& ctx) +json cad_note(const CommandCatalog& catalog) { - // Preferences may write AppConfig while this runs, so the preference is read on the UI thread. - try { - if (!ctx.observe_ui([] { return json(wxGetApp().is_enable_cad_feature()); }).get<bool>()) - return kCadOffNote; - } catch (const ToolFailure&) { - } - return nullptr; -} - -// Why list_verbs exists: the deck profile in VSD_n1_streamcontroller is built by parsing -// DesignPanel's key tables out of the SOURCE, so a verb without a keyboard shortcut is invisible -// to it. Serving the whole offer table lets the profile be generated from the running app -// instead, and lets a deck key name a verb rather than spend a letter. The row and family say -// where the offer menu puts the verb, so a client can find it there by its label path. -json cad_list_verbs(int kind, const json& params) -{ - const uint32_t bit = offer_bit(OfferSel(kind)); - const bool applicable_only = params.value("applicable_only", false); - const bool has_sketch_mode = params.contains("sketch_mode"); - const bool want_sketch_mode = has_sketch_mode && params["sketch_mode"].get<bool>(); - - json verbs = json::array(); - for (int i = 0; i < kOfferVerbCount; ++i) { - const OfferVerb& v = kOfferVerbs[i]; - const bool applies = (v.accepts & bit) != 0; - if (applicable_only && !applies) continue; - if (has_sketch_mode && v.sketch_mode != want_sketch_mode) continue; - // Verbs whose action is nullptr exist in the vocabulary but have no GUI path yet — report - // them with a null action rather than dropping them. - verbs.push_back(json{ - {"id", v.id}, - {"name", v.name}, - {"row", v.row}, - {"row_name", kOfferRowNames[v.row]}, - {"family", v.family ? json(v.family) : json(nullptr)}, - {"key", v.key ? json(v.key) : json(nullptr)}, - {"action", v.action ? json(v.action) : json(nullptr)}, - {"sketch_mode", v.sketch_mode}, - {"applies", applies}, - {"modal", verb_is_modal(v.id)}, // opening a dialog: this key will want a mouse - {"hint", v.hint ? json(v.hint) : json(nullptr)}, - }); - } - return json{{"ok", true}, {"selection_kind", kind}, {"count", verbs.size()}, - {"verbs", std::move(verbs)}}; + if (!wxGetApp().is_editor()) + return nullptr; + const std::vector<NativeCommand>& commands = catalog.commands(); + const bool registered = std::any_of(commands.begin(), commands.end(), [](const NativeCommand& c) { return c.group == kDesignGroup; }); + return registered && wxGetApp().is_enable_cad_feature() ? json() : json(kCadOffNote); } SketchPlane cad_resolve_plane(const json& plane, const CadDocument& doc, bool drill, int* face_body) @@ -5249,7 +3914,7 @@ void cad_apply_feature_fields(CadFeature& f, const json& fields) for (const auto& [bound, e] : f.expr) if (same_value(bound, key)) throw std::runtime_error(key + " is driven by the expression '" + e + "'; change it with set_variable, or " - "remove the binding with set_feature_expr {field: '" + bound + "', expr: ''}"); + "remove the binding with edit_feature {field: '" + bound + "', expr: ''}"); const auto range = ranges.find(key); if (range == ranges.end()) { set_card_choice(edited, key, v); @@ -5317,7 +3982,7 @@ json cad_sketch_call(DesignSketchTool& tool, const std::string& name, const json if (name == "sketch_constrain") return sketch_constrain(tool, p); if (name == "sketch_constraints") return sketch_constraints(tool, p); if (name == "sketch_unconstrain") return sketch_unconstrain(tool, p); - throw std::runtime_error(name + " is not a CAD tool of the open sketch"); + throw std::runtime_error(name + " is not a Design command of the open sketch"); } std::vector<SketchEntityConstraintDef> cad_constraint_defs(const json& params, const std::vector<SketchEntity>& ents, @@ -5984,13 +4649,13 @@ std::function<int(const std::string& name)> cad_thread(CadDocument& doc, const j spec = find_thread_standard(d.get<std::string>()); if (spec == nullptr) { // The same name in another case, else the names that start the other or are one edit away. - const std::string want = lower(d.get<std::string>()); + const std::string want = boost::algorithm::to_lower_copy(d.get<std::string>()); std::string close; for (const ThreadSpec& t : thread_standards()) - if (lower(t.name) == want) close = t.name; + if (boost::algorithm::to_lower_copy(std::string(t.name)) == want) close = t.name; if (close.empty() && !want.empty()) for (const ThreadSpec& t : thread_standards()) { - const std::string n = lower(t.name); + const std::string n = boost::algorithm::to_lower_copy(std::string(t.name)); if (n.rfind(want, 0) == 0 || want.rfind(n, 0) == 0 || edit_distance(n, want) <= 1) close += (close.empty() ? "" : ", ") + t.name; } @@ -6155,98 +4820,4 @@ std::function<int(const std::string& name)> cad_split(CadDocument& doc, const js }; } -namespace { - -// A reply of list_cad_tools or describe_cad_tool, with the CAD-off note when there is one. -ToolResult with_feature_note(json reply, ToolContext& ctx) -{ - json note = cad_feature_note(ctx); - if (!note.is_null()) reply["note"] = std::move(note); - return ToolResult::ok(std::move(reply)); -} - -// Refuses a name that is no CAD tool but a tool of `tools` or a Speed Dial action, saying where it -// runs: the names closest among the CAD tools would point the wrong way. -void refuse_other_catalog(const ToolRegistry& tools, const std::string& name) -{ - if (find_cad_tool(name) != nullptr) - return; - if (const std::string elsewhere = other_catalog_hint(tools, name, Catalog::Cad); !elsewhere.empty()) - throw ToolFailure("Unknown CAD tool: " + name + "; " + elsewhere, {{"code", -32601}}); -} - -} // namespace - -// The Design tab through MCP: two tools that read the CAD tool table, which needs no Design panel, -// so they answer with the CAD feature off too, and call_cad_tool, the one way to run a CAD tool. -void register_cad_tools(McpService& service) -{ - ToolRegistry& reg = service.registry(); - - reg.add(inspect_tool( - "list_cad_tools", L("List the CAD tools"), - "List the Design (CAD) tab's CAD tools, which call_cad_tool runs: each one's name, access (read; sketch, which " - "edits the open sketch; change, which changes the design) and one-line summary, grouped by what they do, and how " - "face and edge ids expire. query keeps the tools whose name, summary or details hold it, in any case. " - "describe_cad_tool {tool} gives a tool's arguments and examples. With the CAD feature off it still " - "answers, with a note on how a person turns the feature on.", - object_schema({{"query", prop("string", "Text to look for in each tool's name, summary and details, in any case. " - "Leave it out for every tool.")}, - {"limit", {{"type", "integer"}, {"minimum", 1}, {"maximum", 500}, {"description", "Default 200, which holds them all."}}}, - {"offset", {{"type", "integer"}, {"minimum", 0}}}}), - [](const json& args, ToolContext& ctx) { return with_feature_note(cad_list_tools(arg_string(args, "query"), args), ctx); })); - - reg.add(inspect_tool( - "describe_cad_tool", L("Describe a CAD tool"), - "Describe CAD tools for call_cad_tool: each one's summary, details, params (type, default, unit, limits and " - "whether it is required), failure (how a failed call shows: an error, or a reply whose ok is false) and examples. " - "Pass one name or a list of names (list_cad_tools lists them). When a described tool takes or gives face or edge " - "ids, id_lifetime says how long they stay valid. With the CAD feature off it still answers, with a note on how a " - "person turns the feature on.", - object_schema({{"tool", {{"type", json::array({"string", "array"})}, - {"items", {{"type", "string"}}}, - {"description", "A CAD tool's name (list_cad_tools), or a list of names."}}}}, - {"tool"}), - [&service](const json& args, ToolContext& ctx) { - const json tool = args.value("tool", json()); - for (const json& name : tool.is_array() ? tool : json::array({tool})) - if (name.is_string()) - refuse_other_catalog(service.registry(), name.get<std::string>()); - json reply; - try { - reply = cad_describe_tool(tool); - } catch (const std::runtime_error& e) { - throw ToolFailure(e.what()); - } - return with_feature_note(std::move(reply), ctx); - })); - - reg.add(mutate_tool( - "call_cad_tool", L("Call a CAD tool"), - "Run a CAD tool of the Design (CAD) tab: sketches, features, measurements and edits, undo and redo, and commit to " - "the plate. list_cad_tools lists the CAD tools, and describe_cad_tool {tool} gives one's arguments and examples. " - "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); its arguments go in args.")}, - {"args", {{"type", "object"}, {"description", "Its arguments (describe_cad_tool)."}}}}, - {"tool"}), - [&service](const json& args, ToolContext& ctx) { - const std::string tool = arg_string(args, "tool"); - const json tool_args = args.value("args", json::object()); - refuse_other_catalog(service.registry(), tool); - // `generation` guards ids within this session only: a replay rebuilds the same ids by - // replaying the history, but reaches another generation number, so a recorded one - // would refuse the replay. Journal the call without it. - if (tool_args.is_object() && tool_args.contains("generation")) { - json recorded = args; - recorded["args"].erase("generation"); - ctx.set_journal_args(std::move(recorded)); - } - json result = ctx.run_ui([&] { return run_cad_tool(tool, tool_args); }); - settle(ctx); - return ToolResult::ok({{"result", std::move(result)}}); - })); -} - }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsCad.hpp b/src/slic3r/GUI/Mcp/McpToolsCad.hpp index ba8d4d5e33..c2eed84f39 100644 --- a/src/slic3r/GUI/Mcp/McpToolsCad.hpp +++ b/src/slic3r/GUI/Mcp/McpToolsCad.hpp @@ -1,17 +1,29 @@ #pragma once -// The CAD tools behind the MCP server's call_cad_tool, which list_cad_tools and describe_cad_tool -// describe: the Design tab's sketches, features, measurements and edits. They run on the UI thread -// through the GUI's own CadDocument (no engine of their own). Every CAD tool is refused (-32002) -// during a rebuild, whose worker owns the document; one that changes the document is also refused -// while the Design tab is busy with it — an open feature card, a sketch session. Face and edge ids -// read at another generation are refused (-32010). The header exists for McpToolsApi.cpp, which -// reads the table for search_tools, and for the unit tests, which call the cad_* helpers directly. +// The Design tab's commands, one per entry of its table (kDesignTools, DesignOffer.hpp, generated from +// scripts/CAD/tool_atlas.json) but align: its tools, sketches, features, measurements and edits, which an +// agent finds with search_tools (group Design) and runs with call_tool, and a person picks as Speed Dial +// tiles while the Design tab is shown, those of the mode it is in. With no arguments, an entry with an +// action does what the right-click menu's row does, in the mode the row belongs to (open_refusal()); with +// arguments, or silent: true, an entry with a tool block runs that block's silent form. They run on the UI +// thread through the GUI's own CadDocument (no engine of their own), behind one gate (cad_gate()): every +// command is refused (-32002) during a rebuild, whose worker owns the document, and a silent form that +// changes the document also while the Design tab is busy with it, an open feature card or a sketch session; +// face and edge ids read at another generation are refused (-32010). The catalog holds the commands only +// while the CAD feature is on (NativeCommands::register_all_commands()). The unit tests call the cad_* +// helpers directly. + +#include "slic3r/GUI/CAD/DesignOffer.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/Mcp/McpTypes.hpp" #include <nlohmann/json.hpp> +#include <cstddef> #include <functional> +#include <optional> #include <string> +#include <utility> #include <vector> namespace Slic3r { @@ -26,55 +38,94 @@ class Model; namespace GUI { +class DesignPanel; class DesignSketchTool; namespace Mcp { -class ToolContext; +// A Design command's silent form: what it does given its arguments, on the panel cad_gate() returned. +using CadRun = nlohmann::json (*)(DesignPanel* panel, const nlohmann::json& params); -// Runs CAD tool `tool` with `args` and returns its result. It is refused while the main window is -// not up, in the G-code viewer (-32001), with the CAD feature off, and while the Design panel cannot -// be built (-32001); then for an unknown tool (-32601), a busy Design tab (-32002), and a -// `generation` that is not an unsigned integer (-32602) or not the model's (-32010). A tool that -// fails is -32000. Throws ToolFailure, whose details carry the code. UI thread only. -nlohmann::json run_cad_tool(const std::string& tool, const nlohmann::json& args); +// The silent forms, by the id of the table's entry whose tool block describes them: one per block. +extern const std::pair<const char*, CadRun> kSilentForms[]; +extern const std::size_t kSilentFormCount; -// The names of every CAD tool run_cad_tool() dispatches, in dispatch order. -std::vector<std::string> cad_tool_names(); +// A Design command: group Design, not listed, its function run on the UI thread. For a person's pick +// (ToolContext::person()) `fn` runs in place, and a refusal it throws is shown in the UI's language where its +// text is a msgid (an entry's refusal). For an automated call the journal records the arguments without +// `generation`, which numbers ids within this session only, and with `silent`, which it adds where `schema` +// takes it and the call gave nothing else, so that a replay runs the silent form too; then `fn` runs in one +// UI closure and the call settles. The reply is {"result": fn's value}; a ToolFailure is the call's error. +NativeCommand cad_command(std::string key, std::string title, nlohmann::json schema, + std::function<nlohmann::json(const nlohmann::json& args)> fn); -// The CAD tool table, built once, one row per CAD tool grouped by what the tools do: name, access -// (read, change or sketch), a summary of one sentence, details, params (each with `required`, true -// when it has no default), failure ("error", or "reply" with a failure_note for a tool that reports -// a rejected rebuild in its reply instead of failing), examples and, for a tool that takes or gives -// face or edge ids, "ids": true. Needs no Design panel and no UI thread; nor do the two readers below. -const nlohmann::json& cad_tool_table(); +// Adds the Design commands to `catalog`, one per entry of kDesignTools that has an action or a tool block: +// its id as the key, its name as the title, and its icon. An entry with an action is in the palette (its tile +// is materialised only while the Design tab is shown in the entry's mode, +// ActionRegistry::materialize_design_actions()). One with a block is read_only for Read access, and its +// description is the block's summary, details and, for a silent form that reports a rejected rebuild in its +// reply, how that shows; its examples are the block's and its schema cad_input_schema() of it, through +// with_silent() when the entry has an action too. One with an action only takes no arguments, and its +// description is its hint and what the call does. undo and redo are the shared commands of NativeCommands.cpp +// and not among them. +void register_cad_commands(CommandCatalog& catalog); -// list_cad_tools' reply: a page of {name, access, summary} in the table's order, shaped as every list -// is ({items, offset, total} with next_offset while more remain; `paging` holds the call's limit and -// offset), plus ids, how face and edge ids expire, and use. `query` keeps the tools whose name, summary -// or details hold it, in any case ("" keeps them all), and total counts the ones kept. -nlohmann::json cad_list_tools(const std::string& query, const nlohmann::json& paging = nlohmann::json::object()); +// The input schema of a tool block: an object whose properties are the block's params, a type written "a|b" +// as the list of both, min, exclusive_min and max as minimum, exclusiveMinimum and maximum, enum and default +// as written, and the unit joined to the description; a param with no default is required. `generation`, the +// generation the call's face and edge ids were read at, is an optional property of every one. Arguments it +// does not name are not refused: a tool may read more, such as a param in radians also in degrees under its +// name with _deg. +nlohmann::json cad_input_schema(const nlohmann::json& block); -// describe_cad_tool's reply for `tool`, a name or a list of names: {tools, id_lifetime?}, each -// named tool's row once, in the order asked, without the ids flag; id_lifetime when one of them -// takes or gives face or edge ids. Throws std::runtime_error naming close CAD tools for an unknown -// name, and for an empty name, an empty list, an item that is not a string or another type. -nlohmann::json cad_describe_tool(const nlohmann::json& tool); +// The checks every Design command passes before its function, in this order: the main window is up (not +// shutting down or still starting), the app is the editor and not the G-code viewer (-32001), the CAD +// feature is on, and the Design panel can be built (-32001); then the busy rules of `access` (-32002; with +// None only a rebuild's), the project's recipe loaded into an empty document +// (DesignPanel::hydrate_from_model()), as showing the tab would, and a `generation` in `args` that is not an +// unsigned integer (-32602) or not the model's (-32010). Returns the panel. Throws ToolFailure, whose details +// carry the code. UI thread only. +DesignPanel* cad_gate(CadAccess access, const nlohmann::json& args); -// What list_cad_tools and describe_cad_tool add as their `note`: how a person turns the CAD feature -// on, when the preference read on the UI thread through `ctx` says it is off; null when it is on, and -// when the UI does not answer, since the note is advice the reply can go without. From a tool's -// handler, off the UI thread. -nlohmann::json cad_feature_note(ToolContext& ctx); +// The Design table's entry `id`, or nullptr. +const DesignTool* find_design_tool(const std::string& id); -// list_verbs' reply for selection `kind` (an OfferSel): {ok, selection_kind, count, verbs}, the -// Design tab's offer table in its order, each verb with its id, name, row and row_name, family -// (its submenu within the row, or null), key, action, sketch_mode, applies (it accepts `kind`), -// modal and hint. params.applicable_only keeps the verbs that apply, and params.sketch_mode, when -// given, the sketch-mode (true) or feature-mode (false) ones. Needs no Design panel. -nlohmann::json cad_list_verbs(int kind, const nlohmann::json& params); +// Whether the Design tab offers entry `t` in the mode it is in, `sketching` being the right-click menu's +// DesignPanel::sketch_map_applies(): an entry of the sketch's vocabulary in a sketch, one of the model's +// outside it, as the menu offers them. A sketch in Constrain mode is a sketch to the menu, though the tab's keys +// there are the model's. Only then is its tile shown and its person's form run. +bool offered_in_mode(const DesignTool& t, bool sketching); -// The `plane` param shared by the plane-taking CAD tools: "XY", "XZ" or "YZ" through the modeling +// The commands of `catalog` that have a Speed Dial tile while the Design tab is shown in the mode `sketching` +// names (as offered_in_mode() takes it), in the catalog's order: those of group kDesignGroup with in_palette whose +// entry is offered in that mode. None while the CAD feature is off (`cad_on` false): the tab stays until a +// restart, but cad_gate() would refuse every pick of its tiles. +std::vector<const NativeCommand*> design_tiles(const CommandCatalog& catalog, bool sketching, bool cad_on); + +// Why the person's form of entry `t` is refused before its action runs, or nothing: `t` is not offered in the +// tab's mode (offered_in_mode()), and the message says which mode it belongs to and what to do; or `t`'s +// action is a btn: or fly: one, which the menu greys for a selection it does not accept, and selection `kind` +// (OfferSel as int) is not one it accepts, and the details name the selection and those it accepts. A key: +// action runs whatever is selected, as its key does. The message is a msgid, the code -32000. +std::optional<ToolFailure> open_refusal(const DesignTool& t, bool sketching, int kind); + +// Runs the silent form of Design command `id` with `args` past cad_gate() with its entry's access, and +// returns its result. One that fails is -32000, with "OCCT: " before a kernel exception's message; an id with +// no silent form is -32601. UI thread only. +nlohmann::json run_cad_tool(const std::string& id, const nlohmann::json& args); + +// Edit > Undo, or Redo, in the Design tab, past cad_gate() with Sketch access: the Design history, or in a +// sketch session the sketch's own, which takes off or puts back the last drawn shape. Returns {ok, scope} +// with "sketch" and the sketch's entities, or "design" and the undo and redo depth, features, bodies and +// generation. Fails (-32000) when there is nothing to take back or put back. UI thread only. +nlohmann::json cad_undo_redo(bool redo); + +// get_app_state's cad_note: how a person turns the CAD feature on, in the editor while the Design commands +// cannot run, because `catalog` holds none of them (the feature was off at startup) or the feature is off +// now; null otherwise. UI thread. +nlohmann::json cad_note(const CommandCatalog& catalog); + +// The `plane` param shared by the plane-taking Design commands: "XY", "XZ" or "YZ" through the modeling // origin, {"datum": feature index}, or {"body": b, "face": f} on a planar face. A face gives the // sketch-on-face plane (outward normal), or with `drill` the Hole card's inward plane; `face_body` // then receives b. Throws std::runtime_error with the message the call fails with. @@ -102,7 +153,7 @@ std::vector<int> cad_commit_replace(const nlohmann::json& replace, const Model& // finds the loops. Throws std::runtime_error for an index that is not a sketch with entities. nlohmann::json cad_sketch_describe(const CadDocument& doc, const DesignSketchTool& tool, int sketch); -// The CAD tools that work on the open sketch alone, run on `tool`'s session: sketch_add, +// The Design commands that work on the open sketch alone, run on `tool`'s session: sketch_add, // sketch_fillet, sketch_chamfer, sketch_trim, sketch_transform, sketch_constrain, // sketch_constraints (the open sketch's) and sketch_unconstrain. Each runs the sketch tool's own // step for the button or gesture it stands for, checks every argument before it changes anything, @@ -158,7 +209,7 @@ nlohmann::json cad_query_topology(const CadDocument& doc, const nlohmann::json& // faces, the gap between them. Throws std::runtime_error naming the ref that does not resolve. nlohmann::json cad_measure(const CadDocument& doc, const nlohmann::json& params); -// Where a hole CAD tool drills: `plane` from params.plane (a face gives the Hole card's inward plane), +// Where a hole command drills: `plane` from params.plane (a face gives the Hole card's inward plane), // `target_body` the body (a face plane's own body, else params.body, else -1 for the kernel's last // body), and the reply's {body, x, y}: params.x and params.y, or params.at (a world point, or a // cylindrical face or circular edge whose axis the hole shares) projected onto the plane, with diff --git a/src/slic3r/GUI/Mcp/McpToolsCommon.cpp b/src/slic3r/GUI/Mcp/McpToolsCommon.cpp index 7afcbdc848..7f6906fc3d 100644 --- a/src/slic3r/GUI/Mcp/McpToolsCommon.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsCommon.cpp @@ -4,6 +4,8 @@ #include "McpTypes.hpp" #include "UiInspector.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Operations/Outcome.hpp" #include "slic3r/GUI/Operations/PlateOps.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" @@ -11,18 +13,17 @@ #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Plater.hpp" +#include <nlohmann/json.hpp> #include <wx/app.h> #include <wx/glcanvas.h> #include <wx/window.h> #include <algorithm> -#include <cctype> #include <chrono> #include <cstddef> #include <cstdint> #include <functional> #include <initializer_list> -#include <iterator> #include <string> #include <thread> #include <utility> @@ -56,86 +57,39 @@ json enum_prop(std::vector<std::string> values, const std::string& description) json array_prop(json items, const std::string& description) { return {{"type", "array"}, {"items", std::move(items)}, {"description", description}}; } -ToolDef inspect_tool(std::string name, std::string title, std::string description, json schema, ToolHandler handler) +NativeCommand inspect_tool(std::string group, std::string name, std::string title, std::string description, json schema, CommandFn handler) { - ToolDef d; - d.name = std::move(name); - d.title = std::move(title); - d.description = std::move(description); - d.input_schema = std::move(schema); - d.read_only = true; - d.idempotent = true; - d.guard = GuardClass::Inspect; - d.inline_call = true; - d.journal = false; - d.handler = std::move(handler); + NativeCommand d = NativeCommands::long_command(std::move(name), std::move(title), std::move(group), std::move(schema), + std::move(handler), /*inline_call=*/true); + d.description = std::move(description); + d.listed = true; + d.read_only = true; + d.idempotent = true; + d.guard = GuardClass::Inspect; + d.journal = false; return d; } -ToolDef reaching(std::vector<std::string> operations, ToolDef def) +NativeCommand reaching(std::vector<std::string> operations, NativeCommand command) { - def.operations = std::move(operations); - return def; + command.operations = std::move(operations); + return command; } -ToolDef mutate_tool(std::string name, std::string title, std::string description, json schema, ToolHandler handler, bool destructive) +NativeCommand mutate_tool(std::string group, std::string name, std::string title, std::string description, json schema, CommandFn handler, + bool destructive) { - ToolDef d; - d.name = std::move(name); - d.title = std::move(title); - d.description = std::move(description); - d.input_schema = std::move(schema); - d.destructive = destructive; - d.guard = GuardClass::Mutate; - d.handler = std::move(handler); + NativeCommand d = NativeCommands::long_command(std::move(name), std::move(title), std::move(group), std::move(schema), + std::move(handler)); + d.description = std::move(description); + d.listed = true; + d.destructive = destructive; + d.guard = GuardClass::Mutate; return d; } namespace { -// The words of `text` in lower case, split at anything but a letter or a digit. With `camel`, a word -// with a capital after a lower-case letter also counts as its parts: TriangleMesh as triangle and mesh. -std::vector<std::string> text_words(const std::string& text, bool camel) -{ - std::vector<std::string> words; - std::string word; - std::vector<std::size_t> parts; // where each CamelCase part after the first starts in `word` - const auto flush = [&] { - if (word.empty()) - return; - std::size_t from = 0; - for (const std::size_t at : parts) { - words.push_back(word.substr(from, at - from)); - from = at; - } - if (!parts.empty()) - words.push_back(word.substr(from)); - words.push_back(std::exchange(word, {})); - parts.clear(); - }; - unsigned char previous = 0; - for (const char c : text) { - const auto u = static_cast<unsigned char>(c); - if (!std::isalnum(u)) { - flush(); - previous = 0; - continue; - } - if (camel && std::isupper(u) && std::islower(previous)) - parts.push_back(word.size()); - word += char(std::tolower(u)); - previous = u; - } - flush(); - return words; -} - -// Whether a word of `words` starts with `w`. -bool has_word(const std::vector<std::string>& words, const std::string& w) -{ - return std::any_of(words.begin(), words.end(), [&w](const std::string& word) { return word.compare(0, w.size(), w) == 0; }); -} - // Whether a 3D view is shown but can't draw yet. On Wayland a canvas gets its GL surface from the // map event GTK handles once the main loop runs again, after the closures queued with the change // that showed it, such as a tab switch. wxGLCanvas's IsShownOnScreen() needs that surface; the @@ -277,40 +231,6 @@ json page(const json& items, const json& args, std::size_t default_limit) return result; } -std::vector<std::string> query_words(const std::string& query) -{ - std::vector<std::string> words = text_words(query, false); - std::vector<std::string> longer; - std::copy_if(words.begin(), words.end(), std::back_inserter(longer), [](const std::string& w) { return w.size() >= 3; }); - return longer.empty() ? words : longer; -} - -std::pair<int, int> match_score(const std::vector<std::string>& words, const std::string& name, const std::string& text) -{ - const std::vector<std::string> in_name = text_words(name, true); - const std::vector<std::string> in_text = text_words(text, true); - std::pair<int, int> score; - for (const std::string& w : words) - if (has_word(in_name, w)) { - ++score.first; - ++score.second; - } else if (has_word(in_text, w)) - ++score.first; - return score; -} - -std::string first_sentence(const std::string& text) -{ - std::string line = text; - std::replace(line.begin(), line.end(), '\n', ' '); - for (std::size_t dot = line.find('.'); dot != std::string::npos; dot = line.find('.', dot + 1)) { - const bool abbreviation = dot >= 3 && (line.compare(dot - 3, 3, "e.g") == 0 || line.compare(dot - 3, 3, "i.e") == 0); - if (!abbreviation && (dot + 1 == line.size() || line[dot + 1] == ' ')) - return line.substr(0, dot + 1); - } - return line; -} - json poll_ui(ToolContext& ctx, const std::function<json()>& poll, std::chrono::milliseconds timeout, const std::string& what) { json v = poll_until(ctx, poll, timeout, std::chrono::milliseconds(200)); @@ -330,6 +250,15 @@ json expected_id_prop(const char* of) ": the call is refused when the index names another one now."}}; } +NativeCommand with_expected_ids(NativeCommand command) +{ + const json properties = command.input_schema.value("properties", json::object()); + for (const char* name : {"object_id", "part_id", "object_ids", "part_ids", "instance_object_ids"}) + if (properties.contains(name)) + command.id_args.emplace_back(name); + return command; +} + void check_expected_ids(const ModelObject& object, const ModelVolume* volume, const json& args) { if (args.contains("object_id") && args["object_id"].get<std::size_t>() != object.id().id) diff --git a/src/slic3r/GUI/Mcp/McpToolsConfig.cpp b/src/slic3r/GUI/Mcp/McpToolsConfig.cpp index f7313ae7d3..efa3a75c66 100644 --- a/src/slic3r/GUI/Mcp/McpToolsConfig.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsConfig.cpp @@ -5,7 +5,6 @@ // so the UI and the project stay consistent. Preferences are only read here; they change in the Preferences // dialog, whose handlers carry their effects. -#include "McpService.hpp" #include "slic3r/GUI/I18N.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" @@ -1821,10 +1820,9 @@ json search_settings(const std::string& query, std::size_t limit) return {{"total", ranked.size()}, {"items", std::move(items)}}; } -void register_config_tools(McpService& service) +void register_config_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - const json plate_prop = {{"type", "integer"}, {"minimum", 0}, {"description", "Plate index (plate scope; default: the current plate)."}}; + const json plate_prop = {{"type", "integer"}, {"minimum", 0}, {"description", "Plate index (plate scope; default: the current plate)."}}; // get_settings and set_settings take the same scopes and differ in what they do without one. const std::vector<std::string> scopes{"process", "filament", "printer", "object", "part", "project", "plate", "preferences"}; const std::string scope_text = "Which settings: the process, filament or printer preset being edited, an " @@ -1834,8 +1832,8 @@ void register_config_tools(McpService& service) "and printer settings; anything else reads the process."); const json write_scope_prop = enum_prop(scopes, scope_text + " Default: the process."); - reg.add(inspect_tool( - "list_presets", L("List presets"), + catalog.add(inspect_tool( + "api", "list_presets", L("List presets"), "Printer, process or filament presets with flags: system or user, selected (and modified), compatible with the " "selected printer, and for filaments the slots using them. Only compatible, visible presets unless asked: a fresh " "install hides most system filaments and printers (visible: false), and select_preset takes those too.", @@ -1848,8 +1846,8 @@ void register_config_tools(McpService& service) {"type"}), [](const json& args, ToolContext& ctx) { return ToolResult::ok(ctx.run_ui([&] { return list_presets(args); })); })); - reg.add(reaching({"resolve_preset", "select_preset", "assign_filament_preset"}, mutate_tool( - "select_preset", L("Select a preset"), + catalog.add(reaching({"resolve_preset", "select_preset", "assign_filament_preset"}, mutate_tool( + "api", "select_preset", L("Select a preset"), "Select a printer, process or filament preset by the name its selector shows (or its internal name), as a person " "would. A hidden one (list_presets include_hidden) is shown in the selectors first, until the app restarts. With " "unsaved changes the Transfer-or-discard prompt opens (blocked_by_dialog) unless preset_changes answers it. A " @@ -1909,8 +1907,8 @@ void register_config_tools(McpService& service) return ToolResult::ok(result); }))); - ToolDef save = mutate_tool( - "save_preset", L("Save a preset"), + NativeCommand save = mutate_tool( + "api", "save_preset", L("Save a preset"), "Save the printer, process or filament preset being edited, with its unsaved changes, as a preset called name, " "which is then selected: what the tab's Save button does through its dialog. A filament is filament_slot's " "(default 1), and every slot using the old preset takes the new one. Replacing another existing preset needs " @@ -1967,10 +1965,10 @@ void register_config_tools(McpService& service) }); // A user preset syncs to the cloud account when preset sync is on. save.open_world = true; - reg.add(save); + catalog.add(save); - ToolDef remove = mutate_tool( - "delete_preset", L("Delete a preset"), + NativeCommand remove = mutate_tool( + "api", "delete_preset", L("Delete a preset"), "Delete a user preset or one inside the project, its file and its cloud copy, as the tab's Delete does, without " "asking. A selected preset is replaced as the tab does (its parent or the next preset). Another filament is deleted " "without changing the selection, and slots using it take the selected one; another process is selected, deleted " @@ -2042,10 +2040,10 @@ void register_config_tools(McpService& service) true); // It deletes the preset's cloud copy too. remove.open_world = true; - reg.add(remove); + catalog.add(remove); - reg.add(inspect_tool( - "get_settings", L("Read settings"), + catalog.add(inspect_tool( + "api", "get_settings", L("Read settings"), "Read settings: each item has its value, as OrcaSlicer writes it, and meta: label, description (what the setting " "does, when to change it), where (its settings page and group), type, unit, range, allowed values and mode. Choose " "them by keys; by query, a few words matched in keys, labels and descriptions, best matches first; by where, a page " @@ -2092,8 +2090,8 @@ void register_config_tools(McpService& service) })); })); - reg.add(reaching({"set_plate_locked"}, mutate_tool( - "set_settings", L("Change settings"), + catalog.add(reaching({"set_plate_locked"}, with_expected_ids(mutate_tool( + "api", "set_settings", L("Change settings"), "Change settings of one scope (default the process) as typing them into its settings tab would. Values are strings " "in OrcaSlicer's format (\"15%\", \"0.2\", \"1,2\") or JSON numbers, booleans and arrays (a point as [x, y]). All are " "parsed strictly first and applied together, so nothing changes if one is invalid, and a key of another scope is " @@ -2131,7 +2129,7 @@ void register_config_tools(McpService& service) // writing the key would skip. if (arg_string(args, "scope") == "preferences") throw ToolFailure("Preferences change in the Preferences dialog: run_action orca_command:open_preferences:orca " - "with param \"<tab>:<key>\", then set_widget_value {\"target\": {\"name\": \"<key>\", \"within\": " + "with args {\"tab\": \"<tab>\", \"key\": \"<key>\"}, then set_widget_value {\"target\": {\"name\": \"<key>\", \"within\": " "\"Preferences\"}, \"value\": ...}"); if (arg_string(args, "scope") == "project") return set_project_settings(args, ctx); @@ -2260,10 +2258,10 @@ void register_config_tools(McpService& service) }); settle(ctx); return ToolResult::ok(result); - }))); + })))); - reg.add(inspect_tool( - "list_plates", L("List plates"), + catalog.add(inspect_tool( + "api", "list_plates", L("List plates"), "Plates with name, locked, current, objects (how many are on it; list_objects lists them), and the settings they print with: curr_bed_type, " "print_sequence, spiral_mode, first_layer_print_sequence and other_layers_print_sequence (null: Auto); overrides " "lists those the plate sets itself (set_settings scope plate). Also sliced (an up-to-date slice), wipe_tower [x, y] " diff --git a/src/slic3r/GUI/Mcp/McpToolsLayers.cpp b/src/slic3r/GUI/Mcp/McpToolsLayers.cpp index 677d626b4f..d7dda85ddf 100644 --- a/src/slic3r/GUI/Mcp/McpToolsLayers.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsLayers.cpp @@ -3,7 +3,6 @@ // Adaptive, Smooth and Reset on an object. And how list_objects reports both. set_custom_gcode_at_layer: the // pauses, custom G-codes and filament changes of a plate's layers, through the Preview's layer slider. -#include "McpService.hpp" #include "slic3r/GUI/I18N.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" @@ -573,10 +572,9 @@ bool edit_layer_gcode(IMSlider& slider, const json& args, int filaments, bool ha return changed; } -void register_layer_tools(McpService& service) +void register_layer_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - const json range = object_schema( + const json range = object_schema( {{"min_z", {{"type", "number"}, {"minimum", 0}, {"description", "Bottom, mm above the bed."}}}, {"max_z", {{"type", "number"}, {"minimum", 0}, {"description", "Top, mm above the bed."}}}, {"values", {{"type", "object"}, @@ -584,8 +582,8 @@ void register_layer_tools(McpService& service) "filament) and per-region process settings such as sparse_infill_density or wall_loops."}}}}, {"min_z", "max_z"}); - reg.add(mutate_tool( - "set_height_ranges", L("Set height range modifiers"), + catalog.add(with_expected_ids(mutate_tool( + "api", "set_height_ranges", L("Set height range modifiers"), "Replace an object's height range modifiers (Height Range Modifier in the object list): Z ranges in mm, each printed " "with its own layer_height, filament and process settings, starting from the object's layer height and filament. " "Ranges may touch but not overlap; [] removes them all. One undo step; the object is selected. Reply: the " @@ -599,10 +597,10 @@ void register_layer_tools(McpService& service) json out = ctx.run_ui([&] { return set_height_ranges(ui_plater(), args); }); settle(ctx); return ToolResult::ok(out); - })); + }))); - reg.add(mutate_tool( - "set_variable_layer_height", L("Set a variable layer height profile"), + catalog.add(with_expected_ids(mutate_tool( + "api", "set_variable_layer_height", L("Set a variable layer height profile"), "Run the Variable layer height panel's Adaptive, Smooth or Reset on an object, without opening the panel: adaptive " "computes layer heights from the object's shape (inside a height range, the range's layer_height), smooth smooths " "its profile (or the one its height ranges give), reset goes back to its layer height and ranges. One undo step; " @@ -635,12 +633,12 @@ void register_layer_tools(McpService& service) json out = ctx.run_ui([&] { return set_variable_layer_height(ui_plater(), args); }); settle(ctx); return ToolResult::ok(out); - })); + }))); const json layer = {{"type", "integer"}, {"minimum", 1}, {"description", "1-based, as the Preview's layer slider numbers layers."}}; const json z = {{"type", "number"}, {"minimum", 0}, {"description", "mm: the layer whose top is at or above it."}}; - reg.add(mutate_tool( - "set_custom_gcode_at_layer", L("Set custom G-code at a layer"), + catalog.add(mutate_tool( + "api", "set_custom_gcode_at_layer", L("Set custom G-code at a layer"), "Add or remove pauses, custom G-code, custom templates and filament changes at the start of a layer, as the Preview " "layer slider's menu does; they are saved per plate in the project. They go on the plate's sliced layers, so the " "plate needs an up-to-date slice, or must be the one the Preview still shows after an earlier edit; the call selects " diff --git a/src/slic3r/GUI/Mcp/McpToolsProject.cpp b/src/slic3r/GUI/Mcp/McpToolsProject.cpp index f44c02f3fc..d73af2d34a 100644 --- a/src/slic3r/GUI/Mcp/McpToolsProject.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsProject.cpp @@ -6,9 +6,12 @@ #include "McpService.hpp" #include "McpTools.hpp" #include "McpTypes.hpp" +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/MainFrame.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Operations/ExportOps.hpp" #include "slic3r/GUI/Operations/Outcome.hpp" #include "slic3r/GUI/Operations/PlateOps.hpp" @@ -386,12 +389,10 @@ json calib_params_json(const json& args, const Calib_Params& p, const DynamicPri return out; } -void register_project_tools(McpService& service) +void register_project_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(reaching({"open_project", "import_models"}, mutate_tool( - "open_files", L("Open files"), + catalog.add(reaching({"open_project", "import_models"}, mutate_tool( + "api", "open_files", L("Open files"), "Open model files (STL, 3MF, STEP, OBJ, AMF, SVG...), a project (.3mf) or G-code by absolute path, without a file " "dialog. Models are added to the current project. A .3mf opens as a project, replacing the current one, unless as " "is \"geometry\"; when the current project has unsaved changes that fails, changing nothing, unless " @@ -402,7 +403,8 @@ void register_project_tools(McpService& service) {"discard_changes", prop("boolean", "Drop the project's unsaved changes rather than fail when a .3mf " "replaces it.")}}, {"paths"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); std::vector<fs::path> paths; for (const json& p : args["paths"]) { std::string err; @@ -447,9 +449,12 @@ void register_project_tools(McpService& service) return ToolResult::ok(out); }))); - reg.add(reaching({"new_project"}, mutate_tool( - "new_project", L("New project"), - "Start a new, empty project. Fails, changing nothing, when the current project has unsaved changes, unless " + // The Speed Dial's New Project too: with no arguments it asks as the tile does. + catalog.add(NativeCommands::with_person_form(reaching({"new_project"}, mutate_tool( + {}, "new_project", {}, + "Start a new, empty project. Called with no arguments, it asks as New Project does, about the unsaved changes " + "if there are any: the reply is then blocked_by_dialog, and answer_dialog answers it. With arguments, or silent: " + "true, it asks nothing: it fails, changing nothing, when the current project has unsaved changes, unless " "discard_changes. The presets' unsaved changes carry over to the new project unless preset_changes is \"discard\", as " "New Project's prompt offers. Reply: objects, names, plates; when presets had or have unsaved changes, discarded " "and modified list per preset the keys dropped and the keys still unsaved.", @@ -457,7 +462,8 @@ void register_project_tools(McpService& service) "presets', see preset_changes.")}, {"preset_changes", enum_prop({"keep", "discard"}, "The presets' unsaved changes, not the project's: keep " "them for the new project (default) or drop them.")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const bool discard = arg_bool(args, "discard_changes", false) || service.discard_authorized(ctx.lineage()); const bool discard_presets = arg_string(args, "preset_changes", "keep") == "discard"; json out = ctx.run_ui([&] { @@ -475,10 +481,15 @@ void register_project_tools(McpService& service) }); settle(ctx); return ToolResult::ok(out); - }))); + })), + L("New Project"), L("Commands"), "menu_open", [] { + if (Plater* plater = wxGetApp().plater()) + plater->new_project(); + return AppActionRunResult{AppActionRunResult::Level::Success}; + })); - reg.add(mutate_tool( - "generate_calibration_test", L("Generate a calibration test"), + catalog.add(mutate_tool( + "api", "generate_calibration_test", L("Generate a calibration test"), "Generate a Calibration menu test as its dialog's OK does: a new project named after the test with the test " "model, and the process, filament and printer presets changed as the test needs (presets_changed). The test prints " "with filament slot 1, so the filament tab is pointed at slot 1's preset. Omitted parameters take the dialog's " @@ -521,7 +532,8 @@ void register_project_tools(McpService& service) {"preset_changes", enum_prop({"keep", "discard"}, "The presets' unsaved changes, not the project's: keep them for the " "test or drop them first. Required when presets are modified.")}}, {"test"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); json recorded = args; const bool discard = arg_bool(args, "discard_changes", false) || service.discard_authorized(ctx.lineage()); json out = ctx.run_ui([&]() -> json { @@ -626,9 +638,12 @@ void register_project_tools(McpService& service) return ToolResult::ok(out); })); - reg.add(reaching({"save_project_as"}, mutate_tool( - "save_project", L("Save the project"), - "Save the project as a .3mf at an absolute path without a dialog; it becomes the project's file.", + // The Speed Dial's Save Project too: with no arguments it saves as the tile does. + catalog.add(NativeCommands::with_person_form(reaching({"save_project_as"}, mutate_tool( + {}, "save_project", {}, + "Save the project. Called with no arguments, it saves as Save Project does: to the project's file, or, when it has " + "none, through a file dialog (blocked_by_dialog; a native picker needs auto_answer_dialogs registered first). With " + "path, it saves a .3mf there without a dialog, and the file becomes the project's.", object_schema({{"path", prop("string", "Absolute .3mf path.")}, {"overwrite", prop("boolean", "Replace an existing file.")}}, {"path"}), [](const json& args, ToolContext& ctx) { std::string err; @@ -647,10 +662,15 @@ void register_project_tools(McpService& service) }); settle(ctx); return ToolResult::ok({{"path", path_to_utf8(*path)}, {"bytes", fs::file_size(*path)}}); - }))); + })), + L("Save Project"), L("Commands"), "menu_save", [] { + if (Plater* plater = wxGetApp().plater()) + plater->save_project(false); + return AppActionRunResult{AppActionRunResult::Level::Success}; + })); - reg.add(reaching({"start_gcode_export", "export_sliced_3mf", "export_model_3mf", "export_stl"}, mutate_tool( - "export", L("Export"), + catalog.add(reaching({"start_gcode_export", "export_sliced_3mf", "export_model_3mf", "export_stl"}, mutate_tool( + "api", "export", L("Export"), "Write the project to a file without a dialog. gcode: the plate's G-code (slice first; it is written in the " "background, and the call returns once it is). sliced_3mf: the sliced plate, or all plates, as .gcode.3mf. 3mf: " "the model without slicing data. stl: all objects as one STL. Without format, the path's extension (.gcode, " diff --git a/src/slic3r/GUI/Mcp/McpToolsPython.cpp b/src/slic3r/GUI/Mcp/McpToolsPython.cpp index 58c872cc97..4809c917d5 100644 --- a/src/slic3r/GUI/Mcp/McpToolsPython.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsPython.cpp @@ -279,12 +279,10 @@ ToolResult run_python_session_job(McpService& service, ToolContext& ctx, PythonS return ToolResult::ok({{"status", "ended"}}); } -void register_python_tools(McpService& service) +void register_python_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - ToolDef run = mutate_tool( - "run_script", L("Run a Python script"), + NativeCommand run = mutate_tool( + "core", "run_script", L("Run a Python script"), "Run Python code inside OrcaSlicer as its main program (__name__ == \"__main__\") against orca.host, the whole plugin " "API (search_python_api searches it): read objects, meshes and settings, compute, use orca.host.ui and the preset " "API, and call these same tools, with their guards and undo, through orca.host.tools.call(name, args), from the code " @@ -307,7 +305,8 @@ void register_python_tools(McpService& service) "path makes it a file run, as `python file.py` runs it: __file__, sys.argv, imports " "from its folder and its PEP 723 dependencies; any other name only names it.")}}, {"code"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); // A plugin's script is the plugin's own code: its identity and grants. const std::string& plugin = ctx.caller_plugin(); const std::string identity = !plugin.empty() ? plugin : @@ -357,10 +356,10 @@ void register_python_tools(McpService& service) run.cancellable = true; // A script reaches outside the app: files, programs and the network. run.open_world = true; - reg.add(run); + catalog.add(run); - reg.add(inspect_tool( - "search_python_api", L("Search the Python API"), + catalog.add(inspect_tool( + "core", "search_python_api", L("Search the Python API"), "Search orca, the Python API of run_script scripts and plugins, in the running build: orca.host (the project's " "model and meshes, presets and their editors, slicing data, orca.host.ui windows and dialogs, orca.host.tools " "calling these tools) and the classes, events and pages plugins build on. Each entry has its kind, signature (a " diff --git a/src/slic3r/GUI/Mcp/McpToolsRecord.cpp b/src/slic3r/GUI/Mcp/McpToolsRecord.cpp index 1fab71dfa4..3aca5775ed 100644 --- a/src/slic3r/GUI/Mcp/McpToolsRecord.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsRecord.cpp @@ -8,7 +8,9 @@ #include "McpTypes.hpp" #include "RecordingSettings.hpp" #include "VideoEncode.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/I18N.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem/operations.hpp> @@ -45,17 +47,14 @@ namespace { // The recording tools only read the app, so they run behind dialogs and during operations, but each // is a job: ownership is read from the job's ancestry, and an encode outlives the reply budget. -ToolDef record_tool(std::string name, std::string title, std::string description, json schema, ToolHandler handler) +NativeCommand record_tool(std::string group, std::string name, std::string title, std::string description, json schema, CommandFn handler) { - ToolDef d; - d.name = std::move(name); - d.title = std::move(title); - d.description = std::move(description); - d.input_schema = std::move(schema); - d.guard = GuardClass::Inspect; - d.inline_call = false; - d.journal = true; - d.handler = std::move(handler); + NativeCommand d = NativeCommands::long_command(std::move(name), std::move(title), std::move(group), std::move(schema), + std::move(handler)); + d.description = std::move(description); + d.listed = true; + d.guard = GuardClass::Inspect; + d.journal = true; return d; } @@ -97,24 +96,27 @@ std::vector<std::string> encode_preset_keys() } // namespace -void register_record_tools(McpService& service) +void register_record_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(record_tool( - "start_recording", L("Start a recording"), + // The Speed Dial's Start Recording too: with no arguments it opens the tile's dialog. + catalog.add(NativeCommands::with_person_form(record_tool( + {}, "start_recording", {}, "Record a video of OrcaSlicer until stop_recording: the main window with any modal dialog on it (target main), or " "the 3D view shown (canvas). Frames are MJPEG in a Matroska (.mkv) file with their real timestamps. With captions, " "the tool call acting on the app shows as a caption at the bottom (secret setting values never show); with pointer, " "the pointer is highlighted, its clicks rippling. Capture takes at most about a third of the UI thread, so " "the frame rate drops where capturing is slow. One recording at a time: one a replay or script starts ends with it, a " "client's when the server is turned off. With encode, the stop_recording that reports it also encodes it to an MP4 " - "beside it, as the Start Recording command does; encode_recording makes an MP4 of any recording later.", + "beside it, as the Start Recording command does; encode_recording makes an MP4 of any recording later. Called with no " + "arguments, it opens the Start Recording dialog instead, as the Start Recording command does (blocked_by_dialog): " + "its controls are named after their settings for set_widget_value, answer_dialog \"Start recording\" starts the " + "person's recording, which neither the end of a replay or script nor the server turning off ends, and the dialog " + "remembers the settings; silent: true starts one here at once with the defaults.", object_schema({{"target", enum_prop({"main", "canvas"}, "main (default): the main window and its dialogs; canvas: the 3D view shown.")}, {"fps", int_prop(1, 30, "Frames per second at most (default 10).")}, {"max_dim", int_prop(320, 3840, "Long edge of the video in pixels (default 1920).")}, {"quality", int_prop(30, 95, "JPEG quality of the frames (default 80).")}, - {"max_seconds", int_prop(1, 3600, "The recording ends on its own after this long (default 600).")}, + {"max_seconds", int_prop(1, 3600, "The recording ends on its own after this long (default 3600).")}, {"captions", prop("boolean", "Caption the tool call acting on the app (default false).")}, {"pointer", prop("boolean", "Highlight the pointer and show its clicks (default false).")}, {"encode", prop("boolean", "Encode it to an MP4 once stopped; needs an ffmpeg (default false).")}, @@ -128,23 +130,19 @@ void register_record_tools(McpService& service) "the codec's first).")}, {"save_path", prop("string", "Absolute .mkv path; default the session's output folder.")}, {"overwrite", prop("boolean", "Replace an existing save_path, and with encode its MP4.")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); RecordingOptions o; o.target = arg_string(args, "target", "main"); o.fps = arg_int(args, "fps", 10); o.max_dim = arg_int(args, "max_dim", 1920); o.quality = arg_int(args, "quality", 80); - o.max_seconds = arg_int(args, "max_seconds", 600); + o.max_seconds = arg_int(args, "max_seconds", 3600); o.captions = arg_bool(args, "captions", false); o.pointer = arg_bool(args, "pointer", false); - // The encode as the Start Recording command takes it: its keys, defaults and checks. - json encode_args = json::object(); - for (const char* key : {"encode", "encode_preset", "codec", "crf", "speed", "profile"}) - if (args.contains(key)) - encode_args[key] = args[key]; + // The encode with the Start Recording dialog's defaults, the Balanced preset. RecordingSettings settings; - bool silent = false; - if (const std::string err = apply_recording_overrides(settings, encode_args, silent); !err.empty()) + if (const std::string err = apply_recording_overrides(settings, args); !err.empty()) throw ToolFailure(err); if (std::string err; settings.encode && !find_ffmpeg(err)) throw ToolFailure("Cannot encode: " + err); @@ -203,23 +201,31 @@ void register_record_tools(McpService& service) {"crf", settings.crf}, {"speed", settings.speed}, {"profile", settings.profile}}; + // The limit it runs under, which a call that leaves it out did not choose. + out["max_seconds"] = o.max_seconds; // The path used, so a replay records into its own output folder under the same name and its // encode finds it there. json recorded = args; recorded["save_path"] = out["path"]; ctx.set_journal_args(std::move(recorded)); return ToolResult::ok(out); - })); + }), + L("Start Recording"), L("Commands"), "recording_start", NativeCommands::start_person_recording)); - reg.add(record_tool("stop_recording", L("Stop the recording"), + // The Speed Dial's Stop Recording too: with no arguments it stops as the tile does. + catalog.add(NativeCommands::with_person_form(record_tool({}, "stop_recording", {}, "Stop the running recording and return its file once it is written: seconds, frames captured and " "written, frames dropped when encoding fell behind, failed when they could not be encoded, or " "skipped when the window could not be captured, " "the size, the mean UI-thread time a capture took (capture_ms), and why it ended. A recording that ended on its own (max_seconds, the replay or script that started it ended, a " "write error) is reported once by the next stop_recording. For a recording started with encode, it then " "starts the MP4 encode and returns it under encode: a job, whose wait {for: \"job\"} returns " - "encode_recording's result.", - object_schema({}), [&service](const json&, ToolContext& ctx) { + "encode_recording's result. This is the call with silent: true. Called with no arguments, it stops " + "the recording as the Stop Recording command does, whoever started it: without waiting for its " + "file, it shows the person a notification naming it and replies with its path; the next " + "stop_recording with silent: true reports it as ended stopped_in_app.", + object_schema({}), [](const json&, ToolContext& ctx) { + McpService& service = ctx.service(); // The last state too, even if the timer has not ticked since the last call. Without the // UI thread (a native dialog holds it), the recording ends with its last frame. try { @@ -238,10 +244,12 @@ void register_record_tools(McpService& service) report["encode"] = r.is_error ? json{{"error", r.message}} : r.data; } return ToolResult::ok(report); - })); + }), + // The person's stop opens nothing: like the silent one, it stops a recording behind a dialog. + L("Stop Recording"), L("Commands"), "recording_stop", NativeCommands::stop_recording_in_app, /*person_form_behind_dialogs=*/true)); - ToolDef encode = record_tool( - "encode_recording", L("Encode a recording"), + NativeCommand encode = record_tool( + "ui", "encode_recording", L("Encode a recording"), "Encode a recording into an H.265 (or H.264) MP4 with the system ffmpeg (ORCA_FFMPEG, else ffmpeg on PATH; it " "needs libx265 or libx264), keeping its timing. Takes this session's last finished recording unless path names " "one, and writes beside it unless save_path says where. A long encode returns a job: wait for it, or cancel_job {job} " @@ -256,7 +264,8 @@ void register_record_tools(McpService& service) "h264: high, main or baseline; h265: main, or main10 for 10 bits per sample. Default the " "encoder's (high, main).")}, {"delete_source", prop("boolean", "Delete the .mkv once encoded (a recording this session made).")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const std::shared_ptr<RecordingFiles>& files = service.recorder().files(); std::string err; fs::path source; @@ -404,7 +413,7 @@ void register_record_tools(McpService& service) return ToolResult::ok(out); }); encode.cancellable = true; - reg.add(encode); + catalog.add(encode); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsReplay.cpp b/src/slic3r/GUI/Mcp/McpToolsReplay.cpp index e0de7a6fcb..bd7052c438 100644 --- a/src/slic3r/GUI/Mcp/McpToolsReplay.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsReplay.cpp @@ -107,12 +107,10 @@ json run_replay_job(McpService& service, ToolContext& ctx, const Replay& replay, return result; } -void register_replay_tools(McpService& service) +void register_replay_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - ToolDef run = mutate_tool( - "run_replay", L("Run a replay"), + NativeCommand run = mutate_tool( + "core", "run_replay", L("Run a replay"), "Replay a list of tool calls in order and report each step: {orca_replay:1, name, vars, steps:[{tool, args, expect, " "optional, await, save_as, timeout_s}]}, JSON with comments. Strings may use ${replay_dir}, ${out_dir}, ${env:NAME}, " "${vars.NAME} and ${jobs.NAME}. A step that returns a job is awaited unless await:false, which stores the job under " @@ -125,7 +123,8 @@ void register_replay_tools(McpService& service) {"description", "The replay itself, as an object or as its JSON text, instead of path."}}}, {"out_dir", prop("string", "Absolute directory for result.json and screenshots; created if missing.")}, {"vars", {{"type", "object"}, {"description", "Values that override the replay's vars."}}}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const bool has_path = args.contains("path"), has_replay = args.contains("replay"); if (has_path == has_replay) return invalid("give exactly one of path and replay"); @@ -155,7 +154,7 @@ void register_replay_tools(McpService& service) if (!replay) return invalid(err); for (const ReplayStep& step : replay->steps) - if (service.registry().lookup(step.tool) == nullptr) + if (service.catalog().lookup(step.tool) == nullptr) return invalid("unknown tool " + step.tool); if (args.contains("vars")) for (const auto& [key, value] : args["vars"].items()) @@ -171,10 +170,10 @@ void register_replay_tools(McpService& service) }); // Its steps call any tool, run_script included. run.open_world = true; - reg.add(run); + catalog.add(run); - ToolDef exp = inspect_tool( - "export_replay", L("Export this session as a replay"), + NativeCommand exp = inspect_tool( + "core", "export_replay", L("Export this session as a replay"), "Turn the calls this session made into a replay that run_replay runs: mutating calls, wait and screenshot, in order, " "with refs replaced by locators, job replies replayed with await:false, and screenshot paths moved under ${out_dir}. " "Calls that failed, at once or as a job later, are left out; so is a call whose job is still running (unless it " @@ -184,7 +183,8 @@ void register_replay_tools(McpService& service) {"path", prop("string", "Absolute .json path to write.")}, {"overwrite", prop("boolean", "Replace an existing file.")}, {"clear", prop("boolean", "Forget the calls recorded so far once exported.")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); if (!ctx.caller_plugin().empty()) throw ToolFailure("export_replay exports the agent's session, which a plugin's calls are not part of"); json running; @@ -208,7 +208,7 @@ void register_replay_tools(McpService& service) exp.read_only = false; // clear empties the recording, so a second call exports less. exp.idempotent = false; - reg.add(exp); + catalog.add(exp); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsScene.cpp b/src/slic3r/GUI/Mcp/McpToolsScene.cpp index 5dae42f3b1..f1841ef07d 100644 --- a/src/slic3r/GUI/Mcp/McpToolsScene.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsScene.cpp @@ -466,8 +466,8 @@ ArrangeStart start_arrange(Plater& plater, const json& args) } const std::string plate_name = "Plate " + std::to_string(plate); if (plate >= 0 && plates.get_plate(plate)->is_locked()) - throw ToolFailure(plate_name + " is locked; unlock it first (run_action plate_goto with param " + std::to_string(plate) + - ", then plate_toggle_lock)"); + throw ToolFailure(plate_name + " is locked; unlock it first (run_action plate_goto with args {\"plate\": " + std::to_string(plate) + + "}, then plate_toggle_lock)"); if (plate >= 0 && plates.get_plate(plate)->empty()) throw ToolFailure(plate_name + " has no objects to arrange"); @@ -967,12 +967,10 @@ json plate_summary(const json& statistics, const GCodeProcessorResult& result) return out; } -void register_scene_tools(McpService& service) +void register_scene_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(inspect_tool( - "list_objects", L("List objects"), + catalog.add(inspect_tool( + "api", "list_objects", L("List objects"), "The project as the Objects panel lists it. plates: each {index, name, objects}, with the objects that have an " "instance on it; outside: the objects with an instance on no plate. An object with instances on two plates is " "listed under both, each time with that plate's instances. An object has its filament, auto_drop, bounding box " @@ -997,8 +995,8 @@ void register_scene_tools(McpService& service) {"offset", {{"type", "integer"}, {"minimum", 0}}}}), [](const json& args, ToolContext& ctx) { return ToolResult::ok(ctx.run_ui([&] { return list_objects(args); })); })); - reg.add(mutate_tool( - "select_objects", L("Select objects"), + catalog.add(with_expected_ids(mutate_tool( + "ui", "select_objects", L("Select objects"), "Select objects, instances or parts in the 3D view (the assemble view while it is shown, else Prepare, switching to it), as clicking them would. Give objects, " "instances ([[object, instance], ...]) or parts ([[object, part], ...]); add keeps the current selection; all / " "none select everything or nothing. The reply is the selection as get_app_state.selection gives it.", @@ -1105,10 +1103,10 @@ void register_scene_tools(McpService& service) }); settle(ctx); return ToolResult::ok(out); - })); + }))); - reg.add(mutate_tool( - "transform", L("Move, rotate or scale an instance or a part"), + catalog.add(with_expected_ids(mutate_tool( + "api", "transform", L("Move, rotate or scale an instance or a part"), "Change one instance's placement, or one part's with part. translate is in mm, position where it goes (mm, as " "the Move panel shows it, whatever mode says), rotate in degrees about X/Y/Z, " "scale a factor (one number or [x, y, z]), size [x, y, z] mm along the object's or part's own axes, plate moves " @@ -1148,10 +1146,10 @@ void register_scene_tools(McpService& service) }); settle(ctx); return ToolResult::ok(out); - })); + }))); - reg.add(mutate_tool( - "add_part", L("Add a part or modifier to an object"), + catalog.add(with_expected_ids(mutate_tool( + "api", "add_part", L("Add a part or modifier to an object"), "Add a part, negative part, modifier, support blocker or enforcer, or precise seam to an object, as its context " "menu's Add items do: a primitive shape at a size, or a model file as Load... adds it. The part lands where the " "menu puts it (a shape beside the object, a file at its coordinates relative to the object's first part) unless " @@ -1176,10 +1174,10 @@ void register_scene_tools(McpService& service) json out = ctx.run_ui([&] { return add_part(ui_plater(), args); }); settle(ctx); return ToolResult::ok(out); - })); + }))); - reg.add(reaching({"start_arrange"}, mutate_tool( - "arrange", L("Arrange objects or fill the bed"), + catalog.add(reaching({"start_arrange"}, mutate_tool( + "api", "arrange", L("Arrange objects or fill the bed"), "Arrange the objects of every unlocked plate as the toolbar's Arrange does, or of one plate (plates: an index or " "\"current\") as its Arrange icon does. With fill, fill that object's plate with more of it instead, as Fill bed " "with instances (or copies, by fill_with) does. spacing, rotate, align_y and multi_material are the Arrange options " @@ -1195,7 +1193,8 @@ void register_scene_tools(McpService& service) {"fill", {{"type", "integer"}, {"minimum", 0}, {"description", "Instead of arranging, fill this object's plate with more of it."}}}, {"fill_with", enum_prop({"instances", "copies"}, "Default instances.")}, {"timeout_s", {{"type", "integer"}, {"minimum", 10}, {"maximum", 1800}, {"description", "Cancel it after this long (default 300)."}}}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); ArrangeStart start; ctx.run_ui([&] { start = start_arrange(ui_plater(), args); @@ -1225,8 +1224,8 @@ void register_scene_tools(McpService& service) } }))); - ToolDef slice = reaching({"start_slice"}, mutate_tool( - "slice", L("Slice"), + NativeCommand slice = reaching({"start_slice"}, mutate_tool( + "api", "slice", L("Slice"), "Slice the current plate, all plates, or one plate by index, the way the toolbar's Slice button does, and wait for " "the result (or reply with a job id when it takes longer than the reply budget). Each requested plate reports ok, " "error, cancelled, empty or skipped; the whole operation is superseded when someone else started a slice or " @@ -1348,16 +1347,17 @@ void register_scene_tools(McpService& service) return ToolResult::ok(result); })); slice.budget_ms = 45000; - reg.add(slice); + catalog.add(slice); - ToolDef cancel = mutate_tool( - "cancel_job", L("Cancel a job"), + NativeCommand cancel = mutate_tool( + "core", "cancel_job", L("Cancel a job"), "Stop the running operation: a slice or G-code export, as the slicing progress's cancel button does, or a " "background job an MCP call started (an arrange, orient or fill bed). Its job then reports cancelled; a background " "job keeps other changes out until it has really stopped. With job, only that job is stopped: the running " "operation, a run_script run or an encode_recording. Allowed while an operation holds the project.", object_schema({{"job", prop("string", "The operation's job to cancel, e.g. \"j12\".")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const auto ops = service.jobs().running_operations(); // A plugin stops only what its own calls started, so it names the job. if (!ctx.caller_plugin().empty() && !args.contains("job")) @@ -1368,7 +1368,7 @@ void register_scene_tools(McpService& service) const std::string job = arg_string(args, "job"); if (std::find(ops.begin(), ops.end(), job) == ops.end()) { // A call that is no operation but can be stopped: its handler watches for the stop. - const ToolDef* def = service.registry().find(service.jobs().running_tool(job)); + const NativeCommand* def = service.catalog().find(service.jobs().running_tool(job)); if (def == nullptr || !def->cancellable) throw ToolFailure("Job " + job + " is not a running operation", {{"running", ops}}); service.request_stop(job); @@ -1391,7 +1391,7 @@ void register_scene_tools(McpService& service) cancel.allowed_during_operation = true; // Recovery: it must get through a dialog the operation opened and another call's nested loop. cancel.guard = GuardClass::Recover; - reg.add(cancel); + catalog.add(cancel); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsUi.cpp b/src/slic3r/GUI/Mcp/McpToolsUi.cpp index 3d3380014a..619978d410 100644 --- a/src/slic3r/GUI/Mcp/McpToolsUi.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsUi.cpp @@ -13,6 +13,7 @@ #include "UiInspector.hpp" #include "WebPages.hpp" #include "WindowControl.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GUI.hpp" @@ -114,9 +115,11 @@ void journal_with_locator(ToolContext& ctx, const json& args, const json& locato ctx.set_journal_args(std::move(recorded)); } -ToolDef recover_input_tool(std::string name, std::string title, std::string description, json schema, ToolHandler handler) +NativeCommand recover_input_tool(std::string group, std::string name, std::string title, std::string description, json schema, + CommandFn handler) { - ToolDef d = mutate_tool(std::move(name), std::move(title), std::move(description), std::move(schema), std::move(handler)); + NativeCommand d = mutate_tool(std::move(group), std::move(name), std::move(title), std::move(description), std::move(schema), + std::move(handler)); d.guard = GuardClass::Recover; return d; } @@ -1326,12 +1329,10 @@ json display_area(unsigned index) return {{"index", index}, {"x", area.x}, {"y", area.y}, {"width", area.width}, {"height", area.height}}; } -void register_ui_tools(McpService& service) +void register_ui_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - reg.add(inspect_tool( - "list_windows", L("List the windows"), + catalog.add(inspect_tool( + "ui", "list_windows", L("List the windows"), "List OrcaSlicer's open windows: the main window, then the windows that don't block the app (Plugins, an " "object's settings, a dock panel floating on its own), then the modal dialogs in the order they opened, the " "topmost last. A window's ref goes to screenshot as target to capture that window, to list_widgets as target to " @@ -1344,13 +1345,14 @@ void register_ui_tools(McpService& service) "setting), which no tool reaches and screenshots leave out.", object_schema({{"limit", {{"type", "integer"}, {"minimum", 1}, {"maximum", 200}, {"description", "Default 100."}}}, {"offset", {{"type", "integer"}, {"minimum", 0}}}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); return ToolResult::ok(page(ctx.run_ui([&] { return service.inspector().windows(); }), args)); })); { - ToolDef def = recover_input_tool( - "set_window", L("Size or move a window"), + NativeCommand def = recover_input_tool( + "ui", "set_window", L("Size or move a window"), "Size, move, maximize, minimize or raise a window: the main window (default), the topmost modal dialog, or one " "list_windows lists, also while a modal dialog is open. Size the main window before set_view fits the camera and " "before start_recording, as a recording keeps its first frame's size. size and position are in the units " @@ -1371,14 +1373,14 @@ void register_ui_tools(McpService& service) "or position.")}, {"raise", prop("boolean", "Bring the window in front of the app's other windows; active in the reply says " "whether it became the active one.")}}), - [&service](const json& args, ToolContext& ctx) { return set_window(service, ctx, args); }); + [](const json& args, ToolContext& ctx) { return set_window(ctx.service(), ctx, args); }); def.allowed_during_operation = true; - reg.add(def); + catalog.add(def); } { - ToolDef def = inspect_tool( - "list_widgets", L("List the widgets"), + NativeCommand def = inspect_tool( + "ui", "list_widgets", L("List the widgets"), "Describe what is on screen as an indented tree, one element per line with a ref to pass to click, set_widget_value, " "press_keys and run_javascript (a page element's to mouse_gesture too): the widgets of every shown window, the rows of lists, " "trees and tables, each shown popup after the window it opened from, the main menus, the 3D canvas's toolbar " @@ -1409,7 +1411,8 @@ void register_ui_tools(McpService& service) {"include_web", prop("boolean", "List the elements of web pages (default true).")}, {"max_web_nodes", {{"type", "integer"}, {"minimum", 1}, {"maximum", 5000}, {"description", "Page elements, apart from max_nodes; default 300."}}}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); SnapshotOptions o; o.root = arg_string(args, "target", "all"); o.query = arg_string(args, "query"); @@ -1462,11 +1465,11 @@ void register_ui_tools(McpService& service) r.content.push_back({{"type", "text"}, {"text", tree.empty() ? std::string("(nothing shown)") : tree}}); return r; }); - reg.add(def); + catalog.add(def); } - reg.add(recover_input_tool( - "click", L("Click an element"), + catalog.add(recover_input_tool( + "ui", "click", L("Click an element"), "Click a GUI element as a person would. Menu items, buttons, checkboxes, toggles, radio buttons, toolbar items and " "gizmos are activated the way their owners expect: a gizmo opens and a second click closes it (Text on an object " "without text creates a text part: created). Other widgets and ImGui items get a mouse click once scrolled into " @@ -1492,7 +1495,8 @@ void register_ui_tools(McpService& service) {"popup_item", kPopupItemSchema}, {"timeout_s", kPageTimeoutSchema}}, {"target"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); end_web_press(service, ctx); // a click ends a press held on a page, even one refused here if (is_web_target(args["target"])) return web_click(service, ctx, args); @@ -1571,8 +1575,8 @@ void register_ui_tools(McpService& service) return ToolResult::ok(out); })); - reg.add(recover_input_tool( - "set_widget_value", L("Set a widget's value"), + catalog.add(recover_input_tool( + "ui", "set_widget_value", L("Set a widget's value"), "Set a widget's value and send the events a person's edit would. Widgets: text fields (submit, the default, also " "presses Enter and leaves the field, which is when Orca's setting fields commit), spin controls, sliders, choice, " "combo and list boxes (by option text or index), checkboxes, toggles and a row's checkbox (true or false), and a " @@ -1591,7 +1595,8 @@ void register_ui_tools(McpService& service) {"submit", prop("boolean", "Press Enter / commit after setting (default true).")}, {"timeout_s", kPageTimeoutSchema}}, {"target", "value"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); if (is_web_target(args["target"])) return web_input(service, ctx, args); refuse_web_view(service, ctx, args["target"]); @@ -1607,8 +1612,8 @@ void register_ui_tools(McpService& service) return ToolResult::ok(out); })); - reg.add(recover_input_tool( - "press_keys", L("Press keys"), + catalog.add(recover_input_tool( + "ui", "press_keys", L("Press keys"), "Send a key chord (\"Ctrl+S\", \"Escape\", \"Return\", \"Delete\", \"Shift+Tab\", \"Left\", \"F5\") and/or type text to " "a target or, without one, to the focused window (the topmost dialog while one is open, the shown 3D view when " "nothing has focus). As with a real key press, the shortcut handling of the target's panels and window sees the keys " @@ -1622,7 +1627,8 @@ void register_ui_tools(McpService& service) {"text", prop("string", "Characters to type.")}, {"popup_item", kPopupItemSchema}, {"timeout_s", kPageTimeoutSchema}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const std::string keys = arg_string(args, "keys"), text = arg_string(args, "text"); if (keys.empty() && text.empty()) throw ToolFailure("Give keys, text or both"); @@ -1684,8 +1690,8 @@ void register_ui_tools(McpService& service) #ifdef SLIC3R_CAD mouse_canvases.insert(mouse_canvases.end() - 1, "design"); #endif - reg.add(recover_input_tool( - "mouse_gesture", L("Mouse gesture on the 3D view"), + catalog.add(recover_input_tool( + "ui", "mouse_gesture", L("Mouse gesture on the 3D view"), "Make a mouse gesture on a 3D canvas as a person would: move, down, up, click, drag or wheel. It starts at `at`, a " "point of the model, which is projected through the camera and by default checked to land on that part (check " "\"point\" only projects it), or at x/y, logical pixels from the canvas's top left. A drag goes through `waypoints` to " @@ -1719,7 +1725,8 @@ void register_ui_tools(McpService& service) {"target", {{"type", json::array({"string", "object"})}, {"description", "A web page's element (its ref or a {web}/{css} locator) to gesture on instead of a 3D canvas."}}}, {"timeout_s", kPageTimeoutSchema}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); if (args.contains("target") && is_web_target(args["target"])) return web_mouse(service, ctx, args); end_web_press(service, ctx); // a gesture elsewhere ends a press held on a page, even one refused here @@ -1768,8 +1775,8 @@ void register_ui_tools(McpService& service) return ToolResult::ok(out); })); - reg.add(mutate_tool( - "pick_gizmo_file", L("Pick a file for the open gizmo"), + catalog.add(mutate_tool( + "ui", "pick_gizmo_file", L("Pick a file for the open gizmo"), "Do what a file picker inside the open gizmo does, with a path instead of its dialog: svg_change loads another SVG " "file into the SVG part being edited, svg_save_as writes that part's SVG to a new file (an existing one only with " "overwrite), texture_import imports a height-map image into the texture library and puts it on Texture " @@ -1815,8 +1822,8 @@ void register_ui_tools(McpService& service) return ToolResult::ok(out); })); - reg.add(recover_input_tool( - "answer_dialog", L("Answer a dialog"), + catalog.add(recover_input_tool( + "core", "answer_dialog", L("Answer a dialog"), "Press a button of the topmost modal dialog: yes, no, ok, cancel, close, apply, a button's label, or a numeric id. " "A disabled button (enabled: false) is refused, the dialog's message showing what it still needs, and so is one on " "a page the dialog does not show, except a hidden cancel or close, which ends the dialog. The label of an option of a " @@ -1836,7 +1843,8 @@ void register_ui_tools(McpService& service) {"additionalProperties", false}, {"description", "Which dialog; default the topmost."}}}}, {"button"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); end_web_press(service, ctx); // pressing a button ends a press held on a page, even one refused here const std::string button = arg_string(args, "button"); const std::string title = args.contains("dialog") ? args["dialog"].value("title", "") : std::string(); @@ -1989,8 +1997,8 @@ void register_ui_tools(McpService& service) })); { - ToolDef def = recover_input_tool( - "auto_answer_dialogs", L("Answer dialogs automatically"), + NativeCommand def = recover_input_tool( + "core", "auto_answer_dialogs", L("Answer dialogs automatically"), "Answer modal dialogs automatically when their title or message matches a rule's regex (case-insensitive). " "get_app_state.auto_answer_rules lists the rules in force. Called from a replay or script, the rules last until it " "ends; otherwise they replace the ones this session set before, and an empty list clears them. A native dialog " @@ -2011,7 +2019,8 @@ void register_ui_tools(McpService& service) {"additionalProperties", false}}, "Rules, first match wins.")}}, {"rules"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); std::vector<AutoAnswerRule> rules; for (const json& r : args["rules"]) rules.push_back(make_rule(r["match"].get<std::string>(), r["button"].get<std::string>(), r.value("path", std::string()), @@ -2065,11 +2074,11 @@ void register_ui_tools(McpService& service) return ToolResult::ok(std::move(out)); }); def.idempotent = true; - reg.add(def); + catalog.add(def); } - ToolDef eval = recover_input_tool( - "run_javascript", L("Run JavaScript in a web view"), + NativeCommand eval = recover_input_tool( + "ui", "run_javascript", L("Run JavaScript in a web view"), "Evaluate JavaScript in one of OrcaSlicer's web views (Home, the device page, dialogs, plugin windows). Prefer " "list_widgets and the input tools (click, set_widget_value, press_keys, mouse_gesture), which see and drive pages as they do widgets. The code runs in the target's page: " "a web view's (kind webview in list_widgets), or a page element's, with the element as `el`; without a target, in " @@ -2082,7 +2091,8 @@ void register_ui_tools(McpService& service) {"target", kTargetSchema}, {"timeout_s", {{"type", "integer"}, {"minimum", 1}, {"maximum", 120}, {"description", "Seconds the code gets (default 10)."}}}}, {"code"}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const std::string code = arg_string(args, "code"); const auto timeout = std::chrono::seconds(std::clamp(arg_int(args, "timeout_s", 10), 1, 120)); const bool element = args.contains("target") && is_web_target(args["target"]); @@ -2148,7 +2158,7 @@ void register_ui_tools(McpService& service) }); // Its script runs with the page's own reach: the device page and Home talk to printers and the cloud. eval.open_world = true; - reg.add(eval); + catalog.add(eval); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpToolsView.cpp b/src/slic3r/GUI/Mcp/McpToolsView.cpp index bb38e9c71d..578e38cd0e 100644 --- a/src/slic3r/GUI/Mcp/McpToolsView.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsView.cpp @@ -417,12 +417,10 @@ json preview_state(GCodeViewer& viewer) {"layer_count", layers->GetMaxValue() + 1}}; } -void register_view_tools(McpService& service) +void register_view_tools(CommandCatalog& catalog) { - ToolRegistry& reg = service.registry(); - - ToolDef screenshot = inspect_tool( - "screenshot", L("Take a screenshot"), + NativeCommand screenshot = inspect_tool( + "ui", "screenshot", L("Take a screenshot"), "Capture what OrcaSlicer shows and return it as an image, downscaled to max_dim on the long edge (default 1280), " "plus the full-size PNG written to save_path (or the session's output folder). target: \"main\" (the main " "window), \"canvas\" (the visible 3D view exactly as rendered: scene, toolpaths, toolbars, ImGui panels; on the " @@ -437,7 +435,8 @@ void register_view_tools(McpService& service) {"save_path", prop("string", "Absolute .png path for the full-size image.")}, {"overwrite", prop("boolean", "Replace an existing save_path.")}, {"include_image", prop("boolean", "Return the image itself (default true); false returns only the path.")}}), - [&service](const json& args, ToolContext& ctx) { + [](const json& args, ToolContext& ctx) { + McpService& service = ctx.service(); const json target_arg = args.value("target", json("main")); const std::string target = target_arg.is_string() ? target_arg.get<std::string>() : std::string(); json locator; @@ -578,10 +577,10 @@ void register_view_tools(McpService& service) return out; }); screenshot.journal = true; // a replay takes the same screenshots - reg.add(screenshot); + catalog.add(screenshot); - reg.add(inspect_tool( - "get_slice_stats", L("Get slice statistics"), + catalog.add(inspect_tool( + "api", "get_slice_stats", L("Get slice statistics"), "What the Preview shows for a sliced plate. summary: the slice reply's, plus prepare and travel time and travel " "distance. features: seconds, share of the print time and grams per feature type (the Line Type legend), and " "travel. layers: per layer (1-based, as set_view's layer) Z, height, seconds and grams, paged; layer_features adds " @@ -647,7 +646,7 @@ void register_view_tools(McpService& service) out["view"] = shown ? preview_view(*canvas) : json(); if (index != current) out["note"] = "The Preview shows plate " + std::to_string(current) + "; show plate " + std::to_string(index) + - " there (run_action orca_command:plate_goto:orca, param \"" + std::to_string(index) + "\") to read its legend"; + " there (run_action orca_command:plate_goto:orca, args {\"plate\": " + std::to_string(index) + "}) to read its legend"; else if (!shown) out["note"] = "The Preview has not loaded this plate's toolpaths; show it with set_view {\"tab\": \"preview\"}"; } @@ -666,8 +665,8 @@ void register_view_tools(McpService& service) tabs.insert(tabs.begin() + 1, "design"); #endif - reg.add(reaching({"show_layer_range"}, mutate_tool( - "set_view", L("Point the view"), + catalog.add(reaching({"show_layer_range"}, mutate_tool( + "ui", "set_view", L("Point the view"), "Set up what the window shows, for screenshots and GUI work: the main tab, the 3D view (canvas: Prepare's, the " "preview or the assemble view, which has its own gizmos), the camera of the 3D view shown (a named direction, the " "default view, or fit to bed / objects / selection, then look_at, the point it looks at, an orbit to look from " @@ -683,7 +682,7 @@ void register_view_tools(McpService& service) "Camera direction or fit.")}, {"look_at", array_prop({{"type", "number"}}, "[x, y, z] in mm: the point the camera looks at, in the 3D view's " "world coordinates, as list_objects gives positions; on the Design tab, " - "the Design view's, which the CAD tools' world points use (describe_scene's " + "the Design view's, which the Design commands' world points use (describe_scene's " "modeling_origin is the sketch planes' origin). The camera moves " "parallel, keeping its direction and distance. After camera.")}, {"orbit", array_prop({{"type", "number"}}, "[yaw, pitch] in degrees: move the camera around what it looks at, " diff --git a/src/slic3r/GUI/Mcp/McpTypes.hpp b/src/slic3r/GUI/Mcp/McpTypes.hpp index e579d863c3..c04422e656 100644 --- a/src/slic3r/GUI/Mcp/McpTypes.hpp +++ b/src/slic3r/GUI/Mcp/McpTypes.hpp @@ -14,7 +14,18 @@ #include <utility> #include <vector> -namespace Slic3r { namespace GUI { namespace Mcp { +namespace Slic3r { namespace GUI { + +// Defined in ActionRegistry.hpp, which brings in wx: a ToolResult only holds one through a shared_ptr, which +// the code that makes one (NativeCommands.cpp) completes. +struct AppActionRunResult; +// Defined in CommandCatalog.hpp, which includes this header. +struct NativeCommand; +class CommandCatalog; + +namespace Mcp { + +class McpService; // The name of a top-level window the MCP GUI tools never see: list_widgets and locators skip it, // run_javascript never picks its web views, keys sent without a target never go to it, window screenshots leave it @@ -33,12 +44,6 @@ inline constexpr char kSecretField[] = "OrcaSecretForMcp"; // app; everything else is Mutate and is refused in both situations. enum class GuardClass { Inspect, Recover, Mutate }; -// Which way a tool acts, for the agent choosing one: Core tools run the session and recover from -// dialogs, Api tools act on project data by index and name with JSON in and out, Ui tools drive -// the GUI itself (refs, pixels, GUI commands). Every caller reaches every tool; the lane is a hint, -// shown at the start of each description and ordering tools/list and the server instructions. -enum class ToolLane { Core, Api, Ui }; - // A tool's outcome in protocol-neutral form. `data` is the JSON the model receives as text (and a // script evaluates `expect` against); `content` carries extra MCP content blocks such as images. struct ToolResult @@ -47,6 +52,9 @@ struct ToolResult std::vector<nlohmann::json> content; bool is_error = false; std::string message; + // What a person's pick of the command shows, in the UI's language (NativeCommands::notify_result()); + // null for a result that shows nothing. + std::shared_ptr<const AppActionRunResult> notice; static ToolResult ok(nlohmann::json data = nlohmann::json::object()) { @@ -73,12 +81,25 @@ struct ToolFailure : std::runtime_error {} }; -// The services a handler gets for one call. Handlers run on a request or job thread, never on the -// UI thread; everything that touches wx goes through run_ui(). +// The services a handler gets for one call. A client's call, a replay's and a script's run on a request or +// job thread, never on the UI thread, and everything that touches wx goes through run_ui(); a person's pick +// runs on the UI thread (person()). class ToolContext { public: virtual ~ToolContext() = default; + // True for a person's pick from the Speed Dial or a menu: the call is on the UI thread and has no job. + virtual bool person() const { return false; } + // The MCP service the call runs under: what a command that reaches the automation runtime (jobs, the + // journal, recordings, the UI inspector) reads it from, so that the catalog is built without a service. + // Throws when the call has none: std::logic_error here, ToolFailure where one cannot be started. + virtual McpService& service() { throw std::logic_error("This call runs without an MCP service"); } + // Starts command `key` with `args` as a job and returns at once, as the reply to a long command that a + // person picks. Throws ToolFailure where this call cannot start a job. + virtual ToolResult submit(const std::string& key, const nlohmann::json& /*args*/) + { + throw ToolFailure("This call cannot start " + key + " as a job"); + } // Runs `fn` on the UI thread under the tool's guard class and returns its value. Throws // ToolFailure when a guard refuses the call, the UI does not pick it up in time, or the app is // closing. @@ -118,110 +139,49 @@ public: } }; -using ToolHandler = std::function<ToolResult(const nlohmann::json& args, ToolContext& ctx)>; - -struct ToolDef -{ - std::string name; - std::string title; - std::string description; - nlohmann::json input_schema = {{"type", "object"}, {"properties", nlohmann::json::object()}}; - // ToolRegistry::add sets it from tool_lane(). - ToolLane lane = ToolLane::Api; - // The tool's access label, sent as MCP's annotations. Clients act on them: Codex asks a person before every call - // of a destructive tool, and Claude Code runs read-only calls in parallel and retries idempotent ones. read_only: - // it changes nothing in the app or the project; screenshot is, since its PNG replaces no file without overwrite, - // and export_replay, which can clear the journal, is not. destructive: every call deletes what a person made, with - // no undo: delete_preset. A tool that can lose work only when an argument asks for it is not: new_project, - // generate_calibration_test and open_files drop unsaved changes only with discard_changes, an output replaces a file only with - // overwrite, and encode_recording deletes its source only with delete_source. Nor is a tool that runs what its - // arguments name (click and the other input tools, run_action, call_tool, run_replay, run_script), though what it runs may be. The - // client sees both in the arguments, and the label would ask on every call. open_world: it can reach outside - // OrcaSlicer (a printer, the cloud account, the network, or anything the computer allows), including through what - // it runs. - bool read_only = false; - bool destructive = false; - bool idempotent = false; - bool open_world = false; - GuardClass guard = GuardClass::Mutate; - // Pure observation: runs on the request thread and is never a job. Everything that can activate - // UI runs as a job instead, because activating UI can open a modal that blocks the call. - bool inline_call = false; - // May run while an MCP slice/export operation holds the project (cancel_job). - bool allowed_during_operation = false; - // `cancel_job {job}` stops a running call of this tool that is not an operation (encode_recording): the - // handler sees ToolContext::cancelled() and ends. - bool cancellable = false; - // Recorded by the session journal for export_replay. Observation tools turn this off, except - // wait and screenshot, which a replay needs. - bool journal = true; - // How long a call may run before the reply returns a job envelope and the call continues. - int budget_ms = 45000; - // The operations (GUI/Operations) the handler reaches, by function name. A tool that changes something - // names them or is on the exception list of the catalog test; no listing shows the field. - std::vector<std::string> operations; - ToolHandler handler; -}; - -// The lane of the tool `name`: the session and recovery tools and Python are Core, the GUI-driving -// tools Ui, everything else (the typed tools, call_tool, plugin operations) Api. -ToolLane tool_lane(const std::string& name); -// "core", "api" or "ui": the tag that starts each tool's description. -const char* lane_name(ToolLane lane); - -class ToolRegistry -{ -public: - // Adds or replaces a tool, setting its lane from tool_lane() and starting its description with the - // lane's tag in brackets. - void add(ToolDef def); - const ToolDef* find(const std::string& name) const; - const std::vector<ToolDef>& tools() const { return m_tools; } - // Resolves names the table does not hold (plugin operations), which tools/list never shows. Set once, - // before any call. - void set_dynamic(std::function<std::shared_ptr<const ToolDef>(const std::string&)> resolver) { m_dynamic = std::move(resolver); } - // A registered tool, else one the resolver gives, or nullptr. The pointer keeps a resolved tool alive - // through its call. - std::shared_ptr<const ToolDef> lookup(const std::string& name) const; - // Up to `limit` registered names closest to `name`, for "did you mean" errors. - std::vector<std::string> similar(const std::string& name, std::size_t limit = 3) const; - // Says where a name lookup() does not resolve belongs when another catalog has it (a CAD tool, a - // Speed Dial action), as a clause for the error: "it is a CAD tool: call_cad_tool ... runs it". - // Called on any thread. Set once, before any call. - void set_elsewhere(std::function<std::string(const std::string&)> hint) { m_elsewhere = std::move(hint); } - // The error for a name lookup() does not resolve: "Unknown tool: <name>", then where the name does - // belong (set_elsewhere), or else, with `suggest`, the closest registered name. - std::string unknown_tool(const std::string& name, bool suggest = false) const; - -private: - std::vector<ToolDef> m_tools; - std::function<std::shared_ptr<const ToolDef>(const std::string&)> m_dynamic; - std::function<std::string(const std::string&)> m_elsewhere; -}; - -// For a call of call_tool ({tool, args}): replaces `def` and `args` with its target's, normalized and +// For a call of call_tool ({tool, args}): replaces `command` and `args` with its target's, normalized and // validated, so the call runs and is journaled as the target's own. Returns an error message, or "" (also -// for any other tool, which it leaves as it is). -std::string resolve_api_call(const ToolRegistry& registry, std::shared_ptr<const ToolDef>& def, nlohmann::json& args); +// for any other command, which it leaves as it is). +std::string resolve_call(const CommandCatalog& catalog, std::shared_ptr<const NativeCommand>& command, nlohmann::json& args); -// Executes a tool for the protocol layer: the service implementation adds jobs, budgets, guards -// and the journal; tests call the handler directly. +// Executes a command for the protocol layer: the service implementation adds jobs, budgets, guards +// and the journal; tests call the command's function directly. class ToolCaller { public: virtual ~ToolCaller() = default; - virtual ToolResult call(const ToolDef& def, const nlohmann::json& args) = 0; + virtual ToolResult call(const NativeCommand& command, const nlohmann::json& args) = 0; }; +// ---- arguments and name matching (McpArguments.cpp) ------------------------------------------ + // Validates `args` against the subset of JSON Schema the tool catalog uses (object properties with -// type, enum, minimum/maximum, required, additionalProperties:false, array items). Returns an empty -// string when valid, else a message naming the offending property. +// type, enum, minimum/maximum, required, additionalProperties:false, array items, and the +// "if": {"minProperties": 1}, "then": {"required": [...]} of with_silent()). Returns an empty string when +// valid, else a message naming the offending property. std::string validate_arguments(const nlohmann::json& schema, const nlohmann::json& args); +// Whether `args` asks for a command's person's form: an object with no members, or null. A command that has +// a person's form and a silent one does the person's then (it asks, as a person's pick does), and the +// silent one when it is given any argument. +bool person_form(const nlohmann::json& args); +// `args` without `silent`, which only chooses the silent form. +nlohmann::json silent_args(nlohmann::json args); +// The schema of a two-form command from its silent form's `schema`: it gains the property `silent`, which +// takes only true and asks for the silent form with its defaults, and a top-level `required` list moves to +// "if": {"minProperties": 1}, "then": {"required": [...]}, since the call with no arguments, the person's +// form, needs none of them. +nlohmann::json with_silent(nlohmann::json schema); + +// Readies a call's arguments for `command`, as every caller of a command does: normalizes `args` in place +// (normalize_arguments()) and returns why validate_arguments() refuses them; empty when they are valid. +std::string argument_error(const NativeCommand& command, nlohmann::json& args); + // Rewrites, before validation, what agents often send in place of what the schema asks for: an // argument under a name the tool does not take but that stands for one it does, which the call leaves // out and the value fits (ref for target, key for keys, text for value, action for id or button, object for objects, -// plate for plates, filter for query, settings for values, path for save_path), a value written in +// plate for plates, filter for query, settings for values, path for save_path, index for feature, params or +// values for fields), a value written in // another JSON form (a number, boolean, array or object as a string, a single item for an array), // a value outside its argument's enum that only one omitted argument's enum takes (set_view's canvas // "front" as camera), and the x and y, or width and height, that list_windows reports, both given, as @@ -229,4 +189,24 @@ std::string validate_arguments(const nlohmann::json& schema, const nlohmann::jso // that still does not fit is left for validate_arguments to report. void normalize_arguments(const nlohmann::json& schema, nlohmann::json& args); +// The Levenshtein distance between `a` and `b`: the fewest insertions, deletions and substitutions of one +// character that turn one into the other. A "did you mean" ranks the names a mistyped one may stand for by it, +// each lookup with its own threshold. +std::size_t edit_distance(const std::string& a, const std::string& b); + +// The words of a search query: lower case, split at anything but a letter or a digit. "to" or "of" +// starts a word of most help texts, so words of fewer than three letters are left out when the query +// has longer ones. +std::vector<std::string> query_words(const std::string& query); + +// How well an entry matches the words of query_words(): {words found in `name` or `text`, of them those +// found in `name`}, {0, 0} when none is. A word is found where a word of the text starts with it, so +// "retract" finds "retraction"; the text's words are split at underscores, dots and the like and also +// at a capital in a CamelCase name, so "mesh" finds TriangleMesh. +std::pair<int, int> match_score(const std::vector<std::string>& words, const std::string& name, const std::string& text); + +// The first sentence of `text` on one line, for a listing: up to the first full stop followed by a space +// or the end, "e.g." and "i.e." aside; the whole text when it has none. +std::string first_sentence(const std::string& text); + }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/RecordingSettings.cpp b/src/slic3r/GUI/Mcp/RecordingSettings.cpp index 7af549ee37..bd00a30790 100644 --- a/src/slic3r/GUI/Mcp/RecordingSettings.cpp +++ b/src/slic3r/GUI/Mcp/RecordingSettings.cpp @@ -1,11 +1,9 @@ #include "RecordingSettings.hpp" -#include "McpPaths.hpp" #include "VideoEncode.hpp" #include "libslic3r/AppConfig.hpp" #include "slic3r/GUI/I18N.hpp" -#include <boost/filesystem/path.hpp> #include <nlohmann/json.hpp> #include <algorithm> @@ -116,16 +114,8 @@ void save_recording_settings(AppConfig& config, const RecordingSettings& setting config.set(kSection, "folder", settings.folder); } -std::string apply_recording_overrides(RecordingSettings& settings, const json& overrides, bool& silent) +std::string apply_recording_overrides(RecordingSettings& settings, const json& overrides) { - if (!overrides.is_object()) - return "the parameter must be a JSON object"; - static const std::vector<std::string> keys{"quality", "captions", "pointer", "encode", "encode_preset", "codec", - "crf", "speed", "profile", "folder", "silent"}; - for (const auto& [key, value] : overrides.items()) - if (!listed(keys, key)) - return "unknown key \"" + key + - "\": quality, captions, pointer, encode, encode_preset, codec, crf, speed, profile, folder or silent"; const auto integer = [&](const char* key, int min, int max, int& out) -> std::string { if (!overrides.contains(key)) return {}; @@ -154,7 +144,6 @@ std::string apply_recording_overrides(RecordingSettings& settings, const json& o }; RecordingSettings s = settings; - bool quiet = false; std::string err; if (overrides.contains("encode_preset")) { const json& v = overrides["encode_preset"]; @@ -167,10 +156,8 @@ std::string apply_recording_overrides(RecordingSettings& settings, const json& o } apply_encode_preset(s, *p); } - if (!(err = integer("quality", kMinQuality, kMaxQuality, s.quality)).empty() || !(err = flag("captions", s.captions)).empty() || - !(err = flag("pointer", s.pointer)).empty() || !(err = flag("encode", s.encode)).empty() || - !(err = text("codec", {"h265", "h264"}, s.codec)).empty() || !(err = integer("crf", 0, kMaxCrf, s.crf)).empty() || - !(err = text("speed", encoder_speeds(), s.speed)).empty() || !(err = flag("silent", quiet)).empty()) + if (!(err = flag("encode", s.encode)).empty() || !(err = text("codec", {"h265", "h264"}, s.codec)).empty() || + !(err = integer("crf", 0, kMaxCrf, s.crf)).empty() || !(err = text("speed", encoder_speeds(), s.speed)).empty()) return err; if (overrides.contains("profile")) { if (!(err = text("profile", codec_profiles(s.codec), s.profile)).empty()) @@ -178,17 +165,7 @@ std::string apply_recording_overrides(RecordingSettings& settings, const json& o } else { fit_profile(s); } - if (overrides.contains("folder")) { - const json& v = overrides["folder"]; - if (!v.is_string()) - return "folder must be the path of an existing directory"; - const auto dir = resolve_output_dir(v.get<std::string>(), err); - if (!dir) - return "folder: " + err; - s.folder = path_to_utf8(*dir); - } settings = s; - silent = quiet; return {}; } diff --git a/src/slic3r/GUI/Mcp/RecordingSettings.hpp b/src/slic3r/GUI/Mcp/RecordingSettings.hpp index b756573efb..f16fe8006e 100644 --- a/src/slic3r/GUI/Mcp/RecordingSettings.hpp +++ b/src/slic3r/GUI/Mcp/RecordingSettings.hpp @@ -56,12 +56,11 @@ std::string matching_encode_preset(const RecordingSettings& settings); RecordingSettings load_recording_settings(const AppConfig& config); void save_recording_settings(AppConfig& config, const RecordingSettings& settings); -// Applies Start Recording's parameter, an object with any of quality, captions, pointer, encode, encode_preset, -// codec, crf, speed, profile, folder (an existing directory, absolute) and silent: encode_preset's fields first, then the -// fields it names. A codec named without a profile takes the codec's default profile when the one it had does -// not fit. Returns what is wrong, "" when nothing; `settings` is then unchanged. `silent` is true when the -// parameter says so. -std::string apply_recording_overrides(RecordingSettings& settings, const nlohmann::json& overrides, bool& silent); +// Applies start_recording's encode arguments, an object with any of encode, encode_preset, codec, crf, speed and +// profile, other keys left alone: encode_preset's fields first, then the fields it names. A codec named without a +// profile takes the codec's default profile when the one it had does not fit. Returns what is wrong, "" when +// nothing; `settings` is then unchanged. +std::string apply_recording_overrides(RecordingSettings& settings, const nlohmann::json& overrides); // encode_recording's arguments for the recording at `path` (UTF-8). nlohmann::json encode_arguments(const RecordingSettings& settings, const std::string& path); diff --git a/src/slic3r/GUI/Mcp/UiInspector.cpp b/src/slic3r/GUI/Mcp/UiInspector.cpp index 64decc887a..724ad9daba 100644 --- a/src/slic3r/GUI/Mcp/UiInspector.cpp +++ b/src/slic3r/GUI/Mcp/UiInspector.cpp @@ -3610,7 +3610,7 @@ json UiInspector::mouse(GLCanvas3D& canvas, const json& g, const std::string& ow if (p.is_array() && p.size() != 2) throw ToolFailure("A pixel is [x, y]"); if (!p.is_array() && design) - throw ToolFailure("Points of the model name Prepare objects; on the Design view give x/y (call_cad_tool query_topology gives faces)"); + throw ToolFailure("Points of the model name Prepare objects; on the Design view give x/y (query_topology gives faces)"); const wxPoint px = p.is_array() ? wxPoint(p[0].get<int>(), p[1].get<int>()) : target_pixel(canvas, p, check, tolerance); pixels.push_back({px.x, px.y}); return px; diff --git a/src/slic3r/GUI/Mcp/VideoOverlay.cpp b/src/slic3r/GUI/Mcp/VideoOverlay.cpp index d37360064a..765cce0ab2 100644 --- a/src/slic3r/GUI/Mcp/VideoOverlay.cpp +++ b/src/slic3r/GUI/Mcp/VideoOverlay.cpp @@ -435,12 +435,13 @@ double fade(CaptionBoard::Clock::duration since, CaptionBoard::Clock::duration l } // namespace -void CaptionBoard::call_started(uint64_t id, std::string title, std::string detail, Clock::time_point) +void CaptionBoard::call_started(uint64_t id, std::string title, std::string detail, Clock::time_point, std::string context) { Call c; - c.id = id; - c.title = std::move(title); - c.detail = std::move(detail); + c.id = id; + c.title = std::move(title); + c.context = std::move(context); + c.detail = std::move(detail); m_calls.push_back(std::move(c)); // A burst of quick calls, all lingering at once: the oldest finished ones go. Running calls stay, so a // replay still running shows again once its steps have faded; they are few (a replay and its step). @@ -478,9 +479,10 @@ std::optional<CaptionBoard::Line> CaptionBoard::current(Clock::time_point now) return std::nullopt; const Call& c = m_calls.back(); Line l; - l.id = c.id; - l.title = c.title; - l.detail = c.detail; + l.id = c.id; + l.title = c.title; + l.context = c.context; + l.detail = c.detail; l.error = c.status == CaptionStatus::Failed ? c.error : std::string(); l.status = c.status; l.alpha = c.status == CaptionStatus::Running ? 1. : fade(now - c.ended, kLinger); @@ -681,8 +683,13 @@ std::string caption_detail(const std::string& tool, const json& args) parts.push_back(p.get<std::string>()); return join(parts); } - if (kind == "command") - return str(what, "key") + (what.contains("param") ? " " + scalar_text(what["param"]) : ""); + if (kind == "command") { + std::vector<std::string> args; + for (const json& a : what.value("args", json::array())) + if (a.is_string()) + args.push_back(a.get<std::string>()); + return str(what, "key") + (args.empty() ? "" : " " + join(args)); + } if (kind == "plates") { const json& plates = what["plates"]; if (plates.is_array()) { diff --git a/src/slic3r/GUI/Mcp/VideoOverlay.hpp b/src/slic3r/GUI/Mcp/VideoOverlay.hpp index 8f2a9ee241..bf4ccfe831 100644 --- a/src/slic3r/GUI/Mcp/VideoOverlay.hpp +++ b/src/slic3r/GUI/Mcp/VideoOverlay.hpp @@ -180,14 +180,16 @@ public: static constexpr auto kLinger = std::chrono::milliseconds(4000); // after a call ends static constexpr auto kFade = std::chrono::milliseconds(500); - void call_started(uint64_t id, std::string title, std::string detail, Clock::time_point now); + // `context` is the msgctxt `title` is translated in (title_context()), empty for none. + void call_started(uint64_t id, std::string title, std::string detail, Clock::time_point now, std::string context = {}); void call_detail(uint64_t id, std::string detail); void call_ended(uint64_t id, bool ok, std::string error, Clock::time_point now); struct Line { uint64_t id = 0; - std::string title; // untranslated tool title + std::string title; // untranslated tool title + std::string context; // the msgctxt it is translated in, empty for none std::string detail; std::string error; // a failed call's CaptionStatus status = CaptionStatus::Running; @@ -200,7 +202,7 @@ private: struct Call { uint64_t id = 0; - std::string title, detail, error; + std::string title, context, detail, error; CaptionStatus status = CaptionStatus::Running; Clock::time_point ended; }; diff --git a/src/slic3r/GUI/NativeCommands.cpp b/src/slic3r/GUI/NativeCommands.cpp index 3228103557..4c5d0ea3ba 100644 --- a/src/slic3r/GUI/NativeCommands.cpp +++ b/src/slic3r/GUI/NativeCommands.cpp @@ -2,6 +2,7 @@ #include "calib_dlg.hpp" #include "Camera.hpp" +#include "CommandCatalog.hpp" #include "CreatePresetsDialog.hpp" #include "DailyTips.hpp" #include "GLCanvas3D.hpp" @@ -19,6 +20,7 @@ #include "RunScriptPanel.hpp" #include "ObjectDataViewModel.hpp" #include "NetworkTestDialog.hpp" +#include "Notebook.hpp" #include "Operations/ExportOps.hpp" #include "Operations/Outcome.hpp" #include "Operations/PlateOps.hpp" @@ -34,26 +36,28 @@ #include "format.hpp" #include "DeviceCore/DevManager.h" #include "Mcp/McpPaths.hpp" +#include "Mcp/McpPersonContext.hpp" #include "Mcp/McpRecorder.hpp" #include "Mcp/McpService.hpp" +#include "Mcp/McpTools.hpp" +#ifdef SLIC3R_CAD +#include "CAD/DesignPanel.hpp" +#include "Mcp/McpToolsCad.hpp" +#endif #include "Mcp/McpTypes.hpp" #include "Mcp/RecordingSettings.hpp" #include "Mcp/ScreenCapture.hpp" +#include "Mcp/UiInvoker.hpp" #include "Mcp/VideoEncode.hpp" #include "NotificationManager.hpp" #include "libslic3r/AppConfig.hpp" #include "libslic3r/Config.hpp" -#include "libslic3r/LocalesUtils.hpp" #include "libslic3r/Preset.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/Utils.hpp" -#include <boost/algorithm/string/classification.hpp> -#include <boost/algorithm/string/constants.hpp> #include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/predicate.hpp> -#include <boost/algorithm/string/split.hpp> -#include <boost/algorithm/string/trim.hpp> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> #include <nlohmann/json.hpp> @@ -63,7 +67,7 @@ #include <nlohmann/json.hpp> #include <algorithm> -#include <charconv> +#include <atomic> #include <cmath> #include <cstddef> #include <cstdint> @@ -71,15 +75,17 @@ #include <exception> #include "libslic3r/libslic3r.h" #include <memory> +#include <mutex> #include "slic3r/GUI/ActionRegistry.hpp" #include <optional> #include <set> +#include <stdexcept> #include <string> -#include <system_error> #include <tuple> #include <utility> #include <vector> +#include <wx/app.h> #include <wx/dataview.h> #include <wx/filedlg.h> #include <wx/gdicmn.h> @@ -91,6 +97,8 @@ class wxWindow; namespace Slic3r { namespace GUI { +using nlohmann::json; + namespace { // Plate ops are an FFF feature: SLA has a single plate and no plate UI, gcode-only mode has no @@ -161,6 +169,96 @@ AppActionRunResult orient_all(Plater* plater) return {AppActionRunResult::Level::Success}; } +// How many undo and how many redo items the project's active history lists, as the canvas's Undo and Redo lists +// show them (Plater::undo_redo_string_getter()). Both are counted from the active snapshot, so they change exactly +// when it moves, which is when Plater::undo() or redo() takes back or puts back an entry of the history. +std::pair<int, int> project_history_items(Plater& plater) +{ + const auto count = [&plater](bool undo) { + int items = 0; + const char* text = nullptr; + while (plater.undo_redo_string_getter(undo, items, &text)) + ++items; + return items; + }; + return {count(true), count(false)}; +} + +// The project's Undo, or Redo, as the Edit menu's. Plater::undo() steps back past every snapshot that does not modify +// the project to the nearest one that does and loads it; redo() steps forward the same way. Each leaves the active +// snapshot where it is when there is no such record, while a background job holds the model, and (undo) in the +// assemble view for a record that is not a gizmo's. So the history's items unchanged mean no entry was taken back or +// put back, and changed mean one was. Success is that: an entry of the history taken back or put back, as the Undo +// list shows it. It is not a promise that the project differs afterwards, since the plater classes a snapshot by its +// type, not by what it changed, and an action can leave one that changed nothing (renaming an object to the name it +// has). When no entry moved, a person's pick shows nothing, as the menu does, and an agent's call (`agent`) is +// refused. +AppActionRunResult project_undo_redo(bool redo, bool agent) +{ + Plater* const plater = wxGetApp().plater(); + const std::pair<int, int> before = agent && plater != nullptr ? project_history_items(*plater) : std::pair<int, int>(); + if (plater != nullptr) + redo ? plater->redo() : plater->undo(); + if (agent && (plater == nullptr || project_history_items(*plater) == before)) + throw Mcp::ToolFailure(redo ? "Nothing was redone in the project's history (nothing to put back, or a background job is running)" + : "Nothing was undone in the project's history (nothing to take back, or a background job is running)"); + return {AppActionRunResult::Level::Success, {}, true, json{{"history", "project"}}.dump()}; +} + +// An automated call of Undo, or Redo, on the history args.history names: "design", the Design tab's, or +// "project". Without it the history is the shown tab's, as the Edit menu's Undo and Redo choose it. The reply says +// which history it was and, for the Design tab's, what Mcp::cad_undo_redo() replies. A refusal is thrown as +// Mcp::ToolFailure. +AppActionRunResult undo_redo(const json& args, bool redo) +{ + std::string history = args.value("history", std::string()); + if (history.empty()) { + history = "project"; +#ifdef SLIC3R_CAD + if (MainFrame* mf = wxGetApp().mainframe; mf != nullptr && mf->shown_design_panel() != nullptr) + history = "design"; +#endif + } + if (history == "design") { +#ifdef SLIC3R_CAD + json reply{{"history", "design"}, {"result", Mcp::cad_undo_redo(redo)}}; + return {AppActionRunResult::Level::Success, {}, true, reply.dump()}; +#else + throw Mcp::ToolFailure("The CAD feature is off: this build of OrcaSlicer has no Design tab"); +#endif + } + return project_undo_redo(redo, /*agent=*/true); +} + +// A person's pick of Undo, or Redo: what the Edit menu's item does, on the history args.history names or else the +// shown tab's, through the function the menu calls. It shows nothing: where the menu's item would be greyed it does +// nothing, and otherwise the Design tab's status line or the canvas shows what changed, as after the menu's. +AppActionRunResult picked_undo_redo(const json& args, bool redo) +{ + const std::string history = args.value("history", std::string()); + // What a pick that does nothing shows: nothing. + const AppActionRunResult greyed{AppActionRunResult::Level::Info, {}, false}; +#ifdef SLIC3R_CAD + DesignPanel* design = nullptr; + if (history.empty()) { + if (MainFrame* mf = wxGetApp().mainframe) + design = mf->shown_design_panel(); + } else if (history == "design") + design = DesignPanel::if_built(); + if (design != nullptr || history == "design") { + if (design == nullptr || !design->menu_can_undo_redo(redo)) + return greyed; + design->menu_undo_redo(redo); + return {AppActionRunResult::Level::Success, {}, true, json{{"history", "design"}}.dump()}; + } +#else + // A build without CAD has no Design tab, so no history of it to take back. + if (history == "design") + return greyed; +#endif + return project_undo_redo(redo, /*agent=*/false); +} + // The object list, once the Prepare view is shown; the object structure commands act on its selected // rows, as the context menu items they stand for do. ObjectList* object_list_in_3d_view() @@ -217,12 +315,8 @@ AppActionRunResult ordered(Plater& plater, ObjectOrder order, bool all_plates) // Jumps the Preview to the layer a 0-100 percent of its layers stands for. The percent moves the top // of the shown range; its bottom stays. The caller has already switched to the Preview. -AppActionRunResult go_to_layer(const std::string& param) +AppActionRunResult go_to_layer(double pct) { - double pct = 50.0; - try { - pct = std::stod(param); - } catch (const std::exception&) {} pct = std::clamp(pct, 0.0, 100.0); const Ops::Outcome<int> count = Ops::layer_count(); @@ -235,20 +329,51 @@ AppActionRunResult go_to_layer(const std::string& param) return {AppActionRunResult::Level::Success}; } -// The path a command was given, checked for reading (`output` false) or writing. nullopt with an -// Error in `fail` when the parameter is unusable. -std::optional<boost::filesystem::path> path_param(const std::string& param, bool output, AppActionRunResult& fail) +// The file `args` names ({"path", "overwrite"?}), checked for reading (`output` false) or for writing, where +// a file that exists is replaced only with overwrite. nullopt with an Error in `fail` when the path is +// missing or unusable. +std::optional<boost::filesystem::path> path_argument(const json& args, bool output, AppActionRunResult& fail) { - std::string err; - auto pp = Mcp::parse_path_param(param, err); + std::string err = "path is required"; std::optional<boost::filesystem::path> path; - if (pp) - path = output ? Mcp::resolve_output_path(pp->path, pp->overwrite, err) : Mcp::resolve_input_path(pp->path, err); + if (const std::string given = args.value("path", std::string()); !given.empty()) + path = output ? Mcp::resolve_output_path(given, args.value("overwrite", false), err) : Mcp::resolve_input_path(given, err); if (!path) fail = {AppActionRunResult::Level::Error, from_u8(err)}; return path; } +// The existing directory `args` names ({"path"}), for an export of several files. nullopt with an Error in +// `fail` when the path is missing or no directory. +std::optional<boost::filesystem::path> dir_argument(const json& args, AppActionRunResult& fail) +{ + std::string err = "path is required"; + std::optional<boost::filesystem::path> dir; + if (const std::string given = args.value("path", std::string()); !given.empty()) + dir = Mcp::resolve_output_dir(given, err); + if (!dir) + fail = {AppActionRunResult::Level::Error, from_u8(err)}; + return dir; +} + +// The plater of the running app, or nullptr: before the main window is up, and in a unit test, which has no +// GUI_App. +Plater* app_plater() +{ + auto* app = dynamic_cast<GUI_App*>(wxTheApp); + return app != nullptr ? app->plater() : nullptr; +} + +const char* level_name(AppActionRunResult::Level level) +{ + switch (level) { + case AppActionRunResult::Level::Success: return "success"; + case AppActionRunResult::Level::Error: return "error"; + case AppActionRunResult::Level::Busy: return "busy"; + default: return "info"; + } +} + // What a command that wrote `path` answers, or its operation's refusal. AppActionRunResult written(const Ops::Outcome<Ops::Done>& outcome, const boost::filesystem::path& path) { @@ -277,14 +402,15 @@ void notify_error(const wxString& text) NotificationManager::NotificationLevel::ErrorNotificationLevel, into_u8(text)); } -// Recordings are the MCP service's. With the server off, Start Recording starts the service without its endpoint, -// as the Run Script dialog does. nullptr while OrcaSlicer closes. +// Recordings are the MCP service's: the one a person's pick reaches (Mcp::PersonContext::service()), which with the +// server off is started without its endpoint. nullptr when it cannot start, as while OrcaSlicer closes. Mcp::McpService* recording_service() { - if (Mcp::McpService* s = wxGetApp().mcp_service(); s == nullptr || !s->started()) - wxGetApp().start_mcp_service(false); - Mcp::McpService* s = wxGetApp().mcp_service(); - return s != nullptr && s->started() && !s->stopping() ? s : nullptr; + try { + return &Mcp::PersonContext().service(); + } catch (const Mcp::ToolFailure&) { + return nullptr; + } } // Encodes the recording at `path` to an MP4 beside it once its file is closed, and tells the person how that @@ -303,38 +429,26 @@ bool encode_when_closed(const boost::filesystem::path& path, const Mcp::Recordin }); } -// The person's recording: the main window, with the overlays the settings ask for, for up to an hour, -// into the folder the settings name. The dialog shows the remembered settings, with what `param` overrides, -// and remembers what it starts with; a silent `param` starts with them at once and remembers -// nothing. Encoding needs an ffmpeg: the dialog says so and records without encoding, and a silent start that -// would encode is refused. Neither a run's end nor the server turning off ends the recording. Whatever does -// end it says where it went: Stop Recording itself, or the recording's `ended` for an agent's stop_recording, -// the limit or a write error; with encode, `ended` also encodes it. -AppActionRunResult start_recording(const std::string& param) +} // namespace + +// The dialog shows the remembered settings and remembers what it starts with. Encoding needs an ffmpeg: the +// dialog says so, and the recording is then not encoded. Neither a run's end nor the server turning off ends +// the recording. Whatever does end it says where it went: Stop Recording itself, or the recording's `ended` for +// an agent's stop_recording, the limit or a write error; with encode, `ended` also encodes it. +AppActionRunResult NativeCommands::start_person_recording() { - if (NativeCommands::recording_active()) + if (recording_active()) return {AppActionRunResult::Level::Info, _L("A recording is already running."), false}; AppConfig& config = *wxGetApp().app_config; Mcp::RecordingSettings settings = Mcp::load_recording_settings(config); - bool silent = false; - if (!param.empty()) - if (const std::string err = Mcp::apply_recording_overrides(settings, nlohmann::json::parse(param, nullptr, false), silent); - !err.empty()) - return {AppActionRunResult::Level::Error, from_u8(err), false}; - std::string ffmpeg_err; - const bool has_ffmpeg = Mcp::find_ffmpeg(ffmpeg_err).has_value(); - if (silent && settings.encode && !has_ffmpeg) - // TRN %1% is why, in English. - return {AppActionRunResult::Level::Error, - format_wxstr(_L("The recording could not be encoded: %1%. Install ffmpeg, or start without encoding."), ffmpeg_err), false}; - if (!silent) { - RecordingDialog dialog(wxGetApp().mainframe, settings); - if (dialog.ShowModal() != wxID_OK) - return {AppActionRunResult::Level::Info, _L("Recording cancelled."), false}; - settings = dialog.settings(); - Mcp::save_recording_settings(config, settings); - config.save(); - } + std::string ffmpeg_err; + const bool has_ffmpeg = Mcp::find_ffmpeg(ffmpeg_err).has_value(); + RecordingDialog dialog(wxGetApp().mainframe, settings); + if (dialog.ShowModal() != wxID_OK) + return {AppActionRunResult::Level::Info, _L("Recording cancelled."), false}; + settings = dialog.settings(); + Mcp::save_recording_settings(config, settings); + config.save(); Mcp::McpService* service = recording_service(); if (service == nullptr) @@ -374,6 +488,24 @@ AppActionRunResult start_recording(const std::string& param) return {AppActionRunResult::Level::Success, _L("Recording started. Stop Recording saves it."), true, reply.dump()}; } +AppActionRunResult NativeCommands::stop_recording_in_app() +{ + Mcp::McpService* service = wxGetApp().mcp_service(); + const nlohmann::json state = service != nullptr && service->started() ? service->recorder().state() : nlohmann::json(); + if (state.is_null() || state.value("ending", false)) + return AppActionRunResult{AppActionRunResult::Level::Info, _L("No recording is running."), false}; + // What the window shows now, even if the timer has not ticked since, before the notification shows. + service->recorder().capture_now(); + // The recording may be an agent's, a replay's or a script's; the person stopped it all the same, so they are told + // where it went. Before it ends: a person's recording that is to be encoded says so instead, as it ends. + const boost::filesystem::path path = Mcp::path_from_utf8(state["path"].get<std::string>()); + notify_saved(_L("Recording saved"), path); + service->recorder().end(kStoppedInApp); + return AppActionRunResult{AppActionRunResult::Level::Success, {}, true, path_reply(path)}; +} + +namespace { + // Select a named camera view. Plater::select_view dispatches to the current panel. AppActionRunResult view_command(Plater* plater, const std::string& dir) { @@ -394,23 +526,6 @@ AppActionRunResult calib_command(CalibKind kind) return {AppActionRunResult::Level::Success}; } -// What import_configs does with a preset that exists already: the `on_conflict` of its param -// {"path": ..., "on_conflict": "skip" | "overwrite"}, skip by default. `overwrite`, which other path -// params use for an output file, is refused rather than ignored. nullopt with an Error in `fail`. -std::optional<bool> import_overwrites(const std::string& param, AppActionRunResult& fail) -{ - const auto first = param.find_first_not_of(" \t"); - if (first == std::string::npos || param[first] != '{') - return false; - const nlohmann::json j = nlohmann::json::parse(param, nullptr, false); - const nlohmann::json conflict = j.is_object() ? j.value("on_conflict", nlohmann::json("skip")) : nlohmann::json(); - if (!j.is_object() || j.contains("overwrite") || (conflict != "skip" && conflict != "overwrite")) { - fail = {AppActionRunResult::Level::Error, "on_conflict is \"skip\" (default) or \"overwrite\": what happens to a preset that exists already"}; - return std::nullopt; - } - return conflict == "overwrite"; -} - // Imports the preset file at `path` (Ops::import_presets()) and words what came of it: the message lists // the presets imported, replaced and kept. AppActionRunResult import_preset_file(const boost::filesystem::path& path, bool overwrite) @@ -436,21 +551,17 @@ AppActionRunResult import_preset_file(const boost::filesystem::path& path, bool return {AppActionRunResult::Level::Success, message}; } -constexpr const char* kCommandPrefix = "orca_command"; - // Thin AppAction wrapper for one catalog entry: identity and presentation come from the catalog, // run() routes back to it. The id is keyed by the stable catalog key (not the display title), so a // rename or a UI-language switch never re-keys the action. struct CommandAction : AppAction { - std::string command_key; + AppActionRunResult run(const json& args) const override { return NativeCommands::run(command, args); } - AppActionRunResult run(const std::string& param) const override { return NativeCommands::run(command_key, param); } - - explicit CommandAction(const NativeCommand& c) - : AppAction(AppActionId{AppAction::compose_id(kCommandPrefix, c.key, kOrcaSourceKey)}, I18N::translate_utf8(c.title), kOrcaSourceKey, + // `title` is the command's title in the UI's language. + CommandAction(const NativeCommand& c, std::string title) + : AppAction(AppActionId{AppAction::compose_id(kCommandPrefix, c.key, kOrcaSourceKey)}, std::move(title), kOrcaSourceKey, kOrcaSourceName) - , command_key(c.key) { this->kind = AppActionKind::Command; this->group = I18N::translate_utf8(c.group); @@ -459,36 +570,35 @@ struct CommandAction : AppAction this->input = c.input; this->icon = c.icon; this->automation_description = c.description; - this->param_type = NativeCommands::param_type_name(c.param.type); - this->param_help = c.param.help; + this->input_schema = c.input_schema; + this->command = c.key; this->completes_in_background = c.completion == CommandCompletion::Export; } }; -// What automation needs to call each command: a description for agents (English, never shown in the -// palette), the meaning of `param`, and whether the effect finishes after run() returns. Commands -// without an entry run immediately and ignore `param`. +// A description of each command for agents (English, never shown in the palette): what it does, what its +// arguments stand for and what it replies. void describe_commands(std::vector<NativeCommand>& commands) { struct Detail { - const char* key; - const char* description; - CommandParamType param = CommandParamType::None; - const char* param_help = ""; - CommandCompletion completion = CommandCompletion::None; + const char* key; + const char* description; }; static const Detail details[] = { {"slice_and_preview", "Slice the current plate and show the Preview tab. Returns at once; use the slice tool to wait for the result."}, {"slice_all", "Slice every plate and show the Preview tab. Returns at once; use the slice tool to wait for results."}, - {"go_to_layer", "Show the Preview tab at a layer chosen as a percentage of the layer range; an error while the Preview has no layers (slice first).", CommandParamType::Percent, "0-100"}, - {"go_to_tab", "Switch to a main window tab.", CommandParamType::Tab, "tab id: home, prepare, preview, monitor, project, calibration, or a plugin page id"}, - {"load_project", "Open a project. With a path, opens that file without a dialog (asks first if the current project has unsaved changes).", CommandParamType::Path, "absolute path of a .3mf project"}, - {"save_project", "Save the project to its current file (asks for a name if it has none)."}, - {"save_project_as", "Save the project as a .3mf file. With a path, saves there without a dialog; a name ending in .gcode.3mf is refused (export_sliced_file writes that).", CommandParamType::Path, "absolute output path, or {\"path\": ..., \"overwrite\": true}"}, - {"new_project", "Start a new, empty project (asks first if the current one has unsaved changes)."}, - {"undo", "Undo the last change to the project."}, - {"redo", "Redo the last undone change."}, + {"go_to_layer", "Show the Preview tab at a layer chosen as a percentage of the layer range; an error while the Preview has no layers (slice first)."}, + {"go_to_tab", "Switch to a main window tab."}, + {"load_project", "Open a project. With a path, opens that file without a dialog (asks first if the current project has unsaved changes)."}, + {"save_project_as", "Save the project as a .3mf file. With a path, saves there without a dialog; a name ending in .gcode.3mf is refused (export_sliced_file writes that)."}, + {"undo", "Take back the last change of a history, as Edit > Undo does. history design is the Design tab's: the last " + "feature added, edited, deleted, moved, shown or hidden, or renamed, or variable changed, or in a sketch session " + "the last drawn shape; project is the project's. Without history, the Design tab's while it is shown, else the " + "project's. Reply: history and, for the Design tab's, result: scope (design or sketch), undo_depth, redo_depth, " + "features, bodies and generation; entities in a sketch."}, + {"redo", "Put back what undo took back, until the next change, as Edit > Redo does, in the history undo takes. Reply " + "as undo's."}, {"open_action_replay", "Open the Action Replay window, where a person opens a replay file (an orca_replay), reads its steps " "and replays them. Agents run replays with the run_replay tool instead."}, {"toggle_run_script", "Show or hide the Run Script panel, where a person writes and runs Python scripts cell by cell. Agents " @@ -496,58 +606,33 @@ void describe_commands(std::vector<NativeCommand>& commands) {"take_screenshot", "Save a PNG of the main window in the folder Start Recording saves in (the person's Downloads unless " "they chose another) and show the person a notification naming it; the reply has its path. Agents use " "the screenshot tool, which returns the image."}, - {"start_recording", "Start the person's recording of the main window, for up to an hour, with the settings the Start " - "Recording dialog remembers: JPEG quality, whether tool calls are captioned and the pointer highlighted, " - "whether and how it is encoded to MP4 once it ends, and the " - "folder both go in (the person's Downloads unless they chose another). Without silent, the dialog opens " - "with them (the param's values filled in): set its controls with set_widget_value (each is named after its " - "param key) and answer it with answer_dialog \"Start recording\"; it remembers what it starts with. " - "With silent, the recording starts at once and nothing is remembered; one that would encode is refused " - "when no ffmpeg is found. The reply has the path and the settings used. Neither the end of a replay or script " - "nor the server turning off ends it. With encode, the encode starts once the recording's file is closed, as " - "an encode_recording job in get_app_state.jobs: wait {for: \"job\"} with its id returns the MP4's path, or an " - "error. Agents record with start_recording instead.", - CommandParamType::Text, - "JSON object, all optional: quality (30-95), captions (bool), pointer (bool), encode (bool), encode_preset (small, " - "balanced, quality, compatible; applied before the fields), codec (h265, h264), crf (0-51), speed (ultrafast ... " - "veryslow), profile (h264: high, main, baseline; h265: main, main10), folder (absolute path of an existing " - "directory), silent (bool)"}, - {"stop_recording", "Stop the running recording, whoever started it, without waiting for its file, and show the person a " - "notification naming it; the reply has its path. A later stop_recording reports it as ended " - "stopped_in_app. A recording Start Recording made with encode is then encoded: find its " - "encode_recording job in get_app_state.jobs. Agents stop their own recordings with stop_recording, which " - "waits and reports."}, {"open_preferences", "Open the Preferences dialog on a tab, scrolled to one preference when given (shown on its own tab). Its " "controls are named after their preference keys: set_widget_value {\"target\": {\"name\": key, \"within\": " - "\"Preferences\"}} changes one through the dialog; get_settings scope preferences reads them.", - CommandParamType::Text, "general, files, behaviour, control, graphics, online or developer, optionally :<key>, e.g. behaviour:auto_arrange"}, + "\"Preferences\"}} changes one through the dialog; get_settings scope preferences reads them."}, {"mode_simple", "Switch the settings view to Simple mode."}, {"mode_advanced", "Switch the settings view to Advanced mode."}, {"mode_expert", "Switch the settings view to Expert mode."}, {"toggle_developer_mode", "Turn Developer mode on or off."}, - {"export_gcode", "Export the current plate's G-code. With a path, exports there without a dialog once the plate is sliced; the export runs in the background.", CommandParamType::Path, "absolute .gcode path, or {\"path\": ..., \"overwrite\": true}", CommandCompletion::Export}, - {"export_stl", "Export all objects as one STL. With a path, writes there without a dialog.", CommandParamType::Path, "absolute .stl path, or {\"path\": ..., \"overwrite\": true}"}, - {"export_3mf", "Export the model as a .3mf without slicing data. With a path, writes there without a dialog.", CommandParamType::Path, "absolute .3mf path, or {\"path\": ..., \"overwrite\": true}"}, - {"export_sliced_file", "Export the current plate's sliced file (.gcode.3mf). With a path, writes there without a dialog.", CommandParamType::Path, "absolute .3mf path, or {\"path\": ..., \"overwrite\": true}"}, - {"export_all_sliced_file", "Export every plate's sliced file into one .gcode.3mf. With a path, writes there without a dialog.", CommandParamType::Path, "absolute .3mf path, or {\"path\": ..., \"overwrite\": true}"}, + {"export_gcode", "Export the current plate's G-code. With a path, exports there without a dialog once the plate is sliced, in the " + "background, and the call returns when the file is written; with no arguments, it opens the export dialog."}, + {"export_stl", "Export all objects as one STL. With a path, writes there without a dialog."}, + {"export_3mf", "Export the model as a .3mf without slicing data. With a path, writes there without a dialog."}, + {"export_sliced_file", "Export the current plate's sliced file (.gcode.3mf). With a path, writes there without a dialog."}, + {"export_all_sliced_file", "Export every plate's sliced file into one .gcode.3mf. With a path, writes there without a dialog."}, {"send_gcode", "Open the Send G-code to printer host dialog for the current plate, as the Print button does for a printer with a print host (OctoPrint, Moonraker, PrusaLink, Duet...). Set the file name with set_widget_value and press Upload or Upload and Print with answer_dialog; the plate is sliced if needed, then uploaded in the background: get_app_state.uploads shows the row's state, and a failed upload also opens an error dialog. A replay uploads again. Fails for a printer without a print host, or one that prints through the Bambu network or printer agents."}, - {"export_stl_multi", "Export each object as its own STL. With a directory, writes there without a dialog.", CommandParamType::Path, "absolute path of an existing directory"}, + {"export_stl_multi", "Export each object as its own STL. With a directory, writes there without a dialog."}, {"export_drc_single", "Export all objects as one Draco (.drc) file."}, {"export_drc_multi", "Export each object as its own Draco (.drc) file."}, {"export_toolpaths_obj", "Export the sliced toolpaths as an OBJ."}, {"export_config", "Export presets as a bundle or ZIP archives. Opens a dialog: click the label of the kind to export, check " "the presets (their checkboxes are named after them), press OK, then answer the result message. With a " - "directory, OK writes there instead of asking for a folder.", - CommandParamType::Path, "absolute path of an existing directory"}, + "directory, OK writes there instead of asking for a folder."}, {"import_file", "Import models (3MF/STL/STEP/SVG/OBJ/AMF). With a path, adds that file's geometry without a dialog, as one undo step; " - "a project file's settings are not loaded (load_project opens a project).", - CommandParamType::Path, "absolute path of a model file"}, + "a project file's settings are not loaded (load_project opens a project)."}, {"import_zip_archive", "Import models from a ZIP archive (opens a file dialog)."}, {"import_configs", "Import presets. With a path, imports a preset .json, a .zip of them or an .orca_printer, " ".orca_filament or .orca_bundle without a dialog, and the message names the presets imported, " - "replaced and kept; a .gcode loads the settings it was sliced with.", - CommandParamType::Path, "absolute path, or {\"path\": ..., \"on_conflict\": \"overwrite\"} to replace presets that exist " - "already (default \"skip\")"}, + "replaced and kept; a .gcode loads the settings it was sliced with."}, {"view_default", "Reset the 3D camera to the default view and fit the plate."}, {"view_fit_bed", "Fit the build plate in the 3D view."}, {"view_toggle_perspective", "Switch the 3D camera between perspective and orthographic."}, @@ -570,35 +655,35 @@ void describe_commands(std::vector<NativeCommand>& commands) "call returns when the arrangement is done. The arrange tool also takes options, one plate or fill bed."}, {"obj_orient", "Auto-orient the selection, or every object when nothing is selected; the call returns when it is done."}, // Object structure: the object list's Change Type, Rename, instance and Assemble items, and the plate - // menu's Order By. A param stands in for the item's dialog. + // menu's Order By. Arguments stand in for the item's dialog. {"obj_type_part", "Make the selected parts (select_objects {parts} first) solid parts, as Change Type does. Parts are listed by type, so part indices change."}, {"obj_type_negative", "Make the selected parts negative parts, as Change Type does; not the object's last solid part. Parts are listed by type, so part indices change."}, {"obj_type_modifier", "Make the selected parts modifiers, as Change Type does; not the object's last solid part. Parts are listed by type, so part indices change."}, {"obj_type_support_blocker", "Make the selected parts support blockers, as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change."}, {"obj_type_support_enforcer", "Make the selected parts support enforcers, as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change."}, {"obj_type_precise_seam", "Make the selected parts Center precise seams (seams keep their subtype), as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change."}, - {"obj_rename", "Rename the selected object or part (select one). With a name, skips the Rename dialog; a name with characters a file name cannot hold is refused.", CommandParamType::Text, "the new name"}, - {"obj_set_instances", "Give the selected object this many instances, in one undo step. With a number, skips the dialog. New instances overlap; arrange afterwards. The reply has object and instances.", CommandParamType::Index, "total number of instances, 1-1000"}, + {"obj_rename", "Rename the selected object or part (select one). With a name, skips the Rename dialog; an empty name, or one with characters a file name cannot hold, is refused."}, + {"obj_set_instances", "Give the selected object this many instances, in one undo step. With a count, skips the dialog. New instances overlap; arrange afterwards. The reply has object and instances."}, {"obj_assemble", "Assemble two or more selected objects into one object of parts named Assembly. They are removed and it is added last, so object indices change; the reply has its index (object) and name."}, {"obj_instances_to_objects", "Make each instance of the selected object a separate object (select_objects {objects: [n]}); with some of its instances selected, only those. New objects are added last; the reply lists the objects the instances are in now (objects)."}, - {"obj_order_by_name", "Order the current plate's objects by name, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", CommandParamType::Text, "all, to order every plate"}, - {"obj_order_by_filament", "Order the current plate's objects by filament, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", CommandParamType::Text, "all, to order every plate"}, - {"obj_order_by_height", "Order the current plate's objects by height, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", CommandParamType::Text, "all, to order every plate"}, - {"obj_order_by_size", "Order the current plate's objects by size (bounding box volume), which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", CommandParamType::Text, "all, to order every plate"}, - {"add_primitive_svg", "Add an SVG as a new object, or as a part of the selected object. With a path, uses that file without a dialog; the part is created in the background (wait for idle), and the SVG gizmo opens on it.", CommandParamType::Path, "absolute path of an .svg file"}, + {"obj_order_by_name", "Order the current plate's objects by name, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending."}, + {"obj_order_by_filament", "Order the current plate's objects by filament, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending."}, + {"obj_order_by_height", "Order the current plate's objects by height, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending."}, + {"obj_order_by_size", "Order the current plate's objects by size (bounding box volume), which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending."}, + {"add_primitive_svg", "Add an SVG as a new object, or as a part of the selected object. With a path, uses that file without a dialog; the part is created in the background (wait for idle), and the SVG gizmo opens on it."}, // Shapes: a size skips the Primitive size dialog. - {"add_primitive_cube", "Add a cube object to the current plate; fails while an object is selected. With a size, skips the size dialog.", CommandParamType::Text, "X Y Z in mm, separated by spaces"}, - {"add_primitive_cylinder", "Add a cylinder object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", CommandParamType::Text, "diameter and height in mm, separated by a space"}, - {"add_primitive_sphere", "Add a sphere object to the current plate; fails while an object is selected. With a size, skips the size dialog.", CommandParamType::Text, "diameter in mm"}, - {"add_primitive_cone", "Add a cone object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", CommandParamType::Text, "base diameter and height in mm, separated by a space"}, - {"add_primitive_disc", "Add a disc object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", CommandParamType::Text, "diameter and height in mm, separated by a space"}, - {"add_primitive_torus", "Add a torus object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", CommandParamType::Text, "inner diameter and tube diameter in mm, separated by a space"}, + {"add_primitive_cube", "Add a cube object to the current plate; fails while an object is selected. With a size, skips the size dialog."}, + {"add_primitive_cylinder", "Add a cylinder object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn."}, + {"add_primitive_sphere", "Add a sphere object to the current plate; fails while an object is selected. With a size, skips the size dialog."}, + {"add_primitive_cone", "Add a cone object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn."}, + {"add_primitive_disc", "Add a disc object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn."}, + {"add_primitive_torus", "Add a torus object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn."}, {"plate_add", "Add a plate."}, {"plate_duplicate", "Duplicate the current plate."}, {"plate_delete", "Delete the current plate."}, {"plate_rename", "Rename the current plate (opens a dialog)."}, {"plate_toggle_lock", "Lock or unlock the current plate."}, - {"plate_goto", "Make a plate the current one; an index the project lacks is an error.", CommandParamType::Index, "0-based plate index"}, + {"plate_goto", "Make a plate the current one; an index the project lacks is an error."}, {"sync_ams", "Synchronize the filament list from the connected printer's AMS."}, {"preset_bundle", "Open the preset bundle manager."}, {"sync_presets", "Synchronize user presets with the cloud account."}, @@ -619,18 +704,16 @@ void describe_commands(std::vector<NativeCommand>& commands) {"install_plugin", "Open the plugin hub to install a plugin."}, {"install_local_plugin", "Install a plugin from a .py or .whl file, as the Plugins dialog's Install local plugin does. With a " "path, installs that file without a dialog. Replacing a plugin installed already asks first " - "(answer with answer_dialog); the message names the plugin installed, or why it was not.", - CommandParamType::Path, "absolute path of a .py or .whl plugin package"}, + "(answer with answer_dialog); the message names the plugin installed, or why it was not."}, // Filament slots {"filament_add", "Add a filament slot, as the + button above the filament list does; the message names the new slot. It " "takes the next colour and the last slot's preset (change them with select_preset filament_slot and " "set_settings scope project filament_colour). It goes after the physical slots: mixed filaments move " "up by one, and objects on them follow."}, {"filament_delete", "Delete a filament slot, as its Delete menu item does; objects on it move to another slot. A mixed " - "filament (project scope filament_is_mixed) is refused.", CommandParamType::Index, - "1-based filament slot; without it, the last physical slot, as the - button"}, + "filament (project scope filament_is_mixed) is refused."}, }; - // The operations (GUI/Operations) a runner reaches once it has what it needs to run without asking. + // The operations (GUI/Operations) a command reaches once it has what it needs to run without asking. static const std::pair<const char*, std::vector<std::string>> reaches[] = { {"slice_and_preview", {"start_slice"}}, {"slice_all", {"start_slice"}}, @@ -656,8 +739,6 @@ void describe_commands(std::vector<NativeCommand>& commands) auto it = std::find_if(std::begin(details), std::end(details), [&](const Detail& d) { return c.key == d.key; }); if (it != std::end(details)) { c.description = it->description; - c.param = {it->param, it->param_help}; - c.completion = it->completion; } else if (c.key.rfind("calib_", 0) == 0) { c.description = "Open the " + c.title + " dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog."; @@ -669,29 +750,51 @@ void describe_commands(std::vector<NativeCommand>& commands) } } -std::vector<NativeCommand> build_command_catalog() +} // namespace + +void NativeCommands::register_all_commands(CommandCatalog& catalog, [[maybe_unused]] const CatalogOptions& options) { + // The Speed Dial's commands: each has a tile. std::vector<NativeCommand> out; + // Adds `command` with a tile. The reference is valid until the next command is added: long enough to say + // what arguments the command takes, as in add(...).input_schema = Mcp::object_schema({...}). + const auto tile = [&out](NativeCommand command) -> NativeCommand& { + command.in_palette = true; + out.push_back(std::move(command)); + return out.back(); + }; // `title` and `group` are the untranslated English msgids, L("...")-marked at each call so xgettext - // extracts them. - auto add = [&](std::string key, std::string title, std::string group, std::function<AppActionRunResult(const std::string&)> runner, - std::string input = {}, std::string icon = {}) { - out.push_back({std::move(key), std::move(title), std::move(group), std::move(input), std::move(icon), std::move(runner)}); + // extracts them. A command takes no arguments unless its schema is given afterwards; with none, a + // dialog command asks as a person's pick does. + using Body = std::function<AppActionRunResult(const json& args)>; + auto add = [&tile](std::string key, std::string title, std::string group, Body fn, std::string input = {}, + std::string icon = {}) -> NativeCommand& { + NativeCommand& c = tile(ui_command(std::move(key), std::move(title), std::move(group), Mcp::object_schema({}), std::move(fn))); + c.input = std::move(input); + c.icon = std::move(icon); + return c; }; // Presentation-first overload: keeps the tile icon next to the title/group it belongs to. - auto add_with_icon = [&](std::string key, std::string title, std::string group, std::string icon, - std::function<AppActionRunResult(const std::string&)> runner, std::string input = {}) { - add(std::move(key), std::move(title), std::move(group), std::move(runner), std::move(input), std::move(icon)); + auto add_with_icon = [&add](std::string key, std::string title, std::string group, std::string icon, Body fn, + std::string input = {}) -> NativeCommand& { + return add(std::move(key), std::move(title), std::move(group), std::move(fn), std::move(input), std::move(icon)); + }; + // The argument of a command that opens or imports a file, in place of its file dialog. + const auto input_file = [](const char* what) { return Mcp::prop("string", std::string("Absolute path of ") + what + "."); }; + // The arguments of a command that writes a file, in place of its save dialog. + const auto output_file = [](const char* what) { + return Mcp::object_schema({{"path", Mcp::prop("string", std::string("Absolute path of the ") + what + " to write.")}, + {"overwrite", Mcp::prop("boolean", "Replace a file that exists already. Default false.")}}); }; // ---- Slice & Export ---- // Slices through the toolbar's path, so it counts as a user slice request (Plater::request_slice). - add_with_icon("slice_and_preview", L("Slice and Preview"), L("Slice & Export"), "media_play", [](const std::string&) { + add_with_icon("slice_and_preview", L("Slice and Preview"), L("Slice & Export"), "media_play", [](const json&) { if (wxGetApp().plater() != nullptr) Ops::start_slice({}); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("slice_all", L("Slice All Plates"), L("Slice & Export"), "media_play", [](const std::string&) { + add_with_icon("slice_all", L("Slice All Plates"), L("Slice & Export"), "media_play", [](const json&) { if (wxGetApp().plater() != nullptr) { Ops::SliceArgs slice; slice.all_plates = true; @@ -700,114 +803,167 @@ std::vector<NativeCommand> build_command_catalog() return AppActionRunResult{AppActionRunResult::Level::Success}; }); + // Go to layer and Go to tab have one form, which needs its value: the palette collects it in its second + // phase (`input`) and passes it as their argument. add_with_icon( "go_to_layer", L("Go to layer (percent)"), L("Commands"), "height_range_layer", - [](const std::string& param) { + [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{AppActionRunResult::Level::Success}; plater->select_view_3D("Preview", false); if (MainFrame* mf = wxGetApp().mainframe; mf) mf->select_tab(TAB_ID_PREVIEW); - return go_to_layer(param); + return go_to_layer(args.at("percent").get<double>()); }, - "percent"); - - // "go_to_tab" is two-phase: the palette collects the tab after activating it, then hands the tab - // id back as `param` (same contract as go_to_layer's percent). + "percent") + .input_schema = Mcp::object_schema({{"percent", {{"type", "number"}, + {"minimum", 0}, + {"maximum", 100}, + {"description", "The layer to show, as a percentage of the layer range."}}}}, + {"percent"}); add( "go_to_tab", L("Go to tab..."), L("Commands"), - [](const std::string& param) { - if (MainFrame* mf = wxGetApp().mainframe; mf && !param.empty()) - mf->select_tab(from_u8(param)); + [](const json& args) { + MainFrame* mf = wxGetApp().mainframe; + if (mf == nullptr) + return AppActionRunResult{}; + const std::string tab = args.at("tab").get<std::string>(); + // select_tab() shows the last tab for an empty id, and leaves the tab as it is for an id no page has. + if (mf->m_tabpanel == nullptr || mf->m_tabpanel->FindPageByName(from_u8(tab)) == wxNOT_FOUND) + // TRN %1% is the tab id the command was given, such as "preview". + return AppActionRunResult{AppActionRunResult::Level::Error, format_wxstr(_L("No tab has the id \"%1%\"."), tab), false}; + mf->select_tab(from_u8(tab)); + // The tab can refuse to open: the Device tab of a Bambu Lab printer without its network plugin. + if (mf->m_tabpanel->GetSelectedPageName() != from_u8(tab)) + // TRN %1% is the id of the tab that could not be opened, such as "monitor". + return AppActionRunResult{AppActionRunResult::Level::Error, format_wxstr(_L("The \"%1%\" tab could not be opened."), tab), false}; return AppActionRunResult{AppActionRunResult::Level::Success}; }, - "tab"); + "tab") + .input_schema = Mcp::object_schema( + {{"tab", Mcp::prop("string", "The tab's id: home, prepare, preview, monitor, project, calibration, or a plugin page's id.")}}, + {"tab"}); - add_with_icon("load_project", L("Load Project"), L("Commands"), "menu_open", [](const std::string& param) { + add_with_icon("load_project", L("Load Project"), L("Commands"), "menu_open", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->load_project(); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, false, fail); + const auto path = path_argument(args, false, fail); if (!path) return fail; plater->load_project(from_path(*path)); return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("save_project", L("Save Project"), L("Commands"), "menu_save", [](const std::string&) { - if (Plater* plater = wxGetApp().plater()) - plater->save_project(false); - return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("save_project_as", L("Save Project As"), L("Commands"), "menu_save", [](const std::string& param) { + }).input_schema = Mcp::object_schema({{"path", input_file("a .3mf project")}}); + add_with_icon("save_project_as", L("Save Project As"), L("Commands"), "menu_save", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->save_project(true); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, true, fail); + const auto path = path_argument(args, true, fail); if (!path) return fail; return written(Ops::save_project_as({*path}), *path); - }); - add_with_icon("new_project", L("New Project"), L("Commands"), "menu_open", [](const std::string&) { - if (Plater* plater = wxGetApp().plater()) - plater->new_project(); - return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("undo", L("Undo"), L("Commands"), "menu_undo", [](const std::string&) { - if (Plater* plater = wxGetApp().plater()) - plater->undo(); - return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("redo", L("Redo"), L("Commands"), "menu_redo", [](const std::string&) { - if (Plater* plater = wxGetApp().plater()) - plater->redo(); - return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("toggle_run_script", L("Run Script"), L("Commands"), "media_play", [](const std::string&) { + }).input_schema = output_file(".3mf project"); + // Undo and Redo act on the shown tab's history, as the Edit menu's do; history names one for automation, + // which acts whatever tab is shown. + const json history = Mcp::object_schema( + {{"history", Mcp::enum_prop({"design", "project"}, "The history: design, the Design tab's (with the CAD feature on), " + "or project. Default: the Design tab's while it is shown, else " + "the project's.")}}); + // A person's pick does what the Edit menu's item does, and shows nothing where it would be greyed. An + // automated call, run_action of the tile included, acts on the history undo_redo() picks: the Design tab's + // through its gate, whose refusals say why, and the project's as the Edit menu's item does. + const auto picked_as_menu = [](NativeCommand& command, bool redo) { + const CommandFn picked = ui_command(command.key, command.title, command.group, command.input_schema, + [redo](const json& args) { return picked_undo_redo(args, redo); }) + .run; + command.run = [picked, automated = std::move(command.run)](const json& args, Mcp::ToolContext& ctx) { + return ctx.person() ? picked(args, ctx) : automated(args, ctx); + }; + }; + NativeCommand& undo = add_with_icon("undo", L("Undo"), L("Commands"), "menu_undo", [](const json& args) { return undo_redo(args, false); }); + undo.input_schema = history; + picked_as_menu(undo, false); +#ifdef SLIC3R_CAD + // An example calls Design commands, so only a catalog that holds them documents the Design history. + if (options.cad) + undo.examples = json::parse(R"json([ + {"title": "Take back an extrude, its sketch with it", "calls": [ + {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, + {"tool": "undo", "args": {"history": "design"}}]}, + {"title": "Take back the last shape drawn in a sketch", "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, + {"tool": "undo", "args": {"history": "design"}}]}])json"); +#endif + NativeCommand& redo = add_with_icon("redo", L("Redo"), L("Commands"), "menu_redo", [](const json& args) { return undo_redo(args, true); }); + redo.input_schema = history; + picked_as_menu(redo, true); +#ifdef SLIC3R_CAD + if (options.cad) + redo.examples = json::parse(R"json([ + {"title": "Put back an extrude undo took back", "calls": [ + {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 5}}, + {"tool": "undo", "args": {"history": "design"}}, + {"tool": "redo", "args": {"history": "design"}}]}, + {"title": "Put back the shape undo took off a sketch", "calls": [ + {"tool": "sketch_begin", "args": {"plane": "XY"}}, + {"tool": "sketch_add", "args": {"rect": [-15, -10, 15, 10]}}, + {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [0, 0], "radius": 4}]}}, + {"tool": "undo", "args": {"history": "design"}}, + {"tool": "redo", "args": {"history": "design"}}]}])json"); +#endif + add_with_icon("toggle_run_script", L("Run Script"), L("Commands"), "media_play", [](const json&) { if (wxGetApp().mainframe != nullptr) wxGetApp().run_script_panel().toggle(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("open_action_replay", L("Action Replay"), L("Commands"), "loop", [](const std::string&) { + add_with_icon("open_action_replay", L("Action Replay"), L("Commands"), "loop", [](const json&) { if (MainFrame* mf = wxGetApp().mainframe) mf->show_action_replay(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("open_preferences", L("Preferences"), L("Commands"), "cog", [](const std::string& param) { - if (param.empty()) { + // The tabs of the Preferences dialog, by the names open_preferences takes. + static const std::pair<const char*, PreferencesTab> preferences_tabs[] = {{"general", PreferencesTab::General}, + {"files", PreferencesTab::Files}, + {"behaviour", PreferencesTab::Behaviour}, + {"control", PreferencesTab::Control}, + {"graphics", PreferencesTab::Graphics}, + {"online", PreferencesTab::Online}, + {"developer", PreferencesTab::Developer}}; + std::vector<std::string> preferences_tab_names; + for (const auto& [name, tab] : preferences_tabs) + preferences_tab_names.emplace_back(name); + add_with_icon("open_preferences", L("Preferences"), L("Commands"), "cog", [](const json& args) { + if (Mcp::person_form(args)) { wxGetApp().open_preferences(); return AppActionRunResult{AppActionRunResult::Level::Success}; } - // "tab[:key]": the tab to show, and the preference whose control is scrolled into view and focused. - static const std::pair<const char*, PreferencesTab> tabs[] = {{"general", PreferencesTab::General}, - {"files", PreferencesTab::Files}, - {"behaviour", PreferencesTab::Behaviour}, - {"control", PreferencesTab::Control}, - {"graphics", PreferencesTab::Graphics}, - {"online", PreferencesTab::Online}, - {"developer", PreferencesTab::Developer}}; - const std::size_t colon = param.find(':'); - const std::string tab = param.substr(0, colon); - const auto it = std::find_if(std::begin(tabs), std::end(tabs), [&](const auto& t) { return tab == t.first; }); - if (it == std::end(tabs)) + // The tab to show, and the preference whose control is scrolled into view and focused. + const std::string tab = args.value("tab", std::string()); + const auto it = std::find_if(std::begin(preferences_tabs), std::end(preferences_tabs), [&](const auto& t) { return tab == t.first; }); + if (it == std::end(preferences_tabs)) return AppActionRunResult{AppActionRunResult::Level::Error, - from_u8("Unknown tab \"" + tab + "\": general, files, behaviour, control, graphics, online or developer")}; - wxGetApp().open_preferences(it->second, colon == std::string::npos ? std::string() : param.substr(colon + 1)); + from_u8("tab is required: general, files, behaviour, control, graphics, online or developer")}; + wxGetApp().open_preferences(it->second, args.value("key", std::string())); return AppActionRunResult{AppActionRunResult::Level::Success}; - }); + }).input_schema = Mcp::object_schema( + {{"tab", Mcp::enum_prop(preferences_tab_names, "The tab to show.")}, + {"key", Mcp::prop("string", "A preference on that tab, e.g. auto_arrange on behaviour: its control is scrolled into view and focused.")}}); // ---- Screenshots and recordings ---- (the MCP screenshot and recording tools' defaults, for the person) - add_with_icon("take_screenshot", L("Take Screenshot"), L("Commands"), "screenshot", [](const std::string&) { + add_with_icon("take_screenshot", L("Take Screenshot"), L("Commands"), "screenshot", [](const json&) { MainFrame* mf = wxGetApp().mainframe; if (mf == nullptr) return AppActionRunResult{}; @@ -823,37 +979,22 @@ std::vector<NativeCommand> build_command_catalog() notify_saved(_L("Screenshot saved"), path); return AppActionRunResult{AppActionRunResult::Level::Success, {}, true, path_reply(path)}; }); - add_with_icon("start_recording", L("Start Recording"), L("Commands"), "recording_start", start_recording); - add_with_icon("stop_recording", L("Stop Recording"), L("Commands"), "recording_stop", [](const std::string&) { - Mcp::McpService* service = wxGetApp().mcp_service(); - const nlohmann::json state = service != nullptr && service->started() ? service->recorder().state() : nlohmann::json(); - if (state.is_null() || state.value("ending", false)) - return AppActionRunResult{AppActionRunResult::Level::Info, _L("No recording is running."), false}; - // What the window shows now, even if the timer has not ticked since, before the notification shows. - service->recorder().capture_now(); - // The recording may be an agent's, a replay's or a script's; the person stopped it all the same, so they are told - // where it went. Before it ends: a person's recording that is to be encoded says so instead, as it ends. - const boost::filesystem::path path = Mcp::path_from_utf8(state["path"].get<std::string>()); - notify_saved(_L("Recording saved"), path); - service->recorder().end(kStoppedInApp); - return AppActionRunResult{AppActionRunResult::Level::Success, {}, true, path_reply(path)}; - }); // ---- Mode ---- - add_with_icon("mode_simple", L("Mode: Simple"), L("Mode"), "advanced", [](const std::string&) { + add_with_icon("mode_simple", L("Mode: Simple"), L("Mode"), "advanced", [](const json&) { wxGetApp().set_mode(comSimple); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("mode_advanced", L("Mode: Advanced"), L("Mode"), "advanced", [](const std::string&) { + add_with_icon("mode_advanced", L("Mode: Advanced"), L("Mode"), "advanced", [](const json&) { wxGetApp().set_mode(comAdvanced); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("mode_expert", L("Mode: Expert"), L("Mode"), "advanced", [](const std::string&) { + add_with_icon("mode_expert", L("Mode: Expert"), L("Mode"), "advanced", [](const json&) { wxGetApp().set_mode(comExpert); return AppActionRunResult{AppActionRunResult::Level::Success}; }); // Mirrors Preferences > Developer > Developer mode: flip the flag, persist, refresh the UI. - add_with_icon("toggle_developer_mode", L("Toggle Developer Mode"), L("Mode"), "advanced", [](const std::string&) { + add_with_icon("toggle_developer_mode", L("Toggle Developer Mode"), L("Mode"), "advanced", [](const json&) { GUI_App& app = wxGetApp(); const bool on = !app.app_config->get_bool("developer_mode"); app.app_config->set_bool("developer_mode", on); @@ -863,63 +1004,68 @@ std::vector<NativeCommand> build_command_catalog() }); // ---- Export pipeline ---- - add_with_icon("export_gcode", L("Export G-code"), L("Slice & Export"), "custom-gcode_gcode", [](const std::string& param) { + // The G-code is written in the background: a call that gives the file waits for it. + tile(ui_command( + "export_gcode", L("Export G-code"), L("Slice & Export"), output_file(".gcode file"), + [](const json& args) { + Plater* plater = wxGetApp().plater(); + if (plater == nullptr) + return AppActionRunResult{}; + if (Mcp::person_form(args)) { + plater->export_gcode(false); + return AppActionRunResult{AppActionRunResult::Level::Success}; + } + AppActionRunResult fail; + const auto path = path_argument(args, true, fail); + if (!path) + return fail; + Ops::ExportGcodeArgs gcode; + gcode.path = *path; + if (const Ops::Outcome<Ops::ExportTicket> started = Ops::start_gcode_export(gcode); !started) + return refused(started.refusal()); + return AppActionRunResult{AppActionRunResult::Level::Info, from_u8(path->string())}; + }, + CommandCompletion::Export)) + .icon = "custom-gcode_gcode"; + add_with_icon("export_stl", L("Export STL"), L("Slice & Export"), "save", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { - plater->export_gcode(false); - return AppActionRunResult{AppActionRunResult::Level::Success}; - } - AppActionRunResult fail; - const auto path = path_param(param, true, fail); - if (!path) - return fail; - Ops::ExportGcodeArgs gcode; - gcode.path = *path; - if (const Ops::Outcome<Ops::ExportTicket> started = Ops::start_gcode_export(gcode); !started) - return refused(started.refusal()); - return AppActionRunResult{AppActionRunResult::Level::Info, from_u8(path->string())}; - }); - add_with_icon("export_stl", L("Export STL"), L("Slice & Export"), "save", [](const std::string& param) { - Plater* plater = wxGetApp().plater(); - if (plater == nullptr) - return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->export_stl(); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, true, fail); + const auto path = path_argument(args, true, fail); if (!path) return fail; return written(Ops::export_stl({*path}), *path); - }); - add_with_icon("export_3mf", L("Export 3MF"), L("Slice & Export"), "menu_save", [](const std::string& param) { + }).input_schema = output_file(".stl file"); + add_with_icon("export_3mf", L("Export 3MF"), L("Slice & Export"), "menu_save", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->export_core_3mf(); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, true, fail); + const auto path = path_argument(args, true, fail); if (!path) return fail; return written(Ops::export_model_3mf({*path}), *path); - }); + }).input_schema = output_file(".3mf file"); auto export_sliced = [](bool all) { - return [all](const std::string& param) { + return [all](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->export_gcode_3mf(all); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, true, fail); + const auto path = path_argument(args, true, fail); if (!path) return fail; Ops::ExportSlicedArgs sliced; @@ -928,13 +1074,15 @@ std::vector<NativeCommand> build_command_catalog() return written(Ops::export_sliced_3mf(sliced), *path); }; }; - add_with_icon("export_sliced_file", L("Export Sliced File"), L("Slice & Export"), "save", export_sliced(false)); - add_with_icon("export_all_sliced_file", L("Export All Sliced Files"), L("Slice & Export"), "save", export_sliced(true)); + add_with_icon("export_sliced_file", L("Export Sliced File"), L("Slice & Export"), "save", export_sliced(false)).input_schema = + output_file(".gcode.3mf file"); + add_with_icon("export_all_sliced_file", L("Export All Sliced Files"), L("Slice & Export"), "save", export_sliced(true)).input_schema = + output_file(".gcode.3mf file"); // ---- Send to print host ---- // The Print button's send for a printer with a print host: the Send G-code dialog, then the upload queue. Where // the button would not send to a print host, the command says why instead of doing nothing. - add_with_icon("send_gcode", L("Send G-code to printer host"), L("Slice & Export"), "printer", [](const std::string&) { + add_with_icon("send_gcode", L("Send G-code to printer host"), L("Slice & Export"), "printer", [](const json&) { if (wxGetApp().plater() == nullptr) return AppActionRunResult{}; if (const Ops::Outcome<Ops::Done> sent = Ops::send_gcode_to_host(); !sent) @@ -946,22 +1094,22 @@ std::vector<NativeCommand> build_command_catalog() // The tab-strip calib_sf glyph is drawn white for the dark tab bar and vanishes on the palette's // light tile, so each wizard borrows the matching settings-group icon instead (gray + accent green). add_with_icon("calib_temperature", L("Temperature Calibration"), L("Calibration"), "param_temperature", - [](const std::string&) { return calib_command(CalibKind::Temperature); }); + [](const json&) { return calib_command(CalibKind::Temperature); }); add_with_icon("calib_max_volumetric", L("Max Volumetric Speed Calibration"), L("Calibration"), "param_volumetric_speed", - [](const std::string&) { return calib_command(CalibKind::MaxVolumetric); }); + [](const json&) { return calib_command(CalibKind::MaxVolumetric); }); add_with_icon("calib_pressure_advance", L("Pressure Advance Calibration"), L("Calibration"), "param_flow_ratio_and_pressure_advance", - [](const std::string&) { return calib_command(CalibKind::PressureAdvance); }); + [](const json&) { return calib_command(CalibKind::PressureAdvance); }); add_with_icon("calib_flow_ratio", L("Flow Ratio Calibration"), L("Calibration"), "param_flow_ratio_and_pressure_advance", - [](const std::string&) { return calib_command(CalibKind::FlowRatio); }); + [](const json&) { return calib_command(CalibKind::FlowRatio); }); add_with_icon("calib_retraction", L("Retraction Calibration"), L("Calibration"), "param_retraction", - [](const std::string&) { return calib_command(CalibKind::Retraction); }); + [](const json&) { return calib_command(CalibKind::Retraction); }); add_with_icon("calib_cornering", L("Cornering Calibration"), L("Calibration"), "param_precision", - [](const std::string&) { return calib_command(CalibKind::Cornering); }); + [](const json&) { return calib_command(CalibKind::Cornering); }); add_with_icon("calib_input_shaping_freq", L("Input Shaping Frequency Calibration"), L("Calibration"), "param_resonance_avoidance", - [](const std::string&) { return calib_command(CalibKind::InputShapingFreq); }); + [](const json&) { return calib_command(CalibKind::InputShapingFreq); }); add_with_icon("calib_input_shaping_damp", L("Input Shaping Damping Calibration"), L("Calibration"), "param_resonance_avoidance", - [](const std::string&) { return calib_command(CalibKind::InputShapingDamp); }); - add_with_icon("calib_vfa", L("VFA Calibration"), L("Calibration"), "param_speed", [](const std::string&) { return calib_command(CalibKind::VFA); }); + [](const json&) { return calib_command(CalibKind::InputShapingDamp); }); + add_with_icon("calib_vfa", L("VFA Calibration"), L("Calibration"), "param_speed", [](const json&) { return calib_command(CalibKind::VFA); }); // ---- View ---- // Titles are L("...")-marked here (not via a variable) so xgettext can extract them. @@ -975,9 +1123,9 @@ std::vector<NativeCommand> build_command_catalog() {"view_iso", "iso", L("View: Isometric")}}) { std::string k = key, d = dir; add(k, title, L("View"), - [d](const std::string&) { return view_command(wxGetApp().plater(), d); }); + [d](const json&) { return view_command(wxGetApp().plater(), d); }); } - add("view_default", L("View: Default"), L("View"), [](const std::string&) { + add("view_default", L("View: Default"), L("View"), [](const json&) { Plater* plater = wxGetApp().plater(); if (plater) { plater->select_view("plate"); @@ -986,32 +1134,32 @@ std::vector<NativeCommand> build_command_catalog() } return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("view_fit_bed", L("Fit Bed to View"), L("View"), [](const std::string&) { + add("view_fit_bed", L("Fit Bed to View"), L("View"), [](const json&) { if (Plater* plater = wxGetApp().plater()) if (GLCanvas3D* canvas = plater->get_current_canvas3D()) canvas->zoom_to_bed(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("view_toggle_perspective", L("Toggle Perspective"), L("View"), [](const std::string&) { + add("view_toggle_perspective", L("Toggle Perspective"), L("View"), [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->get_camera().select_next_type(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("reset_window_layout", L("Reset Window Layout"), L("View"), "toolbar_reset", [](const std::string&) { + add_with_icon("reset_window_layout", L("Reset Window Layout"), L("View"), "toolbar_reset", [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->reset_window_layout(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); // ---- Object ---- - add_with_icon("obj_delete", L("Delete Selected"), L("Object"), "delete", [](const std::string&) { + add_with_icon("obj_delete", L("Delete Selected"), L("Object"), "delete", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return !p->is_selection_empty(); }, [](Plater* p) { p->remove_selected(); }); }); - add_with_icon("obj_delete_all", L("Delete All Objects"), L("Object"), "delete", [](const std::string&) { + add_with_icon("obj_delete_all", L("Delete All Objects"), L("Object"), "delete", [](const json&) { return object_op( wxGetApp().plater(), [](Plater* p) { return p->can_delete_all(); }, [](Plater* p) { p->delete_all_objects_from_model(); }); }); - add("select_all", L("Select All Objects"), L("Object"), [](const std::string&) { + add("select_all", L("Select All Objects"), L("Object"), [](const json&) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; @@ -1019,49 +1167,49 @@ std::vector<NativeCommand> build_command_catalog() plater->select_all(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("deselect_all", L("Deselect All"), L("Object"), [](const std::string&) { + add("deselect_all", L("Deselect All"), L("Object"), [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->deselect_all(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("obj_mirror_x", L("Mirror X"), L("Object"), "menu_mirror_x", [](const std::string&) { + add_with_icon("obj_mirror_x", L("Mirror X"), L("Object"), "menu_mirror_x", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->can_mirror(); }, [](Plater* p) { p->mirror(Axis::X); }); }); - add_with_icon("obj_mirror_y", L("Mirror Y"), L("Object"), "menu_mirror_y", [](const std::string&) { + add_with_icon("obj_mirror_y", L("Mirror Y"), L("Object"), "menu_mirror_y", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->can_mirror(); }, [](Plater* p) { p->mirror(Axis::Y); }); }); - add_with_icon("obj_mirror_z", L("Mirror Z"), L("Object"), "menu_mirror_z", [](const std::string&) { + add_with_icon("obj_mirror_z", L("Mirror Z"), L("Object"), "menu_mirror_z", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->can_mirror(); }, [](Plater* p) { p->mirror(Axis::Z); }); }); - add_with_icon("obj_split_objects", L("Split to Objects"), L("Object"), "menu_split_objects", [](const std::string&) { + add_with_icon("obj_split_objects", L("Split to Objects"), L("Object"), "menu_split_objects", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->can_split_to_objects(); }, [](Plater* p) { p->split_object(true); }); }); - add_with_icon("obj_split_parts", L("Split to Parts"), L("Object"), "menu_split_parts", [](const std::string&) { + add_with_icon("obj_split_parts", L("Split to Parts"), L("Object"), "menu_split_parts", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->can_split_to_volumes(); }, [](Plater* p) { p->split_volume(); }); }); - add("obj_center", L("Center Selected on Plate"), L("Object"), [](const std::string&) { + add("obj_center", L("Center Selected on Plate"), L("Object"), [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return !p->is_selection_empty(); }, [](Plater* p) { p->center_selection(); }); }); - add_with_icon("obj_drop", L("Drop to Bed"), L("Object"), "toolbar_flatten", [](const std::string&) { + add_with_icon("obj_drop", L("Drop to Bed"), L("Object"), "toolbar_flatten", [](const json&) { return object_op(wxGetApp().plater(), [](Plater* p) { return p->get_selection().can_drop(); }, [](Plater* p) { p->drop_selection(); }); }); - add("obj_fit_volume", L("Scale to Fit Print Volume"), L("Object"), [](const std::string&) { + add("obj_fit_volume", L("Scale to Fit Print Volume"), L("Object"), [](const json&) { return object_op( wxGetApp().plater(), [](Plater* p) { return p->can_scale_to_print_volume(); }, [](Plater* p) { p->scale_selection_to_fit_print_volume(); }); }); - add_with_icon("obj_instances_up", L("Increase Instances"), L("Object"), "instance_add", [](const std::string&) { + add_with_icon("obj_instances_up", L("Increase Instances"), L("Object"), "instance_add", [](const json&) { return object_op( wxGetApp().plater(), [](Plater* p) { return p->can_increase_instances(); }, [](Plater* p) { p->increase_instances(); }); }); - add_with_icon("obj_instances_down", L("Decrease Instances"), L("Object"), "instance_remove", [](const std::string&) { + add_with_icon("obj_instances_down", L("Decrease Instances"), L("Object"), "instance_remove", [](const json&) { return object_op( wxGetApp().plater(), [](Plater* p) { return p->can_decrease_instances(); }, [](Plater* p) { p->decrease_instances(); }); }); - add_with_icon("obj_arrange", L("Auto-Arrange"), L("Object"), "toolbar_arrange", [](const std::string&) { + add_with_icon("obj_arrange", L("Auto-Arrange"), L("Object"), "toolbar_arrange", [](const json&) { return arrange_all(wxGetApp().plater()); }); - add_with_icon("obj_orient", L("Auto-Orient"), L("Object"), "toolbar_orient", [](const std::string&) { + add_with_icon("obj_orient", L("Auto-Orient"), L("Object"), "toolbar_orient", [](const json&) { return orient_all(wxGetApp().plater()); }); @@ -1069,7 +1217,7 @@ std::vector<NativeCommand> build_command_catalog() // Change Type is in the part menus only: without part rows, set_volume_type() would change every // part of a selected object, which no menu offers. auto add_type = [&](std::string key, std::string title, ModelVolumeType type) { - add(std::move(key), std::move(title), L("Object"), [type](const std::string&) { + add(std::move(key), std::move(title), L("Object"), [type](const json&) { ObjectList* list = object_list_in_3d_view(); if (list == nullptr) return AppActionRunResult{}; @@ -1087,21 +1235,26 @@ std::vector<NativeCommand> build_command_catalog() add_type("obj_type_support_blocker", L("Change Type to Support Blocker"), ModelVolumeType::SUPPORT_BLOCKER); add_type("obj_type_support_enforcer", L("Change Type to Support Enforcer"), ModelVolumeType::SUPPORT_ENFORCER); add_type("obj_type_precise_seam", L("Change Type to Precise Seam"), ModelVolumeType::PRECISE_SEAM_CENTER); - add("obj_rename", L("Rename"), L("Object"), [](const std::string& param) { + add("obj_rename", L("Rename"), L("Object"), [](const json& args) { + // The Rename dialog leaves the name as it is when it is emptied, so a call has to give one. + const std::string name = args.value("name", std::string()); + if (!Mcp::person_form(args) && name.empty()) + return AppActionRunResult{AppActionRunResult::Level::Error, + from_u8("A name is needed: give the new name, or no arguments for the Rename dialog.")}; ObjectList* list = object_list_in_3d_view(); if (list == nullptr) return AppActionRunResult{}; const wxDataViewItemArray rows = selected_rows(*list, itObject | itVolume); if (rows.size() != 1) return AppActionRunResult{AppActionRunResult::Level::Info, _L("Select one object or part first."), false}; - if (param.empty()) + if (Mcp::person_form(args)) list->rename_item(); - else if (!list->rename_item(rows.front(), from_u8(param))) + else if (!list->rename_item(rows.front(), from_u8(name))) return AppActionRunResult{AppActionRunResult::Level::Error, _L("Invalid name, the following characters are not allowed:") + " <>:/\\|?*\""}; return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("obj_set_instances", L("Set Number of Instances"), L("Object"), "instance_add", [](const std::string& param) { + }).input_schema = Mcp::object_schema({{"name", Mcp::prop("string", "The new name, in place of the Rename dialog.")}}); + add_with_icon("obj_set_instances", L("Set Number of Instances"), L("Object"), "instance_add", [](const json& args) { Plater* plater = wxGetApp().plater(); ObjectList* list = object_list_in_3d_view(); if (list == nullptr) @@ -1112,24 +1265,21 @@ std::vector<NativeCommand> build_command_catalog() return refused(refusal, code == "no_object_selected" || code == "job_running" ? AppActionRunResult::Level::Info : AppActionRunResult::Level::Error); }; - const std::optional<int> count = param.empty() ? std::nullopt : NativeCommands::parse_count(param); - if (!param.empty() && !count) - return refused_count(Ops::bad_instance_count()); - if (count == 0) - return AppActionRunResult{AppActionRunResult::Level::Error, from_u8("0 instances would delete the object; use obj_delete.")}; - if (!count) { + if (Mcp::person_form(args)) { // The asking path: the item's dialog, enabled as the menu enables it. if (const std::optional<Ops::Refusal> refusal = Ops::instance_count_refusal()) return refused_count(*refusal); plater->set_number_of_copies(); return AppActionRunResult{AppActionRunResult::Level::Success}; } - const Ops::Outcome<Ops::InstanceCount> set = Ops::set_instance_count({*count}); + const Ops::Outcome<Ops::InstanceCount> set = Ops::set_instance_count({args.at("count").get<int>()}); if (!set) return refused_count(set.refusal()); return with_reply({{"object", set.value().object}, {"instances", set.value().instances}}); - }); - add("obj_assemble", L("Assemble"), L("Object"), [](const std::string&) { + }).input_schema = Mcp::object_schema({{"count", {{"type", "integer"}, + {"minimum", 1}, + {"description", "The total number of instances, up to 1000, in place of the dialog."}}}}); + add("obj_assemble", L("Assemble"), L("Object"), [](const json&) { ObjectList* list = object_list_in_3d_view(); if (list == nullptr) return AppActionRunResult{}; @@ -1143,7 +1293,7 @@ std::vector<NativeCommand> build_command_catalog() const ModelObjectPtrs& objects = wxGetApp().plater()->model().objects; return with_reply({{"object", objects.size() - 1}, {"name", objects.back()->name}}); }); - add("obj_instances_to_objects", L("Set as Individual Objects"), L("Object"), [](const std::string&) { + add("obj_instances_to_objects", L("Set as Individual Objects"), L("Object"), [](const json&) { Plater* plater = wxGetApp().plater(); ObjectList* list = object_list_in_3d_view(); if (list == nullptr) @@ -1159,15 +1309,12 @@ std::vector<NativeCommand> build_command_catalog() return with_reply({{"objects", objects}}); }); auto add_order = [&](std::string key, std::string title, ObjectOrder order) { - add(std::move(key), std::move(title), L("Object"), [order](const std::string& param) { + add(std::move(key), std::move(title), L("Object"), [order](const json& args) { Plater* plater = wxGetApp().plater(); ObjectList* list = object_list_in_3d_view(); if (list == nullptr) return AppActionRunResult{}; - if (!param.empty() && param != "all") - return AppActionRunResult{AppActionRunResult::Level::Error, - from_u8("The param is all, to order every plate, or nothing for the current plate.")}; - const bool all = param == "all"; + const bool all = args.value("all", false); if (all ? plater->model().objects.empty() : plater->get_partplate_list().get_selected_plate()->empty()) return AppActionRunResult{AppActionRunResult::Level::Info, _L("There are no objects to order."), false}; // order_objects() only shows a notification while a gizmo is open. @@ -1175,7 +1322,7 @@ std::vector<NativeCommand> build_command_catalog() return AppActionRunResult{AppActionRunResult::Level::Error, _L("Error: Please close all toolbar menus first")}; list->order_objects(order, all); return ordered(*plater, order, all); - }); + }).input_schema = Mcp::object_schema({{"all", Mcp::prop("boolean", "Order the objects of every plate. Default false: the current plate's.")}}); }; add_order("obj_order_by_name", L("Order by Name"), ObjectOrder::Name); add_order("obj_order_by_filament", L("Order by Filament"), ObjectOrder::Filament); @@ -1183,9 +1330,10 @@ std::vector<NativeCommand> build_command_catalog() add_order("obj_order_by_size", L("Order by Size"), ObjectOrder::Size); // ---- Add Primitive ---- (the Add > Add Primitive submenu; creates a new object) - // A size param holds the dimensions the size dialog asks for, in its order, and skips the dialog. - auto add_primitive = [&](std::string key, std::string title, std::string icon, const char* type_name) { - add_with_icon(key, std::move(title), L("Add Primitive"), std::move(icon), [key, type_name](const std::string& param) { + // A size holds the dimensions the size dialog asks for, in its order, and skips the dialog; `size_help` names + // them. + auto add_primitive = [&](std::string key, std::string title, std::string icon, const char* type_name, const char* size_help) { + add_with_icon(std::move(key), std::move(title), L("Add Primitive"), std::move(icon), [type_name, size_help](const json& args) { Plater* plater = wxGetApp().plater(); ObjectList* list = wxGetApp().obj_list(); if (plater == nullptr || list == nullptr) @@ -1195,25 +1343,22 @@ std::vector<NativeCommand> build_command_catalog() return AppActionRunResult{AppActionRunResult::Level::Error, _L("Deselect all objects to add a primitive object. To add a shape to the selected object, " "use its Add Part menu.")}; - std::vector<double> size; - if (!param.empty()) { - const std::optional<std::vector<double>> parsed = NativeCommands::parse_sizes(param); - if (!parsed || !is_primitive_size(type_name, *parsed)) - return AppActionRunResult{AppActionRunResult::Level::Error, - from_u8(std::string("The size is ") + NativeCommands::find(key)->param.help + ".")}; - size = *parsed; - } + const std::vector<double> size = args.value("size", std::vector<double>()); + if (!Mcp::person_form(args) && !is_primitive_size(type_name, size)) + return AppActionRunResult{AppActionRunResult::Level::Error, + from_u8(std::string("The size is ") + size_help + ", each above 0.")}; list->load_generic_subobject(type_name, ModelVolumeType::INVALID, true, size); return AppActionRunResult{AppActionRunResult::Level::Success}; - }); + }).input_schema = Mcp::object_schema({{"size", Mcp::array_prop({{"type", "number"}}, std::string("The size, ") + size_help + + ", each above 0, in place of the size dialog.")}}); }; - add_primitive("add_primitive_cube", L("Cube"), "menu_obj_cube", "Cube"); - add_primitive("add_primitive_cylinder", L("Cylinder"), "menu_obj_cylinder", "Cylinder"); - add_primitive("add_primitive_sphere", L("Sphere"), "menu_obj_sphere", "Sphere"); - add_primitive("add_primitive_cone", L("Cone"), "menu_obj_cone", "Cone"); - add_primitive("add_primitive_disc", L("Disc"), "menu_obj_disc", "Disc"); - add_primitive("add_primitive_torus", L("Torus"), "menu_obj_torus", "Torus"); - add_with_icon("add_primitive_text", L("Text"), L("Add Primitive"), "menu_obj_text", [](const std::string&) { + add_primitive("add_primitive_cube", L("Cube"), "menu_obj_cube", "Cube", "[X, Y, Z] in mm"); + add_primitive("add_primitive_cylinder", L("Cylinder"), "menu_obj_cylinder", "Cylinder", "[diameter, height] in mm"); + add_primitive("add_primitive_sphere", L("Sphere"), "menu_obj_sphere", "Sphere", "[diameter] in mm"); + add_primitive("add_primitive_cone", L("Cone"), "menu_obj_cone", "Cone", "[base diameter, height] in mm"); + add_primitive("add_primitive_disc", L("Disc"), "menu_obj_disc", "Disc", "[diameter, height] in mm"); + add_primitive("add_primitive_torus", L("Torus"), "menu_obj_torus", "Torus", "[inner diameter, tube diameter] in mm"); + add_with_icon("add_primitive_text", L("Text"), L("Add Primitive"), "menu_obj_text", [](const json&) { Plater* plater = wxGetApp().plater(); if (plater) { ensure_3d_view(plater); @@ -1223,7 +1368,7 @@ std::vector<NativeCommand> build_command_catalog() } return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("add_primitive_svg", L("SVG"), L("Add Primitive"), "menu_obj_svg", [](const std::string& param) { + add_with_icon("add_primitive_svg", L("SVG"), L("Add Primitive"), "menu_obj_svg", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; @@ -1231,27 +1376,27 @@ std::vector<NativeCommand> build_command_catalog() GLCanvas3D* canvas = plater->canvas3D(); if (canvas != nullptr) canvas->clear_popup_menu_position(); - if (param.empty()) { + if (Mcp::person_form(args)) { MenuFactory::add_svg_volume(ModelVolumeType::INVALID); return AppActionRunResult{AppActionRunResult::Level::Success}; } // What the dialog path does once a file is picked: a new object with nothing selected, else // a part of the selected object. AppActionRunResult fail; - const auto path = path_param(param, false, fail); + const auto path = path_argument(args, false, fail); if (!path) return fail; auto* svg = canvas != nullptr ? dynamic_cast<GLGizmoSVG*>(canvas->get_gizmos_manager().get_gizmo(GLGizmosManager::Svg)) : nullptr; if (svg == nullptr || !svg->create_volume(into_u8(from_path(*path)), ModelVolumeType::MODEL_PART)) return AppActionRunResult{AppActionRunResult::Level::Error, _L("The SVG file could not be added.")}; return AppActionRunResult{AppActionRunResult::Level::Success}; - }); + }).input_schema = Mcp::object_schema({{"path", input_file("an .svg file")}}); // ---- Add Handy models ---- (the Add > Add Handy models submenu) const std::vector<MenuFactory::HandyModel>& handy = MenuFactory::handy_models(); for (std::size_t i = 0; i < handy.size(); ++i) { add("add_handy_" + std::string(handy[i].key), handy[i].label, L("Add Handy models"), - [i](const std::string&) { + [i](const json&) { if (Plater* plater = wxGetApp().plater()) ensure_3d_view(plater); MenuFactory::load_handy_model(i); @@ -1260,7 +1405,7 @@ std::vector<NativeCommand> build_command_catalog() } // ---- Plate ---- - add_with_icon("plate_add", L("Add Plate"), L("Plate"), "toolbar_add_plate", [](const std::string&) { + add_with_icon("plate_add", L("Add Plate"), L("Plate"), "toolbar_add_plate", [](const json&) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1269,7 +1414,7 @@ std::vector<NativeCommand> build_command_catalog() plater->add_plate(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("plate_duplicate", L("Duplicate Plate"), L("Plate"), "menu_copy", [](const std::string&) { + add_with_icon("plate_duplicate", L("Duplicate Plate"), L("Plate"), "menu_copy", [](const json&) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1278,7 +1423,7 @@ std::vector<NativeCommand> build_command_catalog() plater->duplicate_plate(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("plate_delete", L("Delete Plate"), L("Plate"), "delete", [](const std::string&) { + add_with_icon("plate_delete", L("Delete Plate"), L("Plate"), "delete", [](const json&) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1287,7 +1432,7 @@ std::vector<NativeCommand> build_command_catalog() plater->delete_plate(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("plate_rename", L("Rename Plate"), L("Plate"), "plate_name_edit", [](const std::string&) { + add_with_icon("plate_rename", L("Rename Plate"), L("Plate"), "plate_name_edit", [](const json&) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1298,7 +1443,7 @@ std::vector<NativeCommand> build_command_catalog() plater->rename_plate(plater->get_partplate_list().get_curr_plate_index(), dlg.get_plate_name().ToUTF8().data()); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("plate_toggle_lock", L("Toggle Plate Lock"), L("Plate"), "lock_normal", [](const std::string&) { + add_with_icon("plate_toggle_lock", L("Toggle Plate Lock"), L("Plate"), "lock_normal", [](const json&) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1309,7 +1454,7 @@ std::vector<NativeCommand> build_command_catalog() return refused(locked.refusal()); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("plate_goto", L("Go to Plate"), L("Plate"), "go_next_plate", [](const std::string& param) { + add_with_icon("plate_goto", L("Go to Plate"), L("Plate"), "go_next_plate", [](const json& args) { Plater* plater = wxGetApp().plater(); if (!is_fff_plater(plater)) return plate_unavailable(); @@ -1318,16 +1463,14 @@ std::vector<NativeCommand> build_command_catalog() if (count <= 0) return AppActionRunResult{AppActionRunResult::Level::Info, _L("No plates available.")}; Ops::SelectPlateArgs plate; - try { - plate.plate = std::stoi(param); - } catch (const std::exception&) {} + plate.plate = args.value("plate", plate.plate); if (const Ops::Outcome<Ops::Done> selected = Ops::select_plate(plate); !selected) return refused(selected.refusal()); return AppActionRunResult{AppActionRunResult::Level::Success}; - }); + }).input_schema = Mcp::object_schema({{"plate", Mcp::prop("integer", "The plate's 0-based index. Default 0.")}}); // ---- Printer / device connection ---- - add_with_icon("sync_ams", L("Synchronize Filament List from AMS"), L("Printer"), "ams_fila_sync", [](const std::string&) { + add_with_icon("sync_ams", L("Synchronize Filament List from AMS"), L("Printer"), "ams_fila_sync", [](const json&) { Plater* plater = wxGetApp().plater(); DeviceManager* dev = wxGetApp().getDeviceManager(); if (dev && dev->get_selected_machine() && plater) { @@ -1349,7 +1492,7 @@ std::vector<NativeCommand> build_command_catalog() _L("This printer has one filament per extruder; change the number of extruders in the printer settings.")}; return std::nullopt; }; - add_with_icon("filament_add", L("Add Filament Slot"), L("Filament"), "add_filament", [filament_slots_unavailable](const std::string&) { + add_with_icon("filament_add", L("Add Filament Slot"), L("Filament"), "add_filament", [filament_slots_unavailable](const json&) { Plater* plater = wxGetApp().plater(); if (const auto refused = filament_slots_unavailable(plater)) return *refused; @@ -1362,7 +1505,7 @@ std::vector<NativeCommand> build_command_catalog() plater->sidebar().update_filaments_counter(); return AppActionRunResult{AppActionRunResult::Level::Success, format_wxstr(_L("Added filament slot %1%."), slot)}; }); - add_with_icon("filament_delete", L("Delete Filament Slot"), L("Filament"), "delete_filament", [filament_slots_unavailable](const std::string& param) { + add_with_icon("filament_delete", L("Delete Filament Slot"), L("Filament"), "delete_filament", [filament_slots_unavailable](const json& args) { Plater* plater = wxGetApp().plater(); if (const auto refused = filament_slots_unavailable(plater)) return *refused; @@ -1372,12 +1515,8 @@ std::vector<NativeCommand> build_command_catalog() return AppActionRunResult{AppActionRunResult::Level::Info, _L("The only filament slot cannot be deleted.")}; // Without a slot, the last physical one, as the - button. size_t slot = physical; - if (!param.empty()) { - try { - slot = size_t(std::stoul(param)); - } catch (const std::exception&) { - slot = 0; - } + if (args.contains("slot")) { + slot = args.at("slot").get<size_t>(); if (slot < 1 || slot > bundle.filament_presets.size()) return AppActionRunResult{AppActionRunResult::Level::Error, format_wxstr(_L("Filament slot must be 1 to %1%."), bundle.filament_presets.size())}; @@ -1388,14 +1527,17 @@ std::vector<NativeCommand> build_command_catalog() plater->sidebar().delete_filament(slot - 1); plater->sidebar().update_filaments_counter(); return AppActionRunResult{AppActionRunResult::Level::Success, format_wxstr(_L("Deleted filament slot %1%."), slot)}; - }); + }).input_schema = Mcp::object_schema( + {{"slot", {{"type", "integer"}, + {"minimum", 1}, + {"description", "The 1-based filament slot. Default: the last physical slot, as the - button."}}}}); // ---- Presets / cloud ---- - add_with_icon("preset_bundle", L("Open Preset Bundle"), L("Presets"), "menu_edit_preset", [](const std::string&) { + add_with_icon("preset_bundle", L("Open Preset Bundle"), L("Presets"), "menu_edit_preset", [](const json&) { wxGetApp().open_presetbundledialog(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("sync_presets", L("Sync Presets"), L("Presets"), "printer_sync_ok", [](const std::string&) { + add_with_icon("sync_presets", L("Sync Presets"), L("Presets"), "printer_sync_ok", [](const json&) { if (!wxGetApp().is_user_login()) return AppActionRunResult{AppActionRunResult::Level::Info, _L("Sign in to sync presets.")}; wxGetApp().restart_sync_user_preset(); @@ -1403,11 +1545,11 @@ std::vector<NativeCommand> build_command_catalog() }); // ---- Import ---- - add_with_icon("import_file", L("Import 3MF/STL/STEP/SVG/OBJ/AMF"), L("Import"), "menu_open", [](const std::string& param) { + add_with_icon("import_file", L("Import 3MF/STL/STEP/SVG/OBJ/AMF"), L("Import"), "menu_open", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { #ifdef __APPLE__ plater->add_model(); #else @@ -1416,7 +1558,7 @@ std::vector<NativeCommand> build_command_catalog() return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, false, fail); + const auto path = path_argument(args, false, fail); if (!path) return fail; Ops::ImportModelsArgs models; @@ -1424,25 +1566,25 @@ std::vector<NativeCommand> build_command_catalog() if (const Ops::Outcome<Ops::ImportModelsResult> imported = Ops::import_models(models); !imported) return refused(imported.refusal()); return AppActionRunResult{AppActionRunResult::Level::Success}; - }); - add_with_icon("import_zip_archive", L("Import ZIP Archive"), L("Import"), "menu_open", [](const std::string&) { + }).input_schema = Mcp::object_schema({{"path", input_file("a model file")}}); + add_with_icon("import_zip_archive", L("Import ZIP Archive"), L("Import"), "menu_open", [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->import_zip_archive(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("import_configs", L("Import Configs"), L("Import"), "menu_open", [](const std::string& param) { + add_with_icon("import_configs", L("Import Configs"), L("Import"), "menu_open", [](const json& args) { MainFrame* mf = wxGetApp().mainframe; if (mf == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { mf->load_config_file(); return AppActionRunResult{AppActionRunResult::Level::Success}; } AppActionRunResult fail; - const auto path = path_param(param, false, fail); - const auto overwrite = path ? import_overwrites(param, fail) : std::nullopt; - if (!overwrite) + const auto path = path_argument(args, false, fail); + if (!path) return fail; + const bool overwrite = args.value("on_conflict", std::string("skip")) == "overwrite"; const std::string file = Mcp::path_to_utf8(*path); if (is_gcode_file(file)) { if (!mf->load_config_file(file)) @@ -1451,92 +1593,94 @@ std::vector<NativeCommand> build_command_catalog() } for (const char* ext : {".json", ".zip", ".orca_printer", ".orca_filament", ".orca_bundle"}) if (boost::iends_with(file, ext)) - return import_preset_file(*path, *overwrite); + return import_preset_file(*path, overwrite); return AppActionRunResult{AppActionRunResult::Level::Error, "Not a preset file: give a .json, .zip, .orca_printer, .orca_filament, .orca_bundle or .gcode"}; - }); + }).input_schema = Mcp::object_schema( + {{"path", input_file("a preset .json, a .zip of them, an .orca_printer, .orca_filament or .orca_bundle, or a .gcode")}, + {"on_conflict", Mcp::enum_prop({"skip", "overwrite"}, "What happens to a preset that exists already. Default skip.")}}); // ---- Export extras ---- - add_with_icon("export_stl_multi", L("Export All Objects as STLs"), L("Export"), "save", [](const std::string& param) { + // The argument of a command that writes several files, in place of its folder dialog. + const auto output_dir = Mcp::object_schema({{"path", Mcp::prop("string", "Absolute path of an existing directory to write into.")}}); + add_with_icon("export_stl_multi", L("Export All Objects as STLs"), L("Export"), "save", [](const json& args) { Plater* plater = wxGetApp().plater(); if (plater == nullptr) return AppActionRunResult{}; - if (param.empty()) { + if (Mcp::person_form(args)) { plater->export_stl(false, false, true); return AppActionRunResult{AppActionRunResult::Level::Success}; } - std::string err; - auto pp = Mcp::parse_path_param(param, err); - auto dir = pp ? Mcp::resolve_output_dir(pp->path, err) : std::nullopt; + AppActionRunResult fail; + const auto dir = dir_argument(args, fail); if (!dir) - return AppActionRunResult{AppActionRunResult::Level::Error, from_u8(err)}; + return fail; plater->export_stl(false, false, true, FT_STL, from_path(*dir)); return AppActionRunResult{AppActionRunResult::Level::Success, from_u8(dir->string())}; - }); - add_with_icon("export_drc_single", L("Export All Objects as DRC (one file)"), L("Export"), "save", [](const std::string&) { + }).input_schema = output_dir; + add_with_icon("export_drc_single", L("Export All Objects as DRC (one file)"), L("Export"), "save", [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->export_stl(false, false, false, FT_DRC); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("export_drc_multi", L("Export All Objects as DRCs"), L("Export"), "save", [](const std::string&) { + add_with_icon("export_drc_multi", L("Export All Objects as DRCs"), L("Export"), "save", [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->export_stl(false, false, true, FT_DRC); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("export_toolpaths_obj", L("Export Toolpaths as OBJ"), L("Export"), "custom-gcode_gcode", [](const std::string&) { + add_with_icon("export_toolpaths_obj", L("Export Toolpaths as OBJ"), L("Export"), "custom-gcode_gcode", [](const json&) { if (Plater* plater = wxGetApp().plater()) plater->export_toolpaths_to_obj(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("export_config", L("Export Preset Bundle"), L("Export"), "save", [](const std::string& param) { - if (param.empty()) { + add_with_icon("export_config", L("Export Preset Bundle"), L("Export"), "save", [](const json& args) { + if (Mcp::person_form(args)) { if (MainFrame* mf = wxGetApp().mainframe) mf->export_config(); return AppActionRunResult{AppActionRunResult::Level::Success}; } - std::string err; - auto pp = Mcp::parse_path_param(param, err); - auto dir = pp ? Mcp::resolve_output_dir(pp->path, err) : std::nullopt; + AppActionRunResult fail; + const auto dir = dir_argument(args, fail); if (!dir) - return AppActionRunResult{AppActionRunResult::Level::Error, from_u8(err)}; + return fail; // The dialog MainFrame::export_config() opens, given the folder its OK writes to. ExportConfigsDialog dlg(nullptr, from_path(*dir)); if (dlg.ShowModal() != wxID_OK) return AppActionRunResult{AppActionRunResult::Level::Error, _L("Nothing was exported.")}; return AppActionRunResult{AppActionRunResult::Level::Success, from_path(*dir)}; - }); + }).input_schema = output_dir; // ---- Help ---- (mirrors the top-bar Help menu, plus the wiki/YouTube links) - add("help_keyboard_shortcuts", L("Keyboard Shortcuts"), L("Help"), [](const std::string&) { + add("help_keyboard_shortcuts", L("Keyboard Shortcuts"), L("Help"), [](const json&) { wxGetApp().keyboard_shortcuts(ShortcutContext::Global); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("help_setup_wizard", L("Setup Wizard"), L("Help"), [](const std::string&) { + add("help_setup_wizard", L("Setup Wizard"), L("Help"), [](const json&) { wxGetApp().ShowUserGuide(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("help_open_config_folder", L("Show Configuration Folder"), L("Help"), "open_project", [](const std::string&) { + add_with_icon("help_open_config_folder", L("Show Configuration Folder"), L("Help"), "open_project", [](const json&) { Slic3r::GUI::desktop_open_datadir_folder(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("help_migrate_filament_presets", L("Migrate Filament Presets"), L("Help"), [](const std::string&) { + add("help_migrate_filament_presets", L("Migrate Filament Presets"), L("Help"), [](const json&) { wxGetApp().check_legacy_user_filament_presets(true); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("help_troubleshoot", L("Troubleshoot Center"), L("Help"), [](const std::string&) { + add("help_troubleshoot", L("Troubleshoot Center"), L("Help"), [](const json&) { wxGetApp().troubleshoot(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("help_network_test", L("Open Network Test"), L("Help"), [](const std::string&) { + add("help_network_test", L("Open Network Test"), L("Help"), [](const json&) { NetworkTestDialog dlg(wxGetApp().mainframe); dlg.ShowModal(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("help_benchmark_3d_scene", L("Benchmark 3D Scene"), L("Help"), [](const std::string&) { + add("help_benchmark_3d_scene", L("Benchmark 3D Scene"), L("Help"), [](const json&) { run_scene_benchmark(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("help_tip_of_the_day", L("Show Tip of the Day"), L("Help"), "info", [](const std::string&) { + add_with_icon("help_tip_of_the_day", L("Show Tip of the Day"), L("Help"), "info", [](const json&) { if (Plater* plater = wxGetApp().plater()) { plater->get_dailytips()->open(); if (GLCanvas3D* canvas = plater->get_current_canvas3D()) @@ -1544,42 +1688,42 @@ std::vector<NativeCommand> build_command_catalog() } return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("help_check_updates", L("Check for Updates"), L("Help"), "refresh", [](const std::string&) { + add_with_icon("help_check_updates", L("Check for Updates"), L("Help"), "refresh", [](const json&) { wxGetApp().check_new_version_sf(true, 1); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("help_about", L("About OrcaSlicer"), L("Help"), "OrcaSlicer_gradient_circle", [](const std::string&) { + add_with_icon("help_about", L("About OrcaSlicer"), L("Help"), "OrcaSlicer_gradient_circle", [](const json&) { Slic3r::GUI::about(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add_with_icon("open_wiki", L("Open Wiki"), L("Help"), "link_wiki_img", [](const std::string&) { + add_with_icon("open_wiki", L("Open Wiki"), L("Help"), "link_wiki_img", [](const json&) { wxLaunchDefaultBrowser("https://www.orcaslicer.com/wiki/", wxBROWSER_NEW_WINDOW); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("open_youtube", L("Open YouTube Channel"), L("Help"), [](const std::string&) { + add("open_youtube", L("Open YouTube Channel"), L("Help"), [](const json&) { wxLaunchDefaultBrowser("https://www.youtube.com/@OfficialOrcaSlicer/videos", wxBROWSER_NEW_WINDOW); return AppActionRunResult{AppActionRunResult::Level::Success}; }); // ---- Plugins ---- - add("open_plugins", L("Open Plugins"), L("Plugins"), [](const std::string&) { + add("open_plugins", L("Open Plugins"), L("Plugins"), [](const json&) { wxGetApp().open_plugins_dialog(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("refresh_plugins", L("Refresh Plugins"), L("Plugins"), [](const std::string&) { + add("refresh_plugins", L("Refresh Plugins"), L("Plugins"), [](const json&) { wxGetApp().refresh_plugins(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("install_plugin", L("Install Plugin"), L("Plugins"), [](const std::string&) { + add("install_plugin", L("Install Plugin"), L("Plugins"), [](const json&) { open_plugin_hub(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("install_local_plugin", L("Install Local Plugin"), L("Plugins"), [](const std::string& param) { + add("install_local_plugin", L("Install Local Plugin"), L("Plugins"), [](const json& args) { MainFrame* mf = wxGetApp().mainframe; if (mf == nullptr) return AppActionRunResult{}; boost::filesystem::path package; - if (param.empty()) { + if (Mcp::person_form(args)) { wxFileDialog dialog(mf, _L("Select plugin package"), wxEmptyString, wxEmptyString, _L("Plugin files (*.py;*.whl)|*.py;*.whl"), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() != wxID_OK) @@ -1587,7 +1731,7 @@ std::vector<NativeCommand> build_command_catalog() package = into_path(dialog.GetPath()); } else { AppActionRunResult fail; - const auto path = path_param(param, false, fail); + const auto path = path_argument(args, false, fail); if (!path) return fail; package = *path; @@ -1598,84 +1742,235 @@ std::vector<NativeCommand> build_command_catalog() if (message.IsEmpty()) // the overwrite prompt was cancelled return AppActionRunResult{AppActionRunResult::Level::Info, _L("The plugin was not installed."), false}; return AppActionRunResult{installed ? AppActionRunResult::Level::Success : AppActionRunResult::Level::Error, message}; - }); + }).input_schema = Mcp::object_schema({{"path", input_file("a .py or .whl plugin package")}}); describe_commands(out); - return out; + for (NativeCommand& c : out) + catalog.add(std::move(c)); + + // The typed tools, family by family, in the order tools/list shows them: the app's state, the search and the generic + // call first, then the project data, replays, Python and recordings, and the Speed Dial and the GUI-driving tools + // last. Between them the Design tab's commands, which no listing shows, only while the CAD feature is on. + Mcp::register_app_tools(catalog); + Mcp::register_api_tools(catalog); + Mcp::register_project_tools(catalog); + Mcp::register_config_tools(catalog); + Mcp::register_scene_tools(catalog); + Mcp::register_layer_tools(catalog); + Mcp::register_view_tools(catalog); + Mcp::register_replay_tools(catalog); + Mcp::register_python_tools(catalog); + Mcp::register_record_tools(catalog); +#ifdef SLIC3R_CAD + if (options.cad) + Mcp::register_cad_commands(catalog); +#endif + Mcp::register_action_tools(catalog); + Mcp::register_ui_tools(catalog); +} + +namespace { + +// The process catalog: `process_catalog` owns it and is set once, under `catalog_mutex`; `published` +// points at it from then on, so that instance() reads it without the lock. +std::mutex catalog_mutex; +std::unique_ptr<const CommandCatalog> process_catalog; +std::atomic<const CommandCatalog*> published{nullptr}; + +// Builds, seals and publishes the process catalog. Under catalog_mutex. +const CommandCatalog& publish_catalog(const NativeCommands::CatalogOptions& options) +{ + auto catalog = std::make_unique<CommandCatalog>(); + NativeCommands::register_all_commands(*catalog, options); + catalog->seal(); + process_catalog = std::move(catalog); + published.store(process_catalog.get(), std::memory_order_release); + return *process_catalog; } } // namespace -const std::vector<NativeCommand>& NativeCommands::catalog() +void NativeCommands::build(const CatalogOptions& options) { - static const std::vector<NativeCommand> commands = build_command_catalog(); - return commands; + const std::lock_guard<std::mutex> lock(catalog_mutex); + if (process_catalog != nullptr) + throw std::logic_error("The command catalog is built already"); + publish_catalog(options); +} + +const CommandCatalog& NativeCommands::instance() +{ + if (const CommandCatalog* catalog = published.load(std::memory_order_acquire)) + return *catalog; + const std::lock_guard<std::mutex> lock(catalog_mutex); + return process_catalog != nullptr ? *process_catalog : publish_catalog({}); +} + +std::vector<const NativeCommand*> NativeCommands::palette_commands(const CommandCatalog& catalog) +{ + std::vector<const NativeCommand*> out; + for (const NativeCommand& c : catalog.commands()) + // The Design tab's tiles are there only while the tab is shown (ActionRegistry::materialize_design_actions()). + if (c.in_palette && c.group != kDesignGroup) + out.push_back(&c); + return out; +} + +wxString NativeCommands::tile_title(const NativeCommand& command) +{ + const char* context = title_context(command); + return context != nullptr ? I18N::translate(command.title, context) : I18N::translate(command.title); } std::unique_ptr<AppAction> NativeCommands::make_action(const NativeCommand& command) { - return std::make_unique<CommandAction>(command); + return std::make_unique<CommandAction>(command, into_u8(tile_title(command))); } -const NativeCommand* NativeCommands::find(const std::string& key) +const NativeCommand* NativeCommands::find(const std::string& key) { return instance().find(key); } + +NativeCommand NativeCommands::ui_command(std::string key, std::string title, std::string group, json schema, + std::function<AppActionRunResult(const json& args)> fn, CommandCompletion completion) { - for (const NativeCommand& c : catalog()) - if (c.key == key) - return &c; - return nullptr; + NativeCommand c; + c.key = std::move(key); + c.title = std::move(title); + c.group = std::move(group); + c.input_schema = std::move(schema); + c.completion = completion; + c.run = [key = c.key, fn = std::move(fn), completion](const json& args, Mcp::ToolContext& ctx) { + if (ctx.person()) { + AppActionRunResult shown = fn(args); + Mcp::ToolResult reply = from_run_result(key, shown); + reply.notice = std::make_shared<const AppActionRunResult>(std::move(shown)); + return reply; + } + // An export given its file holds the project from before it starts, and the call waits for the file. + const bool exports = completion == CommandCompletion::Export && !Mcp::person_form(args); + AppActionRunResult result; + Ops::ExportTicket ticket; // empty without a plater + ctx.run_ui([&]() -> json { + Plater* plater = exports ? app_plater() : nullptr; + if (exports) + ctx.begin_operation(); + if (plater != nullptr) { + ticket.seq_before = plater->export_seq(); + ticket.revision = plater->project_revision(); + } + result = fn(args); + if (plater != nullptr) { + ticket.seq_after = plater->export_seq(); + if (const auto run = plater->export_run(ticket.seq_after)) + ticket.path = run->path; + } + return json(); + }); + Mcp::ToolResult reply = from_run_result(key, result); + if (!exports) { + Mcp::settle(ctx); + return reply; + } + if (reply.is_error) + return reply; + if (ticket.seq_after == ticket.seq_before) + return Mcp::ToolResult::error(result.message.empty() ? "The export did not start." : into_u8(result.message)); + return Mcp::await_gcode_export(ctx, ticket); + }; + return c; } -const char* NativeCommands::param_type_name(CommandParamType type) +NativeCommand NativeCommands::long_command(std::string key, std::string title, std::string group, json schema, CommandFn fn, bool inline_call) { - switch (type) { - case CommandParamType::Percent: return "percent"; - case CommandParamType::Tab: return "tab"; - case CommandParamType::Path: return "path"; - case CommandParamType::Index: return "index"; - case CommandParamType::Text: return "text"; - default: return "none"; + NativeCommand c; + c.key = std::move(key); + c.title = std::move(title); + c.group = std::move(group); + c.input_schema = std::move(schema); + c.inline_call = inline_call; + c.run = [key = c.key, fn = std::move(fn), inline_call](const json& args, Mcp::ToolContext& ctx) { + // A person's pick is on the UI thread, which a long function must not hold. + if (ctx.person() && !inline_call) + return ctx.submit(key, args); + return fn(args, ctx); + }; + return c; +} + +NativeCommand NativeCommands::with_person_form(NativeCommand tool, std::string title, std::string group, std::string icon, + std::function<AppActionRunResult()> person, bool person_form_behind_dialogs) +{ + // The person's form runs as a ui_command() function does: in place for a person's pick, in one UI closure + // for an automated call, whose reply then says what the pick showed. + const CommandFn asks = ui_command(tool.key, title, group, Mcp::object_schema({}), [person](const json&) { return person(); }).run; + const bool checked = !person_form_behind_dialogs && tool.guard != Mcp::GuardClass::Mutate; + tool.title = std::move(title); + tool.group = std::move(group); + tool.icon = std::move(icon); + tool.in_palette = true; + tool.input_schema = Mcp::with_silent(std::move(tool.input_schema)); + tool.run = [key = tool.key, person = std::move(person), asks, checked, silent = std::move(tool.run)](const json& args, Mcp::ToolContext& ctx) { + if (!Mcp::person_form(args)) + return silent(args, ctx); + if (!checked || ctx.person()) + return asks(args, ctx); + // An agent's call of a tool whose guard lets it run behind dialogs: the person's form opens what a pick + // opens, so it is refused while a modal dialog is open or another call's nested loop runs, in the UI + // closure that runs it. + Mcp::UiInvoker& ui = ctx.service().ui(); + return ui_command(key, {}, {}, Mcp::object_schema({}), [&person, &ui](const json&) { + ui.require_mutate(); + return person(); + }).run(args, ctx); + }; + return tool; +} + +Mcp::ToolResult NativeCommands::from_run_result(const std::string& key, const AppActionRunResult& result) +{ + // An operation's refusal is worded once, in English here as in a tool's reply. + const std::string message = result.refusal ? result.refusal->english() : into_u8(result.message); + // A command that did nothing (no selection, no objects) fails here, though the palette shows it as + // information. + if (result.level == AppActionRunResult::Level::Error || result.level == AppActionRunResult::Level::Busy || !result.done) { + json details; + if (result.refusal) { + details = {{"code", result.refusal->code}}; + if (!result.refusal->names.empty()) + details["names"] = result.refusal->names; + } + return Mcp::ToolResult::error(message.empty() ? "The action failed" : message, std::move(details)); } + json out{{"ran", key}, {"level", level_name(result.level)}}; + if (!message.empty()) + out["message"] = message; + if (!result.reply.empty()) + if (json reply = json::parse(result.reply, nullptr, /*allow_exceptions=*/false); reply.is_object()) + out.update(reply); + return Mcp::ToolResult::ok(std::move(out)); } -std::optional<std::vector<double>> NativeCommands::parse_sizes(const std::string& param) +AppActionRunResult NativeCommands::run(const std::string& key, const json& args) { - std::vector<std::string> tokens; - boost::split(tokens, param, boost::is_any_of(" ,\t"), boost::token_compress_on); - std::vector<double> sizes; - for (const std::string& token : tokens) { - if (token.empty()) - continue; - size_t end = 0; - const double value = string_to_double_decimal_point(token, &end); - if (end != token.size() || !std::isfinite(value) || value <= 0.) - return std::nullopt; - sizes.push_back(value); - } - if (sizes.empty()) - return std::nullopt; - return sizes; -} - -std::optional<int> NativeCommands::parse_count(const std::string& param) -{ - const std::string text = boost::algorithm::trim_copy(param); - int value = 0; - const char* end = text.data() + text.size(); - const auto res = std::from_chars(text.data(), end, value); - if (text.empty() || res.ec != std::errc() || res.ptr != end || value < 0) - return std::nullopt; - return value; -} - -AppActionRunResult NativeCommands::run(const std::string& key, const std::string& param) -{ - GUI_App& app = wxGetApp(); - if (app.is_closing()) + if (wxGetApp().is_closing()) return {}; - for (const NativeCommand& c : catalog()) - if (c.key == key) - return c.runner(param); - return {AppActionRunResult::Level::Info, _L("Unknown command.")}; + const NativeCommand* command = find(key); + if (command == nullptr) + return {AppActionRunResult::Level::Info, _L("Unknown command.")}; + const auto failed = [](const std::string& why) { return AppActionRunResult{AppActionRunResult::Level::Error, from_u8(why), false}; }; + json checked = args; + if (const std::string err = Mcp::argument_error(*command, checked); !err.empty()) + return failed(err); + Mcp::PersonContext person; + try { + const Mcp::ToolResult reply = command->run(checked, person); + if (reply.notice) + return *reply.notice; + if (reply.is_error) + return failed(reply.message); + return {AppActionRunResult::Level::Success}; + } catch (const std::exception& e) { + return failed(e.what()); + } } void NativeCommands::notify_result(const AppActionRunResult& result) diff --git a/src/slic3r/GUI/NativeCommands.hpp b/src/slic3r/GUI/NativeCommands.hpp index 1657980518..ad1d9da318 100644 --- a/src/slic3r/GUI/NativeCommands.hpp +++ b/src/slic3r/GUI/NativeCommands.hpp @@ -1,58 +1,94 @@ #pragma once +#include "ActionRegistry.hpp" // for AppAction / AppActionRunResult +#include "CommandCatalog.hpp" +#include "Mcp/McpTypes.hpp" + +#include <nlohmann/json.hpp> +#include <wx/string.h> + #include <functional> #include <memory> -#include <optional> #include <string> #include <vector> -#include "ActionRegistry.hpp" // for AppAction / AppActionRunResult - namespace Slic3r { namespace GUI { -// What a command's `param` means, for callers other than the palette (MCP, scripts). The palette -// keeps using `input` for its second-phase picker and never passes a path, so a command that takes -// one still opens its file dialog there. -enum class CommandParamType { None, Percent, Tab, Path, Index, Text }; - -struct CommandParam -{ - CommandParamType type = CommandParamType::None; - std::string help; // English, for agents -}; - -// Commands whose effect finishes after run() returns. Export: the G-code export runs in the -// background process, so an automated caller waits for its file. -enum class CommandCompletion { None, Export }; - -// A built-in speed-dial command: identity + how to run it. make_action() wraps a value as a thin -// AppAction for the registry, so this catalog is the single source of truth for the behaviour -// (runner => an owner method), the presentation (title/group/input), the tile pictogram -// (icon = an SVG base name under resources/images, "" for no icon), and what automation needs to -// call it (description, param, completion). -struct NativeCommand -{ - std::string key; - std::string title; // untranslated English msgid; make_action() translates it for display - std::string group; // likewise - std::string input; // "percent"/"tab" or "" for immediate run - std::string icon; // SVG base name, or "" to render a blank tile - std::function<AppActionRunResult(const std::string& param)> runner; - std::string description; // English, for agents; not shown in the palette - CommandParam param; - CommandCompletion completion = CommandCompletion::None; - // The operations (GUI/Operations) the runner reaches when it is given a param, by function name. A - // command with a param names them or is on the exception list of the catalog test. - std::vector<std::string> operations; -}; - namespace NativeCommands { -// The full built-in command catalog. Built on first use and reused; it holds no translated text, so -// it stays valid across a UI language switch. UI thread only. -const std::vector<NativeCommand>& catalog(); +// Which optional families of commands the process catalog holds. cad: the Design tab is on in this run, so the +// catalog holds its commands (in a build with CAD; a build without it has none). +struct CatalogOptions +{ + bool cad = false; +}; -// Dispatches `key` to its runner (unknown keys return a quiet Info). UI thread only. -AppActionRunResult run(const std::string& key, const std::string& param = {}); +// Adds the built-in commands to `catalog`: the Speed Dial's, each with in_palette, then the typed tools, each +// listed, family by family (Mcp::register_app_tools() and the others), and with options.cad the Design tab's +// (Mcp::register_cad_commands()), not listed, of which those with an action have a tile the Speed Dial shows +// in the Design tab. new_project, save_project, start_recording and stop_recording are both: typed tools with +// a tile (with_person_form()). undo and redo act on the Design tab's history or the project's, a person's pick +// as the Edit menu's item does; with options.cad their examples show the Design tab's. +void register_all_commands(CommandCatalog& catalog, const CatalogOptions& options); + +// Builds and seals the process catalog. UI thread, once, at startup; a second call, or a call after +// instance() built the catalog by itself, throws std::logic_error. +void build(const CatalogOptions& options); + +// The process catalog, sealed. In the app, GUI_App's startup builds it before anything reads it; where +// build() never runs, in the unit tests and in the stdio bridge answering with no app running, the first +// read builds it with CatalogOptions{}. It holds no translated text, so it stays valid across a UI language +// switch. Any thread. +const CommandCatalog& instance(); + +// The commands a person picks from the Speed Dial whatever tab is shown: those with in_palette, in the order +// they were added, but the Design tab's (group kDesignGroup), whose tiles the Speed Dial has only while that tab +// is shown (ActionRegistry::materialize_design_actions()). +std::vector<const NativeCommand*> palette_commands(const CommandCatalog& catalog); + +// A command whose function runs on the UI thread and says what a person's pick shows. Its run: for a +// person's pick (ToolContext::person()), `fn(args)` in place, its result as the reply's notice. For an +// automated call, `fn(args)` in one UI closure, then one more pass of the UI's events (Mcp::settle()), and +// the reply from_run_result() makes of it. With `completion` Export and arguments, the call also holds the +// project as an operation from before `fn` starts the export, and waits for the file it writes; called with +// no arguments, an Export command does its person's form and waits for nothing. +NativeCommand ui_command(std::string key, std::string title, std::string group, nlohmann::json schema, + std::function<AppActionRunResult(const nlohmann::json& args)> fn, + CommandCompletion completion = CommandCompletion::None); + +// A command whose function runs where its call does: on the job's thread for an automated call. Picked by a +// person it is started as a job (ToolContext::submit()) and returns at once, unless `inline_call` says it +// runs on the calling thread, where its function then runs. +NativeCommand long_command(std::string key, std::string title, std::string group, nlohmann::json schema, CommandFn fn, + bool inline_call = false); + +// A typed tool that a person picks too: `tool` with the tile's `title`, `group` and `icon`, in_palette, and its +// schema through Mcp::with_silent(). Its run, called with no arguments, is the person's form: `person` on the +// UI thread, as ui_command() runs a function. Called with arguments, or silent: true, it is the tool's own +// function, given the arguments as they are, silent included, so that what the function journals keeps it. +// An agent's call of the person's form is refused while a modal dialog is open or another call's nested loop +// runs (Mcp::UiInvoker::require_mutate()), also where the tool's guard lets it run behind dialogs, unless +// `person_form_behind_dialogs` says the form opens nothing and may run where the tool does. +NativeCommand with_person_form(NativeCommand tool, std::string title, std::string group, std::string icon, + std::function<AppActionRunResult()> person, bool person_form_behind_dialogs = false); + +// The person's forms of start_recording and stop_recording. UI thread. +// The Start Recording dialog, with the settings it remembers, and the person's recording it starts: the main +// window, with the overlays the settings ask for, for up to an hour, into the folder the settings name. +AppActionRunResult start_person_recording(); +// Stops the running recording, whoever started it, without waiting for its file, and shows the person a +// notification naming it; the reply has its path. +AppActionRunResult stop_recording_in_app(); + +// What a command's result replies to an automated call: {"ran": key, "level", "message"?} with the fields +// of its `reply`. It is an error for a Busy or Error level and for a command that did nothing; an operation's +// refusal is worded in English, with {"code", "names"?} as the error's details. +Mcp::ToolResult from_run_result(const std::string& key, const AppActionRunResult& result); + +// Runs command `key` as a person's pick: checks `args` (Mcp::argument_error()), then runs the command with a +// Mcp::PersonContext. Returns what the pick shows, the reply's notice, or an Error holding the message when +// the arguments were refused, the command threw, or it failed with no notice. Unknown keys return a quiet +// Info. UI thread only. +AppActionRunResult run(const std::string& key, const nlohmann::json& args = nlohmann::json::object()); // Shows what a command run from the palette or a menu said: its message as a notification at its level, // nothing for an empty message or a Busy one. UI thread only. @@ -61,22 +97,19 @@ void notify_result(const AppActionRunResult& result); // Whether a recording is being written, whoever started it. UI thread only. bool recording_active(); -// The catalog entry for `key`, or nullptr. +// The process catalog's command `key`, or nullptr. Any thread. const NativeCommand* find(const std::string& key); -const char* param_type_name(CommandParamType type); +// A command's title as its tile shows it, in the UI's language, translated in its title_context(): a Design +// command's, its entry's name, in the Design context, as the right-click menu names a row; any other command's +// title with no context. The Speed Dial's tiles, the replay and script editors and the notice of a job a person +// started show a command's title with it; a recording's caption translates the title in the same context on its +// own (title_context()). UI thread only. +wxString tile_title(const NativeCommand& command); -// The positive numbers of a size param, separated by spaces or commas ("90 4", "90,4"); nullopt when -// it holds anything else or nothing. -std::optional<std::vector<double>> parse_sizes(const std::string& param); - -// A count param: a whole number of 0 or more, nothing else ("6", " 6 "); nullopt otherwise. -std::optional<int> parse_count(const std::string& param); - -// Materialises one catalog entry as a runnable AppAction, titled in the current UI language with the -// English title/group kept as search aliases. Keeps the catalog's identity, presentation and -// behaviour as the single source of truth; ActionRegistry only stores and dispatches the result. -// UI thread only. +// Materialises one catalog entry as a runnable AppAction, titled tile_title() with the English title/group +// kept as search aliases. Keeps the catalog's identity, presentation and behaviour as the single source of +// truth; ActionRegistry only stores and dispatches the result. UI thread only. std::unique_ptr<AppAction> make_action(const NativeCommand& command); } // namespace NativeCommands diff --git a/src/slic3r/GUI/RunScriptPanel.cpp b/src/slic3r/GUI/RunScriptPanel.cpp index b8868bdaef..09794e3b4a 100644 --- a/src/slic3r/GUI/RunScriptPanel.cpp +++ b/src/slic3r/GUI/RunScriptPanel.cpp @@ -647,7 +647,7 @@ void RunScriptPanel::send_service_state() m_ready_timer.Start(500); send({{"command", "service"}, {"ready", ready}}); if (ready) - send({{"command", "catalog"}, {"tools", Mcp::editor_tool_catalog(s->registry())}}); + send({{"command", "catalog"}, {"tools", Mcp::editor_tool_catalog(s->catalog())}}); } // The orca.host API's entries, read once per app run on a thread of the panel's, which it joins. diff --git a/src/slic3r/GUI/SpeedDialDialog.cpp b/src/slic3r/GUI/SpeedDialDialog.cpp index da7634fe90..a3e7e7f842 100644 --- a/src/slic3r/GUI/SpeedDialDialog.cpp +++ b/src/slic3r/GUI/SpeedDialDialog.cpp @@ -327,6 +327,7 @@ void SpeedDialWebDialog::handle_web_command(const nlohmann::json& payload) const bool ok = wxGetApp().action_registry().set_favourite(fav_id, payload.value("fav", false)); if (!ok) call_web_handler({{"command", "favourite_full"}, {"limit", (int) ActionRegistry::kFavLimit}, {"id", fav_id}}); + send_favourites(); } else if (command == "reorder_favourites") { std::vector<std::string> ids; if (payload.contains("ids") && payload["ids"].is_array()) @@ -334,10 +335,11 @@ void SpeedDialWebDialog::handle_web_command(const nlohmann::json& payload) if (id.is_string()) ids.push_back(id.get<std::string>()); wxGetApp().action_registry().reorder_favourites(ids); + send_favourites(); } else if (command == "set_tooltip_expanded") wxGetApp().action_registry().set_tooltip_expanded(payload.value("expanded", true)); else if (command == "run_action") - run_action(payload.value("id", ""), payload.value("title", ""), payload.value("param", "")); + run_action(payload.value("id", ""), payload.value("title", ""), payload.value("args", nlohmann::json::object())); else if (command == "open_wiki") open_wiki(payload.value("id", "")); else if (command == "search_tabs") @@ -456,7 +458,7 @@ void SpeedDialWebDialog::on_dpi_changed(const wxRect&) Refresh(); } -void SpeedDialWebDialog::run_action(const std::string& id, const std::string& title, const std::string& param) +void SpeedDialWebDialog::run_action(const std::string& id, const std::string& title, const nlohmann::json& args) { ActionRegistry& reg = wxGetApp().action_registry(); const AppAction* a = reg.by_id(id); @@ -505,9 +507,9 @@ void SpeedDialWebDialog::run_action(const std::string& id, const std::string& ti wxGetApp().action_registry().suppress_ask(id); } - wxGetApp().CallAfter([id, param] { + wxGetApp().CallAfter([id, args] { if (!wxGetApp().is_closing()) - NativeCommands::notify_result(wxGetApp().action_registry().run(id, param)); + NativeCommands::notify_result(wxGetApp().action_registry().run(id, args)); }); } @@ -531,4 +533,9 @@ void SpeedDialWebDialog::send_actions() {"tooltip_expanded", std::move(snap["tooltip_expanded"])}}); } +void SpeedDialWebDialog::send_favourites() +{ + call_web_handler({{"command", "favourites"}, {"favourites", wxGetApp().action_registry().favourites_bar()}}); +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/SpeedDialDialog.hpp b/src/slic3r/GUI/SpeedDialDialog.hpp index 9fe28d7510..eed989ae0c 100644 --- a/src/slic3r/GUI/SpeedDialDialog.hpp +++ b/src/slic3r/GUI/SpeedDialDialog.hpp @@ -50,9 +50,14 @@ private: // cleared, so ask the window itself instead. bool is_active(); void resize_to_content(int height); - void run_action(const std::string& id, const std::string& title, const std::string& param = ""); + // Runs action `id` as the person picked it, with the command arguments the page passes: none for a plain + // pick, the value of the second phase for Go to layer and Go to tab. + void run_action(const std::string& id, const std::string& title, const nlohmann::json& args); void open_wiki(const std::string& id); void send_actions(); + // Sends the page the bar as the registry now shows it (ActionRegistry::favourites_bar()), after a pin, an unpin + // or a reorder: an unpin can bring a pin past the tenth onto the bar, and the page's own copy would not know. + void send_favourites(); void search_tabs(); void apply_rounded_shape(); // Forces the webview to repaint after it is mapped / re-rendered. The popup is transparent and diff --git a/src/slic3r/plugin/host/PluginHostTools.cpp b/src/slic3r/plugin/host/PluginHostTools.cpp index b53ac486ce..6f11d37f1c 100644 --- a/src/slic3r/plugin/host/PluginHostTools.cpp +++ b/src/slic3r/plugin/host/PluginHostTools.cpp @@ -2,10 +2,13 @@ #include "PluginHostBindings.hpp" +#include <slic3r/GUI/CommandCatalog.hpp> +#include <slic3r/GUI/NativeCommands.hpp> #include <slic3r/plugin/PluginAuditManager.hpp> #include <slic3r/plugin/PluginJsonPy.hpp> #include <slic3r/plugin/PythonRunScope.hpp> +#include <nlohmann/json.hpp> #include <pybind11/eval.h> #include <pybind11/gil.h> #include <pybind11/pybind11.h> @@ -19,6 +22,7 @@ #include <stdexcept> #include <string> #include <utility> +#include <vector> namespace Slic3r { @@ -48,6 +52,35 @@ class ToolError(Exception): self.details = details )PY"; +// Raises orca.host.tools.ToolError with `message` and `details`. +[[noreturn]] void raise_tool_error(py::module_& tools, const std::string& message, const json& details) +{ + py::object error = tools.attr("ToolError")(message, json_to_py(details)); + PyErr_SetObject(reinterpret_cast<PyObject*>(Py_TYPE(error.ptr())), error.ptr()); + throw py::error_already_set(); +} + +// What orca.host.tools.list() gives: the process catalog's commands in the order they were added, then those its +// sources hold now. +json list_commands() +{ + const GUI::CommandCatalog& catalog = GUI::NativeCommands::instance(); + json out = json::array(); + const auto add = [&out](const GUI::NativeCommand& c) { + out.push_back({{"name", c.key}, + {"title", c.title}, + {"group", c.group}, + {"description", c.description}, + {"read_only", c.read_only}, + {"listed", c.listed}}); + }; + for (const GUI::NativeCommand& c : catalog.commands()) + add(c); + for (const std::shared_ptr<const GUI::NativeCommand>& c : catalog.source_commands()) + add(*c); + return out; +} + json call_tool(py::module_& tools, const std::string& name, const py::object& args) { const json arguments = args.is_none() ? json::object() : py_to_json(args); @@ -86,9 +119,7 @@ json call_tool(py::module_& tools, const std::string& name, const py::object& ar py::gil_scoped_release release; return caller(identity, name, arguments); } catch (const ToolCallError& e) { - py::object error = tools.attr("ToolError")(e.what(), json_to_py(e.details)); - PyErr_SetObject(reinterpret_cast<PyObject*>(Py_TYPE(error.ptr())), error.ptr()); - throw py::error_already_set(); + raise_tool_error(tools, e.what(), e.details); } } @@ -117,7 +148,8 @@ namespace host_bindings { void register_tools(py::module_& host) { py::module_ tools = host.def_submodule("tools", "Calls the MCP tools from Python: the same tools, arguments and results " - "an agent gets, with each tool's guards, admission and undo."); + "an agent gets, with each tool's guards, admission and undo; list() and " + "describe() say what there is to call."); py::exec(kToolErrorSource, tools.attr("__dict__")); tools.def( @@ -143,6 +175,48 @@ void register_tools(py::module_& host) "Run a replay ({orca_replay: 1, steps: [...]}) as the run_replay tool does, and return its result. " "`replay` is the replay as a dict or as its JSON text, which may hold comments as a replay file does; " "`vars` override the replay's vars. For a replay file, call(\"run_replay\", {\"path\": ...})."); + // Both only read the catalog, which is sealed and read on any thread, so neither needs a run or a plugin. They read + // it without the GIL, as call() waits without it; no thread holds the plugin operations' lock while it waits for the GIL. + tools.def( + "list", + [] { + json commands; + { + py::gil_scoped_release release; + commands = list_commands(); + } + return json_to_py(commands); + }, + "Every command call() reaches, as a list of {name, title, group, description, read_only, listed}: the tools, the " + "Speed Dial's commands and the Design tab's (with the CAD feature on), in the order the app adds them, then the " + "operations the loaded plugins offer (plugin.<plugin>.<name>). title and description are in English; listed says " + "whether an agent's tool list shows it, read_only that it changes nothing. Any thread."); + tools.def( + "describe", + [tools](const std::string& name) mutable { + json entry; + std::string unknown; // the error for a name the catalog does not hold + json close; + { + py::gil_scoped_release release; + const GUI::CommandCatalog& catalog = GUI::NativeCommands::instance(); + if (const std::shared_ptr<const GUI::NativeCommand> command = catalog.lookup(name)) { + entry = GUI::command_reference(*command); + } else { + unknown = catalog.unknown_command(name); + close = catalog.similar(name); + } + } + if (!unknown.empty()) + raise_tool_error(tools, unknown, {{"did_you_mean", close}}); + return json_to_py(entry); + }, + py::arg("name"), + "The command `name` as a dict: key, title, group, description, input_schema (the JSON Schema of its " + "arguments), examples when it has some ([{title, calls: [{tool, args}]}]), listed, in_palette (a person can " + "pick it in the Speed Dial), the access labels read_only, destructive, idempotent and open_world, guard " + "(inspect, recover or mutate: what it may do behind a dialog), completion and operations. An unknown name " + "raises ToolError, whose details hold did_you_mean, the closest names. Any thread."); } } // namespace host_bindings diff --git a/tests/data/command_catalog.json b/tests/data/command_catalog.json new file mode 100644 index 0000000000..98f72c559d --- /dev/null +++ b/tests/data/command_catalog.json @@ -0,0 +1,15760 @@ +{ + "commands": [ + { + "completion": "none", + "description": "Slice the current plate and show the Preview tab. Returns at once; use the slice tool to wait for the result.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "slice_and_preview", + "listed": false, + "open_world": false, + "operations": [ + "start_slice" + ], + "read_only": false, + "title": "Slice and Preview" + }, + { + "completion": "none", + "description": "Slice every plate and show the Preview tab. Returns at once; use the slice tool to wait for results.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "slice_all", + "listed": false, + "open_world": false, + "operations": [ + "start_slice" + ], + "read_only": false, + "title": "Slice All Plates" + }, + { + "completion": "none", + "description": "Show the Preview tab at a layer chosen as a percentage of the layer range; an error while the Preview has no layers (slice first).", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "percent": { + "description": "The layer to show, as a percentage of the layer range.", + "maximum": 100, + "minimum": 0, + "type": "number" + } + }, + "required": [ + "percent" + ], + "type": "object" + }, + "key": "go_to_layer", + "listed": false, + "open_world": false, + "operations": [ + "show_layer_range" + ], + "read_only": false, + "title": "Go to layer (percent)" + }, + { + "completion": "none", + "description": "Switch to a main window tab.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "tab": { + "description": "The tab's id: home, prepare, preview, monitor, project, calibration, or a plugin page's id.", + "type": "string" + } + }, + "required": [ + "tab" + ], + "type": "object" + }, + "key": "go_to_tab", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Go to tab..." + }, + { + "completion": "none", + "description": "Open a project. With a path, opens that file without a dialog (asks first if the current project has unsaved changes).", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of a .3mf project.", + "type": "string" + } + }, + "type": "object" + }, + "key": "load_project", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Load Project" + }, + { + "completion": "none", + "description": "Save the project as a .3mf file. With a path, saves there without a dialog; a name ending in .gcode.3mf is refused (export_sliced_file writes that).", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .3mf project to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "save_project_as", + "listed": false, + "open_world": false, + "operations": [ + "save_project_as" + ], + "read_only": false, + "title": "Save Project As" + }, + { + "completion": "none", + "description": "Take back the last change of a history, as Edit > Undo does. history design is the Design tab's: the last feature added, edited, deleted, moved, shown or hidden, or renamed, or variable changed, or in a sketch session the last drawn shape; project is the project's. Without history, the Design tab's while it is shown, else the project's. Reply: history and, for the Design tab's, result: scope (design or sketch), undo_depth, redo_depth, features, bodies and generation; entities in a sketch.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "history": "design" + }, + "tool": "undo" + } + ], + "title": "Take back an extrude, its sketch with it" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "history": "design" + }, + "tool": "undo" + } + ], + "title": "Take back the last shape drawn in a sketch" + } + ], + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "history": { + "description": "The history: design, the Design tab's (with the CAD feature on), or project. Default: the Design tab's while it is shown, else the project's.", + "enum": [ + "design", + "project" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "undo", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Undo" + }, + { + "completion": "none", + "description": "Put back what undo took back, until the next change, as Edit > Redo does, in the history undo takes. Reply as undo's.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "history": "design" + }, + "tool": "undo" + }, + { + "args": { + "history": "design" + }, + "tool": "redo" + } + ], + "title": "Put back an extrude undo took back" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "history": "design" + }, + "tool": "undo" + }, + { + "args": { + "history": "design" + }, + "tool": "redo" + } + ], + "title": "Put back the shape undo took off a sketch" + } + ], + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "history": { + "description": "The history: design, the Design tab's (with the CAD feature on), or project. Default: the Design tab's while it is shown, else the project's.", + "enum": [ + "design", + "project" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "redo", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Redo" + }, + { + "completion": "none", + "description": "Show or hide the Run Script panel, where a person writes and runs Python scripts cell by cell. Agents run Python with the run_script tool instead.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "toggle_run_script", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Run Script" + }, + { + "completion": "none", + "description": "Open the Action Replay window, where a person opens a replay file (an orca_replay), reads its steps and replays them. Agents run replays with the run_replay tool instead.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "open_action_replay", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Action Replay" + }, + { + "completion": "none", + "description": "Open the Preferences dialog on a tab, scrolled to one preference when given (shown on its own tab). Its controls are named after their preference keys: set_widget_value {\"target\": {\"name\": key, \"within\": \"Preferences\"}} changes one through the dialog; get_settings scope preferences reads them.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "key": { + "description": "A preference on that tab, e.g. auto_arrange on behaviour: its control is scrolled into view and focused.", + "type": "string" + }, + "tab": { + "description": "The tab to show.", + "enum": [ + "general", + "files", + "behaviour", + "control", + "graphics", + "online", + "developer" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "open_preferences", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Preferences" + }, + { + "completion": "none", + "description": "Save a PNG of the main window in the folder Start Recording saves in (the person's Downloads unless they chose another) and show the person a notification naming it; the reply has its path. Agents use the screenshot tool, which returns the image.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "take_screenshot", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Take Screenshot" + }, + { + "completion": "none", + "description": "Switch the settings view to Simple mode.", + "destructive": false, + "group": "Mode", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "mode_simple", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mode: Simple" + }, + { + "completion": "none", + "description": "Switch the settings view to Advanced mode.", + "destructive": false, + "group": "Mode", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "mode_advanced", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mode: Advanced" + }, + { + "completion": "none", + "description": "Switch the settings view to Expert mode.", + "destructive": false, + "group": "Mode", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "mode_expert", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mode: Expert" + }, + { + "completion": "none", + "description": "Turn Developer mode on or off.", + "destructive": false, + "group": "Mode", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "toggle_developer_mode", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Toggle Developer Mode" + }, + { + "completion": "export", + "description": "Export the current plate's G-code. With a path, exports there without a dialog once the plate is sliced, in the background, and the call returns when the file is written; with no arguments, it opens the export dialog.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .gcode file to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_gcode", + "listed": false, + "open_world": false, + "operations": [ + "start_gcode_export" + ], + "read_only": false, + "title": "Export G-code" + }, + { + "completion": "none", + "description": "Export all objects as one STL. With a path, writes there without a dialog.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .stl file to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_stl", + "listed": false, + "open_world": false, + "operations": [ + "export_stl" + ], + "read_only": false, + "title": "Export STL" + }, + { + "completion": "none", + "description": "Export the model as a .3mf without slicing data. With a path, writes there without a dialog.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .3mf file to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_3mf", + "listed": false, + "open_world": false, + "operations": [ + "export_model_3mf" + ], + "read_only": false, + "title": "Export 3MF" + }, + { + "completion": "none", + "description": "Export the current plate's sliced file (.gcode.3mf). With a path, writes there without a dialog.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .gcode.3mf file to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_sliced_file", + "listed": false, + "open_world": false, + "operations": [ + "export_sliced_3mf" + ], + "read_only": false, + "title": "Export Sliced File" + }, + { + "completion": "none", + "description": "Export every plate's sliced file into one .gcode.3mf. With a path, writes there without a dialog.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "overwrite": { + "description": "Replace a file that exists already. Default false.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the .gcode.3mf file to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_all_sliced_file", + "listed": false, + "open_world": false, + "operations": [ + "export_sliced_3mf" + ], + "read_only": false, + "title": "Export All Sliced Files" + }, + { + "completion": "none", + "description": "Open the Send G-code to printer host dialog for the current plate, as the Print button does for a printer with a print host (OctoPrint, Moonraker, PrusaLink, Duet...). Set the file name with set_widget_value and press Upload or Upload and Print with answer_dialog; the plate is sliced if needed, then uploaded in the background: get_app_state.uploads shows the row's state, and a failed upload also opens an error dialog. A replay uploads again. Fails for a printer without a print host, or one that prints through the Bambu network or printer agents.", + "destructive": false, + "group": "Slice & Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "send_gcode", + "listed": false, + "open_world": false, + "operations": [ + "send_gcode_to_host" + ], + "read_only": false, + "title": "Send G-code to printer host" + }, + { + "completion": "none", + "description": "Open the Temperature Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_temperature", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Temperature Calibration" + }, + { + "completion": "none", + "description": "Open the Max Volumetric Speed Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_max_volumetric", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Max Volumetric Speed Calibration" + }, + { + "completion": "none", + "description": "Open the Pressure Advance Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_pressure_advance", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Pressure Advance Calibration" + }, + { + "completion": "none", + "description": "Open the Flow Ratio Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_flow_ratio", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Flow Ratio Calibration" + }, + { + "completion": "none", + "description": "Open the Retraction Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_retraction", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Retraction Calibration" + }, + { + "completion": "none", + "description": "Open the Cornering Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_cornering", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cornering Calibration" + }, + { + "completion": "none", + "description": "Open the Input Shaping Frequency Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_input_shaping_freq", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Input Shaping Frequency Calibration" + }, + { + "completion": "none", + "description": "Open the Input Shaping Damping Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_input_shaping_damp", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Input Shaping Damping Calibration" + }, + { + "completion": "none", + "description": "Open the VFA Calibration dialog; the generate_calibration_test tool runs the same test with typed parameters and no dialog.", + "destructive": false, + "group": "Calibration", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "calib_vfa", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "VFA Calibration" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Top.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_top", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Top" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Bottom.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_bottom", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Bottom" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Front.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_front", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Front" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Rear.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_rear", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Rear" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Left.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_left", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Left" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Right.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_right", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Right" + }, + { + "completion": "none", + "description": "Point the 3D camera: View: Isometric.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_iso", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Isometric" + }, + { + "completion": "none", + "description": "Reset the 3D camera to the default view and fit the plate.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_default", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "View: Default" + }, + { + "completion": "none", + "description": "Fit the build plate in the 3D view.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_fit_bed", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Fit Bed to View" + }, + { + "completion": "none", + "description": "Switch the 3D camera between perspective and orthographic.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "view_toggle_perspective", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Toggle Perspective" + }, + { + "completion": "none", + "description": "Restore the default window layout.", + "destructive": false, + "group": "View", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "reset_window_layout", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Reset Window Layout" + }, + { + "completion": "none", + "description": "Delete the selected objects or parts.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete Selected" + }, + { + "completion": "none", + "description": "Delete all objects.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_delete_all", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete All Objects" + }, + { + "completion": "none", + "description": "Select all objects in the 3D view.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "select_all", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Select All Objects" + }, + { + "completion": "none", + "description": "Clear the selection.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "deselect_all", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Deselect All" + }, + { + "completion": "none", + "description": "Mirror the selection along X.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_mirror_x", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mirror X" + }, + { + "completion": "none", + "description": "Mirror the selection along Y.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_mirror_y", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mirror Y" + }, + { + "completion": "none", + "description": "Mirror the selection along Z.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_mirror_z", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mirror Z" + }, + { + "completion": "none", + "description": "Split the selected object into separate objects.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_split_objects", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Split to Objects" + }, + { + "completion": "none", + "description": "Split the selected object into parts.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_split_parts", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Split to Parts" + }, + { + "completion": "none", + "description": "Center the selection on its plate.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_center", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Center Selected on Plate" + }, + { + "completion": "none", + "description": "Drop the selection onto the bed.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_drop", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Drop to Bed" + }, + { + "completion": "none", + "description": "Scale the selection to fit the print volume.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_fit_volume", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Scale to Fit Print Volume" + }, + { + "completion": "none", + "description": "Add an instance of the selected object.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_instances_up", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Increase Instances" + }, + { + "completion": "none", + "description": "Remove an instance of the selected object.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_instances_down", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Decrease Instances" + }, + { + "completion": "none", + "description": "Arrange all objects on the unlocked plates with the saved Arrange options, as the toolbar does; the call returns when the arrangement is done. The arrange tool also takes options, one plate or fill bed.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_arrange", + "listed": false, + "open_world": false, + "operations": [ + "start_arrange" + ], + "read_only": false, + "title": "Auto-Arrange" + }, + { + "completion": "none", + "description": "Auto-orient the selection, or every object when nothing is selected; the call returns when it is done.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_orient", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Auto-Orient" + }, + { + "completion": "none", + "description": "Make the selected parts (select_objects {parts} first) solid parts, as Change Type does. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_part", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Part" + }, + { + "completion": "none", + "description": "Make the selected parts negative parts, as Change Type does; not the object's last solid part. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_negative", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Negative Part" + }, + { + "completion": "none", + "description": "Make the selected parts modifiers, as Change Type does; not the object's last solid part. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_modifier", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Modifier" + }, + { + "completion": "none", + "description": "Make the selected parts support blockers, as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_support_blocker", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Support Blocker" + }, + { + "completion": "none", + "description": "Make the selected parts support enforcers, as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_support_enforcer", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Support Enforcer" + }, + { + "completion": "none", + "description": "Make the selected parts Center precise seams (seams keep their subtype), as Change Type does; not the object's last solid part, nor a text or SVG part. Parts are listed by type, so part indices change.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_type_precise_seam", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Change Type to Precise Seam" + }, + { + "completion": "none", + "description": "Rename the selected object or part (select one). With a name, skips the Rename dialog; an empty name, or one with characters a file name cannot hold, is refused.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The new name, in place of the Rename dialog.", + "type": "string" + } + }, + "type": "object" + }, + "key": "obj_rename", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rename" + }, + { + "completion": "none", + "description": "Give the selected object this many instances, in one undo step. With a count, skips the dialog. New instances overlap; arrange afterwards. The reply has object and instances.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "count": { + "description": "The total number of instances, up to 1000, in place of the dialog.", + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "key": "obj_set_instances", + "listed": false, + "open_world": false, + "operations": [ + "set_instance_count" + ], + "read_only": false, + "title": "Set Number of Instances" + }, + { + "completion": "none", + "description": "Assemble two or more selected objects into one object of parts named Assembly. They are removed and it is added last, so object indices change; the reply has its index (object) and name.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_assemble", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Assemble" + }, + { + "completion": "none", + "description": "Make each instance of the selected object a separate object (select_objects {objects: [n]}); with some of its instances selected, only those. New objects are added last; the reply lists the objects the instances are in now (objects).", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "obj_instances_to_objects", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set as Individual Objects" + }, + { + "completion": "none", + "description": "Order the current plate's objects by name, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "all": { + "description": "Order the objects of every plate. Default false: the current plate's.", + "type": "boolean" + } + }, + "type": "object" + }, + "key": "obj_order_by_name", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Order by Name" + }, + { + "completion": "none", + "description": "Order the current plate's objects by filament, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "all": { + "description": "Order the objects of every plate. Default false: the current plate's.", + "type": "boolean" + } + }, + "type": "object" + }, + "key": "obj_order_by_filament", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Order by Filament" + }, + { + "completion": "none", + "description": "Order the current plate's objects by height, which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "all": { + "description": "Order the objects of every plate. Default false: the current plate's.", + "type": "boolean" + } + }, + "type": "object" + }, + "key": "obj_order_by_height", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Order by Height" + }, + { + "completion": "none", + "description": "Order the current plate's objects by size (bounding box volume), which sets the object list and print order, as the plate menu's Order By does. Choosing the order they already have reverses it. Object indices change; the reply lists the new order (order: [{object, name, plate}]) and descending.", + "destructive": false, + "group": "Object", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "all": { + "description": "Order the objects of every plate. Default false: the current plate's.", + "type": "boolean" + } + }, + "type": "object" + }, + "key": "obj_order_by_size", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Order by Size" + }, + { + "completion": "none", + "description": "Add a cube object to the current plate; fails while an object is selected. With a size, skips the size dialog.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [X, Y, Z] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_cube", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cube" + }, + { + "completion": "none", + "description": "Add a cylinder object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [diameter, height] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_cylinder", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cylinder" + }, + { + "completion": "none", + "description": "Add a sphere object to the current plate; fails while an object is selected. With a size, skips the size dialog.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [diameter] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_sphere", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sphere" + }, + { + "completion": "none", + "description": "Add a cone object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [base diameter, height] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_cone", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cone" + }, + { + "completion": "none", + "description": "Add a disc object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [diameter, height] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_disc", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Disc" + }, + { + "completion": "none", + "description": "Add a torus object to the current plate; fails while an object is selected. With a size, skips the size dialog. The shape may then be turned toward the part-cooling fan, so the size is along its own axes before that turn.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "size": { + "description": "The size, [inner diameter, tube diameter] in mm, each above 0, in place of the size dialog.", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "add_primitive_torus", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Torus" + }, + { + "completion": "none", + "description": "Add a Text object to the current plate.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_primitive_text", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Text" + }, + { + "completion": "none", + "description": "Add an SVG as a new object, or as a part of the selected object. With a path, uses that file without a dialog; the part is created in the background (wait for idle), and the SVG gizmo opens on it.", + "destructive": false, + "group": "Add Primitive", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of an .svg file.", + "type": "string" + } + }, + "type": "object" + }, + "key": "add_primitive_svg", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "SVG" + }, + { + "completion": "none", + "description": "Add a Orca Cube object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_orca_cube", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Orca Cube" + }, + { + "completion": "none", + "description": "Add a OrcaSliced Combo object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_orcasliced_combo", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "OrcaSliced Combo" + }, + { + "completion": "none", + "description": "Add a Orca Badge object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_orca_badge", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Orca Badge" + }, + { + "completion": "none", + "description": "Add a Orca Tolerance Test object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_orca_tolerance_test", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Orca Tolerance Test" + }, + { + "completion": "none", + "description": "Add a 3DBenchy object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_3dbenchy", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "3DBenchy" + }, + { + "completion": "none", + "description": "Add a Cali Cat object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_cali_cat", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cali Cat" + }, + { + "completion": "none", + "description": "Add a Autodesk FDM Test object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_autodesk_fdm_test", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Autodesk FDM Test" + }, + { + "completion": "none", + "description": "Add a Voron Cube object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_voron_cube", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Voron Cube" + }, + { + "completion": "none", + "description": "Add a Stanford Bunny object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_stanford_bunny", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Stanford Bunny" + }, + { + "completion": "none", + "description": "Add a Orca String Hell object to the current plate.", + "destructive": false, + "group": "Add Handy models", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "add_handy_orca_string_hell", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Orca String Hell" + }, + { + "completion": "none", + "description": "Add a plate.", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "plate_add", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Add Plate" + }, + { + "completion": "none", + "description": "Duplicate the current plate.", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "plate_duplicate", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Duplicate Plate" + }, + { + "completion": "none", + "description": "Delete the current plate.", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "plate_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete Plate" + }, + { + "completion": "none", + "description": "Rename the current plate (opens a dialog).", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "plate_rename", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rename Plate" + }, + { + "completion": "none", + "description": "Lock or unlock the current plate.", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "plate_toggle_lock", + "listed": false, + "open_world": false, + "operations": [ + "set_plate_locked" + ], + "read_only": false, + "title": "Toggle Plate Lock" + }, + { + "completion": "none", + "description": "Make a plate the current one; an index the project lacks is an error.", + "destructive": false, + "group": "Plate", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "plate": { + "description": "The plate's 0-based index. Default 0.", + "type": "integer" + } + }, + "type": "object" + }, + "key": "plate_goto", + "listed": false, + "open_world": false, + "operations": [ + "select_plate" + ], + "read_only": false, + "title": "Go to Plate" + }, + { + "completion": "none", + "description": "Synchronize the filament list from the connected printer's AMS.", + "destructive": false, + "group": "Printer", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sync_ams", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Synchronize Filament List from AMS" + }, + { + "completion": "none", + "description": "Add a filament slot, as the + button above the filament list does; the message names the new slot. It takes the next colour and the last slot's preset (change them with select_preset filament_slot and set_settings scope project filament_colour). It goes after the physical slots: mixed filaments move up by one, and objects on them follow.", + "destructive": false, + "group": "Filament", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "filament_add", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Add Filament Slot" + }, + { + "completion": "none", + "description": "Delete a filament slot, as its Delete menu item does; objects on it move to another slot. A mixed filament (project scope filament_is_mixed) is refused.", + "destructive": false, + "group": "Filament", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "slot": { + "description": "The 1-based filament slot. Default: the last physical slot, as the - button.", + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "key": "filament_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete Filament Slot" + }, + { + "completion": "none", + "description": "Open the preset bundle manager.", + "destructive": false, + "group": "Presets", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "preset_bundle", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Open Preset Bundle" + }, + { + "completion": "none", + "description": "Synchronize user presets with the cloud account.", + "destructive": false, + "group": "Presets", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sync_presets", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sync Presets" + }, + { + "completion": "none", + "description": "Import models (3MF/STL/STEP/SVG/OBJ/AMF). With a path, adds that file's geometry without a dialog, as one undo step; a project file's settings are not loaded (load_project opens a project).", + "destructive": false, + "group": "Import", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of a model file.", + "type": "string" + } + }, + "type": "object" + }, + "key": "import_file", + "listed": false, + "open_world": false, + "operations": [ + "import_models" + ], + "read_only": false, + "title": "Import 3MF/STL/STEP/SVG/OBJ/AMF" + }, + { + "completion": "none", + "description": "Import models from a ZIP archive (opens a file dialog).", + "destructive": false, + "group": "Import", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "import_zip_archive", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Import ZIP Archive" + }, + { + "completion": "none", + "description": "Import presets. With a path, imports a preset .json, a .zip of them or an .orca_printer, .orca_filament or .orca_bundle without a dialog, and the message names the presets imported, replaced and kept; a .gcode loads the settings it was sliced with.", + "destructive": false, + "group": "Import", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "on_conflict": { + "description": "What happens to a preset that exists already. Default skip.", + "enum": [ + "skip", + "overwrite" + ], + "type": "string" + }, + "path": { + "description": "Absolute path of a preset .json, a .zip of them, an .orca_printer, .orca_filament or .orca_bundle, or a .gcode.", + "type": "string" + } + }, + "type": "object" + }, + "key": "import_configs", + "listed": false, + "open_world": false, + "operations": [ + "import_presets" + ], + "read_only": false, + "title": "Import Configs" + }, + { + "completion": "none", + "description": "Export each object as its own STL. With a directory, writes there without a dialog.", + "destructive": false, + "group": "Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of an existing directory to write into.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_stl_multi", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export All Objects as STLs" + }, + { + "completion": "none", + "description": "Export all objects as one Draco (.drc) file.", + "destructive": false, + "group": "Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "export_drc_single", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export All Objects as DRC (one file)" + }, + { + "completion": "none", + "description": "Export each object as its own Draco (.drc) file.", + "destructive": false, + "group": "Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "export_drc_multi", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export All Objects as DRCs" + }, + { + "completion": "none", + "description": "Export the sliced toolpaths as an OBJ.", + "destructive": false, + "group": "Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "export_toolpaths_obj", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export Toolpaths as OBJ" + }, + { + "completion": "none", + "description": "Export presets as a bundle or ZIP archives. Opens a dialog: click the label of the kind to export, check the presets (their checkboxes are named after them), press OK, then answer the result message. With a directory, OK writes there instead of asking for a folder.", + "destructive": false, + "group": "Export", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of an existing directory to write into.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_config", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export Preset Bundle" + }, + { + "completion": "none", + "description": "Show the keyboard shortcuts dialog.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_keyboard_shortcuts", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Keyboard Shortcuts" + }, + { + "completion": "none", + "description": "Open the setup wizard.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_setup_wizard", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Setup Wizard" + }, + { + "completion": "none", + "description": "Open the configuration folder in the file manager.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_open_config_folder", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Show Configuration Folder" + }, + { + "completion": "none", + "description": "Migrate legacy user filament presets.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_migrate_filament_presets", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Migrate Filament Presets" + }, + { + "completion": "none", + "description": "Open the troubleshooting center.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_troubleshoot", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Troubleshoot Center" + }, + { + "completion": "none", + "description": "Open the network test dialog.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_network_test", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Open Network Test" + }, + { + "completion": "none", + "description": "Benchmark rendering of the current 3D scene.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_benchmark_3d_scene", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Benchmark 3D Scene" + }, + { + "completion": "none", + "description": "Show a tip of the day.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_tip_of_the_day", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Show Tip of the Day" + }, + { + "completion": "none", + "description": "Check for a newer OrcaSlicer.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_check_updates", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Check for Updates" + }, + { + "completion": "none", + "description": "Show the About dialog.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "help_about", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "About OrcaSlicer" + }, + { + "completion": "none", + "description": "Open the OrcaSlicer wiki in the browser.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "open_wiki", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Open Wiki" + }, + { + "completion": "none", + "description": "Open the OrcaSlicer YouTube channel in the browser.", + "destructive": false, + "group": "Help", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "open_youtube", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Open YouTube Channel" + }, + { + "completion": "none", + "description": "Open the plugins dialog.", + "destructive": false, + "group": "Plugins", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "open_plugins", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Open Plugins" + }, + { + "completion": "none", + "description": "Reload plugins.", + "destructive": false, + "group": "Plugins", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "refresh_plugins", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Refresh Plugins" + }, + { + "completion": "none", + "description": "Open the plugin hub to install a plugin.", + "destructive": false, + "group": "Plugins", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "install_plugin", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Install Plugin" + }, + { + "completion": "none", + "description": "Install a plugin from a .py or .whl file, as the Plugins dialog's Install local plugin does. With a path, installs that file without a dialog. Replacing a plugin installed already asks first (answer with answer_dialog); the message names the plugin installed, or why it was not.", + "destructive": false, + "group": "Plugins", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "path": { + "description": "Absolute path of a .py or .whl plugin package.", + "type": "string" + } + }, + "type": "object" + }, + "key": "install_local_plugin", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Install Local Plugin" + }, + { + "completion": "none", + "description": "Snapshot of OrcaSlicer. Call it first and whenever you are unsure what the app is doing. The app: version, platform and display backend, whether it is ready, the main window, the displays (each one's work area x, y, width and height, as set_window takes positions, its scale and whether it is primary), the MCP endpoint (mcp), python (available: Python runs in this build; scripts_unrestricted: a script's own file, network, process and thread access is not held to OrcaSlicer's folders, which only a person turns on, in Preferences > AI features > Python scripts), design_tab (the Design tab is on, and call_tool runs its commands, search_tools' group Design) and, when they do not run, cad_note, how a person turns the CAD feature on. The project: current tab and mode, printer technology, name, path and unsaved changes, selected printer/process/filament presets, plates (count, current), object count, the selection (objects, the instances [[object, instance]] they are selected in and, when parts rather than whole instances are selected, parts [[object, part]], in the indices select_objects takes; wipe_tower when a prime tower is selected; canvas is the 3D view it belongs to), slicing state, the Preview's view type, time mode and layer range (1-based, with their Z), and the camera of the 3D view shown (camera: type, look_at, position, zoom, click_px_per_mm, elevation and azimuth, as set_view replies with it). What is going on: open modal dialogs, each with its title, buttons (enabled: false when disabled) and a message that reads it as shown: its text and its controls row by row, fields [value], choices [value ▾], checkboxes [x] / [ ] / [-], radio and selector options (*) / ( ), list rows \"- row | cells\", secrets [******], \" (disabled)\" after a disabled control; menus closed unseen (a menu a call opened that no reply listed), auto_answer_dialogs rules in force, notifications, print host uploads (state, progress, error), the open gizmo, running jobs and a running recording.", + "destructive": false, + "group": "core", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "get_app_state", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Get app state" + }, + { + "completion": "none", + "description": "Block until a condition holds or timeout_s passes (max 50). for: \"ready\" (startup finished), \"idle\" (no dialog, no running job, nothing slicing or arranging, no gizmo working in the background; a run_script run counts only through the calls it makes), \"dialog\" / \"no_dialog\", or \"job\" with a job id an earlier call returned, whose result is then the reply. On timeout the reply is {satisfied: false}: call it again.", + "destructive": false, + "group": "core", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "for": { + "description": "What to wait for; default job when job is given, else idle.", + "enum": [ + "ready", + "idle", + "dialog", + "no_dialog", + "job" + ], + "type": "string" + }, + "job": { + "description": "Job id, for \"job\".", + "type": "string" + }, + "timeout_s": { + "description": "Default 30.", + "maximum": 50, + "minimum": 0, + "type": "number" + } + }, + "type": "object" + }, + "key": "wait", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Wait for a condition" + }, + { + "completion": "none", + "description": "The last lines of OrcaSlicer's current log file, optionally only those at or above a level.", + "destructive": false, + "group": "core", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "level": { + "description": "Minimum level.", + "enum": [ + "trace", + "debug", + "info", + "warning", + "error", + "fatal" + ], + "type": "string" + }, + "lines": { + "description": "Default 200.", + "maximum": 2000, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "key": "get_log", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Read the log" + }, + { + "completion": "none", + "description": "Find what does something, in one search, or look up one command. With query: the commands that match, best first, each with its group, the first sentence of its description and listed, whether the tool list shows it; one that is not listed (a Speed Dial command, a Design tab command, or an operation a plugin offers, plugin.<plugin>.<name>) comes with its input schema, and its description when that says more, which nothing else shows. Beside them, the best few matches of each other catalog, with its total and how to use it: actions (the Speed Dial's plates, recent projects and plugin scripts and pages, for run_action), settings (get_settings / set_settings) and python (the orca API for run_script). With tool: that command's description and input schema, and its examples when it has some (the Design commands do). With neither: every command's name. group keeps the names and the command matches to one group; the other catalogs' matches stay as they are. call_tool runs any command, listed or not.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "group": { + "description": "Only the commands of this group, in any case: core (the session, dialogs and Python), api (project data by index and name; plugin operations too), ui (the GUI itself), Design (the Design tab's, with the CAD feature on), or a Speed Dial section such as Commands, Object or View. A group no command has is refused with the groups there are.", + "type": "string" + }, + "limit": { + "description": "At most this many commands (default 5).", + "maximum": 200, + "minimum": 1, + "type": "integer" + }, + "query": { + "description": "A few words saying what you want to do or find, e.g. \"brim\" or \"mesh normals\".", + "type": "string" + }, + "tool": { + "description": "A command's name: its description and schema.", + "type": "string" + } + }, + "type": "object" + }, + "key": "search_tools", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Find tools, actions, settings and APIs" + }, + { + "completion": "none", + "description": "Call any command by name with its arguments: a tool, or one the tool list does not show, a Speed Dial command, a Design tab command or an operation a plugin offers (see search_tools). It runs and is recorded as that command's own call, with its guards and reply budget.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "args": { + "description": "Its arguments.", + "type": "object" + }, + "tool": { + "description": "The command to call.", + "type": "string" + } + }, + "required": [ + "tool" + ], + "type": "object" + }, + "key": "call_tool", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Call a tool or plugin operation" + }, + { + "completion": "none", + "description": "Open model files (STL, 3MF, STEP, OBJ, AMF, SVG...), a project (.3mf) or G-code by absolute path, without a file dialog. Models are added to the current project. A .3mf opens as a project, replacing the current one, unless as is \"geometry\"; when the current project has unsaved changes that fails, changing nothing, unless discard_changes. Importing can open a dialog (STEP mesh options, for instance); the reply is then blocked_by_dialog.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "as": { + "description": "How to open .3mf files. Default auto (= project).", + "enum": [ + "auto", + "geometry", + "project" + ], + "type": "string" + }, + "discard_changes": { + "description": "Drop the project's unsaved changes rather than fail when a .3mf replaces it.", + "type": "boolean" + }, + "paths": { + "description": "Absolute paths.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "paths" + ], + "type": "object" + }, + "key": "open_files", + "listed": true, + "open_world": false, + "operations": [ + "open_project", + "import_models" + ], + "read_only": false, + "title": "Open files" + }, + { + "completion": "none", + "description": "Start a new, empty project. Called with no arguments, it asks as New Project does, about the unsaved changes if there are any: the reply is then blocked_by_dialog, and answer_dialog answers it. With arguments, or silent: true, it asks nothing: it fails, changing nothing, when the current project has unsaved changes, unless discard_changes. The presets' unsaved changes carry over to the new project unless preset_changes is \"discard\", as New Project's prompt offers. Reply: objects, names, plates; when presets had or have unsaved changes, discarded and modified list per preset the keys dropped and the keys still unsaved.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "discard_changes": { + "description": "Drop the project's unsaved changes rather than fail; for the presets', see preset_changes.", + "type": "boolean" + }, + "preset_changes": { + "description": "The presets' unsaved changes, not the project's: keep them for the new project (default) or drop them.", + "enum": [ + "keep", + "discard" + ], + "type": "string" + }, + "silent": { + "description": "true runs the command without asking, with the defaults of what the call leaves out. A call with no arguments does what a person's pick does.", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "new_project", + "listed": true, + "open_world": false, + "operations": [ + "new_project" + ], + "read_only": false, + "title": "New Project" + }, + { + "completion": "none", + "description": "Generate a Calibration menu test as its dialog's OK does: a new project named after the test with the test model, and the process, filament and printer presets changed as the test needs (presets_changed). The test prints with filament slot 1, so the filament tab is pointed at slot 1's preset. Omitted parameters take the dialog's defaults (pressure advance's by the printer's extruder type); temperatures are clamped to 155-500 °C and rounded down to 5 °C. Fails, changing nothing, when the project has unsaved changes (pass discard_changes) or presets do (pass preset_changes). Reply: test, project, params (the values used, which the journal records), objects, names, plates, presets_changed, result_keys (where the measured value belongs), warnings, adjusted (vfa), and discarded and modified as new_project. Then slice and export. To save a measured value: new_project {discard_changes, preset_changes: \"discard\"}, set_settings the value, save_preset.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "accelerations": { + "description": "pressure_advance pattern: one test per acceleration and speed; default the process's.", + "items": { + "minimum": 1, + "type": "integer" + }, + "type": "array" + }, + "auto_adjust": { + "description": "vfa: lower the layer height, else the end speed, to stay within the filament's maximum volumetric speed (default true).", + "type": "boolean" + }, + "auto_scale": { + "description": "temperature, vfa: scale the model to the nozzle (default true).", + "type": "boolean" + }, + "damping": { + "description": "input_shaping_freq: the damping ratio printed with.", + "type": "number" + }, + "discard_changes": { + "description": "Drop the project's unsaved changes rather than fail; for the presets', see preset_changes.", + "type": "boolean" + }, + "end": { + "description": "End of the swept value.", + "type": "number" + }, + "end_y": { + "description": "input_shaping_freq: end of the Y range; default the X one.", + "type": "number" + }, + "freq_x": { + "description": "input_shaping_damp: the X frequency, Hz.", + "type": "number" + }, + "freq_y": { + "description": "input_shaping_damp: the Y frequency, Hz; default freq_x.", + "type": "number" + }, + "method": { + "description": "pressure_advance: tower (default), line or pattern; flow_ratio: pass1, pass2, yolo (default) or yolo_perfectionist.", + "enum": [ + "tower", + "line", + "pattern", + "pass1", + "pass2", + "yolo", + "yolo_perfectionist" + ], + "type": "string" + }, + "preset_changes": { + "description": "The presets' unsaved changes, not the project's: keep them for the test or drop them first. Required when presets are modified.", + "enum": [ + "keep", + "discard" + ], + "type": "string" + }, + "print_numbers": { + "description": "pressure_advance line: print the values (default true).", + "type": "boolean" + }, + "shaper_type": { + "description": "Input shaping: an input_shaping_type the printer's firmware offers; default the first.", + "type": "string" + }, + "speeds": { + "description": "pressure_advance pattern: default an optimal speed.", + "items": { + "minimum": 1, + "type": "integer" + }, + "type": "array" + }, + "start": { + "description": "Start of the swept value: °C, mm³/s, PA, mm, mm/s (vfa), Hz (input_shaping_freq), damping (input_shaping_damp), junction deviation mm or jerk mm/s (cornering).", + "type": "number" + }, + "start_y": { + "description": "input_shaping_freq: start of the Y range; default the X one.", + "type": "number" + }, + "step": { + "description": "Step: max_volumetric, pressure_advance, retraction, vfa.", + "type": "number" + }, + "test": { + "description": "The test, named as the calib_* actions.", + "enum": [ + "temperature", + "max_volumetric", + "pressure_advance", + "flow_ratio", + "retraction", + "vfa", + "cornering", + "input_shaping_freq", + "input_shaping_damp" + ], + "type": "string" + }, + "test_model": { + "description": "Input shaping: ringing_tower (default) or fast_tower; cornering: also scv_v2; temperature on belt printers: standard (default) or overhang.", + "enum": [ + "ringing_tower", + "fast_tower", + "scv_v2", + "standard", + "overhang" + ], + "type": "string" + }, + "top_surface_pattern": { + "description": "flow_ratio (default archimedeanchords).", + "enum": [ + "archimedeanchords", + "monotonic" + ], + "type": "string" + } + }, + "required": [ + "test" + ], + "type": "object" + }, + "key": "generate_calibration_test", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Generate a calibration test" + }, + { + "completion": "none", + "description": "Save the project. Called with no arguments, it saves as Save Project does: to the project's file, or, when it has none, through a file dialog (blocked_by_dialog; a native picker needs auto_answer_dialogs registered first). With path, it saves a .3mf there without a dialog, and the file becomes the project's.", + "destructive": false, + "group": "Commands", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "if": { + "minProperties": 1 + }, + "properties": { + "overwrite": { + "description": "Replace an existing file.", + "type": "boolean" + }, + "path": { + "description": "Absolute .3mf path.", + "type": "string" + }, + "silent": { + "description": "true runs the command without asking, with the defaults of what the call leaves out. A call with no arguments does what a person's pick does.", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "path" + ] + }, + "type": "object" + }, + "key": "save_project", + "listed": true, + "open_world": false, + "operations": [ + "save_project_as" + ], + "read_only": false, + "title": "Save Project" + }, + { + "completion": "none", + "description": "Write the project to a file without a dialog. gcode: the plate's G-code (slice first; it is written in the background, and the call returns once it is). sliced_3mf: the sliced plate, or all plates, as .gcode.3mf. 3mf: the model without slicing data. stl: all objects as one STL. Without format, the path's extension (.gcode, .gcode.3mf, .3mf, .stl) says which.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "format": { + "description": "What to write; default from the path's extension.", + "enum": [ + "gcode", + "sliced_3mf", + "3mf", + "stl" + ], + "type": "string" + }, + "overwrite": { + "description": "Replace an existing file.", + "type": "boolean" + }, + "path": { + "description": "Absolute output path.", + "type": "string" + }, + "plates": { + "description": "\"current\" (default), a plate index, which is selected first, or \"all\" (sliced_3mf only).", + "type": [ + "string", + "integer" + ] + } + }, + "required": [ + "path" + ], + "type": "object" + }, + "key": "export", + "listed": true, + "open_world": false, + "operations": [ + "start_gcode_export", + "export_sliced_3mf", + "export_model_3mf", + "export_stl" + ], + "read_only": false, + "title": "Export" + }, + { + "completion": "none", + "description": "Printer, process or filament presets with flags: system or user, selected (and modified), compatible with the selected printer, and for filaments the slots using them. Only compatible, visible presets unless asked: a fresh install hides most system filaments and printers (visible: false), and select_preset takes those too.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "include_hidden": { + "description": "Also list hidden presets.", + "type": "boolean" + }, + "include_incompatible": { + "description": "Also list presets incompatible with the printer.", + "type": "boolean" + }, + "limit": { + "description": "Default 100.", + "maximum": 500, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "query": { + "description": "Case-insensitive part of the name.", + "type": "string" + }, + "type": { + "description": "Preset category.", + "enum": [ + "printer", + "process", + "filament" + ], + "type": "string" + } + }, + "required": [ + "type" + ], + "type": "object" + }, + "key": "list_presets", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "List presets" + }, + { + "completion": "none", + "description": "Select a printer, process or filament preset by the name its selector shows (or its internal name), as a person would. A hidden one (list_presets include_hidden) is shown in the selectors first, until the app restarts. With unsaved changes the Transfer-or-discard prompt opens (blocked_by_dialog) unless preset_changes answers it. A filament is assigned to filament_slot (1-based, default 1). Reply: selected, shown (a hidden preset it showed); when presets had or have unsaved changes, discarded and modified list per preset the keys dropped and the keys still unsaved.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "filament_slot": { + "description": "Filament slot, 1-based.", + "minimum": 1, + "type": "integer" + }, + "name": { + "description": "Preset name as list_presets shows it.", + "type": "string" + }, + "preset_changes": { + "description": "Unsaved changes of the presets the switch replaces: move them to the new preset or drop them, as the prompt's buttons do. Omitted: the prompt opens.", + "enum": [ + "transfer", + "discard" + ], + "type": "string" + }, + "type": { + "description": "Preset category.", + "enum": [ + "printer", + "process", + "filament" + ], + "type": "string" + } + }, + "required": [ + "type", + "name" + ], + "type": "object" + }, + "key": "select_preset", + "listed": true, + "open_world": false, + "operations": [ + "resolve_preset", + "select_preset", + "assign_filament_preset" + ], + "read_only": false, + "title": "Select a preset" + }, + { + "completion": "none", + "description": "Save the printer, process or filament preset being edited, with its unsaved changes, as a preset called name, which is then selected: what the tab's Save button does through its dialog. A filament is filament_slot's (default 1), and every slot using the old preset takes the new one. Replacing another existing preset needs overwrite (pass it in replays and scripts meant to be rerun). Reply: saved, user, project, inherits, filament_slots. A temperature warning or an unsaved-changes prompt makes it blocked_by_dialog. To keep only some edits, set_settings {reset_all: true, values} first.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "detach": { + "description": "Copy inherited values and drop the parent (Developer mode).", + "type": "boolean" + }, + "filament_slot": { + "description": "Filament slot, 1-based.", + "minimum": 1, + "type": "integer" + }, + "inside_project": { + "description": "Keep it inside the project, not as a user preset. Default: where the edited preset is.", + "type": "boolean" + }, + "name": { + "description": "Name to save under.", + "type": "string" + }, + "overwrite": { + "description": "Replace another preset of that name.", + "type": "boolean" + }, + "type": { + "description": "Preset category.", + "enum": [ + "printer", + "process", + "filament" + ], + "type": "string" + } + }, + "required": [ + "type", + "name" + ], + "type": "object" + }, + "key": "save_preset", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Save a preset" + }, + { + "completion": "none", + "description": "Delete a user preset or one inside the project, its file and its cloud copy, as the tab's Delete does, without asking. A selected preset is replaced as the tab does (its parent or the next preset). Another filament is deleted without changing the selection, and slots using it take the selected one; another process is selected, deleted and the selection restored; a printer must be selected first. Refused: system presets, presets others inherit from, another preset while the edited one of its type has unsaved changes. Deleting a selected printer or process can ask about other presets' unsaved changes (blocked_by_dialog). Reply: deleted, selected, filaments (per slot), attached, and discarded/modified as select_preset's.", + "destructive": true, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "delete_attached": { + "description": "A custom printer: also delete the process and filament presets made for it alone, which the GUI deletes with it.", + "type": "boolean" + }, + "name": { + "description": "Preset name as list_presets shows it.", + "type": "string" + }, + "type": { + "description": "Preset category.", + "enum": [ + "printer", + "process", + "filament" + ], + "type": "string" + } + }, + "required": [ + "type", + "name" + ], + "type": "object" + }, + "key": "delete_preset", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Delete a preset" + }, + { + "completion": "none", + "description": "Read settings: each item has its value, as OrcaSlicer writes it, and meta: label, description (what the setting does, when to change it), where (its settings page and group), type, unit, range, allowed values and mode. Choose them by keys; by query, a few words matched in keys, labels and descriptions, best matches first; by where, a page or group (an unknown one lists them all); or by none of these, for the whole scope, paged and, in a preset scope, without meta. Keys the scope lacks are listed in unknown_keys, and scope_of gives the scope of those another scope has.\n- No scope: keys and query look through the process, filament and printer settings, and each item names its scope, the one set_settings takes; anything else reads the process.\n- process, filament, printer: the preset being edited, or with preset a saved one; compare lists only the keys that differ from another preset (value and other). A per-variant value lists in meta its variants (what each entry is for) and active (the entry each extruder prints with).\n- object, part: the overrides that object or part carries, each with effective (the value it prints with) and source (part, object, process or default); an object's item lists in parts the parts and modifiers that override the key inside their own volume.\n- project: the plate type, slot colours, flushing volumes, purge mode, prime tower position per plate, mixed slots and, with several extruders, the filament grouping; meta.offered lists the choices this printer has.\n- plate: a plate's curr_bed_type, print_sequence, spiral_mode, first_layer_print_sequence, other_layers_print_sequence, name and locked, each with value (the plate's own, null where it follows the global setting or Auto) and effective.\n- preferences: the named keys of the app configuration (the Preferences dialog's settings, keys as its controls are named), as stored; it lists none unasked.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "compare": { + "description": "Preset scopes: a preset name, \":saved\" (the unsaved changes) or \":parent\" (the preset it inherits from).", + "type": "string" + }, + "filament_slot": { + "description": "Filament slot, 1-based.", + "minimum": 1, + "type": "integer" + }, + "include_meta": { + "description": "Include labels, types and ranges. Default true, false for a preset scope's whole listing and with compare.", + "type": "boolean" + }, + "keys": { + "description": "Option keys, e.g. [\"layer_height\", \"wall_loops\"].", + "items": { + "type": "string" + }, + "type": "array" + }, + "limit": { + "description": "Default 100, or 20 with query.", + "maximum": 500, + "minimum": 1, + "type": "integer" + }, + "object": { + "description": "Object index (object/part scope).", + "minimum": 0, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "part": { + "description": "Part index (part scope).", + "minimum": 0, + "type": "integer" + }, + "plate": { + "description": "Plate index (plate scope; default: the current plate).", + "minimum": 0, + "type": "integer" + }, + "preset": { + "description": "Preset scopes: read this saved preset (a name from list_presets) instead of the one being edited.", + "type": "string" + }, + "query": { + "description": "A few distinctive words, e.g. \"stringing\" or \"ooze travel\"; the best 20 matches unless limit says otherwise.", + "type": "string" + }, + "scope": { + "description": "Which settings: the process, filament or printer preset being edited, an object's / part's own overrides, the project's own settings, a plate's, or the app's preferences (read only). Without it, keys and query look through the process, filament and printer settings; anything else reads the process.", + "enum": [ + "process", + "filament", + "printer", + "object", + "part", + "project", + "plate", + "preferences" + ], + "type": "string" + }, + "where": { + "description": "A settings page, or \"Page > Group\" as meta.where gives it, e.g. \"Strength > Walls\".", + "type": "string" + } + }, + "type": "object" + }, + "key": "get_settings", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Read settings" + }, + { + "completion": "none", + "description": "Change settings of one scope (default the process) as typing them into its settings tab would. Values are strings in OrcaSlicer's format (\"15%\", \"0.2\", \"1,2\") or JSON numbers, booleans and arrays (a point as [x, y]). All are parsed strictly first and applied together, so nothing changes if one is invalid, and a key of another scope is refused with that scope named. Reply: applied, and changed, every setting the call changed, including those the app adjusted in turn. One undo step. Spiral vase and a few others confirm their adjustments in a dialog (blocked_by_dialog).\n- process, filament, printer: null takes a key back to its saved value, or with reset_to parent to the parent's; reset_all first discards every unsaved change, as the tab's undo button does (reply: reverted). A per-variant value (get_settings meta.variants) takes one value for the entries in use (meta.active), {index, value} for one entry, or an array of all.\n- object, part: overrides of the keys the object list offers there; null removes one. extruder is the object's or part's filament (1-based; 0 or null for Default), set as the Change Filament menu does.\n- project, as the sidebar's controls write them: curr_bed_type, filament_colour (#RRGGBB per slot), flush_multiplier, flush_volumes_matrix, prime_volume_mode, and wipe_tower_x/y (mm from the plate's origin, one per plate). flush_volumes_matrix is per nozzle, slots x slots from row to column, in config order over every slot, before the multiplier; mixed slots' entries are left as they are, and a colour change can recalculate it, so set it last.\n- plate, which it selects and writes as the Plate Settings dialog's OK does: curr_bed_type, print_sequence (\"by layer\", \"by object\"), spiral_mode (true asks for confirmation), first_layer_print_sequence (every slot once, e.g. [2, 1]), other_layers_print_sequence ([{from: layer >= 2, to, order}], to omitted for the last layer), name and locked; null returns a value to the global setting or Auto.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "filament_slot": { + "description": "Filament slot, 1-based.", + "minimum": 1, + "type": "integer" + }, + "object": { + "description": "Object index (object/part scope).", + "minimum": 0, + "type": "integer" + }, + "object_id": { + "description": "The id list_objects reports for this object: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "part": { + "description": "Part index (part scope).", + "minimum": 0, + "type": "integer" + }, + "part_id": { + "description": "The id list_objects reports for this part: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "plate": { + "description": "Plate index (plate scope; default: the current plate).", + "minimum": 0, + "type": "integer" + }, + "reset_all": { + "description": "Preset scopes: discard the unsaved changes before applying values.", + "type": "boolean" + }, + "reset_to": { + "description": "Preset scopes: what a null value takes a key back to: the saved preset (default) or the preset it inherits from.", + "enum": [ + "saved", + "parent" + ], + "type": "string" + }, + "scope": { + "description": "Which settings: the process, filament or printer preset being edited, an object's / part's own overrides, the project's own settings, a plate's, or the app's preferences (read only). Default: the process.", + "enum": [ + "process", + "filament", + "printer", + "object", + "part", + "project", + "plate", + "preferences" + ], + "type": "string" + }, + "values": { + "description": "{key: value}, or {key: {index, value}} for one entry", + "type": "object" + } + }, + "type": "object" + }, + "key": "set_settings", + "listed": true, + "open_world": false, + "operations": [ + "set_plate_locked" + ], + "read_only": false, + "title": "Change settings" + }, + { + "completion": "none", + "description": "Plates with name, locked, current, objects (how many are on it; list_objects lists them), and the settings they print with: curr_bed_type, print_sequence, spiral_mode, first_layer_print_sequence and other_layers_print_sequence (null: Auto); overrides lists those the plate sets itself (set_settings scope plate). Also sliced (an up-to-date slice), wipe_tower [x, y] and layer_gcode: the plate's pauses, custom G-code, templates and filament changes, each {z, layer, type, filament, color, gcode}; layer is the Preview slider's number, given while the plate's slice is up to date.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "limit": { + "description": "Default 100.", + "maximum": 500, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "list_plates", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "List plates" + }, + { + "completion": "none", + "description": "The project as the Objects panel lists it. plates: each {index, name, objects}, with the objects that have an instance on it; outside: the objects with an instance on no plate. An object with instances on two plates is listed under both, each time with that plate's instances. An object has its filament, auto_drop, bounding box (instance 0), brim ear count and the settings it overrides; its instances (offset, rotation in degrees, scale, mirrored, bbox); its parts, one or more: parts, negative parts, modifiers, support blockers and enforcers and precise seams (type, with subtype for a precise seam; filament: a part's own or its object's, a modifier's only when it sets one; position, bbox and scaled_volume in mm3 on the bed, measured on instance 0; rotation_deg and scale in the object's frame; mirrored; triangle count; mesh_volume, the unscaled mesh's mm3; painted facets: supports and seam enforcers/blockers, fuzzy_skin, mmu per filament, texture per layer; a text part's text and font, an SVG part's file); its height range modifiers when it has any (layer_config_ranges: [{min_z, max_z, values}], as set_height_ranges takes them) and its variable layer height profile when it has one (layer_height_profile: {points, min_height, max_height}). A bbox is {min, max, size} in mm of model parts only, so unlike the panel's Size it leaves out modifiers. An object's index numbers it in the project and a part's in its object, whatever the plate: they are what select_objects, transform, mouse_gesture targets and the object/part settings scopes take. Each object and part also has an id, which stays with it when a delete, split or assemble shifts the indices: pass it as object_id / part_id to transform, add_part, set_settings, set_height_ranges and set_variable_layer_height (object_ids, part_ids and instance_object_ids to select_objects), and a call whose index names another one now is refused instead of acting on it. limit and offset page the objects and total counts them, each once.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "limit": { + "description": "Objects, default 200.", + "maximum": 500, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "plate": { + "description": "List this plate alone, without outside.", + "minimum": 0, + "type": "integer" + }, + "screen": { + "description": "Add each instance's rectangle in the shown 3D view, logical pixels [x, y, w, h].", + "type": "boolean" + } + }, + "type": "object" + }, + "key": "list_objects", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "List objects" + }, + { + "completion": "none", + "description": "Select objects, instances or parts in the 3D view (the assemble view while it is shown, else Prepare, switching to it), as clicking them would. Give objects, instances ([[object, instance], ...]) or parts ([[object, part], ...]); add keeps the current selection; all / none select everything or nothing. The reply is the selection as get_app_state.selection gives it.", + "destructive": false, + "group": "ui", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "add": { + "description": "Add to the selection instead of replacing it.", + "type": "boolean" + }, + "all": { + "description": "Select all objects.", + "type": "boolean" + }, + "instance_object_ids": { + "description": "The ids list_objects reports for the objects of instances, one per entry: refused when a pair names another object now.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "instances": { + "description": "[[object, instance], ...]", + "items": { + "type": "array" + }, + "type": "array" + }, + "none": { + "description": "Clear the selection.", + "type": "boolean" + }, + "object_ids": { + "description": "The ids list_objects reports for objects, one per entry: refused when an index names another object now.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "objects": { + "description": "Object indices.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "part_ids": { + "description": "The ids list_objects reports for the entries of parts, one per entry: refused when a pair names another part now.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "parts": { + "description": "[[object, part], ...]", + "items": { + "type": "array" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "select_objects", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Select objects" + }, + { + "completion": "none", + "description": "Change one instance's placement, or one part's with part. translate is in mm, position where it goes (mm, as the Move panel shows it, whatever mode says), rotate in degrees about X/Y/Z, scale a factor (one number or [x, y, z]), size [x, y, z] mm along the object's or part's own axes, plate moves the instance onto that plate at the same place. mode \"relative\" (default) adds to the current placement, \"absolute\" sets it. An instance is dropped back onto the bed unless drop_to_bed is false. A part moves as the Object manipulation panel moves it: translate and rotate along the bed's axes, measured on instance 0, scale and size along its own axes; every instance shows the change, and Auto Drop may lower the object afterwards. One undo step. Reply: the instance's offset, scale and plate, or the part's size along its own axes and its list_objects entry (part_info).", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "drop_to_bed": { + "description": "Default true; instances only.", + "type": "boolean" + }, + "instance": { + "description": "Default 0.", + "minimum": 0, + "type": "integer" + }, + "mode": { + "description": "Default relative.", + "enum": [ + "relative", + "absolute" + ], + "type": "string" + }, + "object": { + "description": "Object index (list_objects).", + "minimum": 0, + "type": "integer" + }, + "object_id": { + "description": "The id list_objects reports for this object: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "part": { + "description": "Transform this part instead of the instance.", + "minimum": 0, + "type": "integer" + }, + "part_id": { + "description": "The id list_objects reports for this part: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "plate": { + "description": "Move the instance to this plate.", + "minimum": 0, + "type": "integer" + }, + "position": { + "description": "[x, y, z] mm: the position to move to. Not with translate.", + "items": { + "type": "number" + }, + "type": "array" + }, + "rotate": { + "description": "[x, y, z] degrees; relative only for a part", + "items": { + "type": "number" + }, + "type": "array" + }, + "scale": { + "description": "Factor or [x, y, z] factors.", + "type": [ + "number", + "array" + ] + }, + "size": { + "description": "[x, y, z] mm, null keeps an axis; one number and two nulls keep the proportions. Not with scale.", + "items": { + "type": [ + "number", + "null" + ] + }, + "type": "array" + }, + "translate": { + "description": "[x, y, z] mm", + "items": { + "type": "number" + }, + "type": "array" + } + }, + "required": [ + "object" + ], + "type": "object" + }, + "key": "transform", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Move, rotate or scale an instance or a part" + }, + { + "completion": "none", + "description": "Add a part, negative part, modifier, support blocker or enforcer, or precise seam to an object, as its context menu's Add items do: a primitive shape at a size, or a model file as Load... adds it. The part lands where the menu puts it (a shape beside the object, a file at its coordinates relative to the object's first part) unless position is given. Like the menu, adding a shape folds the instance's rotation and scale into the object's parts (the instance's scale then reads 1). Refused for an object with several instances: add parts first. A STEP file may ask for mesh options (blocked_by_dialog). The new part is selected; one undo step. Reply: its index, which is not always the last (parts are ordered by type), the object's part count and the part's list_objects entry (part_info).", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "object": { + "description": "Object index (list_objects).", + "minimum": 0, + "type": "integer" + }, + "object_id": { + "description": "The id list_objects reports for this object: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "path": { + "description": "Instead of shape: absolute path of a model file (STL, OBJ, 3MF, STEP, ...).", + "type": "string" + }, + "position": { + "description": "[x, y, z] mm on the bed for the part's centre, on instance 0, as the Move panel shows it.", + "items": { + "type": "number" + }, + "type": "array" + }, + "shape": { + "description": "A primitive shape.", + "enum": [ + "cube", + "cylinder", + "sphere", + "cone", + "disc", + "torus" + ], + "type": "string" + }, + "size": { + "description": "mm, the Primitive size dialog's fields: cube [x, y, z]; cylinder, cone, disc [diameter, height]; sphere [diameter]; torus [inner diameter, tube diameter]. Default: the built-in size.", + "items": { + "type": "number" + }, + "type": "array" + }, + "type": { + "description": "What the new part is.", + "enum": [ + "part", + "negative", + "modifier", + "support_blocker", + "support_enforcer", + "precise_seam" + ], + "type": "string" + } + }, + "required": [ + "object", + "type" + ], + "type": "object" + }, + "key": "add_part", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Add a part or modifier to an object" + }, + { + "completion": "none", + "description": "Arrange the objects of every unlocked plate as the toolbar's Arrange does, or of one plate (plates: an index or \"current\") as its Arrange icon does. With fill, fill that object's plate with more of it instead, as Fill bed with instances (or copies, by fill_with) does. spacing, rotate, align_y and multi_material are the Arrange options panel's settings: the values given stay in the panel, so later arranges use them too. Waits for the arrangement (a longer one replies with a job). Reply: the settings in force, instances left off every plate, plates the all-plates arrange skipped and the job's notifications. An arrange may reorder objects, so list_objects again. One undo step.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "align_y": { + "description": "Align to Y axis (off while rotate is on).", + "type": "boolean" + }, + "fill": { + "description": "Instead of arranging, fill this object's plate with more of it.", + "minimum": 0, + "type": "integer" + }, + "fill_with": { + "description": "Default instances.", + "enum": [ + "instances", + "copies" + ], + "type": "string" + }, + "multi_material": { + "description": "Allow multiple materials on same plate.", + "type": "boolean" + }, + "plates": { + "description": "\"all\" (default), \"current\" or a plate index.", + "type": [ + "string", + "integer" + ] + }, + "rotate": { + "description": "Auto rotate for arrangement.", + "type": "boolean" + }, + "spacing": { + "description": "mm between objects; 0 means auto.", + "minimum": 0, + "type": "number" + }, + "timeout_s": { + "description": "Cancel it after this long (default 300).", + "maximum": 1800, + "minimum": 10, + "type": "integer" + } + }, + "type": "object" + }, + "key": "arrange", + "listed": true, + "open_world": false, + "operations": [ + "start_arrange" + ], + "read_only": false, + "title": "Arrange objects or fill the bed" + }, + { + "completion": "none", + "description": "Slice the current plate, all plates, or one plate by index, the way the toolbar's Slice button does, and wait for the result (or reply with a job id when it takes longer than the reply budget). Each requested plate reports ok, error, cancelled, empty or skipped; the whole operation is superseded when someone else started a slice or edited the project while it ran. An ok plate has time_s (silent_time_s when the printer estimates it), filament_m and filament_g including flush, filament_cost, layers, max_z, filament_changes, and filaments[i] for slot i+1 with m, g and the grams of model_g, support_g, flush_g and tower_g. Other changes are refused until it finishes; cancel_job stops it.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "plates": { + "description": "\"current\" (default), \"all\", or a plate index.", + "type": [ + "string", + "integer" + ] + }, + "timeout_s": { + "description": "Give up after this long (default 1800).", + "maximum": 7200, + "minimum": 10, + "type": "integer" + } + }, + "type": "object" + }, + "key": "slice", + "listed": true, + "open_world": false, + "operations": [ + "start_slice" + ], + "read_only": false, + "title": "Slice" + }, + { + "completion": "none", + "description": "Stop the running operation: a slice or G-code export, as the slicing progress's cancel button does, or a background job an MCP call started (an arrange, orient or fill bed). Its job then reports cancelled; a background job keeps other changes out until it has really stopped. With job, only that job is stopped: the running operation, a run_script run or an encode_recording. Allowed while an operation holds the project.", + "destructive": false, + "group": "core", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "job": { + "description": "The operation's job to cancel, e.g. \"j12\".", + "type": "string" + } + }, + "type": "object" + }, + "key": "cancel_job", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cancel a job" + }, + { + "completion": "none", + "description": "Replace an object's height range modifiers (Height Range Modifier in the object list): Z ranges in mm, each printed with its own layer_height, filament and process settings, starting from the object's layer height and filament. Ranges may touch but not overlap; [] removes them all. One undo step; the object is selected. Reply: the object's height and its ranges as list_objects shows them, and warnings, such as a variable layer height profile deciding the layer heights instead.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "object": { + "description": "Object index (list_objects).", + "minimum": 0, + "type": "integer" + }, + "object_id": { + "description": "The id list_objects reports for this object: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "ranges": { + "description": "The object's ranges afterwards, in any order.", + "items": { + "additionalProperties": false, + "properties": { + "max_z": { + "description": "Top, mm above the bed.", + "minimum": 0, + "type": "number" + }, + "min_z": { + "description": "Bottom, mm above the bed.", + "minimum": 0, + "type": "number" + }, + "values": { + "description": "{key: value} as set_settings takes them: layer_height, extruder (0 = the object's filament) and per-region process settings such as sparse_infill_density or wall_loops.", + "type": "object" + } + }, + "required": [ + "min_z", + "max_z" + ], + "type": "object" + }, + "type": "array" + } + }, + "required": [ + "object", + "ranges" + ], + "type": "object" + }, + "key": "set_height_ranges", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set height range modifiers" + }, + { + "completion": "none", + "description": "Run the Variable layer height panel's Adaptive, Smooth or Reset on an object, without opening the panel: adaptive computes layer heights from the object's shape (inside a height range, the range's layer_height), smooth smooths its profile (or the one its height ranges give), reset goes back to its layer height and ranges. One undo step; the object is selected. Reply: the object's height, its layer_height_profile {points, min_height, max_height} as list_objects shows it (absent after reset), and warnings.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "action": { + "description": "The panel's button.", + "enum": [ + "adaptive", + "smooth", + "reset" + ], + "type": "string" + }, + "keep_min": { + "description": "smooth: keep the minimum layer heights (default false).", + "type": "boolean" + }, + "object": { + "description": "Object index (list_objects).", + "minimum": 0, + "type": "integer" + }, + "object_id": { + "description": "The id list_objects reports for this object: the call is refused when the index names another one now.", + "minimum": 0, + "type": "integer" + }, + "quality": { + "description": "adaptive: 0 = quality .. 1 = speed (default 0.5, as the panel).", + "maximum": 1, + "minimum": 0, + "type": "number" + }, + "radius": { + "description": "smooth: default 5.", + "maximum": 10, + "minimum": 1, + "type": "integer" + } + }, + "required": [ + "object", + "action" + ], + "type": "object" + }, + "key": "set_variable_layer_height", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set a variable layer height profile" + }, + { + "completion": "none", + "description": "Add or remove pauses, custom G-code, custom templates and filament changes at the start of a layer, as the Preview layer slider's menu does; they are saved per plate in the project. They go on the plate's sliced layers, so the plate needs an up-to-date slice, or must be the one the Preview still shows after an earlier edit; the call selects it and shows the Preview. Applies clear, then remove, then add, all checked first. One code per layer: a custom code or filament change where there is one replaces it. Not undoable, as in the slider. A change invalidates the plate's slice: slice again before exporting. Reply: the plate's codes as list_plates' layer_gcode lists them, each with z and layer.", + "destructive": false, + "group": "api", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "add": { + "description": "Codes to add, each with layer or z.", + "items": { + "additionalProperties": false, + "properties": { + "filament": { + "description": "change_filament: printed from this layer up.", + "minimum": 1, + "type": "integer" + }, + "gcode": { + "description": "custom: the G-code.", + "type": "string" + }, + "layer": { + "description": "1-based, as the Preview's layer slider numbers layers.", + "minimum": 1, + "type": "integer" + }, + "type": { + "description": "template runs the printer's template_custom_gcode.", + "enum": [ + "pause", + "custom", + "template", + "change_filament" + ], + "type": "string" + }, + "z": { + "description": "mm: the layer whose top is at or above it.", + "minimum": 0, + "type": "number" + } + }, + "required": [ + "type" + ], + "type": "object" + }, + "type": "array" + }, + "clear": { + "description": "Remove every code on the plate first.", + "type": "boolean" + }, + "plate": { + "description": "Default: the current plate.", + "minimum": 0, + "type": "integer" + }, + "remove": { + "description": "Codes to remove, by layer or z.", + "items": { + "additionalProperties": false, + "properties": { + "layer": { + "description": "1-based, as the Preview's layer slider numbers layers.", + "minimum": 1, + "type": "integer" + }, + "z": { + "description": "mm: the layer whose top is at or above it.", + "minimum": 0, + "type": "number" + } + }, + "type": "object" + }, + "type": "array" + } + }, + "type": "object" + }, + "key": "set_custom_gcode_at_layer", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set custom G-code at a layer" + }, + { + "completion": "none", + "description": "Capture what OrcaSlicer shows and return it as an image, downscaled to max_dim on the long edge (default 1280), plus the full-size PNG written to save_path (or the session's output folder). target: \"main\" (the main window), \"canvas\" (the visible 3D view exactly as rendered: scene, toolpaths, toolbars, ImGui panels; on the Design tab its view), \"dialog\" (the topmost modal dialog), or a ref: a window's from list_windows (one that is not modal, say), or a widget's from list_widgets, cropped to that widget (a page element's ref captures its whole web view). The result says when parts may differ from the screen (approximate). Point the view first with set_view.", + "destructive": false, + "group": "ui", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "include_image": { + "description": "Return the image itself (default true); false returns only the path.", + "type": "boolean" + }, + "max_dim": { + "description": "Long edge of the returned image.", + "maximum": 2000, + "minimum": 256, + "type": "integer" + }, + "overwrite": { + "description": "Replace an existing save_path.", + "type": "boolean" + }, + "save_path": { + "description": "Absolute .png path for the full-size image.", + "type": "string" + }, + "target": { + "description": "main (default), canvas, dialog, or a widget's ref or locator from list_widgets.", + "type": [ + "string", + "object" + ] + } + }, + "type": "object" + }, + "key": "screenshot", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Take a screenshot" + }, + { + "completion": "none", + "description": "What the Preview shows for a sliced plate. summary: the slice reply's, plus prepare and travel time and travel distance. features: seconds, share of the print time and grams per feature type (the Line Type legend), and travel. layers: per layer (1-based, as set_view's layer) Z, height, seconds and grams, paged; layer_features adds each feature type's seconds. objects: grams per object instance, with its list_objects index when its name is unique. view, for the plate the Preview shows: view type, time mode, layer range, which legend rows are visible, and each view type's colour range for what the legend shows. Times are normal-mode estimates. A G-code file opened for viewing reads the same.", + "destructive": false, + "group": "api", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "include": { + "description": "Parts besides the summary; default [\"features\", \"view\"].", + "items": { + "enum": [ + "features", + "layers", + "layer_features", + "objects", + "view" + ], + "type": "string" + }, + "type": "array" + }, + "limit": { + "description": "Layers per page (default 100).", + "maximum": 1000, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "plate": { + "description": "Plate index; default the current plate.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "get_slice_stats", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Get slice statistics" + }, + { + "completion": "none", + "description": "Set up what the window shows, for screenshots and GUI work: the main tab, the 3D view (canvas: Prepare's, the preview or the assemble view, which has its own gizmos), the camera of the 3D view shown (a named direction, the default view, or fit to bed / objects / selection, then look_at, the point it looks at, an orbit to look from between the named directions, and the zoom), the preview's color scheme (picked as in the legend's combo, which shows every feature type again), legend rows, time estimate and layers (1-based, or up to a height). Only the given fields change. On the Design tab the camera points its view (default is its Home view; no fit_bed). The reply echoes them; preview layers as [first, last, count] with z, the heights of first and last; with any camera field, camera_state, the camera it leaves as get_app_state.camera gives it, and adjusted: [\"zoom\"] when the zoom was held to its limits.", + "destructive": false, + "group": "ui", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "camera": { + "description": "Camera direction or fit.", + "enum": [ + "iso", + "top", + "bottom", + "front", + "rear", + "left", + "right", + "default", + "fit_bed", + "fit_objects", + "fit_selection" + ], + "type": "string" + }, + "canvas": { + "description": "3D view: Prepare's, the preview, or the assemble view (needs an object; leave it with 3d, as its Return button does).", + "enum": [ + "3d", + "preview", + "assemble" + ], + "type": "string" + }, + "layer": { + "description": "Preview: show layers up to this one (1-based).", + "minimum": 1, + "type": "integer" + }, + "layer_range": { + "description": "Preview: [first, last] layers, 1-based.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "layer_z": { + "description": "Preview: show layers up to the first whose top is at or above this height (mm), as the slider places a custom G-code.", + "minimum": 0, + "type": "number" + }, + "legend": { + "additionalProperties": { + "type": "boolean" + }, + "description": "Preview: show (true) or hide (false) legend rows: feature types by name as get_slice_stats lists them (\"Sparse infill\"), and travel, wipe, retract, unretract, seams, filament_changes, color_changes, pauses, custom_gcode, in any case and with _ or a space between words. Hiding a row this print lacks does nothing. Applied after view_type.", + "type": "object" + }, + "look_at": { + "description": "[x, y, z] in mm: the point the camera looks at, in the 3D view's world coordinates, as list_objects gives positions; on the Design tab, the Design view's, which the Design commands' world points use (describe_scene's modeling_origin is the sketch planes' origin). The camera moves parallel, keeping its direction and distance. After camera.", + "items": { + "type": "number" + }, + "type": "array" + }, + "orbit": { + "description": "[yaw, pitch] in degrees: move the camera around what it looks at, yaw to its right and pitch up (negative looks from lower), after camera and look_at. The same on every install, unlike a mouse drag.", + "items": { + "type": "number" + }, + "type": "array" + }, + "tab": { + "description": "Main window tab.", + "enum": [ + "home", + "design", + "prepare", + "preview", + "device", + "multi_device", + "project", + "calibration" + ], + "type": "string" + }, + "time_mode": { + "description": "Preview: the time estimate the legend and layer times show; silent only when the print has its own.", + "enum": [ + "normal", + "silent" + ], + "type": "string" + }, + "view_type": { + "description": "Preview color scheme.", + "enum": [ + "summary", + "feature_type", + "color_print", + "speed", + "actual_speed", + "height", + "width", + "volumetric_flow_rate", + "actual_volumetric_flow_rate", + "layer_time_linear", + "layer_time_logarithmic", + "fan_speed", + "temperature", + "pressure_advance", + "acceleration", + "jerk" + ], + "type": "string" + }, + "zoom": { + "description": "Screenshot pixels per mm at look_at's depth, so everywhere in an orthographic view; held to the camera's limits (at most 250, at least what the scene's size allows). Applied last.", + "exclusiveMinimum": 0, + "type": "number" + } + }, + "type": "object" + }, + "key": "set_view", + "listed": true, + "open_world": false, + "operations": [ + "show_layer_range" + ], + "read_only": false, + "title": "Point the view" + }, + { + "completion": "none", + "description": "Replay a list of tool calls in order and report each step: {orca_replay:1, name, vars, steps:[{tool, args, expect, optional, await, save_as, timeout_s}]}, JSON with comments. Strings may use ${replay_dir}, ${out_dir}, ${env:NAME}, ${vars.NAME} and ${jobs.NAME}. A step that returns a job is awaited unless await:false, which stores the job under save_as so later steps can answer the dialog it opened. expect maps a JSON pointer into the step's result to matchers (eq ne gt ge lt le contains regex exists empty); the first failed step or expectation stops the run unless the step is optional. Writes result.json to out_dir (default: <replay name>.out next to a replay file). auto_answer_dialogs rules a replay registers end with it. export_replay turns this session into one.", + "destructive": false, + "group": "core", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "out_dir": { + "description": "Absolute directory for result.json and screenshots; created if missing.", + "type": "string" + }, + "path": { + "description": "Absolute path of a replay file.", + "type": "string" + }, + "replay": { + "description": "The replay itself, as an object or as its JSON text, instead of path.", + "type": [ + "object", + "string" + ] + }, + "vars": { + "description": "Values that override the replay's vars.", + "type": "object" + } + }, + "type": "object" + }, + "key": "run_replay", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Run a replay" + }, + { + "completion": "none", + "description": "Turn the calls this session made into a replay that run_replay runs: mutating calls, wait and screenshot, in order, with refs replaced by locators, job replies replayed with await:false, and screenshot paths moved under ${out_dir}. Calls that failed, at once or as a job later, are left out; so is a call whose job is still running (unless it waits on a dialog), which left_out_running lists as {tool, job}. Reply: the replay, which with path is also written there. clear:true starts a new recording afterwards.", + "destructive": false, + "group": "core", + "guard": "inspect", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "clear": { + "description": "Forget the calls recorded so far once exported.", + "type": "boolean" + }, + "name": { + "description": "Replay name.", + "type": "string" + }, + "overwrite": { + "description": "Replace an existing file.", + "type": "boolean" + }, + "path": { + "description": "Absolute .json path to write.", + "type": "string" + } + }, + "type": "object" + }, + "key": "export_replay", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export this session as a replay" + }, + { + "completion": "none", + "description": "Run Python code inside OrcaSlicer as its main program (__name__ == \"__main__\") against orca.host, the whole plugin API (search_python_api searches it): read objects, meshes and settings, compute, use orca.host.ui and the preset API, and call these same tools, with their guards and undo, through orca.host.tools.call(name, args), from the code and from the threads and pool tasks it starts while the run lasts. Mesh and matrix arrays need numpy, which search_python_api says is installed or not; a file run's PEP 723 block can install it. The code runs on a worker thread, where calls documented as UI thread only raise RuntimeError. The run ends once its code and the non-daemon threads and pool tasks it started are done; its windows close with it. `args` holds the args you pass; set `result` to a JSON value to return it; print() output comes back as output. Reply: {status: finished | raised | cancelled | timed_out, result, output, traceback?, message?}; a script that raised changed what it changed before. The code's own file access is held to OrcaSlicer's folders (its data and resources folders, and for a file run the file's folder, read only), and it starts no programs or threads and reaches no network: such an access raises PermissionError, unless a person has let Python scripts run unrestricted in Preferences (get_app_state.python.scripts_unrestricted); the tools it calls work as they do for you. Recorded by export_replay as one step with its code, which a replay runs again against the project as it is then.", + "destructive": false, + "group": "core", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "args": { + "description": "Bound to the name `args` in the code.", + "type": "object" + }, + "code": { + "description": "Python source, run as a module body.", + "type": "string" + }, + "filename": { + "description": "The name tracebacks show for the code (default <run_script>). An existing file's path makes it a file run, as `python file.py` runs it: __file__, sys.argv, imports from its folder and its PEP 723 dependencies; any other name only names it.", + "type": "string" + }, + "timeout_s": { + "description": "The run is stopped as timed_out after this many seconds (default 300).", + "maximum": 3600, + "minimum": 1, + "type": "integer" + } + }, + "required": [ + "code" + ], + "type": "object" + }, + "key": "run_script", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Run a Python script" + }, + { + "completion": "none", + "description": "Search orca, the Python API of run_script scripts and plugins, in the running build: orca.host (the project's model and meshes, presets and their editors, slicing data, orca.host.ui windows and dialogs, orca.host.tools calling these tools) and the classes, events and pages plugins build on. Each entry has its kind, signature (a class's constructors) and documentation. A query ranks them, best match first; without one, the whole package is listed with each entry's first sentence. Page with offset. numpy says whether numpy is installed, which mesh and matrix arrays need.", + "destructive": false, + "group": "core", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "limit": { + "description": "At most this many (default 20).", + "maximum": 200, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "query": { + "description": "A few words, such as \"mesh normals\" or \"preset value\".", + "type": "string" + } + }, + "type": "object" + }, + "key": "search_python_api", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Search the Python API" + }, + { + "completion": "none", + "description": "Record a video of OrcaSlicer until stop_recording: the main window with any modal dialog on it (target main), or the 3D view shown (canvas). Frames are MJPEG in a Matroska (.mkv) file with their real timestamps. With captions, the tool call acting on the app shows as a caption at the bottom (secret setting values never show); with pointer, the pointer is highlighted, its clicks rippling. Capture takes at most about a third of the UI thread, so the frame rate drops where capturing is slow. One recording at a time: one a replay or script starts ends with it, a client's when the server is turned off. With encode, the stop_recording that reports it also encodes it to an MP4 beside it, as the Start Recording command does; encode_recording makes an MP4 of any recording later. Called with no arguments, it opens the Start Recording dialog instead, as the Start Recording command does (blocked_by_dialog): its controls are named after their settings for set_widget_value, answer_dialog \"Start recording\" starts the person's recording, which neither the end of a replay or script nor the server turning off ends, and the dialog remembers the settings; silent: true starts one here at once with the defaults.", + "destructive": false, + "group": "Commands", + "guard": "inspect", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "captions": { + "description": "Caption the tool call acting on the app (default false).", + "type": "boolean" + }, + "codec": { + "description": "With encode: the codec (default the preset's).", + "enum": [ + "h265", + "h264" + ], + "type": "string" + }, + "crf": { + "description": "With encode: constant rate factor, lower is better and larger (default the preset's).", + "maximum": 51, + "minimum": 0, + "type": "integer" + }, + "encode": { + "description": "Encode it to an MP4 once stopped; needs an ffmpeg (default false).", + "type": "boolean" + }, + "encode_preset": { + "description": "With encode: the settings the fields below change (default balanced: h265, crf 28, medium, main).", + "enum": [ + "small", + "balanced", + "quality", + "compatible" + ], + "type": "string" + }, + "fps": { + "description": "Frames per second at most (default 10).", + "maximum": 30, + "minimum": 1, + "type": "integer" + }, + "max_dim": { + "description": "Long edge of the video in pixels (default 1920).", + "maximum": 3840, + "minimum": 320, + "type": "integer" + }, + "max_seconds": { + "description": "The recording ends on its own after this long (default 3600).", + "maximum": 3600, + "minimum": 1, + "type": "integer" + }, + "overwrite": { + "description": "Replace an existing save_path, and with encode its MP4.", + "type": "boolean" + }, + "pointer": { + "description": "Highlight the pointer and show its clicks (default false).", + "type": "boolean" + }, + "profile": { + "description": "With encode: h264 high, main or baseline; h265 main or main10 (default the preset's, else the codec's first).", + "enum": [ + "high", + "main", + "baseline", + "main10" + ], + "type": "string" + }, + "quality": { + "description": "JPEG quality of the frames (default 80).", + "maximum": 95, + "minimum": 30, + "type": "integer" + }, + "save_path": { + "description": "Absolute .mkv path; default the session's output folder.", + "type": "string" + }, + "silent": { + "description": "true runs the command without asking, with the defaults of what the call leaves out. A call with no arguments does what a person's pick does.", + "enum": [ + true + ], + "type": "boolean" + }, + "speed": { + "description": "With encode: slower makes a smaller file (default the preset's).", + "enum": [ + "ultrafast", + "superfast", + "veryfast", + "faster", + "fast", + "medium", + "slow", + "slower", + "veryslow" + ], + "type": "string" + }, + "target": { + "description": "main (default): the main window and its dialogs; canvas: the 3D view shown.", + "enum": [ + "main", + "canvas" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "start_recording", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Start Recording" + }, + { + "completion": "none", + "description": "Stop the running recording and return its file once it is written: seconds, frames captured and written, frames dropped when encoding fell behind, failed when they could not be encoded, or skipped when the window could not be captured, the size, the mean UI-thread time a capture took (capture_ms), and why it ended. A recording that ended on its own (max_seconds, the replay or script that started it ended, a write error) is reported once by the next stop_recording. For a recording started with encode, it then starts the MP4 encode and returns it under encode: a job, whose wait {for: \"job\"} returns encode_recording's result. This is the call with silent: true. Called with no arguments, it stops the recording as the Stop Recording command does, whoever started it: without waiting for its file, it shows the person a notification naming it and replies with its path; the next stop_recording with silent: true reports it as ended stopped_in_app.", + "destructive": false, + "group": "Commands", + "guard": "inspect", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": { + "silent": { + "description": "true runs the command without asking, with the defaults of what the call leaves out. A call with no arguments does what a person's pick does.", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "stop_recording", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Stop Recording" + }, + { + "completion": "none", + "description": "Encode a recording into an H.265 (or H.264) MP4 with the system ffmpeg (ORCA_FFMPEG, else ffmpeg on PATH; it needs libx265 or libx264), keeping its timing. Takes this session's last finished recording unless path names one, and writes beside it unless save_path says where. A long encode returns a job: wait for it, or cancel_job {job} stops it. delete_source removes the .mkv afterwards, only for a recording this session made.", + "destructive": false, + "group": "ui", + "guard": "inspect", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "codec": { + "description": "Default h265.", + "enum": [ + "h265", + "h264" + ], + "type": "string" + }, + "crf": { + "description": "Constant rate factor, lower is better and larger (default 28 for h265, 23 for h264).", + "maximum": 51, + "minimum": 0, + "type": "integer" + }, + "delete_source": { + "description": "Delete the .mkv once encoded (a recording this session made).", + "type": "boolean" + }, + "overwrite": { + "description": "Replace an existing save_path.", + "type": "boolean" + }, + "path": { + "description": "Absolute .mkv of a finished recording; default this session's last.", + "type": "string" + }, + "profile": { + "description": "h264: high, main or baseline; h265: main, or main10 for 10 bits per sample. Default the encoder's (high, main).", + "enum": [ + "high", + "main", + "baseline", + "main10" + ], + "type": "string" + }, + "save_path": { + "description": "Absolute .mp4 path; default the recording's, with .mp4.", + "type": "string" + }, + "speed": { + "description": "The encoder's preset: slower makes a smaller file of the same quality (default medium).", + "enum": [ + "ultrafast", + "superfast", + "veryfast", + "faster", + "fast", + "medium", + "slow", + "slower", + "veryslow" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "encode_recording", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Encode a recording" + }, + { + "completion": "none", + "description": "Sketch on the selected flat face or plane, or click one next. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sketch", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch" + }, + { + "completion": "none", + "description": "Extrude a committed sketch, one of its loops, a face or a drawn profile into a body. A committed sketch, or one loop of it, extrudes as the Extrude card does; push/pull grows a planar face of a body; a profile drawn here is an explicit closed `profile` (list of [x,y]) or a centred width x height rectangle on `plane`. End conditions match Onshape. Reply: extrude_index, the index of its sketch (-1 for a face), the boolean and body used, end, frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + } + ], + "title": "A 20 x 20 x 5 mm plate on the XY plane" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 5, + "sketch": 0 + }, + "tool": "extrude" + } + ], + "title": "A committed sketch extruded 5 mm: a rectangle around a circle makes a plate with a bore" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "distance": 3, + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + } + }, + "tool": "extrude" + } + ], + "title": "A plate's top face pushed up 3 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "the body to join, subtract from or intersect, or whose face is pushed; omit for the body a sketch touches, else the last body", + "type": "integer" + }, + "boolean": { + "default": null, + "description": "auto joins the body the profile touches, else makes a new body, as the card's default; default auto with sketch, new without", + "enum": [ + "auto", + "new", + "union", + "subtract", + "intersect", + null + ], + "type": [ + "string", + "null" + ] + }, + "distance": { + "default": 10, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "distance2": { + "default": 0, + "description": "second-side depth when end=two_sided (else falls back to distance) (mm)", + "type": "number" + }, + "end": { + "default": "blind", + "enum": [ + "blind", + "symmetric", + "two_sided", + "through_all", + "up_to_face" + ], + "type": "string" + }, + "face": { + "default": null, + "description": "push/pull: a planar face (query_topology id) of `body` grown along its outward normal (flip for inward); boolean auto joins that body. sketch, loop, profile, width, height, plane and taper are then refused, and end is blind or symmetric", + "type": [ + "integer", + "null" + ] + }, + "flip": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "height": { + "default": 20, + "description": "In mm.", + "type": "number" + }, + "loop": { + "default": null, + "description": "with sketch: one closed loop (closed_loops[].index of sketch_describe {sketch}) with the loops inside it as holes; a hole is a loop of its own, so its index extrudes the disc. Omit for the whole sketch", + "type": [ + "integer", + "null" + ] + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "profile": { + "default": [], + "description": "optional closed contour [[x,y],...] in plane mm; overrides width/height", + "type": "array" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "default": null, + "description": "a committed Sketch feature to extrude (sketch_commit's sketch_index); profile, width, height and plane are then refused", + "type": [ + "integer", + "null" + ] + }, + "taper": { + "default": 0, + "description": "draft/taper of the side wall (deg)", + "type": "number" + }, + "up_to_face": { + "default": -1, + "description": "face id (query_topology) of the body the extrude works on, when end=up_to_face", + "type": "integer" + }, + "width": { + "default": 20, + "description": "In mm.", + "type": "number" + } + }, + "type": "object" + }, + "key": "extrude", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Extrude" + }, + { + "completion": "none", + "description": "Revolve a committed sketch as the Revolve card does, or a profile drawn here, about an axis. A sketch turns about a line of it or a plane axis; a profile drawn here is an explicit `profile` offset from the axis, or a width x height rectangle with one edge on the axis, centred along it, so a full turn is a cylinder width long of radius height. Reply: revolve_index, the index of its sketch, the boolean, body and axis used, frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "axis": 1, + "plane": "XZ", + "profile": [ + [ + 10, + 0 + ], + [ + 15, + 0 + ], + [ + 15, + 10 + ], + [ + 10, + 10 + ] + ] + }, + "tool": "revolve" + } + ], + "title": "A ring: a profile 10 to 15 mm out from the XZ plane's vertical axis, turned a full circle" + }, + { + "calls": [ + { + "args": { + "plane": "XZ" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + 10, + 0, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "construction": true, + "p0": [ + 0, + 0 + ], + "p1": [ + 0, + 10 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "revolve" + } + ], + "title": "A committed sketch turned about its centerline, a construction line" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "angle": { + "default": 360, + "description": "In deg.", + "type": "number" + }, + "axis": { + "default": 0, + "description": "the plane's X (0) or Y (1) axis through its origin", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "axis_entity": { + "default": null, + "description": "with sketch: a line of the sketch (entity index) as the axis, or -1 for the plane axis; omit for the sketch's only centerline (construction line) when it has one and axis is not given", + "type": [ + "integer", + "null" + ] + }, + "body": { + "default": -1, + "description": "the body to join, subtract from or intersect; omit for the last body", + "type": "integer" + }, + "boolean": { + "default": "new", + "enum": [ + "new", + "union", + "subtract", + "intersect" + ], + "type": "string" + }, + "flip": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "height": { + "default": 10, + "description": "without sketch or profile: how far the rectangle reaches out from the axis, the solid's radius (mm)", + "type": "number" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "profile": { + "default": [], + "description": "optional closed contour [[x,y],...] in plane mm; overrides width/height", + "type": "array" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "default": null, + "description": "a committed Sketch feature to revolve (sketch_commit's sketch_index); profile, width, height and plane are then refused", + "type": [ + "integer", + "null" + ] + }, + "width": { + "default": 20, + "description": "without sketch or profile: the rectangle's length along the axis (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "revolve", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Revolve" + }, + { + "completion": "none", + "description": "Sweep a committed sketch's closed profile along a path, a sketch or a helix, as the Sweep card does. Draw the profile across the path's start (a helix's start and tangent are in its reply); along a helix the profile keeps its angle to the helix axis. Long sweeps take seconds and the reply may be a job. Reply: sweep_index, bodies, boolean, body.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "height": 20, + "pitch": 5, + "radius": 10 + }, + "tool": "helix" + }, + { + "args": { + "plane": "XZ" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 10, + 0 + ], + "radius": 1, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "path": 0, + "sketch": 1 + }, + "tool": "sweep" + } + ], + "title": "A spring: a 2 mm circle across a helix's start, swept along it" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 0, + 40 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "plane": "XZ" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 3, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "path": 0, + "sketch": 1 + }, + "tool": "sweep" + } + ], + "title": "A 6 mm rod swept along a 40 mm line" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "the body a union, subtract or intersect works on; omit for the last body", + "type": "integer" + }, + "boolean": { + "default": "new", + "enum": [ + "new", + "union", + "subtract", + "intersect" + ], + "type": "string" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "path": { + "description": "feature index of a sketch or a helix, other than the profile", + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "description": "the profile: a committed sketch's feature index", + "type": "integer" + } + }, + "then": { + "required": [ + "sketch", + "path" + ] + }, + "type": "object" + }, + "key": "sweep", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sweep" + }, + { + "completion": "none", + "description": "Loft a solid through two or more committed sketches, in order, as the Loft card does. Each sketch is on its own plane (sketch on datum planes). Lofts take seconds and the reply may be a job. Reply: loft_index, bodies, boolean, body.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "base": "XY", + "offset": 20, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -10, + -10, + 10, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "plane": { + "datum": 0 + } + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 6, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "profiles": [ + 1, + 2 + ] + }, + "tool": "loft" + } + ], + "title": "A square-to-round transition 20 mm tall, the circle sketched on a datum plane" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "the body a union, subtract or intersect works on; omit for the last body", + "type": "integer" + }, + "boolean": { + "default": "new", + "enum": [ + "new", + "union", + "subtract", + "intersect" + ], + "type": "string" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "profiles": { + "description": "sketch feature indices, in loft order", + "type": "array" + }, + "ruled": { + "default": false, + "description": "straight sections between the profiles instead of a smooth skin", + "type": "boolean" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "profiles" + ] + }, + "type": "object" + }, + "key": "loft", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Loft" + }, + { + "completion": "none", + "description": "Offset a face of a body by a wall thickness, producing a new thin solid body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "thickness": 2 + }, + "tool": "thicken" + } + ], + "title": "A 2 mm skin grown from a plate's top face as a new body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "face": { + "description": "face id to thicken (query_topology)", + "type": "integer" + }, + "flip": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "thickness": { + "default": 2, + "description": "In mm.", + "type": "number" + } + }, + "then": { + "required": [ + "face" + ] + }, + "type": "object" + }, + "key": "thicken", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Thicken" + }, + { + "completion": "none", + "description": "Grow a thin rib wall (stiffener) from an open Line sketch entity, fused to a body. The wall is centred on the line in the sketch plane, thickness wide, and grows depth along the sketch plane's normal. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 3, + "height": 20, + "width": 40 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + } + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + -15, + 0 + ], + "p1": [ + 15, + 0 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "depth": 8, + "entity": 0, + "sketch": 2, + "thickness": 2 + }, + "tool": "rib" + } + ], + "title": "A 2 mm rib 8 mm tall across a plate's top face" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "depth": { + "default": 10, + "description": "along the sketch plane's normal, or against it when negative (mm)", + "type": "number" + }, + "entity": { + "description": "entity index of the open Line within the sketch", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "description": "sketch feature index holding the open line", + "type": "integer" + }, + "thickness": { + "default": 2, + "description": "In mm.", + "type": "number" + } + }, + "then": { + "required": [ + "sketch", + "entity" + ] + }, + "type": "object" + }, + "key": "rib", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rib" + }, + { + "completion": "none", + "description": "Combine two bodies: union | subtract (tool from target) | intersect. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 20, + "height": 6, + "width": 6 + }, + "tool": "extrude" + }, + { + "args": { + "op": "subtract", + "target": 0, + "tool": 1 + }, + "tool": "boolean" + } + ], + "title": "A post subtracted from a block" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 5, + -5 + ], + [ + 20, + -5 + ], + [ + 20, + 5 + ], + [ + 5, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "op": "union", + "target": 0, + "tool": 1 + }, + "tool": "boolean" + } + ], + "title": "Two overlapping blocks joined into one body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "keep_tool": { + "default": false, + "type": "boolean" + }, + "op": { + "default": "subtract", + "enum": [ + "union", + "subtract", + "intersect" + ], + "type": "string" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "target": { + "default": 0, + "type": "integer" + }, + "tolerance": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "tool": { + "default": 1, + "type": "integer" + } + }, + "type": "object" + }, + "key": "boolean", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Join" + }, + { + "completion": "none", + "description": "Cut the tool body out of the target. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "bool_subtract", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Subtract" + }, + { + "completion": "none", + "description": "Keep only where the two bodies overlap. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "bool_intersect", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Intersect" + }, + { + "completion": "none", + "description": "Extrude a sketch wire with no end caps -> an open sheet body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + -15, + 0 + ], + "p1": [ + 15, + 0 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 10, + "sketch": 0 + }, + "tool": "surf_extrude" + } + ], + "title": "A 30 mm line extruded 10 mm into a flat sheet" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 10, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 20, + "sketch": 0 + }, + "tool": "surf_extrude" + } + ], + "title": "A circle extruded 20 mm into an open tube, with no end caps" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "distance": { + "default": 10, + "description": "along the sketch plane's normal, or against it when negative (mm)", + "type": "number" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "description": "sketch feature index", + "type": "integer" + } + }, + "then": { + "required": [ + "sketch" + ] + }, + "type": "object" + }, + "key": "surf_extrude", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Surface Extrude" + }, + { + "completion": "none", + "description": "Revolve a sketch wire with no caps -> an open sheet body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XZ" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 10, + 0 + ], + "p1": [ + 10, + 20 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "axis": 1, + "sketch": 0 + }, + "tool": "surf_revolve" + } + ], + "title": "A cylinder's wall: a line 10 mm out from the XZ plane's vertical axis, turned a full circle" + }, + { + "calls": [ + { + "args": { + "plane": "XZ" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 5, + 0 + ], + "p1": [ + 15, + 20 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "angle": 180, + "axis": 1, + "sketch": 0 + }, + "tool": "surf_revolve" + } + ], + "title": "Half a truncated cone's wall: a sloping line turned 180 degrees about the XZ plane's vertical axis" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "angle": { + "default": 360, + "description": "In deg.", + "type": "number" + }, + "axis": { + "default": 0, + "description": "the sketch plane's X (0) or Y (1) axis through its origin", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "description": "sketch feature index", + "type": "integer" + } + }, + "then": { + "required": [ + "sketch" + ] + }, + "type": "object" + }, + "key": "surf_revolve", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Surface Revolve" + }, + { + "completion": "none", + "description": "Skin two or more profile sketches with no end caps -> an open sheet body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "base": "XY", + "offset": 20, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 5, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "plane": { + "datum": 0 + } + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 15, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "profiles": [ + 1, + 2 + ] + }, + "tool": "surf_loft" + } + ], + "title": "An open funnel skinned from a circle on XY to a wider one on a datum plane 20 mm up" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "profiles": { + "description": "sketch feature indices, in order", + "type": "array" + }, + "ruled": { + "default": false, + "type": "boolean" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "profiles" + ] + }, + "type": "object" + }, + "key": "surf_loft", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Surface Loft" + }, + { + "completion": "none", + "description": "Fill a sketch's closed boundary with one smooth face -> a sheet body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 10, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "surf_fill" + } + ], + "title": "A circle filled with a disc-shaped sheet" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "surf_fill" + } + ], + "title": "A rectangle filled with a flat sheet" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "sketch": { + "description": "sketch feature index", + "type": "integer" + } + }, + "then": { + "required": [ + "sketch" + ] + }, + "type": "object" + }, + "key": "surf_fill", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Surface Fill" + }, + { + "completion": "none", + "description": "Thicken a whole sheet body into a solid. A sheet of several faces whose free rims close into planar loops (the walls of a box with no lids) is capped at them and grows inward, into the closed shape that makes, whatever flip says; one whose rim can't be capped is refused. A single face or a closed shell is offset face by face along each face's normal, the one query_topology gives, or against it with flip; a closed shell can fail to thicken this way. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "surf_fill" + }, + { + "args": { + "thickness": 2 + }, + "tool": "thicken_surf" + } + ], + "title": "A 30 x 20 mm sheet thickened into a 2 mm plate, a new body" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 10, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 20, + "sketch": 0 + }, + "tool": "surf_extrude" + }, + { + "args": { + "body": 0, + "flip": true, + "thickness": 1.5 + }, + "tool": "thicken_surf" + } + ], + "title": "An open tube thickened 1.5 mm outward into a pipe: flip, as its normal points inward" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "sheet body; omit for the last body", + "type": "integer" + }, + "flip": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "thickness": { + "default": 2, + "description": "In mm.", + "type": "number" + } + }, + "type": "object" + }, + "key": "thicken_surf", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Thicken Surface" + }, + { + "completion": "none", + "description": "Drill a circular hole at (x,y) or `at` on a plane. Reply: hole_index, body, x and y in the frame, off_plane with at, frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + } + ], + "title": "A 5 mm hole through the middle of a plate" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "depth": 3, + "diameter": 4, + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + }, + "x": 5 + }, + "tool": "hole" + } + ], + "title": "A 4 mm hole 3 mm deep into a plate's top face, 5 mm off centre" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "at": { + "default": null, + "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer", + "type": [ + "array", + "object", + "null" + ] + }, + "body": { + "default": -1, + "description": "the body to drill; omit for a face plane's body, else the last body", + "type": "integer" + }, + "depth": { + "default": 10, + "description": "In mm.", + "type": "number" + }, + "diameter": { + "default": 5, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "through": { + "default": false, + "type": "boolean" + }, + "x": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + }, + "y": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "hole", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Hole" + }, + { + "completion": "none", + "description": "Cut a thread as the Thread card does, along a cylindrical face or a circular edge, or on a plane. On a face a bore is tapped, a boss threaded; on a plane the thread goes at (x,y) or `at`. Without designation, a face or edge takes the nearest standard size, ISO metric and UTS alike. Long threads take seconds and the reply may be a job. Reply: thread_index, designation (null when custom), internal, diameter, pitch, depth, length, body, x, y, frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 6.8, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "body": 0, + "kinds": [ + "cylindrical" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "designation": "M8", + "face": 6, + "generation": { + "from_call": 2, + "key": "generation" + } + }, + "tool": "thread" + } + ], + "title": "An M8 thread tapped into a 6.8 mm hole through a block" + }, + { + "calls": [ + { + "args": { + "designation": "M6", + "internal": false, + "length": 10, + "plane": "XY" + }, + "tool": "thread" + } + ], + "title": "An M6 threaded rod 10 mm long, standing on the XY plane" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 5, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 12, + "sketch": 0 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "kinds": [ + "cylindrical" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 0, + "generation": { + "from_call": 4, + "key": "generation" + } + }, + "tool": "thread" + } + ], + "title": "A 10 mm boss threaded at the nearest standard size, which the reply's designation names" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "at": { + "default": null, + "description": "on a plane, instead of x and y: a world point [x, y, z], or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the thread shares, as hole takes it", + "type": [ + "array", + "object", + "null" + ] + }, + "body": { + "default": -1, + "description": "the body of face or edge, or the body threaded on a plane; omit for the last body (on a plane, a face plane's body)", + "type": "integer" + }, + "depth": { + "default": null, + "description": "radial depth; default the 60 degree V's for the pitch and role (mm)", + "type": [ + "number", + "null" + ] + }, + "designation": { + "default": null, + "description": "e.g. M5, M8x1, 1/4-20 UNC: sets diameter, pitch and depth", + "type": [ + "string", + "null" + ] + }, + "diameter": { + "default": null, + "description": "nominal (major) diameter, replacing the standard's; with pitch, a custom thread (mm)", + "type": [ + "number", + "null" + ] + }, + "edge": { + "default": null, + "description": "instead of face: a circular edge id of `body`, the thread rising along its normal; needs length", + "type": [ + "integer", + "null" + ] + }, + "face": { + "default": null, + "description": "a cylindrical face id of `body` (query_topology); the thread runs its length from its lower end", + "type": [ + "integer", + "null" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "internal": { + "default": null, + "description": "true taps a hole, false threads a rod; required on a plane, else from the face (a bore is internal), external for an edge", + "type": [ + "boolean", + "null" + ] + }, + "length": { + "default": null, + "description": "default the face's length; required for an edge or a plane (mm)", + "type": [ + "number", + "null" + ] + }, + "pitch": { + "default": null, + "description": "replaces the standard's (mm)", + "type": [ + "number", + "null" + ] + }, + "plane": { + "default": null, + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "x": { + "default": 0, + "description": "on a plane: offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + }, + "y": { + "default": 0, + "description": "on a plane: offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "thread", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Thread" + }, + { + "completion": "none", + "description": "Hollow a body to a wall thickness (inward); optionally leave one face open. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "thickness": 1.5 + }, + "tool": "shell" + } + ], + "title": "A 20 x 20 x 10 mm box hollowed to 1.5 mm walls, open at the top" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "thickness": 2 + }, + "tool": "shell" + } + ], + "title": "A block hollowed to closed 2 mm walls" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "face": { + "default": -1, + "description": "face id to leave open (query_topology); omit for a closed hollow", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "thickness": { + "default": 1, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + } + }, + "type": "object" + }, + "key": "shell", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Shell" + }, + { + "completion": "none", + "description": "Trim the body with a plane — drag the offset arrow; keep one half or both. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "cut", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Cut" + }, + { + "completion": "none", + "description": "Split a body with a plane, as the Cut card does, moved by offset and turned over by flip; or along the plane of a face. The upper piece is on the plane's normal side; keeping both makes two bodies, the lower one right after the upper. Reply: split_index, bodies, body, upper_body and lower_body (the pieces kept), frame (a plane's, after offset and flip).", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "offset": 5, + "plane": "XY" + }, + "tool": "split" + } + ], + "title": "A block cut in two at half its height" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "keep_upper": false, + "offset": 5, + "plane": "XY" + }, + "tool": "split" + } + ], + "title": "A block cut at half its height, keeping only the lower half" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 4, + "height": 30, + "width": 30 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 1 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 5, + "face_body": 1, + "generation": { + "from_call": 2, + "key": "generation" + } + }, + "tool": "split" + } + ], + "title": "A block split along the top face of a wider plate" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "face": { + "default": null, + "description": "instead of plane: a face id (query_topology) to split along", + "type": [ + "integer", + "null" + ] + }, + "face_body": { + "default": -1, + "description": "with face: the body that owns it; -1 = target", + "type": "integer" + }, + "flip": { + "default": false, + "description": "with plane: turn it over, swapping upper and lower", + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "keep_lower": { + "default": true, + "type": "boolean" + }, + "keep_upper": { + "default": true, + "type": "boolean" + }, + "offset": { + "default": 0, + "description": "with plane: along its normal (mm)", + "type": "number" + }, + "plane": { + "default": null, + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object", + "null" + ] + } + }, + "type": "object" + }, + "key": "split", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Split" + }, + { + "completion": "none", + "description": "Round measured edges of a body (edge ids from query_topology on that body). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "convex": true, + "direction": [ + 0, + 0, + 1 + ], + "edge_kinds": [ + "line" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "edge": [ + 0, + 1, + 4, + 7 + ], + "generation": { + "from_call": 1, + "key": "generation" + }, + "radius": 2 + }, + "tool": "fillet" + } + ], + "title": "A plate's four vertical corners rounded to 2 mm" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "adjacency": true, + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "edge": 3, + "generation": { + "from_call": 1, + "key": "generation" + }, + "radius": 1 + }, + "tool": "fillet" + } + ], + "title": "One top edge of a plate rounded to 1 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body. edge id is resolved against THIS body.", + "type": "integer" + }, + "edge": { + "description": "one edge id, or an array of ids rounded together in one feature", + "type": [ + "integer", + "array" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "radius": { + "default": 1, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "edge" + ] + }, + "type": "object" + }, + "key": "fillet", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Fillet" + }, + { + "completion": "none", + "description": "Chamfer measured edges of a body (edge ids from query_topology on that body). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "adjacency": true, + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "distance": 1, + "edge": [ + 3, + 6, + 9, + 11 + ], + "generation": { + "from_call": 1, + "key": "generation" + } + }, + "tool": "chamfer" + } + ], + "title": "A plate's top edges chamfered 1 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body. edge id is resolved against THIS body.", + "type": "integer" + }, + "distance": { + "default": 1, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "edge": { + "description": "one edge id, or an array of ids chamfered together in one feature", + "type": [ + "integer", + "array" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "edge" + ] + }, + "type": "object" + }, + "key": "chamfer", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Chamfer" + }, + { + "completion": "none", + "description": "Taper a body face by an angle about its base (pull direction +Z). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "direction": [ + 1, + 0, + 0 + ] + }, + "tool": "query_topology" + }, + { + "args": { + "angle": 5, + "body": 0, + "face": 1, + "generation": { + "from_call": 1, + "key": "generation" + } + }, + "tool": "draft" + } + ], + "title": "A block's +X side tapered 5 degrees" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "angle": { + "default": 5, + "description": "In deg.", + "type": "number" + }, + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "face": { + "description": "face id to draft (query_topology)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "face" + ] + }, + "type": "object" + }, + "key": "draft", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Draft" + }, + { + "completion": "none", + "description": "Offset a sheet body by a signed distance -> another sheet body. A positive offset moves each face along its normal, the one query_topology gives, and a negative one against it, so the side depends on how the sheet was made: an extruded circle's normal points inward. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "surf_fill" + }, + { + "args": { + "offset": 5 + }, + "tool": "surf_offset" + } + ], + "title": "A rectangular sheet copied 5 mm above itself" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 10, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 20, + "sketch": 0 + }, + "tool": "surf_extrude" + }, + { + "args": { + "body": 0, + "offset": -2 + }, + "tool": "surf_offset" + } + ], + "title": "An open tube of radius 10 mm offset -2 mm, against its inward normal, to one of radius 12 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "sheet body; omit for the last body", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "offset": { + "default": 1, + "description": "In mm.", + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "surf_offset", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Surface Offset" + }, + { + "completion": "none", + "description": "Replicate a body: linear (count along a plane axis at spacing) or circular (count over an angle about the plane normal). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "count": 3, + "spacing": 30 + }, + "tool": "pattern" + } + ], + "title": "Three plates 30 mm apart along X" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "profile": [ + [ + 20, + -3 + ], + [ + 30, + -3 + ], + [ + 30, + 3 + ], + [ + 20, + 3 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "circular": true, + "count": 6 + }, + "tool": "pattern" + } + ], + "title": "Six blocks in a circle about the XY plane's normal" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "angle": { + "default": 360, + "description": "circular total sweep (deg)", + "type": "number" + }, + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "circular": { + "default": false, + "type": "boolean" + }, + "count": { + "default": 3, + "minimum": 1, + "type": "integer" + }, + "dir": { + "default": 0, + "description": "linear axis: 0=plane X, 1=plane Y", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "spacing": { + "default": 10, + "description": "linear step (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "pattern", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Linear pattern" + }, + { + "completion": "none", + "description": "Repeat the body around an axis — set the count and sweep. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "pattern_circular", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Circular pattern" + }, + { + "completion": "none", + "description": "Mirror a body about a base plane. mode=new creates a mirrored copy; mode=add fuses the mirror back into the source. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "profile": [ + [ + -5, + 5 + ], + [ + 5, + 5 + ], + [ + 5, + 15 + ], + [ + -5, + 15 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "plane": "XZ" + }, + "tool": "mirror" + } + ], + "title": "A mirrored copy of a block across the XZ plane" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "profile": [ + [ + -5, + 0 + ], + [ + 5, + 0 + ], + [ + 5, + 10 + ], + [ + -5, + 10 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "mode": "add", + "plane": "XZ" + }, + "tool": "mirror" + } + ], + "title": "A block against the XZ plane and its mirror image fused into one body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "keep_original": { + "default": true, + "description": "when mode=new, keep the source body", + "type": "boolean" + }, + "mode": { + "default": "new", + "enum": [ + "new", + "add" + ], + "type": "string" + }, + "plane": { + "default": "XZ", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "mirror", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mirror" + }, + { + "completion": "none", + "description": "Replicate a body along a sketch curve. `count` copies are placed at equal-parameter points on the entity, each translated by (P_i - P_0). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "end_angle_deg": 180, + "radius": 30, + "start_angle_deg": 0, + "type": "arc" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 10, + "profile": [ + [ + 28, + -2 + ], + [ + 32, + -2 + ], + [ + 32, + 2 + ], + [ + 28, + 2 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "count": 4, + "entity": 0, + "sketch": 0 + }, + "tool": "pat_curve" + } + ], + "title": "Four pegs spaced along a half circle" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "count": { + "default": 3, + "minimum": 1, + "type": "integer" + }, + "entity": { + "description": "entity index of the guide curve within that sketch", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "sketch": { + "description": "feature index of the sketch holding the guide curve", + "type": "integer" + } + }, + "required": [ + "sketch", + "entity" + ], + "type": "object" + }, + "key": "pat_curve", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Pattern on Curve" + }, + { + "completion": "none", + "description": "Move and/or rotate a body (B-rep transform). copy=true keeps the source and appends the transformed copy as a new body. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "dx": 30 + }, + "tool": "body_transform" + } + ], + "title": "A plate moved 30 mm along X" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "copy": true, + "dz": 10 + }, + "tool": "body_transform" + } + ], + "title": "A copy of a plate 10 mm above it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "angle": { + "default": 0, + "description": "In deg.", + "type": "number" + }, + "axis_x": { + "default": 0, + "type": "number" + }, + "axis_y": { + "default": 0, + "type": "number" + }, + "axis_z": { + "default": 1, + "type": "number" + }, + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "copy": { + "default": false, + "type": "boolean" + }, + "dx": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "dy": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "dz": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "pivot_x": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "pivot_y": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "pivot_z": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "body_transform", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Move" + }, + { + "completion": "none", + "description": "Mate two bodies: transform the moving body (cs_b) so its connector lands on the fixed one (cs_a). kind: 0=Fastened, 1=Planar, 2=Revolute, 3=Slider, 4=Cylindrical. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 30, + -5 + ], + [ + 40, + -5 + ], + [ + 40, + 5 + ], + [ + 30, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 5, + "generation": { + "from_call": 2, + "key": "generation" + }, + "type": "face_and_direction" + }, + "tool": "coordsys_v" + }, + { + "args": { + "at_extreme": "-z", + "body": 1 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 1, + "face": 4, + "generation": { + "from_call": 4, + "key": "generation" + }, + "type": "face_and_direction" + }, + "tool": "coordsys_v" + }, + { + "args": { + "cs_a": 4, + "cs_b": 5, + "flip": true, + "kind": 0 + }, + "tool": "mate" + } + ], + "title": "A block stood on a plate: its bottom-face connector fastened, turned over, to the plate's top-face one" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "angle": { + "default": 0, + "description": "In deg.", + "type": "number" + }, + "cs_a": { + "description": "feature index of the fixed CoordSys (mate connector A)", + "type": "integer" + }, + "cs_b": { + "description": "feature index of the CoordSys on the body that moves", + "type": "integer" + }, + "flip": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "kind": { + "default": 0, + "description": "0=Fastened (rigid), 1=Planar (normal only), 2=Revolute (free rotation about axis), 3=Slider (free translation along axis), 4=Cylindrical (free rotation+translation)", + "type": "integer" + }, + "offset": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "cs_a", + "cs_b" + ] + }, + "type": "object" + }, + "key": "mate", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mate" + }, + { + "completion": "none", + "description": "Add a datum plane as the Plane card does, to sketch or build on as {\"datum\": plane_index}. Offset from a base plane or a face, at an angle about an edge, midway between two faces, tangent to a cylindrical face, through two edges, or coincident with a base plane or a face. Not the `plane` param of other Design commands. Reply: plane_index, name, frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "base": "XY", + "offset": 20, + "type": "offset" + }, + "tool": "plane" + } + ], + "title": "A datum plane 20 mm above XY" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "kinds": [ + "planar" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "face_a": { + "body": 0, + "face": 4 + }, + "face_b": { + "body": 0, + "face": 5 + }, + "generation": { + "from_call": 1, + "key": "generation" + }, + "type": "midplane" + }, + "tool": "plane" + } + ], + "title": "A datum plane midway between a block's top and bottom faces" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "adjacency": true, + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "angle": 30, + "edge_a": { + "body": 0, + "edge": 3 + }, + "face_a": { + "body": 0, + "face": 5 + }, + "generation": { + "from_call": 1, + "key": "generation" + }, + "type": "angle" + }, + "tool": "plane" + } + ], + "title": "A datum plane turned 30 degrees from a plate's top face about its front edge" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "angle": { + "default": 0, + "description": "offset without face_a: tilt about the base axis `axis`; angle: turn about edge_a from the reference plane; tangent: position around the cylinder (deg)", + "type": "number" + }, + "axis": { + "default": 0, + "description": "offset without face_a: tilt about the base plane's X (0) or Y (1) axis", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "base": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin, or {\"datum\": i}: what offset, coincident and angle build on without face_a", + "type": [ + "string", + "object" + ] + }, + "edge_a": { + "default": null, + "description": "Edge A, {\"body\": b, \"edge\": e}: angle's hinge; two_edges' first edge", + "type": [ + "object", + "null" + ] + }, + "edge_b": { + "default": null, + "description": "Edge B, {\"body\": b, \"edge\": e}: two_edges' second edge", + "type": [ + "object", + "null" + ] + }, + "face_a": { + "default": null, + "description": "Face A, {\"body\": b, \"face\": f}: offset or coincident on a face; angle's reference plane; midplane's first face; tangent's cylindrical face", + "type": [ + "object", + "null" + ] + }, + "face_b": { + "default": null, + "description": "Face B, {\"body\": b, \"face\": f}: midplane's second face", + "type": [ + "object", + "null" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "offset": { + "default": 20, + "description": "offset: distance along the normal of base or face_a (mm)", + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "size": { + "default": [ + 60, + 60 + ], + "description": "[u, v]: the size the plane is drawn at (mm)", + "type": "array" + }, + "type": { + "default": "offset", + "enum": [ + "offset", + "angle", + "midplane", + "tangent", + "two_edges", + "coincident" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "plane", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Plane" + }, + { + "completion": "none", + "description": "Create a datum axis (reference line): two points, face normal, cylinder centreline, plane intersection, or along edge. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "body": 0, + "kinds": [ + "cylindrical" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 6, + "generation": { + "from_call": 2, + "key": "generation" + }, + "type": "cylinder" + }, + "tool": "axis" + } + ], + "title": "The axis of a hole through a plate" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "type": "face_normal" + }, + "tool": "axis" + } + ], + "title": "The normal through the centre of a plate's top face" + }, + { + "calls": [ + { + "args": { + "base": "XZ", + "offset": 10, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "base": "YZ", + "offset": 10, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "plane_a": 0, + "plane_b": 1, + "type": "plane_intersection" + }, + "tool": "axis" + } + ], + "title": "The vertical line where two datum planes meet" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "body for face/edge refs", + "type": "integer" + }, + "edge": { + "default": -1, + "description": "edge id (query_topology) for along_edge", + "type": "integer" + }, + "face": { + "default": -1, + "description": "face id (query_topology) for face_normal/cylinder", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "p1": { + "default": [ + 0, + 0, + 0 + ], + "description": "first point [x,y,z] for two_points", + "type": "array" + }, + "p2": { + "default": [ + 0, + 0, + 10 + ], + "description": "second point [x,y,z] for two_points", + "type": "array" + }, + "plane_a": { + "default": -1, + "description": "first datum plane feature index for plane_intersection", + "type": "integer" + }, + "plane_b": { + "default": -1, + "description": "second datum plane feature index for plane_intersection", + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "type": { + "default": "two_points", + "enum": [ + "two_points", + "face_normal", + "cylinder", + "plane_intersection", + "along_edge" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "axis", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Axis" + }, + { + "completion": "none", + "description": "Create a datum coordinate system (origin + orthonormal axes). PointWorld aligns to world; FaceAndDirection uses a face for Z and an edge/hint for X. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "adjacency": true, + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "edge": 3, + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "type": "face_and_direction" + }, + "tool": "coordsys_v" + } + ], + "title": "A connector on a plate's top face, its x axis along the front edge" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": -1, + "description": "body for face/edge refs", + "type": "integer" + }, + "edge": { + "default": -1, + "description": "edge id (query_topology) for X axis hint", + "type": "integer" + }, + "face": { + "default": -1, + "description": "face id (query_topology) for Z axis", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "point": { + "default": [ + 0, + 0, + 0 + ], + "description": "origin [x,y,z] for point_world", + "type": "array" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "type": { + "default": "point_world", + "enum": [ + "point_world", + "face_and_direction" + ], + "type": "string" + }, + "x_hint": { + "default": [ + 1, + 0, + 0 + ], + "description": "fallback X direction hint if no edge given", + "type": "array" + } + }, + "type": "object" + }, + "key": "coordsys_v", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Coordinate system" + }, + { + "completion": "none", + "description": "Create a helical curve, a sweep path for springs, coils and augers. It starts on the plane's x axis at `radius` from its origin. pitch = axial rise per turn. left_handed flips the winding. taper_deg != 0 gives a conical helix. Reply: helix_index, frame, start and tangent (world), to draw a sweep's profile across the curve there.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "height": 20, + "pitch": 5, + "radius": 10 + }, + "tool": "helix" + } + ], + "title": "A four-turn helix on XY: radius 10 mm, pitch 5 mm, 20 mm tall" + }, + { + "calls": [ + { + "args": { + "height": 20, + "left_handed": true, + "pitch": 4, + "radius": 10, + "taper_deg": 10 + }, + "tool": "helix" + } + ], + "title": "A left-handed conical helix tapering 10 degrees" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "height": { + "default": 20, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "left_handed": { + "default": false, + "type": "boolean" + }, + "pitch": { + "default": 5, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "radius": { + "default": 10, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "taper_deg": { + "default": 0, + "description": "In deg.", + "type": "number" + } + }, + "type": "object" + }, + "key": "helix", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Helix" + }, + { + "completion": "none", + "description": "Project edges of a solid onto a sketch plane, producing a new sketch feature. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "face": 5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": "XY", + "source_body": 0 + }, + "tool": "project" + } + ], + "title": "A plate's top-face outline projected onto the XY plane as a new sketch" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "adjacency": true, + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "edges": [ + 3, + 6 + ], + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": "XY", + "source_body": 0 + }, + "tool": "project" + } + ], + "title": "Two top edges of a plate, meeting at a corner, projected onto the XY plane" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "edges": { + "default": [], + "description": "global edge ids to project; empty => project the face", + "type": "array" + }, + "face": { + "default": -1, + "description": "global face id on the source body; when set, all its edges are projected", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + }, + "source_body": { + "default": -1, + "description": "body owning the edges; -1 = last body", + "type": "integer" + } + }, + "type": "object" + }, + "key": "project", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Project" + }, + { + "completion": "none", + "description": "Measure two refs, on one body or two: distance, closest points, angle and the gap between parallel faces. distance is between their representative points (a face's centroid, an edge's middle, an axis's middle); min_distance comes with closest_a and closest_b; angle_deg when both have a direction; parallel_gap across two parallel planar faces.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "kinds": [ + "planar" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "a": { + "face": 5 + }, + "b": { + "face": 4 + }, + "body": 0, + "generation": { + "from_call": 1, + "key": "generation" + } + }, + "tool": "measure" + } + ], + "title": "A plate's thickness, between its top and bottom faces" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 20, + -5 + ], + [ + 30, + -5 + ], + [ + 30, + 5 + ], + [ + 20, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "direction": [ + 1, + 0, + 0 + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 1, + "direction": [ + -1, + 0, + 0 + ] + }, + "tool": "query_topology" + }, + { + "args": { + "a": { + "body": 0, + "face": 1 + }, + "b": { + "body": 1, + "face": 3 + }, + "generation": { + "from_call": 3, + "key": "generation" + } + }, + "tool": "measure" + } + ], + "title": "The 10 mm gap between two blocks' facing sides" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "a": { + "description": "{\"face\": f}, {\"edge\": e} or {\"point\": [x, y, z]}, with an optional \"body\"; {\"face\": f, \"axis\": true} is a cylindrical face's axis over its length", + "type": "object" + }, + "b": { + "description": "as a", + "type": "object" + }, + "body": { + "default": 0, + "description": "the body of a ref that names none", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "a", + "b" + ], + "type": "object" + }, + "key": "measure", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Measure" + }, + { + "completion": "none", + "description": "Volume / surface area / centre of mass / inertia tensor of a body.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0 + }, + "tool": "mass_props" + } + ], + "title": "The volume and centre of mass of a 20 x 20 x 5 mm plate" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "body": { + "default": 0, + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "mass_props", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Volume and area" + }, + { + "completion": "none", + "description": "Solid bodies that overlap, as {body_a, body_b, volume}. Read-only; bodies that merely touch enclose no volume and are not reported.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 20, + "height": 10, + "width": 10 + }, + "tool": "extrude" + }, + { + "args": { + "silent": true + }, + "tool": "interference" + } + ], + "title": "A post standing in a block: the two overlap" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "min_volume": { + "default": 1e-06, + "description": "overlap volume above which a pair counts as interfering (mm^3)", + "type": "number" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "type": "object" + }, + "key": "interference", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Interference" + }, + { + "completion": "none", + "description": "Bind a feature's numeric field to an expression over the design variables, or unbind it with an empty expr. Unbound, the field keeps its value. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "expr": "8", + "name": "t" + }, + "tool": "set_variable" + }, + { + "args": { + "expr": "t", + "feature": 1, + "field": "distance" + }, + "tool": "edit_feature" + } + ], + "title": "A plate's thickness bound to the variable t" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "expr": "8", + "name": "t" + }, + "tool": "set_variable" + }, + { + "args": { + "expr": "t", + "feature": 1, + "field": "distance" + }, + "tool": "edit_feature" + }, + { + "args": { + "expr": "", + "feature": 1, + "field": "distance" + }, + "tool": "edit_feature" + } + ], + "title": "A plate's thickness unbound, keeping the 8 mm the binding gave it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "expr": { + "description": "\"\" removes the binding", + "type": "string" + }, + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "field": { + "description": "a numeric field of describe_feature's params, e.g. width, distance, hole_diameter, thread_diameter", + "type": "string" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "feature", + "field", + "expr" + ] + }, + "type": "object" + }, + "key": "edit_feature", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Edit" + }, + { + "completion": "none", + "description": "Give this feature a name you will recognise in the tree (a body takes its name from the feature that makes it). It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "rename", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rename…" + }, + { + "completion": "none", + "description": "Remove faces from a solid, healing the gap via OCCT defeaturing. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "body": 0, + "kinds": [ + "cylindrical" + ] + }, + "tool": "query_topology" + }, + { + "args": { + "body": 0, + "faces": [ + 6 + ], + "generation": { + "from_call": 2, + "key": "generation" + } + }, + "tool": "delete_face" + } + ], + "title": "A plate's bore filled in by deleting its cylindrical face" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "if": { + "minProperties": 1 + }, + "properties": { + "body": { + "default": -1, + "description": "target body; omit for the last body", + "type": "integer" + }, + "faces": { + "description": "global face ids to delete", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "silent": { + "description": "true runs the tool with the other arguments and opens nothing. A call with no arguments does what the Design tab's menu row does, as a person's pick does. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "enum": [ + true + ], + "type": "boolean" + } + }, + "then": { + "required": [ + "faces" + ] + }, + "type": "object" + }, + "key": "delete_face", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete Face" + }, + { + "completion": "none", + "description": "Set the selected body's display color. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "colour", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Color" + }, + { + "completion": "none", + "description": "Frame the selection in the view, keeping the view direction. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "zoom_to", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Zoom to selection" + }, + { + "completion": "none", + "description": "Delete what is selected. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete" + }, + { + "completion": "none", + "description": "Delete this whole body — removes the feature it was made from. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "delete_body", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete Body" + }, + { + "completion": "none", + "description": "Line — click start, then end. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_line_t", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Line" + }, + { + "completion": "none", + "description": "Click points; click the first point to close the loop, right-click to end it open. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_polyline", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Polyline" + }, + { + "completion": "none", + "description": "Rectangle — click two opposite corners. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_rect", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Corner rectangle" + }, + { + "completion": "none", + "description": "Click center, then a corner. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_rect_center", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Center rectangle" + }, + { + "completion": "none", + "description": "Click two corners of one edge, then a point for the width. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_rect_oblique", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Oblique rectangle" + }, + { + "completion": "none", + "description": "Click two opposite corners, then a point for the corner radius. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_rect_rounded", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rounded rectangle" + }, + { + "completion": "none", + "description": "Circle — click center, then radius. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_circle", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Center circle" + }, + { + "completion": "none", + "description": "Click two ends of the diameter. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_circle_2pt", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "2-point circle" + }, + { + "completion": "none", + "description": "Click three points on the circle. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_circle_3pt", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "3-point circle" + }, + { + "completion": "none", + "description": "Arc — click start, end, then a point. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_arc_t", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "3-point arc" + }, + { + "completion": "none", + "description": "Click start (on the last entity) then end. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_arc_tangent", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Tangent arc" + }, + { + "completion": "none", + "description": "Click center, then start, then a point for the end angle. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_arc_center", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Center-point arc" + }, + { + "completion": "none", + "description": "Slot — two centerline ends, then the width. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_slot", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Slot" + }, + { + "completion": "none", + "description": "Click center, start, end, then a point for the width. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_slot_arc", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Arc slot" + }, + { + "completion": "none", + "description": "Ellipse — center, major end, minor point. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_ellipse", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Ellipse" + }, + { + "completion": "none", + "description": "Click center, major-axis end, minor point, then arc start and end. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_ellipse_arc", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Elliptical arc" + }, + { + "completion": "none", + "description": "Spline — click control points. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_spline", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Spline" + }, + { + "completion": "none", + "description": "Triangle — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_3", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Triangle" + }, + { + "completion": "none", + "description": "Square — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_4", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Square" + }, + { + "completion": "none", + "description": "Pentagon — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_5", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Pentagon" + }, + { + "completion": "none", + "description": "Hexagon — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_polygon", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Hexagon" + }, + { + "completion": "none", + "description": "Octagon — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_8", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Octagon" + }, + { + "completion": "none", + "description": "Dodecagon — click center, then a vertex. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_12", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Dodecagon" + }, + { + "completion": "none", + "description": "Measure the polygon to its corners (inscribed). It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_inscribed", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Inscribed" + }, + { + "completion": "none", + "description": "Measure the polygon to its flats (circumscribed). It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_poly_circumscribed", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Circumscribed" + }, + { + "completion": "none", + "description": "Point — click to place. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_point_t", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Point" + }, + { + "completion": "none", + "description": "Type text; it becomes a Text feature on this sketch's plane, editable later. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_text", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Text" + }, + { + "completion": "none", + "description": "Import an SVG outline into this sketch as editable lines. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_svg", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "SVG" + }, + { + "completion": "none", + "description": "Offset — pick an entity, drag the distance. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_offset", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Offset" + }, + { + "completion": "none", + "description": "Trim — click a segment to trim it. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_trim", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Trim" + }, + { + "completion": "none", + "description": "Fillet — pick two lines, set the radius. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_fillet", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Fillet" + }, + { + "completion": "none", + "description": "Chamfer — pick two lines, set the distance. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_chamfer", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Chamfer" + }, + { + "completion": "none", + "description": "Pick entities, drag the spacing handle, click the count; click empty to apply. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_array", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Linear array" + }, + { + "completion": "none", + "description": "Pick entities, drag the sweep handle, click the count; click empty to apply. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_array_polar", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Polar array" + }, + { + "completion": "none", + "description": "Mirror — pick axis, then entities. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_mirror", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mirror" + }, + { + "completion": "none", + "description": "Pick entities, then drag the handle or click the distance; click empty to apply. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_move", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Move" + }, + { + "completion": "none", + "description": "Pick entities, then drag around the pivot or click the angle; click empty to apply. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_rotate", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Rotate" + }, + { + "completion": "none", + "description": "Pick entities, then drag the handle or click the factor; click empty to apply. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_scale", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Scale" + }, + { + "completion": "none", + "description": "Dimension — click 2 points or an entity. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_dimension", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Dimension" + }, + { + "completion": "none", + "description": "Constrain the selected sketch entities to each other. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_constrain", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Constrain" + }, + { + "completion": "none", + "description": "Add dimensions and relations (coincident, tangent, parallel...) to the selected sketch. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only outside a sketch (sketch_commit or sketch_cancel ends one; while the tab constrains a sketch, its Confirm or Cancel button ends that).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "constrain", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Constrain sketch" + }, + { + "completion": "none", + "description": "Toggle construction: geometry that guides but is never built. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_construct", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Construction" + }, + { + "completion": "none", + "description": "Extend — click a line/arc to extend it. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_extend", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Extend" + }, + { + "completion": "none", + "description": "Delete the selected sketch entities. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Delete" + }, + { + "completion": "none", + "description": "Type the length of this line. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_length", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Length…" + }, + { + "completion": "none", + "description": "Type the radius of this arc, or the diameter of this circle. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_radius", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Radius / diameter…" + }, + { + "completion": "none", + "description": "Type the angle between two lines, or the distance between the two picks. It takes no arguments and does what the Design tab's menu row or key does, as a person's pick does: open a tool, start a sketch tool, or act at once. The reply's status is what the tab's status line shows then. It runs only in an open sketch (sketch_begin opens one).", + "destructive": false, + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "sk_angdist", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Angle / distance…" + }, + { + "completion": "none", + "description": "The Design document: features, variables with their values, bodies, undo_depth / redo_depth and generation. A feature's bound lists the fields an expression drives; a body gives bbox, source_feature, visible, color and moved (by the Move gizmo). selection is what the right-click menu would be built for: its kind, the selection_kind a tool's opening reply gives, and its id (none, face_planar, body_solid, sk_line and the like).", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": {}, + "tool": "describe_scene" + } + ], + "title": "An empty design" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": {}, + "tool": "describe_scene" + } + ], + "title": "A plate's two features and its body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "describe_scene", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Describe scene" + }, + { + "completion": "none", + "description": "One feature as its card shows it: params, the editable ones with their ranges, expr, refs, used_by and bodies_made. expr holds its bindings, and refs the feature and body indices and face and edge ids it uses; a sketch adds its plane, entities and constraints (angles in degrees). Imported Text or SVG art shows its regions (a count), region_loops (how many closed loops each region has, its outer loop plus its holes; counts, not the loops' geometry) and region_areas (each region's filled area in mm² as placed, its outer loop less its holes).", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "feature": 1 + }, + "tool": "describe_feature" + } + ], + "title": "A plate's extrude, with the fields its card edits" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "feature": 0 + }, + "tool": "describe_feature" + } + ], + "title": "A committed sketch's plane, entities and constraints" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "feature" + ], + "type": "object" + }, + "key": "describe_feature", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Describe feature" + }, + { + "completion": "none", + "description": "A body's faces and edges, with their kinds and geometry, narrowed by face and edge filters. Faces give kind, area, centroid, normal, and a cylinder's, cone's, sphere's or torus's numbers; edges give kind, length, ends, a circle's centre and radius. Face filters (kinds, direction, at_extreme) and edge filters (edge_kinds, direction, convex) narrow their own list; when filters are given, a list none of its filters names is empty, or with adjacency holds the neighbours of the other list. Reply: face_count and edge_count of the body, faces_total and edges_total after filtering, next_offset while a page has more, generation.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0 + }, + "tool": "query_topology" + } + ], + "title": "Every face and edge of a 20 x 20 x 5 mm plate" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + } + ], + "title": "A plate's top face" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "convex": true, + "direction": [ + 0, + 0, + 1 + ], + "edge_kinds": [ + "line" + ] + }, + "tool": "query_topology" + } + ], + "title": "A plate's vertical outside corners, the edges a fillet rounds" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "adjacency": { + "default": false, + "description": "faces list their edges; edges list their faces (one for a seam) and say convex true or false, or tangent where the faces meet smoothly", + "type": "boolean" + }, + "at_extreme": { + "default": null, + "description": "faces whose centroid lies on that side of the body's bounding box, e.g. +z for the top face", + "enum": [ + "+x", + "-x", + "+y", + "-y", + "+z", + "-z", + null + ], + "type": [ + "string", + "null" + ] + }, + "body": { + "default": 0, + "type": "integer" + }, + "convex": { + "default": null, + "description": "edges where two faces meet in an outside (true) or inside (false) corner; implies adjacency", + "type": [ + "boolean", + "null" + ] + }, + "direction": { + "default": null, + "description": "[x, y, z]: planar faces whose outward normal points this way, and line edges along it either way, within 1 degree", + "type": [ + "array", + "null" + ] + }, + "edge_kinds": { + "default": null, + "description": "edge kinds to list: line, circle, ellipse, bspline, bezier, other", + "type": [ + "array", + "null" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "kinds": { + "default": null, + "description": "face kinds to list: planar, cylindrical, conical, spherical, toroidal, bezier, bspline, revolution, extrusion, offset, other", + "type": [ + "array", + "null" + ] + }, + "limit": { + "default": null, + "description": "page size of both lists; omit for all", + "minimum": 1, + "type": [ + "integer", + "null" + ] + }, + "offset": { + "default": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "query_topology", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Query topology" + }, + { + "completion": "none", + "description": "Cross-section of a body by a base plane at an offset (sections-as-evidence). Returns ordered world contours, each flagged closed/open.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "offset": 2.5, + "plane": "XY" + }, + "tool": "slice_body" + } + ], + "title": "A plate's cross-section halfway up" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 5, + "sketch": 0 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "offset": 2.5, + "plane": "XY" + }, + "tool": "slice_body" + } + ], + "title": "The two contours through a plate with a bore" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "default": 0, + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "offset": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "plane": { + "default": "XY", + "enum": [ + "XY", + "XZ", + "YZ" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "slice_body", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Slice body" + }, + { + "completion": "none", + "description": "Compare a body with a reference: volume, bbox, centroid and surface deviation (the RE acceptance metric). The reference is {step:path|body:id}; the surface deviation is max/mean/rms in mm.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 6, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "reference": { + "body": 1 + } + }, + "tool": "validate_against" + } + ], + "title": "A 5 mm plate against a 6 mm one" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "reference": { + "step": "/path/to/reference.step" + } + }, + "tool": "validate_against" + } + ], + "needs": "a STEP file of the reference part", + "title": "A plate against a reference part's STEP file" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "default": 0, + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "reference": { + "type": "object" + } + }, + "required": [ + "reference" + ], + "type": "object" + }, + "key": "validate_against", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Validate against" + }, + { + "completion": "none", + "description": "The open sketch, or a committed one: entities, constraint count and its loops. The loops are closed_loops {index, entities, holes, area}, open_ends, defects, buildable. The open sketch adds dof, the armed tool, the selection (entity indices) and selected_constraint, the index of the constraint picked by its badge or the Constraints list, null for none; a committed one adds its name and plane.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_describe" + } + ], + "title": "The open sketch: a rectangle with a circle inside it as a hole" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "sketch_describe" + } + ], + "title": "A committed sketch's plane, entities and loop" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "sketch": { + "default": null, + "description": "a committed Sketch feature's index; omit for the open sketch", + "type": [ + "integer", + "null" + ] + } + }, + "type": "object" + }, + "key": "sketch_describe", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Sketch describe" + }, + { + "completion": "none", + "description": "The open sketch's loops (closed_loops, open_ends, defects, buildable) and dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 20, + 0 + ], + "type": "line" + }, + { + "p0": [ + 20, + 0.05 + ], + "p1": [ + 20, + 10 + ], + "type": "line" + }, + { + "p0": [ + 20, + 10 + ], + "p1": [ + 0, + 0 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_validate" + } + ], + "title": "A triangle with a 0.05 mm gap: two open ends, not buildable" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "tolerance": { + "default": 0.001, + "description": "reported back (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "sketch_validate", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Sketch validate" + }, + { + "completion": "none", + "description": "The constraints of the open sketch, or of a committed one: index, type, refs and value. A ref is {entity, role} for a point and {entity} for a whole entity; value is mm, or degrees for an angle. Reply: scope (live or committed), items, and dof and solve_ok for the open sketch.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_constraints" + } + ], + "title": "The coincident, horizontal and vertical constraints a drawn rectangle gets" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "sketch": 0 + }, + "tool": "sketch_constraints" + } + ], + "title": "A committed sketch's constraints" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "sketch": { + "default": null, + "description": "a committed Sketch feature's index; omit for the open sketch", + "type": [ + "integer", + "null" + ] + } + }, + "type": "object" + }, + "key": "sketch_constraints", + "listed": false, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Sketch constraints" + }, + { + "completion": "none", + "description": "Import a STEP file as native B-rep bodies (the reference part to measure). A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "path": "/path/to/part.step" + }, + "tool": "import_step" + } + ], + "needs": "a STEP file of the part", + "title": "A part read from a STEP file as a body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "path": { + "description": "absolute path", + "type": "string" + } + }, + "required": [ + "path" + ], + "type": "object" + }, + "key": "import_step", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Import step" + }, + { + "completion": "none", + "description": "Convert a triangle mesh (STL/OBJ) into an editable B-rep body. Reports whether the result is a real solid or an open shell, and why. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "path": "/path/to/part.stl" + }, + "tool": "import_mesh" + } + ], + "needs": "an STL or OBJ mesh file", + "title": "An STL mesh turned into an editable body" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "merge_angle_deg": { + "default": 5.0, + "type": "number" + }, + "path": { + "description": "absolute path", + "type": "string" + }, + "tolerance": { + "default": 0.01, + "type": "number" + } + }, + "required": [ + "path" + ], + "type": "object" + }, + "key": "import_mesh", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Import mesh" + }, + { + "completion": "none", + "description": "Drill a hole with optional counterbore (style=1) or countersink (style=2) at (x,y) or `at` on a plane. Reply as hole.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 10, + "height": 30, + "width": 30 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "cbore_depth": 6, + "cbore_diameter": 11, + "diameter": 6.6, + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + }, + "style": 1 + }, + "tool": "hole_styled" + } + ], + "title": "A counterbored hole for an M6 cap screw through a 10 mm block's top face" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "csink_angle": 90, + "csink_diameter": 9, + "diameter": 4.5, + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + }, + "style": 2 + }, + "tool": "hole_styled" + } + ], + "title": "A countersunk hole through a plate's top face" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "at": { + "default": null, + "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer", + "type": [ + "array", + "object", + "null" + ] + }, + "body": { + "default": -1, + "description": "the body to drill; omit for a face plane's body, else the last body", + "type": "integer" + }, + "cbore_depth": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "cbore_diameter": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "csink_angle": { + "default": 90, + "description": "In deg.", + "type": "number" + }, + "csink_diameter": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "depth": { + "default": 10, + "description": "In mm.", + "type": "number" + }, + "diameter": { + "default": 5, + "description": "In mm.", + "exclusiveMinimum": 0, + "type": "number" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "standard": { + "default": "", + "description": "provenance designation, e.g. M6", + "type": "string" + }, + "style": { + "default": 0, + "description": "0=simple, 1=counterbore, 2=countersink", + "type": "integer" + }, + "through": { + "default": true, + "type": "boolean" + }, + "x": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + }, + "y": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + } + }, + "type": "object" + }, + "key": "hole_styled", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Hole styled" + }, + { + "completion": "none", + "description": "Drill a standard clearance hole (ISO 273 / ANSI) at (x,y) or `at` on a plane. style: 0=simple, 1=counterbore, 2=countersink. Reply as hole.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "designation": "M5", + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + } + }, + "tool": "hole_standard" + } + ], + "title": "An M5 clearance hole through a plate's top face" + }, + { + "calls": [ + { + "args": { + "distance": 10, + "height": 30, + "width": 30 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "designation": "M6", + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + }, + "style": 1 + }, + "tool": "hole_standard" + } + ], + "title": "An M6 counterbored clearance hole through a 10 mm block's top face" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "at": { + "default": null, + "description": "instead of x and y: a world point [x, y, z], projected onto the plane along its normal (off_plane says how far), or {\"body\": b, \"face\": f} a cylindrical face or {\"body\": b, \"edge\": e} a circular edge whose axis the hole shares. A world point moves with modeling_origin; x and y replay on any printer", + "type": [ + "array", + "object", + "null" + ] + }, + "body": { + "default": -1, + "description": "the body to drill; omit for a face plane's body, else the last body", + "type": "integer" + }, + "depth": { + "default": 10, + "description": "In mm.", + "type": "number" + }, + "designation": { + "description": "e.g. M6, 1/4-20", + "type": "string" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face to drill into that body (origin at its centroid, normal into the body, x along its longest edge). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + }, + "style": { + "default": 0, + "type": "integer" + }, + "through": { + "default": true, + "type": "boolean" + }, + "x": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + }, + "y": { + "default": 0, + "description": "offset in the plane's frame from its origin, NOT world (mm)", + "type": "number" + } + }, + "required": [ + "designation" + ], + "type": "object" + }, + "key": "hole_standard", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Hole standard" + }, + { + "completion": "none", + "description": "Build a cubic-Bezier G1 bridge (BSpline) between two sketch-entity endpoints within a sketch feature. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + -20, + 0 + ], + "p1": [ + -5, + 0 + ], + "type": "line" + }, + { + "p0": [ + 5, + 10 + ], + "p1": [ + 20, + 10 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "end_a": 1, + "end_b": 0, + "ent_a": 0, + "ent_b": 1, + "sketch": 0 + }, + "tool": "bridge" + } + ], + "title": "A smooth curve joining the facing ends of two lines in a committed sketch" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "end_a": { + "default": 1, + "description": "0 = start/p0 side, 1 = end/p1 side", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "end_b": { + "default": 0, + "description": "0 = start/p0 side, 1 = end/p1 side", + "enum": [ + 0, + 1 + ], + "type": "integer" + }, + "ent_a": { + "description": "first entity index within the sketch", + "type": "integer" + }, + "ent_b": { + "description": "second entity index within the sketch", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "sketch": { + "description": "sketch feature index", + "type": "integer" + } + }, + "required": [ + "sketch", + "ent_a", + "ent_b" + ], + "type": "object" + }, + "key": "bridge", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Bridge" + }, + { + "completion": "none", + "description": "Set a design variable to an expression, or remove it with an empty expr. Feature fields bound with edit_feature follow it. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "expr": "20", + "name": "w" + }, + "tool": "set_variable" + } + ], + "title": "A variable w of 20" + }, + { + "calls": [ + { + "args": { + "expr": "20", + "name": "w" + }, + "tool": "set_variable" + }, + { + "args": { + "expr": "w / 2 + 3", + "name": "h" + }, + "tool": "set_variable" + } + ], + "title": "A variable worked out from another: h = w / 2 + 3, which is 13" + }, + { + "calls": [ + { + "args": { + "expr": "20", + "name": "w" + }, + "tool": "set_variable" + }, + { + "args": { + "expr": "", + "name": "w" + }, + "tool": "set_variable" + } + ], + "title": "A variable removed with an empty expression" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "expr": { + "description": "e.g. \"20\" or \"width / 2 + 3\"; \"\" removes the variable", + "type": "string" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "name": { + "type": "string" + } + }, + "required": [ + "name", + "expr" + ], + "type": "object" + }, + "key": "set_variable", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set variable" + }, + { + "completion": "none", + "description": "Change a feature's editable fields as its card's Confirm does when editing: one undo step and a rebuild. A field an expression drives is refused. Reply: changed {field: [old, new]}.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "feature": 1, + "fields": { + "distance": 15 + } + }, + "tool": "set_feature" + } + ], + "title": "A plate made 15 mm thick" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "feature": 2, + "fields": { + "hole_diameter": 8 + } + }, + "tool": "set_feature" + } + ], + "title": "A plate's hole widened from 5 to 8 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "fields": { + "description": "{field: value} from describe_feature's editable, e.g. {\"distance\": 15}: numbers within its ranges; mode new|union|subtract|intersect; extrude_end blind|symmetric|two_sided|through_all; shape rectangle|circle; xf_* vectors [x, y, z]", + "type": "object" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "feature", + "fields" + ], + "type": "object" + }, + "key": "set_feature", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set feature" + }, + { + "completion": "none", + "description": "Delete a feature as its tree row's Delete does; deleting a sketch also deletes the features built on it. One undo step. Later indices shift. Reply: removed (how many features went), features, bodies.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "feature": 2 + }, + "tool": "feature_delete" + } + ], + "title": "A plate's hole deleted" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + }, + { + "args": { + "distance": 5, + "sketch": 0 + }, + "tool": "extrude" + }, + { + "args": { + "feature": 0 + }, + "tool": "feature_delete" + } + ], + "title": "A committed sketch deleted, and the extrude built on it with it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "feature" + ], + "type": "object" + }, + "key": "feature_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Feature delete" + }, + { + "completion": "none", + "description": "Move a feature one place up or down the history, as Move up / Move down do. A feature cannot come before one it uses. One undo step. Reply: feature (its new index), from.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "base": "XY", + "offset": 20, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "delta": -1, + "feature": 2 + }, + "tool": "feature_move" + } + ], + "title": "A datum plane moved up the history, above the extrude before it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "delta": { + "description": "-1 up, 1 down", + "enum": [ + -1, + 1 + ], + "type": "integer" + }, + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "feature", + "delta" + ], + "type": "object" + }, + "key": "feature_move", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Feature move" + }, + { + "completion": "none", + "description": "Show or hide (suppress) a feature as its row's eye does. A hidden feature is left out of the rebuild and bodies may renumber. One undo step, none when it already was. Reply: enabled, changed, bodies.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "enabled": false, + "feature": 2 + }, + "tool": "feature_set_enabled" + } + ], + "title": "A plate's hole hidden: the plate rebuilds without it" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "diameter": 5, + "through": true + }, + "tool": "hole" + }, + { + "args": { + "enabled": false, + "feature": 2 + }, + "tool": "feature_set_enabled" + }, + { + "args": { + "enabled": true, + "feature": 2 + }, + "tool": "feature_set_enabled" + } + ], + "title": "A hidden hole shown again" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "enabled": { + "type": "boolean" + }, + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "feature", + "enabled" + ], + "type": "object" + }, + "key": "feature_set_enabled", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Feature set enabled" + }, + { + "completion": "none", + "description": "Rename a feature as F2 on its row does. Its own undo step. Reply: name, changed.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "feature": 1, + "name": "Base plate" + }, + "tool": "feature_rename" + } + ], + "title": "A plate's extrude renamed Base plate" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "feature": { + "description": "feature index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "name": { + "description": "trimmed; not empty", + "type": "string" + } + }, + "required": [ + "feature", + "name" + ], + "type": "object" + }, + "key": "feature_rename", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Feature rename" + }, + { + "completion": "none", + "description": "Rename, colour or show/hide a body, as its Bodies row and the Color button do; give one or more. Not in the undo history. The name and colour are saved with the project and the name names its committed object; visibility is view state, and commit leaves hidden bodies out. Reply: name, color, visible.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "body": 0, + "color": "#3366CC", + "name": "Base" + }, + "tool": "body_set" + } + ], + "title": "A plate's body named Base and coloured blue" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 20, + -5 + ], + [ + 30, + -5 + ], + [ + 30, + 5 + ], + [ + 20, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "body": 1, + "visible": false + }, + "tool": "body_set" + } + ], + "title": "The second of two bodies hidden" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "description": "body index (describe_scene)", + "type": "integer" + }, + "color": { + "default": null, + "description": "\"#RRGGBB\"", + "type": [ + "string", + "null" + ] + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "name": { + "default": null, + "description": "trimmed; not empty", + "type": [ + "string", + "null" + ] + }, + "visible": { + "default": null, + "type": [ + "boolean", + "null" + ] + } + }, + "required": [ + "body" + ], + "type": "object" + }, + "key": "body_set", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Body set" + }, + { + "completion": "none", + "description": "Delete a body as its row's Delete does: the feature that made it goes, which can take other features and bodies with it. One undo step. Reply: deleted_feature {index, type, name}, removed, features, bodies.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 20, + -5 + ], + [ + 30, + -5 + ], + [ + 30, + 5 + ], + [ + 20, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "body": 1 + }, + "tool": "body_delete" + } + ], + "title": "The second of two bodies deleted, with the extrude that made it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "body": { + "description": "body index (describe_scene)", + "type": "integer" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "body" + ], + "type": "object" + }, + "key": "body_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Body delete" + }, + { + "completion": "none", + "description": "Commit to Plate: send the visible bodies to Prepare at their Move-gizmo positions and show Prepare. It is one Prepare undo step. A lone body is sent even when hidden. A body named in the Bodies list or with body_set names its object or part. Reply: objects (list_objects index after replace, name, parts: how many), bodies_sent, bodies_hidden, replaced.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": {}, + "tool": "commit" + } + ], + "title": "A plate sent to Prepare as one object" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "boolean": "new", + "distance": 10, + "profile": [ + [ + 20, + -5 + ], + [ + 30, + -5 + ], + [ + 30, + 5 + ], + [ + 20, + 5 + ] + ] + }, + "tool": "extrude" + }, + { + "args": { + "mode": "bodies" + }, + "tool": "commit" + } + ], + "title": "Two bodies sent to Prepare as an object each" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "mode": { + "default": "", + "description": "assembly: one object with a part per body; bodies: an object per body. Default: the Commit button's mode, which this leaves as it is.", + "enum": [ + "assembly", + "bodies" + ], + "type": "string" + }, + "replace": { + "default": [], + "description": "list_objects indices to delete in the same undo step, such as an earlier commit. Their settings, modifiers and paint go with them.", + "type": "array" + } + }, + "type": "object" + }, + "key": "commit", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Commit" + }, + { + "completion": "none", + "description": "New Design: erase every feature, body and variable and the Design undo history. Committed objects stay on the plate. Reply: cleared {features, bodies, variables}.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "discard_changes": true + }, + "tool": "new_design" + } + ], + "title": "A plate's design erased" + }, + { + "calls": [ + { + "args": {}, + "tool": "new_design" + } + ], + "title": "An empty design started over, which needs no discard_changes" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "discard_changes": { + "default": false, + "description": "needed when the design is not empty", + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "new_design", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "New design" + }, + { + "completion": "none", + "description": "Export STEP: write every body to a file as native B-rep, at its Move-gizmo position. Reply: path, bytes, bodies, moved_bodies.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "path": "/path/to/part.step" + }, + "tool": "export_step" + } + ], + "needs": "a folder to write the STEP file in", + "title": "A plate written to a STEP file" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "overwrite": { + "default": false, + "description": "replace an existing file", + "type": "boolean" + }, + "path": { + "description": "absolute path; its directory must exist", + "type": "string" + } + }, + "required": [ + "path" + ], + "type": "object" + }, + "key": "export_step", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Export step" + }, + { + "completion": "none", + "description": "Open a sketch session on a plane, as picking a plane or face for Sketch does. Sketch points are [x, y] in that plane's frame (mm), from its origin: modeling_origin for a base plane. Reply: frame.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + } + ], + "title": "A sketch on the XY plane" + }, + { + "calls": [ + { + "args": { + "distance": 5, + "height": 20, + "width": 20 + }, + "tool": "extrude" + }, + { + "args": { + "at_extreme": "+z", + "body": 0 + }, + "tool": "query_topology" + }, + { + "args": { + "generation": { + "from_call": 1, + "key": "generation" + }, + "plane": { + "body": 0, + "face": 5 + } + }, + "tool": "sketch_begin" + } + ], + "title": "A sketch on a plate's top face" + }, + { + "calls": [ + { + "args": { + "base": "XY", + "offset": 20, + "type": "offset" + }, + "tool": "plane" + }, + { + "args": { + "plane": { + "datum": 0 + } + }, + "tool": "sketch_begin" + } + ], + "title": "A sketch on a datum plane 20 mm above XY" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "plane": { + "default": "XY", + "description": "\"XY\", \"XZ\" or \"YZ\" through modeling_origin; {\"datum\": i}, a Plane feature; or {\"body\": b, \"face\": f}, a planar face (origin at its centroid, normal out of the body, x from the world axes). The reply's frame gives the axes.", + "type": [ + "string", + "object" + ] + } + }, + "type": "object" + }, + "key": "sketch_begin", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch begin" + }, + { + "completion": "none", + "description": "Commit the open sketch as a Sketch feature, as the sketch's Confirm does, and leave sketch mode. An empty sketch is refused and stays open. Reply: sketch_index, name, features (the new count) and its loops (closed_loops with the index extrude's loop takes, open_ends, defects, buildable).", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_commit" + } + ], + "title": "A rectangle around a circle, committed as a sketch of two loops" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_commit", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch commit" + }, + { + "completion": "none", + "description": "Discard the open sketch and leave sketch mode.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_cancel" + } + ], + "title": "Discard a sketch with a rectangle drawn" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_cancel", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch cancel" + }, + { + "completion": "none", + "description": "Add entities or shapes to the open sketch: `entities` (a list), or one item's fields beside `type`, or `rect`. Entities: line {p0, p1}, circle {center, radius}, arc {center, radius, start_angle, end_angle}, point {p}. Shapes, built as their drawing tools build them: polygon {center, sides, radius (to a vertex) or across_flats, angle (of that vertex, or of the first edge's midpoint)}, slot {c0, c1, width}, ellipse {center, radius (semi-major), rminor, rotation}, ellipse_arc {the ellipse's fields, start_angle, end_angle: parametric, counter-clockwise}, spline {ctrl: 2 or more poles}. Each item of entities may carry its own construction: true; the top-level construction applies only to rect and to the single-type form. Points are [x, y] in the sketch plane (mm); angles are radians, or degrees as start_angle_deg and the like. A polygon is lines; its side count is not kept once committed. Reply: first_index, added, shapes [{first, count}] per item, entities, dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + } + ], + "title": "A 30 x 20 mm rectangle" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 12, + "type": "circle" + }, + { + "across_flats": 10, + "center": [ + 0, + 0 + ], + "sides": 6, + "type": "polygon" + } + ] + }, + "tool": "sketch_add" + } + ], + "title": "A hexagon 10 mm across flats inside a circle" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "end_angle_deg": 90, + "radius": 20, + "start_angle_deg": 0, + "type": "arc" + }, + { + "c0": [ + -10, + -20 + ], + "c1": [ + 10, + -20 + ], + "type": "slot", + "width": 6 + } + ] + }, + "tool": "sketch_add" + } + ], + "title": "A quarter arc given in degrees, and a slot" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "construction": { + "default": false, + "description": "for rect and the single-type form; an item of entities carries its own", + "type": "boolean" + }, + "end_angle": { + "default": 0, + "description": "In rad.", + "type": "number" + }, + "entities": { + "default": [], + "description": "entity or shape objects, each with a type", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "rect": { + "default": [], + "description": "[x0, y0, x1, y1]: a closed rectangle of four lines", + "type": "array" + }, + "start_angle": { + "default": 0, + "description": "arc start, counter-clockwise from the plane's x axis (rad)", + "type": "number" + }, + "type": { + "default": "", + "description": "one item, its fields beside it", + "enum": [ + "line", + "arc", + "circle", + "point", + "polygon", + "slot", + "ellipse", + "ellipse_arc", + "spline" + ], + "type": "string" + } + }, + "type": "object" + }, + "key": "sketch_add", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch add" + }, + { + "completion": "none", + "description": "Select sketch entities by index; an empty list clears the selection. Reply: selected.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0, + 2 + ] + }, + "tool": "sketch_select" + } + ], + "title": "Select a rectangle's two long sides" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0 + ] + }, + "tool": "sketch_select" + }, + { + "args": { + "entities": [] + }, + "tool": "sketch_select" + } + ], + "title": "Clear the selection" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "entities": { + "default": [], + "description": "entity indices", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_select", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch select" + }, + { + "completion": "none", + "description": "Delete sketch entities. Reply: removed, entities.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 2 + ] + }, + "tool": "sketch_delete" + } + ], + "title": "Delete a rectangle's top side" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 1, + 3 + ] + }, + "tool": "sketch_select" + }, + { + "args": {}, + "tool": "sketch_delete" + } + ], + "title": "Delete the selected sides" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "entities": { + "default": [], + "description": "entity indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_delete", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch delete" + }, + { + "completion": "none", + "description": "Toggle construction on sketch entities. Reply: changed. A rejected rebuild is reported in the reply: ok is false or error is not empty.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + -10 + ], + "p1": [ + 0, + 10 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 4 + ] + }, + "tool": "sketch_construction" + } + ], + "title": "A centre line across a rectangle, made construction so it splits no loop" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "entities": { + "default": [], + "description": "entity indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_construction", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch construction" + }, + { + "completion": "none", + "description": "Add an offset copy of sketch lines, arcs and circles. Reply: first_index, added, dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "distance": 2 + }, + "tool": "sketch_offset" + } + ], + "title": "A rectangle's 2 mm inner wall" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 5, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "distance": -2, + "entities": [ + 0 + ] + }, + "tool": "sketch_offset" + } + ], + "title": "A circle grown 2 mm by a negative offset" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "distance": { + "description": "signed offset (mm)", + "type": "number" + }, + "entities": { + "default": [], + "description": "entity indices; omit for the selection, else every entity", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "distance" + ], + "type": "object" + }, + "key": "sketch_offset", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch offset" + }, + { + "completion": "none", + "description": "Add a mirrored copy of sketch entities about the line through axis_a and axis_b. Reply: first_index, added, dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 10, + 0 + ], + "radius": 3, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "axis_a": [ + 0, + 0 + ], + "axis_b": [ + 0, + 1 + ] + }, + "tool": "sketch_mirror" + } + ], + "title": "A circle mirrored across the sketch's y axis" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "axis_a": { + "default": [ + 0, + 0 + ], + "description": "[x, y] in the sketch plane, mm", + "type": "array" + }, + "axis_b": { + "default": [ + 0, + 1 + ], + "description": "[x, y] in the sketch plane, mm", + "type": "array" + }, + "entities": { + "default": [], + "description": "entity indices; omit for the selection, else every entity", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "sketch_mirror", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch mirror" + }, + { + "completion": "none", + "description": "Weld sketch endpoints that nearly meet and constrain them coincident, so loops are closed by construction. Reply: welded and the loops.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 20, + 0 + ], + "type": "line" + }, + { + "p0": [ + 20, + 0.05 + ], + "p1": [ + 20, + 10 + ], + "type": "line" + }, + { + "p0": [ + 20, + 10 + ], + "p1": [ + 0, + 0 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "tolerance": 0.1 + }, + "tool": "sketch_heal" + } + ], + "title": "Close a triangle's 0.05 mm gap" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "ignore_construction": { + "default": true, + "type": "boolean" + }, + "tolerance": { + "default": 0.001, + "description": "In mm.", + "type": "number" + } + }, + "type": "object" + }, + "key": "sketch_heal", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch heal" + }, + { + "completion": "none", + "description": "Set the dimension of the selected sketch entities, as the value field does. A line's length, a circle's diameter, an arc's radius, or the angle or distance between two. Select them with sketch_select first. Reply: kind, before, value, dof and the loops.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0 + ] + }, + "tool": "sketch_select" + }, + { + "args": { + "value": 40 + }, + "tool": "sketch_set_value" + } + ], + "title": "A rectangle's bottom side made 40 mm long" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0 + ] + }, + "tool": "sketch_select" + }, + { + "args": { + "value": 12 + }, + "tool": "sketch_set_value" + } + ], + "title": "A circle's diameter set to 12 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "value": { + "description": "mm, or degrees for an angle", + "type": "number" + } + }, + "required": [ + "value" + ], + "type": "object" + }, + "key": "sketch_set_value", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch set value" + }, + { + "completion": "none", + "description": "Round the corner of two lines of the open sketch, as the Fillet tool does. Both lines are cut back and joined by an arc of `radius`, bound coincident and tangent to them; constraints the sharp corner held are released. Reply: entity (the arc), lines, released_constraints, entities, constraints, dof, solve_ok.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0, + 1 + ], + "radius": 3 + }, + "tool": "sketch_fillet" + } + ], + "title": "A rectangle's corner rounded to 3 mm" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "entities": { + "default": [], + "description": "the two line indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "radius": { + "description": "In mm.", + "type": "number" + } + }, + "required": [ + "radius" + ], + "type": "object" + }, + "key": "sketch_fillet", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch fillet" + }, + { + "completion": "none", + "description": "Bevel the corner of two lines of the open sketch, as the Chamfer tool does. Both lines are cut back by `distance` from the corner and joined by a line bound coincident to them. Reply: entity (the new line), lines, released_constraints, entities, constraints, dof, solve_ok.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "distance": 2, + "entities": [ + 1, + 2 + ] + }, + "tool": "sketch_chamfer" + } + ], + "title": "A rectangle's corner bevelled 2 mm back" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "distance": { + "description": "setback along each line (mm)", + "type": "number" + }, + "entities": { + "default": [], + "description": "the two line indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + } + }, + "required": [ + "distance" + ], + "type": "object" + }, + "key": "sketch_chamfer", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch chamfer" + }, + { + "completion": "none", + "description": "Trim or extend the open sketch's entity nearest `at`, as a Trim or Extend click there does. Trim: a line or an arc is cut back from its end nearer `at` to the first crossing with another entity beyond `at`; a circle loses the part between the crossings either side of `at` and becomes an arc. With extend, as an Extend click: the line's or arc's end nearer `at` runs out to the next entity. The entity's constraints are released. Reply: entity, geometry (its new fields), released_constraints, entities, dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + -10, + 0 + ], + "p1": [ + 10, + 0 + ], + "type": "line" + }, + { + "p0": [ + 0, + -5 + ], + "p1": [ + 0, + 5 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "at": [ + 5, + 0 + ] + }, + "tool": "sketch_trim" + } + ], + "title": "A line cut back to the line crossing it" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + -10, + 0 + ], + "p1": [ + 10, + 0 + ], + "type": "line" + }, + { + "p0": [ + 0, + 3 + ], + "p1": [ + 0, + 8 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "at": [ + 0, + 3 + ], + "extend": true + }, + "tool": "sketch_trim" + } + ], + "title": "A line extended down to the line below it" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "at": { + "description": "[x, y] in the sketch plane, mm: a point on the part to cut, or near the end to extend", + "type": "array" + }, + "extend": { + "default": false, + "type": "boolean" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "tolerance": { + "default": 0.05, + "description": "how far from `at` the entity may be (mm)", + "type": "number" + } + }, + "required": [ + "at" + ], + "type": "object" + }, + "key": "sketch_trim", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch trim" + }, + { + "completion": "none", + "description": "Move, rotate, scale or array entities of the open sketch, as the transform tools' Confirm does. move {dx, dy}, rotate {angle, pivot} and scale {scale, pivot} change the entities and release the constraints that no longer hold. array {dx, dy, count} adds copies stepped by dx, dy; polar_array {pivot, angle, count} adds copies every angle/count about pivot (angle is the whole sweep, default 360 degrees). count includes the original, and each copy is bound to its source (equal length and parallel, or its radius). pivot defaults to the entities' centroid. Angles are radians, or degrees as angle_deg. Reply: moved and released_constraints, or first_index, added and bound; pivot; entities, dof.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 3, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "dx": 10, + "entities": [ + 0 + ], + "op": "move" + }, + "tool": "sketch_transform" + } + ], + "title": "A circle moved 10 mm along x" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 20, + 0 + ], + "radius": 3, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "angle_deg": 360, + "count": 6, + "entities": [ + 0 + ], + "op": "polar_array", + "pivot": [ + 0, + 0 + ] + }, + "tool": "sketch_transform" + } + ], + "title": "Six holes on a 40 mm bolt circle" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 20, + 0 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "angle_deg": 30, + "entities": [ + 0 + ], + "op": "rotate", + "pivot": [ + 0, + 0 + ] + }, + "tool": "sketch_transform" + } + ], + "title": "A line turned 30 degrees about its start" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "angle": { + "default": null, + "description": "or angle_deg (rad)", + "type": "number" + }, + "count": { + "default": null, + "maximum": 1000, + "minimum": 2, + "type": "integer" + }, + "dx": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "dy": { + "default": 0, + "description": "In mm.", + "type": "number" + }, + "entities": { + "default": [], + "description": "entity indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "op": { + "enum": [ + "move", + "rotate", + "scale", + "array", + "polar_array" + ], + "type": "string" + }, + "pivot": { + "default": null, + "description": "[x, y] in the sketch plane, mm", + "type": "array" + }, + "scale": { + "default": null, + "type": "number" + } + }, + "required": [ + "op" + ], + "type": "object" + }, + "key": "sketch_transform", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch transform" + }, + { + "completion": "none", + "description": "Add a constraint to the open sketch, as a CONSTRAIN bar button does (sketch_set_value is the value field, V). With `entities`, else the selection, the button's own rules choose the points, and a value it would ask for is `value` or the current one. With `refs` the references are taken as written, in sketch_constraints' form: {entity, role} for a point (role p0, p1 or center; entity also \"origin\") and {entity} for a whole entity (also \"x_axis\", \"y_axis\"). distance, lock_x, lock_y, point_on_line and point_on_object have no button and take refs. A constraint the sketch cannot solve with is rolled back and the call fails. Reply: added (indices), items, constraints, dof, solve_ok.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 10, + 2 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0 + ], + "type": "horizontal" + }, + "tool": "sketch_constrain" + } + ], + "title": "A sloping line made horizontal" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "center": [ + 0, + 0 + ], + "radius": 4, + "type": "circle" + }, + { + "center": [ + 15, + 0 + ], + "radius": 6, + "type": "circle" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "entities": [ + 0, + 1 + ], + "type": "equal" + }, + "tool": "sketch_constrain" + } + ], + "title": "Two circles given equal radii" + }, + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "entities": [ + { + "p0": [ + 0, + 0 + ], + "p1": [ + 10, + 2 + ], + "type": "line" + } + ] + }, + "tool": "sketch_add" + }, + { + "args": { + "refs": [ + { + "entity": 0, + "role": "p0" + }, + { + "entity": 0, + "role": "p1" + } + ], + "type": "distance", + "value": 25 + }, + "tool": "sketch_constrain" + } + ], + "title": "A line's ends held 25 mm apart, named by refs" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "entities": { + "default": [], + "description": "1 to 3 entity indices; omit for the selection", + "type": "array" + }, + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "refs": { + "default": [], + "description": "[{entity, role?}], instead of entities", + "type": "array" + }, + "type": { + "description": "\"equal\" is the Equal button: equal length, or equal radius for two curves", + "enum": [ + "fix", + "coincident", + "horizontal", + "vertical", + "distance", + "lock_x", + "lock_y", + "equal_length", + "parallel", + "perpendicular", + "concentric", + "tangent", + "midpoint", + "symmetric", + "angle", + "radius", + "diameter", + "point_on_line", + "point_on_object", + "equal_radius", + "collinear", + "distance_x", + "distance_y", + "symmetric_about_y", + "symmetric_about_x", + "equal" + ], + "type": "string" + }, + "value": { + "default": null, + "description": "mm, or degrees for an angle", + "type": [ + "number", + "null" + ] + } + }, + "required": [ + "type" + ], + "type": "object" + }, + "key": "sketch_constrain", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch constrain" + }, + { + "completion": "none", + "description": "Delete a constraint of the open sketch, as its row's delete button does; the constraints after it move down one index. Reply: removed, constraints, dof, solve_ok.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": { + "plane": "XY" + }, + "tool": "sketch_begin" + }, + { + "args": { + "rect": [ + -15, + -10, + 15, + 10 + ] + }, + "tool": "sketch_add" + }, + { + "args": {}, + "tool": "sketch_constraints" + }, + { + "args": { + "index": 4 + }, + "tool": "sketch_unconstrain" + } + ], + "title": "A rectangle's bottom side freed from horizontal" + } + ], + "group": "Design", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "properties": { + "generation": { + "description": "The generation (describe_scene, query_topology) the face and edge ids this call passes were read at. Ids expire when a feature rebuilds the model, and a stale id still names a real face or edge: with the generation, a call whose ids were read before the model changed is refused.", + "minimum": 0, + "type": "integer" + }, + "index": { + "description": "sketch_constraints' items[].index", + "type": "integer" + } + }, + "required": [ + "index" + ], + "type": "object" + }, + "key": "sketch_unconstrain", + "listed": false, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Sketch unconstrain" + }, + { + "completion": "none", + "description": "Search everything the Speed Dial can run: built-in commands (slice, export, views, object operations, plates, calibration wizards, help), recent projects, plugin scripts and pages. Each entry has an id for run_action, a description, the command's key for a built-in command, and, when it takes arguments, their input_schema. A query ranks them, best match first, as search_tools does; without one they are listed by group and title. include_settings also lists settings (each jumps to that setting in the sidebar; use get_settings / set_settings to read or change values).", + "destructive": false, + "group": "ui", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "group": { + "description": "Only this group, e.g. \"Object\", \"View\", \"Slice & Export\".", + "type": "string" + }, + "include_settings": { + "description": "Also list settings (thousands). Default false.", + "type": "boolean" + }, + "limit": { + "description": "Default 50.", + "maximum": 200, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + }, + "query": { + "description": "A few words, e.g. \"delete object\": each is matched at the start of the words of an action's id, title, group and description.", + "type": "string" + } + }, + "type": "object" + }, + "key": "search_actions", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Search Speed Dial actions" + }, + { + "completion": "none", + "description": "Run one action by the id search_actions returned (orca_command:view_front:orca, or the name inside it, view_front), with args, the command's arguments, when it takes some (its input_schema). A command that asks in a dialog asks when it is given no args, as a person's pick does, and runs without asking when given them: an absolute path skips a file dialog, and an output needs {\"path\": ..., \"overwrite\": true} to replace a file. Go to layer and Go to tab need their value ({\"percent\": 50}, {\"tab\": \"preview\"}). Actions that open a dialog return blocked_by_dialog; answer it with answer_dialog, or, for a native one it can't press (a file picker), register auto_answer_dialogs before the call. An export_gcode with a path completes when the file is written; an action that starts a background job (obj_arrange, obj_orient) when the job ends. An action that does nothing (no object selected) is an error. Some commands add what they did to the reply (the obj_order_by_* order, the object obj_assemble made).", + "destructive": false, + "group": "ui", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "args": { + "description": "The command's arguments, as its input_schema gives them.", + "type": "object" + }, + "id": { + "description": "Action id from search_actions, or the name inside it.", + "type": "string" + } + }, + "required": [ + "id" + ], + "type": "object" + }, + "key": "run_action", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Run a Speed Dial action" + }, + { + "completion": "none", + "description": "List OrcaSlicer's open windows: the main window, then the windows that don't block the app (Plugins, an object's settings, a dock panel floating on its own), then the modal dialogs in the order they opened, the topmost last. A window's ref goes to screenshot as target to capture that window, to list_widgets as target to list it alone, and to press_keys as target; its title is the within of locators for its widgets.\nReply: each window's title, kind (main, window, dialog, or panel: a dock panel floating on its own), modal, ref, web (it shows a web page), x and y on screen (not on Wayland, which doesn't say), width and height, state (normal, maximized or minimized) and resizable (it has a resize border); set_window changes them.\nA native dialog (a message box, a file picker) has native: true and no ref: answer_dialog answers it. hidden: true marks the person's own windows (Action Replay, the Run Script panel and their prompts, the Python scripts setting), which no tool reaches and screenshots leave out.", + "destructive": false, + "group": "ui", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "limit": { + "description": "Default 100.", + "maximum": 200, + "minimum": 1, + "type": "integer" + }, + "offset": { + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "key": "list_windows", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "List the windows" + }, + { + "completion": "none", + "description": "Size, move, maximize, minimize or raise a window: the main window (default), the topmost modal dialog, or one list_windows lists, also while a modal dialog is open. Size the main window before set_view fits the camera and before start_recording, as a recording keeps its first frame's size. size and position are in the units list_windows reports, whose x/y and width/height are read as position and size too. A size or position restores a maximized or minimized window first. A window takes only the states its title bar offers; a modal dialog never minimizes. A refused call changes nothing. Replies once the window holds still and the 3D view has drawn at its new size (3 s at most): title, kind, ref, size, position, state, resizable, scale (screenshot pixels per window unit), display (its work area), active with raise, and adjusted with a note: what the OS or a size limit changed.", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "position": { + "description": "[x, y] of the window's top-left corner on screen; not on Wayland.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "raise": { + "description": "Bring the window in front of the app's other windows; active in the reply says whether it became the active one.", + "type": "boolean" + }, + "size": { + "description": "[width, height], held to the window's minimum and maximum size.", + "items": { + "type": "integer" + }, + "type": "array" + }, + "state": { + "description": "normal restores a maximized or minimized window; maximized and minimized take no size or position.", + "enum": [ + "normal", + "maximized", + "minimized" + ], + "type": "string" + }, + "target": { + "description": "main (default), dialog (the topmost modal dialog), or a window's ref or locator from list_windows; a widget's ref or locator picks the window it is in.", + "type": [ + "string", + "object" + ] + } + }, + "type": "object" + }, + "key": "set_window", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Size or move a window" + }, + { + "completion": "none", + "description": "Describe what is on screen as an indented tree, one element per line with a ref to pass to click, set_widget_value, press_keys and run_javascript (a page element's to mouse_gesture too): the widgets of every shown window, the rows of lists, trees and tables, each shown popup after the window it opened from, the main menus, the 3D canvas's toolbar items and gizmos, each ImGui panel drawn in the last frame with its items and text, and the elements of each shown web page (dialogs, the setup wizard, sign-in, plugin windows) under its web view. With a modal dialog open, only the topmost dialog's pages are read. Refs go stale when their element goes away: call list_widgets again then. Prefer run_action and the typed tools when one fits.\nA locator names an element without a ref, in any session (export_replay records them); index (0-based) picks one of several matches:\n- a widget: {label, class, name, within, index}, within being its window's title; a notebook page: {tab: \"General\", within}\n- a setting's field: {option: \"layer_height\"}\n- {menu: \"File>Export>Export G-code\"}, {gltoolbar: \"arrange\"}, {gizmo: \"Move\"}\n- an ImGui item: {imgui: \"label\", imgui_name?: \"name\", window?, canvas?, index?}, by its label, its name or both\n- a row of a list, tree, table or drop-down list: {row: \"Plate 1>Cube>Cylinder\", column?, within?, index?}, by its last labels; column names the cell to act on\n- a plate or one of its icons in the Prepare view: {plate_icon: \"lock\", plate: 0}, the icon being plate, delete, orient, arrange, lock, settings, name, move_to_front, filament_map or imex_mode\n- a web page's element: {web: \"Next\", kind?: \"button\", css?: \"#AcceptBtn\", within?, index?}, by the label list_widgets lists (exactly, else ignoring case, else a part of it), its kind, a CSS selector (the id a line shows as name: name=#save is {css: \"#save\"}), or together. Without within it looks in the topmost dialog's pages while one is open, else in every shown page, and it waits up to 3 s for its element.", + "destructive": false, + "group": "ui", + "guard": "inspect", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "include_imgui": { + "description": "List ImGui items (default true).", + "type": "boolean" + }, + "include_menus": { + "description": "List menu items (default true).", + "type": "boolean" + }, + "include_web": { + "description": "List the elements of web pages (default true).", + "type": "boolean" + }, + "max_nodes": { + "description": "Default 400.", + "maximum": 5000, + "minimum": 1, + "type": "integer" + }, + "max_web_nodes": { + "description": "Page elements, apart from max_nodes; default 300.", + "maximum": 5000, + "minimum": 1, + "type": "integer" + }, + "query": { + "description": "Case-insensitive text to look for in labels, values, names and classes.", + "type": "string" + }, + "target": { + "description": "all (default), main, dialog (the topmost modal), popup, or a window's ref (list_windows).", + "type": "string" + } + }, + "type": "object" + }, + "key": "list_widgets", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "List the widgets" + }, + { + "completion": "none", + "description": "Click a GUI element as a person would. Menu items, buttons, checkboxes, toggles, radio buttons, toolbar items and gizmos are activated the way their owners expect: a gizmo opens and a second click closes it (Text on an object without text creates a text part: created). Other widgets and ImGui items get a mouse click once scrolled into view; with x/y, at that point of a 3D canvas or custom-drawn widget, in logical pixels from its top left. A row is selected as a click on its cell selects it (ctrl adds, shift extends; in the object list the named column acts, as Printable toggles), double activates it and a right click opens its menu; a drop-down list's row is picked. A plate icon does what it does in the Prepare view: lock replies locked, arrange and orient reply done once their job ends, settings and filament_map list the dialog they open (dialogs). Modifiers reach the 3D canvas, the object list and handlers that read them. A menu the click opens is never shown: the reply lists it as popup_menu, or popup_item runs one of its items (ran). A click that opens a dialog replies blocked_by_dialog.\nA web page's element gets the pointer and mouse events of a click at its centre (or x/y) once scrolled into view, refused when something else covers that point. The reply reads back checked, and has closed when the click closed its dialog (with dialogs, those still open under it, which still need an answer), navigated (with url) when it changed the page, or dialogs when it opened another. Otherwise page says what changed on the page within 300 ms: changed (false when its lines are as before), the list_widgets lines added and removed, partial when a plugin configuration frame could not be compared, and posted, how many messages the page sent OrcaSlicer.", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "button": { + "description": "Default left.", + "enum": [ + "left", + "right", + "middle" + ], + "type": "string" + }, + "double": { + "description": "Double click.", + "type": "boolean" + }, + "modifiers": { + "description": "Modifier keys held during the click, as in press_keys: ctrl and cmd are both Command on macOS and Ctrl elsewhere; rawctrl is the macOS Control key.", + "items": { + "enum": [ + "ctrl", + "cmd", + "rawctrl", + "shift", + "alt" + ], + "type": "string" + }, + "type": "array" + }, + "popup_item": { + "description": "Run this item of the menu the input opens (a right click's context menu, a button's menu), by its label path, \"Add Modifier>Cylinder\"; \"#2\" picks a repeated label's second item. Without it, such a menu is listed in the reply (popup_menu), not shown.", + "type": "string" + }, + "target": { + "description": "A ref from the latest list_widgets call (\"w12\") or a locator, such as {label: \"OK\", within: \"Preferences\"} or {menu: \"File>Export>Export G-code\"}; list_widgets's description lists every kind.", + "type": [ + "string", + "object" + ] + }, + "timeout_s": { + "description": "For a web page's element: seconds the page gets to answer (default 10).", + "maximum": 120, + "minimum": 1, + "type": "integer" + }, + "x": { + "description": "x of the point to click, in a 3D canvas, a custom-drawn widget or a page element.", + "type": "integer" + }, + "y": { + "description": "y of the point to click.", + "type": "integer" + } + }, + "required": [ + "target" + ], + "type": "object" + }, + "key": "click", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Click an element" + }, + { + "completion": "none", + "description": "Set a widget's value and send the events a person's edit would. Widgets: text fields (submit, the default, also presses Enter and leaves the field, which is when Orca's setting fields commit), spin controls, sliders, choice, combo and list boxes (by option text or index), checkboxes, toggles and a row's checkbox (true or false), and a radio button (an Orca radio box too) or a selector's option, as the dialog message shows them (*) / ( ) (true selects it; false on the selected one is refused, as only selecting another unselects it). ImGui items, by their kind, with the value read back: a field is typed into (a slider through the number field beside it, multiline text with \\n), a combo's option is picked by its text or 0-based index, and a checkbox, radio or toggle is clicked when it differs. A web page's fields, as typing would leave them: text, number, range, colour and date fields and editable text get the value with input and change events (submit then leaves the field; press_keys Return presses Enter), a select its option by text, value or index, and a checkbox or radio is clicked when it differs; the value is read back and page says what changed, as for click. File fields can't be set. For settings, set_settings is more reliable.", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "submit": { + "description": "Press Enter / commit after setting (default true).", + "type": "boolean" + }, + "target": { + "description": "A ref from the latest list_widgets call (\"w12\") or a locator, such as {label: \"OK\", within: \"Preferences\"} or {menu: \"File>Export>Export G-code\"}; list_widgets's description lists every kind.", + "type": [ + "string", + "object" + ] + }, + "timeout_s": { + "description": "For a web page's element: seconds the page gets to answer (default 10).", + "maximum": 120, + "minimum": 1, + "type": "integer" + }, + "value": { + "description": "The new value.", + "type": [ + "string", + "number", + "boolean" + ] + } + }, + "required": [ + "target", + "value" + ], + "type": "object" + }, + "key": "set_widget_value", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Set a widget's value" + }, + { + "completion": "none", + "description": "Send a key chord (\"Ctrl+S\", \"Escape\", \"Return\", \"Delete\", \"Shift+Tab\", \"Left\", \"F5\") and/or type text to a target or, without one, to the focused window (the topmost dialog while one is open, the shown 3D view when nothing has focus). As with a real key press, the shortcut handling of the target's panels and window sees the keys first. Typing reaches ImGui fields and key handlers; fill a widget's text field with set_widget_value. A menu the keys open is listed as popup_menu, or popup_item runs one of its items. Keys for a web page (its element, or without a target the focused web view or the topmost dialog's only page) go to the page's focused element with the browser's default actions: typing, Backspace/Delete, Enter (submits a form, activates a button), Space, Tab moving the focus, arrows stepping a select, range or radio group; page says what they changed, as for click.", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "keys": { + "description": "Key chord.", + "type": "string" + }, + "popup_item": { + "description": "Run this item of the menu the input opens (a right click's context menu, a button's menu), by its label path, \"Add Modifier>Cylinder\"; \"#2\" picks a repeated label's second item. Without it, such a menu is listed in the reply (popup_menu), not shown.", + "type": "string" + }, + "target": { + "description": "A ref from the latest list_widgets call (\"w12\") or a locator, such as {label: \"OK\", within: \"Preferences\"} or {menu: \"File>Export>Export G-code\"}; list_widgets's description lists every kind.", + "type": [ + "string", + "object" + ] + }, + "text": { + "description": "Characters to type.", + "type": "string" + }, + "timeout_s": { + "description": "For a web page's element: seconds the page gets to answer (default 10).", + "maximum": 120, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "key": "press_keys", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Press keys" + }, + { + "completion": "none", + "description": "Make a mouse gesture on a 3D canvas as a person would: move, down, up, click, drag or wheel. It starts at `at`, a point of the model, which is projected through the camera and by default checked to land on that part (check \"point\" only projects it), or at x/y, logical pixels from the canvas's top left. A drag goes through `waypoints` to `to`, `steps` moves per leg: on an object it moves the object, in a painting gizmo it paints from a press on the object being painted (waypoints zigzagging over an area paint all of it), and elsewhere it turns or pans the camera as this install's mouse settings say, so turn the camera with set_view camera or orbit instead. A wheel turns delta notches; positive zooms in or scrolls a panel up. Modifiers are held as keys for the gesture (shift for Measure's point picking, alt for erasing). A down keeps its button and modifiers held, so moves drag, until an up or another gesture. Grabbers are set through the gizmo's panel fields or transform, not dragged. A menu a right click opens is listed as popup_menu, or popup_item (with click or up) runs one of its items. The reply's camera_moved says the gesture moved the camera, so earlier screenshots and pixels no longer match the view.\nWith target, the gesture is on a web page's element instead (a canvas such as the colour picker's spectrum, a slider, a sortable or scrolled list): x/y, to and waypoints are logical pixels from its top left, a drag keeps the pointer captured where the page asks for it, and a wheel scrolls what is under the pointer unless the page takes it; page says what the gesture changed there, as for click.", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "action": { + "description": "Default click.", + "enum": [ + "move", + "down", + "up", + "click", + "drag", + "wheel" + ], + "type": "string" + }, + "at": { + "additionalProperties": false, + "description": "A point of the model: {object, instance (default 0), part (default 0), and point [x, y, z] in the part's own mesh coordinates (frame \"part\", the default) or the scene's (frame \"world\"), or spot: top | bottom | front | back | left | right, where a ray along that axis first meets the part}.", + "properties": { + "frame": { + "description": "Default part.", + "enum": [ + "part", + "world" + ], + "type": "string" + }, + "instance": { + "minimum": 0, + "type": "integer" + }, + "object": { + "minimum": 0, + "type": "integer" + }, + "part": { + "minimum": 0, + "type": "integer" + }, + "point": { + "description": "[x, y, z] mm", + "items": { + "type": "number" + }, + "type": "array" + }, + "spot": { + "description": "A side of the part.", + "enum": [ + "top", + "bottom", + "front", + "back", + "left", + "right" + ], + "type": "string" + } + }, + "required": [ + "object" + ], + "type": "object" + }, + "button": { + "description": "Default left.", + "enum": [ + "left", + "right", + "middle" + ], + "type": "string" + }, + "canvas": { + "description": "Default current, the view shown. design takes x/y only.", + "enum": [ + "3d", + "preview", + "assemble", + "design", + "current" + ], + "type": "string" + }, + "check": { + "description": "For model points: surface (default) or projection only.", + "enum": [ + "surface", + "point" + ], + "type": "string" + }, + "delta": { + "description": "Wheel notches.", + "type": "integer" + }, + "double": { + "description": "Double click.", + "type": "boolean" + }, + "modifiers": { + "description": "Modifier keys held during the click, as in press_keys: ctrl and cmd are both Command on macOS and Ctrl elsewhere; rawctrl is the macOS Control key.", + "items": { + "enum": [ + "ctrl", + "cmd", + "rawctrl", + "shift", + "alt" + ], + "type": "string" + }, + "type": "array" + }, + "popup_item": { + "description": "Run this item of the menu the input opens (a right click's context menu, a button's menu), by its label path, \"Add Modifier>Cylinder\"; \"#2\" picks a repeated label's second item. Without it, such a menu is listed in the reply (popup_menu), not shown.", + "type": "string" + }, + "steps": { + "description": "Moves per drag leg (default 10).", + "maximum": 200, + "minimum": 1, + "type": "integer" + }, + "target": { + "description": "A web page's element (its ref or a {web}/{css} locator) to gesture on instead of a 3D canvas.", + "type": [ + "string", + "object" + ] + }, + "timeout_s": { + "description": "For a web page's element: seconds the page gets to answer (default 10).", + "maximum": 120, + "minimum": 1, + "type": "integer" + }, + "to": { + "description": "A canvas pixel [x, y] or a point of the model, as for at.", + "type": [ + "array", + "object" + ] + }, + "tolerance": { + "description": "Surface check distance in mm (default 1% of the part's size, at least 0.1).", + "minimum": 0, + "type": "number" + }, + "waypoints": { + "description": "Where a drag goes after the start, before to.", + "items": { + "description": "A canvas pixel [x, y] or a point of the model, as for at.", + "type": [ + "array", + "object" + ] + }, + "type": "array" + }, + "x": { + "description": "Start x, instead of at.", + "type": "integer" + }, + "y": { + "description": "Start y, instead of at.", + "type": "integer" + } + }, + "type": "object" + }, + "key": "mouse_gesture", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Mouse gesture on the 3D view" + }, + { + "completion": "none", + "description": "Do what a file picker inside the open gizmo does, with a path instead of its dialog: svg_change loads another SVG file into the SVG part being edited, svg_save_as writes that part's SVG to a new file (an existing one only with overwrite), texture_import imports a height-map image into the texture library and puts it on Texture Displacement's active layer. To add an SVG part, use run_action add_primitive_svg with a path. Gizmos open with click {target: {gizmo: name}}, and their panels take set_widget_value / click on the ImGui items list_widgets lists.", + "destructive": false, + "group": "ui", + "guard": "mutate", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "action": { + "description": "What to do.", + "enum": [ + "svg_change", + "svg_save_as", + "texture_import" + ], + "type": "string" + }, + "overwrite": { + "description": "svg_save_as: replace an existing file.", + "type": "boolean" + }, + "path": { + "description": "Absolute path of the file to read or write.", + "type": "string" + } + }, + "required": [ + "action", + "path" + ], + "type": "object" + }, + "key": "pick_gizmo_file", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Pick a file for the open gizmo" + }, + { + "completion": "none", + "description": "Press a button of the topmost modal dialog: yes, no, ok, cancel, close, apply, a button's label, or a numeric id. A disabled button (enabled: false) is refused, the dialog's message showing what it still needs, and so is one on a page the dialog does not show, except a hidden cancel or close, which ends the dialog. The label of an option of a selector made of buttons (Orca's radio groups, tab bars and multi-switches, shown as (*) / ( ) in the message) selects that option and leaves the dialog open; set other radio buttons and switches with click or set_widget_value true, and notebook tabs with click. dialog.title, text the dialog's title contains, makes sure which dialog that is; it must be the topmost. Reply: closed: true when it closed, and dialogs, those still open. A native message box (native: true) is pressed through the OS, by one of the buttons get_app_state.dialogs lists for it; a file or folder picker can't be answered here, nor any native dialog on macOS (its buttons list is empty): register auto_answer_dialogs before opening them. A web dialog's buttons are on its page: a label is pressed there, waiting up to 3 s for it to show, so the page's own handler runs. With no such page button, or a page busy for those 3 s, cancel and close end the dialog, and ok, yes, no and apply are refused rather than skip the page's commit; page_buttons then lists the page's buttons.", + "destructive": false, + "group": "core", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "button": { + "description": "Button to press.", + "type": "string" + }, + "dialog": { + "additionalProperties": false, + "description": "Which dialog; default the topmost.", + "properties": { + "title": { + "description": "Text the dialog's title contains (case-insensitive).", + "type": "string" + } + }, + "type": "object" + } + }, + "required": [ + "button" + ], + "type": "object" + }, + "key": "answer_dialog", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Answer a dialog" + }, + { + "completion": "none", + "description": "Answer modal dialogs automatically when their title or message matches a rule's regex (case-insensitive). get_app_state.auto_answer_rules lists the rules in force. Called from a replay or script, the rules last until it ends; otherwise they replace the ones this session set before, and an empty list clears them. A native dialog returns the rule's button at once and never shows. A file or folder picker takes button ok with an absolute path and returns it without showing (on Linux such a rule cancels it); without a path a picker can only be cancelled, and a multi-select picker takes no path. A wx dialog has the button pressed as answer_dialog does, so its handler runs. A matching dialog already open is answered too (answered_open_dialog), so a prompt that shows around the same time, such as the restore prompt after startup, is caught either way. A web dialog is matched by its title: a button that names one of its shown wx buttons (by label, standard name or id) is pressed as for a wx dialog, any other on its page once it shows there, for up to 10 s after the page loads; past that, cancel and close end the dialog and any other button gives up.", + "destructive": false, + "group": "core", + "guard": "recover", + "idempotent": true, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "rules": { + "description": "Rules, first match wins.", + "items": { + "additionalProperties": false, + "properties": { + "button": { + "description": "yes | no | ok | cancel | close | apply | label | id", + "type": "string" + }, + "match": { + "description": "Regex searched in \"title\\nmessage\", in \"title\\ntext\" (the dialog's own static text, one line each, without its controls), and in the title alone for a dialog with no text (a web dialog), so ^Title$ matches it.", + "type": "string" + }, + "overwrite": { + "description": "A save picker may return an existing file at path (default false).", + "type": "boolean" + }, + "path": { + "description": "Absolute path a matching file or folder picker returns, with button ok. A picker has no title until it shows, so the rule matches its prompt and must not anchor on a title with ^. The rule answers pickers only: an open picker needs an existing file, a folder picker an existing folder, and a save picker a new file. A picker the path can't serve is cancelled and the reason logged.", + "type": "string" + } + }, + "required": [ + "match", + "button" + ], + "type": "object" + }, + "type": "array" + } + }, + "required": [ + "rules" + ], + "type": "object" + }, + "key": "auto_answer_dialogs", + "listed": true, + "open_world": false, + "operations": [], + "read_only": false, + "title": "Answer dialogs automatically" + }, + { + "completion": "none", + "description": "Evaluate JavaScript in one of OrcaSlicer's web views (Home, the device page, dialogs, plugin windows). Prefer list_widgets and the input tools (click, set_widget_value, press_keys, mouse_gesture), which see and drive pages as they do widgets. The code runs in the target's page: a web view's (kind webview in list_widgets), or a page element's, with the element as `el`; without a target, in the topmost dialog's web view, else in the only shown one. While a modal dialog is open, only its pages run code. Reply: result, the value of the last expression (JSON values come back parsed), and url; closed: true when the code closed its dialog, navigated: true when it changed the page, dialogs when it opened another. Messages the page posts to OrcaSlicer reach it once the code has returned. It runs through eval, which a page whose Content-Security-Policy forbids it may refuse (list_widgets and the input tools still work there).", + "destructive": false, + "group": "ui", + "guard": "recover", + "idempotent": false, + "in_palette": false, + "input_schema": { + "additionalProperties": false, + "properties": { + "code": { + "description": "JavaScript to run.", + "type": "string" + }, + "target": { + "description": "A ref from the latest list_widgets call (\"w12\") or a locator, such as {label: \"OK\", within: \"Preferences\"} or {menu: \"File>Export>Export G-code\"}; list_widgets's description lists every kind.", + "type": [ + "string", + "object" + ] + }, + "timeout_s": { + "description": "Seconds the code gets (default 10).", + "maximum": 120, + "minimum": 1, + "type": "integer" + } + }, + "required": [ + "code" + ], + "type": "object" + }, + "key": "run_javascript", + "listed": true, + "open_world": true, + "operations": [], + "read_only": false, + "title": "Run JavaScript in a web view" + } + ] +} diff --git a/tests/slic3rutils/CMakeLists.txt b/tests/slic3rutils/CMakeLists.txt index ab9cbab52e..42f01c9351 100644 --- a/tests/slic3rutils/CMakeLists.txt +++ b/tests/slic3rutils/CMakeLists.txt @@ -48,6 +48,7 @@ add_executable(${_TEST_NAME}_tests test_network_versions.cpp test_orca_cloud_agent.cpp test_action_source.cpp + test_command_catalog.cpp test_option_state_registry.cpp test_plugin_host_api.cpp # Exercise seam enums and predicates through the embedded Python host API. @@ -90,7 +91,7 @@ add_executable(${_TEST_NAME}_tests if (SLIC3R_CAD) target_sources(${_TEST_NAME}_tests PRIVATE test_design_sketch_tool.cpp) - # The Design tab's MCP surface: list_cad_tools, describe_cad_tool and call_cad_tool. + # The Design tab's commands. target_sources(${_TEST_NAME}_tests PRIVATE test_mcp_cad.cpp) endif () diff --git a/tests/slic3rutils/test_action_source.cpp b/tests/slic3rutils/test_action_source.cpp index 99e02c9341..5dc4ba1978 100644 --- a/tests/slic3rutils/test_action_source.cpp +++ b/tests/slic3rutils/test_action_source.cpp @@ -4,6 +4,7 @@ #include <catch2/catch_message.hpp> #include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/GUI_Factories.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/NativeCommands.hpp" @@ -38,7 +39,7 @@ public: : AppAction("test", std::move(title), "src-key", std::move(source_name)) {} - AppActionRunResult run(const std::string& param = {}) const override { return {}; } + AppActionRunResult run(const nlohmann::json& /*args*/) const override { return {}; } }; } // namespace @@ -107,7 +108,7 @@ TEST_CASE("Command actions are keyed by catalog key, not display title", "[Actio // so the displayed title and group equal them. TEST_CASE("Command action construction keys by catalog key", "[ActionSource][SpeedDial]") { - const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog(); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); REQUIRE_FALSE(commands.empty()); const Slic3r::GUI::NativeCommand& c = commands.front(); @@ -131,8 +132,9 @@ TEST_CASE("Actions default to no description or wiki link", "[ActionSource][Spee CHECK(action.tooltip.empty()); CHECK(action.help_url.empty()); - REQUIRE_FALSE(Slic3r::GUI::NativeCommands::catalog().empty()); - std::unique_ptr<AppAction> command = Slic3r::GUI::NativeCommands::make_action(Slic3r::GUI::NativeCommands::catalog().front()); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); + REQUIRE_FALSE(commands.empty()); + std::unique_ptr<AppAction> command = Slic3r::GUI::NativeCommands::make_action(commands.front()); REQUIRE(command != nullptr); CHECK(command->tooltip.empty()); CHECK(command->help_url.empty()); @@ -142,7 +144,7 @@ TEST_CASE("Actions default to no description or wiki link", "[ActionSource][Spee TEST_CASE("Two-phase commands declare their input phase", "[ActionSource][SpeedDial]") { auto input_of = [](const std::string& key) -> std::string { - for (const auto& c : Slic3r::GUI::NativeCommands::catalog()) + for (const auto& c : Slic3r::GUI::NativeCommands::instance().commands()) if (c.key == key) return c.input; return {}; @@ -155,7 +157,7 @@ TEST_CASE("Two-phase commands declare their input phase", "[ActionSource][SpeedD // A typo here would leave a command that never enters its second phase, so pin the allowed set. TEST_CASE("Command input tokens stay in the known vocabulary", "[ActionSource][SpeedDial]") { - for (const auto& c : Slic3r::GUI::NativeCommands::catalog()) { + for (const auto& c : Slic3r::GUI::NativeCommands::instance().commands()) { INFO(c.key << " input=" << c.input); CHECK((c.input.empty() || c.input == "percent" || c.input == "tab")); } @@ -175,15 +177,95 @@ TEST_CASE("Favourite lists are capped and deduped preserving order", "[ActionSou CHECK(cap_favourites({"a", "b"}, 0) == std::vector<std::string>{}); } +TEST_CASE("A pin with no live action is dropped, the others keep their order", "[ActionSource][SpeedDial]") +{ + std::vector<std::string> stored, shown; + const auto live = [](const std::string& id) { return id != "gone"; }; + Slic3r::GUI::prune_favourites({"b", "gone", "a"}, live, stored, shown); + CHECK(stored == std::vector<std::string>{"b", "a"}); + CHECK(shown == std::vector<std::string>{"b", "a"}); +#ifndef SLIC3R_CAD + // Without the Design table, a Design tile's pin cannot be told from a removed command's. + CHECK_FALSE(Slic3r::GUI::is_design_tile_id("orca_command:shell:orca")); +#endif +} + +namespace { + +// `n` pins, pin1 to pin<n>. +std::vector<std::string> pins(int n) +{ + std::vector<std::string> out; + for (int i = 1; i <= n; ++i) + out.push_back("pin" + std::to_string(i)); + return out; +} + +} // namespace + +TEST_CASE("The favourites bar shows the first ten live pins and keeps the rest", "[ActionSource][SpeedDial]") +{ + const auto live = [](const std::string&) { return true; }; + const std::vector<std::string> twelve = pins(12); + std::vector<std::string> stored, shown; + Slic3r::GUI::prune_favourites(twelve, live, stored, shown); + CHECK(stored == twelve); + CHECK(shown == pins(10)); + // A pin past the tenth comes onto the bar once one before it is unpinned. + std::vector<std::string> unpinned = twelve; + unpinned.erase(unpinned.begin()); + Slic3r::GUI::prune_favourites(unpinned, live, stored, shown); + CHECK(shown.back() == "pin11"); +} + +TEST_CASE("A pin is refused while the bar shows ten", "[ActionSource][SpeedDial]") +{ + const auto live = [](const std::string&) { return true; }; + std::vector<std::string> favs = pins(10); + CHECK_FALSE(Slic3r::GUI::add_favourite(favs, "pin11", live)); + CHECK(favs == pins(10)); + // A pin already on the bar stays where it is. + CHECK(Slic3r::GUI::add_favourite(favs, "pin3", live)); + CHECK(favs == pins(10)); + // A stored pin past the tenth is not on the bar, which is full, so it is refused as a new one is. + favs = pins(12); + CHECK_FALSE(Slic3r::GUI::add_favourite(favs, "pin12", live)); + CHECK(favs == pins(12)); +} + +// Ordinary use stores at most thirty pins: ten for each set of live actions the bar is shown with. +static_assert(ActionRegistry::kFavStoredLimit > 3 * ActionRegistry::kFavLimit, "kFavStoredLimit must stay out of ordinary use's reach"); + +TEST_CASE("The stored pins stay within their bound however few the bar shows", "[ActionSource][SpeedDial]") +{ + const auto none_live = [](const std::string&) { return false; }; + std::vector<std::string> favs = pins(int(ActionRegistry::kFavStoredLimit)); + CHECK_FALSE(Slic3r::GUI::add_favourite(favs, "one_more", none_live)); + CHECK(favs.size() == ActionRegistry::kFavStoredLimit); +} + +TEST_CASE("Reordering the bar moves only the pins it shows, each other pin keeping its place", "[ActionSource][SpeedDial]") +{ + // The bar shows a, b and c; hidden1 and hidden2 are pins it does not show. The page moves b to the front and + // sends the pins it shows. + CHECK(Slic3r::GUI::reordered_favourites({"a", "hidden1", "b", "c", "hidden2"}, {"b", "a", "c"}) == + std::vector<std::string>{"b", "hidden1", "a", "c", "hidden2"}); + // An id that is no pin, and one sent twice, move nothing else. + CHECK(Slic3r::GUI::reordered_favourites({"a", "hidden1", "b"}, {"gone", "b", "b", "a"}) == + std::vector<std::string>{"b", "hidden1", "a"}); +} + TEST_CASE("Native command catalog has unique keys and present titles", "[ActionSource][SpeedDial]") { - const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog(); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); CHECK_FALSE(commands.empty()); std::set<std::string> seen; for (const auto& c : commands) { + INFO(c.key); CHECK_FALSE(c.key.empty()); CHECK_FALSE(c.title.empty()); + // A tile shows under its group; a typed tool's group is what search_tools filters by. CHECK_FALSE(c.group.empty()); // A duplicated key would silently shadow the earlier command in the palette. CHECK(seen.insert(c.key).second); @@ -196,7 +278,7 @@ TEST_CASE("Native command catalog has unique keys and present titles", "[ActionS // cannot leave broken images in the palette. TEST_CASE("Native command icons resolve to shipped SVGs", "[ActionSource][SpeedDial]") { - const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog(); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); auto icon_of = [&commands](const std::string& key) -> const std::string* { for (const auto& c : commands) if (c.key == key) @@ -240,12 +322,31 @@ TEST_CASE("Native command icons resolve to shipped SVGs", "[ActionSource][SpeedD } } +// The Design tab's tiles are the registry's to show while the tab is shown (materialize_design_actions()), +// so the palette's own commands, which it holds whatever tab is shown, leave the Design group out. +TEST_CASE("the palette's own commands leave the Design group out", "[ActionSource][SpeedDial]") +{ + Slic3r::GUI::CommandCatalog catalog; + for (const char* group : {"Design", "Commands"}) { + Slic3r::GUI::NativeCommand c; + c.key = std::string(group) + "_tile"; + c.title = group; + c.group = group; + c.in_palette = true; + catalog.add(std::move(c)); + } + catalog.seal(); + const std::vector<const Slic3r::GUI::NativeCommand*> palette = Slic3r::GUI::NativeCommands::palette_commands(catalog); + REQUIRE(palette.size() == 1); + CHECK(palette.front()->key == "Commands_tile"); +} + // The Help-menu commands, wiki/YouTube links and the developer-mode toggle are part of the palette. // Guard their presence and that they stay grouped with their peers, so a catalog edit cannot drop // or scatter them. Groups are compared to the peer's own group to stay independent of translation. TEST_CASE("Native command catalog includes the Help and developer-mode commands", "[ActionSource][SpeedDial]") { - const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog(); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); auto find = [&commands](const std::string& key) -> const Slic3r::GUI::NativeCommand* { for (const auto& c : commands) if (c.key == key) @@ -270,8 +371,8 @@ TEST_CASE("Native command catalog includes the Help and developer-mode commands" CHECK(dev_mode->group == mode_simple->group); } -// A person takes screenshots and records from the palette, beside Run Script, with no agent involved. Start -// Recording takes its settings as a parameter, which an agent passes to skip its dialog. +// A person takes screenshots and records from the palette, beside Run Script, with no agent involved. Start and +// Stop Recording are the typed tools too, whose arguments skip what the tile does. TEST_CASE("Native command catalog has the screenshot and recording commands", "[ActionSource][SpeedDial]") { const Slic3r::GUI::NativeCommand* runner = Slic3r::GUI::NativeCommands::find("open_action_replay"); @@ -282,7 +383,7 @@ TEST_CASE("Native command catalog has the screenshot and recording commands", "[ REQUIRE(c != nullptr); CHECK(c->group == runner->group); CHECK(c->input.empty()); - CHECK(c->param.type == (std::string(key) == "start_recording" ? Slic3r::GUI::CommandParamType::Text : Slic3r::GUI::CommandParamType::None)); + CHECK(c->input_schema.at("properties").empty() == (std::string(key) == "take_screenshot")); CHECK_FALSE(c->description.empty()); } } @@ -298,7 +399,7 @@ TEST_CASE("Native command catalog has the Run Script panel and Action Replay com REQUIRE(panel != nullptr); CHECK(panel->group == replay->group); CHECK(panel->input.empty()); - CHECK(panel->param.type == Slic3r::GUI::CommandParamType::None); + CHECK(panel->input_schema.at("properties").empty()); CHECK_FALSE(panel->description.empty()); } @@ -306,7 +407,7 @@ TEST_CASE("Native command catalog has the Run Script panel and Action Replay com // menu. Groups are compared to a peer's own group to stay independent of translation. TEST_CASE("Native command catalog covers the Add menus", "[ActionSource][SpeedDial]") { - const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog(); + const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::instance().commands(); auto group_of = [&commands](const std::string& key) -> const std::string* { for (const auto& c : commands) if (c.key == key) diff --git a/tests/slic3rutils/test_command_catalog.cpp b/tests/slic3rutils/test_command_catalog.cpp new file mode 100644 index 0000000000..9a1472703c --- /dev/null +++ b/tests/slic3rutils/test_command_catalog.cpp @@ -0,0 +1,852 @@ +#include <catch2/catch_message.hpp> +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers.hpp> +#include <catch2/matchers/catch_matchers_string.hpp> + +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/Mcp/McpPersonContext.hpp" +#include "slic3r/GUI/Mcp/McpProtocol.hpp" +#include "slic3r/GUI/Mcp/McpTypes.hpp" +#include "slic3r/GUI/NativeCommands.hpp" +#include "slic3r/GUI/Operations/Outcome.hpp" + +#include <nlohmann/json.hpp> + +#include <algorithm> +#include <cstddef> +#include <cstdlib> +#include <fstream> +#include <functional> +#include <ios> +#include <iterator> +#include <memory> +#include <set> +#include <sstream> +#include <stdexcept> +#include <string> +#include <thread> +#include <utility> +#include <vector> + +using Catch::Matchers::ContainsSubstring; +using nlohmann::json; +using Slic3r::GUI::AppActionRunResult; +using Slic3r::GUI::CommandCatalog; +using Slic3r::GUI::CommandCompletion; +using Slic3r::GUI::CommandFn; +using Slic3r::GUI::CommandSource; +using Slic3r::GUI::NativeCommand; +namespace Mcp = Slic3r::GUI::Mcp; +namespace NativeCommands = Slic3r::GUI::NativeCommands; +namespace Ops = Slic3r::GUI::Ops; + +namespace { + +NativeCommand command(std::string key, bool in_palette = false) +{ + NativeCommand c; + c.key = std::move(key); + c.in_palette = in_palette; + return c; +} + +json no_arguments() { return {{"type", "object"}, {"properties", json::object()}}; } + +// A call's context without the MCP core: UI closures run in place and nothing is left to wait for. It +// counts the operations a call begins and records the commands it submits as jobs. +class TestContext final : public Mcp::ToolContext +{ +public: + explicit TestContext(bool person = false) : m_person(person) {} + + bool person() const override { return m_person; } + json run_ui(const std::function<json()>& fn) override { return fn(); } + json observe_ui(const std::function<json()>& /*fn*/) override { return true; } + const std::string& job_id() const override { return m_job; } + bool cancelled() const override { return false; } + Mcp::ToolResult call_child(const std::string& /*tool*/, const json& /*args*/) override { return Mcp::ToolResult::error("no child calls"); } + std::set<std::string> lineage() const override { return {}; } + void set_journal_args(json args) override { journaled = std::move(args); } + void begin_operation() override { ++operations; } + Mcp::ToolResult submit(const std::string& key, const json& /*args*/) override + { + submitted.push_back(key); + return Mcp::ToolResult::ok(); + } + + int operations = 0; + std::vector<std::string> submitted; + json journaled; // what the call last recorded for the journal + +private: + bool m_person; + std::string m_job; +}; + +// Holds one command, as a plugin's operations are held while it is loaded. +class OneCommandSource final : public CommandSource +{ +public: + explicit OneCommandSource(std::string key) : m_command(std::make_shared<const NativeCommand>(command(std::move(key)))) {} + + std::shared_ptr<const NativeCommand> find(const std::string& key) const override + { + return key == m_command->key ? m_command : nullptr; + } + std::vector<std::shared_ptr<const NativeCommand>> all() const override { return {m_command}; } + +private: + std::shared_ptr<const NativeCommand> m_command; +}; + +std::vector<std::string> keys_of(const std::vector<NativeCommand>& commands) +{ + std::vector<std::string> keys; + for (const NativeCommand& c : commands) + keys.push_back(c.key); + return keys; +} + +// Every built-in command, the Design tab's among them in a build with CAD, as a run with the Design tab on holds +// them. Not sealed yet. +CommandCatalog catalog_with_design() +{ + CommandCatalog catalog; + NativeCommands::register_all_commands(catalog, {true}); + return catalog; +} + +// The entry of command `key` in a reference, or null. +json reference_entry(const json& reference, const std::string& key) +{ + for (const json& entry : reference.at("commands")) + if (entry.at("key") == key) + return entry; + return nullptr; +} + +// The lines of `text`, split at "\n". +std::vector<std::string> lines_of(const std::string& text) +{ + std::vector<std::string> lines; + std::istringstream in(text); + for (std::string line; std::getline(in, line);) + lines.push_back(line); + return lines; +} + +// Where `actual` first differs from `expected`, for a message: the line and both versions of it; empty when they +// are equal. +std::string first_difference(const std::string& actual, const std::string& expected) +{ + if (actual == expected) + return {}; + const std::vector<std::string> a = lines_of(actual), e = lines_of(expected); + for (std::size_t i = 0; i < std::min(a.size(), e.size()); ++i) + if (a[i] != e[i]) + return "line " + std::to_string(i + 1) + " is `" + a[i] + "` where the catalog has `" + e[i] + "`"; + if (a.size() == e.size()) + return "the file does not end with the newline the catalog's dump ends with"; + return "the file has " + std::to_string(a.size()) + " lines where the catalog has " + std::to_string(e.size()); +} + +} // namespace + +TEST_CASE("a key added twice is refused", "[CommandCatalog]") +{ + CommandCatalog catalog; + catalog.add(command("a")); + CHECK_THROWS_AS(catalog.add(command("a")), std::logic_error); + CHECK(catalog.commands().size() == 1); +} + +TEST_CASE("a sealed catalog refuses additions", "[CommandCatalog]") +{ + CommandCatalog catalog; + catalog.add(command("a")); + CHECK_FALSE(catalog.sealed()); + catalog.seal(); + CHECK(catalog.sealed()); + CHECK_THROWS_AS(catalog.add(command("b")), std::logic_error); + CHECK_THROWS_AS(catalog.add_source(std::make_unique<OneCommandSource>("plugin.x.y")), std::logic_error); + CHECK(catalog.find("b") == nullptr); +} + +TEST_CASE("find sees added commands, lookup also a source's", "[CommandCatalog]") +{ + CommandCatalog catalog; + catalog.add(command("slice")); + catalog.add_source(std::make_unique<OneCommandSource>("plugin.x.y")); + catalog.seal(); + + CHECK(catalog.find("plugin.x.y") == nullptr); + const std::shared_ptr<const NativeCommand> from_source = catalog.lookup("plugin.x.y"); + REQUIRE(from_source != nullptr); + CHECK(from_source->key == "plugin.x.y"); + + const NativeCommand* added = catalog.find("slice"); + REQUIRE(added != nullptr); + CHECK(catalog.lookup("slice").get() == added); + + CHECK(catalog.lookup("plugin.x.z") == nullptr); + REQUIRE(catalog.source_commands().size() == 1); + CHECK(catalog.source_commands().front()->key == "plugin.x.y"); +} + +TEST_CASE("commands keep the order they were added in", "[CommandCatalog]") +{ + CommandCatalog catalog; + for (const char* key : {"c", "a", "b"}) + catalog.add(command(key)); + catalog.seal(); + CHECK(keys_of(catalog.commands()) == std::vector<std::string>{"c", "a", "b"}); +} + +TEST_CASE("a Design command's title is translated in the Design context, any other's in none", "[CommandCatalog]") +{ + NativeCommand design; + design.key = "shell"; + design.title = "Shell"; + design.group = Slic3r::GUI::kDesignGroup; + REQUIRE(Slic3r::GUI::title_context(design) != nullptr); + CHECK(std::string(Slic3r::GUI::title_context(design)) == "Design"); + NativeCommand other; + other.key = "save_project"; + other.title = "Save project"; + other.group = "Commands"; + CHECK(Slic3r::GUI::title_context(other) == nullptr); +} + +TEST_CASE("the process catalog's palette is the Speed Dial's commands", "[CommandCatalog]") +{ + const CommandCatalog& catalog = NativeCommands::instance(); + CHECK(catalog.sealed()); + const std::vector<const NativeCommand*> palette = NativeCommands::palette_commands(catalog); + CHECK(palette.size() == 129); + for (const NativeCommand* c : palette) { + INFO(c->key); + CHECK(c->in_palette); + } + // The Speed Dial's own lookup reads the same catalog. + CHECK(NativeCommands::find("slice_all") == catalog.find("slice_all")); +} + +TEST_CASE("every key of the process catalog is unique, tools and commands together", "[CommandCatalog]") +{ + std::set<std::string> keys; + for (const NativeCommand& c : NativeCommands::instance().commands()) { + INFO(c.key); + CHECK(keys.insert(c.key).second); + } + // The Speed Dial's commands and the typed tools are both there. + CHECK(keys.count("obj_arrange") == 1); + CHECK(keys.count("get_app_state") == 1); +} + +TEST_CASE("the typed tools are listed and the four merged commands are both", "[CommandCatalog]") +{ + for (const char* key : {"new_project", "save_project", "start_recording", "stop_recording"}) { + INFO(key); + const NativeCommand* merged = NativeCommands::find(key); + REQUIRE(merged != nullptr); + CHECK(merged->listed); + CHECK(merged->in_palette); + // The Speed Dial's title and section. + CHECK(merged->group == "Commands"); + CHECK_FALSE(merged->icon.empty()); + } + CHECK(NativeCommands::find("new_project")->title == "New Project"); + + const NativeCommand* tool = NativeCommands::find("get_app_state"); + REQUIRE(tool != nullptr); + CHECK(tool->listed); + CHECK_FALSE(tool->in_palette); + + const NativeCommand* tile = NativeCommands::find("obj_arrange"); + REQUIRE(tile != nullptr); + CHECK_FALSE(tile->listed); + CHECK(tile->in_palette); +} + +TEST_CASE("no typed tool is in the palette", "[CommandCatalog]") +{ + // Every tile of the Speed Dial: its own commands, the four merged ones among them, and no other typed tool. + const std::set<std::string> tiles{ + "add_handy_3dbenchy", "add_handy_autodesk_fdm_test", "add_handy_cali_cat", "add_handy_orca_badge", + "add_handy_orca_cube", "add_handy_orca_string_hell", "add_handy_orca_tolerance_test", "add_handy_orcasliced_combo", + "add_handy_stanford_bunny", "add_handy_voron_cube", "add_primitive_cone", "add_primitive_cube", + "add_primitive_cylinder", "add_primitive_disc", "add_primitive_sphere", "add_primitive_svg", "add_primitive_text", + "add_primitive_torus", "calib_cornering", "calib_flow_ratio", "calib_input_shaping_damp", "calib_input_shaping_freq", + "calib_max_volumetric", "calib_pressure_advance", "calib_retraction", "calib_temperature", "calib_vfa", "deselect_all", + "export_3mf", "export_all_sliced_file", "export_config", "export_drc_multi", "export_drc_single", "export_gcode", + "export_sliced_file", "export_stl", "export_stl_multi", "export_toolpaths_obj", "filament_add", "filament_delete", + "go_to_layer", "go_to_tab", "help_about", "help_benchmark_3d_scene", "help_check_updates", "help_keyboard_shortcuts", + "help_migrate_filament_presets", "help_network_test", "help_open_config_folder", "help_setup_wizard", + "help_tip_of_the_day", "help_troubleshoot", "import_configs", "import_file", "import_zip_archive", + "install_local_plugin", "install_plugin", "load_project", "mode_advanced", "mode_expert", "mode_simple", "new_project", + "obj_arrange", "obj_assemble", "obj_center", "obj_delete", "obj_delete_all", "obj_drop", "obj_fit_volume", + "obj_instances_down", "obj_instances_to_objects", "obj_instances_up", "obj_mirror_x", "obj_mirror_y", "obj_mirror_z", + "obj_order_by_filament", "obj_order_by_height", "obj_order_by_name", "obj_order_by_size", "obj_orient", "obj_rename", + "obj_set_instances", "obj_split_objects", "obj_split_parts", "obj_type_modifier", "obj_type_negative", "obj_type_part", + "obj_type_precise_seam", "obj_type_support_blocker", "obj_type_support_enforcer", "open_action_replay", "open_plugins", + "open_preferences", "open_wiki", "open_youtube", "plate_add", "plate_delete", "plate_duplicate", "plate_goto", + "plate_rename", "plate_toggle_lock", "preset_bundle", "redo", "refresh_plugins", "reset_window_layout", "save_project", + "save_project_as", "select_all", "send_gcode", "slice_all", "slice_and_preview", "start_recording", "stop_recording", + "sync_ams", "sync_presets", "take_screenshot", "toggle_developer_mode", "toggle_run_script", "undo", "view_bottom", + "view_default", "view_fit_bed", "view_front", "view_iso", "view_left", "view_rear", "view_right", + "view_toggle_perspective", "view_top"}; + REQUIRE(tiles.size() == 129); + + std::set<std::string> palette; + for (const NativeCommand* c : NativeCommands::palette_commands(NativeCommands::instance())) + palette.insert(c->key); + CHECK(palette == tiles); + CHECK(palette.count("new_project") == 1); + CHECK(palette.count("get_app_state") == 0); + CHECK(palette.count("slice") == 0); +} + +TEST_CASE("a merged command accepts silent and publishes its form", "[CommandCatalog]") +{ + const NativeCommand* save = NativeCommands::find("save_project"); + REQUIRE(save != nullptr); + CHECK_FALSE(save->input_schema.contains("required")); + CHECK(save->input_schema["then"]["required"] == json::array({"path"})); + json none = json::object(); + CHECK(Mcp::argument_error(*save, none).empty()); + json path{{"path", "C:/a.3mf"}}; + CHECK(Mcp::argument_error(*save, path).empty()); + json silent{{"silent", true}}; + CHECK_THAT(Mcp::argument_error(*save, silent), ContainsSubstring("path")); + + const NativeCommand* fresh = NativeCommands::find("new_project"); + REQUIRE(fresh != nullptr); + const json& properties = fresh->input_schema["properties"]; + for (const char* name : {"silent", "discard_changes", "preset_changes"}) { + INFO(name); + CHECK(properties.contains(name)); + } +} + +TEST_CASE("a merged command's call with no arguments is the person's form", "[CommandCatalog]") +{ + int tool_calls = 0, person_calls = 0; + const json schema{{"type", "object"}, {"properties", {{"path", {{"type", "string"}}}}}, {"required", {"path"}}}; + const auto tool = NativeCommands::long_command("k", "K", "", schema, [&tool_calls](const json&, Mcp::ToolContext&) { + ++tool_calls; + return Mcp::ToolResult::ok({{"tool", true}}); + }); + const NativeCommand merged = NativeCommands::with_person_form(tool, "K", "Commands", "menu_save", [&person_calls] { + ++person_calls; + return AppActionRunResult{AppActionRunResult::Level::Success, "Asked"}; + }); + CHECK(merged.in_palette); + CHECK(merged.title == "K"); + CHECK(merged.group == "Commands"); + CHECK(merged.icon == "menu_save"); + CHECK(merged.input_schema["properties"].contains("silent")); + + TestContext agent; + const Mcp::ToolResult asked = merged.run(json::object(), agent); + CHECK(person_calls == 1); + CHECK(tool_calls == 0); + CHECK(asked.data["ran"] == "k"); + const Mcp::ToolResult given = merged.run({{"path", "a"}}, agent); + CHECK(person_calls == 1); + CHECK(tool_calls == 1); + CHECK(given.data["tool"] == true); +} + +TEST_CASE("an agent's call of a person's form is checked as a mutate call, a person's is not", "[CommandCatalog]") +{ + int person_calls = 0; + auto tool = NativeCommands::long_command("k", "K", "", no_arguments(), [](const json&, Mcp::ToolContext&) { + return Mcp::ToolResult::ok(); + }); + tool.guard = Mcp::GuardClass::Inspect; // as the recording tools run, behind dialogs + const auto person = [&person_calls] { + ++person_calls; + return AppActionRunResult{AppActionRunResult::Level::Success, "Asked"}; + }; + const NativeCommand opens = NativeCommands::with_person_form(tool, "K", "Commands", "", person); + const NativeCommand quiet = NativeCommands::with_person_form(tool, "K", "Commands", "", person, /*person_form_behind_dialogs=*/true); + + // An agent's call asks the service's UI for the mutate check before the person's form runs: a context + // without a service refuses it, and the form never runs. + TestContext agent; + CHECK_THROWS_AS(opens.run(json::object(), agent), std::logic_error); + CHECK(person_calls == 0); + // A form that opens nothing runs where the tool does, and a person's pick is never checked. + CHECK_FALSE(quiet.run(json::object(), agent).is_error); + CHECK(person_calls == 1); + TestContext picked(/*person=*/true); + CHECK_FALSE(opens.run(json::object(), picked).is_error); + CHECK(person_calls == 2); + // The tool's own form is not the person's: no check. + CHECK_FALSE(opens.run({{"silent", true}}, agent).is_error); + CHECK(person_calls == 2); +} + +TEST_CASE("a silent call is journaled silent", "[CommandCatalog]") +{ + const NativeCommand tool = NativeCommands::long_command("k", "K", "", no_arguments(), [](const json& args, Mcp::ToolContext& ctx) { + ctx.set_journal_args(args); + return Mcp::ToolResult::ok(); + }); + const NativeCommand merged = NativeCommands::with_person_form(tool, "K", "Commands", "", [] { return AppActionRunResult{}; }); + + TestContext agent; + merged.run({{"silent", true}}, agent); + CHECK(agent.journaled == json{{"silent", true}}); +} + +TEST_CASE("a recording started with arguments lasts an hour by default", "[CommandCatalog]") +{ + const NativeCommand* start = NativeCommands::find("start_recording"); + REQUIRE(start != nullptr); + CHECK_THAT(start->input_schema["properties"]["max_seconds"]["description"].get<std::string>(), ContainsSubstring("default 3600")); +} + +TEST_CASE("the catalog needs no service", "[CommandCatalog]") +{ + // No McpService is made in this test: the catalog is built without one, and its listing is the tool list. + const CommandCatalog& catalog = NativeCommands::instance(); + struct NoApp final : Mcp::ToolCaller + { + Mcp::ToolResult call(const NativeCommand&, const json&) override { return Mcp::ToolResult::error("no app"); } + } caller; + Mcp::McpProtocol protocol(catalog, caller, Mcp::ServerInfo{}); + const Mcp::PostReply reply = protocol.handle_post({json{{"jsonrpc", "2.0"}, {"id", 1}, {"method", "tools/list"}}.dump(), {}, {}, {}}); + REQUIRE(reply.status == 200); + const json tools = json::parse(reply.body)["result"]["tools"]; + std::set<std::string> names; + for (const json& tool : tools) + names.insert(tool["name"].get<std::string>()); + CHECK(names.count("get_app_state") == 1); + CHECK(names.count("call_tool") == 1); + CHECK(names.count("obj_arrange") == 0); +} + +TEST_CASE("a Speed Dial command is found by the one lookup", "[CommandCatalog]") +{ + const CommandCatalog& catalog = NativeCommands::instance(); + CHECK(catalog.lookup("obj_arrange") != nullptr); + // A misspelt key is answered with the closest command, which call_tool runs, not with a tile's run_action. + const std::string unknown = catalog.unknown_command("obj_arange", /*suggest=*/true); + CHECK_THAT(unknown, ContainsSubstring("obj_arrange")); + CHECK_THAT(unknown, !ContainsSubstring("run_action")); +} + +TEST_CASE("every expected-id argument of a schema is in id_args", "[CommandCatalog]") +{ + for (const NativeCommand& c : NativeCommands::instance().commands()) { + INFO(c.key); + std::set<std::string> in_schema; + if (c.input_schema.is_object() && c.input_schema.contains("properties")) + for (const char* name : {"object_id", "part_id", "object_ids", "part_ids", "instance_object_ids"}) + if (c.input_schema["properties"].contains(name)) + in_schema.insert(name); + CHECK(std::set<std::string>(c.id_args.begin(), c.id_args.end()) == in_schema); + } + for (const char* key : {"transform", "select_objects", "set_settings"}) { + INFO(key); + const NativeCommand* takes_ids = NativeCommands::find(key); + REQUIRE(takes_ids != nullptr); + CHECK_FALSE(takes_ids->id_args.empty()); + } +} + +TEST_CASE("the process catalog is built once", "[CommandCatalog]") +{ + // Built here on first use, if no test before this one built it. + const CommandCatalog& catalog = NativeCommands::instance(); + CHECK_THROWS_AS(NativeCommands::build({}), std::logic_error); + CHECK(&NativeCommands::instance() == &catalog); +} + +TEST_CASE("the palette is the commands with in_palette", "[CommandCatalog]") +{ + CommandCatalog catalog; + catalog.add(command("first", true)); + catalog.add(command("typed_tool", false)); + catalog.add(command("last", true)); + catalog.seal(); + + const std::vector<const NativeCommand*> palette = NativeCommands::palette_commands(catalog); + REQUIRE(palette.size() == 2); + CHECK(palette[0] == catalog.find("first")); + CHECK(palette[1] == catalog.find("last")); +} + +TEST_CASE("a sealed catalog is read from eight threads", "[CommandCatalog]") +{ + // Keys the catalog holds, misspells and lacks; each thread asks about them in turn. + const std::vector<std::string> keys{"slice_all", "undo", "slice_al", "export_gcod", "no_such_command"}; + struct Answer + { + const NativeCommand* found = nullptr; + std::vector<std::string> similar; + + bool operator==(const Answer& other) const { return found == other.found && similar == other.similar; } + }; + constexpr std::size_t thread_count = 8; + constexpr std::size_t rounds = 1000; + std::vector<std::vector<Answer>> answers(thread_count); + { + std::vector<std::thread> threads; + for (std::size_t t = 0; t < thread_count; ++t) + threads.emplace_back([&keys, &answers, t] { + // The first of them to get here may build the process catalog. + const CommandCatalog& catalog = NativeCommands::instance(); + answers[t].reserve(rounds); + for (std::size_t i = 0; i < rounds; ++i) { + const std::string& key = keys[i % keys.size()]; + answers[t].push_back({catalog.find(key), catalog.similar(key)}); + } + }); + for (std::thread& thread : threads) + thread.join(); + } + + for (std::size_t t = 0; t < thread_count; ++t) { + INFO("thread " << t); + REQUIRE(answers[t].size() == rounds); + CHECK(answers[t] == answers.front()); + } + // And they are the right answers. + const std::vector<Answer>& first = answers.front(); + REQUIRE(first[0].found != nullptr); + CHECK(first[0].found->key == "slice_all"); + CHECK(first[2].found == nullptr); + REQUIRE_FALSE(first[2].similar.empty()); + CHECK(first[2].similar.front() == "slice_all"); + CHECK(first[4].found == nullptr); +} + +TEST_CASE("the person's form is the call with no arguments", "[CommandCatalog]") +{ + CHECK(Mcp::person_form(json::object())); + CHECK(Mcp::person_form(json())); + CHECK_FALSE(Mcp::person_form({{"silent", true}})); + CHECK_FALSE(Mcp::person_form({{"path", "a"}})); + CHECK(Mcp::silent_args({{"silent", true}, {"path", "a"}}) == json{{"path", "a"}}); +} + +TEST_CASE("a two-form schema requires its arguments only when some are given", "[CommandCatalog]") +{ + const json s = Mcp::with_silent({{"type", "object"}, + {"properties", {{"path", {{"type", "string"}}}, {"overwrite", {{"type", "boolean"}}}}}, + {"required", {"path"}}, + {"additionalProperties", false}}); + CHECK_FALSE(s.contains("required")); + CHECK(s["then"]["required"] == json::array({"path"})); + CHECK(s["properties"]["silent"]["enum"] == json::array({true})); + CHECK(Mcp::validate_arguments(s, json::object()).empty()); + CHECK(Mcp::validate_arguments(s, {{"path", "a"}}).empty()); + CHECK_THAT(Mcp::validate_arguments(s, {{"overwrite", true}}), ContainsSubstring("path")); + CHECK_THAT(Mcp::validate_arguments(s, {{"silent", true}}), ContainsSubstring("path")); + CHECK_THAT(Mcp::validate_arguments(s, {{"silent", false}}), ContainsSubstring("silent")); +} + +TEST_CASE("a person's pick runs the function in place", "[CommandCatalog]") +{ + int calls = 0; + const NativeCommand c = NativeCommands::ui_command("k", "K", "Commands", no_arguments(), [&calls](const json&) { + ++calls; + return AppActionRunResult{AppActionRunResult::Level::Success, "Done"}; + }); + Mcp::PersonContext person; + const Mcp::ToolResult result = c.run(json::object(), person); + CHECK(calls == 1); + REQUIRE(result.notice != nullptr); + CHECK(result.notice->level == AppActionRunResult::Level::Success); + CHECK(result.notice->message == "Done"); +} + +TEST_CASE("a long command picked by a person is submitted", "[CommandCatalog]") +{ + int calls = 0; + const CommandFn fn = [&calls](const json&, Mcp::ToolContext&) { + ++calls; + return Mcp::ToolResult::ok(); + }; + TestContext person(true); + NativeCommands::long_command("k", "K", "Commands", no_arguments(), fn).run(json::object(), person); + CHECK(person.submitted == std::vector<std::string>{"k"}); + CHECK(calls == 0); + + const NativeCommand in_place = NativeCommands::long_command("k", "K", "Commands", no_arguments(), fn, true); + CHECK(in_place.inline_call); + in_place.run(json::object(), person); + CHECK(calls == 1); + CHECK(person.submitted.size() == 1); + + // An agent's call is already a job: the function runs. + TestContext agent; + NativeCommands::long_command("k", "K", "Commands", no_arguments(), fn).run(json::object(), agent); + CHECK(calls == 2); + CHECK(agent.submitted.empty()); +} + +TEST_CASE("a person's submit refuses an unknown command, and starts no job without OrcaSlicer", "[CommandCatalog]") +{ + // The lookup comes first; starting the runtime, the job and its notices need the app, which no unit test runs. + Mcp::PersonContext person; + CHECK_THROWS_WITH(person.submit("no_such_command", json::object()), ContainsSubstring("Unknown command no_such_command")); + CHECK_THROWS_AS(person.submit("run_script", json::object()), Mcp::ToolFailure); +} + +TEST_CASE("an Export command called with arguments takes the project, and with none does not", "[CommandCatalog]") +{ + const auto fails = [](const json&) { return AppActionRunResult{AppActionRunResult::Level::Error, "Nothing to export", false}; }; + const NativeCommand exporting = NativeCommands::ui_command("k", "K", "Commands", no_arguments(), fails, CommandCompletion::Export); + CHECK(exporting.completion == CommandCompletion::Export); + + TestContext given; + const Mcp::ToolResult refused = exporting.run({{"path", "a.gcode"}}, given); + CHECK(given.operations == 1); + CHECK(refused.is_error); + CHECK(refused.message == "Nothing to export"); + + TestContext none; + exporting.run(json::object(), none); + CHECK(none.operations == 0); + + const NativeCommand plain = NativeCommands::ui_command("k", "K", "Commands", no_arguments(), fails); + TestContext either; + plain.run({{"path", "a.gcode"}}, either); + plain.run(json::object(), either); + CHECK(either.operations == 0); +} + +TEST_CASE("a command with a second phase refuses a call without its value", "[CommandCatalog]") +{ + json none = json::object(); + CHECK_THAT(Mcp::argument_error(*NativeCommands::find("go_to_tab"), none), ContainsSubstring("tab")); + none = json::object(); + CHECK_THAT(Mcp::argument_error(*NativeCommands::find("go_to_layer"), none), ContainsSubstring("percent")); + json percent{{"percent", 50}}; + CHECK(Mcp::argument_error(*NativeCommands::find("go_to_layer"), percent).empty()); +} + +TEST_CASE("a rename to an empty name is refused before anything is renamed", "[CommandCatalog]") +{ + const NativeCommand* rename = NativeCommands::find("obj_rename"); + REQUIRE(rename != nullptr); + // No app runs here: the refusal comes before the command looks at the object list. + TestContext agent; + const Mcp::ToolResult refused = rename->run({{"name", ""}}, agent); + CHECK(refused.is_error); + CHECK_THAT(refused.message, ContainsSubstring("name")); +} + +TEST_CASE("undo takes a history", "[CommandCatalog]") +{ + for (const char* key : {"undo", "redo"}) { + INFO(key); + const NativeCommand* command = NativeCommands::find(key); + REQUIRE(command != nullptr); + CHECK(command->in_palette); + CHECK_FALSE(command->listed); + json design{{"history", "design"}}; + CHECK(Mcp::argument_error(*command, design).empty()); + json project{{"history", "project"}}; + CHECK(Mcp::argument_error(*command, project).empty()); + // With none, the history of the tab shown. + json none = json::object(); + CHECK(Mcp::argument_error(*command, none).empty()); + json sketch{{"history", "sketch"}}; + CHECK_THAT(Mcp::argument_error(*command, sketch), ContainsSubstring("history")); + } +} + +TEST_CASE("a person's undo shows nothing where the Edit menu's is greyed, an agent's is refused", "[CommandCatalog]") +{ + // No Design tab is built here, so the Edit menu's Undo and Redo of its history would be greyed. + const json design{{"history", "design"}}; + for (const char* key : {"undo", "redo"}) { + INFO(key); + const NativeCommand* command = NativeCommands::find(key); + REQUIRE(command != nullptr); + TestContext person(true); + const Mcp::ToolResult picked = command->run(design, person); + REQUIRE(picked.notice != nullptr); + CHECK(picked.notice->message.empty()); + CHECK(picked.notice->level != AppActionRunResult::Level::Error); + // Nothing was done: the project's history is not taken back in the Design history's place. + CHECK_FALSE(picked.notice->done); + // An agent's call reaches the Design history's gate, which says why it cannot run. + TestContext agent; + CHECK_THROWS_AS(command->run(design, agent), Mcp::ToolFailure); + } +} + +TEST_CASE("a command's result reads as run_action's did", "[CommandCatalog]") +{ + using Level = AppActionRunResult::Level; + const Mcp::ToolResult done = NativeCommands::from_run_result("k", {Level::Success, "Done"}); + CHECK_FALSE(done.is_error); + CHECK(done.data == json{{"ran", "k"}, {"level", "success"}, {"message", "Done"}}); + CHECK(NativeCommands::from_run_result("k", {Level::Busy, "Wait"}).is_error); + CHECK(NativeCommands::from_run_result("k", {Level::Error, "Failed"}).is_error); + // A command that did nothing fails, though the palette shows it as information. + CHECK(NativeCommands::from_run_result("k", {Level::Info, "Select an object first.", false}).is_error); + + // What a command adds to its reply joins the reply's fields. + const Mcp::ToolResult ordered = NativeCommands::from_run_result("k", {Level::Success, {}, true, R"({"descending": true})"}); + CHECK(ordered.data == json{{"ran", "k"}, {"level", "success"}, {"descending", true}}); + + Ops::Refusal why; + why.code = "no_objects"; + why.msgid = "There are no objects."; + AppActionRunResult refused{Level::Error, "translated", false}; + refused.refusal = std::make_shared<const Ops::Refusal>(why); + const Mcp::ToolResult failed = NativeCommands::from_run_result("k", refused); + CHECK(failed.is_error); + CHECK(failed.message == "There are no objects."); + CHECK(failed.data["code"] == "no_objects"); +} + +#ifdef SLIC3R_CAD +// The file is the reference of the build with every command, so a build without CAD does not check it. +TEST_CASE("the checked-in command reference matches the catalog", "[CommandCatalog][Reference]") +{ + CommandCatalog catalog = catalog_with_design(); + catalog.seal(); + const std::string dump = Slic3r::GUI::catalog_reference(catalog).dump(1) + "\n"; + const std::string path = std::string(TEST_DATA_DIR) + "/command_catalog.json"; + + const char* update = std::getenv("ORCA_UPDATE_COMMAND_REFERENCE"); + if (update != nullptr && std::string(update) == "1") { + std::ofstream out(path, std::ios::binary | std::ios::trunc); + out << dump; + out.close(); + INFO(path); + CHECK(out.good()); + return; + } + + std::ifstream in(path, std::ios::binary); + std::string file(std::istreambuf_iterator<char>(in), {}); + // A checkout may turn the file's line ends into CRLF; the dump has no carriage return of its own, since JSON + // writes one inside a string as \r. + file.erase(std::remove(file.begin(), file.end(), '\r'), file.end()); + const std::string difference = in.is_open() ? first_difference(file, dump) : "the file is missing"; + INFO("tests/data/command_catalog.json is not the catalog's reference: " << difference + << ". Regenerate it by running slic3rutils_tests \"[Reference]\" with ORCA_UPDATE_COMMAND_REFERENCE=1 in the " + "environment, check the file in, then regenerate the skill's actions.md with " + "tools/mcp/gen_skill_reference.py <skills checkout>."); + CHECK(difference.empty()); +} +#endif + +TEST_CASE("the reference leaves out nothing a client is told", "[CommandCatalog][Reference]") +{ + CommandCatalog catalog = catalog_with_design(); + catalog.add_source(std::make_unique<OneCommandSource>("plugin.x.y")); + catalog.seal(); + const json reference = Slic3r::GUI::catalog_reference(catalog); + + // Every command added, in that order, and none of a source. + std::vector<std::string> keys; + for (const json& entry : reference.at("commands")) + keys.push_back(entry.at("key").get<std::string>()); + CHECK(keys == keys_of(catalog.commands())); + + std::set<std::string> listed; + for (const NativeCommand& command : catalog.commands()) { + INFO(command.key); + const json entry = reference_entry(reference, command.key); + CHECK(entry == Slic3r::GUI::command_reference(command)); + if (!entry.at("listed").get<bool>()) + continue; + listed.insert(command.key); + const json told = Mcp::McpProtocol::tool_to_json(command); + CHECK(entry["description"] == told["description"]); + CHECK(entry["input_schema"] == told["inputSchema"]); + CHECK(entry["title"] == told.value("title", std::string())); + const json& annotations = told["annotations"]; + CHECK(entry["read_only"] == annotations["readOnlyHint"]); + CHECK(entry["destructive"] == annotations["destructiveHint"]); + CHECK(entry["idempotent"] == annotations["idempotentHint"]); + CHECK(entry["open_world"] == annotations["openWorldHint"]); + } + // The entries marked listed are the tools a client's tools/list names. + struct NoApp final : Mcp::ToolCaller + { + Mcp::ToolResult call(const NativeCommand&, const json&) override { return Mcp::ToolResult::error("no app"); } + } caller; + Mcp::McpProtocol protocol(catalog, caller, Mcp::ServerInfo{}); + const Mcp::PostReply reply = protocol.handle_post({json{{"jsonrpc", "2.0"}, {"id", 1}, {"method", "tools/list"}}.dump(), {}, {}, {}}); + REQUIRE(reply.status == 200); + const json told_list = json::parse(reply.body); + std::set<std::string> tools; + for (const json& tool : told_list["result"]["tools"]) + tools.insert(tool["name"].get<std::string>()); + CHECK_FALSE(tools.empty()); + CHECK(listed == tools); +} + +TEST_CASE("a reference entry has the command's fields, and its examples only when it has some", "[CommandCatalog][Reference]") +{ + NativeCommand c = command("export_it", true); + c.title = "Export It"; + c.group = "Commands"; + c.description = "Exports it."; + c.input_schema = {{"type", "object"}, {"properties", {{"path", {{"type", "string"}}}}}}; + c.guard = Mcp::GuardClass::Recover; + c.completion = CommandCompletion::Export; + c.operations = {"export_gcode"}; + c.open_world = true; + const json entry = Slic3r::GUI::command_reference(c); + CHECK(entry == json{{"key", "export_it"}, + {"title", "Export It"}, + {"group", "Commands"}, + {"description", "Exports it."}, + {"input_schema", c.input_schema}, + {"listed", false}, + {"in_palette", true}, + {"read_only", false}, + {"destructive", false}, + {"idempotent", false}, + {"open_world", true}, + {"guard", "recover"}, + {"completion", "export"}, + {"operations", json::array({"export_gcode"})}}); + + const json call{{"tool", "export_it"}, {"args", {{"path", "a"}}}}; + c.guard = Mcp::GuardClass::Inspect; + c.completion = CommandCompletion::None; + c.examples = json::array({json{{"title", "Export"}, {"calls", json::array({call})}}}); + const json other = Slic3r::GUI::command_reference(c); + CHECK(other["guard"] == "inspect"); + CHECK(other["completion"] == "none"); + CHECK(other["examples"] == c.examples); + c.guard = Mcp::GuardClass::Mutate; + CHECK(Slic3r::GUI::command_reference(c)["guard"] == "mutate"); +} + +TEST_CASE("the reference shows both forms of a two-form command", "[CommandCatalog][Reference]") +{ + CommandCatalog catalog = catalog_with_design(); + catalog.seal(); + const json reference = Slic3r::GUI::catalog_reference(catalog); + std::vector<std::string> two_forms{"save_project"}; +#ifdef SLIC3R_CAD + two_forms.push_back("fillet"); +#endif + for (const std::string& key : two_forms) { + INFO(key); + const json entry = reference_entry(reference, key); + REQUIRE(entry.is_object()); + const json& schema = entry.at("input_schema"); + CHECK(schema.at("properties").contains("silent")); + // The silent form's requirement holds once a call gives any argument; the person's form needs none. + CHECK_FALSE(schema.contains("required")); + CHECK(schema.at("if") == json{{"minProperties", 1}}); + REQUIRE(schema.at("then").contains("required")); + CHECK_FALSE(schema.at("then").at("required").empty()); + } + CHECK(reference_entry(reference, "save_project")["input_schema"]["then"]["required"] == json::array({"path"})); +} diff --git a/tests/slic3rutils/test_mcp_cad.cpp b/tests/slic3rutils/test_mcp_cad.cpp index 51e23efc8d..e4a0ccc533 100644 --- a/tests/slic3rutils/test_mcp_cad.cpp +++ b/tests/slic3rutils/test_mcp_cad.cpp @@ -1,7 +1,7 @@ -// The Design tab's MCP surface (list_cad_tools, describe_cad_tool and call_cad_tool): the CAD tool -// table, the CAD-off note, the plane resolver, the kernel's rollback, reading and editing a feature as -// its card does, and the open sketch's tools driven on a bare sketch tool. None of it needs a wx -// application or a Design panel. +// The Design tab's commands: what the catalog holds of them (schemas, descriptions, examples) and how a call +// of one is journaled, the plane resolver, the kernel's rollback, reading and editing a feature as its card +// does, and the open sketch's tools driven on a bare sketch tool. None of it needs a wx application or a +// Design panel. // McpTools.hpp reaches wx's MSW headers through GLCanvas3D.hpp after OCCT has hidden the USER and GDI // declarations they need; the Windows headers first keep them, as in test_plugin_host_api.cpp. #ifdef WIN32 @@ -31,11 +31,14 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Point.hpp" #include "libslic3r/libslic3r.h" +#include "slic3r/GUI/ActionRegistry.hpp" #include "slic3r/GUI/CAD/DesignOffer.hpp" #include "slic3r/GUI/CAD/DesignSketchTool.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/Mcp/McpTools.hpp" #include "slic3r/GUI/Mcp/McpToolsCad.hpp" #include "slic3r/GUI/Mcp/McpTypes.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include <TopoDS_Edge.hxx> #include <TopoDS_Face.hxx> @@ -43,12 +46,16 @@ #include <boost/filesystem/operations.hpp> #include <boost/filesystem/path.hpp> #include <nlohmann/json.hpp> +#include <wx/string.h> #include <algorithm> #include <cmath> #include <cstddef> #include <functional> +#include <iterator> #include <map> +#include <memory> +#include <optional> #include <set> #include <stdexcept> #include <string> @@ -149,23 +156,64 @@ void add_bound_block(CadDocument& doc) REQUIRE(doc.recompute()); } -// Every CAD tool's name, as describe_cad_tool takes a list. -json all_cad_tools() +// The Design commands in a catalog of their own. +GUI::CommandCatalog cad_catalog() { - json names = json::array(); - for (const std::string& n : GUI::Mcp::cad_tool_names()) names.push_back(n); - return names; + GUI::CommandCatalog catalog; + GUI::Mcp::register_cad_commands(catalog); + catalog.seal(); + return catalog; } -// The row `reply` lists for `name`, or null. -json row_of(const json& reply, const std::string& name) +// Every built-in command, with the Design commands among them, as a run with the CAD feature on holds them. +GUI::CommandCatalog catalog_with_cad() { - for (const json& row : reply.at(reply.contains("items") ? "items" : "tools")) // a listing's page, or a description's rows - if (row.at("name") == name) return row; - return json(); + GUI::CommandCatalog catalog; + GUI::NativeCommands::register_all_commands(catalog, {true}); + catalog.seal(); + return catalog; } -// Whether a CAD tool param by this name takes face or edge ids. +// The command `key` of `catalog`; the test stops when there is none. +const GUI::NativeCommand& command_of(const GUI::CommandCatalog& catalog, const std::string& key) +{ + const GUI::NativeCommand* command = catalog.find(key); + INFO(key); + REQUIRE(command != nullptr); + return *command; +} + +// A property of a command's input schema, or null when the schema has none by that name. +json property_of(const GUI::NativeCommand& command, const std::string& name) +{ + return command.input_schema.at("properties").value(name, json()); +} + +// The arguments a command's silent form requires, in its order: its schema's, or for a command that also has a +// person's form, those its schema requires once a call gives any argument (with_silent()). +std::vector<std::string> required_of(const GUI::NativeCommand& command) +{ + const json& schema = command.input_schema; + if (schema.contains("then")) + return schema.at("then").value("required", std::vector<std::string>()); + return schema.value("required", std::vector<std::string>()); +} + +// Whether `command` has a person's form beside its silent one: it takes `silent`. +bool two_forms(const GUI::NativeCommand& command) { return command.input_schema.at("properties").contains("silent"); } + +// The Design table's row `id`; the test stops when there is none. +const GUI::DesignTool& design_row(const std::string& id) +{ + for (int i = 0; i < GUI::kDesignToolCount; ++i) + if (id == GUI::kDesignTools[i].id) + return GUI::kDesignTools[i]; + INFO(id); + FAIL("no such row"); + throw std::logic_error("unreachable"); +} + +// Whether a param by this name takes face or edge ids. bool is_id_param(const std::string& name) { static const std::vector<std::string> ids = {"face", "faces", "edge", "edges", "up_to_face", @@ -173,245 +221,628 @@ bool is_id_param(const std::string& name) return std::find(ids.begin(), ids.end(), name) != ids.end(); } -// Whether a CAD tool param is a plane that may also be a planar face, {"body": b, "face": f}. -bool takes_face_plane(const json& param) +// A call's context that runs its UI closures in place and keeps the arguments it journals. +struct JournalContext final : GUI::Mcp::ToolContext { - return param.at("name") == "plane" && - param.value("description", std::string()).find("{\"body\": b, \"face\": f}") != std::string::npos; -} + explicit JournalContext(bool person = false) : picked(person) {} -// A call's context whose short reads on the UI thread (observe_ui) give `answer`, or fail as they do -// when the UI does not answer in time. A run_ui call fails the test. -struct UiReadContext final : GUI::Mcp::ToolContext -{ - json answer; - bool answers = true; - std::string id; - - json observe_ui(const std::function<json()>&) override - { - if (!answers) throw GUI::Mcp::ToolFailure("the UI did not answer"); - return answer; - } - json run_ui(const std::function<json()>&) override - { - FAIL("cad_feature_note must read the preference through observe_ui"); - return json(); - } - const std::string& job_id() const override { return id; } - bool cancelled() const override { return false; } - GUI::Mcp::ToolResult call_child(const std::string&, const json&) override { return GUI::Mcp::ToolResult::error("no children"); } + bool person() const override { return picked; } + json run_ui(const std::function<json()>& fn) override { return fn(); } + json observe_ui(const std::function<json()>&) override { return true; } + const std::string& job_id() const override { return id; } + bool cancelled() const override { return false; } + GUI::Mcp::ToolResult call_child(const std::string&, const json&) override { return GUI::Mcp::ToolResult::error("no children"); } std::set<std::string> lineage() const override { return {}; } - void set_journal_args(json) override {} - void begin_operation() override {} + void set_journal_args(json args) override { journaled = std::move(args); } + void begin_operation() override {} + + bool picked; + std::string id; + json journaled; // null until the call journals its arguments }; } // namespace -TEST_CASE("list_cad_tools has one row per dispatched tool", "[Mcp][CAD]") +TEST_CASE("the CAD commands are the Design table's rows less align", "[Mcp][CAD]") { - std::vector<std::string> names = GUI::Mcp::cad_tool_names(); - const json reply = GUI::Mcp::cad_list_tools(""); - std::sort(names.begin(), names.end()); - REQUIRE(std::adjacent_find(names.begin(), names.end()) == names.end()); - CHECK(std::find(names.begin(), names.end(), "describe_tools") == names.end()); - CHECK(row_names(reply) == names); // row_names() sorts: the two tables' orders differ - CHECK(reply.at("total") == names.size()); - CHECK_THAT(reply.at("use").get<std::string>(), ContainsSubstring("describe_cad_tool")); - CHECK_FALSE(reply.at("ids").get<std::string>().empty()); - for (const json& row : reply.at("items")) CHECK(row.size() == 3); // name, access, summary - // One page holds them all, in the shape every list has. - CHECK(reply.at("offset") == 0); - CHECK_FALSE(reply.contains("next_offset")); - CHECK_FALSE(reply.contains("tools")); + const GUI::CommandCatalog catalog = cad_catalog(); + std::set<std::string> keys; + for (const GUI::NativeCommand& c : catalog.commands()) { + INFO(c.key); + CHECK(keys.insert(c.key).second); + CHECK(c.group == "Design"); + CHECK_FALSE(c.listed); + // Its title is the row's name, the one the right-click menu and its tile show. + CHECK(c.title == design_row(c.key).name); + } + CHECK(keys.size() == 133); + // The body's move is named apart from the Prepare tool transform; undo and redo are the shared commands. + CHECK(keys.count("body_transform") == 1); + for (const char* gone : {"transform", "undo", "redo", "align"}) { + INFO(gone); + CHECK(keys.count(gone) == 0); + } } -TEST_CASE("list_cad_tools pages like the other lists", "[Mcp][CAD]") +TEST_CASE("the Design table has a form for every row but align", "[Mcp][CAD]") { - const std::vector<std::string> all = row_names(GUI::Mcp::cad_list_tools("")); - const json first = GUI::Mcp::cad_list_tools("", {{"limit", 3}}); - CHECK(first.at("items").size() == 3); - CHECK(first.at("total") == all.size()); - CHECK(first.at("next_offset") == 3); - const json rest = GUI::Mcp::cad_list_tools("", {{"limit", 200}, {"offset", 3}}); - CHECK(rest.at("items").size() == all.size() - 3); - CHECK(rest.at("offset") == 3); - CHECK_FALSE(rest.contains("next_offset")); + REQUIRE(GUI::kDesignToolCount == 134); + for (int i = 0; i < GUI::kDesignToolCount; ++i) { + const GUI::DesignTool& t = GUI::kDesignTools[i]; + INFO(t.id); + const bool has_form = t.action != nullptr || t.doc != nullptr; + CHECK(has_form == (std::string(t.id) != "align")); + // A row's access is its silent form's, and one with no silent form has none. + CHECK((t.doc == nullptr) == (t.access == GUI::CadAccess::None)); + if (t.doc != nullptr) { + const json doc = json::parse(t.doc); + for (const char* key : {"summary", "details", "params", "examples", "ids"}) { + INFO(key); + CHECK(doc.contains(key)); + } + } + } + // Opening Text, SVG or Color opens a dialog. + for (int i = 0; i < GUI::kDesignToolCount; ++i) { + const std::string id = GUI::kDesignTools[i].id; + INFO(id); + CHECK(GUI::kDesignTools[i].modal == (id == "sk_text" || id == "sk_svg" || id == "colour")); + } } -TEST_CASE("every CAD tool's summary is one sentence of at most 120 characters", "[Mcp][CAD]") +TEST_CASE("every block has a silent function and every silent function a block", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_list_tools(""); - for (const json& row : reply.at("items")) { - INFO(row.at("name").get<std::string>()); - const std::string summary = row.at("summary").get<std::string>(); + std::set<std::string> blocks, functions; + for (int i = 0; i < GUI::kDesignToolCount; ++i) + if (GUI::kDesignTools[i].doc != nullptr) + blocks.insert(GUI::kDesignTools[i].id); + for (std::size_t i = 0; i < GUI::Mcp::kSilentFormCount; ++i) { + INFO(GUI::Mcp::kSilentForms[i].first); + CHECK(functions.insert(GUI::Mcp::kSilentForms[i].first).second); + CHECK(GUI::Mcp::kSilentForms[i].second != nullptr); + } + CHECK(blocks.size() == 76); + CHECK(blocks == functions); +} + +TEST_CASE("a row with no slot is in no menu row", "[Mcp][CAD]") +{ + std::size_t commands_only = 0; + for (int i = 0; i < GUI::kDesignToolCount; ++i) { + const GUI::DesignTool& t = GUI::kDesignTools[i]; + INFO(t.id); + CHECK(t.row >= -1); + CHECK(t.row < GUI::kOfferRowCount); + if (t.row != -1) + continue; + ++commands_only; + CHECK(t.action == nullptr); + CHECK(t.doc != nullptr); + } + CHECK(commands_only == 41); +} + +TEST_CASE("the Design table names the row and the family submenu each verb sits in", "[Mcp][CAD]") +{ + // The offer lists the corner rectangle at Create > Rectangle > Corner rectangle. + const GUI::DesignTool& rect = design_row("sk_rect"); + CHECK(std::string(GUI::kOfferRowNames[rect.row]) == "Create"); + CHECK(std::string(rect.family) == "Rectangle"); + CHECK(std::string(rect.name) == "Corner rectangle"); + CHECK(rect.sketch_mode); + CHECK((rect.accepts & GUI::offer_bit(GUI::OfferSel::SkNone)) != 0); + CHECK(std::string(design_row("sk_rect_center").family) == "Rectangle"); + CHECK(design_row("sk_spline").family == nullptr); // directly in Create + CHECK((design_row("sk_offset").accepts & GUI::offer_bit(GUI::OfferSel::SkNone)) == 0); // it needs a picked line, curve or pair + const GUI::DesignTool& sketch = design_row("sketch"); + CHECK(std::string(GUI::kOfferRowNames[sketch.row]) == "Create"); + CHECK(sketch.family == nullptr); // the feature-mode Sketch sits directly in Create + CHECK_FALSE(sketch.sketch_mode); + // describe_scene names the selection by the atlas's ids, in OfferSel's order. + REQUIRE(std::size(GUI::kDesignSelectionIds) == std::size_t(GUI::OfferSel::Count)); + CHECK(std::string(GUI::kDesignSelectionIds[int(GUI::OfferSel::None)]) == "none"); + CHECK(std::string(GUI::kDesignSelectionIds[int(GUI::OfferSel::FacePlanar)]) == "face_planar"); + CHECK(std::string(GUI::kDesignSelectionIds[int(GUI::OfferSel::Sk2Ent)]) == "sk_2ent"); +} + +TEST_CASE("a verb with both forms accepts silent, a verb with one does not", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + CHECK(two_forms(command_of(catalog, "shell"))); + CHECK_FALSE(two_forms(command_of(catalog, "describe_scene"))); + CHECK_FALSE(two_forms(command_of(catalog, "sk_rect"))); + // A command with only a person's form takes no arguments at all. + json silent{{"silent", true}}; + CHECK_THAT(GUI::Mcp::argument_error(command_of(catalog, "sk_rect"), silent), ContainsSubstring("silent")); + json none = json::object(); + CHECK(GUI::Mcp::argument_error(command_of(catalog, "sk_rect"), none).empty()); + // A command that has a tile is the one whose row has an action, and it carries the row's icon. + for (const GUI::NativeCommand& c : catalog.commands()) { + INFO(c.key); + const GUI::DesignTool& row = design_row(c.key); + CHECK(c.in_palette == (row.action != nullptr)); + CHECK(c.icon == (row.icon != nullptr ? row.icon : "")); + CHECK(two_forms(c) == (row.action != nullptr && row.doc != nullptr)); + // A tile with no icon would be a blank square in the Speed Dial. + if (c.in_palette) + CHECK_FALSE(c.icon.empty()); + } +} + +TEST_CASE("a two-form CAD command publishes what its silent form requires", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + const GUI::NativeCommand& fillet = command_of(catalog, "fillet"); + CHECK_FALSE(fillet.input_schema.contains("required")); + CHECK(fillet.input_schema.at("if") == json{{"minProperties", 1}}); + CHECK(fillet.input_schema.at("then").at("required") == json::array({"edge"})); + // No arguments is the person's form, which opens the Fillet tool and requires nothing. + json person = json::object(); + CHECK(GUI::Mcp::argument_error(fillet, person).empty()); + json radius{{"radius", 2}}; + CHECK_THAT(GUI::Mcp::argument_error(fillet, radius), ContainsSubstring("edge")); + json silent{{"silent", true}}; + CHECK_THAT(GUI::Mcp::argument_error(fillet, silent), ContainsSubstring("edge")); +} + +TEST_CASE("a Design command is named by its verb's id", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + for (const char* key : {"surf_extrude", "surf_revolve", "surf_loft", "surf_fill", "thicken_surf", "surf_offset", "pat_curve", + "coordsys_v", "mass_props", "interference", "edit_feature", "body_transform"}) { + INFO(key); + CHECK(catalog.find(key) != nullptr); + } + const std::set<std::string> old = {"surface_extrude", "surface_revolve", "surface_loft", "surface_fill", + "thicken_surface", "surface_offset", "pattern_on_curve", "coordsys", + "mass_properties", "check_interference", "set_feature_expr", "transform"}; + for (const std::string& key : old) { + INFO(key); + CHECK(catalog.find(key) == nullptr); + } + // Bound to a name: a range-for over catalog_with_cad().commands() would walk a destroyed catalog. + const GUI::CommandCatalog with_cad = catalog_with_cad(); + for (const GUI::NativeCommand& c : with_cad.commands()) + for (const json& example : c.examples) + for (const json& call : example.at("calls")) { + INFO(c.key << " / " << example.value("title", "")); + CHECK(old.count(call.at("tool").get<std::string>()) == 0); + } + // Nor does a description: the names that are no English word. + for (const GUI::NativeCommand& c : with_cad.commands()) + for (const std::string& name : old) + if (name != "transform" && name != "coordsys") { + INFO(c.key << " / " << name); + CHECK(c.description.find(name) == std::string::npos); + CHECK(c.input_schema.dump().find(name) == std::string::npos); + } +} + +TEST_CASE("a Design command carries its row's icon", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + CHECK(command_of(catalog, "sketch").icon == "design_sketch"); + CHECK(command_of(catalog, "body_transform").icon == "design_move"); + // Its tile, titled as the right-click menu names its entry, in the tests' English UI. + const std::unique_ptr<GUI::AppAction> tile = GUI::NativeCommands::make_action(command_of(catalog, "sketch")); + REQUIRE(tile != nullptr); + CHECK(tile->id() == "orca_command:sketch:orca"); + CHECK(tile->group == "Design"); + CHECK(tile->title() == "Sketch"); + CHECK(GUI::NativeCommands::tile_title(command_of(catalog, "sketch")) == "Sketch"); + CHECK(std::string(GUI::title_context(command_of(catalog, "sketch"))) == "Design"); + CHECK(tile->icon == "design_sketch"); + CHECK(tile->command == "sketch"); +} + +TEST_CASE("the Design tiles' icons resolve to shipped SVGs", "[Mcp][CAD][SpeedDial]") +{ + // An icon comes from a hand-edited atlas row, so a typo would be a blank tile and a blank menu row. + const boost::filesystem::path images = boost::filesystem::path(PROFILES_DIR).parent_path() / "images"; + const GUI::CommandCatalog catalog = catalog_with_cad(); + std::size_t tiles = 0; + for (const GUI::NativeCommand& c : catalog.commands()) { + if (c.group != "Design" || c.icon.empty()) + continue; + INFO(c.key << " -> " << c.icon); + CHECK(boost::filesystem::exists(images / (c.icon + ".svg"))); + tiles += c.in_palette ? 1 : 0; + } + CHECK(tiles == 89); +} + +TEST_CASE("a tool refused for the selection says it does not apply and what it takes", "[Mcp][CAD]") +{ + // Delete Face takes a picked face. With nothing picked, the obstacle is the selection, not the document its + // row's refusal speaks of. + const GUI::DesignTool& delete_face = design_row("delete_face"); + const int none = int(GUI::OfferSel::None); + const std::optional<GUI::Mcp::ToolFailure> refused = GUI::Mcp::open_refusal(delete_face, false, none); + REQUIRE(refused.has_value()); + CHECK(std::string(refused->what()) == "This tool does not apply to what is selected"); + CHECK(refused->details.at("code") == -32000); + CHECK(refused->details.at("selection_kind") == 0); + CHECK(refused->details.at("selection") == "none"); + CHECK(refused->details.at("accepts") == json::array({"face_planar", "face_cyl", "face_other"})); + CHECK_FALSE(GUI::Mcp::open_refusal(delete_face, false, int(GUI::OfferSel::FacePlanar)).has_value()); + // Every row only the menu reaches says the same for a selection it does not take, in its own mode. + for (int i = 0; i < GUI::kDesignToolCount; ++i) { + const GUI::DesignTool& t = GUI::kDesignTools[i]; + if (t.action == nullptr || std::string(t.action).rfind("key:", 0) == 0) + continue; + INFO(t.id); + int miss = 0; + while (miss < int(GUI::OfferSel::Count) && (t.accepts & GUI::offer_bit(GUI::OfferSel(miss))) != 0) + ++miss; + REQUIRE(miss < int(GUI::OfferSel::Count)); + const std::optional<GUI::Mcp::ToolFailure> missed = GUI::Mcp::open_refusal(t, t.sketch_mode, miss); + REQUIRE(missed.has_value()); + CHECK(std::string(missed->what()) == "This tool does not apply to what is selected"); + CHECK(missed->details.at("selection") == GUI::kDesignSelectionIds[miss]); + } + // A key: action runs whatever is selected, as its key does. + CHECK_FALSE(GUI::Mcp::open_refusal(design_row("shell"), false, int(GUI::OfferSel::None)).has_value()); +} + +TEST_CASE("a Design tool opens only in the mode its row belongs to", "[Mcp][CAD]") +{ + const std::string in_sketch = "This tool works in a sketch: open a sketch first"; + const std::string on_model = "This tool works on the model: finish or cancel the sketch first"; + std::size_t sketch_rows = 0, model_rows = 0; + for (int i = 0; i < GUI::kDesignToolCount; ++i) { + const GUI::DesignTool& t = GUI::kDesignTools[i]; + if (t.action == nullptr) + continue; + INFO(t.id); + CHECK(GUI::Mcp::offered_in_mode(t, t.sketch_mode)); + CHECK_FALSE(GUI::Mcp::offered_in_mode(t, !t.sketch_mode)); + // In the other mode it is refused whatever is selected there, before the selection is looked at. + for (int kind = 0; kind < int(GUI::OfferSel::Count); ++kind) { + INFO(kind); + const std::optional<GUI::Mcp::ToolFailure> refused = GUI::Mcp::open_refusal(t, !t.sketch_mode, kind); + REQUIRE(refused.has_value()); + CHECK(std::string(refused->what()) == (t.sketch_mode ? in_sketch : on_model)); + CHECK(refused->details.at("code") == -32000); + CHECK(refused->details.at("mode") == (t.sketch_mode ? "sketch" : "model")); + } + ++(t.sketch_mode ? sketch_rows : model_rows); + } + CHECK(sketch_rows == 46); + CHECK(model_rows == 43); + // Shell opens on the model whatever is picked, and never over an open sketch. + CHECK_FALSE(GUI::Mcp::open_refusal(design_row("shell"), false, int(GUI::OfferSel::None)).has_value()); + CHECK(GUI::Mcp::open_refusal(design_row("shell"), true, int(GUI::OfferSel::SkNone)).has_value()); + CHECK_FALSE(GUI::Mcp::open_refusal(design_row("sk_rect"), true, int(GUI::OfferSel::SkNone)).has_value()); +} + +TEST_CASE("a pinned Design tile stays pinned while its tile is not shown", "[Mcp][CAD][SpeedDial]") +{ + CHECK(GUI::is_design_tile_id("orca_command:shell:orca")); + CHECK(GUI::is_design_tile_id("orca_command:sk_rect:orca")); + CHECK_FALSE(GUI::is_design_tile_id("orca_command:describe_scene:orca")); // a Design command with no tile + CHECK_FALSE(GUI::is_design_tile_id("orca_command:align:orca")); // an entry with no command + CHECK_FALSE(GUI::is_design_tile_id("orca_command:save_project:orca")); + CHECK_FALSE(GUI::is_design_tile_id("orca_plate_goto:shell:orca")); + CHECK_FALSE(GUI::is_design_tile_id("shell")); + // On the Prepare tab no Design tile is live, and the third plate is gone. + const std::string shell = "orca_command:shell:orca", rect = "orca_command:sk_rect:orca"; + const std::string save = "orca_command:save_project:orca", plate = "orca_plate_goto:2:orca"; + const std::set<std::string> live = {save}; + std::vector<std::string> stored, shown; + const auto is_live = [&](const std::string& id) { return live.count(id) != 0; }; + GUI::prune_favourites({shell, plate, save, rect}, is_live, stored, shown); + CHECK(stored == std::vector<std::string>{shell, save, rect}); + CHECK(shown == std::vector<std::string>{save}); +} + +TEST_CASE("a hidden Design pin takes no place on the favourites bar", "[Mcp][CAD][SpeedDial]") +{ + // Ten stored pins on the Prepare tab, three of them Design tiles, which are not live there. + const std::vector<std::string> design = {"orca_command:shell:orca", "orca_command:sk_rect:orca", "orca_command:fillet:orca"}; + std::vector<std::string> favs; + for (int i = 1; i <= 7; ++i) + favs.push_back("orca_command:command" + std::to_string(i) + ":orca"); + favs.insert(favs.begin() + 2, design.begin(), design.end()); + REQUIRE(favs.size() == 10); + const auto is_live = [&](const std::string& id) { return std::find(design.begin(), design.end(), id) == design.end(); }; + std::vector<std::string> stored, shown; + GUI::prune_favourites(favs, is_live, stored, shown); + CHECK(shown.size() == 7); + // Another pin is taken, and all eleven stay stored. + std::vector<std::string> pinned = favs; + CHECK(GUI::add_favourite(pinned, "orca_command:new_project:orca", is_live)); + CHECK(pinned.size() == 11); + GUI::prune_favourites(pinned, is_live, stored, shown); + CHECK(stored == pinned); + CHECK(shown.size() == 8); +} + +TEST_CASE("the Design tab's tiles are its mode's tools, and none with the CAD feature off", "[Mcp][CAD][SpeedDial]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + for (const bool sketching : {false, true}) { + INFO("sketching " << sketching); + std::set<std::string> tiles; + for (const GUI::NativeCommand* command : GUI::Mcp::design_tiles(catalog, sketching, /*cad_on=*/true)) + tiles.insert(command->key); + for (const GUI::NativeCommand& command : catalog.commands()) { + INFO(command.key); + const GUI::DesignTool* entry = GUI::Mcp::find_design_tool(command.key); + REQUIRE(entry != nullptr); + CHECK(tiles.count(command.key) == (command.in_palette && entry->sketch_mode == sketching ? 1u : 0u)); + } + CHECK(tiles.count(sketching ? "sk_rect" : "shell") == 1); + // Turned off while the app runs, the tab stays until a restart, and has no tile. + CHECK(GUI::Mcp::design_tiles(catalog, sketching, /*cad_on=*/false).empty()); + } +} + +TEST_CASE("a Design command with a read block is read-only", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + CHECK(command_of(catalog, "describe_scene").read_only); + CHECK(command_of(catalog, "query_topology").read_only); + CHECK_FALSE(command_of(catalog, "extrude").read_only); + CHECK_FALSE(command_of(catalog, "sketch_add").read_only); +} + +TEST_CASE("a CAD command's schema says what its row says", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + const GUI::NativeCommand& fillet = command_of(catalog, "fillet"); + CHECK(required_of(fillet) == std::vector<std::string>{"edge"}); + const json radius = property_of(fillet, "radius"); + CHECK(radius.at("type") == "number"); + CHECK(radius.at("default") == 1); + CHECK(radius.at("exclusiveMinimum") == 0); + CHECK_FALSE(radius.contains("minimum")); + CHECK_THAT(radius.at("description").get<std::string>(), ContainsSubstring("mm")); + CHECK(property_of(fillet, "edge").at("type") == json::array({"integer", "array"})); + CHECK(property_of(fillet, "body").at("default") == -1); + // Every command with a silent form takes the generation its face and edge ids were read at, and none + // requires it; one with only a person's form takes no argument. + for (const GUI::NativeCommand& c : catalog.commands()) { + INFO(c.key); + if (design_row(c.key).doc == nullptr) { + CHECK(c.input_schema.at("properties").empty()); + CHECK(c.input_schema.at("additionalProperties") == false); + continue; + } + const json generation = property_of(c, "generation"); + REQUIRE(generation.is_object()); + CHECK(generation.at("type") == "integer"); + CHECK(generation.at("minimum") == 0); + CHECK_FALSE(generation.at("description").get<std::string>().empty()); + // A param is required when its row gives it no default, and only then. + const std::vector<std::string> required = required_of(c); + for (const auto& [name, prop] : c.input_schema.at("properties").items()) { + INFO(name); + const bool is_required = std::find(required.begin(), required.end(), name) != required.end(); + CHECK(is_required == (name != "generation" && name != "silent" && !prop.contains("default"))); + } + // An argument the row does not name is not refused: the function reads the names it knows. + CHECK(c.input_schema.value("additionalProperties", true) == true); + } + // A type of two kinds, a limit, an enum and a default carry over. + CHECK(property_of(command_of(catalog, "sketch_begin"), "plane").at("type") == json::array({"string", "object"})); + CHECK(property_of(command_of(catalog, "plane"), "type").at("enum").size() == 6); + const json count = property_of(command_of(catalog, "sketch_transform"), "count"); + CHECK(count.at("minimum") == 2); + CHECK(count.at("maximum") == 1000); + // export_step's path has no default, so it is required; sketch_transform's angle defaults to null. + CHECK(required_of(command_of(catalog, "export_step")) == std::vector<std::string>{"path"}); + CHECK(property_of(command_of(catalog, "sketch_transform"), "angle").at("default").is_null()); +} + +TEST_CASE("a CAD command's limit is the one its function applies", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + // A negative distance grows the surface against the sketch plane's normal. + json backwards{{"sketch", 0}, {"distance", -5}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "surf_extrude"), backwards).empty()); + // A fillet's radius is refused at zero, as its function refuses it, and a small one is not. + json flat{{"edge", 0}, {"radius", 0}}; + CHECK_THAT(GUI::Mcp::argument_error(command_of(catalog, "fillet"), flat), ContainsSubstring("radius")); + json small{{"edge", 0}, {"radius", 0.005}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "fillet"), small).empty()); +} + +TEST_CASE("a CAD param whose default is null takes null, which its function reads as left out", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + // No limit; the open sketch's constraints; an extrude that joins the body its profile touches. + json no_limit{{"limit", nullptr}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "query_topology"), no_limit).empty()); + json open_sketch{{"sketch", nullptr}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "sketch_constraints"), open_sketch).empty()); + json auto_mode{{"boolean", nullptr}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "extrude"), auto_mode).empty()); + // A two-form command given only a null runs its silent form, the default rectangle: the argument stays, so the + // call is not the person's, which would open the Extrude card. + json rectangle{{"sketch", nullptr}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "extrude"), rectangle).empty()); + CHECK(rectangle == json{{"sketch", nullptr}}); + CHECK_FALSE(GUI::Mcp::person_form(rectangle)); + // A param whose default is a value refuses null, as does one whose function would read a null as given. + json no_distance{{"distance", nullptr}}; + CHECK_THAT(GUI::Mcp::argument_error(command_of(catalog, "extrude"), no_distance), ContainsSubstring("distance")); + json no_angle{{"op", "rotate"}, {"angle", nullptr}}; + CHECK_THAT(GUI::Mcp::argument_error(command_of(catalog, "sketch_transform"), no_angle), ContainsSubstring("angle")); + // One kind still stands for the list of it. + json one_kind{{"kinds", "planar"}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "query_topology"), one_kind).empty()); + CHECK(one_kind == json{{"kinds", {"planar"}}}); + + // Every param whose default is null admits null, but these, whose functions read a null as given: thread on a + // plane resolves `plane` as the plane named, and sketch_transform tells an op's own params by their presence. + const std::set<std::pair<std::string, std::string>> as_given{ + {"thread", "plane"}, {"sketch_transform", "angle"}, {"sketch_transform", "scale"}, + {"sketch_transform", "count"}, {"sketch_transform", "pivot"}}; + int admitting = 0; + for (const GUI::NativeCommand& c : catalog.commands()) + for (const auto& [name, prop] : c.input_schema.at("properties").items()) { + if (!prop.contains("default") || !prop.at("default").is_null()) + continue; + INFO(c.key << "." << name); + const json& type = prop.at("type"); + const bool admits = type.is_array() && std::find(type.begin(), type.end(), "null") != type.end(); + CHECK(admits == (as_given.count({c.key, name}) == 0)); + if (prop.contains("enum")) + CHECK((std::find(prop.at("enum").begin(), prop.at("enum").end(), nullptr) != prop.at("enum").end()) == admits); + admitting += admits; + } + CHECK(admitting == 36); +} + +TEST_CASE("a CAD command takes the names its function also reads", "[Mcp][CAD]") +{ + // describe_feature and the tree edits read `index` as `feature`, and set_feature `params` or `values` as + // `fields`: what agents often call them. The call is read as the schema names them. + const GUI::CommandCatalog catalog = cad_catalog(); + json set{{"index", 0}, {"params", {{"width", 20}}}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "set_feature"), set).empty()); + CHECK(set == json{{"feature", 0}, {"fields", {{"width", 20}}}}); + json values{{"feature", 0}, {"values", {{"width", 30}}}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "set_feature"), values).empty()); + CHECK(values == json{{"feature", 0}, {"fields", {{"width", 30}}}}); + json describe{{"index", 1}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "describe_feature"), describe).empty()); + CHECK(describe == json{{"feature", 1}}); + // A command that takes `index` itself keeps it. + json unconstrain{{"index", 4}}; + CHECK(GUI::Mcp::argument_error(command_of(catalog, "sketch_unconstrain"), unconstrain).empty()); + CHECK(unconstrain == json{{"index", 4}}); +} + +TEST_CASE("a CAD command's summary is one sentence of at most 120 characters", "[Mcp][CAD]") +{ + const GUI::CommandCatalog catalog = cad_catalog(); + for (const GUI::NativeCommand& c : catalog.commands()) { + INFO(c.key); + const std::string summary = GUI::Mcp::first_sentence(c.description); REQUIRE_FALSE(summary.empty()); CHECK(summary.size() <= 120); - CHECK(GUI::Mcp::first_sentence(summary) == summary); CHECK(summary.back() == '.'); } + // The description goes on with the row's details, and with how a rejected rebuild shows when the reply says it. + CHECK_THAT(command_of(catalog, "sketch_transform").description, ContainsSubstring("polar")); + CHECK_THAT(command_of(catalog, "fillet").description, ContainsSubstring("ok is false")); + CHECK_THAT(command_of(catalog, "extrude").description, !ContainsSubstring("ok is false")); + // One with an action only does what its row does, which for Delete Body is to delete it at once. + CHECK_THAT(command_of(catalog, "delete_body").description, ContainsSubstring("or act at once")); + CHECK_THAT(command_of(catalog, "delete_body").description, !ContainsSubstring("opens the tool")); } -TEST_CASE("list_cad_tools narrows by a query in any case and counts what it kept", "[Mcp][CAD]") +TEST_CASE("a Design command with a person's form says which mode it runs in", "[Mcp][CAD]") { - const json sketch = GUI::Mcp::cad_list_tools("SKETCH_"); - const std::vector<std::string> names = row_names(sketch); - CHECK(std::find(names.begin(), names.end(), "sketch_add") != names.end()); - for (const std::string& n : names) CHECK_THAT(n, ContainsSubstring("sketch_")); - CHECK(sketch.at("total") == names.size()); - CHECK(names.size() < GUI::Mcp::cad_tool_names().size()); - - const json none = GUI::Mcp::cad_list_tools("zzzz"); - CHECK(none.at("items").empty()); - CHECK(none.at("total") == 0); -} - -TEST_CASE("list_cad_tools finds a tool by a word only its details hold", "[Mcp][CAD]") -{ - const json described = GUI::Mcp::cad_describe_tool("sketch_transform").at("tools").at(0); - CHECK(described.at("summary").get<std::string>().find("polar") == std::string::npos); - CHECK_THAT(described.at("details").get<std::string>(), ContainsSubstring("polar")); - - const json listed = row_of(GUI::Mcp::cad_list_tools("polar"), "sketch_transform"); - REQUIRE_FALSE(listed.is_null()); - CHECK(listed.size() == 3); // the summary only -} - -TEST_CASE("describe_cad_tool takes a name or a list and describes each once", "[Mcp][CAD]") -{ - const json one = GUI::Mcp::cad_describe_tool("extrude"); - REQUIRE(one.at("tools").size() == 1); - const json extrude = one.at("tools").at(0); - CHECK(extrude.at("name") == "extrude"); - CHECK(extrude.at("access") == "change"); - CHECK_FALSE(extrude.at("summary").get<std::string>().empty()); - CHECK(extrude.at("details").is_string()); - CHECK(extrude.at("params").is_array()); - CHECK(extrude.at("failure") == "error"); - CHECK_FALSE(extrude.contains("failure_note")); - CHECK(extrude.at("examples").is_array()); - - const json two = GUI::Mcp::cad_describe_tool(json::array({"hole", "fillet", "hole"})); - std::vector<std::string> names; - for (const json& row : two.at("tools")) names.push_back(row.at("name").get<std::string>()); - CHECK(names == std::vector<std::string>{"hole", "fillet"}); // in the order asked, each once - const json fillet = row_of(two, "fillet"); - CHECK(fillet.at("failure") == "reply"); - CHECK_FALSE(fillet.at("failure_note").get<std::string>().empty()); -} - -TEST_CASE("describe_cad_tool refuses an unknown name with the close ones", "[Mcp][CAD]") -{ - auto refusal = [](const json& tool) { return failure([&] { GUI::Mcp::cad_describe_tool(tool); }); }; - CHECK_THAT(refusal("extrud"), ContainsSubstring("Unknown CAD tool: extrud")); - CHECK_THAT(refusal("extrud"), ContainsSubstring("extrude")); - for (const json& bad : {json(3), json(""), json::array(), json::array({"hole", 3})}) { - INFO(bad.dump()); - CHECK_THAT(refusal(bad), ContainsSubstring("a name or a list of names")); + const std::string in_sketch = "It runs only in an open sketch", outside = "It runs only outside a sketch"; + const GUI::CommandCatalog catalog = cad_catalog(); + std::size_t told = 0; + for (const GUI::NativeCommand& c : catalog.commands()) { + const GUI::DesignTool& row = design_row(c.key); + if (row.action == nullptr) + continue; + INFO(c.key); + // An action only: its description says it. Both forms: the `silent` property, which says what the call + // with no arguments does, as the description is the silent form's. + const std::string text = row.doc == nullptr ? c.description + : property_of(c, "silent").value("description", std::string()); + CHECK_THAT(text, ContainsSubstring(row.sketch_mode ? in_sketch : outside)); + CHECK_THAT(text, !ContainsSubstring(row.sketch_mode ? outside : in_sketch)); + ++told; } + CHECK(told == 89); + CHECK_THAT(command_of(catalog, "sk_rect").description, ContainsSubstring(in_sketch)); + CHECK_THAT(command_of(catalog, "delete_body").description, ContainsSubstring(outside)); + CHECK_THAT(property_of(command_of(catalog, "shell"), "silent").value("description", std::string()), + ContainsSubstring("opens nothing")); } -TEST_CASE("describe_cad_tool marks a param without a default required", "[Mcp][CAD]") +TEST_CASE("no CAD command exists with the feature off", "[Mcp][CAD]") { - auto param = [](const char* tool, const char* name) { - const json reply = GUI::Mcp::cad_describe_tool(tool); - for (const json& p : reply.at("tools").at(0).at("params")) - if (p.at("name") == name) return p; - FAIL(tool << " has no param " << name); - return json(); + const auto design_commands = [](bool cad) { + GUI::CommandCatalog catalog; + GUI::NativeCommands::register_all_commands(catalog, {cad}); + std::size_t count = 0; + for (const GUI::NativeCommand& c : catalog.commands()) + if (c.group == "Design") + ++count; + return count; }; - CHECK(param("export_step", "path").at("required") == true); - CHECK(param("sketch_transform", "angle").at("required") == false); // "default": null - - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - for (const json& row : all.at("tools")) - for (const json& p : row.at("params")) { - INFO(row.at("name").get<std::string>() << " " << p.at("name").get<std::string>()); - REQUIRE(p.contains("required")); - CHECK(p.at("required").is_boolean()); - CHECK(p.at("required") == !p.contains("default")); - } + CHECK(design_commands(false) == 0); + CHECK(design_commands(true) == 133); } -TEST_CASE("describe_cad_tool gives id_lifetime only for tools that take or give ids", "[Mcp][CAD]") +TEST_CASE("a CAD call is journaled without its generation and with its silent", "[Mcp][CAD]") { - CHECK(GUI::Mcp::cad_describe_tool("fillet").contains("id_lifetime")); - CHECK(GUI::Mcp::cad_describe_tool("query_topology").contains("id_lifetime")); - CHECK(GUI::Mcp::cad_describe_tool("describe_feature").contains("id_lifetime")); // its refs hold face and edge ids - CHECK_FALSE(GUI::Mcp::cad_describe_tool("describe_scene").contains("id_lifetime")); - CHECK(GUI::Mcp::cad_describe_tool(json::array({"describe_scene", "fillet"})).contains("id_lifetime")); + json seen; + const GUI::NativeCommand fillet = GUI::Mcp::cad_command("fillet", "Fillet", json{{"type", "object"}, {"properties", json::object()}}, + [&seen](const json& args) { + seen = args; + return json{{"ok", true}}; + }); + CHECK(fillet.group == "Design"); + CHECK_FALSE(fillet.listed); - // A tool takes ids through a face or edge param, or through a plane that may be a planar face; these - // give them in their replies. - const std::set<std::string> gives_ids = {"query_topology", "measure", "slice_body", "describe_feature"}; - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - for (const json& row : all.at("tools")) { - const std::string name = row.at("name").get<std::string>(); - INFO(name); - CHECK_FALSE(row.contains("ids")); - bool ids = gives_ids.count(name) != 0; - for (const json& p : row.at("params")) - if (is_id_param(p.at("name").get<std::string>()) || takes_face_plane(p)) ids = true; - CHECK(GUI::Mcp::cad_describe_tool(name).contains("id_lifetime") == ids); - } + JournalContext agent; + const GUI::Mcp::ToolResult reply = fillet.run({{"generation", 4}, {"silent", true}, {"radius", 2}}, agent); + CHECK(agent.journaled == json{{"silent", true}, {"radius", 2}}); + // The function still checks the generation, and the reply wraps its value. + CHECK(seen == json{{"generation", 4}, {"silent", true}, {"radius", 2}}); + CHECK_FALSE(reply.is_error); + CHECK(reply.data == json{{"result", {{"ok", true}}}}); + + // A person's pick runs the function in place, with the same reply, and journals nothing. + JournalContext person(/*person=*/true); + CHECK(fillet.run(json::object(), person).data == json{{"result", {{"ok", true}}}}); + CHECK(person.journaled.is_null()); + + // A silent call of a command that also has a person's form, which gives nothing but its generation, is + // journaled silent: with no arguments, its replay would open the tool. + const GUI::NativeCommand shell = GUI::Mcp::cad_command( + "shell", "Shell", GUI::Mcp::with_silent(json{{"type", "object"}, {"properties", json::object()}}), + [](const json&) { return json{{"ok", true}}; }); + JournalContext generation_only; + shell.run({{"generation", 4}}, generation_only); + CHECK(generation_only.journaled == json{{"silent", true}}); + // One with a silent form only has no `silent` to journal. + JournalContext read; + fillet.run({{"generation", 4}}, read); + CHECK(read.journaled == json::object()); + + // A failure is the call's error. + const GUI::NativeCommand refused = GUI::Mcp::cad_command("hole", "Hole", json{{"type", "object"}, {"properties", json::object()}}, + [](const json&) -> json { + throw GUI::Mcp::ToolFailure("removed no material", {{"code", -32000}}); + }); + CHECK_THROWS_AS(refused.run(json::object(), agent), GUI::Mcp::ToolFailure); } -TEST_CASE("list_verbs names the row and the family submenu each verb sits in", "[Mcp][CAD]") +TEST_CASE("an unknown command is answered with close names only", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_list_verbs(int(GUI::OfferSel::SkNone), json{{"sketch_mode", true}}); - std::map<std::string, json> verbs; - for (const json& v : reply.at("verbs")) { - CHECK(v.at("sketch_mode") == true); - verbs[v.at("id").get<std::string>()] = v; - } - // The offer lists the corner rectangle at Create > Rectangle > Corner rectangle. - const json& rect = verbs.at("sk_rect"); - CHECK(rect.at("row_name") == "Create"); - CHECK(rect.at("family") == "Rectangle"); - CHECK(rect.at("name") == "Corner rectangle"); - CHECK(rect.at("applies") == true); - CHECK(verbs.at("sk_rect_center").at("family") == "Rectangle"); - CHECK(verbs.at("sk_spline").at("family").is_null()); // directly in Create - CHECK(verbs.at("sk_dimension").at("family").is_null()); - CHECK(verbs.at("sk_offset").at("applies") == false); // it needs a picked line, curve or pair - - const json model = GUI::Mcp::cad_list_verbs(int(GUI::OfferSel::None), json{{"sketch_mode", false}}); - const json& sketch = model.at("verbs").at(0); - CHECK(sketch.at("id") == "sketch"); - CHECK(sketch.at("row_name") == "Create"); - CHECK(sketch.at("family").is_null()); // the feature-mode Sketch sits directly in Create -} - -TEST_CASE("the CAD-off note is given when the UI says the feature is off, and only then", "[Mcp][CAD]") -{ - UiReadContext ctx; - ctx.answer = false; - const json off = GUI::Mcp::cad_feature_note(ctx); - REQUIRE(off.is_string()); - CHECK_THAT(off.get<std::string>(), ContainsSubstring("Preferences")); - - ctx.answer = true; - CHECK(GUI::Mcp::cad_feature_note(ctx).is_null()); - - // The note is advice: a UI that does not answer leaves it out rather than failing the reply. - ctx.answers = false; - CHECK(GUI::Mcp::cad_feature_note(ctx).is_null()); + const GUI::CommandCatalog catalog = cad_catalog(); + const std::string unknown = catalog.unknown_command("extrud", /*suggest=*/true); + // The closest key, and no sentence about another tool. + CHECK(unknown == "Unknown tool: extrud (did you mean extrude?)"); } namespace { -// Whether an example may pass `key` to a tool with these params: one of them, the generation the -// dispatcher checks on every tool, or <p>_deg for a param <p> in radians, which the tool also reads -// in degrees. -bool takes_arg(const json& params, const std::string& key) +// Whether `command` takes the argument `key`: a property of its schema, or <p>_deg for a property <p> in +// radians, which the function also reads in degrees. +bool takes_arg(const GUI::NativeCommand& command, const std::string& key) { - if (key == "generation") return true; - for (const json& p : params) { - const std::string name = p.at("name").get<std::string>(); - if (key == name) return true; - if (key == name + "_deg" && p.value("unit", "") == "rad") return true; - } - return false; + const json& properties = command.input_schema.at("properties"); + if (properties.contains(key)) return true; + const std::string suffix = "_deg"; + if (key.size() <= suffix.size() || key.compare(key.size() - suffix.size(), suffix.size(), suffix) != 0) return false; + const auto radians = properties.find(key.substr(0, key.size() - suffix.size())); + if (radians == properties.end()) return false; + // cad_input_schema() writes a param's unit into its description. + const std::string description = radians->value("description", std::string()); + const std::string unit = " (rad)"; + return description == "In rad." || + (description.size() > unit.size() && description.compare(description.size() - unit.size(), unit.size(), unit) == 0); } // Whether an example passes a face or edge id as `key`: a param that takes ids, or a reference that @@ -425,16 +856,24 @@ bool passes_id(const std::string& key, const json& value) return false; } +// Whether `value` is {"from_call": i, "key": k}: the value under k in the reply of call i of the example. +bool from_call(const json& value) { return value.is_object() && value.contains("from_call"); } + } // namespace -TEST_CASE("every CAD tool example calls real tools with arguments they declare", "[Mcp][CAD]") +TEST_CASE("every example passes its command's schema", "[Mcp][CAD]") { - const std::vector<std::string> names = GUI::Mcp::cad_tool_names(); - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - for (const json& row : all.at("tools")) - for (const json& example : row.at("examples")) { + // The Design commands' and undo's and redo's, which a run with the CAD feature on documents with them. + const GUI::CommandCatalog catalog = catalog_with_cad(); + std::size_t described = 0; + for (const GUI::NativeCommand& c : catalog.commands()) { + if (c.examples.is_null()) + continue; + ++described; + REQUIRE(c.examples.is_array()); + for (const json& example : c.examples) { const std::string title = example.value("title", ""); - INFO(row.at("name").get<std::string>() << " / " << title); + INFO(c.key << " / " << title); CHECK_FALSE(title.empty()); for (const auto& item : example.items()) CHECK_THAT(item.key(), Equals("title") || Equals("calls") || Equals("needs")); @@ -446,14 +885,16 @@ TEST_CASE("every CAD tool example calls real tools with arguments they declare", INFO("call " << i << ": " << tool); for (const auto& item : calls[i].items()) CHECK_THAT(item.key(), Equals("tool") || Equals("args")); - REQUIRE(std::find(names.begin(), names.end(), tool) != names.end()); - const json params = row_of(all, tool).at("params"); - const json& args = calls[i].at("args"); - REQUIRE(args.is_object()); - for (const auto& [key, value] : args.items()) { + const GUI::NativeCommand& called = command_of(catalog, tool); + REQUIRE(calls[i].at("args").is_object()); + // What an earlier call gives is left out; the rest is what the call sends. + json sent = json::object(); + for (const auto& [key, value] : calls[i].at("args").items()) { INFO("argument " << key); - CHECK(takes_arg(params, key)); - if (!value.is_object() || !value.contains("from_call")) continue; + if (!from_call(value)) { + sent[key] = value; + continue; + } const json& from = value.at("from_call"); REQUIRE(from.is_number_integer()); CHECK(from.get<int>() >= 0); @@ -461,35 +902,46 @@ TEST_CASE("every CAD tool example calls real tools with arguments they declare", REQUIRE(value.contains("key")); REQUIRE(value.at("key").is_string()); CHECK_FALSE(value.at("key").get<std::string>().empty()); + // What a later call is given still goes by a name the command takes. + CHECK(takes_arg(called, key)); + } + // With no arguments, a command that has a person's form would open its tool instead. + if (two_forms(called)) + CHECK_FALSE(sent.empty()); + CHECK(GUI::Mcp::argument_error(called, sent) == ""); + // The schema lets other names through, which the function then ignores, so a misspelt one + // would pass. argument_error() has put an alias under the name it stands for. + for (const auto& item : sent.items()) { + INFO("argument " << item.key()); + CHECK(takes_arg(called, item.key())); } - for (const json& p : params) - if (p.at("required").get<bool>()) { - INFO("required " << p.at("name").get<std::string>()); - CHECK(args.contains(p.at("name").get<std::string>())); - } } + // An example ends with the command it documents. + CHECK(calls.back().at("tool") == c.key); } + } + // The 76 Design commands with a silent form, undo and redo. + CHECK(described == 78); } -TEST_CASE("every CAD tool example ends with the tool it describes", "[Mcp][CAD]") +TEST_CASE("an example's argument goes by a name its command takes", "[Mcp][CAD]") { - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - for (const json& row : all.at("tools")) - for (const json& example : row.at("examples")) { - INFO(row.at("name").get<std::string>() << " / " << example.value("title", "")); - REQUIRE_FALSE(example.at("calls").empty()); - CHECK(example.at("calls").back().at("tool") == row.at("name")); - } + const GUI::CommandCatalog catalog = cad_catalog(); + CHECK(takes_arg(command_of(catalog, "fillet"), "radius")); + CHECK_FALSE(takes_arg(command_of(catalog, "fillet"), "radious")); + // A param in radians is also read in degrees, and only such a param. + CHECK(takes_arg(command_of(catalog, "sketch_transform"), "angle_deg")); + CHECK_FALSE(takes_arg(command_of(catalog, "fillet"), "radius_deg")); } // A stale id still names a real face or edge, so an example that passes ids shows the safe pattern: // read them with query_topology and pass that reply's generation with the call. -TEST_CASE("every CAD tool example that passes a face or edge id passes the generation it was read at", "[Mcp][CAD]") +TEST_CASE("every example that passes a face or edge id passes the generation it was read at", "[Mcp][CAD]") { - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - for (const json& row : all.at("tools")) - for (const json& example : row.at("examples")) { - INFO(row.at("name").get<std::string>() << " / " << example.value("title", "")); + const GUI::CommandCatalog catalog = cad_catalog(); + for (const GUI::NativeCommand& c : catalog.commands()) + for (const json& example : c.examples) { + INFO(c.key << " / " << example.value("title", "")); const json& calls = example.at("calls"); for (size_t i = 0; i < calls.size(); ++i) { const json& args = calls[i].at("args"); @@ -510,14 +962,28 @@ TEST_CASE("every CAD tool example that passes a face or edge id passes the gener } } -TEST_CASE("every CAD tool has one to three examples", "[Mcp][CAD]") +TEST_CASE("every CAD command with a silent form has one to three examples", "[Mcp][CAD]") { - const json all = GUI::Mcp::cad_describe_tool(all_cad_tools()); - REQUIRE(all.at("tools").size() == GUI::Mcp::cad_tool_names().size()); - for (const json& row : all.at("tools")) { - INFO(row.at("name").get<std::string>()); - CHECK(row.at("examples").size() >= 1); - CHECK(row.at("examples").size() <= 3); + const GUI::CommandCatalog catalog = cad_catalog(); + for (const GUI::NativeCommand& c : catalog.commands()) { + INFO(c.key); + // A command with an action and no silent form takes no arguments, so there is no call to show. + if (design_row(c.key).doc == nullptr) { + CHECK(c.examples.is_null()); + continue; + } + REQUIRE(c.examples.is_array()); + CHECK(c.examples.size() >= 1); + CHECK(c.examples.size() <= 3); + } + // undo and redo document the Design history only where the Design commands are. + GUI::CommandCatalog without; + GUI::NativeCommands::register_all_commands(without, {false}); + const GUI::CommandCatalog with = catalog_with_cad(); + for (const char* key : {"undo", "redo"}) { + INFO(key); + CHECK(command_of(without, key).examples.is_null()); + CHECK(command_of(with, key).examples.size() == 2); } } @@ -699,7 +1165,7 @@ TEST_CASE("describe_feature names constraint references as the solver reads them CHECK(c[0].at("refs") == json::array({json{{"entity", 0}}, json{{"entity", 1}}})); // whole lines, no roles CHECK_FALSE(c[0].contains("value")); CHECK(c[1].at("type") == "angle"); - CHECK_THAT(c[1].at("value").get<double>(), WithinAbs(90.0, 1e-9)); // degrees, as call_cad_tool takes angles + CHECK_THAT(c[1].at("value").get<double>(), WithinAbs(90.0, 1e-9)); // degrees, as the Design commands take angles CHECK(c[2].at("refs")[1] == json{{"entity", "origin"}}); CHECK(c[3].at("type") == "point_on_line"); CHECK(c[3].at("refs") == json::array({json{{"entity", 1}, {"role", "p1"}}, json{{"entity", 0}}})); @@ -815,6 +1281,8 @@ TEST_CASE("set_feature refuses what the card would not produce, changing nothing CHECK_THAT(failure([&] { GUI::Mcp::cad_apply_feature_fields(doc.features[1], {{"distance", 15}}); }), ContainsSubstring("driven by the expression 'h'")); + CHECK_THAT(failure([&] { GUI::Mcp::cad_apply_feature_fields(doc.features[1], {{"distance", 15}}); }), + ContainsSubstring("remove the binding with edit_feature {field: 'distance', expr: ''}")); CHECK_THAT(failure([&] { GUI::Mcp::cad_apply_feature_fields(ex, {{"depth", 1}}); }), ContainsSubstring("editable: distance, distance2, taper_deg, extrude_end, flip, mode")); CHECK_THAT(failure([&] { GUI::Mcp::cad_apply_feature_fields(ex, {{"sketch_ref", 2}}); }), @@ -925,19 +1393,16 @@ TEST_CASE("literal edits and bindings reach the same numeric fields", "[Mcp][CAD TEST_CASE("commit, new_design and export_step change the design or the plate, and fail as errors", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_describe_tool(json::array({"commit", "new_design", "export_step"})); - REQUIRE(reply.at("tools").size() == 3); - for (const json& row : reply.at("tools")) { - INFO(row.at("name").get<std::string>()); - CHECK(row.at("access") == "change"); - CHECK(row.at("failure") == "error"); + const GUI::CommandCatalog catalog = cad_catalog(); + for (const char* key : {"commit", "new_design", "export_step"}) { + INFO(key); + const GUI::NativeCommand& c = command_of(catalog, key); + CHECK_FALSE(c.read_only); + // A failure is the call's error, not a reply whose ok is false. + CHECK_THAT(c.description, !ContainsSubstring("ok is false")); } - // export_step's path has no default, so it is required. - for (const json& row : reply.at("tools")) - if (row.at("name") == "export_step") - for (const json& p : row.at("params")) - if (p.at("name") == "path") CHECK(p.at("required") == true); + CHECK(required_of(command_of(catalog, "export_step")) == std::vector<std::string>{"path"}); } TEST_CASE("commit's replace takes distinct object indices that are not part of a cut", "[Mcp][CAD]") @@ -988,29 +1453,21 @@ TEST_CASE("export_step's STEP file reads back with each body where the Move gizm CHECK((shifted.center_of_mass - box.center_of_mass - Vec3d(50, 0, 0)).norm() < 1e-6); } -TEST_CASE("undo, redo and the tree and body edits are rows with the access their gate needs", "[Mcp][CAD]") +TEST_CASE("the tree and body edits change the design, fail as errors and require what they edit", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_describe_tool(json::array({"undo", "redo", "feature_delete", "feature_move", "feature_set_enabled", - "feature_rename", "body_set", "body_delete"})); - REQUIRE(reply.at("tools").size() == 8); - std::map<std::string, std::vector<std::string>> required; - for (const json& row : reply.at("tools")) { - const std::string name = row.at("name").get<std::string>(); - INFO(name); - // Undo and redo run in a sketch session too, where they act on the drawn shapes. - CHECK(row.at("access") == (name == "undo" || name == "redo" ? "sketch" : "change")); - CHECK(row.at("failure") == "error"); - for (const json& p : row.at("params")) - if (p.at("required") == true) required[name].push_back(p.at("name").get<std::string>()); + const GUI::CommandCatalog catalog = cad_catalog(); + for (const char* key : {"feature_delete", "feature_move", "feature_set_enabled", "feature_rename", "body_set", "body_delete"}) { + INFO(key); + CHECK_FALSE(command_of(catalog, key).read_only); + CHECK_THAT(command_of(catalog, key).description, !ContainsSubstring("ok is false")); } // The params each one requires. - CHECK(required["undo"].empty()); - CHECK(required["feature_delete"] == std::vector<std::string>{"feature"}); - CHECK(required["feature_move"] == std::vector<std::string>{"feature", "delta"}); - CHECK(required["feature_set_enabled"] == std::vector<std::string>{"feature", "enabled"}); - CHECK(required["feature_rename"] == std::vector<std::string>{"feature", "name"}); - CHECK(required["body_set"] == std::vector<std::string>{"body"}); - CHECK(required["body_delete"] == std::vector<std::string>{"body"}); + CHECK(required_of(command_of(catalog, "feature_delete")) == std::vector<std::string>{"feature"}); + CHECK(required_of(command_of(catalog, "feature_move")) == std::vector<std::string>{"feature", "delta"}); + CHECK(required_of(command_of(catalog, "feature_set_enabled")) == std::vector<std::string>{"feature", "enabled"}); + CHECK(required_of(command_of(catalog, "feature_rename")) == std::vector<std::string>{"feature", "name"}); + CHECK(required_of(command_of(catalog, "body_set")) == std::vector<std::string>{"body"}); + CHECK(required_of(command_of(catalog, "body_delete")) == std::vector<std::string>{"body"}); } TEST_CASE("abandon_checkpoint drops the refused edit's undo step and keeps what was redoable", "[Mcp][CAD]") @@ -1347,24 +1804,25 @@ TEST_CASE("revolve without a sketch turns a width by height rectangle lying besi TEST_CASE("the sketch-to-solid rows take a sketch, and sketch_begin takes every plane form", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_describe_tool(json::array({"sketch_begin", "sketch_describe", "extrude", "revolve"})); - std::map<std::string, std::map<std::string, json>> params; - for (const json& row : reply.at("tools")) { - const std::string name = row.at("name").get<std::string>(); - INFO(name); - CHECK(row.at("failure") == "error"); - for (const json& p : row.at("params")) params[name][p.at("name").get<std::string>()] = p; + const GUI::CommandCatalog catalog = cad_catalog(); + for (const char* key : {"sketch_begin", "sketch_describe", "extrude", "revolve"}) { + INFO(key); + CHECK_THAT(command_of(catalog, key).description, !ContainsSubstring("ok is false")); } - CHECK(row_of(reply, "sketch_describe").at("access") == "read"); // reads, so it also answers under an open card - CHECK(params["sketch_begin"]["plane"].at("type") == "string|object"); + CHECK(command_of(catalog, "sketch_describe").read_only); // reads, so it also answers under an open card + CHECK(property_of(command_of(catalog, "sketch_begin"), "plane").at("type") == json::array({"string", "object"})); // Optional everywhere: none of these is required. - CHECK(params["sketch_describe"]["sketch"].at("required") == false); - CHECK(params["extrude"]["sketch"].at("required") == false); - CHECK(params["extrude"]["loop"].at("required") == false); - CHECK(params["extrude"].count("body") == 1); - CHECK(params["revolve"]["sketch"].at("required") == false); - CHECK(params["revolve"]["axis_entity"].at("required") == false); - CHECK(params["revolve"].count("body") == 1); + CHECK(required_of(command_of(catalog, "sketch_describe")).empty()); + CHECK(required_of(command_of(catalog, "extrude")).empty()); + CHECK(required_of(command_of(catalog, "revolve")).empty()); + for (const char* key : {"sketch", "loop", "body"}) { + INFO(key); + CHECK(property_of(command_of(catalog, "extrude"), key).is_object()); + } + for (const char* key : {"sketch", "axis_entity", "body"}) { + INFO(key); + CHECK(property_of(command_of(catalog, "revolve"), key).is_object()); + } } namespace { @@ -1900,29 +2358,41 @@ TEST_CASE("plane refuses what the card refuses, and what a construction would no TEST_CASE("the rows for topology, measure, holes, push/pull and plane", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_describe_tool( - json::array({"query_topology", "measure", "hole", "hole_styled", "hole_standard", "extrude", "plane"})); - std::map<std::string, json> rows; - for (const json& row : reply.at("tools")) rows[row.at("name").get<std::string>()] = row; - auto param = [&](const char* tool, const char* name) { - for (const json& p : rows.at(tool).at("params")) - if (p.at("name") == name) return p; - FAIL(tool << " has no param " << name); - return json(); + const GUI::CommandCatalog catalog = cad_catalog(); + // The property `name` of command `key`, which the test needs it to have. + auto param = [&](const char* key, const char* name) { + const json p = property_of(command_of(catalog, key), name); + INFO(key << " " << name); + REQUIRE(p.is_object()); + return p; }; - CHECK(rows.at("plane").at("access") == "change"); - CHECK(rows.at("query_topology").at("access") == "read"); - CHECK(rows.at("measure").at("access") == "read"); - for (const char* t : {"hole", "hole_styled", "hole_standard", "extrude", "plane"}) CHECK(rows.at(t).at("failure") == "error"); + auto required = [&](const char* key, const char* name) { + const std::vector<std::string> req = required_of(command_of(catalog, key)); + return std::find(req.begin(), req.end(), name) != req.end(); + }; + CHECK_FALSE(command_of(catalog, "plane").read_only); + CHECK(command_of(catalog, "query_topology").read_only); + CHECK(command_of(catalog, "measure").read_only); + for (const char* t : {"hole", "hole_styled", "hole_standard", "extrude", "plane"}) { + INFO(t); + CHECK_THAT(command_of(catalog, t).description, !ContainsSubstring("ok is false")); + } // Optional everywhere: none of these is required. - for (const char* k : {"kinds", "edge_kinds", "direction", "at_extreme", "convex", "limit"}) - CHECK(param("query_topology", k).at("required") == false); + for (const char* k : {"kinds", "edge_kinds", "direction", "at_extreme", "convex", "limit"}) { + param("query_topology", k); + CHECK_FALSE(required("query_topology", k)); + } for (const char* hole : {"hole", "hole_styled", "hole_standard"}) { - CHECK(param(hole, "at").at("required") == false); + param(hole, "at"); + CHECK_FALSE(required(hole, "at")); CHECK(param(hole, "body").at("default") == -1); } - CHECK(param("extrude", "face").at("required") == false); - for (const char* k : {"face_a", "face_b", "edge_a", "edge_b"}) CHECK(param("plane", k).at("required") == false); + param("extrude", "face"); + CHECK_FALSE(required("extrude", "face")); + for (const char* k : {"face_a", "face_b", "edge_a", "edge_b"}) { + param("plane", k); + CHECK_FALSE(required("plane", k)); + } CHECK(param("plane", "type").at("enum").size() == 6); } @@ -2255,34 +2725,25 @@ TEST_CASE("split cuts a body with a plane and keeps either piece", "[Mcp][CAD]") TEST_CASE("the rows for thread, sweep, loft, split and helix", "[Mcp][CAD]") { - const json reply = GUI::Mcp::cad_describe_tool(json::array({"thread", "sweep", "loft", "split", "helix"})); - std::map<std::string, json> rows; - for (const json& row : reply.at("tools")) rows[row.at("name").get<std::string>()] = row; - REQUIRE(rows.size() == 5); - auto param = [&](const char* tool, const char* name) { - for (const json& p : rows.at(tool).at("params")) - if (p.at("name") == name) return p; - FAIL(tool << " has no param " << name); - return json(); - }; + const GUI::CommandCatalog catalog = cad_catalog(); for (const char* t : {"thread", "sweep", "loft", "split"}) { INFO(t); - CHECK(rows.at(t).at("access") == "change"); - CHECK(rows.at(t).at("failure") == "error"); + CHECK_FALSE(command_of(catalog, t).read_only); + CHECK_THAT(command_of(catalog, t).description, !ContainsSubstring("ok is false")); } // These of thread and split are optional; sweep's and loft's, which have no default, are required. - for (const char* k : {"face", "edge", "designation", "internal", "diameter", "pitch", "depth", "length", "plane", "at"}) - CHECK(param("thread", k).at("required") == false); - CHECK(param("sweep", "sketch").at("required") == true); - CHECK(param("sweep", "path").at("required") == true); - CHECK(param("loft", "profiles").at("required") == true); - CHECK(param("split", "plane").at("required") == false); - CHECK(param("split", "face").at("required") == false); - CHECK(param("split", "face_body").at("default") == -1); - // The text may sit in the summary or the details. - const json& helix = rows.at("helix"); - CHECK_THAT(helix.at("summary").get<std::string>() + " " + helix.at("details").get<std::string>(), - ContainsSubstring("start and tangent")); + for (const char* k : {"face", "edge", "designation", "internal", "diameter", "pitch", "depth", "length", "plane", "at"}) { + INFO(k); + CHECK(property_of(command_of(catalog, "thread"), k).is_object()); + } + CHECK(required_of(command_of(catalog, "thread")).empty()); + CHECK(required_of(command_of(catalog, "sweep")) == std::vector<std::string>{"sketch", "path"}); + CHECK(required_of(command_of(catalog, "loft")) == std::vector<std::string>{"profiles"}); + CHECK(required_of(command_of(catalog, "split")).empty()); + CHECK(property_of(command_of(catalog, "split"), "plane").is_object()); + CHECK(property_of(command_of(catalog, "split"), "face").is_object()); + CHECK(property_of(command_of(catalog, "split"), "face_body").at("default") == -1); + CHECK_THAT(command_of(catalog, "helix").description, ContainsSubstring("start and tangent")); } // --- The open sketch: shapes, edit ops and constraints (cad_model A5, A7, A8) ----------------- @@ -2807,37 +3268,42 @@ TEST_CASE("sketch_constrain solves with the new constraint or rolls it back, and CHECK(r.at("dof") == free_dof - 2); CHECK_THAT(failure([&] { sketch(tool, "sketch_unconstrain", {{"index", 99}}); }), ContainsSubstring("out of range")); CHECK_THAT(failure([&] { sketch(tool, "sketch_unconstrain", json::object()); }), ContainsSubstring("index must be")); - CHECK_THAT(failure([&] { sketch(tool, "sketch_move", json::object()); }), ContainsSubstring("not a CAD tool of the open sketch")); + CHECK_THAT(failure([&] { sketch(tool, "sketch_move", json::object()); }), ContainsSubstring("not a Design command of the open sketch")); } TEST_CASE("the rows for the sketch's shapes, edit ops and constraints", "[Mcp][CAD]") { const std::vector<const char*> tools = {"sketch_add", "sketch_fillet", "sketch_chamfer", "sketch_trim", "sketch_transform", "sketch_constrain", "sketch_constraints", "sketch_unconstrain"}; - json names = json::array(); - for (const char* t : tools) names.push_back(t); - const json reply = GUI::Mcp::cad_describe_tool(names); - std::map<std::string, json> rows; - for (const json& row : reply.at("tools")) rows[row.at("name").get<std::string>()] = row; - REQUIRE(rows.size() == tools.size()); + const GUI::CommandCatalog catalog = cad_catalog(); for (const char* t : tools) { INFO(t); - CHECK(rows.at(t).at("access") == (std::string(t) == "sketch_constraints" ? "read" : "sketch")); - CHECK(rows.at(t).at("failure") == "error"); + CHECK(command_of(catalog, t).read_only == (std::string(t) == "sketch_constraints")); + CHECK_THAT(command_of(catalog, t).description, !ContainsSubstring("ok is false")); } - auto param = [&](const char* tool, const char* name) { - for (const json& p : rows.at(tool).at("params")) - if (p.at("name") == name) return p; - FAIL(tool << " has no param " << name); - return json(); + auto param = [&](const char* key, const char* name) { + const json p = property_of(command_of(catalog, key), name); + INFO(key << " " << name); + REQUIRE(p.is_object()); + return p; + }; + auto required = [&](const char* key, const char* name) { + const std::vector<std::string> req = required_of(command_of(catalog, key)); + return std::find(req.begin(), req.end(), name) != req.end(); }; // Required, as a param without a default is; then optional ones. for (const auto& [t, k] : std::vector<std::pair<const char*, const char*>>{ {"sketch_fillet", "radius"}, {"sketch_chamfer", "distance"}, {"sketch_trim", "at"}, {"sketch_transform", "op"}, - {"sketch_constrain", "type"}, {"sketch_unconstrain", "index"}}) - CHECK(param(t, k).at("required") == true); - for (const char* k : {"angle", "scale", "count", "pivot"}) CHECK(param("sketch_transform", k).at("required") == false); - CHECK(param("sketch_constraints", "sketch").at("required") == false); + {"sketch_constrain", "type"}, {"sketch_unconstrain", "index"}}) { + INFO(t << " " << k); + CHECK(required(t, k)); + } + for (const char* k : {"angle", "scale", "count", "pivot"}) { + param("sketch_transform", k); + CHECK_FALSE(required("sketch_transform", k)); + } + param("sketch_constraints", "sketch"); + CHECK_FALSE(required("sketch_constraints", "sketch")); const json types = param("sketch_add", "type").at("enum"); for (const char* t : {"polygon", "slot", "ellipse", "ellipse_arc", "spline"}) CHECK(std::find(types.begin(), types.end(), json(t)) != types.end()); diff --git a/tests/slic3rutils/test_mcp_core.cpp b/tests/slic3rutils/test_mcp_core.cpp index 170e994afd..5c0e167479 100644 --- a/tests/slic3rutils/test_mcp_core.cpp +++ b/tests/slic3rutils/test_mcp_core.cpp @@ -1,10 +1,14 @@ #include <catch2/catch_test_macros.hpp> #include <catch2/generators/catch_generators.hpp> +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/Mcp/JobRegistry.hpp" #include "slic3r/GUI/Mcp/McpCore.hpp" #include "slic3r/GUI/Mcp/McpJournal.hpp" +#include "slic3r/GUI/Mcp/McpPersonContext.hpp" #include "slic3r/GUI/Mcp/McpProtocol.hpp" +#include "slic3r/GUI/Mcp/McpService.hpp" +#include "slic3r/GUI/Mcp/McpServicePtr.hpp" #include "slic3r/GUI/Mcp/McpTypes.hpp" #include "slic3r/GUI/Mcp/UiInvoker.hpp" @@ -19,6 +23,7 @@ #include <functional> #include <memory> #include <new> +#include <optional> #include <set> #include <stdexcept> #include <utility> @@ -30,6 +35,9 @@ using namespace Slic3r::GUI::Mcp; using nlohmann::json; +using Slic3r::GUI::CommandCatalog; +using Slic3r::GUI::CommandFn; +using Slic3r::GUI::NativeCommand; using namespace std::chrono_literals; namespace { @@ -161,7 +169,7 @@ struct Harness }}; JobRegistry jobs; Journal journal; - ToolRegistry registry; + CommandCatalog registry; CoreTiming timing = [] { CoreTiming t; t.soft_budget = 100ms; @@ -208,12 +216,12 @@ struct Harness ToolResult call(const std::string& tool, const json& args = json::object()) { return core->call(*registry.find(tool), args); } }; -ToolDef tool(const std::string& name, GuardClass guard, ToolHandler handler) +NativeCommand tool(const std::string& name, GuardClass guard, CommandFn handler) { - ToolDef d; - d.name = name; + NativeCommand d; + d.key = name; d.guard = guard; - d.handler = std::move(handler); + d.run = std::move(handler); return d; } @@ -415,7 +423,7 @@ TEST_CASE("a recover call that targets outside the dialog applies the mutate gua TEST_CASE("a job outlives its reply and wait() returns its result", "[Mcp]") { Harness h; - ToolDef slow = tool("slow", GuardClass::Mutate, [](const json&, ToolContext&) { + NativeCommand slow = tool("slow", GuardClass::Mutate, [](const json&, ToolContext&) { std::this_thread::sleep_for(600ms); return ToolResult::ok({{"done", true}}); }); @@ -513,7 +521,7 @@ TEST_CASE("a held UI thread under a wx dialog is not reported as blocked_by_dial std::atomic<bool> release{false}; Harness h; SetOnExit releaser{release}; - ToolDef hold = tool("hold", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + NativeCommand hold = tool("hold", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { ctx.run_ui([&] { h.hold_ui(release, json::array({kNativePicker[0], {{"title", "Preferences"}}})); return json(); @@ -618,7 +626,7 @@ TEST_CASE("inspect tools run inline and recover tools run as jobs while another }); return ToolResult::ok(); })); - ToolDef look = tool("look", GuardClass::Inspect, [](const json&, ToolContext& ctx) { + NativeCommand look = tool("look", GuardClass::Inspect, [](const json&, ToolContext& ctx) { return ToolResult::ok({{"job", ctx.job_id()}, {"ui", ctx.run_ui([] { return json("ok"); })}}); }); look.inline_call = true; @@ -662,7 +670,7 @@ TEST_CASE("every mutate call is refused while a slice job runs, but cancel_job a { Harness h; std::atomic<bool> release{false}; - ToolDef slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + NativeCommand slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { ctx.begin_operation(); while (!release) std::this_thread::sleep_for(10ms); @@ -671,7 +679,7 @@ TEST_CASE("every mutate call is refused while a slice job runs, but cancel_job a slice.budget_ms = 100; h.registry.add(slice); h.registry.add(tool("new_project", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); - ToolDef cancel = tool("cancel_job", GuardClass::Mutate, [&](const json&, ToolContext&) { + NativeCommand cancel = tool("cancel_job", GuardClass::Mutate, [&](const json&, ToolContext&) { release = true; return ToolResult::ok(); }); @@ -691,15 +699,150 @@ TEST_CASE("every mutate call is refused while a slice job runs, but cancel_job a CHECK_FALSE(h.call("new_project").is_error); } +TEST_CASE("a context with no service set refuses", "[Mcp]") +{ + Harness h; + const CommandFn needs_service = [](const json&, ToolContext& ctx) { + [[maybe_unused]] McpService& service = ctx.service(); + return ToolResult::ok(); + }; + NativeCommand look = tool("look", GuardClass::Inspect, needs_service); + look.inline_call = true; + h.registry.add(look); + h.registry.add(tool("act", GuardClass::Mutate, needs_service)); + h.start(); + + // A core no McpService owns, as a test builds one: the call fails, inline or as a job, and nothing crashes. + CHECK(h.call("look").is_error); + const ToolResult acted = h.call("act"); + CHECK(acted.is_error); + CHECK_FALSE(acted.data.contains("status")); +} + +TEST_CASE("a submitted call returns its job at once and runs on a job's thread", "[Mcp]") +{ + // Before the harness: the job's thread may still use them until the harness has joined it. + std::atomic<bool> open{false}; + std::promise<ToolResult> ended; + std::mutex seen_mutex; + std::thread::id ran_on; + Harness h; + SetOnExit let_go{open}; + h.registry.add(tool("work", GuardClass::Mutate, [&](const json& args, ToolContext&) { + { + std::lock_guard<std::mutex> lock(seen_mutex); + ran_on = std::this_thread::get_id(); + } + while (!open) + std::this_thread::sleep_for(5ms); + return ToolResult::ok({{"n", args.value("n", 0)}}); + })); + h.start(); + + std::future<ToolResult> result = ended.get_future(); + const std::string job = h.core->submit(*h.registry.find("work"), {{"n", 7}}, [&ended](const ToolResult& r) { ended.set_value(r); }); + CHECK_FALSE(job.empty()); + // It returned while the call is still held. + CHECK(result.wait_for(0ms) == std::future_status::timeout); + open = true; + REQUIRE(result.wait_for(3000ms) == std::future_status::ready); + const ToolResult r = result.get(); + CHECK_FALSE(r.is_error); + CHECK(r.data["n"] == 7); + { + std::lock_guard<std::mutex> lock(seen_mutex); + CHECK(ran_on != std::this_thread::get_id()); + } + // The job is registered as a client's would be, and the call is not journaled. + CHECK(h.jobs.wait(job, 3000ms).has_value()); + CHECK(h.journal.to_replay("r")["steps"].empty()); +} + +TEST_CASE("a submitted change is refused as a client's is while an operation runs, and none starts after shutdown", "[Mcp]") +{ + std::atomic<bool> release{false}; + Harness h; + SetOnExit let_go{release}; + NativeCommand slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + ctx.begin_operation(); + while (!release) + std::this_thread::sleep_for(10ms); + return ToolResult::ok(); + }); + slice.budget_ms = 100; + h.registry.add(slice); + h.registry.add(tool("new_project", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); + h.start(); + + const ToolResult running = h.call("slice"); + REQUIRE(running.data["status"] == "running"); + const ToolResult client = h.call("new_project"); + REQUIRE(client.is_error); + // No job starts, and the refusal comes at once, on the calling thread. + std::optional<ToolResult> refusal; + CHECK(h.core->submit(*h.registry.find("new_project"), json::object(), [&refusal](const ToolResult& r) { refusal = r; }).empty()); + REQUIRE(refusal.has_value()); + CHECK(refusal->is_error); + CHECK(refusal->message == client.message); + + release = true; + CHECK(h.jobs.wait(running.data["job"], 3000ms).has_value()); + h.core->shutdown(); + bool called = false; + CHECK(h.core->submit(*h.registry.find("new_project"), json::object(), [&called](const ToolResult&) { called = true; }).empty()); + CHECK_FALSE(called); +} + +TEST_CASE("a submitted job runs as a person's, a client's call of the same command does not", "[Mcp]") +{ + // The service that owns the core, as GUI_App's does; never started, since the mark needs no endpoint or UI. + // Before the harness, so that it outlives the job threads the harness joins. + McpServicePtr service(new McpService()); + Harness h; + h.registry.add(tool("work", GuardClass::Mutate, [](const json&, ToolContext& ctx) { + return ToolResult::ok({{"person", ctx.service().person_run(ctx.lineage())}}); + })); + h.start(); + h.core->set_service(service.get()); + + std::promise<ToolResult> ended; + std::future<ToolResult> result = ended.get_future(); + const std::string job = h.core->submit(*h.registry.find("work"), json::object(), [&ended](const ToolResult& r) { ended.set_value(r); }); + REQUIRE_FALSE(job.empty()); + REQUIRE(result.wait_for(3000ms) == std::future_status::ready); + const ToolResult submitted = result.get(); + REQUIRE_FALSE(submitted.is_error); + CHECK(submitted.data.value("person", false)); + // The mark ends with the job. + REQUIRE(h.jobs.wait(job, 3000ms).has_value()); + CHECK_FALSE(service->person_run({job})); + const ToolResult client = h.call("work"); + REQUIRE_FALSE(client.is_error); + CHECK_FALSE(client.data.value("person", true)); +} + +TEST_CASE("a submitted call whose done throws still ends its job", "[Mcp]") +{ + Harness h; + h.registry.add(tool("work", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); + h.start(); + + // done runs on the job's thread: what it throws must not end the process, nor keep the job from finishing. + const std::string job = h.core->submit(*h.registry.find("work"), json::object(), + [](const ToolResult&) { throw std::runtime_error("the caller's own failure"); }); + REQUIRE_FALSE(job.empty()); + CHECK(h.jobs.wait(job, 3000ms).has_value()); +} + // What a recording's CallObserver hears, in order. struct HeardCalls final : CallObserver { std::mutex mutex; std::vector<std::string> events; - void call_started(uint64_t, const ToolDef& def, const json&, const std::string& parent) override + void call_started(uint64_t, const NativeCommand& def, const json&, const std::string& parent) override { std::lock_guard<std::mutex> lock(mutex); - events.push_back("start " + def.name + (parent.empty() ? "" : " in a job")); + events.push_back("start " + def.key + (parent.empty() ? "" : " in a job")); } void call_args(uint64_t, const json& args) override { @@ -722,7 +865,7 @@ TEST_CASE("the call observer hears inline, job and child calls, and not calls re { Harness h; HeardCalls heard; - ToolDef look = tool("look", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); + NativeCommand look = tool("look", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); look.inline_call = true; h.registry.add(look); h.registry.add(tool("click", GuardClass::Recover, [](const json&, ToolContext& ctx) { @@ -732,7 +875,7 @@ TEST_CASE("the call observer hears inline, job and child calls, and not calls re })); h.registry.add(tool("replay", GuardClass::Mutate, [](const json&, ToolContext& ctx) { return ctx.call_child("click", json::object()); })); std::atomic<bool> release{false}; - ToolDef slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + NativeCommand slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { ctx.begin_operation(); while (!release) std::this_thread::sleep_for(10ms); @@ -764,12 +907,12 @@ TEST_CASE("an observer that throws fails no call", "[Mcp]") { struct Throwing final : CallObserver { - void call_started(uint64_t, const ToolDef&, const json&, const std::string&) override { throw std::runtime_error("started"); } + void call_started(uint64_t, const NativeCommand&, const json&, const std::string&) override { throw std::runtime_error("started"); } void call_args(uint64_t, const json&) override { throw std::bad_alloc(); } void call_ended(uint64_t, const ToolResult&) override { throw std::runtime_error("ended"); } } throwing; Harness h; - ToolDef look = tool("look", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok({{"seen", true}}); }); + NativeCommand look = tool("look", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok({{"seen", true}}); }); look.inline_call = true; h.registry.add(look); h.registry.add(tool("act", GuardClass::Mutate, [](const json&, ToolContext& ctx) { @@ -785,12 +928,59 @@ TEST_CASE("an observer that throws fails no call", "[Mcp]") CHECK(acted.data["done"] == true); } +TEST_CASE("a tile's journal update stays inside run_action's envelope", "[Mcp]") +{ + Harness h; + h.registry.add(tool("run_action", GuardClass::Mutate, [](const json&, ToolContext& ctx) { + // The command's function, as run_action runs a tile with it. + const auto command = [](const json&, ToolContext& own) { + own.set_journal_args({{"a", 1}}); + return ToolResult::ok(); + }; + TileContext tile(ctx, "orca_command:k:orca"); + return command(json::object(), tile); + })); + h.start(); + const ToolResult ran = h.call("run_action", {{"id", "k"}}); + REQUIRE_FALSE(ran.is_error); + REQUIRE_FALSE(ran.data.contains("status")); + const json steps = h.journal.to_replay("s")["steps"]; + REQUIRE(steps.size() == 1); + CHECK(steps[0]["tool"] == "run_action"); + CHECK(steps[0]["args"] == json{{"id", "orca_command:k:orca"}, {"args", {{"a", 1}}}}); +} + +TEST_CASE("the journal records a call without its command's id arguments", "[Mcp]") +{ + Harness h; + NativeCommand move = tool("move", GuardClass::Mutate, [](const json& args, ToolContext& ctx) { + // A handler that replaces what the journal records, as the GUI tools record locators for refs. + if (args.contains("rewrite")) + ctx.set_journal_args({{"object", 2}, {"object_id", 5}}); + return ToolResult::ok(); + }); + move.id_args = {"object_id"}; + h.registry.add(move); + // A command without id_args keeps an argument of that name: it is its own. + h.registry.add(tool("measure", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); + h.start(); + + REQUIRE_FALSE(h.call("move", {{"object", 1}, {"object_id", 9}}).is_error); + REQUIRE_FALSE(h.call("move", {{"rewrite", true}, {"object_id", 9}}).is_error); + REQUIRE_FALSE(h.call("measure", {{"object_id", 4}}).is_error); + const json steps = h.journal.to_replay("s")["steps"]; + REQUIRE(steps.size() == 3); + CHECK(steps[0]["args"] == json{{"object", 1}}); + CHECK(steps[1]["args"] == json{{"object", 2}}); + CHECK(steps[2]["args"] == json{{"object_id", 4}}); +} + TEST_CASE("without a blocking slot a job call returns its envelope at once and an inline call returns pending", "[Mcp]") { Harness h; h.timing.blocking_slots = 1; std::atomic<bool> release{false}; - ToolDef hold = tool("hold", GuardClass::Inspect, [&](const json&, ToolContext&) { + NativeCommand hold = tool("hold", GuardClass::Inspect, [&](const json&, ToolContext&) { while (!release) std::this_thread::sleep_for(10ms); return ToolResult::ok(); @@ -920,7 +1110,7 @@ TEST_CASE("operation admission is checked again when a mutate call reaches the U h.registry.add(tool("edit", GuardClass::Mutate, [](const json&, ToolContext& ctx) { return ToolResult::ok(ctx.run_ui([] { return json("edited"); })); })); - ToolDef slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + NativeCommand slice = tool("slice", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { ctx.run_ui([&] { ctx.begin_operation(); return json(); @@ -1006,7 +1196,7 @@ TEST_CASE("a call made by a stopped job sees itself cancelled", "[Mcp]") { Harness h; // An inline call that polls for cancellation, as wait does. - ToolDef spin = tool("spin", GuardClass::Inspect, [](const json&, ToolContext& ctx) { + NativeCommand spin = tool("spin", GuardClass::Inspect, [](const json&, ToolContext& ctx) { const auto end = std::chrono::steady_clock::now() + 5s; while (!ctx.cancelled() && std::chrono::steady_clock::now() < end) std::this_thread::sleep_for(10ms); @@ -1014,7 +1204,7 @@ TEST_CASE("a call made by a stopped job sees itself cancelled", "[Mcp]") }); spin.inline_call = true; h.registry.add(spin); - ToolDef replay = tool("replay", GuardClass::Mutate, [](const json&, ToolContext& ctx) { return ctx.call_child("spin", json::object()); }); + NativeCommand replay = tool("replay", GuardClass::Mutate, [](const json&, ToolContext& ctx) { return ctx.call_child("spin", json::object()); }); replay.budget_ms = 50; h.registry.add(replay); h.start(); @@ -1123,18 +1313,18 @@ TEST_CASE("a job's call over the byte cap stays until its job ends", "[Mcp]") json left; // The reply comes first, as the job's envelope; the job ends later. - const uint64_t seq = journal.begin("call_cad_tool", huge); + const uint64_t seq = journal.begin("thread", huge); journal.job_started(seq, "j"); journal.end(seq, ToolResult::ok({{"status", "running"}, {"job", "j"}})); CHECK(journal.to_replay("s", &left)["steps"].empty()); REQUIRE(left.size() == 1); - CHECK(left[0] == json{{"tool", "call_cad_tool"}, {"job", "j"}}); + CHECK(left[0] == json{{"tool", "thread"}, {"job", "j"}}); journal.job_ended(seq, ToolResult::ok()); CHECK(journal.to_replay("s", &left)["steps"].empty()); CHECK(left.empty()); // The job ends before its reply. - const uint64_t seq2 = journal.begin("call_cad_tool", huge); + const uint64_t seq2 = journal.begin("thread", huge); journal.job_started(seq2, "k"); journal.job_ended(seq2, ToolResult::ok()); CHECK(journal.to_replay("s", &left)["steps"].empty()); @@ -1182,10 +1372,10 @@ TEST_CASE("one call bigger than the cap is dropped once it has replied", "[Mcp]" { Journal journal; json left; - const uint64_t seq = journal.begin("call_cad_tool", args_of_mib(65)); + const uint64_t seq = journal.begin("thread", args_of_mib(65)); CHECK(journal.to_replay("s", &left)["steps"].empty()); REQUIRE(left.size() == 1); - CHECK(left[0] == json{{"tool", "call_cad_tool"}}); + CHECK(left[0] == json{{"tool", "thread"}}); journal.end(seq, ToolResult::ok()); CHECK(journal.to_replay("s", &left)["steps"].empty()); CHECK(left.empty()); @@ -1206,7 +1396,7 @@ TEST_CASE("a job refused at shutdown after it registered ends its journal entry" }); JobRegistry jobs; Journal journal; - ToolRegistry registry; + CommandCatalog registry; registry.add(tool("answer_dialog", GuardClass::Recover, [](const json&, ToolContext&) { return ToolResult::ok(); })); McpCore core(registry, invoker, jobs, &journal, CoreTiming{}); core_ptr = &core; @@ -1291,11 +1481,11 @@ TEST_CASE("the journal records client calls in order and replays jobs with await TEST_CASE("only client calls of journaled tools reach the journal", "[Mcp]") { Harness h; - ToolDef look = tool("get_app_state", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); + NativeCommand look = tool("get_app_state", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); look.inline_call = true; look.journal = false; h.registry.add(look); - ToolDef wait = tool("wait", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); + NativeCommand wait = tool("wait", GuardClass::Inspect, [](const json&, ToolContext&) { return ToolResult::ok(); }); wait.inline_call = true; h.registry.add(wait); h.registry.add(tool("set_settings", GuardClass::Mutate, [](const json&, ToolContext& ctx) { @@ -1344,7 +1534,7 @@ TEST_CASE("call_tool is journaled as the tool it calls", "[Mcp]") { Harness h; h.registry.add(tool("set_settings", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); - ToolDef api = tool("call_tool", GuardClass::Mutate, [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }); + NativeCommand api = tool("call_tool", GuardClass::Mutate, [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }); api.input_schema = {{"type", "object"}, {"properties", {{"tool", {{"type", "string"}}}, {"args", {{"type", "object"}}}}}}; h.registry.add(api); h.start(); @@ -1422,7 +1612,7 @@ TEST_CASE("a plugin's calls are refused once it unloads, before the block comes, ToolResult job_child; // The plugin manager's state, which changes as the plugin unloads; end_plugin_scope()'s block comes later. h.jobs.set_owner_liveness([&](const std::string& plugin) { return plugin != "measure" || loaded; }); - ToolDef look = tool("look", GuardClass::Inspect, [&](const json&, ToolContext&) { ++looks; return ToolResult::ok(); }); + NativeCommand look = tool("look", GuardClass::Inspect, [&](const json&, ToolContext&) { ++looks; return ToolResult::ok(); }); look.inline_call = true; h.registry.add(look); h.registry.add(tool("make", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); @@ -1519,7 +1709,7 @@ TEST_CASE("a call under a lineage node sees a stop asked for the node, inline ca std::this_thread::sleep_for(10ms); return ToolResult::ok({{"cancelled", ctx.cancelled()}}); }; - ToolDef inline_poll = tool("inline_poll", GuardClass::Inspect, poll); + NativeCommand inline_poll = tool("inline_poll", GuardClass::Inspect, poll); inline_poll.inline_call = true; h.registry.add(inline_poll); h.registry.add(tool("job_poll", GuardClass::Mutate, poll)); diff --git a/tests/slic3rutils/test_mcp_protocol.cpp b/tests/slic3rutils/test_mcp_protocol.cpp index 47397a679d..3548aadb5b 100644 --- a/tests/slic3rutils/test_mcp_protocol.cpp +++ b/tests/slic3rutils/test_mcp_protocol.cpp @@ -1,21 +1,29 @@ #include <catch2/catch_test_macros.hpp> +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/Mcp/McpProtocol.hpp" #include "slic3r/GUI/Mcp/McpService.hpp" #include "slic3r/GUI/Mcp/McpStdioBridge.hpp" #include "slic3r/GUI/Mcp/McpTypes.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "libslic3r_version.h" #include <nlohmann/json.hpp> +#include <algorithm> #include <functional> #include <set> #include <memory> #include <string> +#include <utility> #include <vector> using namespace Slic3r::GUI::Mcp; using nlohmann::json; +using Slic3r::GUI::CommandCatalog; +using Slic3r::GUI::CommandSource; +using Slic3r::GUI::NativeCommand; +namespace NativeCommands = Slic3r::GUI::NativeCommands; namespace { @@ -25,9 +33,9 @@ class DirectCaller final : public ToolCaller public: std::vector<std::string> called; // the tools it ran, in order - ToolResult call(const ToolDef& def, const json& args) override + ToolResult call(const NativeCommand& def, const json& args) override { - called.push_back(def.name); + called.push_back(def.key); struct Context final : ToolContext { std::string id; @@ -40,20 +48,21 @@ public: void set_journal_args(json) override {} void begin_operation() override {} } ctx; - return def.handler(args, ctx); + return def.run(args, ctx); } }; struct Fixture { - ToolRegistry registry; - DirectCaller caller; - McpProtocol protocol{registry, caller, ServerInfo{"orcaslicer", "OrcaSlicer", "9.9.9", "Use get_app_state first."}}; + CommandCatalog registry; + DirectCaller caller; + McpProtocol protocol{registry, caller, ServerInfo{"orcaslicer", "OrcaSlicer", "9.9.9", "Use get_app_state first."}}; Fixture() { - ToolDef echo; - echo.name = "echo"; + NativeCommand echo; + echo.key = "echo"; + echo.listed = true; echo.description = "Echo text back."; echo.read_only = true; echo.idempotent = true; @@ -61,14 +70,15 @@ struct Fixture {"properties", {{"text", {{"type", "string"}}}}}, {"required", {"text"}}, {"additionalProperties", false}}; - echo.handler = [](const json& args, ToolContext&) { return ToolResult::ok({{"echo", args["text"]}}); }; + echo.run = [](const json& args, ToolContext&) { return ToolResult::ok({{"echo", args["text"]}}); }; registry.add(echo); - ToolDef fail; - fail.name = "fail"; + NativeCommand fail; + fail.key = "fail"; + fail.listed = true; fail.destructive = true; fail.open_world = true; - fail.handler = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("it broke", {{"why", "test"}}); }; + fail.run = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("it broke", {{"why", "test"}}); }; registry.add(fail); } @@ -134,22 +144,34 @@ TEST_CASE("tools/list keeps registration order and maps annotations", "[Mcp]") CHECK(tools[0]["inputSchema"]["required"][0] == "text"); } -TEST_CASE("tools/list lists the core tools, then the API lane, then the UI lane", "[Mcp]") +TEST_CASE("tools/list lists the listed commands in the order they were added", "[Mcp]") { - Fixture f; - for (const char* name : {"click", "get_app_state"}) { - ToolDef def; - def.name = name; - def.handler = [](const json&, ToolContext&) { return ToolResult::ok(); }; - f.registry.add(def); - } - const json tools = body(f.post({{"jsonrpc", "2.0"}, {"id", 2}, {"method", "tools/list"}}))["result"]["tools"]; - REQUIRE(tools.size() == 4); - CHECK(tools[0]["name"] == "get_app_state"); - CHECK(tools[1]["name"] == "echo"); - CHECK(tools[2]["name"] == "fail"); - CHECK(tools[3]["name"] == "click"); - CHECK(tools[3]["description"] == "[ui] "); + const CommandCatalog& catalog = NativeCommands::instance(); + DirectCaller caller; + McpProtocol protocol{catalog, caller, ServerInfo{}}; + const json tools = body(protocol.handle_post(PostRequest{json{{"jsonrpc", "2.0"}, {"id", 2}, {"method", "tools/list"}}.dump(), {}, {}, {}})) + ["result"]["tools"]; + std::vector<std::string> names; + for (const json& tool : tools) + names.push_back(tool["name"].get<std::string>()); + + std::vector<std::string> added; + for (const NativeCommand& def : catalog.commands()) + if (def.listed) + added.push_back(def.key); + CHECK(names == added); + + // The families in the order register_all_commands() adds them: the Speed Dial's commands before them are + // not listed. + REQUIRE_FALSE(names.empty()); + CHECK(names.front() == "get_app_state"); + const auto position = [&names](const std::string& name) { + const auto it = std::find(names.begin(), names.end(), name); + REQUIRE(it != names.end()); + return it - names.begin(); + }; + CHECK(position("search_tools") < position("open_files")); + CHECK(position("slice") < position("click")); } TEST_CASE("tools/call returns the result as a JSON text block", "[Mcp]") @@ -183,6 +205,13 @@ TEST_CASE("an unknown tool is a JSON-RPC error with suggestions", "[Mcp]") CHECK(reply["error"]["data"]["did_you_mean"][0] == "echo"); } +TEST_CASE("one edit distance serves every did-you-mean", "[Mcp]") +{ + CHECK(edit_distance("fillet", "filet") == 1); + CHECK(edit_distance("", "abc") == 3); + CHECK(edit_distance("a", "a") == 0); +} + TEST_CASE("malformed messages are rejected", "[Mcp]") { Fixture f; @@ -231,18 +260,19 @@ TEST_CASE("the stdio bridge derives no headers from a line that is not a message TEST_CASE("the catalog the stdio bridge lists without the app holds every tool family", "[Mcp]") { - const ToolRegistry& catalog = McpService::offline_catalog(); + const CommandCatalog& catalog = NativeCommands::instance(); std::set<std::string> names; - for (const ToolDef& def : catalog.tools()) { - CHECK(names.insert(def.name).second); - CHECK(def.description.rfind(std::string("[") + lane_name(def.lane) + "] ", 0) == 0); + for (const NativeCommand& def : catalog.commands()) { + if (!def.listed) + continue; + CHECK(names.insert(def.key).second); } for (const char* name : {"get_app_state", "run_action", "open_files", "set_settings", "slice", "set_height_ranges", "set_view", "list_widgets", "run_replay", "start_recording", "run_script", "call_tool", "set_variable_layer_height", "set_custom_gcode_at_layer"}) CHECK(names.count(name) == 1); // Built once, for the life of the process. - CHECK(&McpService::offline_catalog() == &catalog); + CHECK(&NativeCommands::instance() == &catalog); CHECK(McpService::server_info().version == SLIC3R_VERSION); CHECK_FALSE(McpService::server_info().instructions.empty()); // Clients cut the instructions off after 4096 characters. @@ -525,39 +555,30 @@ TEST_CASE("a position or size in mm, an array of numbers, takes no pair list_win CHECK(sized == json{{"width", 30}, {"height", 5}}); } -TEST_CASE("an unknown tool another catalog has is pointed there, not at similar names", "[Mcp]") +TEST_CASE("an unknown tool is answered with the closest names", "[Mcp]") { Fixture f; - f.registry.set_elsewhere([](const std::string& name) { - return name == "echo_cad" ? std::string("it is a CAD tool: call_cad_tool runs it") : std::string(); - }); - const char* const pointed = "Unknown tool: echo_cad; it is a CAD tool: call_cad_tool runs it"; + const json direct = body(f.post({{"jsonrpc", "2.0"}, {"id", 7}, {"method", "tools/call"}, {"params", {{"name", "no_such_tool"}}}})); + CHECK(direct["error"]["message"] == "Unknown tool: no_such_tool"); - const json direct = body(f.post({{"jsonrpc", "2.0"}, {"id", 7}, {"method", "tools/call"}, {"params", {{"name", "echo_cad"}}}})); - CHECK(direct["error"]["message"] == pointed); - - ToolDef api; - api.name = "call_tool"; + NativeCommand api; + api.key = "call_tool"; api.input_schema = {{"type", "object"}, {"properties", {{"tool", {{"type", "string"}}}, {"args", {{"type", "object"}}}}}, {"required", {"tool"}}}; - api.handler = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }; + api.run = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }; f.registry.add(api); - const json through = body(f.post({{"jsonrpc", "2.0"}, {"id", 8}, {"method", "tools/call"}, - {"params", {{"name", "call_tool"}, {"arguments", {{"tool", "echo_cad"}}}}}}))["result"]; - CHECK(through["isError"] == true); - CHECK(through["content"][0]["text"] == pointed); - - // A name no catalog has still gets the closest tools. + // call_tool's target names the closest command, and nothing else. const json typo = body(f.post({{"jsonrpc", "2.0"}, {"id", 9}, {"method", "tools/call"}, {"params", {{"name", "call_tool"}, {"arguments", {{"tool", "ech"}}}}}}))["result"]; - CHECK(typo["content"][0]["text"].get<std::string>().find("did you mean echo") != std::string::npos); + CHECK(typo["isError"] == true); + CHECK(typo["content"][0]["text"] == "Unknown tool: ech (did you mean echo?)"); } TEST_CASE("a call's arguments are normalized, then validated", "[Mcp]") { - ToolDef capture; - capture.name = "screenshot"; + NativeCommand capture; + capture.key = "screenshot"; capture.input_schema = {{"type", "object"}, {"properties", {{"target", {{"type", "string"}}}, {"save_path", {{"type", "string"}}}}}, {"additionalProperties", false}}; @@ -575,12 +596,12 @@ TEST_CASE("a call's arguments are normalized, then validated", "[Mcp]") TEST_CASE("call_tool runs and is journaled as the tool it names", "[Mcp]") { Fixture f; - ToolDef api; - api.name = "call_tool"; + NativeCommand api; + api.key = "call_tool"; api.input_schema = {{"type", "object"}, {"properties", {{"tool", {{"type", "string"}}}, {"args", {{"type", "object"}}}}}, {"required", {"tool"}}}; - api.handler = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }; + api.run = [](const json&, ToolContext&) -> ToolResult { throw ToolFailure("not dispatched"); }; f.registry.add(api); const json result = body(f.post({{"jsonrpc", "2.0"}, {"id", 4}, {"method", "tools/call"}, @@ -599,20 +620,31 @@ TEST_CASE("call_tool runs and is journaled as the tool it names", "[Mcp]") CHECK(unknown["content"][0]["text"].get<std::string>().find("did you mean echo") != std::string::npos); } -TEST_CASE("a name the table lacks resolves through the dynamic resolver, without being listed", "[Mcp]") +// Holds the one operation a plugin offers while it is loaded. +class MeasureSource final : public CommandSource +{ +public: + MeasureSource() + { + auto area = std::make_shared<NativeCommand>(); + area->key = "plugin.measure.area"; + area->run = [](const json&, ToolContext&) { return ToolResult::ok({{"area", 12.5}}); }; + m_area = std::move(area); + } + std::shared_ptr<const NativeCommand> find(const std::string& key) const override { return key == m_area->key ? m_area : nullptr; } + std::vector<std::shared_ptr<const NativeCommand>> all() const override { return {m_area}; } + +private: + std::shared_ptr<const NativeCommand> m_area; +}; + +TEST_CASE("a name the table lacks resolves through a source, without being listed", "[Mcp]") { Fixture f; - f.registry.set_dynamic([](const std::string& name) -> std::shared_ptr<const ToolDef> { - if (name != "plugin.measure.area") - return nullptr; - auto def = std::make_shared<ToolDef>(); - def->name = name; - def->handler = [](const json&, ToolContext&) { return ToolResult::ok({{"area", 12.5}}); }; - return def; - }); + f.registry.add_source(std::make_unique<MeasureSource>()); REQUIRE(f.registry.lookup("plugin.measure.area") != nullptr); CHECK(f.registry.lookup("plugin.measure.volume") == nullptr); - CHECK(f.registry.lookup("echo")->name == "echo"); + CHECK(f.registry.lookup("echo")->key == "echo"); const json tools = body(f.post({{"jsonrpc", "2.0"}, {"id", 2}, {"method", "tools/list"}}))["result"]["tools"]; for (const json& t : tools) CHECK(t["name"] != "plugin.measure.area"); diff --git a/tests/slic3rutils/test_mcp_recording.cpp b/tests/slic3rutils/test_mcp_recording.cpp index b99a9c7fae..3d1c82f2bd 100644 --- a/tests/slic3rutils/test_mcp_recording.cpp +++ b/tests/slic3rutils/test_mcp_recording.cpp @@ -992,6 +992,20 @@ TEST_CASE("an image with alpha is blended over what it is composited onto", "[Mc // ---- captions ------------------------------------------------------------------------------------------------------ +TEST_CASE("a caption keeps the context its title is translated in", "[Mcp][Recording]") +{ + // A Design command's title is its entry's name, translated as the Design tab's menu translates it. + CaptionBoard board; + const auto t0 = CaptionBoard::Clock::now(); + board.call_started(1, "Slice", "", t0); + REQUIRE(board.current(t0).has_value()); + CHECK(board.current(t0)->context.empty()); + board.call_started(2, "Shell", "", t0, "Design"); + REQUIRE(board.current(t0).has_value()); + CHECK(board.current(t0)->title == "Shell"); + CHECK(board.current(t0)->context == "Design"); +} + TEST_CASE("the caption is the newest call that runs or lingers", "[Mcp][Recording]") { CaptionBoard board; @@ -1104,6 +1118,8 @@ TEST_CASE("captions name what a call acts on and never show secrets", "[Mcp][Rec CHECK(settings.find("nozzle_diameter = 0.4") != std::string::npos); CHECK(caption_detail("open_files", {{"paths", {"C:/models/part.stl", "/tmp/b.3mf"}}}) == "part.stl, b.3mf"); CHECK(caption_detail("run_action", {{"id", "orca_command:obj_arrange:orca"}}) == "obj_arrange"); + CHECK(caption_detail("run_action", {{"id", "orca_command:import_file:orca"}, {"args", {{"path", "C:/models/part.stl"}}}}) == + "import_file path: part.stl"); CHECK(caption_detail("run_javascript", {{"code", "login('s3cret')"}}).empty()); CHECK(is_sensitive_key("printhost_apikey")); CHECK(is_sensitive_key("cloud_Token")); @@ -1236,44 +1252,33 @@ TEST_CASE("remembered recording settings come back, and a bad value keeps its de CHECK(loaded.profile == "main"); } -TEST_CASE("Start Recording's parameter overrides the settings, a preset before the fields", "[Mcp][Recording]") +TEST_CASE("start_recording's encode arguments override the settings, a preset before the fields", "[Mcp][Recording]") { RecordingSettings s; - bool silent = false; - const json overrides{{"encode_preset", "compatible"}, {"crf", 18}, {"quality", 60}, {"pointer", true}, {"silent", true}}; - CHECK(apply_recording_overrides(s, overrides, silent).empty()); + // The tool's other arguments are left to it. + const json args_given{{"encode_preset", "compatible"}, {"crf", 18}, {"encode", true}, {"quality", 60}, {"silent", true}}; + CHECK(apply_recording_overrides(s, args_given).empty()); CHECK(s.codec == "h264"); CHECK(s.profile == "high"); CHECK(s.crf == 18); - CHECK(s.quality == 60); - CHECK(s.pointer); - CHECK_FALSE(s.captions); - CHECK(silent); + CHECK(s.encode); + CHECK(s.quality == RecordingSettings().quality); // A codec without a profile takes the codec's default when the one it had doesn't fit. - CHECK(apply_recording_overrides(s, json{{"codec", "h265"}}, silent).empty()); + CHECK(apply_recording_overrides(s, json{{"codec", "h265"}}).empty()); CHECK(s.profile == "main"); - CHECK_FALSE(silent); - CHECK(apply_recording_overrides(s, json{{"profile", "main10"}}, silent).empty()); + CHECK(apply_recording_overrides(s, json{{"profile", "main10"}}).empty()); CHECK(s.profile == "main10"); // Anything wrong leaves the settings as they were. const RecordingSettings before = s; - CHECK_FALSE(apply_recording_overrides(s, json{{"codec", "h264"}, {"profile", "main10"}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"crf", 52}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"quality", "high"}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"captions", "yes"}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"overlays", true}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"encode_preset", "tiny"}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"fps", 30}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json::array(), silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"folder", "relative/videos"}}, silent).empty()); - CHECK_FALSE(apply_recording_overrides(s, json{{"folder", path_to_utf8(fs::temp_directory_path() / "no-such-folder-here")}}, silent).empty()); + CHECK_FALSE(apply_recording_overrides(s, json{{"codec", "h264"}, {"profile", "main10"}}).empty()); + CHECK_FALSE(apply_recording_overrides(s, json{{"crf", 52}}).empty()); + CHECK_FALSE(apply_recording_overrides(s, json{{"encode", "yes"}}).empty()); + CHECK_FALSE(apply_recording_overrides(s, json{{"speed", "warp"}}).empty()); + CHECK_FALSE(apply_recording_overrides(s, json{{"encode_preset", "tiny"}}).empty()); CHECK(s == before); - CHECK(apply_recording_overrides(s, json{{"folder", path_to_utf8(fs::temp_directory_path())}}, silent).empty()); - CHECK(RecordingFiles::same_file(path_from_utf8(s.folder), fs::temp_directory_path())); - const json args = encode_arguments(s, "C:/videos/a.mkv"); CHECK(args["path"] == "C:/videos/a.mkv"); CHECK(args["codec"] == "h265"); @@ -1471,3 +1476,29 @@ TEST_CASE("an exported replay encodes the recording it makes and leaves other so CHECK(steps[2]["args"]["save_path"] == "${out_dir}/rec.mp4"); CHECK(steps[3]["args"]["path"] == "D:/videos/old.mkv"); } + +TEST_CASE("an exported replay records a tile's recording into its own folder and encodes it there", "[Mcp][Recording]") +{ + Journal j; + auto ok = [&](const std::string& tool, const json& args) { j.end(j.begin(tool, args), ToolResult::ok()); }; + // run_action of the Start Recording tile, journaled as the tile's {id, args}, by its full id with the path the + // call gave. A call that gives none is journaled with the path its silent form chose in the session's output + // folder, as start_recording's own call is; the tile by its key here. + ok("run_action", {{"id", "orca_command:start_recording:orca"}, {"args", {{"silent", true}, {"save_path", "C:/Users/me/out/tile.mkv"}}}}); + ok("run_action", {{"id", "orca_command:stop_recording:orca"}}); + ok("encode_recording", {{"path", "C:/Users/me/out/tile.mkv"}}); + ok("run_action", {{"id", "start_recording"}, {"args", {{"silent", true}, {"save_path", "C:/Users/me/mcp/recording-20261113.mkv"}}}}); + ok("run_action", {{"id", "stop_recording"}}); + ok("encode_recording", {{"path", "C:/Users/me/mcp/recording-20261113.mkv"}, {"save_path", "C:/Users/me/mcp/take.mp4"}}); + // The person's form, which opens the Start Recording dialog, names no file. + ok("run_action", {{"id", "start_recording"}}); + const json steps = j.to_replay("s")["steps"]; + REQUIRE(steps.size() == 7); + CHECK(steps[0]["tool"] == "run_action"); + CHECK(steps[0]["args"] == json{{"id", "orca_command:start_recording:orca"}, {"args", {{"silent", true}, {"save_path", "${out_dir}/tile.mkv"}}}}); + CHECK(steps[2]["args"]["path"] == "${out_dir}/tile.mkv"); + CHECK(steps[3]["args"] == json{{"id", "start_recording"}, {"args", {{"silent", true}, {"save_path", "${out_dir}/recording-20261113.mkv"}}}}); + CHECK(steps[5]["args"]["path"] == "${out_dir}/recording-20261113.mkv"); + CHECK(steps[5]["args"]["save_path"] == "${out_dir}/take.mp4"); + CHECK(steps[6]["args"] == json{{"id", "start_recording"}}); +} diff --git a/tests/slic3rutils/test_mcp_replay_summary.cpp b/tests/slic3rutils/test_mcp_replay_summary.cpp index d9a8720aaa..07976803b9 100644 --- a/tests/slic3rutils/test_mcp_replay_summary.cpp +++ b/tests/slic3rutils/test_mcp_replay_summary.cpp @@ -41,7 +41,7 @@ Flags flags_of(const StepDescription& d) return out; } -// An absolute path on this platform: Speed Dial params name files only by absolute paths, and +// An absolute path on this platform: Speed Dial commands name files only by absolute paths, and // "C:/a" is relative outside Windows. std::string abs_path(const std::string& name) { @@ -52,11 +52,11 @@ std::string abs_path(const std::string& name) #endif } -std::string action(const std::string& id, const std::string& param = {}) +std::string action(const std::string& id, const json& command_args = json::object()) { json args{{"id", id}}; - if (!param.empty()) - args["param"] = param; + if (!command_args.empty()) + args["args"] = command_args; return json{{"tool", "run_action"}, {"args", args}}.dump(); } @@ -96,6 +96,29 @@ TEST_CASE("project tools replace the project after checking for unsaved changes" const StepDescription calib = describe(R"({"tool": "generate_calibration_test", "args": {"test": "temperature"}})"); CHECK(flags_of(calib) == Flags{"changes_presets", "replaces_project"}); CHECK(calib.replace == "checked"); + + // Silent with its defaults, it checks as with arguments; with none, it asks as New Project does. + CHECK(describe(R"({"tool": "new_project", "args": {"silent": true}})").replace == "checked"); + const StepDescription asked = describe(R"({"tool": "new_project", "args": {}})"); + CHECK(flags_of(asked) == Flags{"replaces_project"}); + CHECK(asked.replace == "app_asked"); +} + +TEST_CASE("a command called by name is described as its tile is", "[Mcp]") +{ + const auto [key, args, flags] = GENERATE_COPY(table<std::string, json, Flags>({ + {"load_project", {{"path", abs_path("p.3mf")}}, {"replaces_project"}}, + {"export_stl", {{"path", abs_path("a.stl")}}, {"writes_file"}}, + {"sync_presets", json::object(), {"changes_presets"}}, + })); + INFO(key << " " << args.dump()); + const StepDescription by_name = describe(json{{"tool", key}, {"args", args}}.dump()); + const StepDescription tile = describe(action("orca_command:" + key + ":orca", args)); + CHECK(flags_of(by_name) == flags); + CHECK(flags_of(by_name) == flags_of(tile)); + CHECK(by_name.replace == tile.replace); + CHECK(by_name.what == tile.what); + CHECK(describe_call(key, args) == tile.what); } TEST_CASE("speed dial actions are flagged by their id", "[Mcp]") @@ -103,33 +126,33 @@ TEST_CASE("speed dial actions are flagged by their id", "[Mcp]") struct Case { std::string id; - std::string param; + json args; Flags flags; std::string replace; }; - const Case c = GENERATE(values<Case>({ - {"orca_command:calib_flow_ratio:orca", "", {"changes_presets", "replaces_project"}, "app_asked"}, - {"orca_command:send_gcode:orca", "", {"sends_to_printer"}, ""}, - {"orca_command:open_preferences:orca", "", {}, ""}, - {"orca_command:slice_all:orca", "", {}, ""}, - {"orca_command:export_gcode:orca", "C:/x/a.gcode", {"writes_file"}, ""}, - {"orca_command:export_gcode:orca", "", {"writes_file"}, ""}, - {"orca_command:export_config:orca", "C:/x", {"writes_file"}, ""}, - {"orca_command:obj_set_instances:orca", "3", {}, ""}, - {"orca_command:save_project_as:orca", "C:/x/a.3mf", {"writes_file"}, ""}, - {"orca_command:new_project:orca", "", {"replaces_project"}, "app_asked"}, - {"orca_command:import_file:orca", abs_path("p.3mf"), {}, ""}, - {"orca_command:import_file:orca", json{{"path", abs_path("p.3mf")}, {"overwrite", true}}.dump(), {}, ""}, - {"orca_command:import_file:orca", json{{"path", abs_path("x.gcode")}}.dump(), {}, ""}, - {"orca_command:import_file:orca", abs_path("b.stl"), {}, ""}, - {"orca_recent_project:C:/p/a.3mf:orca", "", {"replaces_project"}, "app_asked"}, - {"orca_plate_goto:1:orca", "", {}, ""}, - {"orca_setting:layer_height:1", "", {}, ""}, - {"plugin_replay_action:tool:plugin", "", kEveryFlag, "app_asked"}, - {"plugin_page_action:page:plugin", "", kEveryFlag, "app_asked"}, + const json none = json::object(); + const Case c = GENERATE_COPY(values<Case>({ + {"orca_command:calib_flow_ratio:orca", none, {"changes_presets", "replaces_project"}, "app_asked"}, + {"orca_command:send_gcode:orca", none, {"sends_to_printer"}, ""}, + {"orca_command:open_preferences:orca", none, {}, ""}, + {"orca_command:slice_all:orca", none, {}, ""}, + {"orca_command:export_gcode:orca", {{"path", "C:/x/a.gcode"}}, {"writes_file"}, ""}, + {"orca_command:export_gcode:orca", none, {"writes_file"}, ""}, + {"orca_command:export_config:orca", {{"path", "C:/x"}}, {"writes_file"}, ""}, + {"orca_command:obj_set_instances:orca", {{"count", 3}}, {}, ""}, + {"orca_command:save_project_as:orca", {{"path", "C:/x/a.3mf"}, {"overwrite", true}}, {"writes_file"}, ""}, + {"orca_command:new_project:orca", none, {"replaces_project"}, "app_asked"}, + {"orca_command:import_file:orca", {{"path", abs_path("p.3mf")}}, {}, ""}, + {"orca_command:import_file:orca", {{"path", abs_path("x.gcode")}}, {}, ""}, + {"orca_command:import_file:orca", {{"path", abs_path("b.stl")}}, {}, ""}, + {"orca_recent_project:C:/p/a.3mf:orca", none, {"replaces_project"}, "app_asked"}, + {"orca_plate_goto:1:orca", none, {}, ""}, + {"orca_setting:layer_height:1", none, {}, ""}, + {"plugin_replay_action:tool:plugin", none, kEveryFlag, "app_asked"}, + {"plugin_page_action:page:plugin", none, kEveryFlag, "app_asked"}, })); - INFO(c.id << " " << c.param); - const StepDescription d = describe(action(c.id, c.param)); + INFO(c.id << " " << c.args.dump()); + const StepDescription d = describe(action(c.id, c.args)); CHECK(flags_of(d) == c.flags); CHECK(d.replace == c.replace); } @@ -142,19 +165,22 @@ TEST_CASE("plugin actions are taken to answer dialogs", "[Mcp]") TEST_CASE("speed dial actions describe their command and file", "[Mcp]") { - const auto [id, param, what] = GENERATE(table<std::string, std::string, json>({ - {"orca_command:import_file:orca", abs_path("p.3mf"), {{"kind", "command"}, {"key", "import_file"}, {"param", "p.3mf"}}}, - {"orca_command:import_file:orca", json{{"path", abs_path("p.3mf")}, {"overwrite", true}}.dump(), - {{"kind", "command"}, {"key", "import_file"}, {"param", "p.3mf"}}}, - {"orca_command:import_file:orca", json{{"path", abs_path("x.gcode")}}.dump(), {{"kind", "command"}, {"key", "import_file"}, {"param", "x.gcode"}}}, - {"orca_command:go_to_layer:orca", "50", {{"kind", "command"}, {"key", "go_to_layer"}, {"param", "50"}}}, - {"orca_command:slice_all:orca", "", {{"kind", "command"}, {"key", "slice_all"}}}, - {"orca_recent_project:C:/p/a.3mf:orca", "", {{"kind", "recent_project"}, {"name", "a.3mf"}}}, - {"orca_setting:layer_height:1", "", {{"kind", "value"}, {"text", "layer_height"}}}, - {"plugin_replay_action:tool:plugin", "", {{"kind", "value"}, {"text", "plugin_replay_action:tool:plugin"}}}, + const json none = json::object(); + const auto [id, args, what] = GENERATE_COPY(table<std::string, json, json>({ + {"orca_command:import_file:orca", {{"path", abs_path("p.3mf")}}, {{"kind", "command"}, {"key", "import_file"}, {"args", {"path: p.3mf"}}}}, + {"orca_command:save_project_as:orca", {{"path", abs_path("p.3mf")}, {"overwrite", true}}, + {{"kind", "command"}, {"key", "save_project_as"}, {"args", {"overwrite: true", "path: p.3mf"}}}}, + {"orca_command:import_file:orca", {{"path", "models/x.gcode"}}, {{"kind", "command"}, {"key", "import_file"}, {"args", {"path: x.gcode"}}}}, + {"orca_command:go_to_layer:orca", {{"percent", 50}}, {{"kind", "command"}, {"key", "go_to_layer"}, {"args", {"percent: 50"}}}}, + {"orca_command:add_primitive_cube:orca", {{"size", {20, 20, 20}}}, + {{"kind", "command"}, {"key", "add_primitive_cube"}, {"args", {"size: [20,20,20]"}}}}, + {"orca_command:slice_all:orca", none, {{"kind", "command"}, {"key", "slice_all"}}}, + {"orca_recent_project:C:/p/a.3mf:orca", none, {{"kind", "recent_project"}, {"name", "a.3mf"}}}, + {"orca_setting:layer_height:1", none, {{"kind", "value"}, {"text", "layer_height"}}}, + {"plugin_replay_action:tool:plugin", none, {{"kind", "value"}, {"text", "plugin_replay_action:tool:plugin"}}}, })); - INFO(id << " " << param); - CHECK(describe(action(id, param)).what == what); + INFO(id << " " << args.dump()); + CHECK(describe(action(id, args)).what == what); } TEST_CASE("files written inside the output folder are not flagged", "[Mcp]") @@ -235,7 +261,7 @@ TEST_CASE("nested replays join their steps' descriptions", "[Mcp]") CHECK(flags_of(own_folder).empty()); const StepDescription mixed = describe( - R"({"tool": "run_replay", "args": {"replay": {"orca_replay": 1, "steps": [{"tool": "run_action", "args": {"id": "orca_command:new_project:orca"}}, {"tool": "new_project"}]}}})"); + R"({"tool": "run_replay", "args": {"replay": {"orca_replay": 1, "steps": [{"tool": "run_action", "args": {"id": "orca_command:new_project:orca"}}, {"tool": "new_project", "args": {"silent": true}}]}}})"); CHECK(mixed.replace == "checked"); const StepDescription clicking = describe( @@ -275,7 +301,7 @@ TEST_CASE("saved jobs don't change a step's flags", "[Mcp]") { const std::string step = GENERATE(as<std::string>{}, R"({"tool": "open_files", "args": {"paths": ["${jobs.p}"]}})", R"({"tool": "screenshot", "args": {"save_path": "${jobs.p}/a.png"}})", - R"({"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${jobs.p}"}})"); + R"({"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${jobs.p}"}}})"); INFO(step); std::string err; const auto replay = parse_replay(R"({"orca_replay": 1, "steps": [)" + step + "]}", err); diff --git a/tests/slic3rutils/test_mcp_results.cpp b/tests/slic3rutils/test_mcp_results.cpp index f97d67b477..25a2b86472 100644 --- a/tests/slic3rutils/test_mcp_results.cpp +++ b/tests/slic3rutils/test_mcp_results.cpp @@ -15,6 +15,7 @@ #include <catch2/catch_test_macros.hpp> #include <catch2/matchers/catch_matchers.hpp> #include <catch2/matchers/catch_matchers_floating_point.hpp> +#include <catch2/matchers/catch_matchers_string.hpp> #include "libslic3r/ExtrusionEntity.hpp" #include "libslic3r/GCode/GCodeProcessor.hpp" @@ -33,6 +34,7 @@ #include "slic3r/GUI/Mcp/McpCore.hpp" #include "slic3r/GUI/Mcp/McpJournal.hpp" #include "slic3r/GUI/Mcp/McpPaths.hpp" +#include "slic3r/GUI/Mcp/McpProtocol.hpp" #include "slic3r/GUI/Mcp/McpReplay.hpp" #include "slic3r/GUI/Mcp/McpService.hpp" #include "slic3r/GUI/Mcp/McpServicePtr.hpp" @@ -1210,12 +1212,12 @@ TEST_CASE("a menu opened while a call acts on the UI is listed, run by its path inspector.ui_activity("click", false); // A menu from a call that armed nothing is closed unseen, until the first idle after the call. - inspector.ui_activity("call_cad_tool", true); - inspector.ui_activity("call_cad_tool", false); + inspector.ui_activity("extrude", true); + inspector.ui_activity("extrude", false); CHECK(popup_menu(frame, menu)); const nlohmann::json closed = inspector.closed_menus(); REQUIRE(closed.size() == 2); - CHECK(closed[1]["tool"] == "call_cad_tool"); + CHECK(closed[1]["tool"] == "extrude"); CHECK(closed[1]["items"].size() == 7); wxTheApp->ProcessPendingEvents(); wxIdleEvent idle; @@ -1223,8 +1225,8 @@ TEST_CASE("a menu opened while a call acts on the UI is listed, run by its path CHECK_FALSE(inspector.on_menu(menu, frame)); // Past a second a person's menu shows even when no idle came, as while events keep queuing. - inspector.ui_activity("call_cad_tool", true); - inspector.ui_activity("call_cad_tool", false); + inspector.ui_activity("extrude", true); + inspector.ui_activity("extrude", false); wxMilliSleep(1100); CHECK_FALSE(inspector.on_menu(menu, frame)); @@ -2424,7 +2426,7 @@ struct JobJournal UiInvoker invoker{ui, [] { return GuardState{}; }}; JobRegistry jobs; Journal journal; - ToolRegistry registry; + CommandCatalog registry; std::atomic<bool> release{false}; ToolResult build_result; std::atomic<int> builds{0}; @@ -2433,28 +2435,28 @@ struct JobJournal JobJournal() { - ToolDef build; - build.name = "build"; + NativeCommand build; + build.key = "build"; build.budget_ms = 100; - build.handler = [this](const nlohmann::json&, ToolContext&) { + build.run = [this](const nlohmann::json&, ToolContext&) { ++builds; while (!release) std::this_thread::sleep_for(std::chrono::milliseconds(5)); return build_result; }; registry.add(build); - ToolDef edit; - edit.name = "edit"; - edit.handler = [this](const nlohmann::json&, ToolContext&) { + NativeCommand edit; + edit.key = "edit"; + edit.run = [this](const nlohmann::json&, ToolContext&) { ++edits; return ToolResult::ok({{"edited", true}}); }; registry.add(edit); - ToolDef wait; - wait.name = "wait"; + NativeCommand wait; + wait.key = "wait"; wait.guard = GuardClass::Inspect; wait.inline_call = true; - wait.handler = [this](const nlohmann::json& args, ToolContext&) { + wait.run = [this](const nlohmann::json& args, ToolContext&) { const std::string job = args["job"].get<std::string>(); if (auto r = jobs.wait(job, std::chrono::milliseconds(args.value("timeout_ms", 5000)))) return *r; @@ -2704,13 +2706,23 @@ TEST_CASE("an upload's row reaches 100 percent only once the host has answered", CHECK(percent(4096, 4096) == 99); } -TEST_CASE("the send command is a Slice & Export command that takes no param", "[Mcp][SpeedDial]") +TEST_CASE("the send command is a Slice & Export command that takes no arguments", "[Mcp][SpeedDial]") { const NativeCommand* send = NativeCommands::find("send_gcode"); REQUIRE(send != nullptr); CHECK(send->title == "Send G-code to printer host"); CHECK(send->group == "Slice & Export"); - CHECK(send->param.type == CommandParamType::None); + CHECK(send->input_schema.at("properties").empty()); CHECK(send->completion == CommandCompletion::None); CHECK(send->description.find("get_app_state.uploads") != std::string::npos); } + +TEST_CASE("run_action with a param is refused by name", "[Mcp][SpeedDial]") +{ + const NativeCommand* run_action = NativeCommands::find("run_action"); + REQUIRE(run_action != nullptr); + nlohmann::json args{{"id", "x"}, {"param", "1"}}; + CHECK_THAT(argument_error(*run_action, args), Catch::Matchers::ContainsSubstring("param")); + nlohmann::json given{{"id", "x"}, {"args", {{"percent", 50}}}}; + CHECK(argument_error(*run_action, given).empty()); +} diff --git a/tests/slic3rutils/test_mcp_scene.cpp b/tests/slic3rutils/test_mcp_scene.cpp index 6dc66070a3..f602c5b2c3 100644 --- a/tests/slic3rutils/test_mcp_scene.cpp +++ b/tests/slic3rutils/test_mcp_scene.cpp @@ -1,7 +1,7 @@ -// Scene tools: transform's size argument, the primitive size param, the notifications MCP -// operations raise before the 3D view has drawn, arrange's options, the admission that holds a -// UI worker job a call starts, how list_objects describes objects, instances and parts, -// add_part's type names and shape sizes, the params of the object structure commands, the height +// Scene tools: transform's size argument, the arguments of the commands that replace a dialog, the +// notifications MCP operations raise before the 3D view has drawn, arrange's options, the admission that +// holds a UI worker job a call starts, how list_objects describes objects, instances and parts, +// add_part's type names and shape sizes, the object structure commands, the height // ranges set_height_ranges takes and list_objects reports, and set_custom_gcode_at_layer's edits of the layer slider. // GLCanvas3D.hpp reaches wx's MSW headers after OCCT has hidden the USER and GDI declarations they need; // the Windows headers first keep them, as in test_plugin_host_api.cpp. @@ -61,6 +61,7 @@ #include <memory> #include <mutex> #include <optional> +#include <set> #include <string> #include <thread> #include <utility> @@ -122,19 +123,48 @@ TEST_CASE("the arrange options keep Align to Y axis off while auto rotation is o CHECK(settings.enable_rotation); } -TEST_CASE("primitive size params parse numbers separated by spaces or commas", "[Mcp][Scene]") +// A command that replaces a dialog takes, as JSON arguments, what the dialog asks; Go to layer and Go to tab +// take the value of the Speed Dial's second phase, which they need. +TEST_CASE("the commands that replace a dialog take the arguments the table gives", "[Mcp][Scene]") { - CHECK(NativeCommands::parse_sizes("90 4") == std::vector<double>{90., 4.}); - CHECK(NativeCommands::parse_sizes("90,4") == std::vector<double>{90., 4.}); - CHECK(NativeCommands::parse_sizes(" 40, 40 10.5 ") == std::vector<double>{40., 40., 10.5}); - CHECK(NativeCommands::parse_sizes("25.6") == std::vector<double>{25.6}); + using Names = std::set<std::string>; + const auto names = [](const char* key) { + Names out; + if (const NativeCommand* c = NativeCommands::find(key)) + for (const auto& [name, schema] : c->input_schema.at("properties").items()) + out.insert(name); + return out; + }; + const Names path{"path"}, output{"path", "overwrite"}, all{"all"}, size{"size"}; + const Names recording{"target", "fps", "max_dim", "quality", "max_seconds", "captions", "pointer", "encode", + "encode_preset", "codec", "crf", "speed", "profile", "save_path", "overwrite", "silent"}; + REQUIRE(names("go_to_layer") == Names{"percent"}); + REQUIRE(names("go_to_tab") == Names{"tab"}); + for (const char* key : {"load_project", "import_file", "add_primitive_svg", "install_local_plugin"}) + REQUIRE(names(key) == path); + for (const char* key : {"save_project_as", "export_gcode", "export_stl", "export_3mf", "export_sliced_file", "export_all_sliced_file"}) + REQUIRE(names(key) == output); + for (const char* key : {"export_stl_multi", "export_config"}) + REQUIRE(names(key) == path); + REQUIRE(names("import_configs") == Names{"path", "on_conflict"}); + REQUIRE(names("open_preferences") == Names{"tab", "key"}); + REQUIRE(names("obj_rename") == Names{"name"}); + REQUIRE(names("obj_set_instances") == Names{"count"}); + for (const char* key : {"obj_order_by_name", "obj_order_by_filament", "obj_order_by_height", "obj_order_by_size"}) + REQUIRE(names(key) == all); + for (const char* key : {"add_primitive_cube", "add_primitive_cylinder", "add_primitive_sphere", "add_primitive_cone", + "add_primitive_disc", "add_primitive_torus"}) + REQUIRE(names(key) == size); + REQUIRE(names("plate_goto") == Names{"plate"}); + REQUIRE(names("filament_delete") == Names{"slot"}); + REQUIRE(names("start_recording") == recording); - CHECK_FALSE(NativeCommands::parse_sizes("").has_value()); - CHECK_FALSE(NativeCommands::parse_sizes(" , ").has_value()); - CHECK_FALSE(NativeCommands::parse_sizes("90 x").has_value()); - CHECK_FALSE(NativeCommands::parse_sizes("90mm 4").has_value()); - CHECK_FALSE(NativeCommands::parse_sizes("90 0").has_value()); - CHECK_FALSE(NativeCommands::parse_sizes("90 -4").has_value()); + // Of the tiles, only the two values of the second phase are required; every other tile does its person's + // form when it is given no arguments. + for (const NativeCommand* c : NativeCommands::palette_commands(NativeCommands::instance())) { + INFO(c->key); + CHECK(c->input_schema.contains("required") == (c->key == "go_to_layer" || c->key == "go_to_tab")); + } } // The app opens on Home, so a slice or arrange an agent starts at once updates its progress @@ -264,7 +294,7 @@ struct Harness Mcp::UiInvoker invoker{ui, [] { return Mcp::GuardState{}; }}; Mcp::JobRegistry jobs; Mcp::Journal journal; - Mcp::ToolRegistry registry; + CommandCatalog registry; Mcp::CoreTiming timing; std::chrono::milliseconds job_length{800}; std::unique_ptr<Mcp::McpCore> core; @@ -326,15 +356,15 @@ struct Harness core->shutdown(); } - void add(const std::string& name, Mcp::GuardClass guard, Mcp::ToolHandler handler) + void add(const std::string& name, Mcp::GuardClass guard, CommandFn handler) { - Mcp::ToolDef d; - d.name = name; + NativeCommand d; + d.key = name; d.guard = guard; d.inline_call = guard == Mcp::GuardClass::Inspect; d.allowed_during_operation = name == "cancel_job"; d.budget_ms = 200; - d.handler = std::move(handler); + d.run = std::move(handler); registry.add(std::move(d)); } void start() @@ -775,49 +805,20 @@ TEST_CASE("a shape's size needs one positive number per field of the size dialog } } -TEST_CASE("an instance count param is a whole number", "[Mcp][Scene]") -{ - CHECK(NativeCommands::parse_count("6") == 6); - CHECK(NativeCommands::parse_count(" 12 ") == 12); - CHECK(NativeCommands::parse_count("0") == 0); - CHECK(NativeCommands::parse_count("1000") == 1000); - - CHECK_FALSE(NativeCommands::parse_count("").has_value()); - CHECK_FALSE(NativeCommands::parse_count("-1").has_value()); - CHECK_FALSE(NativeCommands::parse_count("6.5").has_value()); - CHECK_FALSE(NativeCommands::parse_count("6 7").has_value()); - CHECK_FALSE(NativeCommands::parse_count("1e3").has_value()); - CHECK_FALSE(NativeCommands::parse_count("six").has_value()); - CHECK_FALSE(NativeCommands::parse_count("99999999999").has_value()); -} - -// The object list's context-menu commands are Speed Dial commands beside the other object commands, -// and a param stands in for each one's dialog. -TEST_CASE("the object structure commands take the params that replace their dialogs", "[Mcp][Scene]") +// The object list's context-menu commands are Speed Dial commands beside the other object commands. +TEST_CASE("the object structure commands sit beside the other object commands", "[Mcp][Scene]") { const NativeCommand* peer = NativeCommands::find("obj_delete"); REQUIRE(peer != nullptr); - struct Expected - { - const char* key; - CommandParamType param; - }; - for (const Expected& e : {Expected{"obj_type_part", CommandParamType::None}, Expected{"obj_type_negative", CommandParamType::None}, - Expected{"obj_type_modifier", CommandParamType::None}, - Expected{"obj_type_support_blocker", CommandParamType::None}, - Expected{"obj_type_support_enforcer", CommandParamType::None}, - Expected{"obj_type_precise_seam", CommandParamType::None}, Expected{"obj_rename", CommandParamType::Text}, - Expected{"obj_set_instances", CommandParamType::Index}, Expected{"obj_assemble", CommandParamType::None}, - Expected{"obj_instances_to_objects", CommandParamType::None}, - Expected{"obj_order_by_name", CommandParamType::Text}, Expected{"obj_order_by_filament", CommandParamType::Text}, - Expected{"obj_order_by_height", CommandParamType::Text}, Expected{"obj_order_by_size", CommandParamType::Text}}) { - INFO(e.key); - const NativeCommand* c = NativeCommands::find(e.key); + for (const char* key : {"obj_type_part", "obj_type_negative", "obj_type_modifier", "obj_type_support_blocker", + "obj_type_support_enforcer", "obj_type_precise_seam", "obj_rename", "obj_set_instances", "obj_assemble", + "obj_instances_to_objects", "obj_order_by_name", "obj_order_by_filament", "obj_order_by_height", + "obj_order_by_size"}) { + INFO(key); + const NativeCommand* c = NativeCommands::find(key); REQUIRE(c != nullptr); CHECK(c->group == peer->group); - CHECK(c->param.type == e.param); CHECK_FALSE(c->description.empty()); - CHECK(c->param.help.empty() == (e.param == CommandParamType::None)); } } diff --git a/tests/slic3rutils/test_mcp_tools.cpp b/tests/slic3rutils/test_mcp_tools.cpp index 60a9ca0869..021652da9a 100644 --- a/tests/slic3rutils/test_mcp_tools.cpp +++ b/tests/slic3rutils/test_mcp_tools.cpp @@ -11,10 +11,16 @@ #include <CommCtrl.h> #endif +#include <catch2/catch_message.hpp> #include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers.hpp> +#include <catch2/matchers/catch_matchers_string.hpp> #include "python_test_support.hpp" +#include "slic3r/GUI/ActionRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" +#include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Mcp/McpTools.hpp" #include "slic3r/GUI/Mcp/McpTypes.hpp" #include "slic3r/GUI/Mcp/McpJournal.hpp" @@ -32,12 +38,47 @@ #include <wx/types.h> #include <map> +#include <memory> +#include <regex> +#include <set> #include <string> #include <utility> #include <vector> using namespace Slic3r::GUI::Mcp; using nlohmann::json; +using Slic3r::GUI::CommandCatalog; +using Slic3r::GUI::CommandSource; +using Slic3r::GUI::NativeCommand; + +namespace { + +// Holds one command, as a plugin holds its operations while it is loaded. +class OneCommandSource final : public CommandSource +{ +public: + explicit OneCommandSource(NativeCommand command) : m_command(std::make_shared<const NativeCommand>(std::move(command))) {} + + std::shared_ptr<const NativeCommand> find(const std::string& key) const override + { + return key == m_command->key ? m_command : nullptr; + } + std::vector<std::shared_ptr<const NativeCommand>> all() const override { return {m_command}; } + +private: + std::shared_ptr<const NativeCommand> m_command; +}; + +// A Speed Dial action that runs nothing, with the id `prefix`:`name`:orca, as the registry's own are made. +class IdleAction final : public Slic3r::GUI::AppAction +{ +public: + IdleAction(const char* prefix, const char* name) : AppAction(prefix, name, "orca", "OrcaSlicer") {} + + Slic3r::GUI::AppActionRunResult run(const json& /*args*/) const override { return {}; } +}; + +} // namespace TEST_CASE("setting values serialize the way their options read them back", "[Mcp]") { @@ -117,30 +158,34 @@ TEST_CASE("an action search ranks by the query's words and puts the plainer comm CHECK(rank_actions(listed, query_words("top")) == json::array({listed[2]})); } -TEST_CASE("a name its catalog lacks is pointed to the catalog that has it", "[Mcp]") +TEST_CASE("run_action refuses arguments for an action that takes none", "[Mcp][SpeedDial]") { - ToolRegistry registry; - ToolDef list; - list.name = "list_objects"; - registry.add(list); - const auto says = [®istry](const std::string& name, Catalog missed, const std::string& text) { - return other_catalog_hint(registry, name, missed).find(text) != std::string::npos; - }; + // A plate's, a setting's, a recent project's and a plugin's action run what they are, whatever args says. + for (const char* prefix : {"orca_plate_goto", "orca_setting", "orca_recent_project", "plugin_script_action", "plugin_page_action"}) { + INFO(prefix); + const IdleAction action(prefix, "2"); + CHECK_THAT(action_args_error(action, {{"plate", 2}}), Catch::Matchers::ContainsSubstring("takes no arguments")); + CHECK(action_args_error(action, json::object()).empty()); + } + // A command's tile takes its command's arguments, which the command checks against its schema. + IdleAction tile("orca_command", "plate_goto"); + tile.command = "plate_goto"; + CHECK(action_args_error(tile, {{"plate", 2}}).empty()); +} - // A Speed Dial command, by the name inside its id or by the whole id. - CHECK(says("view_front", Catalog::Tools, "run_action {id: \"view_front\"}")); - CHECK(says("orca_command:view_front:orca", Catalog::Tools, "run_action {id: \"orca_command:view_front:orca\"}")); - // A tool, asked of the actions or of the CAD tools. - CHECK(says("list_objects", Catalog::Actions, "call list_objects directly")); - CHECK(says("list_objects", Catalog::Cad, "call list_objects directly")); - // Never the catalog that missed the name, and nothing for a name no catalog has. - CHECK(other_catalog_hint(registry, "list_objects", Catalog::Tools).empty()); - CHECK(other_catalog_hint(registry, "view_front", Catalog::Actions).empty()); - CHECK(other_catalog_hint(registry, "no_such_name", Catalog::Tools).empty()); +TEST_CASE("run_action says where an action it cannot find is", "[Mcp][SpeedDial]") +{ + CHECK_THAT(unknown_action("obj_arange"), Catch::Matchers::ContainsSubstring("search_actions")); #ifdef SLIC3R_CAD - CHECK(says("extrude", Catalog::Tools, "call_cad_tool {tool: \"extrude\", args}")); - CHECK(says("extrude", Catalog::Actions, "call_cad_tool {tool: \"extrude\", args}")); - CHECK(other_catalog_hint(registry, "extrude", Catalog::Cad).empty()); + // A Design tab tile, by its id or its key, while it is not shown. + for (const char* id : {"orca_command:shell:orca", "shell"}) { + INFO(id); + const std::string why = unknown_action(id); + CHECK_THAT(why, Catch::Matchers::ContainsSubstring("while the Design tab is shown")); + CHECK_THAT(why, Catch::Matchers::ContainsSubstring("call_tool {\"tool\": \"shell\"}")); + } + // A Design command without a tile is any unknown action. + CHECK_THAT(unknown_action("orca_command:describe_scene:orca"), Catch::Matchers::ContainsSubstring("search_actions")); #endif } @@ -210,37 +255,109 @@ TEST_CASE("search_python_api's reference covers the orca package with constructo CHECK(rank_python_api(reference, "mesh normals")[0]["name"] == "orca.host.TriangleMesh.face_normals"); } -TEST_CASE("every tool of the catalog has the lane the concept gives it", "[Mcp]") +TEST_CASE("a typed tool's group is core, api or ui, and a merged command's is Commands", "[Mcp]") { - for (const char* name : {"get_app_state", "wait", "cancel_job", "get_log", "run_replay", "export_replay", "answer_dialog", - "auto_answer_dialogs", "run_script", "search_python_api"}) - CHECK(tool_lane(name) == ToolLane::Core); - for (const char* name : {"list_windows", "set_window", "list_widgets", "click", "set_widget_value", "press_keys", "mouse_gesture", - "pick_gizmo_file", "run_javascript", "set_view", "screenshot", "start_recording", "stop_recording", - "encode_recording", "search_actions", "run_action", "select_objects"}) - CHECK(tool_lane(name) == ToolLane::Ui); - for (const char* name : {"set_settings", "slice", "generate_calibration_test", "list_cad_tools", "describe_cad_tool", - "call_cad_tool", "call_tool", "search_tools", "get_slice_stats", "plugin.example.measure"}) - CHECK(tool_lane(name) == ToolLane::Api); + const std::set<std::string> core{"get_app_state", "wait", "cancel_job", "get_log", "run_replay", "export_replay", + "answer_dialog", "auto_answer_dialogs", "run_script", "search_python_api"}; + const std::set<std::string> ui{"list_windows", "set_window", "list_widgets", "click", "set_widget_value", "press_keys", + "mouse_gesture", "pick_gizmo_file", "run_javascript", "set_view", "screenshot", + "encode_recording", "search_actions", "run_action", "select_objects"}; + const std::set<std::string> merged{"new_project", "save_project", "start_recording", "stop_recording"}; + REQUIRE(core.size() == 10); + REQUIRE(ui.size() == 15); + + std::map<std::string, std::set<std::string>> by_group; + for (const NativeCommand& def : Slic3r::GUI::NativeCommands::instance().commands()) + if (def.listed) + by_group[def.group].insert(def.key); + CHECK(by_group.size() == 4); + CHECK(by_group["core"] == core); + CHECK(by_group["ui"] == ui); + CHECK(by_group["Commands"] == merged); + // The rest act on project data by index and name. + for (const char* name : {"set_settings", "slice", "generate_calibration_test", "get_slice_stats", "search_tools", "call_tool"}) + CHECK(by_group["api"].count(name) == 1); } -TEST_CASE("a registered tool's description starts with its lane, once", "[Mcp]") +TEST_CASE("no description starts with a bracketed tag", "[Mcp]") { - ToolRegistry registry; - ToolDef def; - def.name = "click"; - def.description = "Click a widget."; - def.read_only = false; - registry.add(def); - const ToolDef* added = registry.find("click"); - REQUIRE(added != nullptr); - CHECK(added->lane == ToolLane::Ui); - CHECK(added->description == "[ui] Click a widget."); - CHECK_FALSE(added->read_only); + const std::regex tag(R"(^\[[a-z]+\] )"); + for (const NativeCommand& def : Slic3r::GUI::NativeCommands::instance().commands()) + if (def.listed) { + INFO(def.key); + CHECK_FALSE(std::regex_search(def.description, tag)); + } - // A def copied from the registry and added again keeps one tag. - registry.add(*added); - CHECK(registry.find("click")->description == "[ui] Click a widget."); + // The catalog keeps a listed command's description as it is given. + CommandCatalog registry; + NativeCommand def; + def.key = "click"; + def.description = "Click a widget."; + def.listed = true; + registry.add(def); + REQUIRE(registry.find("click") != nullptr); + CHECK(registry.find("click")->description == "Click a widget."); +} + +TEST_CASE("search_tools reads one inventory", "[Mcp]") +{ + const auto command = [](const char* key, const char* group, bool listed, const char* description) { + NativeCommand c; + c.key = key; + c.group = group; + c.listed = listed; + c.description = description; + c.input_schema = object_schema({{"a", prop("number", "A number.")}}); + return c; + }; + CommandCatalog catalog; + catalog.add(command("measure_bed", "api", true, "Measure the bed. In mm.")); + NativeCommand tile = command("measure_tile", "View", false, "Measure what the view shows."); + tile.in_palette = true; + catalog.add(tile); + catalog.add_source(std::make_unique<OneCommandSource>(command("plugin.fixture.measure", "api", false, "Offered by a plugin. Doubles a."))); + catalog.seal(); + + const json found = search_commands(catalog, {{"query", "measure"}}); + CHECK(found["total"] == 3); + std::map<std::string, json> items; + for (const json& item : found["items"]) + items[item["name"].get<std::string>()] = item; + REQUIRE(items.size() == 3); + // A listed command's schema is in the tool list; the others' are nowhere else. + CHECK(items["measure_bed"]["listed"] == true); + CHECK(items["measure_bed"]["summary"] == "Measure the bed."); + CHECK_FALSE(items["measure_bed"].contains("input_schema")); + for (const char* unlisted : {"measure_tile", "plugin.fixture.measure"}) { + INFO(unlisted); + CHECK(items[unlisted]["listed"] == false); + CHECK(items[unlisted]["input_schema"]["properties"].contains("a")); + } + // An operation's first sentence only says a plugin offers it. + CHECK(items["plugin.fixture.measure"]["description"] == "Offered by a plugin. Doubles a."); + CHECK(found["use"].get<std::string>().find("call_tool {tool, args}") != std::string::npos); + + // {tool} describes any of them. + const json described = search_commands(catalog, {{"tool", "measure_tile"}}); + CHECK(described["listed"] == false); + CHECK(described["input_schema"]["properties"].contains("a")); + CHECK_THROWS_AS(search_commands(catalog, {{"tool", "measure_nothing"}}), ToolFailure); + + // group narrows the names and the matches, in any case, a source's commands included. + CHECK(search_commands(catalog, json::object())["names"] == json::array({"measure_bed", "measure_tile", "plugin.fixture.measure"})); + CHECK(search_commands(catalog, {{"group", "API"}})["names"] == json::array({"measure_bed", "plugin.fixture.measure"})); + CHECK(search_commands(catalog, {{"group", "view"}})["names"] == json::array({"measure_tile"})); + const json in_view = search_commands(catalog, {{"group", "View"}, {"query", "measure"}}); + REQUIRE(in_view["items"].size() == 1); + CHECK(in_view["items"][0]["name"] == "measure_tile"); + // A group no command has is refused with the groups there are. + try { + search_commands(catalog, {{"group", "commands"}}); + FAIL("an unknown group was not refused"); + } catch (const ToolFailure& f) { + CHECK(std::string(f.what()).find("Unknown group: commands") != std::string::npos); + CHECK(f.details["groups"] == json::array({"api", "View"})); + } } TEST_CASE("set_window refuses a request the window can't take, before changing anything", "[Mcp]") @@ -407,36 +524,45 @@ TEST_CASE("a call naming an object's id is refused once its index names another TEST_CASE("the journal records indices without expected ids, except a Python step's arguments", "[Mcp]") { - CHECK(without_expected_ids("set_settings", json{{"object", 0}, {"object_id", 7}, {"part_id", 8}}) == json{{"object", 0}}); - CHECK(without_expected_ids("set_height_ranges", json{{"object", 0}, {"object_id", 7}}) == json{{"object", 0}}); - CHECK(without_expected_ids("set_variable_layer_height", json{{"object", 0}, {"object_id", 7}}) == json{{"object", 0}}); + const CommandCatalog& catalog = Slic3r::GUI::NativeCommands::instance(); + CHECK(without_expected_ids(catalog, "set_settings", json{{"object", 0}, {"object_id", 7}, {"part_id", 8}}) == json{{"object", 0}}); + CHECK(without_expected_ids(catalog, "set_height_ranges", json{{"object", 0}, {"object_id", 7}}) == json{{"object", 0}}); + CHECK(without_expected_ids(catalog, "set_variable_layer_height", json{{"object", 0}, {"object_id", 7}}) == json{{"object", 0}}); const json replay{{"replay", {{"orca_replay", 1}, {"steps", {{{"tool", "transform"}, {"args", {{"object", 1}, {"object_id", 9}}}}, {{"tool", "run_script"}, {"args", {{"code", "x"}, {"args", {{"object_id", 9}}}}}}}}}}}; - const json recorded = without_expected_ids("run_replay", replay); + const json recorded = without_expected_ids(catalog, "run_replay", replay); CHECK(recorded["replay"]["steps"][0]["args"] == json{{"object", 1}}); CHECK(recorded["replay"]["steps"][1]["args"]["args"]["object_id"] == 9); - CHECK(without_expected_ids("run_script", json{{"code", "x"}, {"args", {{"object_id", 3}}}})["args"]["object_id"] == 3); + CHECK(without_expected_ids(catalog, "run_script", json{{"code", "x"}, {"args", {{"object_id", 3}}}})["args"]["object_id"] == 3); } TEST_CASE("the journal records an inline replay given as JSON text as its object, without expected ids", "[Mcp]") { + const CommandCatalog& catalog = Slic3r::GUI::NativeCommands::instance(); const json as_text{{"replay", "// moves the lid\n" R"({"orca_replay": 1, "steps": [{"tool": "transform", "args": {"object": 1, "object_id": 9}}]})"}}; - const json recorded = without_expected_ids("run_replay", as_text); + const json recorded = without_expected_ids(catalog, "run_replay", as_text); REQUIRE(recorded["replay"].is_object()); CHECK(recorded["replay"]["steps"][0]["args"] == json{{"object", 1}}); // Text that doesn't parse is the call's error; it is recorded as given. - CHECK(without_expected_ids("run_replay", json{{"replay", "{\"orca_replay\": 1,"}}) == json{{"replay", "{\"orca_replay\": 1,"}}); + CHECK(without_expected_ids(catalog, "run_replay", json{{"replay", "{\"orca_replay\": 1,"}}) == json{{"replay", "{\"orca_replay\": 1,"}}); } -TEST_CASE("the journal strips expected ids through call_tool and only from the tools that take them", "[Mcp]") +TEST_CASE("the journal strips a command's id arguments", "[Mcp]") { - CHECK(without_expected_ids("call_tool", json{{"tool", "transform"}, {"args", {{"object", 1}, {"object_id", 9}}}}) == + const CommandCatalog& catalog = Slic3r::GUI::NativeCommands::instance(); + CHECK(without_expected_ids(catalog, "transform", json{{"object", 0}, {"object_id", 7}}) == json{{"object", 0}}); + // Inside the call_tool and run_replay wrappers too. + CHECK(without_expected_ids(catalog, "call_tool", json{{"tool", "transform"}, {"args", {{"object", 1}, {"object_id", 9}}}}) == json{{"tool", "transform"}, {"args", {{"object", 1}}}}); + const json replay{{"replay", {{"orca_replay", 1}, + {"steps", {{{"tool", "call_tool"}, {"args", {{"tool", "transform"}, {"args", {{"object", 1}, {"object_id", 9}}}}}}}}}}}; + CHECK(without_expected_ids(catalog, "run_replay", replay)["replay"]["steps"][0]["args"]["args"] == json{{"object", 1}}); // A plugin operation's own fields of the same names are its arguments, recorded as given. - CHECK(without_expected_ids("plugin.measure.area", json{{"object_id", 4}}) == json{{"object_id", 4}}); - CHECK(without_expected_ids("call_tool", json{{"tool", "plugin.measure.area"}, {"args", {{"object_id", 4}}}})["args"]["object_id"] == 4); - CHECK(without_expected_ids("select_objects", json{{"objects", {0, 1}}, {"object_ids", {5, 6}}}) == json{{"objects", {0, 1}}}); - CHECK(without_expected_ids("select_objects", json{{"instances", {{0, 1}}}, {"instance_object_ids", {5}}}) == json{{"instances", {{0, 1}}}}); + CHECK(without_expected_ids(catalog, "plugin.measure.area", json{{"object_id", 4}}) == json{{"object_id", 4}}); + CHECK(without_expected_ids(catalog, "call_tool", json{{"tool", "plugin.measure.area"}, {"args", {{"object_id", 4}}}})["args"]["object_id"] == 4); + CHECK(without_expected_ids(catalog, "select_objects", json{{"objects", {0, 1}}, {"object_ids", {5, 6}}}) == json{{"objects", {0, 1}}}); + CHECK(without_expected_ids(catalog, "select_objects", json{{"instances", {{0, 1}}}, {"instance_object_ids", {5}}}) == + json{{"instances", {{0, 1}}}}); } diff --git a/tests/slic3rutils/test_operations.cpp b/tests/slic3rutils/test_operations.cpp index e8cd2696f7..f354fbd1c4 100644 --- a/tests/slic3rutils/test_operations.cpp +++ b/tests/slic3rutils/test_operations.cpp @@ -1,7 +1,7 @@ #include <catch2/catch_message.hpp> #include <catch2/catch_test_macros.hpp> -#include "slic3r/GUI/Mcp/McpService.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/Mcp/McpTypes.hpp" #include "slic3r/GUI/NativeCommands.hpp" #include "slic3r/GUI/Operations/Outcome.hpp" @@ -352,7 +352,7 @@ TEST_CASE("a project is not saved under a sliced file's name", "[Operations]") // ---- The catalogs name their operations --------------------------------------------------------------- // -// A tool that changes something, and a command that takes a param, either names the operations +// A tool that changes something, and a palette command that takes arguments, either names the operations // (GUI/Operations) it reaches or is listed here with the reason it reaches none. The lists are what a // new tool or command has to be added to, or kept off, in plain sight. They say how an entry is // classified; they do not check what its handler calls, which scripts/check_operation_calls.py does @@ -360,6 +360,20 @@ TEST_CASE("a project is not saved under a sliced file's name", "[Operations]") namespace { +// A command a person picks from the Speed Dial whose arguments stand for what it asks: it has a tile, no +// tool lists it (a listed command is under the tools' rule), and its schema has an argument beside the +// `silent` every two-form command takes. A Design command acts on the Design tab's document, which no +// operation stands for. +bool palette_command_with_arguments(const Slic3r::GUI::NativeCommand& command) +{ + if (!command.in_palette || command.listed || command.group == Slic3r::GUI::kDesignGroup) + return false; + for (const auto& [name, schema] : command.input_schema.at("properties").items()) + if (name != "silent") + return true; + return false; +} + // Every function of GUI/Operations a catalog entry may name. const std::set<std::string> kOperations = { "start_gcode_export", "export_sliced_3mf", "export_model_3mf", "export_stl", "send_gcode_to_host", @@ -374,13 +388,13 @@ constexpr const char* kDrivesTheGui = "drives the GUI as a person does: the constexpr const char* kSessionState = "changes the automation session (jobs, the journal, recordings), not the project"; constexpr const char* kOneEntryPoint = "its function has one automation entry point, so no second caller can drift from it"; constexpr const char* kAsks = "the asking path: it calls the owner's method, which asks the person"; +constexpr const char* kHistory = "it calls the undo and redo of the history it names, which no operation stands for"; const std::map<std::string, const char*> kToolExceptions = { {"run_replay", kRunsWhatItIsGiven}, {"run_script", kRunsWhatItIsGiven}, {"run_action", kRunsWhatItIsGiven}, {"call_tool", kRunsWhatItIsGiven}, - {"call_cad_tool", kRunsWhatItIsGiven}, {"run_javascript", kRunsWhatItIsGiven}, {"click", kDrivesTheGui}, {"set_widget_value", kDrivesTheGui}, @@ -410,7 +424,6 @@ const std::map<std::string, const char*> kCommandExceptions = { {"load_project", kAsks}, {"go_to_tab", kOneEntryPoint}, {"open_preferences", kOneEntryPoint}, - {"start_recording", kSessionState}, {"export_stl_multi", kOneEntryPoint}, {"export_config", kOneEntryPoint}, {"obj_rename", kOneEntryPoint}, @@ -427,6 +440,8 @@ const std::map<std::string, const char*> kCommandExceptions = { {"add_primitive_torus", kOneEntryPoint}, {"install_local_plugin", kOneEntryPoint}, {"filament_delete", kOneEntryPoint}, + {"undo", kHistory}, + {"redo", kHistory}, }; } // namespace @@ -487,22 +502,22 @@ TEST_CASE("a filament pick finds the selector's row that stores the preset, else CHECK(row_for_preset({}, "Bambu ABS") == -1); } -TEST_CASE("a tool that changes something names its operations or is a listed exception", "[Operations]") +TEST_CASE("a listed command that is not read-only names its operations or is a listed exception", "[Operations]") { - for (const Slic3r::GUI::Mcp::ToolDef& tool : Slic3r::GUI::Mcp::McpService::offline_catalog().tools()) { - if (tool.read_only) + for (const Slic3r::GUI::NativeCommand& tool : Slic3r::GUI::NativeCommands::instance().commands()) { + if (!tool.listed || tool.read_only) continue; - INFO(tool.name); - const bool excepted = kToolExceptions.count(tool.name) != 0; + INFO(tool.key); + const bool excepted = kToolExceptions.count(tool.key) != 0; // One or the other: an exception that names operations has stopped being one. CHECK(tool.operations.empty() == excepted); } } -TEST_CASE("a command with a param names its operations or is a listed exception", "[Operations]") +TEST_CASE("a palette command that takes arguments names its operations or is a listed exception", "[Operations]") { - for (const Slic3r::GUI::NativeCommand& command : Slic3r::GUI::NativeCommands::catalog()) { - if (command.param.type == Slic3r::GUI::CommandParamType::None) + for (const Slic3r::GUI::NativeCommand& command : Slic3r::GUI::NativeCommands::instance().commands()) { + if (!palette_command_with_arguments(command)) continue; INFO(command.key); const bool excepted = kCommandExceptions.count(command.key) != 0; @@ -512,12 +527,7 @@ TEST_CASE("a command with a param names its operations or is a listed exception" TEST_CASE("a catalog entry names only operations the layer has", "[Operations]") { - for (const Slic3r::GUI::Mcp::ToolDef& tool : Slic3r::GUI::Mcp::McpService::offline_catalog().tools()) - for (const std::string& operation : tool.operations) { - INFO(tool.name << " names " << operation); - CHECK(kOperations.count(operation) == 1); - } - for (const Slic3r::GUI::NativeCommand& command : Slic3r::GUI::NativeCommands::catalog()) + for (const Slic3r::GUI::NativeCommand& command : Slic3r::GUI::NativeCommands::instance().commands()) for (const std::string& operation : command.operations) { INFO(command.key << " names " << operation); CHECK(kOperations.count(operation) == 1); @@ -526,11 +536,11 @@ TEST_CASE("a catalog entry names only operations the layer has", "[Operations]") TEST_CASE("the exception lists name only entries the catalogs have", "[Operations]") { - const Slic3r::GUI::Mcp::ToolRegistry& tools = Slic3r::GUI::Mcp::McpService::offline_catalog(); for (const auto& [name, reason] : kToolExceptions) { INFO(name << ": " << reason); - const Slic3r::GUI::Mcp::ToolDef* tool = tools.find(name); + const Slic3r::GUI::NativeCommand* tool = Slic3r::GUI::NativeCommands::find(name); REQUIRE(tool != nullptr); + CHECK(tool->listed); // A read-only tool needs no exception. CHECK_FALSE(tool->read_only); } @@ -538,14 +548,40 @@ TEST_CASE("the exception lists name only entries the catalogs have", "[Operation INFO(key << ": " << reason); const Slic3r::GUI::NativeCommand* command = Slic3r::GUI::NativeCommands::find(key); REQUIRE(command != nullptr); - CHECK(command->param.type != Slic3r::GUI::CommandParamType::None); + CHECK(palette_command_with_arguments(*command)); + } +} + +// The Design tab's commands act on its document, which no operation stands for, as +// scripts/check_operation_calls.py leaves McpToolsCad.cpp out. +TEST_CASE("the operations rule leaves the Design group out", "[Operations]") +{ + Slic3r::GUI::NativeCommand tile; + tile.key = "shell"; + tile.group = "Design"; + tile.in_palette = true; + tile.input_schema = {{"type", "object"}, {"properties", {{"thickness", {{"type", "number"}}}, {"silent", {{"type", "boolean"}}}}}}; + CHECK_FALSE(palette_command_with_arguments(tile)); + tile.group = "Commands"; + CHECK(palette_command_with_arguments(tile)); + + // With the CAD feature on, no Design command is under the rule, and none is on an exception list. + Slic3r::GUI::CommandCatalog catalog; + Slic3r::GUI::NativeCommands::register_all_commands(catalog, {true}); + for (const Slic3r::GUI::NativeCommand& command : catalog.commands()) { + if (command.group != "Design") + continue; + INFO(command.key); + CHECK_FALSE(palette_command_with_arguments(command)); + CHECK(kToolExceptions.count(command.key) == 0); + CHECK(kCommandExceptions.count(command.key) == 0); } } TEST_CASE("the field that names a tool's operations is in no listing", "[Operations]") { // tools/list and search_actions stay as they are: the field is for the catalog test alone. - const Slic3r::GUI::Mcp::ToolDef* tool = Slic3r::GUI::Mcp::McpService::offline_catalog().find("export"); + const Slic3r::GUI::NativeCommand* tool = Slic3r::GUI::NativeCommands::find("export"); REQUIRE(tool != nullptr); REQUIRE_FALSE(tool->operations.empty()); CHECK(tool->input_schema.dump().find("start_gcode_export") == std::string::npos); diff --git a/tests/slic3rutils/test_plugin_host_api.cpp b/tests/slic3rutils/test_plugin_host_api.cpp index 37f6b68c2c..762142061d 100644 --- a/tests/slic3rutils/test_plugin_host_api.cpp +++ b/tests/slic3rutils/test_plugin_host_api.cpp @@ -17,6 +17,7 @@ #include <catch2/catch_all.hpp> +#include <algorithm> #include <cstddef> #include <libslic3r/Model.hpp> #include <libslic3r/PresetBundle.hpp> @@ -45,6 +46,7 @@ #include <nlohmann/json.hpp> #include <slic3r/GUI/Mcp/McpTools.hpp> +#include <slic3r/plugin/PluginOperations.hpp> #include <regex> #include <set> @@ -637,6 +639,78 @@ TEST_CASE("Plugin host API exposes TriangleMesh geometry to Python", "[PluginHos REQUIRE_THAT(instance_matrix.attr("__getitem__")(py::make_tuple(1, 3)).cast<double>(), WithinAbs(6.0, 1e-6)); } +TEST_CASE("a script reads the catalog", "[PluginHost][Python]") +{ + py::module_ orca = import_orca_module(); + // An operation a plugin offers is among the commands while it is offered. + Slic3r::PluginOperation op; + op.plugin_key = "catalog_reader"; + op.name = "measure"; + op.description = "Measures the plate."; + op.changes = false; + Slic3r::PluginOperations::instance().add(op); + py::dict scope; + try { + py::exec(R"PY( +import orca +tools = orca.host.tools +state = tools.describe("get_app_state") +commands = tools.list() +names = [entry["name"] for entry in commands] +fields = sorted(commands[0]) +plugin_fields = sorted(next(entry for entry in commands if entry["name"] == "plugin.catalog_reader.measure")) +operation = tools.describe("plugin.catalog_reader.measure") +try: + tools.describe("nope") + unknown = None +except tools.ToolError as error: + unknown = (str(error), error.details) +try: + tools.describe("get_app_stat") + mistyped = None +except tools.ToolError as error: + mistyped = error.details +)PY", + scope); + } catch (...) { + Slic3r::PluginOperations::instance().remove_plugin("catalog_reader"); + throw; + } + Slic3r::PluginOperations::instance().remove_plugin("catalog_reader"); + + CHECK(scope["state"]["read_only"].cast<bool>()); + CHECK(scope["state"]["key"].cast<std::string>() == "get_app_state"); + CHECK(scope["state"].contains("input_schema")); + CHECK(py::len(scope["commands"]) >= 53); + const std::vector<std::string> list_fields{"description", "group", "listed", "name", "read_only", "title"}; + CHECK(scope["fields"].cast<std::vector<std::string>>() == list_fields); + CHECK(scope["plugin_fields"].cast<std::vector<std::string>>() == list_fields); + const auto names = scope["names"].cast<std::vector<std::string>>(); + for (const char* name : {"get_app_state", "obj_arrange", "plugin.catalog_reader.measure"}) { + CAPTURE(name); + CHECK(std::count(names.begin(), names.end(), name) == 1); + } + CHECK(scope["operation"]["group"].cast<std::string>() == "api"); + CHECK(scope["operation"]["read_only"].cast<bool>()); + REQUIRE_FALSE(scope["unknown"].is_none()); + CHECK(scope["unknown"].cast<py::tuple>()[0].cast<std::string>() == "Unknown tool: nope"); + const py::dict details = scope["unknown"].cast<py::tuple>()[1].cast<py::dict>(); + REQUIRE(details.contains("did_you_mean")); + CHECK(py::isinstance<py::list>(details["did_you_mean"])); + REQUIRE_FALSE(scope["mistyped"].is_none()); + const auto close = scope["mistyped"]["did_you_mean"].cast<std::vector<std::string>>(); + REQUIRE_FALSE(close.empty()); + CHECK(close.front() == "get_app_state"); + + // search_python_api documents both, as it does every function of the package. + std::set<std::string> documented; + for (const nlohmann::json& entry : Slic3r::GUI::Mcp::python_api_reference()) + if (entry["kind"] == "function" && !entry["doc"].get<std::string>().empty()) + documented.insert(entry["name"].get<std::string>()); + CHECK(documented.count("orca.host.tools.list") == 1); + CHECK(documented.count("orca.host.tools.describe") == 1); +} + TEST_CASE("every public member of the orca package has documentation and named parameters", "[PluginHost][Python]") { // search_python_api serves this documentation to agents writing scripts and plugins: a member without it, or diff --git a/tools/mcp/README.md b/tools/mcp/README.md index 96207103ff..ee7e4e6efe 100644 --- a/tools/mcp/README.md +++ b/tools/mcp/README.md @@ -18,8 +18,9 @@ Python. It uses only the standard library. `docs/HLSD/mcp-server.md` covers the `launch` creates a fresh temporary datadir unless you pass `--datadir`. It seeds the datadir with an `OrcaSlicer.conf` that has a finished setup wizard and one printer and filament (Bambu Lab X1 Carbon 0.4 by default), with update checks and daily tips turned off. `--cad` turns the Design -(CAD) tab on, which `call_cad_tool` needs: it sets `enable_cad_feature` in a fresh datadir's -`OrcaSlicer.conf`, and in a reused one too, since the app creates the Design tab only at startup, when that setting is on. +(CAD) tab on, and with it its commands: it sets `enable_cad_feature` in a fresh datadir's +`OrcaSlicer.conf`, and in a reused one too, since the app creates the Design tab and its commands only at +startup, when that setting is on. `--unrestricted-scripts` lets Python scripts (`run_script`) run unrestricted the same way, by setting `mcp_python_unrestricted`, since no tool can turn that on. The token comes from `ORCA_MCP_TOKEN` or is generated, and it reaches the app through the environment, not the command @@ -84,8 +85,8 @@ under AI features in Preferences), attach to it through its datadir instead of a ```python orca = OrcaMcp.from_datadir() # the datadir the app uses without --datadir orca = OrcaMcp.from_datadir("/abs/datadir") # an app started with --datadir /abs/datadir -scene = orca.call_cad_tool("describe_scene") # one CAD tool of the Design tab -orca.call_cad_tool("helix", radius=10, pitch=3, height=30) +scene = orca.call_command("describe_scene")["result"] # a Design command (the Design tab on) +orca.call_command("helix", radius=10, pitch=3, height=30) ``` `from_datadir()` reads the port and token from `<datadir>/mcp/server.json`, which the server writes @@ -100,13 +101,25 @@ unverified, which matters only for a symlinked binary. When the file is missing, port it names fails (nothing listens there, or another server answers), `from_datadir()` raises `McpError` saying so, with the failure as its cause. -`call_cad_tool(tool, **args)` calls `call_cad_tool {tool, args}`, follows a running job to its end -and returns the CAD tool's `result`. A call whose first reply says a dialog blocks it fails at -once, naming the dialog, rather than waiting on it. A call that first replied `running` and opens a -dialog later is waited on up to the timeout (600 s), since `wait` reports only that its job is still -running. Every `McpError` it raises starts with the CAD tool's name (`"extrude: ..."`) and has the -original error as its cause. `list_cad_tools` and `describe_cad_tool` name the CAD tools and their -arguments. +`call_command(tool, **args)` calls `call_tool {tool, args}`, follows a running job to its end and +returns the command's whole reply, which for a Design command is `{"result": ...}`. A call whose first +reply says a dialog blocks it fails at once, naming the dialog, rather than waiting on it. A call that +first replied `running` and opens a dialog later is waited on up to the timeout (600 s), since `wait` +reports only that its job is still running. Every `McpError` it raises starts with the command's name +(`"extrude: ..."`) and has the original error as its cause. `search_tools {group: "Design"}` names the +Design commands, and `search_tools {tool}` gives one's arguments and examples. + +## The skill's list of commands + +`gen_skill_reference.py <skills-checkout> [--check]` writes +`skills/orcaslicer-mcp-skills/references/actions.md` in a checkout of the orcaslicer-mcp-skills repository: +the Speed Dial's commands section by section, each with its key, title, arguments and description, from +the command reference `tests/data/command_catalog.json` (`docs/HLSD/mcp-server.md`, "Making a feature +reachable"), and before them what the reference says of particular commands: those with one form, which +needs its value, and the typed tools that are tiles too. It needs no running app. With `--check` it writes +nothing, prints the difference and exits 1 when the file is not what it would write. When a command +changed, regenerate the reference first: run `slic3rutils_tests "[Reference]"` with +`ORCA_UPDATE_COMMAND_REFERENCE=1` in the environment. ## Smoke test @@ -132,8 +145,10 @@ screenshots in the output directory. `tests/replay_basic.json` is the smallest s change a setting, slice and capture. `test_plugin_tools.py` checks a plugin's calls into the tools in the running app: it side-loads -`tests/plugins/mcp_tools_fixture` into a fresh data folder and launches twice: over MCP (its operation is -reached through `search_tools` and `call_tool`, and stays out of `tools/list`, calls from its Script worker +`tests/plugins/mcp_tools_fixture` into a fresh data folder and launches twice: over MCP, with the Design tab +on (its operation is reached through `search_tools` and `call_tool` and stays out of `tools/list`, a Speed +Dial command is found among `search_tools`' commands with its schema and not again among its actions, a +Design command is found there too, in no section of its own, calls from its Script worker and a thread it starts reach the tools, an auto-answer rule it sets is the plugin's, `export_replay` is refused, nothing it calls is journaled, a script that finds its progress dialog handle can use it, `tests/plugins/mcp_tools_broken`, whose load fails, offers none of its operations, and unticking the @@ -199,14 +214,14 @@ tools/mcp/orca_mcp.py call run_replay '{"path": "/abs/tools/mcp/tests/gizmos.jso `tests/scene.json` checks object structure and placement: `transform` on an instance (the drop after a scale, `size`, a move to another plate), on a part, what `list_objects` reports of them (bounding boxes on the bed, filament, the scaled volume, a mirrored part and instance), the selection as `select_objects` and -`get_app_state` report it (parts, whole instances, one instance of two), the shape commands with a size -param, `arrange` on one plate and every plate, Fill bed, the Speed Dial no-op that `run_action` -reports as an error, `add_part` (shapes at a size and a position, a model file, one undo step, -and what it refuses), and the object structure commands (Change Type, Rename, number of instances, -individual objects, Assemble, Order By and its reversal, and what each refuses). It ends with all of -them on one scene: a block with a magnet pocket and a boss, sized, moved to a second plate, copied six -times and arranged there, split into objects, one mirrored, two assembled, ordered, the plate filled -and sliced. +`get_app_state` report it (parts, whole instances, one instance of two), the shape commands given a size +(`run_action` with `args` `{"size": [...]}`), `arrange` on one plate and every plate, Fill bed, the Speed +Dial no-op that `run_action` reports as an error, `add_part` (shapes at a size and a position, a model +file, one undo step, and what it refuses), and the object structure commands (Change Type, Rename, +number of instances, individual objects, Assemble, Order By and its reversal, and what each refuses). It +ends with all of them on one scene: a block with a magnet pocket and a boss, sized, moved to a second +plate, copied six times and arranged there, split into objects, one mirrored, two assembled, ordered, +the plate filled and sliced. `tests/layers.json` checks height range modifiers: `set_height_ranges` with ranges given out of order, their read-back in `list_objects`, one undo step (and none for the same ranges again), the layer count @@ -226,8 +241,10 @@ filament change, a 3MF round trip, and `clear`. Preferences dialog opened and closed, a slice. It stops the recording (frames, length, size) and encodes it to H.265, then has a nested replay start a recording of the 3D view that it never stops, checks the replay's end closed it, and encodes that to H.264. Short recordings check that a recording has no overlays -unless `captions` or `pointer` turns one on, and that one started with `encode` is encoded as a job once -`stop_recording` reports it. The encodes need an ffmpeg with libx265 and libx264 +unless `captions` or `pointer` turns one on, that one started with a path and no `max_seconds` runs under an +hour's limit, and that one started with `encode` is encoded as a job once `stop_recording` reports it. Its +`new_project` and `stop_recording` calls pass `silent: true`: with no arguments they would do what a +person's pick does, asking and stopping without a report. The encodes need an ffmpeg with libx265 and libx264 (`ORCA_FFMPEG`, or `ffmpeg` on `PATH`) and are optional without one. Look at the videos, or at frames `ffmpeg -i session.mkv -vf fps=1 frame%02d.png` extracts, for the caption, the pointer and the dialog. @@ -291,10 +308,9 @@ between two builds. The preset replays share `tests/fixtures/ops_presets.py`, which sets the slots, colours and flushing volumes to known values before each case, and each needs a freshly launched app, since a hidden preset that `select_preset` shows stays shown until a restart. The replays whose commands write files -need a fresh `--out`: a command's JSON path param can't hold a Windows `${out_dir}`, so those commands -write without `overwrite`. Launch the app from a folder that holds no `.py` files, since the app's -working directory is on Python's module path and a file there can shadow a standard module that -`run_script` needs. +need a fresh `--out`, since those commands write without `overwrite`. Launch the app from a folder that +holds no `.py` files, since the app's working directory is on Python's module path and a file there can +shadow a standard module that `run_script` needs. `test_operation_routes.py` asserts what those replays only record: that a command, the tool that does the same thing and the plugin API's binding refuse the same states with the same code and words, and @@ -304,8 +320,9 @@ a gizmo open, a mixed-colour filament slot, and a hidden printer selected throug it on a freshly launched app, for the reasons above and because the Preview keeps the last slice's layers. -The Design-tab replays drive `call_cad_tool` and need an instance launched with `--cad`. Each starts -from a new project and checks what it builds by volume and by what `call_cad_tool` reads back; steps +The Design-tab replays drive the Design commands through `call_tool` and need an instance launched with +`--cad`. Each starts from a new project and checks what it builds by volume and by what the reading +commands give back, under each reply's `result`; steps marked `optional` are calls that must be refused and change nothing. - `tests/cad_sketch_to_solid.json` takes sketches to solids: an L-bracket profile on XZ through the @@ -318,7 +335,7 @@ marked `optional` are calls that must be refused and change nothing. rounded corner, two slots (one an array copy turned upright), an elliptic hole and four holes arrayed about a point, constrained from picks and from named points, with a refused constraint rolled back and one deleted. -- `tests/cad_topology_targets.json` builds the bench's J wall hook from what `call_cad_tool` reads back: +- `tests/cad_topology_targets.json` builds the bench's J wall hook from what the reading commands give back: its inside corners found by convexity, M4 countersinks seated on the front face on the axes of pilot holes, the cones' kind, apex side and radii from `query_topology`, the hole heights and the plate's thickness from `measure`, a datum plane midway through the plate and one 70 mm up with a @@ -350,36 +367,38 @@ commit and a missed hole, which must fail and be left out, a legacy `fillet` ans which stays in, and face and edge ids passed with their `generation`, which the journal drops. `test_cad_slow_build.py` runs a long thread build (an M8 thread tapped 60 mm deep, about 8 s) and checks that while it builds `get_app_state` answers, a window screenshot succeeds, `list_widgets` lists -the progress dialog and a screenshot of that dialog captures it, and another `call_cad_tool` is refused. +the progress dialog and a screenshot of that dialog captures it, and another Design command is refused. `test_cad_failed_job.py` sweeps a coil whose every rebuild takes about 30 s (its turns sized from a short calibration build), then a hole that misses it replies with a running job and fails after the reply budget: an export while it runs leaves it out and names it in `left_out_running`, the export after it has the rename made next and not the hole, and that replay runs to the same coil. -It takes three to four minutes. +It takes three to four minutes. `test_cad_examples.py` runs the examples `search_tools {tool}` gives for +every Design command, and for `undo` and `redo`, each on a fresh design, and fails one whose call fails or +whose result has `ok` false, an error, or is the person's form; `--tool NAME` runs one command's. -Three more harness tests on a `--cad` instance drive the Design tab the way a person does. Every -action goes through the UI tools (`set_view`, `click`, `mouse_gesture`, `press_keys`, -`set_widget_value`, `answer_dialog` and `auto_answer_dialogs`), and `call_cad_tool` only reads the -result back (`sketch_describe`, `describe_scene`, `describe_feature`, `list_verbs`), save for one -call in the scale rung. Buttons and rows are found by label, and canvas positions come from a -calibration that maps the open sketch's plane to canvas pixels, so nothing in them is tuned to a -window size, screen scaling or theme. The sketch tool's pick budgets and badge layout are in the -canvas's GL pixels, which `cad_gui.py` turns into click pixels by the canvas scale that `set_view`'s -`camera_state` gives (`zoom` over `click_px_per_mm`). What they share is in `cad_gui.py` beside them. -`test_cad_sketching.py` draws each sketch tool's primitive with clicks on the canvas and types its -exact values into the canvas's value field, drives the edit operations and each constraint button on -drawn geometry, undoes inside a sketch and across its commit, saves the project and opens it again -through the File menu, and draws on top of a sketch holding 1204 entities. That last rung, `scale`, -loads them with one `call_cad_tool sketch_add` while the rectangle tool is armed: the one call in -these tests that changes the sketch outside the UI, on purpose, since a bulk add made while a +Three more harness tests on a `--cad` instance drive the Design tab the way a person does. Every action goes +through the UI tools (`set_view`, `click`, `mouse_gesture`, `press_keys`, `set_widget_value`, `answer_dialog` +and `auto_answer_dialogs`), and the Design commands only read the result back (`sketch_describe`, +`describe_scene`, `describe_feature`), save for one call in the scale rung; the right-click menu's layout they +grade against is read from `scripts/CAD/tool_atlas.json`, the Design table the app's own is generated from, +for the selection `describe_scene` names. Buttons and rows are found by label, and canvas positions come from +a calibration that maps the open sketch's plane to canvas pixels, so nothing in them is tuned to a window +size, screen scaling or theme. The sketch tool's pick budgets and badge layout are in the canvas's GL pixels, +which `cad_gui.py` turns into click pixels by the canvas scale that `set_view`'s `camera_state` gives (`zoom` +over `click_px_per_mm`). What they share is in `cad_gui.py` beside them. `test_cad_sketching.py` draws each +sketch tool's primitive with clicks on the canvas and types its exact values into the canvas's value field, +drives the edit operations and each constraint button on drawn geometry, undoes inside a sketch and across its +commit, saves the project and opens it again through the File menu, and draws on top of a sketch holding 1204 +entities. That last rung, `scale`, loads them with one `sketch_add` command while the rectangle tool is armed: +the one call in these tests that changes the sketch outside the UI, on purpose, since a bulk add made while a creation tool is armed must not be read as a drawn gesture that swallows the next key and click. -`test_cad_context_menu.py` checks that the right-click offer names what was clicked and lists exactly -the verbs `list_verbs` says apply to it, and drives from the menu every sketch verb that has no key, -a Text typed into the Text dialog and an SVG import (`tests/fixtures/rect_40x20.svg`) among them. -`test_cad_click_edit.py` checks that each value field a drawing tool opens takes digits typed with no -click into it and that Return commits them, for the line, rectangle, circle, slot, polygon, ellipse -and arc tools armed by their keys, the rounded rectangle armed from the offer, and a rectangle's -width label clicked in Select. +`test_cad_context_menu.py` checks that the right-click offer names what was clicked and lists exactly the +verbs the Design table says apply to it, and drives from the menu every sketch verb that has no key, a Text +typed into the Text dialog and an SVG import (`tests/fixtures/rect_40x20.svg`) among them. +`test_cad_click_edit.py` checks that each value field a drawing tool opens takes digits typed with no click +into it and that Return commits them, for the line, rectangle, circle, slot, polygon, ellipse and arc tools +armed by their keys, the rounded rectangle armed from the offer, and a rectangle's width label clicked in +Select. ```bash tools/mcp/orca_mcp.py launch --cad diff --git a/tools/mcp/cad_gui.py b/tools/mcp/cad_gui.py index 0b292bdbdd..e9fa3c8e9a 100644 --- a/tools/mcp/cad_gui.py +++ b/tools/mcp/cad_gui.py @@ -1,8 +1,9 @@ """Drive the Design tab of a running OrcaSlicer the way a person does, for the Design-tab GUI tests. Every action goes through the MCP server's UI tools (set_view, click, mouse_gesture, press_keys, -set_widget_value, answer_dialog); call_cad_tool is used only to read results back (sketch_describe, -describe_scene, describe_feature, list_verbs). Nothing here knows a pixel: buttons and rows are +set_widget_value, answer_dialog); the Design commands are used only to read results back (sketch_describe, +describe_scene, describe_feature), and the right-click menu's layout is read from the Design table's source, +scripts/CAD/tool_atlas.json, as the app's own table is generated from it. Nothing here knows a pixel: buttons and rows are found by label, and canvas positions come from a calibration that maps the open sketch's plane (millimetres) to canvas pixels, so the tests run at any window size, screen scaling and theme. Labels, menu paths and verb names are English, which start() checks. @@ -13,7 +14,9 @@ English, which start() checks. """ import collections +import json import math +import os import re import sys import time @@ -24,6 +27,9 @@ import orca_mcp # the system's legacy code page, which may lack them: they print escaped rather than raise. sys.stdout.reconfigure(errors="backslashreplace") +# The Design table's source, which DesignOffer.hpp, the right-click menu and the Design commands are made from. +ATLAS = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir, "scripts", "CAD", "tool_atlas.json") + # The 3D canvas by its window name, which every platform lists; only Windows gives it as its label too. CANVAS = {"name": "OrcaSceneCanvas"} NEW_DESIGN = "New Design — clear the feature tree" @@ -335,16 +341,16 @@ class CadGui: # ------------------------------------------------------------ reading def cad(self, tool, **args): - """A CAD tool's result. The tests read with it and change nothing, save one bulk add whose + """A Design command's result. The tests read with it and change nothing, save one bulk add whose call says why.""" - return self.client.call_cad_tool(tool, **args) + return self.client.call_command(tool, **args)["result"] def sketch(self): return self.cad("sketch_describe") def _sketch_or_none(self): """sketch_describe, or None when no sketch is open. Any other error (a modal dialog refuses - every call_cad_tool while it is open) is raised, since it says nothing about the sketch.""" + every Design command while it is open) is raised, since it says nothing about the sketch.""" try: return self.sketch() except orca_mcp.McpError as e: @@ -840,4 +846,26 @@ class CadGui: return self.click_mm(X, Y, button="right", popup_item=path) def verbs(self, sketch_mode=True): - return self.cad("list_verbs", sketch_mode=sketch_mode)["verbs"] + """The verbs of the right-click menu, in the Design table's order, for the selection it would be built + for now (describe_scene's selection): those of the sketch vocabulary, or with sketch_mode False of the + model one, or with None both. Each has id, name, row, row_name, family (its submenu within the row, + or None), key, action, sketch_mode, applies (it accepts the selection), modal and hint, as the table + has them; entries with no menu row (commands only) are left out.""" + with open(ATLAS, encoding="utf-8") as f: + atlas = json.load(f) + slots = atlas["slots"] + rows = [s["id"] for s in slots] + selection = self.cad("describe_scene")["selection"]["id"] + out = [] + for v in atlas["verbs"]: + if v["slot"] is None: + continue + sketch = v.get("mode") == "sketch" + if sketch_mode is not None and sketch != sketch_mode: + continue + row = rows.index(v["slot"]) + out.append({"id": v["id"], "name": v["name"], "row": row, "row_name": slots[row]["label"], + "family": v.get("family"), "key": v.get("key"), "action": v.get("action"), + "sketch_mode": sketch, "applies": selection in v["accepts"], + "modal": bool(v.get("modal")), "hint": v.get("hint")}) + return out diff --git a/tools/mcp/gen_skill_reference.py b/tools/mcp/gen_skill_reference.py new file mode 100644 index 0000000000..732d59f74e --- /dev/null +++ b/tools/mcp/gen_skill_reference.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python3 +"""Write the skill's list of the Speed Dial's commands from the command reference. + + python tools/mcp/gen_skill_reference.py <skills-checkout> # rewrite actions.md + python tools/mcp/gen_skill_reference.py <skills-checkout> --check # exit 1 when it differs + +Reads tests/data/command_catalog.json, the reference of the command catalog that the unit test +"the checked-in command reference matches the catalog" keeps current, and writes +skills/orcaslicer-mcp-skills/references/actions.md in the checkout of the orcaslicer-mcp-skills +repository: every command a person can pick (in_palette), section by section in the order the +catalog adds them, with its key, title, arguments and description. The file is generated: edit the +commands in OrcaSlicer and regenerate it. Standard library only. +""" + +import argparse +import difflib +import json +import sys +import textwrap +from pathlib import Path + +REPO = Path(__file__).resolve().parents[2] +REFERENCE = REPO / "tests" / "data" / "command_catalog.json" +TARGET = Path("skills") / "orcaslicer-mcp-skills" / "references" / "actions.md" + +HEADER = """\ +# Speed Dial commands + +Generated by OrcaSlicer's `tools/mcp/gen_skill_reference.py` from its command reference +(`tests/data/command_catalog.json`); do not edit it by hand. + +These are the commands a person picks in the Speed Dial, by section. Call one with +`call_tool {"tool": "<key>", "args": {...}}`, or run its tile with `run_action {"id": "<key>", "args": {...}}`; +`search_tools {"tool": "<key>"}` gives its whole schema, and its examples when it has some. A command called +with no arguments does what a person's pick does: one that asks in a dialog opens it, which a call reports as +`blocked_by_dialog`. A command that takes `silent` has a second form: given any argument, or `silent: true`, +it runs without asking and needs the arguments marked required. The Design section's commands need the +Design tab on (`launch --cad`), and their tiles are the Speed Dial's only while that tab is shown; +`references/cad.md` covers them. +""" + + +def cell(text): + """`text` as one Markdown table cell: on one line, its pipes escaped.""" + return " ".join(str(text).split()).replace("|", "\\|") + + +def argument(name, schema, required): + """One argument of a command's schema: `name` (type, required): description, one of its values.""" + kind = schema.get("type", "any") + if isinstance(kind, list): + kind = " or ".join(kind) + if kind == "array" and isinstance(schema.get("items"), dict) and "type" in schema["items"]: + kind = "array of " + str(schema["items"]["type"]) + notes = [kind] + (["required"] if required else []) + text = "`%s` (%s)" % (name, ", ".join(notes)) + if schema.get("description"): + text += ": " + schema["description"] + if "enum" in schema and not (kind == "boolean" and schema["enum"] == [True]): + text += " One of " + ", ".join("`%s`" % json.dumps(value) for value in schema["enum"]) + "." + return text + + +def arguments(schema): + """A command's arguments for its table row, those its silent form requires marked so.""" + required = set(schema.get("required", [])) | set(schema.get("then", {}).get("required", [])) + properties = schema.get("properties", {}) + return "<br>".join(argument(name, properties[name], name in required) for name in properties) + + +def names(commands): + """The keys of `commands`, in backticks and joined as a sentence lists them.""" + keys = ["`%s`" % c["key"] for c in commands] + return keys[0] if len(keys) == 1 else ", ".join(keys[:-1]) + " and " + keys[-1] + + +def header(palette): + """HEADER, with what it says of particular commands read from the reference: the commands with one form, + which needs a value (a top-level `required`), and the typed tools that are tiles too (`listed`).""" + needs = [c for c in palette if c["input_schema"].get("required")] + both = [c for c in palette if c["listed"]] + facts = [] + if needs: + facts.append("%s %s." % (names(needs), "needs its value" if len(needs) == 1 else "need their value")) + if both: + facts.append("A typed tool that is also a tile (%s) is in the tool list too." % names(both)) + if not facts: + return HEADER + return HEADER + "\n" + "\n".join(textwrap.wrap(" ".join(facts), width=110)) + "\n" + + +def render(reference): + palette = [command for command in reference["commands"] if command["in_palette"]] + sections = {} + for command in palette: + sections.setdefault(command["group"], []).append(command) + out = [header(palette)] + for group, commands in sections.items(): + out.append("\n## %s\n\n| key | title | arguments | does |\n|---|---|---|---|\n" % group) + for c in commands: + out.append("| `%s` | %s | %s | %s |\n" % (c["key"], cell(c["title"]), cell(arguments(c["input_schema"])), + cell(c["description"]))) + return "".join(out) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + parser.add_argument("skills", type=Path, help="the orcaslicer-mcp-skills checkout") + parser.add_argument("--check", action="store_true", help="write nothing; exit 1 when actions.md differs") + args = parser.parse_args() + + target = args.skills / TARGET + if not target.parent.is_dir(): + parser.error("%s is not an orcaslicer-mcp-skills checkout: it has no %s" % (args.skills, TARGET.parent)) + with REFERENCE.open(encoding="utf-8") as f: + text = render(json.load(f)) + + if not args.check: + with target.open("w", encoding="utf-8", newline="\n") as f: + f.write(text) + print("wrote %s" % target) + return 0 + # A checkout may have turned the file's line ends into CRLF. + current = target.read_text(encoding="utf-8").replace("\r\n", "\n") if target.exists() else "" + if current == text: + print("%s is current" % target) + return 0 + sys.stdout.writelines(difflib.unified_diff(current.splitlines(True), text.splitlines(True), str(target), "generated")) + print("\n%s differs from the command reference; run without --check to rewrite it" % target) + return 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/mcp/orca_mcp.py b/tools/mcp/orca_mcp.py index 27a21c8dc8..97b8b1e991 100755 --- a/tools/mcp/orca_mcp.py +++ b/tools/mcp/orca_mcp.py @@ -9,7 +9,7 @@ Standard library only. Two halves: tools/mcp/orca_mcp.py launch --headless # fresh datadir on a private headless desktop (Linux), wait until ready tools/mcp/orca_mcp.py launch --xvfb # on a private Xvfb display, for a Linux machine without a desktop - tools/mcp/orca_mcp.py launch --cad # with the Design (CAD) tab on, for the CAD tools (list_cad_tools, call_cad_tool) + tools/mcp/orca_mcp.py launch --cad # with the Design (CAD) tab on, for its commands (search_tools group Design) tools/mcp/orca_mcp.py launch --unrestricted-scripts # with Python scripts (run_script) unrestricted tools/mcp/orca_mcp.py call get_app_state tools/mcp/orca_mcp.py call open_files '{"paths": ["/abs/model.stl"]}' @@ -193,21 +193,22 @@ class OrcaMcp: result = self.call("wait", **{"for": "job", "job": result["job"], "timeout_s": 45}) return result - def call_cad_tool(self, tool, /, **args): - """Call one CAD tool of the Design tab through call_cad_tool and return its result. + def call_command(self, tool, /, **args): + """Call one command, a tool or one the tool list does not show (a Design command), through + call_tool and return its whole reply; a Design command's result is the reply's "result". A running job is followed to its end. A call whose first reply is blocked_by_dialog fails at once, since a script that waited would wait on a dialog nobody answers. A call that first replied running and opens a dialog later is waited on up to await_job's timeout, since wait reports only that its job is still running. Every McpError's message starts "<tool>: ", with - the original error as its cause. The tool name is positional-only, so a CAD tool's own - argument named tool goes to that tool.""" + the original error as its cause. The command's name is positional-only, so its own argument + named tool goes to the command.""" try: - reply = self.call("call_cad_tool", _timeout=600, tool=tool, args=args) + reply = self.call("call_tool", _timeout=600, tool=tool, args=args) if reply.get("status") == "blocked_by_dialog": titles = ", ".join(f"\"{d.get('title', '')}\"" for d in reply.get("dialogs", [])) raise McpError(f"blocked by a dialog: {titles} (job {reply.get('job')} goes on once it is answered)", reply) - return self.await_job(reply)["result"] + return self.await_job(reply) except McpError as e: raise McpError(f"{tool}: {e}", e.payload) from e @@ -534,7 +535,7 @@ def main(): p.add_argument("--printer", help="\"<model>@<nozzle>\" for a fresh datadir, e.g. \"Bambu Lab X1 Carbon@0.4\"") p.add_argument("--vendor", default="BBL") p.add_argument("--filament") - p.add_argument("--cad", action="store_true", help="turn the Design (CAD) tab on, for the CAD tools (list_cad_tools, call_cad_tool)") + p.add_argument("--cad", action="store_true", help="turn the Design (CAD) tab on, for its commands (search_tools group Design)") p.add_argument("--unrestricted-scripts", action="store_true", help="let Python scripts (run_script) run unrestricted, which no tool can turn on") p.add_argument("--timeout", type=int, default=120) diff --git a/tools/mcp/smoke_test.json b/tools/mcp/smoke_test.json index 48ef9e20e9..354acc6cc7 100644 --- a/tools/mcp/smoke_test.json +++ b/tools/mcp/smoke_test.json @@ -14,7 +14,7 @@ // unsaved changes. The rules end with the replay, so they never answer a prompt after the run. {"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "unsaved changes", "button": "no"}, {"match": "restore", "button": "no"}]}}, - {"tool": "new_project"}, + {"tool": "new_project", "args": {"silent": true}}, {"tool": "open_files", "args": {"paths": ["${vars.model}"]}, "expect": {"/added": {"eq": 1}}}, {"tool": "set_settings", "args": {"scope": "process", "values": {"wall_loops": 3}}}, {"tool": "slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}}, diff --git a/tools/mcp/test_cad_click_edit.py b/tools/mcp/test_cad_click_edit.py index 97286f9fb6..f9f3de677c 100755 --- a/tools/mcp/test_cad_click_edit.py +++ b/tools/mcp/test_cad_click_edit.py @@ -12,7 +12,7 @@ that the field opened by itself, that the typed digits landed in it, that the ty one the field opened with, that Return committed it (the field closed or the next one opened), and that the geometry sketch_describe reads back has the typed value. A field that is shown but does not get the keyboard commits its prefill on Return, and only those last checks tell it from one that -works. Every action goes through the MCP UI tools, and call_cad_tool only reads. Exits 0 when every +works. Every action goes through the MCP UI tools, and the Design commands only read. Exits 0 when every check holds. The rungs: line, rect, circle, slot, polygon, ellipse and arc draw with their tool's key and type @@ -200,11 +200,11 @@ def tool_rung(rung): # ---------------------------------------------------------------- from the offer def offer_path(offer, verb): - """The label path at which `offer` lists `verb` as an item that can be run, from list_verbs: the + """The label path at which `offer` lists `verb` as an item that can be run, from the Design table: the verb's row, then its family, then its name, or its name alone for a row that offers only it.""" v = next((v for v in gui.verbs() if v["id"] == verb), None) if v is None: - raise AssertionError(f"list_verbs has no {verb}") + raise AssertionError(f"the Design table has no {verb}") full = ">".join([v["row_name"]] + ([v["family"]] if v["family"] else []) + [v["name"]]) for path in (full, v["name"]): if path in offer.items and path not in offer.disabled: diff --git a/tools/mcp/test_cad_context_menu.py b/tools/mcp/test_cad_context_menu.py index 56f5cacd62..4430e9616a 100755 --- a/tools/mcp/test_cad_context_menu.py +++ b/tools/mcp/test_cad_context_menu.py @@ -8,10 +8,10 @@ verbs the offer table says apply. With no rung named, every rung runs. The offer is where a sketch's verbs live, and for the many that have no key it is the only way to them. Each rung opens a sketch on the XY plane, right-clicks it with mouse_gesture, which lists the menu the click opens without showing it, and runs an item -by its label path with popup_item. The menu is graded against call_cad_tool list_verbs, the -compiled offer table the menu is built from, read for the selection the right-click left; what a -verb drew is graded on the geometry sketch_describe reads back, or for a text on the feature -describe_feature reads. Every action goes through the MCP UI tools, and call_cad_tool only reads. +by its label path with popup_item. The menu is graded against the Design table it is built from +(CadGui.verbs(): scripts/CAD/tool_atlas.json, for the selection describe_scene says the right-click +left); what a verb drew is graded on the geometry sketch_describe reads back, or for a text on +the feature describe_feature reads. Every action goes through the MCP UI tools, and the Design commands only read. Exits 0 when every check holds. The rungs: kinds right-clicks empty space, a line, a circle, a point and two picked lines, and @@ -78,7 +78,7 @@ def key(k): def verb_paths(verbs): """The label path at which the offer lists each verb that applies, by verb id. `verbs` is - list_verbs' sketch vocabulary, read with the selection the right-click left. + the Design table's sketch vocabulary (CadGui.verbs()), read with the selection the right-click left. It follows DesignPanel::show_offer_menu. A row with two or more verbs for the selection is a submenu named for the row, holding each verb directly or, for a verb of a family (Rectangle: @@ -87,7 +87,7 @@ def verb_paths(verbs): is held back by the document or sits in a flat row, so a verb is listed exactly when it applies.""" if not all(v["sketch_mode"] for v in verbs): - raise ValueError("verb_paths lays out the sketch offer: give it list_verbs' sketch verbs") + raise ValueError("verb_paths lays out the sketch offer: give it the table's sketch verbs") rows = {} for v in verbs: rows.setdefault(v["row"], []).append(v) @@ -844,7 +844,7 @@ def ok_text(s): def feature_names(): - """The design's features by name, from describe_scene, which goes through call_cad_tool and so + """The design's features by name, from describe_scene, which passes the Design commands' gate and so reads the design as loaded from the model's copy of it.""" return [f["name"] for f in gui.cad("describe_scene")["features"]] @@ -860,7 +860,7 @@ def rung_art(): fixture's path before it shows, and the outline lands in the open sketch. What is graded survives a change of font or of importer scale: how many closed loops came back, and the exact proportions of a shape whose proportions are known.""" - # Text, cancelled. The Insert step's Cancel undoes the text. Every call_cad_tool loads the + # Text, cancelled. The Insert step's Cancel undoes the text. Every Design command loads the # design from the model's copy when the document is empty, so a text left in that copy comes # back in describe_scene even though the canvas dropped it. gui.enter_sketch() @@ -877,7 +877,7 @@ def rung_art(): gui.press("Cancel") # the ribbon's Cancel, on the Insert step until(lambda: feature_names() == before, timeout=2.0) left = feature_names() - gui.check("art: the ribbon's Cancel after OK leaves no text, read back through call_cad_tool", left == before, + gui.check("art: the ribbon's Cancel after OK leaves no text, read back through describe_scene", left == before, f"features {left}, before the text {before}") # Text, kept. @@ -961,7 +961,7 @@ DRIVEN = { def rung_coverage(): """O8: every sketch verb with no key is driven from the menu, checked against the table. - The set of keyless sketch verbs list_verbs serves, less the set the rungs drive, must be empty, + The set of keyless sketch verbs the Design table has, less the set the rungs drive, must be empty, so a verb added without a rung fails here.""" sk = gui.verbs() keyless = {v["id"] for v in sk if v["action"] and not v["key"]} diff --git a/tools/mcp/test_cad_examples.py b/tools/mcp/test_cad_examples.py index 708908520b..4e88635dfd 100755 --- a/tools/mcp/test_cad_examples.py +++ b/tools/mcp/test_cad_examples.py @@ -1,14 +1,16 @@ #!/usr/bin/env python3 -"""Runs the examples of the CAD tool table against OrcaSlicer, to show they still work as written. +"""Runs the examples of the Design commands against OrcaSlicer, to show they still work as written. tools/mcp/orca_mcp.py launch --cad tools/mcp/test_cad_examples.py [--tool NAME ...] -Lists the CAD tools, describes them all, and runs every example of the named tools (of all of them -without --tool), each on a fresh, empty design: an open sketch is cancelled and new_design discards -the rest. An argument {"from_call": i, "key": k} is the value under k in the reply of call i of the -same example. A call to a tool whose failure is "reply" fails the example when its reply has ok -false or an error. An example with `needs` uses a file from outside the app and is skipped. Prints a +Lists the Design commands (search_tools {group: "Design"}), with undo and redo, which document the +Design history, reads each one's examples (search_tools {tool}), and runs every example of the named +commands (of all of them without --tool), each on a fresh, empty design: an open sketch is cancelled +and new_design discards the rest. An argument {"from_call": i, "key": k} is the value under k in the +result of call i of the same example. Every call is checked: an example fails when a call fails, or +when its result has ok false, a non-empty error, or is the person's form (interactive) instead of what +the call asked for. An example with `needs` uses a file from outside the app and is skipped. Prints a line per example and the counts; exits 1 when any example failed. """ @@ -20,82 +22,92 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import orca_mcp # noqa: E402 from orca_mcp import McpError # noqa: E402 +# The shared commands whose examples are the Design history's. +HISTORY = ["undo", "redo"] + class ExampleFailed(Exception): pass -def resolve(args, replies): - """`args` with each {"from_call": i, "key": k} replaced by that earlier reply's value.""" +def resolve(args, results): + """`args` with each {"from_call": i, "key": k} replaced by that earlier result's value.""" out = {} for name, value in args.items(): if isinstance(value, dict) and "from_call" in value: i, key = value["from_call"], value.get("key") - if not isinstance(i, int) or not 0 <= i < len(replies): + if not isinstance(i, int) or not 0 <= i < len(results): raise ExampleFailed(f"argument {name}: from_call {i} is not an earlier call") - if not isinstance(replies[i], dict) or key not in replies[i]: - raise ExampleFailed(f"argument {name}: the reply of call {i} has no key {key!r}") - value = replies[i][key] + if not isinstance(results[i], dict) or key not in results[i]: + raise ExampleFailed(f"argument {name}: the result of call {i} has no key {key!r}") + value = results[i][key] out[name] = value return out def fresh_design(client): try: - client.call_cad_tool("sketch_cancel") + client.call_command("sketch_cancel") except McpError: # no sketch was open pass - client.call_cad_tool("new_design", discard_changes=True) + client.call_command("new_design", discard_changes=True) -def run_example(client, example, failure): - replies = [] +def failed(result): + """Why a call's result says it did not do what it was asked, or None.""" + if not isinstance(result, dict): + return None + if result.get("interactive"): + return "it ran the person's form (interactive)" + if result.get("ok") is False or result.get("error"): + return f"ok is {result.get('ok')}, error {result.get('error')!r}" + return None + + +def run_example(client, example): + results = [] for n, call in enumerate(example["calls"]): tool = call["tool"] - args = resolve(call.get("args", {}), replies) + args = resolve(call.get("args", {}), results) try: - reply = client.call_cad_tool(tool, **args) + result = client.call_command(tool, **args).get("result") except McpError as e: raise ExampleFailed(f"call {n}: {e}") from None - if failure.get(tool) == "reply" and isinstance(reply, dict) and (reply.get("ok") is False or reply.get("error")): - raise ExampleFailed(f"call {n}: {tool}: ok is {reply.get('ok')}, error {reply.get('error')!r}") - replies.append(reply) + if why := failed(result): + raise ExampleFailed(f"call {n}: {tool}: {why}") + results.append(result) def main(): ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - ap.add_argument("--tool", action="append", default=[], metavar="NAME", help="run this tool's examples (repeatable)") + ap.add_argument("--tool", action="append", default=[], metavar="NAME", help="run this command's examples (repeatable)") args = ap.parse_args() client, _ = orca_mcp.session_client() - names = [t["name"] for t in client.call("list_cad_tools")["items"]] + names = client.call("search_tools", group="Design")["names"] + HISTORY unknown = [t for t in args.tool if t not in names] if unknown: - sys.exit(f"not CAD tools: {', '.join(unknown)}") - rows = client.call("describe_cad_tool", tool=names)["tools"] - failure = {row["name"]: row.get("failure") for row in rows} - wanted = set(args.tool) or set(names) + sys.exit(f"not Design commands: {', '.join(unknown)}") + wanted = args.tool or names - total = skipped = failed = 0 - for row in rows: - if row["name"] not in wanted: - continue - for example in row["examples"]: + total = skipped = failures = 0 + for name in wanted: + for example in client.call("search_tools", tool=name).get("examples") or []: total += 1 - label = f"{row['name']}: {example['title']}" + label = f"{name}: {example['title']}" if example.get("needs"): skipped += 1 print(f"skip {label}: needs {example['needs']}") continue try: fresh_design(client) - run_example(client, example, failure) + run_example(client, example) print(f"ok {label}") except (ExampleFailed, McpError) as e: - failed += 1 + failures += 1 print(f"FAIL {label}: {e}") - print(f"{total} examples, {skipped} skipped (needs), {failed} failed") - return 1 if failed else 0 + print(f"{total} examples, {skipped} skipped (needs), {failures} failed") + return 1 if failures else 0 if __name__ == "__main__": diff --git a/tools/mcp/test_cad_failed_job.py b/tools/mcp/test_cad_failed_job.py index 56c13ff1d7..42fc3144b8 100755 --- a/tools/mcp/test_cad_failed_job.py +++ b/tools/mcp/test_cad_failed_job.py @@ -31,7 +31,8 @@ REBUILD_S = 60.0 def cad(client, tool, **args): - return client.call("call_cad_tool", _timeout=600, tool=tool, args=args) + """A Design command's reply: its {result}, or the envelope of the job it runs as.""" + return client.call("call_tool", _timeout=600, tool=tool, args=args) def coil(client, turns): @@ -79,7 +80,7 @@ def main(): f"{started.get('status')} after {time.time() - start:.1f} s; the coil rebuilds too fast") during = client.call("export_replay") check("an export while it runs leaves it out and names it", - during.get("left_out_running") == [{"tool": "call_cad_tool", "job": started.get("job")}], during.get("left_out_running")) + during.get("left_out_running") == [{"tool": "hole", "job": started.get("job")}], during.get("left_out_running")) failure = None try: client.await_job(started) @@ -89,11 +90,11 @@ def main(): f"{failure} after {time.time() - start:.1f} s") cad(client, "feature_rename", feature=2, name="Coil") live_scene = cad(client, "describe_scene")["result"] - live_mass = cad(client, "mass_properties", body=0)["result"] + live_mass = cad(client, "mass_props", body=0)["result"] after = client.call("export_replay", path=path, overwrite=True) - calls = [s["args"] for s in after["replay"]["steps"] if s["tool"] == "call_cad_tool"] - tools = [c["tool"] for c in calls] + # A Design command's call is journaled as its own. + tools = [s["tool"] for s in after["replay"]["steps"]] check("the export leaves the failed hole out", "hole" not in tools, tools) check("and keeps the rename made after it", "feature_rename" in tools, tools) check("and leaves nothing out", "left_out_running" not in after, after.get("left_out_running")) @@ -104,7 +105,7 @@ def main(): check("the exported session replays", replay.get("passed") is True, json.dumps([s for s in replay.get("steps", []) if not s.get("ok")][:1])) scene = cad(client, "describe_scene")["result"] - mass = cad(client, "mass_properties", body=0)["result"] + mass = cad(client, "mass_props", body=0)["result"] # Feature names count on across projects; the renamed one keeps its name. kinds = lambda s: [f["type"] for f in s["features"]] # noqa: E731 check("the same features, the coil renamed", kinds(scene) == kinds(live_scene) and scene["features"][2]["name"] == "Coil", diff --git a/tools/mcp/test_cad_replay.py b/tools/mcp/test_cad_replay.py index 2e9f60fc7c..bec8d4bcb4 100755 --- a/tools/mcp/test_cad_replay.py +++ b/tools/mcp/test_cad_replay.py @@ -4,9 +4,9 @@ tools/mcp/orca_mcp.py launch --cad tools/mcp/test_cad_replay.py -Records a session of call_cad_tool client calls (replay steps are not journaled) on the paths a replay -breaks on: a sketch on a base plane, which passes through modeling_origin as every plane does; an -empty sketch commit, which fails and must keep the sketch open for the next call; a CAD tool +Records a session of Design command calls made through call_tool (replay steps are not journaled) on the +paths a replay breaks on: a sketch on a base plane, which passes through modeling_origin as every plane does; an +empty sketch commit, which fails and must keep the sketch open for the next call; a command failing as an error (a hole that misses), which export_replay must leave out; one that reports a rejected rebuild in its reply (ok false), which stays in and replays the same rejection; and face and edge ids passed with the generation they were read at, which the journal drops, since the @@ -26,7 +26,7 @@ import orca_mcp # noqa: E402 def cad(client, tool, **args): - return client.call("call_cad_tool", _timeout=300, tool=tool, args=args)["result"] + return client.call("call_tool", _timeout=300, tool=tool, args=args)["result"] def refused(client, tool, **args): @@ -57,9 +57,9 @@ def record(client): refused_fillet = cad(client, "fillet", edge=corners["edges"][0]["id"], radius=50, body=0) bores = cad(client, "query_topology", body=0, kinds=["cylindrical"]) bore = next(f["id"] for f in bores["faces"] if f.get("internal")) - thread = client.await_job(client.call("call_cad_tool", _timeout=300, tool="thread", + thread = client.await_job(client.call("call_tool", _timeout=300, tool="thread", args={"body": 0, "face": bore, "generation": bores["generation"]})) - return {"mass": cad(client, "mass_properties", body=0), "scene": cad(client, "describe_scene"), + return {"mass": cad(client, "mass_props", body=0), "scene": cad(client, "describe_scene"), "frame": frame, "empty_commit": empty_commit, "missed_hole": missed_hole, "refused_fillet": refused_fillet, "thread": thread.get("result", {})} @@ -77,12 +77,13 @@ def main(): with open(path) as f: text = f.read() steps = json.loads("\n".join(l for l in text.splitlines() if not l.lstrip().startswith("//")))["steps"] - calls = [s["args"] for s in steps if s["tool"] == "call_cad_tool"] - tools = [c["tool"] for c in calls] + # A Design command's call is journaled as its own; the session starts with new_project. + calls = [s for s in steps if s["tool"] != "new_project"] + tools = [s["tool"] for s in calls] client.call("new_project", discard_changes=True) replay = client.await_job(client.call("run_replay", path=path, out_dir=out_dir), timeout=900) - mass = cad(client, "mass_properties", body=0) + mass = cad(client, "mass_props", body=0) scene = cad(client, "describe_scene") kinds = lambda s: [f["type"] for f in s["features"]] # noqa: E731 (names count on across projects) diff --git a/tools/mcp/test_cad_sketching.py b/tools/mcp/test_cad_sketching.py index 205f0ed0dc..0ef2562124 100755 --- a/tools/mcp/test_cad_sketching.py +++ b/tools/mcp/test_cad_sketching.py @@ -7,10 +7,10 @@ With no rung named, every rung runs. Each one opens a sketch on the XY plane (Shift+S, then a click on the plane), draws with clicks on the canvas, types the exact values into the canvas's value field with no click into it, and grades the geometry and loops sketch_describe reads back. It covers what -the CAD tools that build sketches skip: the gesture state, the queue of value fields, snapping, +the Design commands that build sketches skip: the gesture state, the queue of value fields, snapping, inference at gesture tolerance and the keyboard reaching the field. The click only has to be roughly right; the typed number is what must come back exactly. Every action goes through the MCP UI tools, -and call_cad_tool only reads, save the scale rung's one bulk add. Exits 0 when every check holds. +and the Design commands only read, save the scale rung's one bulk add. Exits 0 when every check holds. The rungs: each 2D tool draws its primitive and takes its exact values from the keyboard (rect, circle, line, arc, slot, polygon, ellipse, point, spline), and voids draws one closed outer profile @@ -25,7 +25,7 @@ selects it and deletes nothing, as does a double-click, then deletes it with Del feature_undo undo inside a sketch and across its commit, from the keyboard. roundtrip saves the project and opens it again through the File menu, its file pickers answered by auto_answer_dialogs rules with the path (skipped on Linux, where a GTK picker can't take one). scale draws on top of a sketch holding 1204 entities, -which it loads with one call_cad_tool sketch_add while a tool is armed; the call says why. +which it loads with one sketch_add command while a tool is armed; the call says why. selfcheck-recovery runs only when named: it raises with the mouse button held, the offer menu asked for and a tool armed, to show that the rungs after it start clean. """ diff --git a/tools/mcp/test_cad_slow_build.py b/tools/mcp/test_cad_slow_build.py index 2978bd1130..8096dccb54 100755 --- a/tools/mcp/test_cad_slow_build.py +++ b/tools/mcp/test_cad_slow_build.py @@ -4,10 +4,10 @@ tools/mcp/orca_mcp.py launch --cad tools/mcp/test_cad_slow_build.py -call_cad_tool thread, sweep and loft rebuild as their cards do, off the UI thread behind the progress +The thread, sweep and loft commands rebuild as their cards do, off the UI thread behind the progress dialog (DesignPanel::recompute_guarded). While a long thread builds: get_app_state answers, a screenshot of the main window succeeds, list_widgets lists the progress dialog and a screenshot of that window -captures it (not on Windows, where the dialog is the system's task dialog), and another call_cad_tool is refused rather than run inside the rebuild. The thread then +captures it (not on Windows, where the dialog is the system's task dialog), and another Design command is refused rather than run inside the rebuild. The thread then lands as one feature. Exits 0 when all hold. """ @@ -41,14 +41,14 @@ def main(): client, _ = orca_mcp.session_client() out = tempfile.mkdtemp(prefix="orca-mcp-slow-") client.call("new_project", discard_changes=True) - client.call("call_cad_tool", tool="new_design", args={"discard_changes": True}) - client.call("call_cad_tool", tool="extrude", args=BLOCK) + client.call("call_tool", tool="new_design", args={"discard_changes": True}) + client.call("call_tool", tool="extrude", args=BLOCK) box = {} def build(): try: - box["result"] = client.call("call_cad_tool", _timeout=600, tool="thread", args=THREAD) + box["result"] = client.call("call_tool", _timeout=600, tool="thread", args=THREAD) except orca_mcp.McpError as e: box["error"] = str(e) @@ -75,14 +75,14 @@ def main(): dialog_shot = client.call("screenshot", target=ref, include_image=False, save_path=os.path.join(out, "progress.png")) try: - client.call("call_cad_tool", tool="describe_scene") + client.call("call_tool", tool="describe_scene") refused = False except orca_mcp.McpError as e: refused = str(e) worker.join(600) seconds = time.time() - started result = client.await_job(box.get("result")) if "result" in box else None - scene = client.call("call_cad_tool", tool="describe_scene")["result"] + scene = client.call("call_tool", tool="describe_scene")["result"] threads = [f for f in scene["features"] if f["type"] == "Thread"] print(f"build took {seconds:.1f} s; screenshots in {out}") @@ -91,7 +91,7 @@ def main(): ("the thread call succeeds", result is not None and result.get("result", {}).get("ok") is True, box), ("get_app_state answers during the build", state_ms is not None, state_ms), ("a window screenshot succeeds during the build", bool(window_shot and window_shot.get("width")), window_shot), - ("another call_cad_tool is refused during the build", bool(refused) and "Busy" in refused, refused), + ("another Design command is refused during the build", bool(refused) and "Busy" in refused, refused), ("one thread feature and one body", len(threads) == 1 and len(scene["bodies"]) == 1, scene["features"]), ] if not native_dialog: diff --git a/tools/mcp/test_operation_routes.py b/tools/mcp/test_operation_routes.py index eeb6176db9..eff9f5927c 100644 --- a/tools/mcp/test_operation_routes.py +++ b/tools/mcp/test_operation_routes.py @@ -60,11 +60,8 @@ def main(): return "blocked_by_dialog", json.dumps(reply.get("dialogs")) return None, client.await_job(reply) - def command(name, param=None): - args = {"id": "orca_command:%s:orca" % name} - if param is not None: - args["param"] = param - return answer("run_action", **args) + def command(name, **command_args): + return answer("run_action", id="orca_command:%s:orca" % name, args=command_args) def plugin_api(**args): code = "import ops_presets\nresult = ops_presets.preset_api(args)" @@ -77,7 +74,7 @@ def main(): client.call("set_view", tab="prepare") # ---- A project with no objects ---- - code_c, text_c = command("save_project_as", path("cmd.gcode.3mf")) + code_c, text_c = command("save_project_as", path=path("cmd.gcode.3mf")) code_t, text_t = answer("save_project", path=path("tool.gcode.3mf")) check("the command refuses a .gcode.3mf name", code_c == "sliced_file_name", (code_c, text_c)) check("the tool refuses a .gcode.3mf name", code_t == "sliced_file_name", (code_t, text_t)) @@ -85,19 +82,19 @@ def main(): code_c == code_t == "sliced_file_name" and text_t.startswith(text_c) and "sliced_3mf" in text_t, (text_c, text_t)) check("neither wrote a file", not os.path.exists(path("cmd.gcode.3mf")) and not os.path.exists(path("tool.gcode.3mf"))) - code_c, text_c = command("export_3mf", path("cmd.3mf")) + code_c, text_c = command("export_3mf", path=path("cmd.3mf")) code_t, text_t = answer("export", format="3mf", path=path("tool.3mf")) check("the command writes a .3mf of a project with no objects", code_c is None and os.path.exists(path("cmd.3mf")), text_c) check("the tool writes a .3mf of a project with no objects", code_t is None and os.path.exists(path("tool.3mf")), text_t) for fmt, name, ext in (("stl", "export_stl", ".stl"), ("sliced_3mf", "export_sliced_file", "_sliced.gcode.3mf")): - code_c, text_c = command(name, path("cmd" + ext)) + code_c, text_c = command(name, path=path("cmd" + ext)) code_t, text_t = answer("export", format=fmt, path=path("tool" + ext)) check("the command refuses %s of a project with no objects" % fmt, code_c == "no_objects", (code_c, text_c)) check("the tool refuses %s of a project with no objects" % fmt, code_t == "no_objects", (code_t, text_t)) check("in the same words (%s)" % fmt, text_c == text_t, (text_c, text_t)) check("neither wrote a file (%s)" % fmt, not os.path.exists(path("cmd" + ext)) and not os.path.exists(path("tool" + ext))) - code_c, text_c = command("go_to_layer", "50") + code_c, text_c = command("go_to_layer", percent=50) code_t, text_t = answer("set_view", layer=1) check("the command refuses a layer of a Preview with none", code_c == "no_layers", (code_c, text_c)) check("the tool refuses a layer of a Preview with none", code_t == "no_layers", (code_t, text_t)) @@ -107,7 +104,7 @@ def main(): # ---- Two cubes on one spot ---- for _ in range(2): client.call("select_objects", none=True) - client.call("run_action", id="orca_command:add_primitive_cube:orca", param="20 20 20") + client.call("run_action", id="orca_command:add_primitive_cube:orca", args={"size": [20, 20, 20]}) client.call("wait", **{"for": "idle"}) before = offsets() client.call("set_view", canvas="assemble") diff --git a/tools/mcp/test_orca_mcp_attach.py b/tools/mcp/test_orca_mcp_attach.py index d1f0450b3b..a8165adbf8 100755 --- a/tools/mcp/test_orca_mcp_attach.py +++ b/tools/mcp/test_orca_mcp_attach.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Checks how orca_mcp.py attaches to a running OrcaSlicer and calls CAD tools, without the app. +"""Checks how orca_mcp.py attaches to a running OrcaSlicer and calls commands, without the app. python tools/mcp/test_orca_mcp_attach.py @@ -9,9 +9,9 @@ does through /proc/self/exe, and takes it as given on Windows, as the app does, stdio bridge does (skipped where no symlink can be made). from_datadir() refuses a datadir without mcp/server.json, or whose server.json is not JSON or names no port, naming the file and giving the --mcp advice; and one whose server.json names a port where nothing listens or where another server -answers (HTTP 401, a reply that is not JSON), also chaining the cause. call_cad_tool(), against a -stubbed call(), fails at once on a dialog, follows a running job, prefixes its errors with the CAD -tool's name, chaining the original, and returns the tool's result. Exits 0 when every check passes. +answers (HTTP 401, a reply that is not JSON), also chaining the cause. call_command(), against a +stubbed call(), fails at once on a dialog, follows a running job, prefixes its errors with the +command's name, chaining the original, and returns the command's whole reply. Exits 0 when every check passes. The folders the checks make are removed when they end. """ @@ -215,33 +215,33 @@ def stub(client, *replies): return calls -def check_call_cad_tool(): +def check_call_command(): client = OrcaMcp(1, "t") calls = stub(client, {"status": "blocked_by_dialog", "job": "j", "dialogs": [{"title": "Save?"}]}) - message = raises(lambda: client.call_cad_tool("extrude", distance=5), "Save?") + message = raises(lambda: client.call_command("extrude", distance=5), "Save?") assert message.startswith("extrude: "), message assert len(calls) == 1, calls - ok("call_cad_tool() fails at once on a dialog, naming it") + ok("call_command() fails at once on a dialog, naming it") calls = stub(client, {"result": {"ok": True}}) - assert client.call_cad_tool("extrude", distance=5) == {"ok": True} - assert calls == [("call_cad_tool", 600, {"tool": "extrude", "args": {"distance": 5}})], calls - ok("call_cad_tool() returns the CAD tool's result") + assert client.call_command("extrude", distance=5) == {"result": {"ok": True}} + assert calls == [("call_tool", 600, {"tool": "extrude", "args": {"distance": 5}})], calls + ok("call_command() calls call_tool and returns the command's whole reply") calls = stub(client, {"status": "running", "job": "j"}, {"result": 7}) - assert client.call_cad_tool("sweep", sketch=1, path=0) == 7 + assert client.call_command("sweep", sketch=1, path=0) == {"result": 7} assert calls[1][0] == "wait" and calls[1][2]["job"] == "j", calls - ok("call_cad_tool() follows a running job to its result") + ok("call_command() follows a running job to its reply") refused = McpError("kernel refused the hole") stub(client, refused) - error = raised(lambda: client.call_cad_tool("hole"), "kernel refused the hole") + error = raised(lambda: client.call_command("hole"), "kernel refused the hole") assert str(error).startswith("hole: "), error assert error.__cause__ is refused, repr(error.__cause__) stub(client, {"status": "running", "job": "j"}, McpError("the job failed")) - message = raises(lambda: client.call_cad_tool("hole"), "the job failed") + message = raises(lambda: client.call_command("hole"), "the job failed") assert message.startswith("hole: "), message - ok("call_cad_tool() starts every error with the CAD tool's name, with the original as its cause") + ok("call_command() starts every error with the command's name, with the original as its cause") def main(): @@ -251,7 +251,7 @@ def main(): check_default_datadir() check_symlinked_binary() check_from_datadir() - check_call_cad_tool() + check_call_command() return 0 diff --git a/tools/mcp/test_plugin_tools.py b/tools/mcp/test_plugin_tools.py index 9e3a18b7fa..76a26c2941 100644 --- a/tools/mcp/test_plugin_tools.py +++ b/tools/mcp/test_plugin_tools.py @@ -1,11 +1,12 @@ """Checks a plugin's calls into the MCP tools and the operations it offers, in the running app. -Launches OrcaSlicer on a fresh data folder with tests/plugins/mcp_tools_fixture side-loaded, and -tests/plugins/mcp_tools_broken, whose load fails after declaring an operation: over MCP, then once without -MCP, running a replay with --mcp-run, so the plugin's calls go to the catalog-only service. The first launch -also checks that the plugin is sent the NewProject event when the new_project tool or command starts a -project, and ends by unticking the fixture in the Plugins dialog, as a person unloads it. Run it as -python tools/mcp/test_plugin_tools.py [--bin PATH]. +Launches OrcaSlicer on a fresh data folder with the Design tab on (in a build with CAD) and +tests/plugins/mcp_tools_fixture side-loaded, and tests/plugins/mcp_tools_broken, whose load fails after declaring an +operation: over MCP, then once without MCP, running a replay with --mcp-run, so the plugin's calls go to the +service started without its endpoint. The first launch also checks that the plugin is sent the NewProject event when +the new_project tool or command starts a project, and ends by unticking the fixture in the Plugins dialog, as a person +unloads it. +Run it as python tools/mcp/test_plugin_tools.py [--bin PATH]. """ import json import os @@ -122,10 +123,14 @@ def main(): # --- Over MCP: the plugin's operation and its tool calls, beside a plugin whose load fails. --- plugin_dir = install(datadir) install_broken(datadir) - orca = launch(env, datadir, extra) + # The Design tab on, so that its commands are among search_tools' commands; a build without CAD has none. + orca = launch(env, datadir, ["--cad", *extra]) described = orca.call_raw("search_tools", {"tool": f"plugin.{PLUGIN}.measure"}) check("search_tools describes the plugin's operation", not described.get("isError") and "\"a\"" in described["content"][0]["text"], described) + operation = {} if described.get("isError") else json.loads(described["content"][0]["text"]) + check("the operation is in the api group, its description saying a plugin offers it", + operation.get("group") == "api" and operation.get("description", "").startswith("Offered by a plugin."), operation) called = orca.call_raw("call_tool", {"tool": f"plugin.{PLUGIN}.measure", "args": {"a": 2}}) check("call_tool runs the plugin's operation", not called.get("isError") and json.loads(called["content"][0]["text"]) == {"twice": 4}, called) @@ -140,25 +145,51 @@ def main(): exported = run_plugin_script(orca, plugin_dir, "export", CAPABILITIES[3]) check("a plugin is refused export_replay", exported.get("ok") is False and "agent's session" in exported.get("error", ""), exported) - # search_tools's one search: an operation with its schema, a tool with its summary (its schema is in - # tools/list), and beside them the other catalogs' best matches. + # search_tools's one search: a command the tool list does not show (an operation, a Speed Dial command) with + # its schema, a listed tool with its summary (its schema is in tools/list), and beside them the other + # catalogs' best matches. found = orca.call("search_tools", query="fixture measure") operation = next((i for i in found["items"] if i["name"] == f"plugin.{PLUGIN}.measure"), {}) - check("search_tools's search finds the plugin's operation with its schema", "input_schema" in operation, found) + check("search_tools's search finds the plugin's operation with its schema", + operation.get("listed") is False and "input_schema" in operation, found) found = orca.call("search_tools", query="slice plate") tool = next((i for i in found["items"] if i["name"] == "slice"), {}) - check("search_tools's search names a tool with its summary", tool.get("summary") and "input_schema" not in tool, found) + check("search_tools's search names a listed tool with its summary", + tool.get("listed") is True and tool.get("summary") and "input_schema" not in tool, found) found = orca.call("search_tools", query="brim width") check("search_tools's search finds settings", any(s["key"] == "brim_width" for s in found.get("settings", {}).get("items", [])), found) found = orca.call("search_tools", query="arrange") - check("search_tools's search finds Speed Dial actions", any("arrange" in a["id"] for a in found.get("actions", {}).get("items", [])), - found) + command = next((i for i in found["items"] if i["name"] == "obj_arrange"), {}) + check("search_tools's search finds a Speed Dial command among the commands, with its schema", + command.get("listed") is False and "input_schema" in command, found) + check("and not a second time among the actions", + not any("obj_arrange" in a["id"] for a in found.get("actions", {}).get("items", [])), found) + found = orca.call("search_tools", query="fixture") + check("search_tools's search finds the Speed Dial's other actions", + any("fixture" in a.get("title", "").lower() for a in found.get("actions", {}).get("items", [])), found) + described = orca.call_raw("search_tools", {"tool": "view_front"}) + view = {} if described.get("isError") else json.loads(described["content"][0]["text"]) + check("search_tools describes a Speed Dial command", view.get("listed") is False and "input_schema" in view, described) + names = orca.call("search_tools", group="object").get("names", []) + check("search_tools's group is any case, a Speed Dial section among the groups", "obj_arrange" in names, names) + unknown = orca.call_raw("search_tools", {"group": "commandz"}) + check("a group no command has is refused, naming the groups there are", + unknown.get("isError") and "Object" in unknown["content"][0]["text"], unknown) + ran = orca.call_raw("call_tool", {"tool": "view_front"}) + check("call_tool runs a Speed Dial command", not ran.get("isError"), ran) found = orca.call("search_tools", query="mesh normals") check("search_tools's search finds the Python API", found.get("python", {}).get("items", [{}])[0].get("name") == "orca.host.TriangleMesh.face_normals", found) found = orca.call("search_tools", query="extrude") - check("search_tools's search finds the Design tab's CAD tools", found.get("cad", {}).get("items"), found) + if orca.call("get_app_state").get("design_tab"): + extrude = next((i for i in found["items"] if i["name"] == "extrude"), {}) + check("search_tools's search finds a Design command among the commands, with its schema", + extrude.get("group") == "Design" and extrude.get("listed") is False and "input_schema" in extrude, found) + else: + check("without the Design tab, search_tools's search finds no Design command", + not any(i.get("group") == "Design" for i in found["items"]), found) + check("and in no section of its own", "cad" not in found, found) found = orca.call("search_tools", query="?") check("a query with no words to search for matches nothing", found.get("total") == 0 and "names" not in found, found) journal = orca.call("export_replay")["replay"]["steps"] @@ -191,7 +222,7 @@ def main(): harness(env, "stop") time.sleep(3) - # --- Without MCP: a launch replay runs the plugin's script, whose calls reach the catalog-only service. --- + # --- Without MCP: a launch replay runs the plugin's script, whose calls reach the service without its endpoint. --- install(datadir) # enabled again: unticking it saved it disabled steps = os.path.join(datadir, "plugin_rule.json") with open(steps, "w", encoding="utf-8") as f: diff --git a/tools/mcp/test_set_view_camera.py b/tools/mcp/test_set_view_camera.py index 420c39bfcf..0de416034a 100644 --- a/tools/mcp/test_set_view_camera.py +++ b/tools/mcp/test_set_view_camera.py @@ -103,9 +103,9 @@ def main(): if not client.call("get_app_state").get("design_tab"): check("the Design tab is on (launch --cad)", False) else: - # The Design view's world frame is the CAD tools', where the sketch planes' origin, + # The Design view's world frame is the Design commands', where the sketch planes' origin, # modeling_origin, sits at the Design bed's centre for a new design. - origin = client.call_cad_tool("describe_scene")["modeling_origin"] + origin = client.call_command("describe_scene")["result"]["modeling_origin"] reply = set_view(tab="design", camera="top", look_at=origin, zoom=DESIGN_ZOOM) state = reply.get("camera_state", {}) look_at = state.get("look_at") or [] diff --git a/tools/mcp/test_web_ui.py b/tools/mcp/test_web_ui.py index b3b7dcf857..27dde32ffa 100755 --- a/tools/mcp/test_web_ui.py +++ b/tools/mcp/test_web_ui.py @@ -487,7 +487,7 @@ def main(): call("auto_answer_dialogs", rules=[]) # ---- The Home page, a modeless page window and the web budget ---- - client.call("run_action", id="orca_command:go_to_tab:orca", param="home") + client.call("run_action", id="orca_command:go_to_tab:orca", args={"tab": "home"}) client.call("run_action", id=WINDOW) check("the modeless window's page is listed", wait_for(lambda: 'button "Card one"' in tree(query="Card one"), 10)) native = client.call("list_widgets", include_web=False)["nodes"] @@ -543,7 +543,7 @@ def main(): check("that dialog is gone", wait_for(lambda: dialogs() == []), dialogs()) # ---- A dock panel, beside the 3D view ---- - client.call("run_action", id="orca_command:go_to_tab:orca", param="prepare") + client.call("run_action", id="orca_command:go_to_tab:orca", args={"tab": "prepare"}) client.call("run_action", id=PANEL) check("the dock panel's page is listed", wait_for(lambda: 'button "Ping"' in tree(query="Ping"), 10)) # Its Content-Security-Policy forbids eval: the agent works there, run_javascript says why it can't. diff --git a/tools/mcp/test_worker_admission.py b/tools/mcp/test_worker_admission.py index 48ca04e816..dfc6ea5864 100755 --- a/tools/mcp/test_worker_admission.py +++ b/tools/mcp/test_worker_admission.py @@ -53,9 +53,9 @@ def main(): c.call("wait", **{"for": "ready", "timeout_s": 50}) c.call("new_project", discard_changes=True) c.call("set_view", tab="prepare") - for size in ["6 6 6", "4 9 5", "7 3 5"]: + for size in [[6, 6, 6], [4, 9, 5], [7, 3, 5]]: c.call("select_objects", none=True) - c.call("run_action", id="orca_command:add_primitive_cube:orca", param=size) + c.call("run_action", id="orca_command:add_primitive_cube:orca", args={"size": size}) for o in range(3): c.call("arrange", fill=o, spacing=0, rotate=False) diff --git a/tools/mcp/tests/agent_forms.json b/tools/mcp/tests/agent_forms.json index 2512d05c5a..34dd09e70b 100644 --- a/tools/mcp/tests/agent_forms.json +++ b/tools/mcp/tests/agent_forms.json @@ -18,7 +18,7 @@ {"tool": "open_files", "args": {"paths": "${vars.cube}"}, "expect": {"/added": {"eq": 1}}}, {"tool": "open_files", "args": {"paths": ["${vars.cube}"]}, "expect": {"/added": {"eq": 1}}}, {"tool": "select_objects", "args": {"object": "1"}}, - {"tool": "run_action", "args": {"id": "obj_rename", "param": "renamed"}, "expect": {"/ran": {"eq": "orca_command:obj_rename:orca"}}}, + {"tool": "run_action", "args": {"id": "obj_rename", "args": {"name": "renamed"}}, "expect": {"/ran": {"eq": "orca_command:obj_rename:orca"}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/1/name": {"eq": "renamed"}, "/plates/0/objects/0/name": {"ne": "renamed"}}}, {"tool": "run_action", "args": {"action": "view_top"}, "expect": {"/ran": {"eq": "orca_command:view_top:orca"}}}, diff --git a/tools/mcp/tests/cad_canvas.json b/tools/mcp/tests/cad_canvas.json index fcce3efd24..a5f6ada395 100644 --- a/tools/mcp/tests/cad_canvas.json +++ b/tools/mcp/tests/cad_canvas.json @@ -14,11 +14,11 @@ "steps": [ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, {"tool": "set_view", "args": {"tab": "design", "camera": "iso"}, "expect": {"/tab": {"eq": "design"}, "/camera": {"eq": "iso"}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, "expect": {"/result/ok": {"eq": true}}}, // The Design view has no gizmos, and a change made only in the Design tab marks the project. {"tool": "get_app_state", "expect": {"/tab": {"eq": "design"}, "/gizmo": {"eq": null}, "/project/dirty": {"eq": true}}}, @@ -49,20 +49,20 @@ {"tool": "list_widgets", "args": {"query": "Extrude dist"}, "expect": {"/nodes": {"eq": 1}}}, {"tool": "press_keys", "args": {"keys": "Escape"}}, {"tool": "list_widgets", "args": {"query": "Extrude dist"}, "expect": {"/nodes": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"width": 6, "height": 6, "distance": 20}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"width": 6, "height": 6, "distance": 20}}, "expect": {"/result/ok": {"eq": true}}}, // A design-only project: saved, changed in the Design tab alone, then opened again. {"tool": "save_project", "args": {"path": "${out_dir}/design_only.3mf", "overwrite": true}}, {"tool": "get_app_state", "expect": {"/project/dirty": {"eq": false}, "/project/name": {"eq": "design_only"}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_variable", "args": {"name": "w", "expr": "5"}}, "expect": {"/result/ok": {"eq": true}}}, + {"tool": "call_tool", "args": {"tool": "set_variable", "args": {"name": "w", "expr": "5"}}, "expect": {"/result/ok": {"eq": true}}}, {"tool": "get_app_state", "expect": {"/project/dirty": {"eq": true}}}, {"tool": "open_files", "args": {"paths": ["${out_dir}/design_only.3mf"]}, "optional": true}, {"tool": "open_files", "args": {"paths": ["${out_dir}/design_only.3mf"], "discard_changes": true}, "expect": {"/opened": {"eq": "project"}, "/objects": {"eq": 0}}}, {"tool": "get_app_state", "expect": {"/project/dirty": {"eq": false}, "/project/name": {"eq": "design_only"}, "/project/path": {"regex": "design_only\\.3mf$"}, "/dialogs": {"empty": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/variables": {"empty": true}, "/result/bodies/1": {"exists": true}}} ] } diff --git a/tools/mcp/tests/cad_doc.json b/tools/mcp/tests/cad_doc.json index e4dd37c536..39a7648510 100644 --- a/tools/mcp/tests/cad_doc.json +++ b/tools/mcp/tests/cad_doc.json @@ -16,139 +16,140 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design"}, "expect": {"/result/ok": {"eq": true}, "/result/cleared/features": {"eq": 0}}}, - {"tool": "describe_cad_tool", "args": {"tool": ["describe_feature", "set_feature"]}, "expect": {"/tools/0/access": {"eq": "read"}, "/tools/1/access": {"eq": "change"}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, + {"tool": "call_tool", "args": {"tool": "new_design"}, "expect": {"/result/ok": {"eq": true}, "/result/cleared/features": {"eq": 0}}}, + {"tool": "search_tools", "args": {"tool": "describe_feature"}, "expect": {"/group": {"eq": "Design"}, "/read_only": {"eq": true}}}, + {"tool": "search_tools", "args": {"tool": "set_feature"}, "expect": {"/group": {"eq": "Design"}, "/read_only": {"eq": false}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, "expect": {"/result/ok": {"eq": true}, "/result/extrude_index": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_variable", "args": {"name": "h", "expr": "12"}}, + {"tool": "call_tool", "args": {"tool": "set_variable", "args": {"name": "h", "expr": "12"}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature_expr", "args": {"feature": 1, "field": "distance", "expr": "h"}}, + {"tool": "call_tool", "args": {"tool": "edit_feature", "args": {"feature": 1, "field": "distance", "expr": "h"}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/variables/0/name": {"eq": "h"}, "/result/variables/0/value": {"eq": 12.0}, "/result/features/1/bound/0": {"eq": "distance"}, "/result/bodies/0/source_feature": {"eq": 1}, "/result/bodies/0/visible": {"eq": true}, "/result/bodies/0/moved": {"eq": false}, "/result/bodies/0/color": {"regex": "^#[0-9A-F]{6}$"}, "/result/undo_depth": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/type": {"eq": "Extrude"}, "/result/params/distance": {"eq": 12.0}, "/result/expr/distance": {"eq": "h"}, "/result/refs/sketch_ref": {"eq": 0}, "/result/bodies_made/0": {"eq": 0}, "/result/editable": {"contains": "distance"}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 0}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 0}}, "expect": {"/result/type": {"eq": "Sketch"}, "/result/params/width": {"eq": 20.0}, "/result/plane/base": {"eq": "XY"}, "/result/used_by/0": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature_expr", "args": {"feature": 1, "field": "distance", "expr": ""}}, + {"tool": "call_tool", "args": {"tool": "edit_feature", "args": {"feature": 1, "field": "distance", "expr": ""}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_variable", "args": {"name": "h", "expr": ""}}, + {"tool": "call_tool", "args": {"tool": "set_variable", "args": {"name": "h", "expr": ""}}, "expect": {"/result/ok": {"eq": true}, "/result/removed": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/variables": {"empty": true}, "/result/features/1/bound": {"exists": false}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}}, "expect": {"/result/ok": {"eq": true}, "/result/changed/distance/0": {"eq": 12.0}, "/result/changed/distance/1": {"eq": 15.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 5999.99, "le": 6000.01}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"feature": 0, "fields": {"width": 30}}}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"feature": 0, "fields": {"width": 30}}}, "expect": {"/result/changed/width/1": {"eq": 30.0}}}, // The names agents often use: index for feature, params or values for fields. - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"index": 0, "params": {"width": 20}}}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"index": 0, "params": {"width": 20}}}, "expect": {"/result/changed/width/1": {"eq": 20.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"feature": 0, "values": {"width": 30}}}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"feature": 0, "values": {"width": 30}}}, "expect": {"/result/changed/width/1": {"eq": 30.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"index": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"index": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 8999.99, "le": 9000.01}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [40, 0, 60, 10]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_heal"}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/features": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 2}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [40, 0, 60, 10]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_heal"}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/features": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 2}}, "expect": {"/result/entities/0/type": {"eq": "line"}, "/result/entities/3/type": {"eq": "line"}, "/result/editable": {"empty": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit"}, + {"tool": "call_tool", "args": {"tool": "commit"}, "expect": {"/result/objects/0/index": {"eq": 0}, "/result/objects/0/name": {"eq": "Design Body"}, "/result/objects/0/parts": {"eq": 1}, "/result/bodies_sent/0": {"eq": 0}, "/result/tab": {"eq": "prepare"}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}, "/plates/0/objects/0/name": {"eq": "Design Body"}, "/plates/0/objects/0/bbox/size/2": {"ge": 14.99, "le": 15.01}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 20}}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit", "args": {"replace": [0]}}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 20}}}}, + {"tool": "call_tool", "args": {"tool": "commit", "args": {"replace": [0]}}, "expect": {"/result/objects/0/index": {"eq": 0}, "/result/replaced/0/index": {"eq": 0}, "/result/replaced/0/name": {"eq": "Design Body"}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}, "/plates/0/objects/0/bbox/size/2": {"ge": 19.99, "le": 20.01}}}, {"tool": "run_action", "args": {"id": "orca_command:undo:orca"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}, "/plates/0/objects/0/bbox/size/2": {"ge": 14.99, "le": 15.01}}}, - {"tool": "call_cad_tool", "args": {"tool": "export_step", "args": {"path": "${out_dir}/design.step", "overwrite": true}}, + {"tool": "call_tool", "args": {"tool": "export_step", "args": {"path": "${out_dir}/design.step", "overwrite": true}}, "expect": {"/result/bytes": {"gt": 0}, "/result/bodies": {"eq": 1}, "/result/moved_bodies": {"empty": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}, "expect": {"/result/cleared/features": {"eq": 3}, "/result/cleared/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "import_step", "args": {"path": "${out_dir}/design.step"}}, + {"tool": "call_tool", "args": {"tool": "import_step", "args": {"path": "${out_dir}/design.step"}}, "expect": {"/result/ok": {"eq": true}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 11998.8, "le": 12001.2}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"profile": [[40, 0], [50, 0], [50, 10], [40, 10]], "distance": 5}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"profile": [[40, 0], [50, 0], [50, 10], [40, 10]], "distance": 5}}, "expect": {"/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit", "args": {"mode": "bodies"}}, + {"tool": "call_tool", "args": {"tool": "commit", "args": {"mode": "bodies"}}, "expect": {"/result/mode": {"eq": "bodies"}, "/result/objects/0/index": {"eq": 1}, "/result/objects/1/index": {"eq": 2}, "/result/objects/1/name": {"eq": "Design Body 2"}, "/result/bodies_sent/1": {"eq": 1}, "/result/bodies_hidden": {"empty": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit", "args": {"mode": "assembly"}}, + {"tool": "call_tool", "args": {"tool": "commit", "args": {"mode": "assembly"}}, "expect": {"/result/objects/0/index": {"eq": 3}, "/result/objects/0/name": {"eq": "Design Assembly"}, "/result/objects/0/parts": {"eq": 2}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 4}}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"width": 20, "height": 20, "distance": 10}}, "expect": {"/result/extrude_index": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}}}, - {"tool": "call_cad_tool", "args": {"tool": "undo"}, + {"tool": "call_tool", "args": {"tool": "set_feature", "args": {"feature": 1, "fields": {"distance": 15}}}}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}, "expect": {"/result/scope": {"eq": "design"}, "/result/undo_depth": {"eq": 1}, "/result/redo_depth": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 10.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "redo"}, "expect": {"/result/redo_depth": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"profile": [[40, 0], [50, 0], [50, 10], [40, 10]], "distance": 5}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 10.0}}}, + {"tool": "call_tool", "args": {"tool": "redo", "args": {"history": "design"}}, "expect": {"/result/redo_depth": {"eq": 0}}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"profile": [[40, 0], [50, 0], [50, 10], [40, 10]], "distance": 5}}, "expect": {"/result/extrude_index": {"eq": 3}, "/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_rename", "args": {"feature": 1, "name": " Base "}}, + {"tool": "call_tool", "args": {"tool": "feature_rename", "args": {"feature": 1, "name": " Base "}}, "expect": {"/result/name": {"eq": "Base"}, "/result/changed": {"eq": true}, "/result/undo_depth": {"eq": 4}}}, - {"tool": "call_cad_tool", "args": {"tool": "undo"}, "expect": {"/result/undo_depth": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}, "expect": {"/result/undo_depth": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/name": {"regex": "^Extrude \\d+$"}, "/result/features/3": {"exists": true}, "/result/features/4": {"exists": false}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "redo"}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/name": {"eq": "Base"}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": false}}, + {"tool": "call_tool", "args": {"tool": "describe_feature", "args": {"feature": 1}}, "expect": {"/result/params/distance": {"eq": 15.0}}}, + {"tool": "call_tool", "args": {"tool": "redo", "args": {"history": "design"}}}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/name": {"eq": "Base"}}}, + {"tool": "call_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": false}}, "expect": {"/result/changed": {"eq": true}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": false}}, + {"tool": "call_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": false}}, "expect": {"/result/changed": {"eq": false}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": true}}, + {"tool": "call_tool", "args": {"tool": "feature_set_enabled", "args": {"feature": 3, "enabled": true}}, "expect": {"/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_move", "args": {"feature": 2, "delta": -1}}, + {"tool": "call_tool", "args": {"tool": "feature_move", "args": {"feature": 2, "delta": -1}}, "expect": {"/result/feature": {"eq": 1}, "/result/from": {"eq": 2}, "/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/type": {"eq": "Sketch"}, "/result/features/2/name": {"eq": "Base"}}}, - {"tool": "call_cad_tool", "args": {"tool": "undo"}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/name": {"eq": "Base"}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 1, "name": "Lid", "visible": false}}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/1/name": {"eq": "Base"}}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 1, "name": "Lid", "visible": false}}, "expect": {"/result/name": {"eq": "Lid"}, "/result/visible": {"eq": false}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/1/name": {"eq": "Lid"}, "/result/bodies/1/user_name": {"eq": true}, "/result/bodies/1/visible": {"eq": false}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit"}, + {"tool": "call_tool", "args": {"tool": "commit"}, "expect": {"/result/bodies_sent/1": {"exists": false}, "/result/bodies_sent/0": {"eq": 0}, "/result/bodies_hidden/0": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 1, "visible": true}}, "expect": {"/result/visible": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 0, "visible": false}}}, - {"tool": "call_cad_tool", "args": {"tool": "commit", "args": {"mode": "bodies"}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 1, "visible": true}}, "expect": {"/result/visible": {"eq": true}}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 0, "visible": false}}}, + {"tool": "call_tool", "args": {"tool": "commit", "args": {"mode": "bodies"}}, "expect": {"/result/objects/0/name": {"eq": "Lid"}, "/result/bodies_sent/0": {"eq": 1}, "/result/bodies_hidden/0": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 0, "visible": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_delete", "args": {"body": 1}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 0, "visible": true}}}, + {"tool": "call_tool", "args": {"tool": "body_delete", "args": {"body": 1}}, "expect": {"/result/deleted_feature/index": {"eq": 3}, "/result/deleted_feature/type": {"eq": "Extrude"}, "/result/removed": {"eq": 1}, "/result/features": {"eq": 3}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "undo"}, "expect": {"/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/1/source_feature": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "feature_delete", "args": {"feature": 0}}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}, "expect": {"/result/bodies": {"eq": 2}}}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/1/source_feature": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "feature_delete", "args": {"feature": 0}}, "expect": {"/result/removed": {"eq": 2}, "/result/features": {"eq": 2}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "undo"}, "expect": {"/result/features": {"eq": 4}, "/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 1, "name": "Lid"}}}, - {"tool": "call_cad_tool", "args": {"tool": "body_set", "args": {"body": 1, "color": "#3080ff"}}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}, "expect": {"/result/features": {"eq": 4}, "/result/bodies": {"eq": 2}}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 1, "name": "Lid"}}}, + {"tool": "call_tool", "args": {"tool": "body_set", "args": {"body": 1, "color": "#3080ff"}}, "expect": {"/result/color": {"eq": "#3080FF"}}}, {"tool": "save_project", "args": {"path": "${out_dir}/design.3mf", "overwrite": true}}, {"tool": "new_project", "args": {"discard_changes": true}}, // Presets an earlier session modified make loading a project ask about them; the rule ends with the replay. {"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "Load project: unsaved changes", "button": "Discard"}]}}, {"tool": "open_files", "args": {"paths": ["${out_dir}/design.3mf"]}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/3": {"exists": true}, "/result/features/4": {"exists": false}, "/result/bodies/1/name": {"eq": "Lid"}, "/result/bodies/1/has_color": {"eq": true}, "/result/bodies/1/color": {"eq": "#3080FF"}}} ] diff --git a/tools/mcp/tests/cad_features.json b/tools/mcp/tests/cad_features.json index 0a1046367a..bd65b865d3 100644 --- a/tools/mcp/tests/cad_features.json +++ b/tools/mcp/tests/cad_features.json @@ -1,4 +1,4 @@ -// Threads, sweeps, lofts and plane splits through call_cad_tool. The bench's M5 hex standoff tapped on its +// Threads, sweeps, lofts and plane splits through the Design commands. The bench's M5 hex standoff tapped on its // bore (the size inferred from the bore, as the Thread card infers it) and again on the XY plane; a // spring swept along a helix, round and square wire; a square-to-circle loft between the XY plane and // a datum plane, then split by that datum and by XY turned over. Refused calls change nothing. Face @@ -13,85 +13,85 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, // M5 hex standoff: 8 mm across flats, 15 long, M5's 4.134 mm tap drill through it. - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"distance": 15, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"distance": 15, "profile": [[4.618802, 0], [2.309401, 4], [-2.309401, 4], [-4.618802, 0], [-2.309401, -4], [2.309401, -4]]}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "hole", "args": {"diameter": 4.134, "through": true}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"kinds": ["cylindrical"]}}, + {"tool": "call_tool", "args": {"tool": "hole", "args": {"diameter": 4.134, "through": true}}, "expect": {"/result/ok": {"eq": true}}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"kinds": ["cylindrical"]}}, "expect": {"/result/faces_total": {"eq": 1}, "/result/faces/0/id": {"eq": 8}, "/result/faces/0/internal": {"eq": true}}}, // A planar face cannot be threaded, and a designation not in the tables names the close ones. - {"tool": "call_cad_tool", "args": {"tool": "thread", "args": {"face": 0}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "thread", "args": {"face": 8, "designation": "M5x1"}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "thread", "args": {"face": 0}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "thread", "args": {"face": 8, "designation": "M5x1"}}, "optional": true}, // The bore: M5 inferred from its 4.134 mm minor diameter, internal, the bore's whole 15 mm. - {"tool": "call_cad_tool", "args": {"tool": "thread", "args": {"face": 8}}, + {"tool": "call_tool", "args": {"tool": "thread", "args": {"face": 8}}, "expect": {"/result/thread_index": {"eq": 3}, "/result/designation": {"eq": "M5"}, "/result/internal": {"eq": true}, "/result/pitch": {"ge": 0.7999, "le": 0.8001}, "/result/length": {"ge": 14.9999, "le": 15.0001}, "/result/body": {"eq": 0}, "/result/bodies": {"eq": 1}}}, // The bench case's bounds. - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/is_solid": {"eq": true}, "/result/volume": {"gt": 600.0, "lt": 614.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/3/type": {"eq": "Thread"}, "/result/undo_depth": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/3/type": {"eq": "Thread"}, "/result/undo_depth": {"eq": 3}}}, // The same thread placed on the XY plane, on the bore's axis. - {"tool": "call_cad_tool", "args": {"tool": "undo"}, "expect": {"/result/features": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "thread", "args": {"plane": "XY", "designation": "M5", "internal": true, "length": 15}}, + {"tool": "call_tool", "args": {"tool": "undo", "args": {"history": "design"}}, "expect": {"/result/features": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "thread", "args": {"plane": "XY", "designation": "M5", "internal": true, "length": 15}}, "expect": {"/result/x": {"eq": 0.0}, "/result/y": {"eq": 0.0}, "/result/body": {"eq": 0}, "/result/designation": {"eq": "M5"}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"gt": 600.0, "lt": 614.0}}}, // A spring: a helix of radius 10, pitch 5, six turns; a 1.5 mm wire drawn across its start on XZ. - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "helix", "args": {"radius": 10, "pitch": 5, "height": 30}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "helix", "args": {"radius": 10, "pitch": 5, "height": 30}}, "expect": {"/result/helix_index": {"eq": 0}, "/result/tangent/1": {"ge": 0.9968, "le": 0.9969}, "/result/tangent/2": {"ge": 0.0793, "le": 0.0794}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"type": "circle", "center": [10, 0], "radius": 1.5}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "sweep", "args": {"sketch": 1, "path": 0}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"type": "circle", "center": [10, 0], "radius": 1.5}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 1}}}, + {"tool": "call_tool", "args": {"tool": "sweep", "args": {"sketch": 1, "path": 0}}, "expect": {"/result/sweep_index": {"eq": 2}, "/result/body": {"eq": 0}, "/result/boolean": {"eq": "new"}}}, // pi 1.5^2 x the helix's 378.19 mm x 0.99685, the XZ plane's tilt off the helix's normal plane. - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/is_solid": {"eq": true}, "/result/volume": {"gt": 2638.0, "lt": 2691.0}}}, // A square wire beside it, 2 x 2. - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [9, -1, 11, 1]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 3}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [9, -1, 11, 1]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 3}}}, // A sweep is not a path. - {"tool": "call_cad_tool", "args": {"tool": "sweep", "args": {"sketch": 3, "path": 2}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "sweep", "args": {"sketch": 3, "path": 0}}, + {"tool": "call_tool", "args": {"tool": "sweep", "args": {"sketch": 3, "path": 2}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "sweep", "args": {"sketch": 3, "path": 0}}, "expect": {"/result/sweep_index": {"eq": 4}, "/result/body": {"eq": 1}, "/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 1}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 1}}, "expect": {"/result/is_solid": {"eq": true}, "/result/volume": {"gt": 1492.0, "lt": 1524.0}}}, // A loft from a 20 mm square on XY to an 8 mm circle on a datum plane 40 above it. - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 40}}, "expect": {"/result/plane_index": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [-10, -10, 10, 10]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"type": "circle", "center": [0, 0], "radius": 8}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "loft", "args": {"profiles": [1]}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "loft", "args": {"profiles": [1, 0]}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "loft", "args": {"profiles": [1, 2]}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "plane", "args": {"type": "offset", "base": "XY", "offset": 40}}, "expect": {"/result/plane_index": {"eq": 0}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [-10, -10, 10, 10]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 1}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"datum": 0}}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"type": "circle", "center": [0, 0], "radius": 8}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 2}}}, + {"tool": "call_tool", "args": {"tool": "loft", "args": {"profiles": [1]}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "loft", "args": {"profiles": [1, 0]}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "loft", "args": {"profiles": [1, 2]}}, "expect": {"/result/loft_index": {"eq": 3}, "/result/body": {"eq": 0}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/is_solid": {"eq": true}, "/result/volume": {"gt": 11850.0, "lt": 11861.0}}}, // Split by the datum plane 20 below it: the upper half stays body 0, the lower one is body 1. - {"tool": "call_cad_tool", "args": {"tool": "split", "args": {"plane": {"datum": 0}, "offset": 60}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "split", "args": {"plane": {"datum": 0}, "offset": -20}}, + {"tool": "call_tool", "args": {"tool": "split", "args": {"plane": {"datum": 0}, "offset": 60}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "split", "args": {"plane": {"datum": 0}, "offset": -20}}, "expect": {"/result/split_index": {"eq": 4}, "/result/upper_body": {"eq": 0}, "/result/lower_body": {"eq": 1}, "/result/bodies": {"eq": 2}, "/result/frame/normal/2": {"eq": 1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/4/type": {"eq": "Cut"}, "/result/bodies/0/bbox/min/2": {"ge": 19.999, "le": 20.001}, "/result/bodies/1/bbox/max/2": {"ge": 19.999, "le": 20.001}}}, // The lower half, by XY at 10 turned over, keeping only the side toward the bed. - {"tool": "call_cad_tool", "args": {"tool": "split", "args": {"body": 1, "plane": "XY", "offset": 10, "flip": true, "keep_lower": false}}, + {"tool": "call_tool", "args": {"tool": "split", "args": {"body": 1, "plane": "XY", "offset": 10, "flip": true, "keep_lower": false}}, "expect": {"/result/upper_body": {"eq": 1}, "/result/bodies": {"eq": 2}, "/result/frame/normal/2": {"eq": -1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/1/bbox/min/2": {"ge": -0.001, "le": 0.001}, "/result/bodies/1/bbox/max/2": {"ge": 9.999, "le": 10.001}, "/result/undo_depth": {"eq": 6}}} ] diff --git a/tools/mcp/tests/cad_sketch_edit.json b/tools/mcp/tests/cad_sketch_edit.json index 33d5f7a1aa..48ce18af0c 100644 --- a/tools/mcp/tests/cad_sketch_edit.json +++ b/tools/mcp/tests/cad_sketch_edit.json @@ -1,4 +1,4 @@ -// The sketch's own tools through call_cad_tool: shapes drawn by their drawing tools (polygon, slot, +// The sketch's own tools through the Design commands: shapes drawn by their drawing tools (polygon, slot, // ellipse, spline), the edit tools (trim, extend, chamfer, fillet, move, rotate, linear and polar // arrays) and the CONSTRAIN bar (constraints from picks and from named points, one refused, one // deleted), each read back from the sketch and from the solid it is extruded into. Sketch @@ -13,53 +13,53 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, // The bench's M5 hex standoff from a polygon 8 across the flats and its 4.134 mm tap drill. - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [ + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [ {"type": "polygon", "center": [0, 0], "sides": 6, "across_flats": 8}, {"type": "circle", "center": [0, 0], "radius": 2.067}]}}, "expect": {"/result/shapes/0/count": {"eq": 6}, "/result/shapes/1/first": {"eq": 6}, "/result/entities": {"eq": 7}}}, // The first edge is a flat 4 mm from the centre; the hexagon holds the bore as its hole. - {"tool": "call_cad_tool", "args": {"tool": "sketch_describe"}, + {"tool": "call_tool", "args": {"tool": "sketch_describe"}, "expect": {"/result/entities/0/p0/0": {"ge": 3.9999, "le": 4.0001}, "/result/entities/0/p1/0": {"ge": 3.9999, "le": 4.0001}, "/result/closed_loops/1/holes/0": {"eq": 0}, "/result/closed_loops/1/area": {"ge": 55.4256, "le": 55.4257}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/buildable": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 15}}, "expect": {"/result/body": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/buildable": {"eq": true}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 15}}, "expect": {"/result/body": {"eq": 0}}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 630.0, "le": 630.1}}}, // Trim and extend on crossing lines. - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [ + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [ {"type": "line", "p0": [-10, 0], "p1": [10, 0]}, {"type": "line", "p0": [0, -10], "p1": [0, 10]}, {"type": "line", "p0": [0, 20], "p1": [10, 20]}, {"type": "line", "p0": [30, 15], "p1": [30, 25]}]}}}, // Line 0 is cut back from its end beyond the crossing. - {"tool": "call_cad_tool", "args": {"tool": "sketch_trim", "args": {"at": [5, 0]}}, + {"tool": "call_tool", "args": {"tool": "sketch_trim", "args": {"at": [5, 0]}}, "expect": {"/result/entity": {"eq": 0}, "/result/geometry/p1/0": {"ge": -0.0001, "le": 0.0001}, "/result/geometry/p0/0": {"eq": -10.0}}}, // Nothing there to cut: refused. - {"tool": "call_cad_tool", "args": {"tool": "sketch_trim", "args": {"at": [100, 100]}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "sketch_trim", "args": {"at": [100, 100]}}, "optional": true}, // Line 2 runs out to line 3. - {"tool": "call_cad_tool", "args": {"tool": "sketch_trim", "args": {"at": [9, 20], "extend": true}}, + {"tool": "call_tool", "args": {"tool": "sketch_trim", "args": {"at": [9, 20], "extend": true}}, "expect": {"/result/entity": {"eq": 2}, "/result/geometry/p1/0": {"ge": 29.9999, "le": 30.0001}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_cancel"}}, + {"tool": "call_tool", "args": {"tool": "sketch_cancel"}}, // A 60 x 40 plate: one corner chamfered, one rounded, two slots, an elliptic hole and four // holes arrayed about a point, then constrained. - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [-30, -20, 30, 20]}}, "expect": {"/result/dof": {"eq": 4}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_chamfer", "args": {"entities": [0, 1], "distance": 5}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [-30, -20, 30, 20]}}, "expect": {"/result/dof": {"eq": 4}}}, + {"tool": "call_tool", "args": {"tool": "sketch_chamfer", "args": {"entities": [0, 1], "distance": 5}}, "expect": {"/result/entity": {"eq": 4}, "/result/released_constraints": {"eq": 1}}}, // Too big for the 35 mm left of the bottom edge: refused. - {"tool": "call_cad_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 100}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 6}}, + {"tool": "call_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 100}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 6}}, "expect": {"/result/entity": {"eq": 5}, "/result/entities": {"eq": 6}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [ + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [ {"type": "slot", "c0": [-15, 0], "c1": [-5, 0], "width": 4}, {"type": "ellipse", "center": [0, -10], "radius": 4, "rminor": 2, "rotation_deg": 0}, {"type": "circle", "center": [11, 0], "radius": 1.5}, @@ -67,42 +67,42 @@ "expect": {"/result/shapes/0/count": {"eq": 4}, "/result/shapes/1/first": {"eq": 10}, "/result/shapes/2/first": {"eq": 11}, "/result/shapes/3/first": {"eq": 12}, "/result/entities": {"eq": 13}}}, // A second slot above the first, turned upright about its own centre. - {"tool": "call_cad_tool", "args": {"tool": "sketch_transform", "args": {"op": "array", "entities": [6, 7, 8, 9], "dy": 10, "count": 2}}, + {"tool": "call_tool", "args": {"tool": "sketch_transform", "args": {"op": "array", "entities": [6, 7, 8, 9], "dy": 10, "count": 2}}, "expect": {"/result/first_index": {"eq": 13}, "/result/added": {"eq": 4}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_transform", "args": {"op": "rotate", "entities": [13, 14, 15, 16], "angle_deg": 90}}, + {"tool": "call_tool", "args": {"tool": "sketch_transform", "args": {"op": "rotate", "entities": [13, 14, 15, 16], "angle_deg": 90}}, "expect": {"/result/pivot/0": {"ge": -10.0001, "le": -9.9999}, "/result/pivot/1": {"ge": 9.9999, "le": 10.0001}}}, // The hole moved 1 mm right (picked by selection), then arrayed four times about (17, 0). - {"tool": "call_cad_tool", "args": {"tool": "sketch_select", "args": {"entities": [11]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_transform", "args": {"op": "move", "dx": 1}}, + {"tool": "call_tool", "args": {"tool": "sketch_select", "args": {"entities": [11]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_transform", "args": {"op": "move", "dx": 1}}, "expect": {"/result/moved/0": {"eq": 11}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_transform", "args": {"op": "polar_array", "entities": [11], "pivot": [17, 0], "count": 4}}, + {"tool": "call_tool", "args": {"tool": "sketch_transform", "args": {"op": "polar_array", "entities": [11], "pivot": [17, 0], "count": 4}}, "expect": {"/result/first_index": {"eq": 17}, "/result/added": {"eq": 3}, "/result/bound": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_describe"}, + {"tool": "call_tool", "args": {"tool": "sketch_describe"}, "expect": {"/result/entities/18/center/0": {"ge": 21.9999, "le": 22.0001}, "/result/entities/18/center/1": {"ge": -0.0001, "le": 0.0001}, "/result/entities/14/p0/0": {"ge": -12.0001, "le": -11.9999}, "/result/buildable": {"eq": true}}}, // Constraints: the hole held 12 from the origin (its current distance), the first copy kept the // hole's size. A rival radius cannot be met and is rolled back; the distance is deleted again. - {"tool": "call_cad_tool", "args": {"tool": "sketch_constraints"}, "expect": {"/result/constraints": {"eq": 25}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_constrain", "args": {"type": "distance", + {"tool": "call_tool", "args": {"tool": "sketch_constraints"}, "expect": {"/result/constraints": {"eq": 25}}}, + {"tool": "call_tool", "args": {"tool": "sketch_constrain", "args": {"type": "distance", "refs": [{"entity": 11, "role": "center"}, {"entity": "origin"}], "value": 12}}, "expect": {"/result/added/0": {"eq": 25}, "/result/items/0/type": {"eq": "distance"}, "/result/items/0/refs/1/entity": {"eq": "origin"}, "/result/solve_ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_constrain", "args": {"type": "equal", "entities": [11, 17]}}, + {"tool": "call_tool", "args": {"tool": "sketch_constrain", "args": {"type": "equal", "entities": [11, 17]}}, "expect": {"/result/items/0/type": {"eq": "equal_radius"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_constrain", "args": {"type": "radius", "entities": [11], "value": 2}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_constraints"}, + {"tool": "call_tool", "args": {"tool": "sketch_constrain", "args": {"type": "radius", "entities": [11], "value": 2}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "sketch_constraints"}, "expect": {"/result/scope": {"eq": "live"}, "/result/constraints": {"eq": 27}, "/result/items/26/type": {"eq": "equal_radius"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_unconstrain", "args": {"index": 25}}, + {"tool": "call_tool", "args": {"tool": "sketch_unconstrain", "args": {"index": 25}}, "expect": {"/result/removed/type": {"eq": "distance"}, "/result/constraints": {"eq": 26}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/buildable": {"eq": true}, "/result/sketch_index": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_constraints", "args": {"sketch": 0}}, + {"tool": "call_tool", "args": {"tool": "sketch_constraints", "args": {"sketch": 0}}, "expect": {"/result/scope": {"eq": "committed"}, "/result/constraints": {"eq": 26}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 5}}, "expect": {"/result/body": {"eq": 0}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 5}}, "expect": {"/result/body": {"eq": 0}}}, // 60 x 40, less the chamfer (12.5), the fillet's corner (36 (1 - pi/4)), two slots (40 + 4 pi each), // the ellipse (8 pi) and four holes (2.25 pi each): 2221.23 mm2, 5 mm thick. - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 11106.1, "le": 11106.25}}} ] } diff --git a/tools/mcp/tests/cad_sketch_to_solid.json b/tools/mcp/tests/cad_sketch_to_solid.json index 234aa9904c..b650a62af2 100644 --- a/tools/mcp/tests/cad_sketch_to_solid.json +++ b/tools/mcp/tests/cad_sketch_to_solid.json @@ -1,4 +1,4 @@ -// Sketch to solid through call_cad_tool: sketches on a base plane through modeling_origin and on a +// Sketch to solid through the Design commands: sketches on a base plane through modeling_origin and on a // body's face, committed and read back, then extruded whole, by loop and joined onto the body they // touch, and revolved about the sketch's centerline. An empty sketch is refused and stays open. The // L-bracket's inside corner is rounded in the sketch, as the Fillet tool rounds it. @@ -12,15 +12,15 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, // An L-bracket profile on XZ, which passes through modeling_origin, not the bed corner: 40 x 30, 4 thick. - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}, "expect": {"/result/plane": {"eq": "XZ"}, "/result/frame/normal/1": {"eq": 1.0}, "/result/frame/origin/0": {"gt": 1.0}}}, // Committing it empty fails and leaves it open: the next step reads the open sketch. - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_describe"}, "expect": {"/result/entities": {"empty": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [ + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "sketch_describe"}, "expect": {"/result/entities": {"empty": true}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [ {"type": "line", "p0": [0, 0], "p1": [40, 0]}, {"type": "line", "p0": [40, 0], "p1": [40, 4]}, {"type": "line", "p0": [40, 4], "p1": [4, 4]}, @@ -29,74 +29,74 @@ {"type": "line", "p0": [0, 30], "p1": [0, 0]}]}}, "expect": {"/result/entities": {"eq": 6}}}, // The inside corner, between lines 2 and 3, rounded to 3 mm: an arc tangent to both legs. - {"tool": "call_cad_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 3}}, + {"tool": "call_tool", "args": {"tool": "sketch_fillet", "args": {"entities": [2, 3], "radius": 3}}, "expect": {"/result/entity": {"eq": 6}, "/result/entities": {"eq": 7}, "/result/released_constraints": {"eq": 1}, "/result/solve_ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 0}, "/result/name": {"regex": "^Sketch"}, "/result/features": {"eq": 1}, "/result/buildable": {"eq": true}, "/result/closed_loops/0/index": {"eq": 0}, "/result/closed_loops/0/area": {"ge": 265.93, "le": 265.94}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_describe", "args": {"sketch": 0}}, + {"tool": "call_tool", "args": {"tool": "sketch_describe", "args": {"sketch": 0}}, "expect": {"/result/plane/base": {"eq": "XZ"}, "/result/entities/6/type": {"eq": "arc"}, "/result/entities/6/radius": {"ge": 2.9999, "le": 3.0001}, "/result/closed_loops/0/entities/6": {"exists": true}, "/result/buildable": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 20}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 20}}, "expect": {"/result/extrude_index": {"eq": 1}, "/result/sketch_index": {"eq": 0}, "/result/boolean": {"eq": "new"}, "/result/body": {"eq": 0}, "/result/end": {"eq": "blind"}, "/result/frame/normal/1": {"eq": 1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"gt": 5316.6, "lt": 5320.6}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/0/bbox/min/0": {"gt": 1.0}, "/result/bodies/0/bbox/min/2": {"ge": -0.001, "le": 0.001}, "/result/bodies/0/bbox/max/2": {"ge": 29.999, "le": 30.001}}}, // A shelf-pin jig: a 160 x 60 plate with five 5.2 mm holes on 32 mm centres, in one sketch. - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [-80, -30, 80, 30]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [ + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XY"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [-80, -30, 80, 30]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [ {"type": "circle", "center": [-64, 0], "radius": 2.6}, {"type": "circle", "center": [-32, 0], "radius": 2.6}, {"type": "circle", "center": [0, 0], "radius": 2.6}, {"type": "circle", "center": [32, 0], "radius": 2.6}, {"type": "circle", "center": [64, 0], "radius": 2.6}]}}}, // Six loops: each disc, and the plate listing the five as its holes. - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/buildable": {"eq": true}, "/result/closed_loops/5/index": {"eq": 5}, "/result/closed_loops/5/holes/4": {"exists": true}, "/result/closed_loops/5/area": {"ge": 9599.99, "le": 9600.01}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 8}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "distance": 8}}, "expect": {"/result/boolean": {"eq": "new"}, "/result/body": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 75950.50, "le": 75950.53}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"body": 0}}, "expect": {"/result/face_count": {"eq": 11}, "/result/faces/4/kind": {"eq": "cylindrical"}, "/result/faces/8/kind": {"eq": "cylindrical"}, "/result/faces/10/normal/2": {"eq": 1.0}}}, // The lip, sketched on the plate's top face: that frame's x is world -Y and its y world X. - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"body": 0, "face": 10}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"body": 0, "face": 10}}}, "expect": {"/result/frame/origin/2": {"ge": 7.999, "le": 8.001}, "/result/frame/x_axis/1": {"eq": -1.0}, "/result/frame/y_axis/0": {"eq": 1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [-30, -80, -20, 80]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 2}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [-30, -80, -20, 80]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 2}}}, // It touches the plate, so it joins it, as the Extrude card's default does. - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 2, "distance": 10}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 2, "distance": 10}}, "expect": {"/result/boolean": {"eq": "union"}, "/result/body": {"eq": 0}, "/result/bodies": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 91950.50, "le": 91950.53}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/0/bbox/max/2": {"ge": 17.999, "le": 18.001}}}, // One loop of the plate's sketch: a hole's loop is its disc. - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "loop": 2, "distance": 8, "boolean": "new"}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 0, "loop": 2, "distance": 8, "boolean": "new"}}, "expect": {"/result/loop": {"eq": 2}, "/result/body": {"eq": 1}, "/result/bodies": {"eq": 2}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 1}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 1}}, "expect": {"/result/volume": {"ge": 169.89, "le": 169.91}}}, // A ring: a 10 x 10 profile revolved about the sketch's only centerline. - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"rect": [10, 0, 20, 10]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"type": "line", "p0": [0, 0], "p1": [0, 30], "construction": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "revolve", "args": {"sketch": 0}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": "XZ"}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"rect": [10, 0, 20, 10]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"type": "line", "p0": [0, 0], "p1": [0, 30], "construction": true}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 0}}}, + {"tool": "call_tool", "args": {"tool": "revolve", "args": {"sketch": 0}}, "expect": {"/result/revolve_index": {"eq": 1}, "/result/axis_entity": {"eq": 4}, "/result/boolean": {"eq": "new"}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 9424.70, "le": 9424.86}}} ] } diff --git a/tools/mcp/tests/cad_topology_targets.json b/tools/mcp/tests/cad_topology_targets.json index 661b9d7d59..41f4e63300 100644 --- a/tools/mcp/tests/cad_topology_targets.json +++ b/tools/mcp/tests/cad_topology_targets.json @@ -1,4 +1,4 @@ -// Reading a body's topology and building on what it finds, through call_cad_tool. The bench's J wall +// Reading a body's topology and building on what it finds, through the Design commands. The bench's J wall // hook: its inside corners found by convexity, M4 countersinks seated on the front face on the axes // of pilot holes (`at` a cylindrical face), checked through query_topology's cone kinds and adjacency // and measure's min_distance; then datum planes, a sketch on one, and a face push/pull. A refused @@ -14,81 +14,81 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_window", "args": {"size": [1920, 1200]}}, - {"tool": "call_cad_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, + {"tool": "call_tool", "args": {"tool": "new_design", "args": {"discard_changes": true}}}, // Back plate 60 x 5, arm 35 out, lip 15 up, 20 wide. - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"plane": "XZ", "distance": 20, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"plane": "XZ", "distance": 20, "profile": [[5, 0], [5, 60], [0, 60], [0, 5], [-30, 5], [-30, 15], [-35, 15], [-35, 0]]}}, "expect": {"/result/ok": {"eq": true}, "/result/body": {"eq": 0}}}, // Two inside corners, each with the faces on either side of it. - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"convex": false}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"convex": false}}, "expect": {"/result/edges_total": {"eq": 2}, "/result/edges/0/id": {"eq": 7}, "/result/edges/0/kind": {"eq": "line"}, "/result/edges/0/convex": {"eq": false}, "/result/edges/0/faces": {"contains": 2}, "/result/faces_total": {"eq": 3}}}, - {"tool": "call_cad_tool", "args": {"tool": "fillet", "args": {"edge": 7, "radius": 5}}, "expect": {"/result/ok": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"kinds": ["cylindrical"]}}, + {"tool": "call_tool", "args": {"tool": "fillet", "args": {"edge": 7, "radius": 5}}, "expect": {"/result/ok": {"eq": true}}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"kinds": ["cylindrical"]}}, "expect": {"/result/faces_total": {"eq": 1}, "/result/faces/0/radius": {"ge": 4.9999, "le": 5.0001}, "/result/faces/0/internal": {"eq": true}, "/result/edges": {"empty": true}}}, // Pilot holes from the YZ plane, then countersinks seated on the front face on their axes. - {"tool": "call_cad_tool", "args": {"tool": "hole", "args": {"plane": "YZ", "x": 10, "y": 25, "diameter": 3, "through": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "hole", "args": {"plane": "YZ", "x": 10, "y": 50, "diameter": 3, "through": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"direction": [-1, 0, 0]}}, + {"tool": "call_tool", "args": {"tool": "hole", "args": {"plane": "YZ", "x": 10, "y": 25, "diameter": 3, "through": true}}}, + {"tool": "call_tool", "args": {"tool": "hole", "args": {"plane": "YZ", "x": 10, "y": 50, "diameter": 3, "through": true}}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"direction": [-1, 0, 0]}}, "expect": {"/result/faces_total": {"eq": 2}, "/result/faces/0/id": {"eq": 0}, "/result/faces/0/area": {"ge": 985.86, "le": 985.87}}}, - {"tool": "call_cad_tool", "args": {"tool": "hole_standard", "args": {"designation": "M4", "style": 2, + {"tool": "call_tool", "args": {"tool": "hole_standard", "args": {"designation": "M4", "style": 2, "plane": {"body": 0, "face": 0}, "at": {"body": 0, "face": 6}}}, "expect": {"/result/body": {"eq": 0}, "/result/off_plane": {"ge": 4.9999, "le": 5.0001}, "/result/y": {"ge": -0.0001, "le": 0.0001}, "/result/frame/normal/0": {"eq": 1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "hole_standard", "args": {"designation": "M4", "style": 2, + {"tool": "call_tool", "args": {"tool": "hole_standard", "args": {"designation": "M4", "style": 2, "plane": {"body": 0, "face": 0}, "at": {"body": 0, "face": 5}}}, "expect": {"/result/body": {"eq": 0}, "/result/off_plane": {"ge": 4.9999, "le": 5.0001}}}, // Two cones, opening out of the front face (-X) from an apex inside the 5 mm plate. - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"kinds": ["conical"], "adjacency": true}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"kinds": ["conical"], "adjacency": true}}, "expect": {"/result/faces_total": {"eq": 2}, "/result/faces/0/half_angle_deg": {"ge": 44.999, "le": 45.001}, "/result/faces/0/radius_max": {"ge": 4.4999, "le": 4.5001}, "/result/faces/0/radius_min": {"ge": 2.2499, "le": 2.2501}, "/result/faces/0/internal": {"eq": true}, "/result/faces/0/axis/0": {"eq": -1.0}, "/result/faces/1/axis/0": {"eq": -1.0}, "/result/edges_total": {"eq": 6}, "/result/edges/0/faces": {"contains": 0}, "/result/edges/0/convex": {"eq": true}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 10352.82, "le": 10352.84}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"at_extreme": "-z"}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"at_extreme": "-z"}}, "expect": {"/result/faces_total": {"eq": 1}, "/result/faces/0/id": {"eq": 10}, "/result/edges": {"empty": true}}}, // Hole heights from the bottom face and the spacing, by the bores' axes. - {"tool": "call_cad_tool", "args": {"tool": "measure", "args": {"a": {"face": 14, "axis": true}, "b": {"face": 10}}}, + {"tool": "call_tool", "args": {"tool": "measure", "args": {"a": {"face": 14, "axis": true}, "b": {"face": 10}}}, "expect": {"/result/min_distance": {"ge": 24.9999, "le": 25.0001}, "/result/angle_deg": {"ge": 89.999, "le": 90.001}}}, - {"tool": "call_cad_tool", "args": {"tool": "measure", "args": {"a": {"face": 13, "axis": true}, "b": {"face": 14, "axis": true}}}, + {"tool": "call_tool", "args": {"tool": "measure", "args": {"a": {"face": 13, "axis": true}, "b": {"face": 14, "axis": true}}}, "expect": {"/result/min_distance": {"ge": 24.9999, "le": 25.0001}, "/result/distance": {"ge": 24.9999, "le": 25.0001}}}, // The cone touches the front face and stops 2.75 mm short of the back one. - {"tool": "call_cad_tool", "args": {"tool": "measure", "args": {"a": {"face": 6}, "b": {"face": 0}}}, + {"tool": "call_tool", "args": {"tool": "measure", "args": {"a": {"face": 6}, "b": {"face": 0}}}, "expect": {"/result/min_distance": {"le": 0.0001}}}, - {"tool": "call_cad_tool", "args": {"tool": "measure", "args": {"a": {"face": 6}, "b": {"face": 8}}}, + {"tool": "call_tool", "args": {"tool": "measure", "args": {"a": {"face": 6}, "b": {"face": 8}}}, "expect": {"/result/min_distance": {"ge": 2.7499, "le": 2.7501}}}, - {"tool": "call_cad_tool", "args": {"tool": "measure", "args": {"a": {"face": 0}, "b": {"face": 8}}}, + {"tool": "call_tool", "args": {"tool": "measure", "args": {"a": {"face": 0}, "b": {"face": 8}}}, "expect": {"/result/parallel_gap": {"ge": 4.9999, "le": 5.0001}, "/result/min_distance": {"ge": 4.9999, "le": 5.0001}}}, // Datum planes: midway through the plate, and 70 mm above the bed with a sketch on it. - {"tool": "call_cad_tool", "args": {"tool": "plane", "args": {"type": "midplane", "face_a": {"body": 0, "face": 0}, "face_b": {"body": 0, "face": 8}}}, + {"tool": "call_tool", "args": {"tool": "plane", "args": {"type": "midplane", "face_a": {"body": 0, "face": 0}, "face_b": {"body": 0, "face": 8}}}, "expect": {"/result/plane_index": {"eq": 7}, "/result/name": {"regex": "^Plane"}, "/result/frame/normal/0": {"eq": -1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "plane", "args": {"offset": 70}}, + {"tool": "call_tool", "args": {"tool": "plane", "args": {"offset": 70}}, "expect": {"/result/plane_index": {"eq": 8}, "/result/frame/origin/2": {"eq": 70.0}, "/result/frame/normal/2": {"eq": 1.0}}}, // A tangent plane needs a cylindrical face: refused, and nothing changes. - {"tool": "call_cad_tool", "args": {"tool": "plane", "args": {"type": "tangent", "face_a": {"body": 0, "face": 0}}}, "optional": true}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "plane", "args": {"type": "tangent", "face_a": {"body": 0, "face": 0}}}, "optional": true}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/features/8/type": {"eq": "Plane"}, "/result/features/9": {"exists": false}, "/result/undo_depth": {"eq": 8}, "/result/redo_depth": {"eq": 0}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"datum": 8}}}, + {"tool": "call_tool", "args": {"tool": "sketch_begin", "args": {"plane": {"datum": 8}}}, "expect": {"/result/frame/origin/2": {"eq": 70.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [10, 10], "radius": 5}]}}}, - {"tool": "call_cad_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 9}}}, - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"sketch": 9, "distance": 4}}, + {"tool": "call_tool", "args": {"tool": "sketch_add", "args": {"entities": [{"type": "circle", "center": [10, 10], "radius": 5}]}}}, + {"tool": "call_tool", "args": {"tool": "sketch_commit"}, "expect": {"/result/sketch_index": {"eq": 9}}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"sketch": 9, "distance": 4}}, "expect": {"/result/boolean": {"eq": "new"}, "/result/body": {"eq": 1}}}, - {"tool": "call_cad_tool", "args": {"tool": "describe_scene"}, + {"tool": "call_tool", "args": {"tool": "describe_scene"}, "expect": {"/result/bodies/1/bbox/min/2": {"ge": 69.999, "le": 70.001}, "/result/bodies/1/bbox/max/2": {"ge": 73.999, "le": 74.001}}}, // Push the plate's back face out 2 mm: it joins its own body. - {"tool": "call_cad_tool", "args": {"tool": "extrude", "args": {"face": 8, "body": 0, "distance": 2}}, + {"tool": "call_tool", "args": {"tool": "extrude", "args": {"face": 8, "body": 0, "distance": 2}}, "expect": {"/result/boolean": {"eq": "union"}, "/result/body": {"eq": 0}, "/result/sketch_index": {"eq": -1}, "/result/face": {"eq": 8}, "/result/frame/normal/0": {"eq": 1.0}}}, - {"tool": "call_cad_tool", "args": {"tool": "mass_properties", "args": {"body": 0}}, + {"tool": "call_tool", "args": {"tool": "mass_props", "args": {"body": 0}}, "expect": {"/result/volume": {"ge": 12689.20, "le": 12689.22}}}, - {"tool": "call_cad_tool", "args": {"tool": "query_topology", "args": {"limit": 5}}, + {"tool": "call_tool", "args": {"tool": "query_topology", "args": {"limit": 5}}, "expect": {"/result/faces/4": {"exists": true}, "/result/faces/5": {"exists": false}, "/result/next_offset": {"eq": 5}}} ] } diff --git a/tools/mcp/tests/calibration.json b/tools/mcp/tests/calibration.json index 8794f52e30..3b808fb04b 100644 --- a/tools/mcp/tests/calibration.json +++ b/tools/mcp/tests/calibration.json @@ -129,7 +129,7 @@ {"tool": "get_settings", "args": {"scope": "filament", "keys": ["slow_down_layer_time"]}, "expect": {"/items/0/value": {"eq": "4"}}}, // ---- Back to one slot and no MCP presets ---- - {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "param": "2"}, "expect": {"/level": {"eq": "success"}}}, + {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "args": {"slot": 2}}, "expect": {"/level": {"eq": "success"}}}, {"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Calib PLA"}, "expect": {"/deleted": {"eq": "MCP Calib PLA"}}}, {"tool": "list_presets", "args": {"type": "filament"}, "expect": {"/total": {"eq": 1}, "/items/0/modified": {"exists": false}}} ] diff --git a/tools/mcp/tests/gizmos.json b/tools/mcp/tests/gizmos.json index 760ca5fcce..146866a71d 100644 --- a/tools/mcp/tests/gizmos.json +++ b/tools/mcp/tests/gizmos.json @@ -206,7 +206,7 @@ // ---- SVG: a new object with nothing selected, a part of the selected cube, then Change file and Save as ---- {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "param": "${vars.svg}"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "args": {"path": "${vars.svg}"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 3}, "/plates/0/objects/2/parts/0/svg/path": {"contains": "star.svg"}}}, {"tool": "get_app_state", "expect": {"/gizmo/name": {"eq": "SVG"}}}, @@ -219,7 +219,7 @@ {"tool": "list_widgets", "args": {"query": "star-copy"}, "expect": {"/nodes": {"eq": 0}}}, {"tool": "click", "args": {"target": {"gizmo": "SVG"}}}, {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "param": "${vars.svg}"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "args": {"path": "${vars.svg}"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/2/svg/path": {"contains": "star.svg"}}}, {"tool": "screenshot", "args": {"target": "canvas", "save_path": "${out_dir}/svg.png", "overwrite": true, "include_image": false}}, diff --git a/tools/mcp/tests/ops_assign_filament_preset_multi_slot.json b/tools/mcp/tests/ops_assign_filament_preset_multi_slot.json index 7201ec1864..593b7d6263 100644 --- a/tools/mcp/tests/ops_assign_filament_preset_multi_slot.json +++ b/tools/mcp/tests/ops_assign_filament_preset_multi_slot.json @@ -42,7 +42,7 @@ {"tool": "get_app_state", "expect": {"/presets/filaments/2": {"exists": true}, "/presets/filaments/3": {"exists": false}}}, // ==== Automatic flush calculation "All" (all) ==== - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_calculate_flush"}, "await": false, "save_as": "prefs1"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_calculate_flush"}}, "await": false, "save_as": "prefs1"}, // The choice is saved by the drop-down's own handler, so it is picked from its list. {"tool": "click", "args": {"target": {"name": "auto_calculate_flush", "within": "Preferences"}}}, {"tool": "click", "args": {"target": {"row": "All"}}}, @@ -105,7 +105,7 @@ {"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}}, // ==== Automatic flush calculation "Color" (color change) ==== - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_calculate_flush"}, "await": false, "save_as": "prefs2"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_calculate_flush"}}, "await": false, "save_as": "prefs2"}, // The choice is saved by the drop-down's own handler, so it is picked from its list. {"tool": "click", "args": {"target": {"name": "auto_calculate_flush", "within": "Preferences"}}}, {"tool": "click", "args": {"target": {"row": "Color"}}}, @@ -168,7 +168,7 @@ {"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}}, // ==== Automatic flush calculation "None" (disabled) ==== - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_calculate_flush"}, "await": false, "save_as": "prefs3"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_calculate_flush"}}, "await": false, "save_as": "prefs3"}, // The choice is saved by the drop-down's own handler, so it is picked from its list. {"tool": "click", "args": {"target": {"name": "auto_calculate_flush", "within": "Preferences"}}}, {"tool": "click", "args": {"target": {"row": "None"}}}, @@ -231,7 +231,7 @@ {"tool": "run_script", "args": {"filename": "${replay_dir}/fixtures/ops_presets.py", "code": "import ops_presets\nresult = ops_presets.probe()"}}, // ==== Back to "All": the other forms, unsaved changes, refusals ==== - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_calculate_flush"}, "await": false, "save_as": "prefs4"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_calculate_flush"}}, "await": false, "save_as": "prefs4"}, // The choice is saved by the drop-down's own handler, so it is picked from its list. {"tool": "click", "args": {"target": {"name": "auto_calculate_flush", "within": "Preferences"}}}, {"tool": "click", "args": {"target": {"row": "All"}}}, diff --git a/tools/mcp/tests/ops_assign_filament_preset_one_slot.json b/tools/mcp/tests/ops_assign_filament_preset_one_slot.json index f9ab04b31a..b0c219e1b7 100644 --- a/tools/mcp/tests/ops_assign_filament_preset_one_slot.json +++ b/tools/mcp/tests/ops_assign_filament_preset_one_slot.json @@ -35,7 +35,7 @@ {"tool": "select_preset", "args": {"type": "filament", "name": "Bambu Support for ABS", "filament_slot": 1}}, {"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1}}, {"tool": "get_app_state", "expect": {"/presets/filaments/0": {"exists": true}, "/presets/filaments/1": {"exists": false}}}, - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_calculate_flush"}, "await": false, "save_as": "prefs1"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_calculate_flush"}}, "await": false, "save_as": "prefs1"}, // The choice is saved by the drop-down's own handler, so it is picked from its list. {"tool": "click", "args": {"target": {"name": "auto_calculate_flush", "within": "Preferences"}}}, {"tool": "click", "args": {"target": {"row": "All"}}}, diff --git a/tools/mcp/tests/ops_export_gcode.json b/tools/mcp/tests/ops_export_gcode.json index 72d61b7e4b..59f79aa6f6 100644 --- a/tools/mcp/tests/ops_export_gcode.json +++ b/tools/mcp/tests/ops_export_gcode.json @@ -1,7 +1,7 @@ // Records what the G-code export does through its two routes, the export tool (format gcode) and the -// export_gcode command run with run_action and a path param: with no objects, on a plate not sliced, after a +// export_gcode command run with run_action and a path: with no objects, on a plate not sliced, after a // slice that ended with an error, while a slice runs (started by slice_and_preview and slice_all, which return -// at once), with a plate index the project lacks, with no param, a success, and two exports started back to back +// at once), with a plate index the project lacks, a success, and two exports started back to back // through each route. A replay step returns once a short export has finished, so those two run one after the // other; overlapping calls need two clients. Every call it records is optional, so a refusal is kept in // result.json with its text, which both routes word alike, and each is followed by the reads that show what it @@ -9,8 +9,7 @@ // export to a G-code's path with a plate the project lacks tells whether that file exists: it refuses with // "exists" when it does, with the plate when not. Each case waits for idle first, since an export right after an // edit is refused as slicing while the edit's background update is pending. Run it into a fresh --out directory -// (a command's JSON path param can't carry a Windows ${out_dir}, so the commands write without overwrite and -// refuse the files of an earlier run): +// (the commands write without overwrite, so they refuse the files of an earlier run): // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_gcode.json --out <new dir> { "orca_replay": 1, @@ -29,17 +28,17 @@ // ---- No objects ---- {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/empty_tool.gcode", "overwrite": true}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/empty_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/empty_cmd.gcode"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- A plate that is not sliced ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/unsliced_tool.gcode", "overwrite": true}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/unsliced_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/unsliced_cmd.gcode"}}, "optional": true}, {"tool": "list_plates"}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -48,20 +47,16 @@ {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/noplate_tool.gcode", "overwrite": true, "plates": 3}, "optional": true}, {"tool": "get_app_state"}, - // ---- No param: refused by run_action before the command runs ---- - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca"}, "optional": true}, - {"tool": "get_app_state"}, - // ---- A slice that ended with an error: spiral vase on a plate with two objects ---- {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "arrange", "args": {}}, {"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"spiral_mode": true}}}, {"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "error"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/error_tool.gcode", "overwrite": true}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/error_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/error_cmd.gcode"}}, "optional": true}, {"tool": "list_plates"}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -73,7 +68,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/ok_tool.gcode", "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_tool.gcode", "plates": 999}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/ok_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/ok_cmd.gcode"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_cmd.gcode", "plates": 999}, "optional": true}, {"tool": "list_plates"}, {"tool": "get_app_state"}, @@ -85,12 +80,12 @@ {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/twice_tool_2.gcode", "overwrite": true}, "await": false, "save_as": "tool_2", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/twice_cmd_1.gcode"}, "await": false, "save_as": "cmd_1", "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/twice_cmd_2.gcode"}, "await": false, "save_as": "cmd_2", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/twice_cmd_1.gcode"}}, "await": false, "save_as": "cmd_1", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/twice_cmd_2.gcode"}}, "await": false, "save_as": "cmd_2", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/twice_mix_1.gcode", "overwrite": true}, "await": false, "save_as": "mix_1", "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/twice_mix_2.gcode"}, "await": false, "save_as": "mix_2", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/twice_mix_2.gcode"}}, "await": false, "save_as": "mix_2", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "wait", "args": {"for": "idle"}}, @@ -105,14 +100,14 @@ {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_action", "args": {"id": "orca_command:slice_and_preview:orca"}}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/busy_tool.gcode", "overwrite": true}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/busy_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/busy_cmd.gcode"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_plates"}, {"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_action", "args": {"id": "orca_command:slice_all:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "param": "${out_dir}/busy2_cmd.gcode"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_gcode:orca", "args": {"path": "${out_dir}/busy2_cmd.gcode"}}, "optional": true}, {"tool": "export", "args": {"format": "gcode", "path": "${out_dir}/busy2_tool.gcode", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, {"tool": "wait", "args": {"for": "idle"}}, diff --git a/tools/mcp/tests/ops_export_model_3mf.json b/tools/mcp/tests/ops_export_model_3mf.json index 5d35a5e078..f56012d9ff 100644 --- a/tools/mcp/tests/ops_export_model_3mf.json +++ b/tools/mcp/tests/ops_export_model_3mf.json @@ -1,11 +1,10 @@ // Records what the model 3MF export does through its two routes, the export_3mf command run with run_action and -// a path param and the export tool's 3mf format: with no objects and with one. After each it reads whether the +// a path and the export tool's 3mf format: with no objects and with one. After each it reads whether the // file is there (an stl export to the same path with a plate the project lacks refuses with "exists" when it is, // with the plate when not; for the files written with no objects, once a cube is added), the project's name, // file and unsaved state, the recent projects and the undo snapshots taken since the last read -// (fixtures/ops_undo.py). Every call it records is optional. Run it into a fresh --out directory (a command's -// JSON path param can't carry a Windows ${out_dir}, so the commands write without overwrite and refuse the files -// of an earlier run): +// (fixtures/ops_undo.py). Every call it records is optional. Run it into a fresh --out directory (the commands +// write without overwrite, so they refuse the files of an earlier run): // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_model_3mf.json --out <new dir> { "orca_replay": 1, @@ -19,7 +18,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- No objects ---- - {"tool": "run_action", "args": {"id": "orca_command:export_3mf:orca", "param": "${out_dir}/empty_cmd.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_3mf:orca", "args": {"path": "${out_dir}/empty_cmd.3mf"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "export", "args": {"format": "3mf", "path": "${out_dir}/empty_tool.3mf", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, @@ -27,12 +26,12 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- With an object ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_cmd.3mf", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_tool.3mf", "plates": 999}, "optional": true}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_3mf:orca", "param": "${out_dir}/ok_cmd.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_3mf:orca", "args": {"path": "${out_dir}/ok_cmd.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_cmd.3mf", "plates": 999}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_export_sliced_3mf.json b/tools/mcp/tests/ops_export_sliced_3mf.json index 529c38f529..b9cb3a7432 100644 --- a/tools/mcp/tests/ops_export_sliced_3mf.json +++ b/tools/mcp/tests/ops_export_sliced_3mf.json @@ -1,11 +1,10 @@ // Records what the sliced-file export does through its routes, the export_sliced_file and export_all_sliced_file -// commands run with run_action and a path param, and the export tool's sliced_3mf format (the current plate, a +// commands run with run_action and a path, and the export tool's sliced_3mf format (the current plate, a // plate index, all): with no objects, on a plate not sliced, sliced, and with one plate of two sliced, from // either plate. After each it reads whether the file is there (an stl export to the same path with a plate the // project lacks refuses with "exists" when it is, with the plate when not), the plates, the project and the undo // snapshots taken since the last read (fixtures/ops_undo.py). Every call it records is optional. Run it into a -// fresh --out directory (a command's JSON path param can't carry a Windows ${out_dir}, so the commands write -// without overwrite and refuse the files of an earlier run): +// fresh --out directory (the commands write without overwrite, so they refuse the files of an earlier run): // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_sliced_3mf.json --out <new dir> { "orca_replay": 1, @@ -19,18 +18,18 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- No objects ---- - {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "param": "${out_dir}/empty_cmd.gcode.3mf"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "param": "${out_dir}/empty_all_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "args": {"path": "${out_dir}/empty_cmd.gcode.3mf"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "args": {"path": "${out_dir}/empty_all_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/empty_tool.gcode.3mf", "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/empty_all_tool.gcode.3mf", "plates": "all", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, // ---- A plate that is not sliced ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "param": "${out_dir}/ns_cmd.gcode.3mf"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "param": "${out_dir}/ns_all_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "args": {"path": "${out_dir}/ns_cmd.gcode.3mf"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "args": {"path": "${out_dir}/ns_all_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/ns_tool.gcode.3mf", "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/ns_all_tool.gcode.3mf", "plates": "all", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, @@ -45,9 +44,9 @@ {"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "param": "${out_dir}/ok_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "args": {"path": "${out_dir}/ok_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_cmd.gcode.3mf", "plates": 999}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "param": "${out_dir}/ok_all_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "args": {"path": "${out_dir}/ok_all_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_all_cmd.gcode.3mf", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/ok_tool.gcode.3mf", "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/ok_all_tool.gcode.3mf", "plates": "all", "overwrite": true}, "optional": true}, @@ -57,27 +56,27 @@ // ---- One plate of two sliced: plate 0 sliced, plate 1 not ---- {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "slice", "args": {"plates": 0}, "expect": {"/plates/0/outcome": {"eq": "ok"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_plates", "expect": {"/total": {"eq": 2}, "/items/0/sliced": {"eq": true}, "/items/1/sliced": {"eq": false}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "param": "${out_dir}/half_p0_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, + {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "args": {"path": "${out_dir}/half_p0_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/half_p0_cmd.gcode.3mf", "plates": 999}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "param": "${out_dir}/half_all_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "args": {"path": "${out_dir}/half_all_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/half_all_cmd.gcode.3mf", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/half_p0_tool.gcode.3mf", "plates": 0, "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/half_p1_tool.gcode.3mf", "plates": 1, "overwrite": true}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/half_all_tool.gcode.3mf", "plates": "all", "overwrite": true}, "optional": true}, {"tool": "list_plates"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "param": "${out_dir}/half_p1_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, + {"tool": "run_action", "args": {"id": "orca_command:export_sliced_file:orca", "args": {"path": "${out_dir}/half_p1_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/half_p1_cmd.gcode.3mf", "plates": 999}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "param": "${out_dir}/half_all_from1_cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_all_sliced_file:orca", "args": {"path": "${out_dir}/half_all_from1_cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/half_all_from1_cmd.gcode.3mf", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "sliced_3mf", "path": "${out_dir}/half_cur1_tool.gcode.3mf", "overwrite": true}, "optional": true}, {"tool": "list_plates"}, diff --git a/tools/mcp/tests/ops_export_stl.json b/tools/mcp/tests/ops_export_stl.json index e14f65fc9a..1b2e212419 100644 --- a/tools/mcp/tests/ops_export_stl.json +++ b/tools/mcp/tests/ops_export_stl.json @@ -1,11 +1,10 @@ // Records what the STL export does through its two routes, the export_stl command run with run_action and a path -// param and the export tool's stl format: with no objects and with two. After each it reads whether the file is +// and the export tool's stl format: with no objects and with two. After each it reads whether the file is // there (an stl export to the same path with a plate the project lacks refuses with "exists" when it is, with // the plate when not; for the files written with no objects, once a cube is added), the project and the undo // snapshots taken since the last read (fixtures/ops_undo.py), and last opens each file into an empty project to -// show what it holds. Every call it records is optional. Run it into a fresh --out directory (a command's JSON -// path param can't carry a Windows ${out_dir}, so the commands write without overwrite and refuse the files of -// an earlier run): +// show what it holds. Every call it records is optional. Run it into a fresh --out directory (the commands write +// without overwrite, so they refuse the files of an earlier run): // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_export_stl.json --out <new dir> { "orca_replay": 1, @@ -19,22 +18,22 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- No objects ---- - {"tool": "run_action", "args": {"id": "orca_command:export_stl:orca", "param": "${out_dir}/empty_cmd.stl"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_stl:orca", "args": {"path": "${out_dir}/empty_cmd.stl"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_tool.stl", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- With two objects ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "arrange", "args": {}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_cmd.stl", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_tool.stl", "plates": 999}, "optional": true}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_stl:orca", "param": "${out_dir}/ok_cmd.stl"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:export_stl:orca", "args": {"path": "${out_dir}/ok_cmd.stl"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/ok_cmd.stl", "plates": 999}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_import_models.json b/tools/mcp/tests/ops_import_models.json index ead074642d..2fdf57b40e 100644 --- a/tools/mcp/tests/ops_import_models.json +++ b/tools/mcp/tests/ops_import_models.json @@ -1,12 +1,12 @@ // Records what a model import does through its two routes, the import_file command run with run_action and a -// path param and the open_files tool (models, and a .3mf with as "geometry"), each of which adds the files' +// path and the open_files tool (models, and a .3mf with as "geometry"), each of which adds the files' // geometry as one undo step and loads no settings: an STL into an empty project and into one with objects, a // project .3mf saved here from a cube with wall_loops 5 into a project with a cylinder and top_shell_layers 7, // and imports that load nothing (a path that does not exist, a PNG, a preset .json, each of the last two opening // a warning and an error, which it answers). After each it reads the objects, the project's name and file, the // selected presets and their unsaved keys, the recent projects (search_actions) and the dialogs, then the undo // snapshots taken since the last read (fixtures/ops_undo.py), and runs undo once to show what that step takes -// back. Last, File > Import (import_file without a param) with a rule that answers its picker with a path: the +// back. Last, File > Import (import_file without arguments) with a rule that answers its picker with a path: the // picker is multi-select, which takes no path, so it is cancelled. Every call it records is optional. Run it // with // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_import_models.json --out <dir> @@ -25,7 +25,7 @@ {"tool": "set_view", "args": {"tab": "prepare"}}, // ---- The source project: a cube with wall_loops 5, saved ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "set_settings", "args": {"values": {"wall_loops": 5}}}, {"tool": "save_project", "args": {"path": "${out_dir}/src_project.3mf", "overwrite": true}}, {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, @@ -34,7 +34,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- An STL into an empty project: the command ---- - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${vars.stl}"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${vars.stl}"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "list_objects"}, {"tool": "search_actions", "args": {"group": "Recent Projects"}}, @@ -55,12 +55,12 @@ // ---- An STL into a project with a cylinder and an unsaved process change: the command ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${vars.stl}"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${vars.stl}"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "list_objects"}, {"tool": "get_settings", "args": {"scope": "process", "compare": ":saved"}}, @@ -69,7 +69,7 @@ {"tool": "list_objects"}, // ---- the tool ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -84,13 +84,13 @@ // ---- The project .3mf into a project with a cylinder and top_shell_layers 7: the command ---- // A dialog it opens is listed by get_app_state and cancelled. {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "search_actions", "args": {"group": "Recent Projects"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${out_dir}/src_project.3mf"}, "await": false, "save_as": "cmd3mf", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${out_dir}/src_project.3mf"}}, "await": false, "save_as": "cmd3mf", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "cancel"}, "optional": true}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.cmd3mf}"}, "optional": true}, @@ -108,7 +108,7 @@ {"tool": "get_settings", "args": {"keys": ["wall_loops", "top_shell_layers"]}}, // ---- the tool, as geometry ---- {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "set_settings", "args": {"values": {"top_shell_layers": 7}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -130,12 +130,12 @@ // ---- Imports that load nothing, on a project with a cube ---- {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${out_dir}/missing.stl"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${out_dir}/missing.stl"}}, "optional": true}, {"tool": "open_files", "args": {"paths": ["${out_dir}/missing.stl"]}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${vars.png}"}, "await": false, "save_as": "cmdpng", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${vars.png}"}}, "await": false, "save_as": "cmdpng", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, @@ -145,7 +145,7 @@ {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.toolpng}"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "param": "${vars.preset_json}"}, "await": false, "save_as": "cmdjson", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_file:orca", "args": {"path": "${vars.preset_json}"}}, "await": false, "save_as": "cmdjson", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, diff --git a/tools/mcp/tests/ops_import_presets.json b/tools/mcp/tests/ops_import_presets.json index 484b15f085..ad9e780d15 100644 --- a/tools/mcp/tests/ops_import_presets.json +++ b/tools/mcp/tests/ops_import_presets.json @@ -1,10 +1,8 @@ -// Records what the import_configs command (run_action with a path param) does: one preset file +// Records what the import_configs command (run_action with a path) does: one preset file // (fixtures/mcp_import_pla.json) imported while absent, kept while it exists, and replaced with on_conflict // overwrite; a filament exported first with the Export Preset Bundle dialog, as presets.json does, kept, // imported once deleted, and replaced; and the refusals (a path that does not exist, a file that is no preset, a -// .json that holds no preset, the param's overwrite). A param with on_conflict is JSON, which can't hold a -// Windows ${replay_dir} or ${out_dir}, so those calls go through run_script, which builds the param and calls -// run_action with it (orca.host.tools.call: the same tool, its result or its error). After each it reads the +// .json that holds no preset, an overwrite argument, an on_conflict it does not take). After each it reads the // presets the import touched, the selected presets and the undo snapshots taken since the last read // (fixtures/ops_undo.py). It deletes the presets it made at the end, so it reruns on the same datadir. Every // call it records is optional. Run it with @@ -27,12 +25,12 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- One preset file: imported, kept, replaced ---- - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${vars.pla}"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.pla}"}}, "optional": true}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Import PLA"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${vars.pla}"}, "optional": true}, - {"tool": "run_script", "args": {"code": "import json, orca\ntry:\n result = orca.host.tools.call('run_action', {'id': 'orca_command:import_configs:orca', 'param': json.dumps({'path': args['path'], 'on_conflict': 'overwrite'})})\nexcept Exception as e:\n result = {'error': str(e)}", "args": {"path": "${vars.pla}"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.pla}"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.pla}", "on_conflict": "overwrite"}}, "optional": true}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Import PLA"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -41,7 +39,7 @@ {"tool": "run_action", "args": {"id": "orca_command:toggle_developer_mode:orca"}}, {"tool": "save_preset", "args": {"type": "filament", "name": "MCP Ops Export PLA", "detach": true, "overwrite": true}}, {"tool": "run_action", "args": {"id": "orca_command:toggle_developer_mode:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_config:orca", "param": "${out_dir}"}, "await": false, "save_as": "export"}, + {"tool": "run_action", "args": {"id": "orca_command:export_config:orca", "args": {"path": "${out_dir}"}}, "await": false, "save_as": "export"}, {"tool": "click", "args": {"target": {"label": "Filament presets(.zip)", "within": "Export Preset Bundle"}}}, {"tool": "set_widget_value", "args": {"target": {"name": "MCP Ops Export PLA", "within": "Export Preset Bundle"}, "value": true}}, {"tool": "answer_dialog", "args": {"dialog": {"title": "Export Preset Bundle"}, "button": "ok"}, "await": false, "save_as": "export_ok"}, @@ -51,27 +49,27 @@ {"tool": "wait", "args": {"for": "job", "job": "${jobs.export}"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // kept while it exists, imported once deleted, replaced with on_conflict overwrite - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${vars.zip}"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.zip}"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1}}, {"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Ops Export PLA"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${vars.zip}"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.zip}"}}, "optional": true}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Ops Export PLA"}}, {"tool": "get_app_state"}, - {"tool": "run_script", "args": {"code": "import json, orca\ntry:\n result = orca.host.tools.call('run_action', {'id': 'orca_command:import_configs:orca', 'param': json.dumps({'path': args['path'], 'on_conflict': 'overwrite'})})\nexcept Exception as e:\n result = {'error': str(e)}", "args": {"path": "${vars.zip}"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.zip}", "on_conflict": "overwrite"}}, "optional": true}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Ops Export PLA"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - // ---- Refusals: a missing path, a file that is no preset, a .json with no preset, the param's overwrite ---- - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${out_dir}/missing.json"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${replay_dir}/fixtures/heightmap.png"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${replay_dir}/plates.json"}, "await": false, "save_as": "nopreset", "optional": true}, + // ---- Refusals: a missing path, a file that is no preset, a .json with no preset, an overwrite, an unknown on_conflict ---- + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${out_dir}/missing.json"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${replay_dir}/fixtures/heightmap.png"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${replay_dir}/plates.json"}}, "await": false, "save_as": "nopreset", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "answer_dialog", "args": {"button": "ok"}, "optional": true}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.nopreset}"}, "optional": true}, - {"tool": "run_script", "args": {"code": "import json, orca\ntry:\n result = orca.host.tools.call('run_action', {'id': 'orca_command:import_configs:orca', 'param': json.dumps({'path': args['path'], 'overwrite': True})})\nexcept Exception as e:\n result = {'error': str(e)}", "args": {"path": "${vars.pla}"}}, "optional": true}, - {"tool": "run_script", "args": {"code": "import json, orca\ntry:\n result = orca.host.tools.call('run_action', {'id': 'orca_command:import_configs:orca', 'param': json.dumps({'path': args['path'], 'on_conflict': 'merge'})})\nexcept Exception as e:\n result = {'error': str(e)}", "args": {"path": "${vars.pla}"}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.pla}", "overwrite": true}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${vars.pla}", "on_conflict": "merge"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_new_project.json b/tools/mcp/tests/ops_new_project.json index ee46db26c9..31ab74467f 100644 --- a/tools/mcp/tests/ops_new_project.json +++ b/tools/mcp/tests/ops_new_project.json @@ -1,7 +1,7 @@ -// Records what a new project does through its two routes, the new_project command run with run_action and the -// new_project tool: on a clean project, with unsaved project changes (a cube; the tool with and without -// discard_changes) and with unsaved preset changes (top_shell_layers 7; the command's question answered Discard, -// then Transfer when it offers that, and the tool's preset_changes keep and discard). Each call starts from the +// Records what a new project does through its two forms, the person's (the new_project tile run with run_action) +// and the silent one (new_project called with arguments): on a clean project, with unsaved project changes (a +// cube; silent: true, then discard_changes) and with unsaved preset changes (top_shell_layers 7; the tile's +// question answered Discard, then Transfer when it offers that, and preset_changes keep and discard). Each call starts from the // Home tab, so the reads show the tab it leaves. The command runs with "await": false; get_app_state lists its // question, which the replay answers by its title. After each it reads the objects, the project, the presets' // unsaved keys and the undo snapshots taken since the last read (fixtures/ops_undo.py). Plugins get the @@ -28,12 +28,12 @@ {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "set_view", "args": {"tab": "home"}}, - {"tool": "new_project", "args": {}, "optional": true}, + {"tool": "new_project", "args": {"silent": true}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Unsaved project changes: the command asks ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "set_view", "args": {"tab": "home"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, @@ -48,11 +48,11 @@ {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- the tool, without discard_changes, then with it ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "set_view", "args": {"tab": "home"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "new_project", "args": {}, "optional": true}, + {"tool": "new_project", "args": {"silent": true}, "optional": true}, {"tool": "get_app_state"}, {"tool": "new_project", "args": {"discard_changes": true}, "optional": true}, {"tool": "get_app_state"}, @@ -95,7 +95,7 @@ {"tool": "set_view", "args": {"tab": "home"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "new_project", "args": {}, "optional": true}, + {"tool": "new_project", "args": {"silent": true}, "optional": true}, {"tool": "get_app_state"}, {"tool": "new_project", "args": {"discard_changes": true}, "optional": true}, {"tool": "get_app_state"}, diff --git a/tools/mcp/tests/ops_open_project.json b/tools/mcp/tests/ops_open_project.json index e0c658c946..19ac92adcc 100644 --- a/tools/mcp/tests/ops_open_project.json +++ b/tools/mcp/tests/ops_open_project.json @@ -1,5 +1,5 @@ // Records what opening a project does through its two routes, the load_project command run with run_action and a -// path param, and the open_files tool given a .3mf (as auto): on a clean project, on one with unsaved changes +// path, and the open_files tool given a .3mf (as auto): on a clean project, on one with unsaved changes // (the tool with and without discard_changes) and with unsaved preset changes (top_shell_layers 7). The project // it opens is saved here first: a cube with wall_loops 5. Each call that may ask runs with "await": false; // get_app_state lists the question, which the replay answers, by its title, as a person who does not save: No to @@ -17,7 +17,7 @@ {"tool": "set_view", "args": {"tab": "prepare"}}, // ---- The project to open: a cube with wall_loops 5 ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "set_settings", "args": {"values": {"wall_loops": 5}}}, {"tool": "save_project", "args": {"path": "${out_dir}/open_src.3mf", "overwrite": true}}, @@ -27,7 +27,7 @@ {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "param": "${out_dir}/open_src.3mf"}, "await": false, "save_as": "clean_cmd", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "args": {"path": "${out_dir}/open_src.3mf"}}, "await": false, "save_as": "clean_cmd", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true}, {"tool": "answer_dialog", "args": {"dialog": {"title": "unsaved changes"}, "button": "Discard"}, "optional": true}, @@ -58,11 +58,11 @@ // ---- Unsaved project changes (a cylinder), presets clean: the command asks ---- {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "param": "${out_dir}/open_src.3mf"}, "await": false, "save_as": "dirty_cmd", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "args": {"path": "${out_dir}/open_src.3mf"}}, "await": false, "save_as": "dirty_cmd", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true}, {"tool": "get_app_state"}, @@ -75,7 +75,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- the tool, without discard_changes, then with it ---- {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "open_files", "args": {"paths": ["${out_dir}/open_src.3mf"]}, "optional": true}, @@ -99,7 +99,7 @@ {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "param": "${out_dir}/open_src.3mf"}, "await": false, "save_as": "presets_cmd", "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:load_project:orca", "args": {"path": "${out_dir}/open_src.3mf"}}, "await": false, "save_as": "presets_cmd", "optional": true}, {"tool": "get_app_state"}, {"tool": "answer_dialog", "args": {"dialog": {"title": "- Save"}, "button": "no"}, "optional": true}, {"tool": "get_app_state"}, diff --git a/tools/mcp/tests/ops_save_project_as.json b/tools/mcp/tests/ops_save_project_as.json index a7b6c6fcac..e45053c06a 100644 --- a/tools/mcp/tests/ops_save_project_as.json +++ b/tools/mcp/tests/ops_save_project_as.json @@ -1,11 +1,11 @@ // Records what saving the project under a name does through its two routes, the save_project_as command run with -// run_action and a path param and the save_project tool: a .3mf path, a .gcode.3mf path, a folder that does not +// run_action and a path and the save_project tool: a .3mf path, a .gcode.3mf path, a folder that does not // exist, a file that exists (the tool without overwrite), and a project with no objects. After each it reads the // project's name, file and unsaved state, the recent projects and the undo snapshots taken since the last read // (fixtures/ops_undo.py), and whether the file is there: an stl export to the same path with a plate the project // lacks refuses with "exists" when it is, with the plate when not. Every call it records is optional. Run it -// into a fresh --out directory (a command's JSON path param can't carry a Windows ${out_dir}, so the commands -// write without overwrite and refuse the files of an earlier run): +// into a fresh --out directory (the commands write without overwrite, so they refuse the files of an earlier +// run): // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_save_project_as.json --out <new dir> { "orca_replay": 1, @@ -19,7 +19,7 @@ // ---- No objects (the probes come once there is one) ---- {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "param": "${out_dir}/empty_cmd.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "args": {"path": "${out_dir}/empty_cmd.3mf"}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "save_project", "args": {"path": "${out_dir}/empty_tool.3mf", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, @@ -27,13 +27,13 @@ // ---- A .3mf path ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_cmd.3mf", "plates": 999}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/empty_tool.3mf", "plates": 999}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "param": "${out_dir}/cmd.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "args": {"path": "${out_dir}/cmd.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/cmd.3mf", "plates": 999}, "optional": true}, {"tool": "get_app_state"}, {"tool": "search_actions", "args": {"group": "Recent Projects"}}, @@ -47,7 +47,7 @@ // ---- A .gcode.3mf path ---- {"tool": "transform", "args": {"object": 0, "translate": [5, 0, 0]}}, - {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "param": "${out_dir}/cmd.gcode.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "args": {"path": "${out_dir}/cmd.gcode.3mf"}}, "optional": true}, {"tool": "export", "args": {"format": "stl", "path": "${out_dir}/cmd.gcode.3mf", "plates": 999}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -56,12 +56,12 @@ {"tool": "get_app_state"}, // ---- A folder that does not exist ---- - {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "param": "${out_dir}/missing/cmd.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "args": {"path": "${out_dir}/missing/cmd.3mf"}}, "optional": true}, {"tool": "save_project", "args": {"path": "${out_dir}/missing/tool.3mf", "overwrite": true}, "optional": true}, {"tool": "get_app_state"}, // ---- A file that exists: the command to the tool's file, the tool without overwrite to the command's ---- - {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "param": "${out_dir}/tool.3mf"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:save_project_as:orca", "args": {"path": "${out_dir}/tool.3mf"}}, "optional": true}, {"tool": "save_project", "args": {"path": "${out_dir}/cmd.3mf"}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_select_plate.json b/tools/mcp/tests/ops_select_plate.json index def9193491..8b0bfbdc40 100644 --- a/tools/mcp/tests/ops_select_plate.json +++ b/tools/mcp/tests/ops_select_plate.json @@ -1,9 +1,9 @@ -// Records how a plate is selected: the plate_goto command run with run_action and a param in range, past the -// last plate and negative (refused), not a number and empty (plate 0), and each tool that takes a plate index -// given one the project lacks (slice, export, arrange, set_settings and get_settings plate scope, list_objects, -// transform) and given one it has. After each it reads the current plate (get_app_state, list_plates) and the -// undo snapshots taken since the last read (fixtures/ops_undo.py). The project has three plates with a cube on -// the first. Every call it records is optional. Run it with +// Records how a plate is selected: the plate_goto command run with run_action and a plate in range, past the +// last plate and negative (refused), not a number and not a whole number (refused), and none (plate 0), and +// each tool that takes a plate index given one the project lacks (slice, export, arrange, set_settings and +// get_settings plate scope, list_objects, transform) and given one it has. After each it reads the current +// plate (get_app_state, list_plates) and the undo snapshots taken since the last read (fixtures/ops_undo.py). +// The project has three plates with a cube on the first. Every call it records is optional. Run it with // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_select_plate.json --out <dir> { "orca_replay": 1, @@ -13,7 +13,7 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, {"tool": "wait", "args": {"for": "idle"}}, @@ -21,34 +21,34 @@ {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - // ---- plate_goto: in range, past the last, negative, not a number, empty ---- - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}, "optional": true}, + // ---- plate_goto: in range, past the last, negative, not a number, not a whole number, none ---- + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 2}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 3}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "7"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 7}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "-3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": -3}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "2"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "abc"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 2}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": "abc"}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "2"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1.7"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 2}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1.7}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 2}}, "optional": true}, {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca"}, "optional": true}, {"tool": "get_app_state"}, {"tool": "list_plates"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Tools given a plate the project lacks, from plate 1 ---- - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "slice", "args": {"plates": 5}, "optional": true}, diff --git a/tools/mcp/tests/ops_send_gcode_to_host.json b/tools/mcp/tests/ops_send_gcode_to_host.json index 85b39ab196..f6494e43bd 100644 --- a/tools/mcp/tests/ops_send_gcode_to_host.json +++ b/tools/mcp/tests/ops_send_gcode_to_host.json @@ -21,7 +21,7 @@ // ---- A Bambu network printer: no objects, not sliced, sliced ---- {"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_action", "args": {"id": "orca_command:send_gcode:orca"}, "optional": true}, {"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}}, diff --git a/tools/mcp/tests/ops_set_instance_count.json b/tools/mcp/tests/ops_set_instance_count.json index 38341a52fa..fbd68925c3 100644 --- a/tools/mcp/tests/ops_set_instance_count.json +++ b/tools/mcp/tests/ops_set_instance_count.json @@ -1,9 +1,9 @@ -// Records what the obj_set_instances command (run_action with a count param) does: nothing selected, one object, -// two objects, one instance of an object, a part, counts of 1, 0, negative, past 1000, a fraction and a word, an -// object with an instance that is not printable, a cut object, and no param (it opens its dialog, which the -// replay cancels). After each it reads the objects' instances and the undo snapshots taken since the last read -// (fixtures/ops_undo.py), and once runs undo to show the change is one step. Every call it records is optional. -// Run it with +// Records what the obj_set_instances command (run_action with a count) does: nothing selected, one object, +// two objects, one instance of an object, a part, counts of 1, 2 written as text, 0, negative, past 1000, a +// fraction and a word, an object with an instance that is not printable, a cut object, and no arguments (it +// opens its dialog, which the replay cancels). After each it reads the objects' instances and the undo +// snapshots taken since the last read (fixtures/ops_undo.py), and once runs undo to show the change is one +// step. Every call it records is optional. Run it with // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_set_instance_count.json --out <dir> { "orca_replay": 1, @@ -14,78 +14,78 @@ {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, {"tool": "set_window", "args": {"size": [1600, 1000]}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 1}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Nothing selected ---- {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 3}}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- One object: 3, undone, then 1 ---- {"tool": "select_objects", "args": {"objects": [0]}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 3}}, "optional": true}, {"tool": "list_objects"}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "run_action", "args": {"id": "orca_command:undo:orca"}}, {"tool": "list_objects"}, {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "3"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": " 2 "}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 3}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": " 2 "}}, "optional": true}, {"tool": "list_objects"}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "1"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 1}}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Counts it refuses ---- {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "0"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "-2"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "1001"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2.5"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "three"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 0}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": -2}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 1001}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2.5}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": "three"}}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Two objects selected, one instance of an object, a part ---- {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [20, 10]}}}, {"tool": "arrange", "args": {}}, {"tool": "select_objects", "args": {"objects": [0, 1]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2}}, "optional": true}, {"tool": "list_objects"}, {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2}}, "optional": true}, {"tool": "select_objects", "args": {"instances": [[0, 1]]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "4"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 4}}, "optional": true}, {"tool": "list_objects"}, {"tool": "add_part", "args": {"object": 1, "type": "modifier", "shape": "cube", "size": [5, 5, 5]}}, {"tool": "select_objects", "args": {"parts": [[1, 1]]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2}}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- An instance that is not printable (the cylinder back to one instance, made not printable as the // object list's Printable column does) ---- {"tool": "select_objects", "args": {"objects": [1]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 1}}}, {"tool": "click", "args": {"target": {"row": "Plate 1>Cylinder", "column": "Printable"}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/1/instances/0/printable": {"eq": false}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "select_objects", "args": {"objects": [1]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2}}, "optional": true}, {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca"}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, {"tool": "click", "args": {"target": {"row": "Plate 1>Cylinder", "column": "Printable"}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/1/instances/0/printable": {"eq": true}}}, - // ---- No param: its dialog opens, and is cancelled ---- + // ---- No arguments: its dialog opens, and is cancelled ---- {"tool": "select_objects", "args": {"objects": [1]}}, {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca"}, "await": false, "save_as": "dialog", "optional": true}, {"tool": "get_app_state"}, @@ -97,7 +97,7 @@ // ---- A cut object: a cube cut at 10 mm with a connector, which keeps the halves linked ---- {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_view", "args": {"tab": "prepare", "camera": "top"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"objects": [0]}}, {"tool": "click", "args": {"target": {"gizmo": "Cut"}}, "expect": {"/active": {"eq": true}}}, {"tool": "set_widget_value", "args": {"target": {"imgui_name": "move_Z"}, "value": 10}}, @@ -109,7 +109,7 @@ {"tool": "list_objects", "expect": {"/total": {"eq": 2}, "/plates/0/objects/0/parts/1": {"exists": true}}}, {"tool": "select_objects", "args": {"objects": [0]}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "2"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 2}}, "optional": true}, {"tool": "list_objects"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_set_plate_locked.json b/tools/mcp/tests/ops_set_plate_locked.json index 79cace6643..1619b76765 100644 --- a/tools/mcp/tests/ops_set_plate_locked.json +++ b/tools/mcp/tests/ops_set_plate_locked.json @@ -14,9 +14,9 @@ {"tool": "new_project", "args": {"discard_changes": true, "preset_changes": "discard"}}, {"tool": "set_window", "args": {"size": [1600, 1000]}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_plates", "expect": {"/total": {"eq": 2}, "/items/0/current": {"eq": true}}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -54,13 +54,13 @@ {"tool": "set_settings", "args": {"scope": "plate", "plate": 1, "values": {"locked": true}}, "optional": true}, {"tool": "list_plates"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "click", "args": {"target": {"plate_icon": "lock", "plate": 1}}, "optional": true}, {"tool": "list_plates"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Undo after each route's lock ---- - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}, "optional": true}, {"tool": "list_plates"}, {"tool": "run_action", "args": {"id": "orca_command:undo:orca"}}, diff --git a/tools/mcp/tests/ops_show_layer_range.json b/tools/mcp/tests/ops_show_layer_range.json index 30fd05ec17..f4c6893e33 100644 --- a/tools/mcp/tests/ops_show_layer_range.json +++ b/tools/mcp/tests/ops_show_layer_range.json @@ -1,10 +1,11 @@ -// Records how the Preview's layers are set through its two routes, the go_to_layer command run with run_action -// and its percent param (0, 50, 100, past 100, negative, not a number, none) and set_view's layer, layer_range -// and layer_z (in range, past the top, a layer_z above it): on plates the Preview has no layers for (one with no -// objects, one whose slice fails validation: spiral vase with two objects), then on a sliced one. A plate that -// could slice is left out of the first part, since showing the Preview slices it while the call runs, so what -// the call finds depends on timing. After each it reads get_app_state's tab and preview, and at the end of each -// part the undo snapshots taken (fixtures/ops_undo.py). Every call it records is optional. Run it with +// Records how the Preview's layers are set through its two routes, the go_to_layer command run with +// run_action and its percent (0, 50, 100, a fraction, and refused: past 100, negative, not a number, none) +// and set_view's layer, layer_range and layer_z (in range, past the top, a layer_z above it): on plates the +// Preview has no layers for (one with no objects, one whose slice fails validation: spiral vase with two +// objects), then on a sliced one. A plate that could slice is left out of the first part, since showing the +// Preview slices it while the call runs, so what the call finds depends on timing. After each it reads +// get_app_state's tab and preview, and at the end of each part the undo snapshots taken +// (fixtures/ops_undo.py). Every call it records is optional. Run it with // tools/mcp/orca_mcp.py run-replay tools/mcp/tests/ops_show_layer_range.json --out <dir> { "orca_replay": 1, @@ -17,7 +18,7 @@ {"tool": "set_view", "args": {"tab": "prepare"}}, // The Preview's sliders keep the last slice's layers after a new project, so one known slice comes first: // a 20 mm cube, 100 layers. - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "slice", "expect": {"/plates/0/layers": {"eq": 100}}}, {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_view", "args": {"tab": "prepare"}}, @@ -25,7 +26,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- No objects ---- - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "50"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 50}}, "optional": true}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "set_view", "args": {"tab": "prepare"}}, @@ -37,14 +38,14 @@ // ---- A plate whose slice fails validation ---- {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "arrange", "args": {}}, {"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"spiral_mode": true}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "50"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 50}}, "optional": true}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "list_plates"}, @@ -59,36 +60,36 @@ // ---- A sliced plate: the command ---- {"tool": "new_project", "args": {"discard_changes": true}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "0"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 0}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "50"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 50}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "100"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 100}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "25.5"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 25.5}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "150"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 150}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "-5"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": -5}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "abc"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": "abc"}}, "optional": true}, {"tool": "get_app_state"}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "10"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 10}}, "optional": true}, {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca"}, "optional": true}, {"tool": "get_app_state"}, // the command after set_view showed a range: does it keep the range's bottom? {"tool": "set_view", "args": {"layer_range": [20, 60]}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "80"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 80}}, "optional": true}, {"tool": "get_app_state"}, // from the Prepare tab {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "param": "30"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:go_to_layer:orca", "args": {"percent": 30}}, "optional": true}, {"tool": "get_app_state"}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, diff --git a/tools/mcp/tests/ops_start_arrange.json b/tools/mcp/tests/ops_start_arrange.json index 03b43c4ace..a8e3d1ecf0 100644 --- a/tools/mcp/tests/ops_start_arrange.json +++ b/tools/mcp/tests/ops_start_arrange.json @@ -24,9 +24,9 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- Two cubes on one spot: the command, undone, then the tool ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_objects", "expect": {"/total": {"eq": 2}, "/plates/0/objects/0/instances/0/offset/0": {"eq": 128.0}, "/plates/0/objects/1/instances/0/offset/0": {"eq": 128.0}}}, diff --git a/tools/mcp/tests/ops_start_slice.json b/tools/mcp/tests/ops_start_slice.json index 4fc7514c1d..aec65826ef 100644 --- a/tools/mcp/tests/ops_start_slice.json +++ b/tools/mcp/tests/ops_start_slice.json @@ -35,7 +35,7 @@ {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, // ---- One plate ---- - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "set_view", "args": {"tab": "prepare"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_script", "args": {"filename": "${vars.undo}", "code": "import ops_undo\nresult = ops_undo.taken()"}}, @@ -56,10 +56,10 @@ // ---- Two plates, a cube on each ---- {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "set_view", "args": {"tab": "prepare"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "list_plates", "expect": {"/total": {"eq": 2}, "/items/1/objects": {"eq": 1}}}, @@ -86,7 +86,7 @@ {"tool": "list_plates"}, {"tool": "transform", "args": {"object": 1, "translate": [5, 0, 0]}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "slice", "args": {"plates": 1}, "optional": true}, {"tool": "get_app_state"}, @@ -95,9 +95,9 @@ // ---- Objects that fail validation: spiral vase on a plate with two objects ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "arrange", "args": {}}, {"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"spiral_mode": true}}}, {"tool": "set_view", "args": {"tab": "prepare"}}, diff --git a/tools/mcp/tests/plates.json b/tools/mcp/tests/plates.json index 0d39893e35..8907dce7b5 100644 --- a/tools/mcp/tests/plates.json +++ b/tools/mcp/tests/plates.json @@ -31,15 +31,15 @@ "expect": {"/level": {"eq": "success"}, "/message": {"eq": "Added filament slot 2."}}}, {"tool": "run_action", "args": {"id": "orca_command:filament_add:orca"}, "expect": {"/message": {"eq": "Added filament slot 3."}}}, // A slot past the last is refused; slot 2 by number. - {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "param": "4"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "param": "2"}, "expect": {"/message": {"eq": "Deleted filament slot 2."}}}, + {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "args": {"slot": 4}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "args": {"slot": 2}}, "expect": {"/message": {"eq": "Deleted filament slot 2."}}}, {"tool": "get_settings", "args": {"scope": "project", "keys": ["filament_is_mixed"]}, "expect": {"/items/0/value": {"eq": "0,0"}}}, // ---- A cube on each of two plates ---- {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "select_objects", "args": {"none": true}}, {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca"}}, {"tool": "wait", "args": {"for": "idle"}}, @@ -51,7 +51,7 @@ "/items/0/wipe_tower": {"exists": true}}}, // ---- Plate 1's own plate type and print sequence; plate 0 keeps the global ones ---- - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "set_settings", "args": {"scope": "plate", "plate": 1, "values": {"curr_bed_type": "Textured PEI Plate", "print_sequence": "by object"}}, "expect": {"/plate": {"eq": 1}, "/applied/curr_bed_type": {"eq": "Textured PEI Plate"}, "/applied/print_sequence": {"eq": "by object"}, "/changed/curr_bed_type": {"eq": "Textured PEI Plate"}}}, @@ -122,7 +122,7 @@ {"tool": "answer_dialog", "args": {"button": "OK"}}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.mix}"}}, {"tool": "get_settings", "args": {"scope": "project", "keys": ["filament_is_mixed"]}, "expect": {"/items/0/value": {"eq": "0,0,1"}}}, - {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "param": "3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:filament_delete:orca", "args": {"slot": 3}}, "optional": true}, {"tool": "set_settings", "args": {"scope": "plate", "plate": 0, "values": {"first_layer_print_sequence": [2, 1]}}, "optional": true}, {"tool": "list_plates", "expect": {"/items/0/first_layer_print_sequence": {"eq": null}}}, {"tool": "run_action", "args": {"id": "orca_command:filament_add:orca"}, "expect": {"/message": {"eq": "Added filament slot 3."}}}, diff --git a/tools/mcp/tests/presets.json b/tools/mcp/tests/presets.json index 9b26563d46..9fe37db1ae 100644 --- a/tools/mcp/tests/presets.json +++ b/tools/mcp/tests/presets.json @@ -329,7 +329,7 @@ {"tool": "save_preset", "args": {"type": "filament", "name": "MCP Export PLA", "detach": true, "overwrite": true}, "expect": {"/inherits": {"exists": false}}}, {"tool": "run_action", "args": {"id": "orca_command:toggle_developer_mode:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:export_config:orca", "param": "${out_dir}"}, "await": false, "save_as": "export"}, + {"tool": "run_action", "args": {"id": "orca_command:export_config:orca", "args": {"path": "${out_dir}"}}, "await": false, "save_as": "export"}, {"tool": "click", "args": {"target": {"label": "Filament presets(.zip)", "within": "Export Preset Bundle"}}}, {"tool": "set_widget_value", "args": {"target": {"name": "MCP Export PLA", "within": "Export Preset Bundle"}, "value": true}}, {"tool": "answer_dialog", "args": {"dialog": {"title": "Export Preset Bundle"}, "button": "ok"}, "await": false, "save_as": "export_ok"}, @@ -338,16 +338,16 @@ {"tool": "wait", "args": {"for": "job", "job": "${jobs.export_ok}"}}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.export}"}, "expect": {"/level": {"eq": "success"}}}, // The preset exists: the import keeps it by default, and the message names it. - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${out_dir}/Filament presets.zip"}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${out_dir}/Filament presets.zip"}}, "expect": {"/message": {"eq": "Kept the existing presets: MCP Export PLA."}}}, {"tool": "select_preset", "args": {"type": "filament", "name": "Bambu PLA Basic", "filament_slot": 1}}, {"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Export PLA"}}, - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${out_dir}/Filament presets.zip"}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${out_dir}/Filament presets.zip"}}, "expect": {"/message": {"eq": "Imported presets: MCP Export PLA."}}}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Export PLA"}, "expect": {"/total": {"eq": 1}, "/items/0/user": {"eq": true}}}, {"tool": "delete_preset", "args": {"type": "filament", "name": "MCP Export PLA"}}, // One preset file, inheriting a system filament. - {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "param": "${replay_dir}/fixtures/mcp_import_pla.json"}, + {"tool": "run_action", "args": {"id": "orca_command:import_configs:orca", "args": {"path": "${replay_dir}/fixtures/mcp_import_pla.json"}}, "expect": {"/message": {"eq": "Imported presets: MCP Import PLA."}}}, {"tool": "list_presets", "args": {"type": "filament", "query": "MCP Import PLA"}, "expect": {"/items/0/inherits": {"eq": "Bambu PLA Basic @BBL X1C"}}}, {"tool": "get_settings", "args": {"scope": "filament", "preset": "MCP Import PLA", "keys": ["filament_cost"], "include_meta": false}, @@ -360,15 +360,15 @@ "expect": {"/items/0/key": {"eq": "auto_arrange"}, "/unknown_keys/0": {"eq": "no_such_preference"}}}, // set_settings refuses the scope (expected to fail), and so does open_preferences an unknown tab; no dialog opens. {"tool": "set_settings", "args": {"scope": "preferences", "values": {"auto_arrange": false}}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "advanced"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "advanced"}}, "optional": true}, {"tool": "get_app_state", "expect": {"/dialogs": {"empty": true}}}, - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "behaviour:auto_arrange"}, "await": false, "save_as": "prefs"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "behaviour", "key": "auto_arrange"}}, "await": false, "save_as": "prefs"}, {"tool": "set_widget_value", "args": {"target": {"name": "auto_arrange", "within": "Preferences"}, "value": false}, "expect": {"/checked": {"eq": false}}}, {"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs}"}}, {"tool": "get_settings", "args": {"scope": "preferences", "keys": ["auto_arrange"]}, "expect": {"/items/0/value": {"eq": "false"}}}, // A key on another tab than the one named is shown on its own tab, where it can be changed. - {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "param": "general:auto_arrange"}, "await": false, "save_as": "prefs2"}, + {"tool": "run_action", "args": {"id": "orca_command:open_preferences:orca", "args": {"tab": "general", "key": "auto_arrange"}}, "await": false, "save_as": "prefs2"}, {"tool": "set_widget_value", "args": {"target": {"name": "auto_arrange", "within": "Preferences"}, "value": true}, "expect": {"/checked": {"eq": true}}}, {"tool": "answer_dialog", "args": {"dialog": {"title": "Preferences"}, "button": "close"}}, {"tool": "wait", "args": {"for": "job", "job": "${jobs.prefs2}"}}, diff --git a/tools/mcp/tests/preview.json b/tools/mcp/tests/preview.json index d6239782a5..6a535c06f1 100644 --- a/tools/mcp/tests/preview.json +++ b/tools/mcp/tests/preview.json @@ -106,7 +106,7 @@ // the selected plate's ---- {"tool": "set_view", "args": {"tab": "prepare"}}, {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "select_objects", "args": {"none": true}}, {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca"}}, {"tool": "wait", "args": {"for": "idle"}}, @@ -114,12 +114,12 @@ {"tool": "slice", "args": {"plates": "all"}, "expect": {"/plates/0/outcome": {"eq": "ok"}, "/plates/1/outcome": {"eq": "ok"}}}, // Slicing every plate leaves the Preview on its all-plates statistics; plate 0 is shown from Prepare. {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "0"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 0}}}, {"tool": "set_view", "args": {"tab": "preview"}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "get_app_state", "expect": {"/plates/current": {"eq": 0}, "/preview/plate": {"eq": 0}}}, {"tool": "set_view", "args": {"tab": "prepare"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "get_app_state", "expect": {"/plates/current": {"eq": 1}, "/preview": {"eq": null}}}, {"tool": "get_slice_stats", "expect": {"/plate": {"eq": 1}, "/summary/layers": {"eq": 128}, "/view": {"eq": null}, "/note": {"contains": "has not loaded this plate's toolpaths"}}}, diff --git a/tools/mcp/tests/recording.json b/tools/mcp/tests/recording.json index 96ab24aa72..12d649ddbd 100644 --- a/tools/mcp/tests/recording.json +++ b/tools/mcp/tests/recording.json @@ -11,7 +11,7 @@ {"tool": "wait", "args": {"for": "ready"}}, {"tool": "auto_answer_dialogs", "args": {"rules": [{"match": "unsaved changes", "button": "no"}, {"match": "restore", "button": "no"}]}}, - {"tool": "new_project"}, + {"tool": "new_project", "args": {"silent": true}}, {"tool": "set_window", "args": {"size": [1600, 1000]}}, {"tool": "set_view", "args": {"tab": "prepare"}}, {"tool": "start_recording", "args": {"save_path": "${out_dir}/session.mkv", "overwrite": true, "captions": true, @@ -34,7 +34,7 @@ {"tool": "slice", "expect": {"/plates/0/outcome": {"eq": "ok"}}}, {"tool": "wait", "args": {"for": "idle"}}, - {"tool": "stop_recording", + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "stopped"}, "/frames": {"ge": 5}, "/written": {"ge": 5}, "/seconds": {"gt": 1}, "/size_bytes": {"gt": 0}, "/capture_ms": {"gt": 0}}}, {"tool": "get_app_state", "expect": {"/recording": {"exists": false}}}, @@ -47,28 +47,32 @@ {"tool": "set_view", "args": {"camera": "iso"}}, {"tool": "mouse_gesture", "args": {"action": "drag", "x": 400, "y": 300, "to": [500, 340]}}]}}, "expect": {"/passed": {"eq": true}, "/unfinished_recording": {"exists": false}}}, - {"tool": "stop_recording", "expect": {"/ended": {"eq": "run_ended"}, "/path": {"regex": "inner\\.mkv$"}}}, + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "run_ended"}, "/path": {"regex": "inner\\.mkv$"}}}, {"tool": "encode_recording", "args": {"overwrite": true, "codec": "h264"}, "optional": true, "expect": {"/path": {"regex": "inner\\.mp4$"}, "/encoder": {"eq": "libx264"}}}, // The replay's end released the file: recording to it again starts at once, with no overlays by default. {"tool": "start_recording", "args": {"save_path": "${out_dir}/inner.mkv", "overwrite": true}, "expect": {"/captions": {"eq": false}, "/pointer": {"eq": false}}}, - {"tool": "stop_recording", "expect": {"/ended": {"eq": "stopped"}}}, + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "stopped"}}}, // captions and pointer each turn on one. {"tool": "start_recording", "args": {"save_path": "${out_dir}/plain.mkv", "overwrite": true, "pointer": true}, "expect": {"/captions": {"eq": false}, "/pointer": {"eq": true}}}, - {"tool": "stop_recording", "expect": {"/ended": {"eq": "stopped"}}}, + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "stopped"}}}, {"tool": "start_recording", "args": {"save_path": "${out_dir}/plain.mkv", "overwrite": true, "captions": true}, "expect": {"/captions": {"eq": true}, "/pointer": {"eq": false}}}, - {"tool": "stop_recording", "expect": {"/ended": {"eq": "stopped"}}}, + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "stopped"}}}, + // Left out, the limit is an hour, and the reply says so. + {"tool": "start_recording", "args": {"save_path": "${out_dir}/limit.mkv", "overwrite": true}, + "expect": {"/max_seconds": {"eq": 3600}}}, + {"tool": "stop_recording", "args": {"silent": true}, "expect": {"/ended": {"eq": "stopped"}}}, // Encoding asked for up front (an ffmpeg with libx264): the stop that reports the recording starts the encode // as a job of its own, which wait idle waits for. {"tool": "start_recording", "args": {"save_path": "${out_dir}/encoded.mkv", "overwrite": true, "encode": true, "encode_preset": "compatible", "crf": 30}, "optional": true, "expect": {"/encode/codec": {"eq": "h264"}, "/encode/crf": {"eq": 30}, "/encode/profile": {"eq": "high"}}}, - {"tool": "stop_recording", "optional": true, + {"tool": "stop_recording", "args": {"silent": true}, "optional": true, "expect": {"/path": {"regex": "encoded\\.mkv$"}, "/encode/status": {"eq": "running"}, "/encode/job": {"exists": true}}}, {"tool": "wait", "args": {"for": "idle", "timeout_s": 50}, "optional": true, "expect": {"/satisfied": {"eq": true}}}, {"tool": "get_app_state", "optional": true, diff --git a/tools/mcp/tests/scene.json b/tools/mcp/tests/scene.json index ce05fd4732..a11a688f69 100644 --- a/tools/mcp/tests/scene.json +++ b/tools/mcp/tests/scene.json @@ -38,7 +38,7 @@ // ---- A part: the Object manipulation panel's path, measured on instance 0 ---- {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "param": "${vars.svg}"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "args": {"path": "${vars.svg}"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "click", "args": {"target": {"gizmo": "SVG"}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/svg/path": {"contains": "star.svg"}}}, @@ -91,20 +91,20 @@ // ---- Shapes at a size, without the dialog ---- {"tool": "select_objects", "args": {"none": true}, "expect": {"/empty": {"eq": true}, "/objects": {"empty": true}}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "40 40 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [40, 40, 10]}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 2}, "/plates/1/objects/0/bbox/size/0": {"ge": 39.99, "le": 40.01}, "/plates/1/objects/0/bbox/size/2": {"ge": 9.99, "le": 10.01}}}, {"tool": "transform", "args": {"object": 1, "part": 0, "translate": [1, 0, 0]}, "optional": true}, // a wrong count adds nothing {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "1 2 3"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [1, 2, 3]}}, "optional": true}, {"tool": "list_objects", "expect": {"/total": {"eq": 2}}}, // with an object selected, an error instead of a silent success {"tool": "select_objects", "args": {"objects": [1]}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "10 5"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [10, 5]}}, "optional": true}, {"tool": "list_objects", "expect": {"/total": {"eq": 2}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "param": "10 5"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cylinder:orca", "args": {"size": [10, 5]}}}, {"tool": "list_objects", "expect": {"/total": {"eq": 3}}}, // ---- Fill bed fills the object's own plate, in one undo step ---- @@ -116,7 +116,7 @@ {"tool": "run_action", "args": {"id": "orca_command:undo:orca"}}, {"tool": "list_objects", "expect": {"/plates/1/objects/0/instances/1": {"exists": false}, "/outside": {"empty": true}}}, // refused: a locked plate, a plate that does not exist, fill with plates - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}}, {"tool": "arrange", "args": {"plates": 1}, "optional": true}, {"tool": "run_action", "args": {"id": "orca_command:plate_toggle_lock:orca"}}, @@ -140,7 +140,7 @@ // ---- add_part: the context menu's Add items, with a size, a file or a position, one undo step each ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "40 40 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [40, 40, 10]}}}, {"tool": "transform", "args": {"object": 0, "translate": [100, 100, 5], "mode": "absolute"}}, // a magnet pocket at the bottom centre {"tool": "add_part", "args": {"object": 0, "type": "negative", "shape": "cylinder", "size": [6.2, 3.2], @@ -187,7 +187,7 @@ {"tool": "run_action", "args": {"id": "orca_command:obj_instances_down:orca"}}, // a shape folds the instance's scale into the parts, as the menu does {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "transform", "args": {"object": 1, "scale": 1.5}}, {"tool": "add_part", "args": {"object": 1, "type": "modifier", "shape": "cube"}, "expect": {"/part": {"eq": 1}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/1/instances/0/scale/0": {"ge": 0.999, "le": 1.001}, @@ -197,7 +197,7 @@ // ---- Object structure commands: the context menus' Change Type, Rename, number of instances, // Set as Individual Objects and Assemble, each a run_action on what select_objects picked ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "30 30 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [30, 30, 10]}}}, {"tool": "add_part", "args": {"object": 0, "type": "modifier", "shape": "cube", "size": [10, 10, 10]}, "expect": {"/part": {"eq": 1}}}, // Change Type, one undo step each; a seam made a part again is listed after the first part {"tool": "select_objects", "args": {"parts": [[0, 1]]}}, @@ -222,7 +222,7 @@ {"tool": "run_action", "args": {"id": "orca_command:obj_type_part:orca"}, "optional": true}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/0/type": {"eq": "part"}, "/plates/0/objects/0/parts/1/type": {"eq": "modifier"}}}, // refused: an SVG part stays a part, a modifier or a negative part - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "param": "${vars.svg}"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_svg:orca", "args": {"path": "${vars.svg}"}}}, {"tool": "wait", "args": {"for": "idle"}}, {"tool": "click", "args": {"target": {"gizmo": "SVG"}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/svg/path": {"contains": "star.svg"}, "/plates/0/objects/0/parts/2/type": {"eq": "modifier"}}}, @@ -231,23 +231,23 @@ {"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/type": {"eq": "part"}}}, // Rename an object and a part; refused: a name a file name cannot hold {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "param": "base"}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "args": {"name": "base"}}}, {"tool": "select_objects", "args": {"parts": [[0, 2]]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "param": "infill zone"}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "param": "a/b"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "args": {"name": "infill zone"}}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "args": {"name": "a/b"}}, "optional": true}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/name": {"eq": "base"}, "/plates/0/objects/0/parts/2/name": {"eq": "infill zone"}}}, // a number of instances in one undo step; refused: 0 and a word {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "select_objects", "args": {"objects": [1]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "6"}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 6}}, "expect": {"/object": {"eq": 1}, "/instances": {"eq": 6}}}, {"tool": "run_action", "args": {"id": "orca_command:undo:orca"}}, {"tool": "list_objects", "expect": {"/plates/0/objects/1/instances/1": {"exists": false}}}, {"tool": "select_objects", "args": {"objects": [1]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "3"}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "0"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "three"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 3}}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 0}}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": "three"}}, "optional": true}, {"tool": "list_objects", "expect": {"/total": {"eq": 2}, "/plates/0/objects/1/instances/2": {"exists": true}, "/plates/0/objects/1/instances/3": {"exists": false}}}, // every instance its own object (the whole object selected), then two of them assembled {"tool": "select_objects", "args": {"objects": [1]}}, @@ -265,23 +265,23 @@ // ---- Order By: ascending, reversed when run again, and the reply says which ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 30"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 30]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 10]}}}, {"tool": "select_objects", "args": {"none": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "20 20 20"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [20, 20, 20]}}}, {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_height:orca"}, "expect": {"/descending": {"eq": false}, "/order/2/object": {"eq": 2}, "/order/2/plate": {"eq": 0}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/bbox/size/2": {"ge": 9.99, "le": 10.01}, "/plates/0/objects/2/bbox/size/2": {"ge": 29.99, "le": 30.01}}}, {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_height:orca"}, "expect": {"/descending": {"eq": true}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/bbox/size/2": {"ge": 29.99, "le": 30.01}}}, - // refused: an empty current plate, a param other than all; all orders every plate + // refused: an empty current plate, an all that is not true or false; all orders every plate {"tool": "run_action", "args": {"id": "orca_command:plate_add:orca"}}, - {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "param": "1"}}, + {"tool": "run_action", "args": {"id": "orca_command:plate_goto:orca", "args": {"plate": 1}}}, {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_size:orca"}, "optional": true}, - {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_size:orca", "param": "every"}, "optional": true}, + {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_size:orca", "args": {"all": "every"}}, "optional": true}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/bbox/size/2": {"ge": 29.99, "le": 30.01}}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_size:orca", "param": "all"}, + {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_size:orca", "args": {"all": true}}, "expect": {"/descending": {"eq": false}, "/order/0/plate": {"eq": 0}, "/order/3": {"exists": false}}}, {"tool": "list_objects", "expect": {"/plates/0/objects/0/bbox/size/2": {"ge": 9.99, "le": 10.01}}}, @@ -289,7 +289,7 @@ // plate, six copies arranged apart there, each made its own object, one mirrored, two assembled, // all ordered by name, the plate filled with one of them, and the plate sliced ---- {"tool": "new_project", "args": {"discard_changes": true}}, - {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "param": "40 40 10"}}, + {"tool": "run_action", "args": {"id": "orca_command:add_primitive_cube:orca", "args": {"size": [40, 40, 10]}}}, {"tool": "transform", "args": {"object": 0, "translate": [100, 100, 5], "mode": "absolute"}}, {"tool": "add_part", "args": {"object": 0, "type": "negative", "shape": "cylinder", "size": [6.2, 3.2], "position": [100, 100, 1.6]}, "expect": {"/part": {"eq": 1}}}, @@ -297,7 +297,7 @@ {"tool": "add_part", "args": {"object": 0, "type": "part", "shape": "cylinder", "size": [10, 5], "position": [100, 100, 12.5]}, "expect": {"/part": {"eq": 1}, "/part_count": {"eq": 3}, "/part_info/bbox/min/2": {"ge": 9.99, "le": 10.01}}}, {"tool": "select_objects", "args": {"parts": [[0, 1]]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "param": "boss"}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_rename:orca", "args": {"name": "boss"}}}, {"tool": "transform", "args": {"object": 0, "part": 1, "translate": [5, 0, 0]}, "expect": {"/part_info/name": {"eq": "boss"}, "/part_info/position/0": {"ge": 104.99, "le": 105.01}}}, // 50 mm wide in proportion, so 1.25 x (10 + 5) mm tall, and still on the bed @@ -310,7 +310,7 @@ {"tool": "transform", "args": {"object": 0, "plate": 1}, "expect": {"/plate": {"eq": 1}}}, // six copies, overlapping where Set Number of Instances puts them, spread out on plate 1 alone {"tool": "select_objects", "args": {"objects": [0]}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "param": "6"}, "expect": {"/instances": {"eq": 6}}}, + {"tool": "run_action", "args": {"id": "orca_command:obj_set_instances:orca", "args": {"count": 6}}, "expect": {"/instances": {"eq": 6}}}, {"tool": "arrange", "args": {"plates": 1, "spacing": 10, "rotate": false}, "expect": {"/off_plate": {"empty": true}, "/settings/spacing": {"eq": 10}, "/plates": {"eq": 2}}}, {"tool": "list_objects", "args": {"plate": 0}, "expect": {"/total": {"eq": 0}}}, @@ -329,7 +329,7 @@ {"tool": "list_objects", "expect": {"/total": {"eq": 5}, "/plates/1/objects/4/parts/5": {"exists": true}, "/plates/1/objects/4/bbox/min/2": {"ge": -0.001, "le": 0.001}, "/plates/1/objects/3/instances/0/mirrored": {"eq": true}}}, - {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_name:orca", "param": "all"}, + {"tool": "run_action", "args": {"id": "orca_command:obj_order_by_name:orca", "args": {"all": true}}, "expect": {"/descending": {"eq": false}, "/order/0/name": {"eq": "Assembly"}, "/order/4/plate": {"eq": 1}}}, {"tool": "arrange", "args": {"fill": 1}, "expect": {"/added": {"gt": 0}, "/plate": {"eq": 1}, "/off_plate": {"empty": true}}}, {"tool": "slice", "args": {"plates": 1}, "expect": {"/plates/0/outcome": {"eq": "ok"}}},